David's dead reckoning code for the LVBots competition on March 6th. Uses the mbed LPC1768, DRV8835, QTR-3RC, and two DC motors with encoders.

Dependencies:   PololuEncoder Pacer mbed GeneralDebouncer

Committer:
DavidEGrayson
Date:
Thu Feb 20 23:33:45 2014 +0000
Revision:
6:89a39870e23d
Parent:
5:01ad080dc4fa
Child:
7:85b8b5acfb22
Got high-resolution 20 kHz PWM.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DavidEGrayson 4:1b20a11765c8 1 #include <mbed.h>
DavidEGrayson 4:1b20a11765c8 2
DavidEGrayson 4:1b20a11765c8 3 static PwmOut motor1Pwm(p26);
DavidEGrayson 4:1b20a11765c8 4 DigitalOut motor1Dir(p25);
DavidEGrayson 4:1b20a11765c8 5
DavidEGrayson 4:1b20a11765c8 6 static PwmOut motor2Pwm(p24);
DavidEGrayson 4:1b20a11765c8 7 DigitalOut motor2Dir(p23);
DavidEGrayson 4:1b20a11765c8 8
DavidEGrayson 4:1b20a11765c8 9 void motors_init()
DavidEGrayson 4:1b20a11765c8 10 {
DavidEGrayson 4:1b20a11765c8 11 motor1Pwm.period_us(50);
DavidEGrayson 4:1b20a11765c8 12 motor2Pwm.period_us(50);
DavidEGrayson 5:01ad080dc4fa 13 motor1Pwm.pulsewidth_us(20);
DavidEGrayson 5:01ad080dc4fa 14 motor2Pwm.pulsewidth_us(20);
DavidEGrayson 5:01ad080dc4fa 15
DavidEGrayson 5:01ad080dc4fa 16 LPC_PWM1->MR0 = 1200; // Set the period
DavidEGrayson 5:01ad080dc4fa 17 LPC_PWM1->MCR = (1 << 1); // Reset PWMTC when it is equal to MR0.
DavidEGrayson 4:1b20a11765c8 18 }
DavidEGrayson 4:1b20a11765c8 19
DavidEGrayson 4:1b20a11765c8 20 void motors_speed_set(int16_t motor1_speed, int16_t motor2_speed)
DavidEGrayson 4:1b20a11765c8 21 {
DavidEGrayson 6:89a39870e23d 22 LPC_PWM1->MR1 = motor1_speed;
DavidEGrayson 6:89a39870e23d 23 LPC_PWM1->MR3 = motor2_speed;
DavidEGrayson 4:1b20a11765c8 24 }