Program for testing the motor with SY202 connection from the application board to the L298 motor driver board.
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
main.cpp@0:0da08bb74f7b, 2018-02-28 (annotated)
- Committer:
- jebradshaw
- Date:
- Wed Feb 28 14:59:53 2018 +0000
- Revision:
- 0:0da08bb74f7b
- Child:
- 1:78b320721b2d
mbed SY202 motor control test on p23 (PWM), p24 (DIR1), and p25 (DIR2)
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:0da08bb74f7b | 5 | |
jebradshaw | 0:0da08bb74f7b | 6 | //PC serial connection |
jebradshaw | 0:0da08bb74f7b | 7 | Serial pc(USBTX, USBRX); //tx, rx via USB connection |
jebradshaw | 0:0da08bb74f7b | 8 | DigitalOut led(LED1); |
jebradshaw | 0:0da08bb74f7b | 9 | MotCon m1(p23, p24, p25); //uses p23 for pwm and p24 and 35 for direction (complimentary) |
jebradshaw | 0:0da08bb74f7b | 10 | |
jebradshaw | 0:0da08bb74f7b | 11 | //------------ Main ------------------------------ |
jebradshaw | 0:0da08bb74f7b | 12 | int main() { |
jebradshaw | 0:0da08bb74f7b | 13 | pc.baud(921600);//fast baud rate for USB PC connection |
jebradshaw | 0:0da08bb74f7b | 14 | while(1) { |
jebradshaw | 0:0da08bb74f7b | 15 | //iterate through 2*pi cycles in .01 increments |
jebradshaw | 0:0da08bb74f7b | 16 | for(float cycle=0;cycle<3.14159*2.0;cycle+=.01){ |
jebradshaw | 0:0da08bb74f7b | 17 | float m1_dc = .85*sin(cycle); |
jebradshaw | 0:0da08bb74f7b | 18 | m1.mot_control(m1_dc); |
jebradshaw | 0:0da08bb74f7b | 19 | |
jebradshaw | 0:0da08bb74f7b | 20 | pc.printf("cycle=%.3f m1_dc = %.2f \r\n", cycle, m1_dc); |
jebradshaw | 0:0da08bb74f7b | 21 | wait(.01); //determines period |
jebradshaw | 0:0da08bb74f7b | 22 | led = !led; //toggle LED1 to indicate activity |
jebradshaw | 0:0da08bb74f7b | 23 | } |
jebradshaw | 0:0da08bb74f7b | 24 | } |
jebradshaw | 0:0da08bb74f7b | 25 | } |