TASKS

Hi all

Is it possible to add parallel tasks into the C code ?
like

task1:
do something1
goto task1

task2 :
do something2
goto task2

those task will run on parallel effectively by time sharing
along with the regular C code commands like if then else and for( , , )

Please look at the PICAXE Chip Sizes - What is PICAXE - PICAXE

Thanks
Elico

I think there is a pseudo-paralleling library around for the Arduino, but personally I wouldn't go there.

The closes you will really get on a chip like the 328P is interrupts.

The usual way of handling multiple tasks is to use a Finite State Machine and avoid delay() like the plaque.

Please look at the

Are you in the habit of going around to Ford dealers and putting up Chevy posters, too?

There is no OS running on these chips, so there is nothing to do anytime of thread/process scheduling. As majenko said, there is something out there, but I don't know how well it works.

You best way to achieve "pseduo-paralelling" on the Arduino, is by writing non-blocking code.

At a fundamental level, the answer is really no - the Arduino has a single core, so there is no opportunity for real parallelism. Just as with a single core PC, you can fake it to some extent but there is no OS support to make it easy. For many arduino applications, the processor speed is sufficient that it can appear to be doing things in parallel.

Is this an abstract enquiry or do you have a specific scenario in mind?

elico:
Hi all
Is it possible to add parallel tasks into the C code ?

Sigh.

Every few months Elico posts a similar question:

elico:
Thanks
Is there a way to write parallel functions/statements in ARDUINO ide ?

Elico

...

elico:
Hi all

what is unique for arduino for linux ?
http://arduino.cc/en/Main/Software

Does it supprt linux things like multi threading ?
Eliko

...

elico:
Hi all

I sit rally necessary to use RTOS functions for real time solutions , or is it better to
write c code based on combination of polling and interrupts routines ?

Please explain with some example/s .

Thanks in advance
Elico

I've asked this before, and I'll ask it again. What is your project? Why do you want "parallel tasks"?

elico:
Please look at the PICAXE Chip Sizes - What is PICAXE - PICAXE

What do PICAXE chip sizes have to do with anything, on an Arduino forum?

I want to implement a PLC , with a parallel task for each output .

Elico

I want to implement a PLC , with a parallel task for each output .

Then, maybe a pickaxe is right for you. An Arduino isn't.

elico:
I want to implement a PLC , with a parallel task for each output .

Why? Speed? The overhead of your multitasking mechanism would make it slower. To try to get all outputs switching at the same time? Use shift registers.

elico:
Hi all

Is it possible to add parallel tasks into the C code ?
like

task1:
do something1
goto task1

task2 :
do something2
goto task2

those task will run on parallel effectively by time sharing
along with the regular C code commands like if then else and for( , , )

Please look at the PICAXE Chip Sizes - What is PICAXE - PICAXE

Thanks
Elico

The pixaxe chip is just a single core PIC chip just like any of the AVR chips the arduino board uses. The abstracted picaxe 'tasks' are no more true parallel computing then any arduino sketch could be with proper use of program structure and flow and or using interrupts.

Your wanting to use a crutch or magic bullet, rather then learn the underling principles of programming algorithms need to accomplish the goals of your application. The arduino can accomplish what is required, it just needs a programmer to make it happen.

Lefty

If you absolutely have to have parallel execution, perhaps the Parallax Propeller would suit you. Of course, you'll still have an issue if you need more than eight tasks, but up until then, it might give you what you need.

elico:
I want to implement a PLC , with a parallel task for each output .

Elico

But why? You clearly want parallel tasks, you've mentioned them often enough over the years. But why do you want them?

Let me put it this way, if you really want to make a fish feeder, and you want to turn on the lights to the aquarium "at the same time" that you feed the fish, I'm sure the fish won't notice if the lights come on a millisecond before they are fed. So parallel tasks aren't really required there.

elico wrote:
I want to implement a PLC , with a parallel task for each output

So, a separate task for each output on a PLC, wow, how many outputs are you wanting I wonder?
Why stop there, go for separate tasks for the inputs too, and for all the analogues.
I guess you'll end up with quite a large box of electronics?

I don't see the point of it at all, maybe you can enlighten us with your project as Nick points out.

For PLC jobs I'll stick with the bigger guys, like Siemens S7 or Rockwell Automation's Control Logix systems, where I know when all the I/O is performed.

P.S. I guess that was 'snap' Nick, with the post time.

Even commercial PLCs don't have true parallel 'tasks', just the illusion of such. A PLC performs three fundamental sequential steps within it's embedded micro:

1 Scan all inputs
2 Compute all ladder line diagrams
3 Set all outputs
4 Go to 1

Lefty

elico:
Please look at the PICAXE Chip Sizes - What is PICAXE - PICAXE

The PICAXE manual says (page 62):

However the new PICAXE microcontroller educational range (M2 parts) can now simulate ‘parallel processing’ by repeatedly switching between a number of tasks at very high speed.

My emphasis. It simulates parallel processing. Judging by the description you have co-routines which allow multiple threads which appear to run at once. But they don't of course. As the manual says:

A PICAXE microcontroller is a single core controller and can therefore only process one instruction at any one time.

My emphasis again.

Moving on:

Limitations.

Parallel tasking is primarily designed for simpler educational projects. It works very well using simple input/output commands and programs that contain pause commands within the tasks. This covers the vast majority of school educational projects.

Parallel tasking is not designed for complex parallel tasks with each task trying to use different advanced features simultaneously e.g. trying to use serial / infra-red / 1-wire communication protocols simultaneously in 3 different tasks! In this situation the end user should use a single core program to process each advanced feature in turn.

My emphasis once again.

Elico, maybe read this? http://www.gammon.com.au/blink

Forget about getting an Arduino, or a PICAXE, that magically does "everything in parallel". It ain't gonna happen.