Hi everyone,
What I would like to know from you lot is what you think about finite state machines and if you have ever used them
. Here is my mini story of the day:
So I am still working on the ZBM and decided that a boot loader was needed (sick to death of pulling out 28 pin DIP chips and shoving em back in).
The boot loader uses a PIC18F45K22 that reads from an I2C device and then transfers the data into memory (WIP). But when I tried to get the I2C Module to work it just never did, complete fail. I have used I2C a fair number of times and only once ever got an on-board peripheral to actually work.
So instead of sitting there spending once again hours of time trying to debug and track code I decided to bit bang. I know its bad practice considering the use of the module (which I could not get to work), but I also thought that it would be a good bit of practice to change my style of code from:
"conditional loops where you sit there and wait for something to happen before you move on "
To
"Everything is always running and constantly checking for updates"
In other words, a finite state machine.
So today I have a bit bang I2C module working as a finite state machine and my main function literally only consists of this (so far):
The awesome thing about this code is that it is impossible (I hope), that the code gets stuck somewhere. When I say this I mean that if the I2C module gets stuck in a state it will not affect any other running systems. There are no loops or conditional loops and just about everything is in the form of an if statement.
All the best,
Robin
What I would like to know from you lot is what you think about finite state machines and if you have ever used them
So I am still working on the ZBM and decided that a boot loader was needed (sick to death of pulling out 28 pin DIP chips and shoving em back in).
The boot loader uses a PIC18F45K22 that reads from an I2C device and then transfers the data into memory (WIP). But when I tried to get the I2C Module to work it just never did, complete fail. I have used I2C a fair number of times and only once ever got an on-board peripheral to actually work.
So instead of sitting there spending once again hours of time trying to debug and track code I decided to bit bang. I know its bad practice considering the use of the module (which I could not get to work), but I also thought that it would be a good bit of practice to change my style of code from:
"conditional loops where you sit there and wait for something to happen before you move on "
To
"Everything is always running and constantly checking for updates"
In other words, a finite state machine.
So today I have a bit bang I2C module working as a finite state machine and my main function literally only consists of this (so far):
Code:
do
{
i2c_update();
memory_update();
if(i2c_get_flag() == MACHINEIDLE)
{
memory_read(0,1);
}
}while(1);
All the best,
Robin