libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Public Types | Public Member Functions | List of all members
vnh2sp30 Class Reference

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...
 

Detailed Description

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.

Todo:
(SRLM): add in the minimum off time. Although this doesn't seem to be necessary on my test module.

Member Enumeration Documentation

If direction needs to be specified use these constants.

Enumerator
FORWARD 
REVERSE 

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 

Constructor & Destructor Documentation

vnh2sp30::vnh2sp30 ( )
inline

Construct a new instance.

Does not start a new cog.

vnh2sp30::~vnh2sp30 ( )
inline

Delete this instance.

Does not stop the PWM driver, but does stop the motor.

Here is the call graph for this function:

Member Function Documentation

void vnh2sp30::Init ( PWM32 new_pwm,
const int  new_pwmPin,
const int  inApin,
const int  inBpin 
)
inline

Initialize this motor driver using a PWM32 object.

Sets the motor to stop.

Parameters
new_pwmThe PWM32 driver to use. Must be Start()'d
new_pwmPinThe pin connected to the VNH2SP30 PWM pin (with voltage translator)
inApinThe pin connected to inA (with voltage translator)
inBpinThe pin connected to inB (with voltage translator)

Here is the call graph for this function:

void vnh2sp30::Init ( PWM2 new_pwm,
const PwmChannel  new_channel,
const int  new_pwmPin,
const int  inApin,
const int  inBpin 
)
inline

Initialize this motor driver using a PWM2 object.

Sets the motor to stop.

Parameters
new_pwmThe PWM2 driver to use. Must be Start()'d
new_channelThe PWM2 driver channel to use. Must not be used by anything else
new_pwmPinThe pin connected to the VNH2SP30 PWM pin (with voltage translator)
inApinThe pin connected to inA (with voltage translator)
inBpinThe pin connected to inB (with voltage translator)

Here is the call graph for this function:

void vnh2sp30::Set ( const int  power)
inline

Set motor speed and direction.

Parameters
powerSet the power in range [-100..100] where negative is reverse and positive is forward

Here is the call graph for this function:

void vnh2sp30::Set ( const Direction  direction,
const int  power 
)
inline

Set motor speed and direction.

Parameters
directionThe direction
powerThe power [0..100] to deliver to the motor

Here is the call graph for this function:

void vnh2sp30::SetDirection ( const Direction  direction)
inline

The direction to rotate the motor.

Parameters
direction

Here is the call graph for this function:

void vnh2sp30::SetPower ( const int  power)
inline

Set the power delivered to the motor.

Parameters
powerThe power [0..100] to deliver to the motor

The documentation for this class was generated from the following file: