Library for the VNH5019 Motor Driver, with a helper class for the Pololu Dual VNH5019 Dual Motor Driver Shield http://www.pololu.com/product/2502

Dependents:   VNH5019_second VNH5019_second1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers VNH5019.cpp Source File

VNH5019.cpp

00001 #include "VNH5019.h"
00002 
00003 VNH5019::VNH5019(PinName INA_, PinName INB_, PinName ENDIAG_, PinName CS_, PinName PWM_)
00004  : INA(INA_),
00005    INB(INB_),
00006    ENDIAG(ENDIAG_),
00007    CS(CS_),
00008    PWM(PWM_)
00009 {
00010     this->init();
00011 }
00012 
00013 void VNH5019::init()
00014 {
00015    ENDIAG.input();
00016    ENDIAG.mode(PullUp);
00017    PWM.period(0.00025);   // 4 kHz (valid 0 - 20 kHz)
00018    PWM.write(0);
00019    INA = 0;
00020    INB = 0;
00021 }
00022  
00023 void VNH5019::speed(float Speed)
00024 {
00025    bool Reverse = 0;
00026   
00027    if (Speed < 0)
00028    {
00029      Speed = -Speed;  // Make speed a positive quantity
00030      Reverse = 1;  // Preserve the direction
00031    }
00032   
00033    // clamp the speed at maximum
00034    if (Speed > 1.0)
00035       Speed = 1.0;
00036     
00037    if (Speed == 0.0)
00038    {
00039        INA = 0;
00040        INB = 0;
00041        PWM = 0;
00042     }
00043     else
00044     {
00045       INA = !Reverse;
00046       INB = Reverse;
00047       PWM = Speed;
00048     }
00049 }
00050 
00051 void VNH5019::clear_fault()
00052 {
00053     // if ENDIAG is high, then there is no fault
00054     if (ENDIAG.read())
00055        return;
00056 
00057    // toggle the inputs
00058    INA = 0;
00059    INB = 0;
00060    wait_us(250);
00061    INA = 1;
00062    INB = 1;
00063    wait_us(250);
00064    
00065    // pull low all inputs and wait 1600us for t_DEL
00066    INA = 0;
00067    INB = 0;
00068    PWM = 0;
00069    ENDIAG.output();
00070    ENDIAG = 0;
00071    wait_us(1600);
00072    
00073    // and finally re-enable the motor
00074    ENDIAG.input();
00075 }