Multiple picaxe chips working side by side

edmunds

Senior Member
Dear friends,

I have another post active here with some detail on my big project. However, after designing possible schematics and some programming effort, I feel at square one. Not in a bad way, but while writing the code, I certainly have found a few things I will have to change in my schematics and the PCB I spent so many hours designing. In the process of doing that I have a question about sharing the workload between several picaxe chips.

My application requires running several parallel, but interdependent processes. I am working with I2C already because of I/O expanders to have enough ports for everything.

1st thing is a traffic light (4 of them actually). Simple enough as a standalone thing. I realised if I run it as a parallel task on the same single picaxe running everything else, my traffic light will not be very constant as the other parallel tasks the program will be dancing to will take different times depending on if, elseif, else and what not. Right?

So this calls for a separate chip running the traffic lights. Fine. Still, the main chip needs to know when and where it is red, yellow or green. What is the best way to achieve that? Read through I2C? I would have to query the thing all the time that would make I2C bus quite busy and would still take processing power of the main chip? Some kind of serial connection?

2nd. There is also the need to drive four servos. This could also be exported to a separate picaxe chip as picaxes are so convenient for servos. What is the best way to let that chip know what to do? Serial line? I2C? Is mixing these a good idea?

3rd. Can I have more than one interrupt? I seem to need one to sense if any of the parameters through I/O expanders have changed, one to sense if there are cars to divert (4 reed switches) and now one more to know when the traffic light has changed its state.


Thank you for your time,

Edmunds
 

lbenson

Senior Member
Considering that a 28X2 running at 8mhz can run 2,000-4,000 instruction per second, or more, and 8 times that at 64mHz (with external resonator), I'm not sure why you can't run lots of things off of a single chip. What that would mean is that instead of using pauses to time your lights, you'd need to use the chip's timers so you can count seconds and trigger events based on the seconds count (I'm assuming that you don't need more than seconds accuracy in timing).

Do your 4 servos just move back and forth between two positions or are does the position have to be fully controllable or possibly have variable-speed panning? At least in simulation, an 08M2 can control 4 servos (on pins 0, 1, 2, 4). Some servos will hold their position when halted, so you might be able to read a serial control character on pin 3 with serin (which is blocking), and then set the servo and position indicated by the control character sent from the main picaxe.

You can interrupt on more than one input, but you can also just poll a port in a loop (I assume your main loop would process many times a second), and take action based on which bits were altered.

Please post a link to your other thread, so we can better understand the application.
 

hippy

Technical Support
Staff member
I would guess this is part of the main project being planned described here ...

http://www.picaxeforum.co.uk/showthread.php?25919-Code-to-control-a-four-way-roundabout

In essence it seems to be similar to a 'section occupied' detection system of a circular railway track, with feed-in from other tracks plus feed-out routing. The key issue would seem to be inter-locking of sections to only bring vehicles on when the tracks through to routed exit are clear.

To me that's quite a complicated project and my approach would be to design and model how it would need to work before deciding upon how to implement it. If only one vehicle is allowed on the circular track at a time it is relatively straight forward but to have multiple vehicles at the same time gets complicated.
 

edmunds

Senior Member
I would guess this is part of the main project being planned described here ...

http://www.picaxeforum.co.uk/showthread.php?25919-Code-to-control-a-four-way-roundabout

In essence it seems to be similar to a 'section occupied' detection system of a circular railway track, with feed-in from other tracks plus feed-out routing. The key issue would seem to be inter-locking of sections to only bring vehicles on when the tracks through to routed exit are clear.

To me that's quite a complicated project and my approach would be to design and model how it would need to work before deciding upon how to implement it. If only one vehicle is allowed on the circular track at a time it is relatively straight forward but to have multiple vehicles at the same time gets complicated.
Also correct, but I have dropped the roundabout for now :). Or rather implemented it with four separate picaxe chips. One per approaching lane. Works fine for the exhibition layout with a few cars on it at a time anyway. In theory, there should be accidents, in practice, they have not happened so far. I'm working on the normal crossing for now with traffic lights to start with - again to start simpler and then grow to more. There is enough to learn as it is :).

Edmunds
 

geoff07

Senior Member
This feels to me like a state-machine problem. Can you express the design as a state/transition diagram (or several in parallel)? If you can, then the solution can be based on defined states and events that cause transitions from one state to another. You can have multiple state machines running in a single process. A traffic light is an archetypal state machine where the events are a) phase timers, b) crossing button presses, and c) vehicle arrivals. The states are the various combinations of lights that can be on and the events (may) cause transitions from one state to another.

Implementing it is simply a matter of an event manager that looks for events (timers expiring, vehicles crossing a threshold, etc.) and runs the appropriate transition code to move the relevant SM onto the next state with whatever actions are appropriate. It may sound complicated but it isn't really. There is a sample SM on my blog.

If this is new to you then some research into Finite State Machines might be useful. And you can use QFSM to document it rather nicely. (the 'Finite' bit implies that there is a limited set of states that the system can be in so all the events and transitions can be defined and there is no uncertainty)

The key, however, to any complex project is to design it before you start to build it!
 

edmunds

Senior Member
This feels to me like a state-machine problem. Can you express the design as a state/transition diagram (or several in parallel)? If you can, then the solution can be based on defined states and events that cause transitions from one state to another. You can have multiple state machines running in a single process. A traffic light is an archetypal state machine where the events are a) phase timers, b) crossing button presses, and c) vehicle arrivals. The states are the various combinations of lights that can be on and the events (may) cause transitions from one state to another.

Implementing it is simply a matter of an event manager that looks for events (timers expiring, vehicles crossing a threshold, etc.) and runs the appropriate transition code to move the relevant SM onto the next state with whatever actions are appropriate. It may sound complicated but it isn't really. There is a sample SM on my blog.

If this is new to you then some research into Finite State Machines might be useful. And you can use QFSM to document it rather nicely. (the 'Finite' bit implies that there is a limited set of states that the system can be in so all the events and transitions can be defined and there is no uncertainty)

The key, however, to any complex project is to design it before you start to build it!

Thank you for your input! I'm doing here everything at once and while technically I have started building, you could also refer to it as testing my home PCB lab at the same time :). I looked at your blog and it was really interesting. It is a new concept for me, but one possible to grasp, I think :). The only thing that puts me off is, if I understand this correctly, I would have at least 80 circles and I cannot imagine how to draw that efficiently at this point. Will look at QFSM later on - maybe that will help.

Edmunds
 
Top