Program for testing the motor with SY202 connection from the application board to the L298 motor driver board.

Dependencies:   MotCon mbed

SY202 Motor Test Program

This program exercises a DC motor driver using pins 23, 24, and 25 as (PWM, DIR1, DIR2 respectively) motor control signals on the mbed application board. These pins are also tied to the on-board RGB LED.

/media/uploads/jebradshaw/lab_05_-_actuation.pdf - PDF of the Actuator Lab

Committer:
jebradshaw
Date:
Thu Mar 01 13:19:16 2018 +0000
Revision:
1:78b320721b2d
Parent:
0:0da08bb74f7b
Added LCD output for Application board for SY202 motor test program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jebradshaw 0:0da08bb74f7b 1 // J. Bradshaw 20190228
jebradshaw 0:0da08bb74f7b 2 // Program for testing Motor control port on SY202 application board to L293 interface
jebradshaw 0:0da08bb74f7b 3 #include "mbed.h"
jebradshaw 0:0da08bb74f7b 4 #include "MotCon.h" //uses the MotCon.h library for controlling the motor ports
jebradshaw 1:78b320721b2d 5 #include "C12832_lcd.h"
jebradshaw 0:0da08bb74f7b 6
jebradshaw 0:0da08bb74f7b 7 //PC serial connection
jebradshaw 0:0da08bb74f7b 8 Serial pc(USBTX, USBRX); //tx, rx via USB connection
jebradshaw 0:0da08bb74f7b 9 DigitalOut led(LED1);
jebradshaw 1:78b320721b2d 10 MotCon m1(p23, p24, p25); //uses p23 for pwm and p24 and p25 for direction (complimentary)
jebradshaw 1:78b320721b2d 11 C12832_LCD lcd;
jebradshaw 0:0da08bb74f7b 12
jebradshaw 0:0da08bb74f7b 13 //------------ Main ------------------------------
jebradshaw 0:0da08bb74f7b 14 int main() {
jebradshaw 1:78b320721b2d 15 wait(.2); //short delay
jebradshaw 1:78b320721b2d 16 lcd.cls();
jebradshaw 1:78b320721b2d 17 lcd.locate(0,0);
jebradshaw 1:78b320721b2d 18 lcd.printf("SY202 Motor Test");
jebradshaw 1:78b320721b2d 19
jebradshaw 0:0da08bb74f7b 20 pc.baud(921600);//fast baud rate for USB PC connection
jebradshaw 0:0da08bb74f7b 21 while(1) {
jebradshaw 0:0da08bb74f7b 22 //iterate through 2*pi cycles in .01 increments
jebradshaw 0:0da08bb74f7b 23 for(float cycle=0;cycle<3.14159*2.0;cycle+=.01){
jebradshaw 0:0da08bb74f7b 24 float m1_dc = .85*sin(cycle);
jebradshaw 0:0da08bb74f7b 25 m1.mot_control(m1_dc);
jebradshaw 1:78b320721b2d 26
jebradshaw 1:78b320721b2d 27 lcd.locate(0,8);
jebradshaw 1:78b320721b2d 28 lcd.printf("cycle=%.2f dc=%7.2f \n", cycle, m1_dc);
jebradshaw 1:78b320721b2d 29
jebradshaw 1:78b320721b2d 30 lcd.locate(0,16);
jebradshaw 1:78b320721b2d 31 if(m1_dc > 0.001)
jebradshaw 1:78b320721b2d 32 lcd.printf("Forward\n");
jebradshaw 1:78b320721b2d 33 else if(m1_dc < 0.001)
jebradshaw 1:78b320721b2d 34 lcd.printf("Reverse\n");
jebradshaw 1:78b320721b2d 35
jebradshaw 0:0da08bb74f7b 36 pc.printf("cycle=%.3f m1_dc = %.2f \r\n", cycle, m1_dc);
jebradshaw 0:0da08bb74f7b 37 wait(.01); //determines period
jebradshaw 0:0da08bb74f7b 38 led = !led; //toggle LED1 to indicate activity
jebradshaw 0:0da08bb74f7b 39 }
jebradshaw 0:0da08bb74f7b 40 }
jebradshaw 0:0da08bb74f7b 41 }