State Machine language concept
tonyp12
Posts: 1,951
Though Prop can be programmed pretty easy without thinking in
'state machine way', due to it's 8 parallel processors.
But for beginners that just want some LEDs to flash,
Or you just want to through something quick together that can 'multitask'
Or wire your brain to think in this way, just to know.
In a statemachine there are no wait or loops
The actual code should not be considered running in a specific order.
But that all of the code is checked all the time.
P0 to P27 is the prop pins and can be high or low
M0 to M15 is memory and can be low(0)/high(255) but also 1-254
T1 is 1khz freq timer, can be high or low.
T2 is 1khz timer that rolls around at 255.
T3 same as T2, but 100hz
I'm planning to put each line statement in 32bits
The optional second compare can only do low/high test.
So the prop will be running a byte code interpreter.
The code is not typed it but with drop down menus (line 12 in below pic)
What my code does (starting at line 7 in the excel concept test)
For each push button press.
The LED on P8 blink 4 times a second or stays off.
It debouce the button on P0, by making sure it's pressed down for at least 1/10 second.
(M0 does not roll around, but stop at 255)
For each press it toggles M1 memory.
If the 1/1000 second timmer is at 128 it turns on the LED
If the timer is at 0 OR the button have been pressed again, the LED is low.
I may add some more registers, maybe Sx to send or recive serial data from ps2, Uart or spi
P.S I have to rethink the timers, If the code is checked 100'000+/second ,at line 7 would made M0=100 to fast.
Maybe I will check code at a fixed 1000/second and T1 is not needed.
'state machine way', due to it's 8 parallel processors.
But for beginners that just want some LEDs to flash,
Or you just want to through something quick together that can 'multitask'
Or wire your brain to think in this way, just to know.
In a statemachine there are no wait or loops
The actual code should not be considered running in a specific order.
But that all of the code is checked all the time.
P0 to P27 is the prop pins and can be high or low
M0 to M15 is memory and can be low(0)/high(255) but also 1-254
T1 is 1khz freq timer, can be high or low.
T2 is 1khz timer that rolls around at 255.
T3 same as T2, but 100hz
I'm planning to put each line statement in 32bits
The optional second compare can only do low/high test.
So the prop will be running a byte code interpreter.
The code is not typed it but with drop down menus (line 12 in below pic)
What my code does (starting at line 7 in the excel concept test)
For each push button press.
The LED on P8 blink 4 times a second or stays off.
It debouce the button on P0, by making sure it's pressed down for at least 1/10 second.
(M0 does not roll around, but stop at 255)
For each press it toggles M1 memory.
If the 1/1000 second timmer is at 128 it turns on the LED
If the timer is at 0 OR the button have been pressed again, the LED is low.
I may add some more registers, maybe Sx to send or recive serial data from ps2, Uart or spi
P.S I have to rethink the timers, If the code is checked 100'000+/second ,at line 7 would made M0=100 to fast.
Maybe I will check code at a fixed 1000/second and T1 is not needed.