/* Software for Ebot 7/10/01 Alex Brown rbirac@home.com saved as: E:\xxxx written in ImageCraft ICC12 C for the Adapt912 board (68HC912B32) This code extract shows how wheel encoders are run using interrupts */ /* I/O usage 13 PT0 Drive wheel encoder input A Left 12 PT1 Drive wheel encoder input A Right 11 PT2 Drive wheel encoder input B Left 10 PT3 Drive wheel encoder input B Right */ //Global Variable definitions //Encoders long int odomL; //raw count left encoder long int odomR; //raw count right encoder //--------------------------------------------------------------------------- //Drive wheel encoder interrupt Left (TC0) #pragma interrupt_handler odom_handler_L() void odom_handler_L(void) { TFLG1 = 0x01; //Reset timer 0 interrupt flag if (PORTT & 0x04) odomL = odomL + 1; //increment raw encoder count else odomL = odomL - 1; } #pragma abs_address:0xF7EE //jump table address void (*odom_isrL[])() = {odom_handler_L}; #pragma end_abs_address //--------------------------------------------------------------------------- //Drive wheel encoder interrupt Right (TC1) #pragma interrupt_handler odom_handler_R() void odom_handler_R(void) { TFLG1 = 0x02; //Reset timer 1 interrupt flag if (PORTT & 0x08) odomR = odomR - 1; //increment raw encoder count else odomR = odomR + 1; } #pragma abs_address:0xF7EC //jump table address void (*odom_isrR[])() = {odom_handler_R}; #pragma end_abs_address /*--------------------------------------------------------------------------- Initialization of timer for encoders TC0 used for drive wheel encoder left capture (chan A) TC1 used for drive wheel encoder right capture (chan A) TC2 used for drive wheel encoder left (direction, chan B) TC3 used for drive wheel encoder right (direction, chan B) */ void timerinit() { TMSK1 = 0x03; //enable timer interrupts TC0 & TC1 TMSK2 = 0x2B; //disable overflow intr, enable pull ups, //prescale = 8, reset after OC7 compare TCTL4 = 0x05; //TC0 & TC1 to cap on rising edge TSCR = 0x80; //enable timer } main() { timerinit(); //initialize timer //--------------------------------------------------------------------------- // Control program while (1) { /* Do any tasks in background mode. All of my control programs run under a real time interrupt driven program, not shown.*/ }; return(0); }