1 /* Copyright (C) 2013 Czech Technical University in Prague
4 * - Carlos Jenkins <carlos@jenkins.co.cr>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * H-Bridge Output RPP API implementation file.
25 * RPP API documentation.
31 #if rppCONFIG_INCLUDE_HBR == 1
33 #if rppCONFIG_DRV == 1
34 #include "drv/hbridge.h"
37 static boolean_t initialized = FALSE;
50 // Private function to set the H-Bridge to default OFF settings
51 static void rpp_hdr_reset()
53 #if rppCONFIG_DRV == 1
55 drv_hbr_pwm_set_duty(0);
62 static boolean_t enabled = FALSE;
64 int8_t rpp_hbr_enable(int32_t period)
71 period = 55; // ~18kHz (18181.818181818 Hz to be precise)
74 #if rppCONFIG_DRV == 1
76 drv_hbr_pwm_set_signal(period, 0);
79 if(drv_hbr_wdg_start() != SUCCESS) {
90 int8_t rpp_hbr_control(double cmd)
96 // Check range of the command
97 if((cmd < -1.0) || (cmd > 1.0)) {
101 #if rppCONFIG_DRV == 1
102 // Great, now scale and return to sanity world of ints :D
103 int32_t scaled = (int32_t)(cmd * 100.0);
105 // Shutdown if required
111 /// Enabled, configure
113 drv_hbr_set_dir(scaled > 0);
115 // Set PWM duty cycle
116 drv_hbr_pwm_set_duty(abs(scaled));
120 drv_hbr_set_en(HIGH);
127 int8_t rpp_hbr_disable()
133 #if rppCONFIG_DRV == 1
134 // We ignore is watchdog could not be stopped, because is harmless.
135 // It would be worse if we just could not stop the H-Bridge just because
136 // the watchdog could not be stopped.
148 #endif /* rppCONFIG_INCLUDE_HBR */