Skyward boardcore
|
Driver to operate an H-bridge. More...
#include <HBridge.h>
Public Member Functions | |
HBridge (miosix::GpioPin inhibitPin, TIM_TypeDef *timer, TimerUtils::Channel channel, unsigned int frequency, float dutyCycle=0, unsigned int disableDelayMs=50) | |
Prepares the enable pin and the timer. | |
~HBridge () | |
Disables the H-bridge. | |
void | enable () |
Enables the H-bridge and starts the pwm signal. | |
void | disable () |
Stops the pwm signal and deactivates the H-bridge after the configured amount of time. | |
bool | isEnabled () |
void | setDutyCycle (float dutyCycle) |
Changes the current duty cycle and saves it. | |
void | testDutyCycle (float dutyCycle) |
Same as setDutyCycle() but does not memorize the value. | |
void | resetDutyCycle () |
Resets the duty cycle to the last configure value. | |
Driver to operate an H-bridge.
From Wikipedia (https://en.wikipedia.org/wiki/H-bridge): An H-bridge is an electronic circuit that switches the polarity of a voltage applied to a load. These circuits are often used in robotics and other applications to allow DC motors to run forwards or backwards. ... In particular, a bipolar stepper motor is almost always driven by a motor controller containing two H bridges.
Also, most ICs allow to control the voltage applied to the device by the means of a PWM signal which proportionally controls the voltage.
This driver allow to manage the enable pin of the H-bridge and the pwm signal, but it does not still support the control pin needed to reverse the polarity.
When disabling the device, the driver waits a predefined amount of time between changing the inhibit pin and the pwm signal. This delay is achieved by making the current thread sleep.
Note that the driver assumes that the inhibit pin disables the driver if driven low.
Boardcore::HBridge::HBridge | ( | miosix::GpioPin | inhibitPin, |
TIM_TypeDef * | timer, | ||
TimerUtils::Channel | channel, | ||
unsigned int | frequency, | ||
float | dutyCycle = 0, | ||
unsigned int | disableDelayMs = 50 ) |
Prepares the enable pin and the timer.
Note that the timer is enabled automatically when the PWM object is created.
inhibitPin | Inhibit pin of the H-bridge. |
timer | Timer peripheral used for the PWM signal. |
channel | Timer's channel used for the PWM signal. |
frequency | Frequency of the PWM driving the H-bridge. |
dutyCycle | Duty cycle of the PWM in the range [0-1]. |
disableDelayMs | Delay between changing the inhibit pin and the pwm signal when disabling the device. |
Definition at line 28 of file HBridge.cpp.
Boardcore::HBridge::~HBridge | ( | ) |
Disables the H-bridge.
Note that the timer is disabled automatically when the PWM object is destructed, the PWM signal stops.
Definition at line 37 of file HBridge.cpp.
void Boardcore::HBridge::disable | ( | ) |
Stops the pwm signal and deactivates the H-bridge after the configured amount of time.
Definition at line 47 of file HBridge.cpp.
void Boardcore::HBridge::enable | ( | ) |
Enables the H-bridge and starts the pwm signal.
Definition at line 39 of file HBridge.cpp.
bool Boardcore::HBridge::isEnabled | ( | ) |
Definition at line 56 of file HBridge.cpp.
void Boardcore::HBridge::resetDutyCycle | ( | ) |
Resets the duty cycle to the last configure value.
void Boardcore::HBridge::setDutyCycle | ( | float | dutyCycle | ) |
Changes the current duty cycle and saves it.
Node that the change will take effect immediately and it is not needed to re-enable the H-bridge.
Definition at line 58 of file HBridge.cpp.
void Boardcore::HBridge::testDutyCycle | ( | float | dutyCycle | ) |
Same as setDutyCycle() but does not memorize the value.
This is useful if you then want to reset the duty cycle to the previously configured value.
Definition at line 65 of file HBridge.cpp.