1 /* Copyright (C) 2013, 2014, 2015 Czech Technical University in Prague
4 * - Carlos Jenkins <carlos@jenkins.co.cr>
6 * This document contains proprietary information belonging to Czech
7 * Technical University in Prague. Passing on and copying of this
8 * document, and communication of its contents is not permitted
9 * without prior written authorization.
13 * H-Bridge Output RPP API implementation file.
17 * RPP API documentation.
23 #ifndef FREERTOS_POSIX
24 #include "drv/hbridge.h"
25 #include "drv/spi_tms570.h"
28 static boolean_t initialized = FALSE;
35 #ifndef FREERTOS_POSIX
44 // Private function to set the H-Bridge to default OFF settings
45 static void rpp_hdr_reset()
47 #ifndef FREERTOS_POSIX
49 drv_hbr_pwm_set_duty(0);
56 static boolean_t enabled = FALSE;
58 int8_t rpp_hbr_enable(int32_t period)
64 period = 55; // ~18kHz (18181.818181818 Hz to be precise)
68 #ifndef FREERTOS_POSIX
71 if (drv_hbr_pwm_set_signal(period, 0) != SUCCESS)
78 int ret = drv_hbr_wdg_start();
79 if (ret != SUCCESS && ret != -RPP_EBUSY) // Don't fail if already started
90 int8_t rpp_hbr_control(double cmd)
95 // Check range of the command
96 if ((cmd < -1.0) || (cmd > 1.0))
99 #ifndef FREERTOS_POSIX
100 // Great, now scale and return to sanity world of ints :D
101 int32_t scaled = (int32_t)(cmd * 100.0);
105 drv_hbr_set_dir(scaled > 0);
107 // Set PWM duty cycle
108 drv_hbr_pwm_set_duty(abs(scaled));
115 int8_t rpp_hbr_disable()
120 #ifndef FREERTOS_POSIX
123 // We ignore is watchdog could not be stopped, because is harmless.
124 // It would be worse if we just could not stop the H-Bridge just because
125 // the watchdog could not be stopped.