08M2 Parallel processing help needed

tarantulataramasalata

Senior Member
Hi - I'm trying to get some parallel processing going, but struggling. Any help appreciated!

C3 is a PTM switch, C1 and C2 are LEDs. The circuit works with a single program - am I doing something wrong here?

start0:
do
if pinC.3 = 1 then
low C.1
high C.2
endif
loop
stop

start1:
do
high C.1
loop
stop
 

Technical

Technical Support
Staff member
The low C.1 and high C.1 in each task will be constantly 'fighting' each other and so you won't see much change, particularly without any pauses in the program. What were you expecting to happen?
 

techElder

Well-known member
As Technical says, the details are important.

Assign start0 to your left hand; start1 to your right hand. Raise a finger for HIGH C.1 on each hand etc. Your hands are parallel processing.

Now put one of the C.1 fingers on top of the opposite C.1 finger. See what happens?

Works the same way in the PICAXE, but how do you want it to work?
 

tarantulataramasalata

Senior Member
Thanks for the help!
As I understand it, Start1 puts C1 high = red light on.
Start0 checks for the input C3 (push switch), which makes C1 low (red off) and C2 high (green on).

I can understand that Start1 will counteract Start0 - sorry if it's obvious, but how do I get this to work?

Are there any exemplar programs somewhere?
 

tarantulataramasalata

Senior Member
Sorry for still not understanding. I don't really mind what the circuit does, I'm just trying to get a parallel program running!
I can't find any examples of code anywhere that I can look at.
Thanks again.
 

hippy

Technical Support
Staff member
I'm just trying to get a parallel program running!
I can't find any examples of code anywhere that I can look at.
Here's a program which will flash both LED's at different rates -
Code:
#Picaxe 08M2

Start0:
  Do
   Toggle C.1
   Pause 500
  Loop

Start1:
  Do
   Toggle C.2
   Pause 700
  Loop
And here's a program which will keep flashing the LED on C.1 while also monitoring and reporting on button pushes on C.3 -
Code:
#Picaxe 08M2
#Terminal 4800

Start0:
  Do
   Toggle C.1
   Pause 500
  Loop

Start2:
  Pause 2000
  SerTxd( "Looking for button pushes...", CR, LF )
  Do
    Do : Loop Until pinC.3 = 1 : SerTxd( "Pushed " )
    Do : Loop Until pinC.3 = 0 : SerTxd( "Released", CR, LF )
  Loop
You might need to swap the =1 and =0 around depending on how you have your hardware wired.

You can also add in the Start1 code of the first to flash both LED's while monitoring for button pushes.
 
Last edited:

techElder

Well-known member
Typically you would be monitoring different tasks with parallel processing.

Use one start to monitor the switch as above.

Then use start0 to go through your main program steps; perhaps making a little car go through an intersection.
 

tarantulataramasalata

Senior Member
So, parallel tasks can't override each other?
I was hoping to use code0 to flash a light sequence, and code1 to monitor a button press, which then affects code0.
 

hippy

Technical Support
Staff member
So, parallel tasks can't override each other?.
They can; in fact you created a perfect example of that in your original post.

The challenge is in achieving what you want to achieve, avoiding things working in ways other than you desire or intended.

The main problem here is that it's not at all clear what you are trying to achieve, what you want to happen, or what would need to be done to implement that using parallel processing to make it work as desired.

I was hoping to use code0 to flash a light sequence, and code1 to monitor a button press, which then affects code0.
You will have to provide more detail on that, what the light sequence is and how you want it affected, for people to help with that but here is a simple multi-tasking program which affects the speed of the C.1 LED flashing depending on whether the button is pushed or not -
Code:
#Picaxe 08M2

Start0:
  Do
   Toggle C.1
   If b0 = 0 Then
     Pause 1000
   Else
     Pause 240
   End If
  Loop

Start1:
  Do
    If pinC.3 = 0 Then
      b0 = 0
    Else
      b0 = 1
    End If 
  Loop
Here's an alternative, possibly more elegant way, of doing that -
Code:
#Picaxe 08M2

Start0:
  Do
   Toggle C.1
   Pause w0
  Loop

Start1:
  Do
    If pinC.3 = 0 Then
      w0 = 1000
    Else
      w0 = 240
    End If 
  Loop
And here's a version which is more responsive whenever the button is pushed or released -
Code:
#Picaxe 08M2

Start0:
  Do
   Toggle C.1
   w1 = 0
   Do
     Pause 40
     w1 = w1 + 40
   Loop Until w1 >= w0
  Loop

Start1:
  Do
    If pinC.3 = 0 Then
      w0 = 1000
    Else
      w0 = 240
    End If 
  Loop
 
Last edited:

tarantulataramasalata

Senior Member
They can; in fact you created a perfect example of that in your original post.
Thanks :giggle:

The main problem here is that it's not at all clear what you are trying to achieve
I'm sorry for the confusion. My original code intended to light an LED on C1 using start1, whilst start0 monitored C3 for input before turning off C1 and turning on C2. Releasing the input C3 would reverse the process. However, it didn't seem to work. :cry:

Code:
start0:
do
if pinC.3 = 1 then
low C.1
high C.2
endif
loop
stop

start1:
do
high C.1
loop
stop
You will have to provide more detail on that
I hope that makes it a bit clearer?
Thanks again
 
Top