Society of Robots - Robot Forum

Software => Software => Topic started by: dellagd on March 13, 2009, 02:02:08 PM

Title: programming code
Post by: dellagd on March 13, 2009, 02:02:08 PM
is there any way the ATmega8 can multitask?
so it can drive wale taking input from IR LED on both of its sides so when an LED detects something, it will stop and and scan w/ a sonar(just an example)?

sorry I am new to robotics programming and this question is probably noobish.

please help, the science fair is on April 1st!
Title: Re: programming code
Post by: airman00 on March 13, 2009, 02:25:40 PM
listen....
controlling these  "stuff" takes less than half a second. In reality it is not doing two things at once, but since its going so fast, to the human eye it is doing it all in the same time.
Title: Re: programming code
Post by: chelmi on March 13, 2009, 02:36:35 PM
It depends on what you mean by multitask. I you want to run two task in parallel you can fake it using interrupts. But the atmega8 is a single core processor, it execute 1 instruction at a time so when your IR detect code runs, the driver code will stop.

so maybe something like this would work for you:
- motor driving code in main
- every 500ms check IR LED. Setup a timer to invoke your routine every 500ms but you have to keep this as short as possible since during the execution of the interrupt handler the main code is stopped.

more info about AVR timers: http://members.shaw.ca/climber/avrtimers.html (http://members.shaw.ca/climber/avrtimers.html)

Title: Re: programming code
Post by: dellagd on March 13, 2009, 03:13:42 PM
ok thanks