Simple DC motor control commands for driving DC motor conroller with PWM and up to 2 direction signals (complementary). Takes float value from -1.0 to 1.0.

Dependents:   Teensy_Mot_QEI_Ser_20180111 Axis Axis_20181108 Axis_version2

Fork of MotCon by Joseph Bradshaw

Overloaded class that takes a pwm motor control pin and one or two direction pins for driving DC motors with a variety of motor control IC's. Tested examples include the LM298, TD340, MC33926, A3949.

Committer:
jebradshaw
Date:
Mon Aug 31 17:13:55 2015 +0000
Revision:
0:3ba12980833b
Child:
1:69e79f1db999
simple motor control command

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jebradshaw 0:3ba12980833b 1 #include "MotCon.h"
jebradshaw 0:3ba12980833b 2
jebradshaw 0:3ba12980833b 3 //Constructor
jebradshaw 0:3ba12980833b 4 MotCon::MotCon(PinName pwm, PinName dir) : _pwm(pwm), _dir(dir) {
jebradshaw 0:3ba12980833b 5 _pwm.period_us(50);
jebradshaw 0:3ba12980833b 6 _pwm = 0.0;
jebradshaw 0:3ba12980833b 7 _dir = 0;
jebradshaw 0:3ba12980833b 8 }
jebradshaw 0:3ba12980833b 9
jebradshaw 0:3ba12980833b 10 // dc is signed duty cycle (+/-1.0)
jebradshaw 0:3ba12980833b 11 void MotCon::mot_control(float dc){
jebradshaw 0:3ba12980833b 12 if(dc>1.0)
jebradshaw 0:3ba12980833b 13 dc=1.0;
jebradshaw 0:3ba12980833b 14 if(dc<-1.0)
jebradshaw 0:3ba12980833b 15 dc=-1.0;
jebradshaw 0:3ba12980833b 16
jebradshaw 0:3ba12980833b 17 if(dc > 0.001){
jebradshaw 0:3ba12980833b 18 _dir = 0;
jebradshaw 0:3ba12980833b 19 _pwm = dc;
jebradshaw 0:3ba12980833b 20 }
jebradshaw 0:3ba12980833b 21 else if(dc < -0.001){
jebradshaw 0:3ba12980833b 22 _dir = 1;
jebradshaw 0:3ba12980833b 23 _pwm = abs(dc);
jebradshaw 0:3ba12980833b 24 }
jebradshaw 0:3ba12980833b 25 else{
jebradshaw 0:3ba12980833b 26 _dir = 0;
jebradshaw 0:3ba12980833b 27 _pwm = 0.0;
jebradshaw 0:3ba12980833b 28 }
jebradshaw 0:3ba12980833b 29 }