2 * Copyright (C) 2012-2014 Czech Technical University in Prague
4 * Created on: 28.2.2013
9 * This document contains proprietary information belonging to Czech
10 * Technical University in Prague. Passing on and copying of this
11 * document, and communication of its contents is not permitted
12 * without prior written authorization.
17 * This file contains commands controlling H-bridge
27 #include "cmdproc_utils.h"
31 * @brief Enable HBR driver with given period of PWM
33 * @param[in] cmd_io Pointer to IO stack
34 * @param[in] des Pointer to command descriptor
35 * @param[in] param Parameters of command
36 * @return 0 when OK or error code
38 int cmd_do_hbr_enable(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
45 if (sscanf(p, "%d %1s", &period, &spareParams) != 1)
46 return -CMDERR_BADPAR;
48 ret = rpp_hbr_enable(period);
50 rpp_sci_printf("Enable procedure failed.\n");
54 rpp_sci_printf("hbrenable =%d\n", period, ret);
59 * @brief Control HBR driver with given value <-100; 100>
61 * @param[in] cmd_io Pointer to IO stack
62 * @param[in] des Pointer to command descriptor
63 * @param[in] param Parameters of command
64 * @return 0 when OK or error code
66 int cmd_do_hbr_control(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
73 if (sscanf(p, "%d %1s", &cmd, &spareParams) != 1)
74 return -CMDERR_BADPAR;
76 ret = rpp_hbr_control((double)cmd/(double)100);
78 rpp_sci_printf("H-bridge not enabled.\n");
82 rpp_sci_printf("Command out of range.\n");
83 return -CMDERR_BADPAR;
85 rpp_sci_printf("hbrcontrol =%d\n", cmd, ret);
90 * @brief Disable HBR driver.
92 * @param[in] cmd_io Pointer to IO stack
93 * @param[in] des Pointer to command descriptor
94 * @param[in] param Parameters of command
95 * @return 0 when OK or error code
97 int cmd_do_hbr_disable(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
101 ret = rpp_hbr_disable();
103 rpp_sci_printf("H-bridge already disabled.\n");
104 return cmd_opchar_replong(cmd_io, param, ret, 0, 10);
109 /** Command descriptor for HBR enable command */
110 cmd_des_t const cmd_des_hbr_enable = {
112 "hbrenable*","Enable the H-bridge and set its PWM period",
113 "### Command syntax ###\n"
117 "where `<PER>` is PWM period in microseconds.\n"
119 "### Description ###\n"
121 "This command enables the H-bridge (HBR pin), i.e. the enable signal\n"
122 "the H-bridge chip is set, the watchdog reset task is started and the\n"
123 "PWM is configured with the specified period and duty cycle 0%.\n"
125 "If the period is zero, the default frequency of 18kHz is\n"
126 "used instead. Minimum period is 50. This command should be\n"
127 "called before any other command\n"
128 "starting with hbr is used. If H-bridge is already enabled, an error is\n"
133 " --> hbrenable1000\n"
136 "Enables HBR with period 1000 microseconds (frequency 1 kHz). HBR\n"
137 "output is still inactive, but ready for other commands.\n",
138 CMD_HANDLER(cmd_do_hbr_enable), (void *)&cmd_list_hbr
141 /** Command descriptor for HBR control command */
142 cmd_des_t const cmd_des_hbr_control = {
144 "hbrcontrol*","Set the motor voltage direction and size in percent",
145 "### Command syntax ###\n"
147 " hbrcontrol<SPEED>\n"
149 "where `<SPEED>` specifies direction and PWM duty cycle in percent (a\n"
150 "number in range -100, 100).\n"
152 "### Description ###\n"
154 "The command sets the direction and the size of the voltage at the HBR\n"
157 "HBR has to be enabled by the `hbrenable` command before calling this\n"
162 " --> hbrcontrol-25\n"
165 "Rotates the motor to the left with 25% duty cycle.\n"
167 " --> hbrcontrol25\n"
170 "Rotates the motor to the right with 25% duty cycle.\n"
175 "Stops the motor, but the H-Bridge output is active (low-side active\n"
177 CMD_HANDLER(cmd_do_hbr_control), (void *)&cmd_list_hbr
180 /** Command descriptor for HBR disable command */
181 cmd_des_t const cmd_des_hbr_disable = {
183 "hbrdisable","Disable the H-bridge",
184 "### Command syntax ###\n"
188 "### Description ###\n"
190 "The command disables the H-bridge HBR, which means that the PWM is\n"
191 "stopped and the enable signal is cleared. The watchdog task is left\n"
192 "running, because it is harmless.\n"
194 "After the H-bridge is disabled, it cannot be controlled by any command\n"
195 "until it is enabled again by the `hbrenable` command.\n"
202 "Stops motor and disables the H-bridge.\n",
203 CMD_HANDLER(cmd_do_hbr_disable), (void *)&cmd_list_hbr
206 /** List of commands for hbr, defined as external */
207 cmd_des_t const *cmd_list_hbr[] = {
209 &cmd_des_hbr_control,
210 &cmd_des_hbr_disable,