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:   mbed_ES410_simpleSpeedMeasurement mbed_ES20X_V21_Tester

This MotCon motor driver class can be used with a variety of motor driver integrated circuits for driving PM DC motors. The MotCon class is overloaded to accommodate either one or two direction pins and a PwmOut pin for speed control/motor enable .

include the mbed library with this snippet

#include "MotCon.h"     //uses the MotCon.h library for controlling the motor ports

//PC serial connection
Serial pc(USBTX, USBRX);    //tx, rx via USB connection
DigitalOut led(LED1);
MotCon m1(p25, p27);        //uses p25 for PWM and p27 for direction
MotCon m2(p26, p29, p30);   //uses p26 for pwm and p29 and 30 for direction (complimentary)

//------------ Main ------------------------------
int main() {    
    pc.baud(921600);//fast baud rate for USB PC connection
    while(1) {
        //iterate through 2*pi cycles in .01 increments
        for(float cycle=0;cycle<3.14159*2.0;cycle+=.01){
            float m1_dc = .85*sin(cycle);            
            m1.mot_control(m1_dc);
            
            float m2_dc = .85*cos(cycle);
            m2.mot_control(m2_dc);
                        
            pc.printf("cycle=%.3f  m1_dc = %.2f  m1_dc = %.2f\r\n", cycle, m1_dc, m2_dc);
            wait(.01);      //determines period
            led = !led;     //toggle LED1 to indicate activity
        }
    }
}

History

Added shorthand operator read and write functions. May need to check overloaded function using invert default tip

2018-03-16, by jebradshaw [Fri, 16 Mar 2018 15:34:29 +0000] rev 11

Added shorthand operator read and write functions. May need to check overloaded function using invert


Added shorthand read and write functions. May need to check implementation of overloaded function with invert used

2018-03-16, by jebradshaw [Fri, 16 Mar 2018 15:31:03 +0000] rev 10

Added shorthand read and write functions. May need to check implementation of overloaded function with invert used


Added shorthand operators for assignment and float (shorthand read)

2016-11-01, by jebradshaw [Tue, 01 Nov 2016 14:06:30 +0000] rev 9

Added shorthand operators for assignment and float (shorthand read)


added operator functions for simplified parameter passing

2016-10-31, by jebradshaw [Mon, 31 Oct 2016 17:54:50 +0000] rev 8

added operator functions for simplified parameter passing


Improved documentation, printf output and led toggle

2016-12-14, by jebradshaw [Wed, 14 Dec 2016 12:49:53 +0000] rev 7

Improved documentation, printf output and led toggle


Fixed bool error in set_mode function 20161212;

2016-12-12, by jebradshaw [Mon, 12 Dec 2016 20:10:59 +0000] rev 6

Fixed bool error in set_mode function 20161212;


Overloaded MotCon class constructor for interfacing with motor control driver IC's with one or two direction pins. Mutator functions for controlling dynamic breaking and free-wheeling break modes.; J Bradshaw 20161018

2016-10-18, by jebradshaw [Tue, 18 Oct 2016 11:32:36 +0000] rev 5

Overloaded MotCon class constructor for interfacing with motor control driver IC's with one or two direction pins. Mutator functions for controlling dynamic breaking and free-wheeling break modes.; J Bradshaw 20161018


updated API documentation

2016-05-19, by jebradshaw [Thu, 19 May 2016 13:17:10 +0000] rev 4

updated API documentation


Added overloaded mot_control function for reversing the motor direction in software.

2016-05-19, by jebradshaw [Thu, 19 May 2016 12:36:45 +0000] rev 3

Added overloaded mot_control function for reversing the motor direction in software.


Simple motor control library for generating PWM and a direction signal for a motor driver board

2016-05-23, by jebradshaw [Mon, 23 May 2016 19:06:31 +0000] rev 2

Simple motor control library for generating PWM and a direction signal for a motor driver board