Multiple Processes

-D-

New Member
I was just wondering if there is a way to have each I/O pins to work separately. The way I understand picaxe is, is that you cant have more than one operation going at once, so if there is a way to have more than one PLEASE let me know.

Thank you
 

-D-

New Member
here is an example of a previous project ive made,

Code:
let w5 = 75
let w4 = 1
let b1 = 0
let b2 = 0
let b3 = 0

main:

	if pin4=1 then anticlockwise
	if pin5=1 then clockwise
	if pin6=1 then claw
	readadc 1,b4
	readadc 2,b5
	readadc 3,b6
	if b4 != b1 then analyse_1
	if b5 != b2 then analyse_2
	if b6 != b3 then analyse_3
	goto main



" ---------------------------------- servos --------------------------------- "

analyse_1:
	w1 = b1 * 2 / 3 + 75
	servo 4,w1
	goto main

analyse_2:
	w2 = b1 * 2 / 3 + 75
	servo 5,w2
	goto main


analyse_3:
	w3 = b1 * 2 / 3 + 75
	servo 6,w3
	goto main

[code/]

This part of my programming moves a robotic arm i made; analyse 1 to 3 move  3 seperate servos according to the position a variable resistor is in. When i tried to execute the program i found that it would only be able to move one servo a time, so if i moved 2 variable resistors only one of the servos moved.

You see the way i understand it is that the program is excuted from top to bottom, but what if you want more than one sideprogram running at the same time. For example, scanning for an IR signal and communitacating with a different robot aswell as navigating through a maze (ie having touch sensors active)...

lol, i hope tht made it a little bit more clear =S
 

hippy

Technical Support
Staff member
Welcome to the PICAXE forum.

All SERVO commands will operate in parallel so you shouldn't have a problem. It seems most likely to be a program flow error - In this case where b4 != b1 the flow goes to analyse_1, then to main, and it remains in that loop until b4 does equal b1. During that time it will not execute the b5 != b2 code etc.

Change the "goto main" to "return" in the analyse_1/2/3 routines, change the "if ... then analyse_1/2/3" to "if ... then gosub analyse_1/2/3" and that should resolve the problem.
 

-D-

New Member
Code:
let w5 = 75
let w4 = 1
let b1 = 0
let b2 = 0
let b3 = 0

main:

	if pin4=1 then anticlockwise
	if pin5=1 then clockwise
	if pin6=1 then claw
	readadc 1,b4
	readadc 2,b5
	readadc 3,b6
	if b4 != b1 then analyse_1
	if b5 != b2 then analyse_2
	if b6 != b3 then analyse_3
	goto main



" ---------------------------------- servos --------------------------------- "

analyse_1:
	w1 = b1 * 2 / 3 + 75
	servo 4,w1
	goto main

analyse_2:
	w2 = b1 * 2 / 3 + 75
	servo 5,w2
	goto main


analyse_3:
	w3 = b1 * 2 / 3 + 75
	servo 6,w3
	goto main

" --------------------------------- end servos ------------------------------ "




" ----------------------------------- claw ---------------------------------- "

claw:
	if w4 >= 1 then 
		goto open_claw
	else 
		goto close_claw 
	endif

close_claw:
	w4 = 0
	servo 7,w5
	w5 = w5 + 1
	if pin7=1 then main
	goto claw

open_claw:
	servo 7,220
	w4 = 1
	gotomain

" -------------------------------- end claw -------------------------------- "



" ------------------------------ stepper motor ----------------------------- "

clockwise:
	let pins = %00001100
	pause 250
	let pins = %00000110
	pause 250
	let pins = %00000011
	pause 250
	let pins = %00001001
	pause 250
	if pin5=1 then main
	goto clockwise

anticlockwise:
	let pins = %00001001
	pause 10
	let pins = %00000011
	pause 10
	let pins = %00000110
	pause 10
	let pins = %00001100
	pause 10
	if pin4=1 then main
	goto anticlockwise

" ---------------------------- end stepper motor ----------------------------- "
If you need explaination then please ask, because i know that i dont really lay my programming out very well and its really out of context =P

as a side note; the stepper motor controlled the base on which my robotic arm turned, and the 3 servos were controlling the arm. O and btw, "w3 = b1 * 2 / 3 + 75" is a converstion between the servos command which is between 75 - 225 or something and the variable input which is 0 - 255. I did this so i can use the number of the variable resistor to directly move the servo =D
 
Last edited:

-D-

New Member
Welcome to the PICAXE forum.

All SERVO commands will operate in parallel so you shouldn't have a problem. It seems most likely to be a program flow error - In this case where b4 != b1 the flow goes to analyse_1, then to main, and it remains in that loop until b4 does equal b1. During that time it will not execute the b5 != b2 code etc.

Change the "goto main" to "return" in the analyse_1/2/3 routines, change the "if ... then analyse_1/2/3" to "if ... then gosub analyse_1/2/3" and that should resolve the problem.
ok so i think i understand what your tell me to do; just got on question about that. Basically when you move the variable resistor it will already have started to excute the code before having completed the movement of the variable resistor, hence not having the final position of the variable resistor, but just a bit when you started turning it. which is why i left it in a loop so i could check everytime untill the variable resistor stopped moving. is this a problem?

