18M2 4 tasks in parallel

airton65

Member
Hi,

In Silicon Chip magazine it has a bit of a speil on the upcoming 18M2. It states that the 18M2 can now run 4 tasks in parallel. I was wondering what this means? Does it mean that it can run four programs at the same time?

Thanks

Tony
 

hippy

Ex-Staff (retired)
It depends on what you mean by "programs". If you have a loop which toggles a LED at a certain rate, you will be able to add more loops which do the same and they will all appear to run at the same time, flashing their respective LED's at whatever rate their loop dictates.

Because all the loops are part of a single program the terminology is usually "task" for each loop rather program.

There are limitations to what can be run in parallel. With LED loops and similar there should be no problem but if one of the tasks has to 'block', wait for something, then while doing that all tasks will stop. Like juggling cooking with four pans on a stove you can do that, handle all four 'at once', but if you decide to count passing cars for some reason you have to leave them all while doing with that. Unlike pans which will boil over, PICAXE tasks will simply stop until you've done your counting.
 

airton65

Member
Got it

Thanks for that guys, I think I understand, when they become available I will get one and have a play.

Thanks

Tony
 

westaust55

Moderator
Picaxe 18m2

Hi,

In Silicon Chip magazine it has a bit of a speil on the upcoming 18M2. It states that the 18M2 can now run 4 tasks in parallel. I was wondering what this means? Does it mean that it can run four programs at the same time?

Thanks

Tony
More info in post 5 of this thread:
http://www.picaxeforum.co.uk/showthread.php?t=13938

Technicals posted flyer does state:
The 18M2 can now run four separate tasks in parallel. .., and
Multi-tasking is also supported in BASIC program listings.
 

manuka

Senior Member
Since this X4 query has arisen, it may be worth my asking if the glib "256x4" remarks I've added at the earlier PICAXE family features table is strictly valid. If not, what may be a better way of expressing this? Stan
 

Technical

Technical Support
Staff member
18M2's have 2048 bytes of program memory, of which you can split however you want. Any task can be any length, within the total, so it is not 256x4. However your table shows data memory, which is separate and so just '256 + i2c' anyway on the 18M2.

Separate tasks are just typed at any point in the program with the predefined start0:, start1:, start2:, start3: labels. The first task is the default 'task 0', you could use a start0: label if you wanted but that is implied at the start of the program anyway.
The compiler automatically works out where the startX labels are so that all tasks start at the same time when the program commences.

e.g.

Code:
main:
       high b.0
       pause 500
       low b.0
       pause 500
       goto main
 
start1:
       high b.1
       pause 5000
       low b.1
       pause 5000
       goto start1
 
 
start2:
       high b.2
       pause 1000
       low b.2
       pause 1000
       goto start2
 
Last edited:

manuka

Senior Member
Thanks Technical- that's now looking very lucid, & I'm sure others will appreciate the insights too. Hippy has set the tone, but I'm also pondering real world comparisons,& engine starting on a 4 turbine Jumbo Jet & even "one man band" analogies spring to mind. Perhaps however operating a car may be more apt- it must first be keyed in the ignition, then radio, lights, engine,wipers can independently run.
 

MartinM57

Moderator
Looks like fun :)

Presumably all b variables are common to all startN blocks ??
GOTO's from one startN block to another ?? Could be lots of fun there..
Common GOSUB calls in each startN block (re-entrant code anyone?) ?? Where would the subroutine be? Even more fun...

See, I'm getting all excited (well a little bit) about an unreleased chip with very little information in the public domain :D
 

hippy

Ex-Staff (retired)
It's a firmware feature so not something which could be applied to other PICAXE as they are.

That's not entirely true in the strictest sense, it is possible to write PICAXE code which can multi-task to some extent and the compilers could handle that behind the scenes, but as it requires PICAXE variables plus SFR Ram or scratchpad to be used for that multi-tasking you effectively end up with multi-tasking but no PICAXE. There would be such a huge overhead in task switching, massively reduced execution speed and loss of program code space to accommodate it that it's not a sensible nor practical possibility.

http://www.picaxeforum.co.uk/showthread.php?t=5884

What the 18M2 does is place the 'primitives' of task switching into the firmware where they execute at native PICmicro speeds while ensuring operation of commands cater for practical task switching so it becomes viable.
 

nwright

New Member
Maybe an ignorant question, but will the M2 allow concurrent use of pwmout and servo commands ?
ie. will it be able to make better use of internal timers
Thanks
 

teddy7

Member
Hi,

In Silicon Chip magazine it has a bit of a speil on the upcoming 18M2. It states that the 18M2 can now run 4 tasks in parallel. I was wondering what this means? Does it mean that it can run four programs at the same time?

Thanks

Tony
Tony, I have some SPECS. on the 18M2, do in Jul 2010
Have a look: http://elecurls.tripod.com/picaxe-sum.htm

-teddy
 

teddy7

Member
18M2's have 2048 bytes of program memory, of which you can split however you want. Any task can be any length, within the total, so it is not 256x4. However your table shows data memory, which is separate and so just '256 + i2c' anyway on the 18M2.

Separate tasks are just typed at any point in the program with the predefined start0:, start1:, start2:, start3: labels. The first task is the default 'task 0', you could use a start0: label if you wanted but that is implied at the start of the program anyway.
The compiler automatically works out where the startX labels are so that all tasks start at the same time when the program commences.

e.g.

Code:
main:
       high b.0
       pause 500
       low b.0
       pause 500
       goto main
 
start1:
       high b.1
       pause 5000
       low b.1
       pause 5000
       goto start1
 
 
start2:
       high b.2
       pause 1000
       low b.2
       pause 1000
       goto start2
Technical, I'm not sure what my chart is suppose to show since the info your
giving conflicts with the 18M2 chart that's online. Memory: 2048, I had 1800.
Also 256x4 is shown, but you say that it is still: 256+I2C. I' not trying to give
you a hard time, just trying to make my chart as accurate as possible.

-teddy
 

Technical

Technical Support
Staff member
2048 bytes of program memory
256 bytes of data memory (+i2c as an option)

Lines of memory is like asking how long a piece of string is. 2048 bytes is the same as the current 18X capacity - anywhere between 600 and 1800 lines of code depending on which commands are used, as all commands take different amounts of space. Use 'tune' or 'serout' on every line and you will also get less than 600!
 
Last edited:

teddy7

Member
2048 bytes of program memory
256 bytes of data memory (+i2c as an option)

Lines of memory is like asking how long a piece of string is. 2048 bytes is the same as the current 18X capacity - anywhere between 600 and 1800 lines of code depending on which commands are used, as all commands take different amounts of space. Use 'tune' or 'serout' on every line and you will also get less than 600!
Thanks for the info from Technical. I have changed things back the way they were.
-teddy
 
Top