I have programmed the Purix Controller based on the Arduino Mega while developing the hardware from September 2012 and until now. The Purix system has been under development during the very same period, and of cause both controller hard- and software must keep up with that. Although we have more that fourty sketch versions until now the basic structure has remained the same from the beginning.
Click this .pdf to see an artists impression of the Purix setup: Purix drawing
This drawing shows the three basic parts of the Purix Controller-sketch (= Arduino program). There is a setup part (“void setup”) that is only called once the controller starts up, and there is the main loop (“void loop”) that handles the physical input/output algorithms to control the Purix system as long as the power is on. The third and very important part is the serial input/output that enables us to monitor and control certain parts of the main loop. This part is not necessary for the actual execution of the controller algorithms, but absolutely essential to experiments and successful testing.
Click to see .pdf: Purix 2 Program Structure
Start/Stop and State Control
To avoid deadlocks and other nasty real-time pitfalls we use a very strict set of operational states: Standby, starting up, normal operation and closing down. All this takes place within the main loop. Within each state four PID regulators and some additional logic receives state-specific parameters. One can argue that a few more discrete states exist inside the normal operation state, but this is fully under control. This drawing shows how operational state is allowed to change. Until now only an external signal (with a specially developed de-bouncer), timers and some test-commands are allowed to change the states. It is the intention to have a self-check routine that will be able to force the program into closing down state.
Click to see .pdf: Purix 2 Start-Stop and State Control
This drawing shows in more detail what goes on inside the main loop, and how/where the serial control mechanism can interact. This is an early version. We have now added several extra features: Stepper motor control, triac control, etc.
Click to see .pdf: Purix 2 The Loop
The Serial Control
I have made a very simple set of control commands used in monitoring and manually controlling the execution of the program. The commands consists of one character specifying the command-group (e.g. Read, Write or Control) followed by a second character specifying the sub-level of the command (e.g. P or I parameter). Write commands receive an integer as a third input. The two or three inputs are separated by commas and terminated by a return. The protocol is very simple and effective, with no possibilities to send errors to the program. The parser is inspired by the tutorial found here: http://www.dyadica.co.uk/journal/simple-serial-string-parsing/
Sketch Details by cTOPconsult: