Page 1 of 1

multi-threading possible on nxt but not arduino; why?

Posted: 12 Apr 2012, 15:21
by photon-1
So I just wandered why it's possible to perform multi-threading/parallel programming on the nxt (e.g. using the tasks in nxc) but this is not possible on arduino (or is it?).

Has the "task" system been implemented in nxc through 'software/programming tricks' or is it to do with the hardware?

p.s. on a completely separate note:
If anyone can help with this problem I'm having with an nxt-arduino robot which i posted on the arduino forum (since its more an issue with the arduino) I would be grateful.

http://arduino.cc/forum/index.php/topic,101091.0.html

Thanks.

Re: multi-threading possible on nxt but not arduino; why?

Posted: 12 Apr 2012, 15:27
by inxt-generation

Re: multi-threading possible on nxt but not arduino; why?

Posted: 12 Apr 2012, 15:57
by mightor
photon-1 wrote:So I just wandered why it's possible to perform multi-threading/parallel programming on the nxt (e.g. using the tasks in nxc) but this is not possible on arduino (or is it?).
The NXT's firmware implements multi-tasking by effectively scheduling different tasks to make use of the processor. So basically, if you have 8 tasks, they each get a tiny amount of time to do their thing before they're suspended, allowing the next task to use the CPU (and other resources). So it's a bit like a round-robin effect.

Has the "task" system been implemented in nxc through 'software/programming tricks' or is it to do with the hardware?
It's all done in software, like on most single-processor systems. Even on multi-processor systems you still use the standard scheduling method for allowing the apparent running of many processes or tasks simultaneously.

You should check out http://www.state-machine.com/arduino/index.php, which is an awesome framework for implementing event driven systems and multi-tasking. You can also chose to use a small RTOS on your chip: http://www.femtoos.org/index.html. The QP framework (in the first link) also has a small RTOS if you chose to use the baremetal instead of the Arduino Framework.

- Xander

Re: multi-threading possible on nxt but not arduino; why?

Posted: 12 Apr 2012, 17:49
by mattallen37
NXT multitasking seems to have already been explained, so I'll only mention Arduino multitasking. The Arduino framework doesn't have support for multitasking in general, but there is a way you can sort of trick it into simple multitasking. You need to use timer interrupts. This is what I did for my PFIR library, so that it could transmit IR messages while still running the main task. However, it can get extremely complicated to implement it all in the user-program. In the case of my PFIR library, I only needed to have one extra task running along side of the main task. I had to completely manually add the return points and also the re-triggering. If you want to take a look at my implementation, here is a page that explains the user-side, and also has a link to the download.