libpropeller
Making PropellerGCC Easier
|
Operate a VNH2SP30 brushed DC motor driver. More...
#include <vnh2sp30.h>
Public Types | |
enum | Direction { FORWARD, REVERSE } |
If direction needs to be specified use these constants. More... | |
enum | PwmChannel { NONE, X, Y } |
If using the PWM2 driver you must specify a channel to use. More... | |
Public Member Functions | |
vnh2sp30 () | |
Construct a new instance. More... | |
~vnh2sp30 () | |
Delete this instance. More... | |
void | Init (PWM32 *new_pwm, const int new_pwmPin, const int inApin, const int inBpin) |
Initialize this motor driver using a PWM32 object. More... | |
void | Init (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. More... | |
void | Set (const int power) |
Set motor speed and direction. More... | |
void | Set (const Direction direction, const int power) |
Set motor speed and direction. More... | |
void | SetPower (const int power) |
Set the power delivered to the motor. More... | |
void | SetDirection (const Direction direction) |
The direction to rotate the motor. More... | |
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.
enum vnh2sp30::Direction |
enum vnh2sp30::PwmChannel |
If using the PWM2 driver you must specify a channel to use.
Each VNH2SP30 driver can use at most one channel.
Enumerator | |
---|---|
NONE | |
X | |
Y |
|
inline |
Construct a new instance.
Does not start a new cog.
|
inline |
Delete this instance.
Does not stop the PWM driver, but does stop the motor.
|
inline |
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) |
|
inline |
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) |
|
inline |
Set motor speed and direction.
power | Set the power in range [-100..100] where negative is reverse and positive is forward |
|
inline |
Set motor speed and direction.
direction | The direction |
power | The power [0..100] to deliver to the motor |
|
inline |
The direction to rotate the motor.
direction |
|
inline |
Set the power delivered to the motor.
power | The power [0..100] to deliver to the motor |