In any case, thank you for solving my problem ^.^ this still didnt awsner my initial question though, which was can picaxe execute different codes at the same time. Because for my A-lvl project i wanted to do something along the line of swarm robotics, and ive pretty much come up with the idea but i just wanted to know if you could communicate via IR and still run a seperate side program at the same time.
 
Last edited:

hippy

Technical Support
Staff member
No, the PICAXE cannot do two things at the same time, except those things which are handed-off to internal hardware to handle, servos, PWM, background serial, I2C Slave and so on. Most commands are "blocking", in that they wait for whatever a particular command expects until continuing; infra red receive commands will wait until a valid infra-red signal is received.

There are ways round that; interrupts, bit-banged IR receive, using smaller PICAXE's to off-load the polling for IR commands to. What you have to do is emulate the parallel processing you want.
 

-D-

New Member
No, the PICAXE cannot do two things at the same time, except those things which are handed-off to internal hardware to handle, servos, PWM, background serial, I2C Slave and so on. Most commands are "blocking", in that they wait for whatever a particular command expects until continuing; infra red receive commands will wait until a valid infra-red signal is received.

There are ways round that; interrupts, bit-banged IR receive, using smaller PICAXE's to off-load the polling for IR commands to. What you have to do is emulate the parallel processing you want.
hmm... thats a shame =/ so ye, i was thinking of either having 2 pics, one which would run the communications, and that would then be able to communitcate with the other pic, I dont know how well this would work though, perhaps as you suggested with an interrupt command it could work. Do you reckon that could work? communication with one pic and then driving with the other?

It doesnt seem ideal though, do you know of any other Mircoprocessor which i could you, it doesnt really matter if its in another progamming language, i know C ++ soort of C and java and phython. Im still the best at basic though so if you know one for basic tht would be awesome =D
 

hippy

Technical Support
Staff member
It is fairly easy to do, and quite cheap using an additional PICAXE-08M. The 08M runs a loop which waits for IR and then tells the master it has received data, the master sees the notification then asks for the data, after that each goes its own way. The 08M doesn't matter that it is stuck 'doing nothing but waiting for IR', the master only has to poll or be interrupted when there is data so it can be doing something else. With an X1 or X2 it could be even simpler using background receive or I2C Slave ( 08M would have to bit-bang I2C but not too hard ). There are previous posts on this forum about the various techniques which can be used.

It doesn't seem ideal at first glance, but that technique has largely been what's allowed PC's to surge ahead speed-wise; off-loading work which involves waiting for things to dedicated chips and peripherals.

There are other micoprocessors and microcontrollers which could be made to do the task but you may be looking at a lot of effort to achieve that and may lose the simplicity of programming the PICAXE otherwise gives. As this is a PICAXE forum we generally only give advice on using PICAXE and Rev-Ed product. What may be required to use an alternative is an important thing to consider along with having to buy tools to use them; if it takes five days to achieve what may take a day and an extra £1.50 chip, unless your time is only worth 40p a day it's still cost effective. It is obviously not as simplistic as that but it's a factor to bear in mind.
 

manie

Senior Member
My Two-Pence worth: Additional 08M's to do scanning and exploring the country side with some X2's at 32MHz (5V is my choice) to do the quick stuff and re-polling for more info. The interrupts are sometimes not that easy to do but if the X2 (or X1) scans for a HIGH pin on the 08M's and with Hserin in the background it becomes a little easier...
 

kranenborg

Senior Member
A few remarks based on my experiences with interrupts, infrain2 and parallel processing, for what it is worth:

* Combining interrupts and infrain2 on the same input port functions very well as a single-chip solution for doing both IR comms and general control operations in the background without any unnecessary waiting for IR signals, since the IR comms are generally asynchronous and thus are perfectly suited for an interrupt-based approach. See also the following discussion in which Arvin provides a code framework: http://www.picaxeforum.co.uk/showthread.php?t=8517&page=2

* There are microcontroller systems around that support multiprocessing (and I am investigating one of them) and that are based on X2-similar devices. However, you will encounter that programming complexity significantly increases because these devices are to the same level resource-limited as the picaxe, in particular regarding timers and memory. This implies generally that you have to do a lot more resource management in terms of memory, semaphores etc. order to get results, even for very basic operations. The availability of very cheap but powerful picaxes like the 08M (with high-level basic functions like INFRAIN etc.) often gives a very satisfactory parallel processing alternative (In one application I went back from the the other platform back to the picaxe just because of this)

* One should not underestimate the fact that the activity level of this forum (and the nice "tone" of most discussions!) is almost a guarantee that you will find help for a proper solution (except for some specific apps that simply require very high speeds that simply cannot be reached by an interpreter-based concept like the picaxe)

/Jurjen
 
Last edited:
Top