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

News, rumors, and other broad discussion topics.
Post Reply
photon-1
Posts: 14
Joined: 02 Dec 2010, 14:29
Location: London, Uk
Contact:

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

Post 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.
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

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

Post 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
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

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

Post 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.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests