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
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.
Diff: MotCon.cpp
- Revision:
- 4:10187d108666
- Parent:
- 0:3ba12980833b
- Child:
- 2:23cd902e1774
- Child:
- 5:3e07f69d8abd
--- a/MotCon.cpp Mon Aug 31 17:13:55 2015 +0000 +++ b/MotCon.cpp Mon May 23 19:06:31 2016 +0000 @@ -27,3 +27,40 @@ _pwm = 0.0; } } + +// dc is signed duty cycle (+/-1.0) +void MotCon::mot_control(float dc, int invert){ + if(dc>1.0) + dc=1.0; + if(dc<-1.0) + dc=-1.0; + + if(invert==0){ + if(dc > 0.001){ + _dir = 0; + _pwm = dc; + } + else if(dc < -0.001){ + _dir = 1; + _pwm = abs(dc); + } + else{ + _dir = 0; + _pwm = 0.0; + } + } + else{ + if(dc > 0.001){ + _dir = 1; + _pwm = dc; + } + else if(dc < -0.001){ + _dir = 0; + _pwm = abs(dc); + } + else{ + _dir = 0; + _pwm = 0.0; + } + } +}