ECE476's Motors Lab
By John Stang





The actual basic software design is quite simple for this lab. Within the while(1) loop in main, I ended up making an if/else block which would continuously poll the sensors to see which one was on and then compare it to a variable that was keeping track of the next sensor. If the comparison passed, the car would be over the correct sensor and I would have the code update the cars status. One sensor would be used to update the lap counter and the others would change one variable that controls the length of the PWM. Here’s a basic state diagram below.


Once I had the code set up to detect sensors and vary the speed, all I had to do was create a timer to keep track of the time the car takes to run 5 laps. This was a simple exercise using Timer0 and its overflow interrupt. I set the prescalar of Timer0 to count at a rate that would cause Timer0 to overflow once every millisecond. From this, I set up a few conditionals that would count hundredths of seconds and seconds and display these on the second line of the LCD display. On the first line, I displayed the lap count which would increment each time the car passed the start/stop line. Here is the final code that I wrote for this lab.


Copyright December 2003
For problems or questions regarding this web contact
Updated: 12-15-03