This library is an attempt to encapsulate the Pololu motor board MC33926 Motor Driver Carrier.
http://www.pololu.com/catalog/product/1213
Dual MC33926 Motor Driver Carrier
This dual brushed DC motor driver, based on Freescale’s MC33926 full H-bridge, has a wide operating range of 5 – 28 V and can deliver almost 3 A continuously (5 A peak) to each of its two motor channels. The MC33926 works with 3 – 5 V logic levels, supports ultrasonic (up to 20 kHz) PWM, and features current feedback, under-voltage protection, over-current protection, and over-temperature protection.
Motor.cpp@1:69e4a93b718d, 2013-02-11 (annotated)
- Committer:
- buckeyes1997
- Date:
- Mon Feb 11 20:53:20 2013 +0000
- Revision:
- 1:69e4a93b718d
- Parent:
- 0:b7c4b6de973e
added more checks on speed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
buckeyes1997 | 0:b7c4b6de973e | 1 | #include "Motor.h" |
buckeyes1997 | 0:b7c4b6de973e | 2 | #include "mbed.h" |
buckeyes1997 | 0:b7c4b6de973e | 3 | |
buckeyes1997 | 0:b7c4b6de973e | 4 | |
buckeyes1997 | 0:b7c4b6de973e | 5 | Motor::Motor(PinName pwm, PinName dir1, PinName dir2): _pwm(pwm), _dir1(dir1), _dir2(dir2) |
buckeyes1997 | 0:b7c4b6de973e | 6 | { |
buckeyes1997 | 1:69e4a93b718d | 7 | _direction=1; //default fwd |
buckeyes1997 | 1:69e4a93b718d | 8 | _pwm.period(0.00005); //20Khz |
buckeyes1997 | 1:69e4a93b718d | 9 | _pwm = 0; //default pwm off |
buckeyes1997 | 0:b7c4b6de973e | 10 | _dir1 = 0; |
buckeyes1997 | 0:b7c4b6de973e | 11 | _dir2 = 0; |
buckeyes1997 | 0:b7c4b6de973e | 12 | |
buckeyes1997 | 0:b7c4b6de973e | 13 | } |
buckeyes1997 | 0:b7c4b6de973e | 14 | |
buckeyes1997 | 0:b7c4b6de973e | 15 | float Motor::speed(float speed, bool direction) |
buckeyes1997 | 0:b7c4b6de973e | 16 | { |
buckeyes1997 | 0:b7c4b6de973e | 17 | if(direction == true) { |
buckeyes1997 | 0:b7c4b6de973e | 18 | _dir1=1; |
buckeyes1997 | 0:b7c4b6de973e | 19 | _dir2=0; |
buckeyes1997 | 0:b7c4b6de973e | 20 | } else { |
buckeyes1997 | 0:b7c4b6de973e | 21 | _dir1=0; |
buckeyes1997 | 0:b7c4b6de973e | 22 | _dir2=1; |
buckeyes1997 | 0:b7c4b6de973e | 23 | } |
buckeyes1997 | 1:69e4a93b718d | 24 | if(speed > 1) { |
buckeyes1997 | 1:69e4a93b718d | 25 | speed = 1; |
buckeyes1997 | 1:69e4a93b718d | 26 | } |
buckeyes1997 | 1:69e4a93b718d | 27 | if(speed < -1) { |
buckeyes1997 | 1:69e4a93b718d | 28 | speed = -1; |
buckeyes1997 | 1:69e4a93b718d | 29 | } |
buckeyes1997 | 1:69e4a93b718d | 30 | |
buckeyes1997 | 0:b7c4b6de973e | 31 | _pwm = abs(speed); |
buckeyes1997 | 0:b7c4b6de973e | 32 | return speed; |
buckeyes1997 | 0:b7c4b6de973e | 33 | } |
buckeyes1997 | 0:b7c4b6de973e | 34 | |
buckeyes1997 | 0:b7c4b6de973e | 35 | float Motor::speed(float speed) |
buckeyes1997 | 0:b7c4b6de973e | 36 | { |
buckeyes1997 | 1:69e4a93b718d | 37 | if(speed > 1) { |
buckeyes1997 | 1:69e4a93b718d | 38 | speed = 1; |
buckeyes1997 | 1:69e4a93b718d | 39 | } |
buckeyes1997 | 1:69e4a93b718d | 40 | if(speed < -1) { |
buckeyes1997 | 1:69e4a93b718d | 41 | speed = -1; |
buckeyes1997 | 1:69e4a93b718d | 42 | } |
buckeyes1997 | 1:69e4a93b718d | 43 | if(speed < 0) { |
buckeyes1997 | 1:69e4a93b718d | 44 | _dir1=1; |
buckeyes1997 | 1:69e4a93b718d | 45 | _dir2=0; |
buckeyes1997 | 1:69e4a93b718d | 46 | } else { |
buckeyes1997 | 1:69e4a93b718d | 47 | _dir1=0; |
buckeyes1997 | 1:69e4a93b718d | 48 | _dir2=1; |
buckeyes1997 | 1:69e4a93b718d | 49 | } |
buckeyes1997 | 0:b7c4b6de973e | 50 | _pwm = abs(speed); |
buckeyes1997 | 0:b7c4b6de973e | 51 | return speed; |
buckeyes1997 | 0:b7c4b6de973e | 52 | } |
buckeyes1997 | 0:b7c4b6de973e | 53 | |
buckeyes1997 | 1:69e4a93b718d | 54 | Motor& Motor::operator= (float speed) |
buckeyes1997 | 1:69e4a93b718d | 55 | { |
buckeyes1997 | 1:69e4a93b718d | 56 | if(speed > 1) { |
buckeyes1997 | 1:69e4a93b718d | 57 | speed = 1; |
buckeyes1997 | 1:69e4a93b718d | 58 | } |
buckeyes1997 | 1:69e4a93b718d | 59 | if(speed < -1) { |
buckeyes1997 | 1:69e4a93b718d | 60 | speed = -1; |
buckeyes1997 | 1:69e4a93b718d | 61 | } |
buckeyes1997 | 1:69e4a93b718d | 62 | if(speed < 0) { |
buckeyes1997 | 1:69e4a93b718d | 63 | _dir1=1; |
buckeyes1997 | 1:69e4a93b718d | 64 | _dir2=0; |
buckeyes1997 | 1:69e4a93b718d | 65 | } else { |
buckeyes1997 | 1:69e4a93b718d | 66 | _dir1=0; |
buckeyes1997 | 1:69e4a93b718d | 67 | _dir2=1; |
buckeyes1997 | 1:69e4a93b718d | 68 | } |
buckeyes1997 | 0:b7c4b6de973e | 69 | _pwm = abs(speed); |
buckeyes1997 | 1:69e4a93b718d | 70 | return *this; |
buckeyes1997 | 0:b7c4b6de973e | 71 | } |