R2 Project Log - Motors
After a minor slip up with a probe killed my primary R2 bot (shorted VBATT to 5VCC, bye bye processor and drive chips) I’ve tonight soldered up another of my spare R2 boards to take over the mantle.
And the motor drive code i was debugging at the time works!
Tomorrow, i add a battery monitor circuit and the sensors, so i’ll finally have al the major electronic systems tested and good to go ready for the motor mounts.
#define F_CPU 1000000UL #include < avr/io.h> #include < util/delay.h> #include < avr/interrupt.h> #include "r2.h" int main(void) { // Activate all the LEDs, set their pins to output bit_set(LED_WHITE_L_DDR, LED_WHITE_L_BIT); bit_set(LED_WHITE_R_DDR, LED_WHITE_R_BIT); bit_set(LED_RED_L_DDR, LED_RED_L_BIT); bit_set(LED_RED_R_DDR, LED_RED_R_BIT); bit_set(LED_YELLOW_FL_DDR, LED_YELLOW_FL_BIT); bit_set(LED_YELLOW_FR_DDR, LED_YELLOW_FR_BIT); bit_set(LED_YELLOW_RL_DDR, LED_YELLOW_RL_BIT); bit_set(LED_YELLOW_RR_DDR, LED_YELLOW_RR_BIT); // Activate the motor's control lines bit_set(MOTOR_R_ENABLE_DDR, MOTOR_R_ENABLE_BIT); bit_set(MOTOR_R_PHASE_DDR, MOTOR_R_PHASE_BIT); bit_set(MOTOR_L_ENABLE_DDR, MOTOR_L_ENABLE_BIT); bit_set(MOTOR_L_PHASE_DDR, MOTOR_L_PHASE_BIT); // turn on the motors bit_set(MOTOR_R_ENABLE_PORT, MOTOR_R_ENABLE_BIT); bit_set(MOTOR_R_PHASE_PORT, MOTOR_R_PHASE_BIT); bit_set(MOTOR_L_ENABLE_PORT, MOTOR_L_ENABLE_BIT); bit_set(MOTOR_L_PHASE_PORT, MOTOR_L_PHASE_BIT); // turn on the white and red LEDs bit_set(LED_WHITE_L_PORT, LED_WHITE_L_BIT); bit_set(LED_WHITE_R_PORT, LED_WHITE_R_BIT); bit_set(LED_RED_L_PORT, LED_RED_L_BIT); bit_set(LED_RED_R_PORT, LED_RED_R_BIT); // enable internal pullup on PD0 bit_set(PORTD, BIT(0)); // enable external interrupts EIMSK = BIT(INT0) | BIT(INT1); // enable global interrupts sei(); // loop forever while (1) { delayms(500); } return 0; } // delay for up to 65k milliseconds void delayms(uint16_t millis) { // loop, delaying 1ms each iteration while ( millis ) { _delay_ms(1); millis--; } } // this catches the Interrupt sent from pin INT0 ISR(INT0_vect) { //Turn everything off bit_clear(LED_WHITE_L_PORT, LED_WHITE_L_BIT); bit_clear(LED_WHITE_R_PORT, LED_WHITE_R_BIT); bit_clear(LED_RED_L_PORT, LED_RED_L_BIT); bit_clear(LED_RED_R_PORT, LED_RED_R_BIT); bit_clear(MOTOR_R_ENABLE_PORT, MOTOR_R_ENABLE_BIT); bit_clear(MOTOR_R_PHASE_PORT, MOTOR_R_PHASE_BIT); bit_clear(MOTOR_L_ENABLE_PORT, MOTOR_L_ENABLE_BIT); bit_clear(MOTOR_L_PHASE_PORT, MOTOR_L_PHASE_BIT); // loop forever, flashing our indicators. while(1) { bit_flip(LED_YELLOW_FL_PORT, LED_YELLOW_FL_BIT); bit_flip(LED_YELLOW_FR_PORT, LED_YELLOW_FR_BIT); bit_flip(LED_YELLOW_RL_PORT, LED_YELLOW_RL_BIT); bit_flip(LED_YELLOW_RR_PORT, LED_YELLOW_RR_BIT); delayms(500); } }


August 17th, 2008 at 7:49 am
hey,
i have been keeping track of R2 project since i m kinda trying to build my own micromouse… pardon me for all dumb queries as my electronics know-how is not quite good. i wanted to know what regulator are you using on R2 (since the drawings dont mention it & pics are not that clear) since it has 5 pins i guess it must be a switching regulator. also i would like to know which one did you use on your previous mouse - Rooter… …the green pcb thingy
thanx
reagrds
erle
August 18th, 2008 at 4:34 pm
Hi Erle!
The Switching regulator i use on R2 is a TL2575 from TI, It is pin-and feature compatible with the more common LM2575, and needs just three external components!
On R1, i used another TI module, the pth08231w module, which is slightly simpler (only needs a pair of caps), but takes up more board space.
I’ll try to tidy up and post the schematics tonight for R2.
Any other questions?