PropWare
C++ objects and CMake build system for Parallax Propeller
|
#include <vnh2sp30.h>
Public Types | |
enum | Direction { FORWARD, REVERSE } |
enum | PwmChannel { NONE, X, Y } |
Public Member Functions | |
vnh2sp30 () | |
~vnh2sp30 () | |
void | Init (libpropeller::PWM32 *new_pwm, const int new_pwmPin, const int inApin, const int inBpin) |
void | Init (libpropeller::PWM2 *new_pwm, const PwmChannel new_channel, const int new_pwmPin, const int inApin, const int inBpin) |
void | Set (const int power) |
void | Set (const Direction direction, const int power) |
void | SetPower (const int power) |
void | SetDirection (const Direction direction) |
Operate a VNH2SP30 brushed DC motor driver.
This class runs using either the PWM2 or PWM32 class. The advantage of the PWM2 class is that it can be run at a higher frequency, which may reduce audible motor noise. The PWM32 class has the advantage that it can run as many channels as PWM as needed (up to 32), including up to 10 channels of VNH2SP30 drivers. It can also run servos and general PWM. The downside is that the maximum PWM frequency is lower.
This object requires the VNH2SP30 driver chip connected via INA, INB, and the PWM pin. Note that the VNH2SP30 driver requires a minimum of 3.25v for the high signal, and a minimum of 0.6v for the low signal. To reliably output this signal you will need to add some sort of 3.3v->5v conversion from the Propeller pin to the VNH2SP30 I/O pins.
One option for voltage conversion is to use a 20kOhm resistor connected from the signal line (Propeller I/O -> VNH2SP30) to 5v. This will pull up the signal to 3.9v when outputting high (3.3v + 0.6v for the protective diode) and the Propeller pin can pull the signal down to 0v when outputting low. Thanks goes to Mike Green for this simple option. SRLM hasn't experienced any issues with this circuit, but your experience may differ.
A more complex (and likely reliable) option would be to use appropriate level converter chips as described in the Parallax Eddie schematic.
Note that this driver does not have any feedback on what the actual speed of the motor is. A heavy load will decrease the actual speed, and requires more power delivered (a higher PWM duty cycle) to increase the actual speed of the motor.
Definition at line 45 of file vnh2sp30.h.
If direction needs to be specified use these constants.
Definition at line 71 of file vnh2sp30.h.
If using the PWM2 driver you must specify a channel to use. Each VNH2SP30 driver can use at most one channel.
Definition at line 78 of file vnh2sp30.h.
libpropeller::vnh2sp30::vnh2sp30 | ( | ) |
Construct a new instance. Does not start a new cog.
Definition at line 50 of file vnh2sp30.h.
libpropeller::vnh2sp30::~vnh2sp30 | ( | ) |
Delete this instance. Does not stop the PWM driver, but does stop the motor.
Definition at line 59 of file vnh2sp30.h.
void libpropeller::vnh2sp30::Init | ( | libpropeller::PWM32 * | new_pwm, |
const int | new_pwmPin, | ||
const int | inApin, | ||
const int | inBpin | ||
) |
Initialize this motor driver using a PWM32 object.
Sets the motor to stop.
new_pwm | The PWM32 driver to use. Must be Start()'d |
new_pwmPin | The pin connected to the VNH2SP30 PWM pin (with voltage translator) |
inApin | The pin connected to inA (with voltage translator) |
inBpin | The pin connected to inB (with voltage translator) |
Definition at line 91 of file vnh2sp30.h.
void libpropeller::vnh2sp30::Init | ( | libpropeller::PWM2 * | new_pwm, |
const PwmChannel | new_channel, | ||
const int | new_pwmPin, | ||
const int | inApin, | ||
const int | inBpin | ||
) |
Initialize this motor driver using a PWM2 object.
Sets the motor to stop.
new_pwm | The PWM2 driver to use. Must be Start()'d |
new_channel | The PWM2 driver channel to use. Must not be used by anything else |
new_pwmPin | The pin connected to the VNH2SP30 PWM pin (with voltage translator) |
inApin | The pin connected to inA (with voltage translator) |
inBpin | The pin connected to inB (with voltage translator) |
Definition at line 116 of file vnh2sp30.h.
void libpropeller::vnh2sp30::Set | ( | const int | power | ) |
Set motor speed and direction.
power | Set the power in range [-100..100] where negative is reverse and positive is forward |
Definition at line 148 of file vnh2sp30.h.
void libpropeller::vnh2sp30::Set | ( | const Direction | direction, |
const int | power | ||
) |
Set motor speed and direction
direction | The direction |
power | The power [0..100] to deliver to the motor |
Definition at line 163 of file vnh2sp30.h.
void libpropeller::vnh2sp30::SetDirection | ( | const Direction | direction | ) |
The direction to rotate the motor
direction |
Definition at line 196 of file vnh2sp30.h.
void libpropeller::vnh2sp30::SetPower | ( | const int | power | ) |
Set the power delivered to the motor.
power | The power [0..100] to deliver to the motor |
Definition at line 173 of file vnh2sp30.h.