Author Topic: How do i time an action?  (Read 1756 times)

0 Members and 1 Guest are viewing this topic.

Offline ioannisTopic starter

  • Jr. Member
  • **
  • Posts: 10
  • Helpful? 0
How do i time an action?
« on: February 27, 2008, 10:50:23 AM »
How do i go about timing an action? for example i want the robot to go back for 2 seconds and then carry on its usual actions?

I am using the Atmega8

Can anyone help?

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: How do i time an action?
« Reply #1 on: February 27, 2008, 11:12:41 AM »
Figure out how many clock cycles are wasted in 2 seconds, than write a program to waste them (piclist.org had a generator for pic and atmel).

Then, order your motors to go backwards, and run the code to waste 2 seconds.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline hazzer123

  • Supreme Robot
  • *****
  • Posts: 460
  • Helpful? 3
Re: How do i time an action?
« Reply #2 on: February 27, 2008, 11:21:07 AM »
Use hardware timers.
A timer counts up every cycles of the MCU, and then when it loops round from the highest number to 0, it will interrupt the current processes of the MCU, to carryout an interrupt routine. This can be used to create a 'clock' variable.

Eg you could get the timer to interrupt every millisecond, and when it interrupts, increment the clock variable.

Then you just do something like -

Code: [Select]
pseudo code

resetClock();

while (clock < 2000 milliseconds) {
       go backwards
}


Heres a page that might help - http://dlangenberg.googlepages.com/atmega8timers
« Last Edit: February 27, 2008, 11:22:13 AM by hazzer123 »
Imperial College Robotics Society
www.icrobotics.co.uk

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: How do i time an action?
« Reply #3 on: February 27, 2008, 12:45:22 PM »
of course, using timers - as hazzer123 said - is a better method, since no cycles are wasted - you can do obstacle avoidance, terrain map or any other computation as needed, but you will need a better understanding of your mcu.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,666
  • Helpful? 169
    • Society of Robots
Re: How do i time an action?
« Reply #4 on: March 09, 2008, 08:51:39 AM »
or if you are using the $50 Robot and do not care about wasted cycles, do this:

delay_cycles(65500);//add a few of these till you get the delay you want

 


Get Your Ad Here