2 * H-Bridge Output RPP API header file.
6 * @copyright Copyright (C) 2013 Czech Technical University in Prague
8 * @author Carlos Jenkins <carlos@jenkins.co.cr>
16 * HBR module initialization.
18 * Call this method before using this module.
20 * @return SUCCESS if initialization successful.\n
21 * FAILURE if module already initialized.
23 int8_t rpp_hbr_init();
27 * Enable the H-Bridge output and set PWM frequency.
29 * Sets duty cycle to zero, direction to LOW and enables the H-Bridge
30 * output. Duty cycle and direction can be later controlled with
31 * rpp_hbr_control() (see below).
33 * @param[in] period Period of the PWM in microseconds (us). If period is
34 * less than 1 (the minimum, see note below) the default of
35 * 55us (~18kHz, 18181.8181_ Hz to be precise) is used.
37 * @return SUCCESS if successful.\n
38 * FAILURE if H-Bridge was already enabled or watchdog task could not
41 * @note Period considerations from Software perspective (hardware verification
44 * - Minimum value is [1us]:
46 * - System clock is 80MHz.
48 * - Maximum value is [2147483647us] (full 32bit signed integer):
49 * - 2147483647us = 2147483.647 ms = 2147.483647 s =
50 * ~35.791394 min => 0.000465661129 Hz -> 0.0... MHz
52 int8_t rpp_hbr_enable(int32_t period);
56 * Control the H-Bridge direction and PWM duty cycle.
58 * @param[in] cmd [-1.0, 1.0] A double between the previous range to
59 * command the H-Bridge in the following manner:
60 * - cmd > 0 : direction set to HIGH and PWM
61 * duty cycle proportional with
63 * - cmd <= 0 : direction set to LOW and PWM
64 * duty cycle proportional with
67 * Consider the following:
70 * rpp_hbr_enable(-1); // Enable H-Bridge at 18kHz.
71 * rpp_hbr_control( 1.0); // Set direction to HIGH and 100% PWM duty cycle.
73 * rpp_hbr_control( 0.0); // 0% duty cycle, but H-Bridge output active (low-side active free wheeling)
75 * rpp_hbr_control(-0.5); // Set direction to LOW and 50% PWM duty cycle.
76 * rpp_hbr_disable(); // Disable H-Bridge output.
79 * @return SUCCESS if change was successful.\n
80 * -1 if H-Bridge is not enabled. Call rpp_hbr_enable() first.\n
81 * -2 if cmd is out of range.
83 int8_t rpp_hbr_control(double cmd);
87 * Disable the H-Bridge output.
89 * Completely disable H-Bridge. After this call the H-Bridge cannot be
90 * controlled again until another call to rpp_hbr_enable() is made.
92 * @return SUCCESS if successful.\n
93 * FAILURE if H-Bridge was already disabled.
95 int8_t rpp_hbr_disable();
98 #endif /* __RPP_HBR_H */