About the only nit-pick I had was your use of external interrupts for switches.
For the purposes of the article I must disagree. The article missed out much of the scaffolding for his state machine but was already too long. I couldn't find the CTransition or CFiniteStateMachine Class for example.
As written, the Keyboard ISR is simply a source of events, where even g_millis is a distraction. To add a traditional keyboard scanner, would have been overkill here.
That aside.
In the code, I could easily find the defined states of the FSM because they are clearly defined and instantiated, but had trouble finding the defined events; I suppose they are SPEED_MASK & STOP_MASK; but was there an enumeration missing ?
There is a missing transition: Pressing STOP in IDLE mode. what would the code have done there ? I couldn't tell.
You really are starting at the wrong end of things!
First define your states:
switch on
switch off
light on
light off
we can get rid of switch on as light on/off means the switch is on.
This leaves us three states. The rest should be simple.
As for creating a state machine that you would code to solve that problem, then that might be quite different as you might want to poll the switch at a iven rate, but derive you flash timing from that rate. So you'd need a counter.
How to convert both diagram into one state diagram?
If they are two separate tasks what makes you think they can be combined into one overall stater diagram/machine.
EDIT: Oh wait a minute are you talking about the same (flashing) light? So it's either off, flashing on or flashing off isn't it?
In terms of programming, LED blinking at every 1 second in main loop when user turn on switch means external interrupt will generate and in interttupt routine LED should be off
Don't understand a word of that. But this is the thing - you need to start with a clear description of exactly what it is you are trying to achieve. Don't try to implement or even get to the level of state description until you have a very clear explanation/picture of what you intend the thing to to. From that you add increasing detail until at some stage you reach the level of state description and even further on you reach the point of actual implementation. Don't be tempted to "jump ahead".
N.Winterbottom Did you download the code? The scaffolding is there, I just didn't put all the code in the article.
The way I did it was only one way it could have been done, there is always a better way.
Do I have to login into jaxcoder in order to download your fms.zip. I searched the jaxcoder article for the word 'download' and the zip file's name and did not find any link
#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."
No need for state machines or any code other than that needed to set-up a 1Hz timer output to a pin...
Agreed - This example is too trivial to warrant or teach a state diagram. It in essence an On/Off switch controlling a LED flasher.
An often quoted FSM example is a pedestrian light controlled crossing. Without RADAR or Traffic loops etc. it's about the right level of complexity to demonstrate the concepts.
When I did research for my article, virtually the only examples I could find where of the stop light.
Quadrature encoder knob is a good example
An elevator is one often used as a school example
That's always a fun one; not just from an FSM point of view, but also from an optimisation perspective. One place I used to work had 6 elevators/lifts serving around 20 floors. You would punch the number of the desired floor and it would tell you which elevator to take, presumably trying to group people together to avoid each one stopping at every floor.
You would punch the number of the desired floor and it would tell you which elevator to take
I recently worked on a "destination based" elevator system, it addition to that method, when you swiped your entry badge, it would look up what floor you worked on and direct you to the designated lift that would take you to that floor or if authorized to more then one, then present a menu of floors to choose from you were authorized to enter.
(Possum Lodge oath) Quando omni flunkus, moritati.
I remember the pre-historic lifts (aka elevators) at university. We raced to use the Goods Lift because it was fast and about 50 people could fit inside, but there was still competition for the nearby passenger lift. Both had an electro-mechanical control system, the algorithm was first-come-first-served without any memory. We engineers quickly discovered this and could easily "game the controller".
You had to listen carefully for the motor stopping, listen even more carefully for the waiting passenger to open the manual doors and after stepping aboard; closing them. At that instant; before the new passenger had pressed the button for his floor, you could press your call button. Whatever button the new passenger pressed, it didn't matter. You had called the lift. It became increasingly difficult for us to keep straight faces when we met the unfortunate passenger we had played the trick on.
Having two states named the same is not a good idea. There's got to be some good tutorials on fundamental like finite state machines - I'd suggest you try to find these and get the basics under control. At the moment you've got half an idea.
Again, you're confusing yourself. I have no idea what problem you are trying to solve - why is there task states mixed in?
There's various tools you can test your codes with. Python and javascript come to mind. But, I'd suggest getting the basics first.
Posted by avrcandies: Sat. Aug 15, 2020 - 04:13 PM
1
2
3
4
5
Total votes: 0
very simple---I have two variables, current_state and next_state
Here are some ideas, you can have a look, however no endless questions, you must think
The conditionals are formed, however you like: if else, else if, elif, case , switch, whatever you like.
This is just to give the overall idea..YOU provide the details and actual workings
biggie_state_machine:
if current_state = next_state
(call) process_same state
else
(call) start next_state
endif
==========================
process_same_state
if current_state = monitor_for_fire
do monitor doorway stuff (might set a new state)
if current_state = sound_alarm
next_state=sounding_alarm
if current_state = sounding_alarm
if alarm reset = pressed
turn off sound
next_state = monitor_doorway
if current_state = fire_detected
if bedroom_temperature < 100
shut off water
next_state = drain_pumping
if bathroom_temp > 200
turn on exhaust
else
turn off exhaust
===================================
start_next_state
(call) process current_state_exit ...finish up any common tasks when leaving a state
if next_state = sound_alarm ...any of these will only be done ONCE, since a next state then becomes a current state
turn on alarm bell
if next_state = fire_detected
call fire dept
trow a rock through the window
turn on sprinklers
current_state = next_state ...important!!
===============================
process current_state_exit ...any common things needing done
if current_state = filling_washing_tub
turn off water valve
if current_state = begin_shutdown_event
turn off power supply
When in the dark remember-the future looks brighter than ever. I look forward to being able to predict the future!
I understand given diagram theoretical, but when it comes to implementing it in a real practical, I do not understand it.
I have spent a lot of time on this to understand. I have given my best to understand with real example. But it is my bad luck that I am unable to understand it even after my many of efforts
Can someone give me a real time example so that I can understand the diagram by comparing this diagram with real time example
Maybe if I have a real time example, then I can also try to create a diagram as given in page
This is the lifecycle of a process on a traditional computer under the control of an operating system, e.g. Windows, Linux, ...
I don't believe it's a helpful example for your learning, as it doesn't show the events that lead to the state changes. The states are controlled by the operating system's scheduler, which is trying to share finite resources (processor cycles, memory, ...) between multiple competing processes. It has little to do with embedded design and development.
I don't believe it's a helpful example for your learning, as it doesn't show the events that lead to the state changes.
I agree with you, I have searched many pages and links, There is more information about the state, they describe what happens in which state but doesn't gives real example. But I have not yet found any example in which explained state with real example.
Real example means an example that represents the objective of the project.
This looks like a really good write-up on hierarchical state machines. The author delivers a walk-though of his state machine design. It's lengthy but if you sit down and read it carefully; there's much to learn there.
The diagram above is a statechart. That's not a place to start.
How about this problem: write a c function that looks at characters in a string to determine if the string is a legal integer or float. The end of the string is denoted by end of string, a space, or non-character, non-digit. This is how regular expressions are parsed.
start in state1: if character is minus, or a digit, go to state 2, otherwise return error
in state 2: if digit stay in state 2. If end char, then go to state 11 and you are done: you have an integer. If the character is '.' (period), proceed to state 3, other wise return an error.
in state3: if you read digits, stay in state 3; if 'e' goto state 4 (exponent notation), if end char, then goto state 12 and you are done: you have a float (w/o exponent), otherwise return an error.
in state4 (you've read 'e' in the floating point): if minus or digit go to state 5, else return error
state5: if digit stay in state 5, if end-char goto state 12, you are done, else signal error.
state 11: return "integer"
state 12: return "float"
EDIT: Part of the exercise is to find the errors in the above state machine. :)
How about this problem: write a c function that looks at characters in a string...
A number of us have suggested possible projects which lend themselves to learning about FSMs. However the OP seems fixed on learning by reading rather than learning by doing, and in so doing keeps running up against the fact that 95% of stuff online is garbage.
#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."
The diagram above is a statechart. That's not a place to start.
Agreed - It's a step beyond that, but I don't believe that's a reason to dismiss it as a place to start - Especially when reading the linked article, it wasn't meant as a stand-alone diagram.
A number of us have suggested possible projects which lend themselves to learning about FSMs.
Looks like you haven't read my last post 87. Everyone has given me advice on how to create a state diagram. Right now I have no problem in creating a state diagram, I have got the idea how to create this
My question was that I have an FSM #87 and I do not understand how it is actually used in real projects.
Looks like you haven't read my last post 87. Everyone has given me advice on how to create a state diagram. Right now I have no problem in creating a state diagram, I have got the idea how to create this
My question was that I have an FSM #87 and I do not understand how it is actually used in real projects.
I think obdevel gave a clear, full and accurate reply in the very next post #88.
The state diagram in post #87 is of no use to you, since you will never write an operating system.
#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."
You don't seem interested at all in any help offered, do you go through #86 or other examples?
There is no doubt that you have given a great answer. I not saying now how to make a state diagram because I understand how to create
My question was how to understand the process state diagram with a real example. I have read all the states in the process state diagram and I understand it But I am not able to imaging process state diagram with any real project.
My request was to help me how you can understand process state diagram by comparing it with a real embedded project.
Then use one of the examples given that represents a real-world device you're familiar with, e.g. traffic light, elevator, turnstile, rather than something abstract or invisible.
If you can imagine the device operating whilst reading the diagram, you're over 50% of the way there. Even better if it's a device that you can physically interact with, maybe as a car driver or pedestrian, or taking an elevator at your home or office.
OT ... I appreciate that some people are happy with abstract technical concepts, but I tend to want to relate things to a real-world example.
For the purposes of the article I must disagree. The article missed out much of the scaffolding for his state machine but was already too long. I couldn't find the CTransition or CFiniteStateMachine Class for example.
As written, the Keyboard ISR is simply a source of events, where even g_millis is a distraction. To add a traditional keyboard scanner, would have been overkill here.
That aside.
N.Winterbottom Did you download the code? The scaffolding is there, I just didn't put all the code in the article.
The way I did it was only one way it could have been done, there is always a better way.
Happy Trails,
Mike
JaxCoder.com
Oh thanks for following up - I'll download and check it out.
I seem to remember where someone had something like:
seconds_is_1_state
seconds_is_2_state
seconds_is_3_state
..
..
seconds_is_59_state
They seemed bent on having as many states as possible!
Well, I suppose that could be a state machine
I'd like to see their state machine for an odometer.
When in the dark remember-the future looks brighter than ever. I look forward to being able to predict the future!
An odometer is a case where there MIGHT be a separate state machine for each wheel.
Jim
Until Black Lives Matter, we do not have "All Lives Matter"!
I don't think a mechanical odometer is a finite state machine because of the myriad of states while the drive wheel revovles between digits.
A digital odometer may internally count in feet or meters but at least that becomes finite.
OK, I have created two state diagram for one system.
System do the two tasks
Blink LED every 1000ms
Turn on LED when user turn on the switch
Task one take 1000ms
Task two take 80 ms
I want to make state diagram in which Led will blink continuously at 1000ms but it should be stop when user turn on the switch.
How to convert both diagram into one state diagram?
You really are starting at the wrong end of things!
First define your states:
switch on
switch off
light on
light off
we can get rid of switch on as light on/off means the switch is on.
This leaves us three states. The rest should be simple.
As for creating a state machine that you would code to solve that problem, then that might be quite different as you might want to poll the switch at a iven rate, but derive you flash timing from that rate. So you'd need a counter.
That's a good point about an analog odometer!
I think you see my point exactly with an odometer
some fools would try to set up these states:
miles_1_state
miles_2_state
...
miles_9999_state
that is NOT what you want to do, (even though technically, they could be considered different states).
My point is it is important to define the perspective of state correctly, or you will create a quick mess of things.
In this case, it would be more of a pulse debouncer state machine connected to a counter, somewhat like a 1000 count encoder
When in the dark remember-the future looks brighter than ever. I look forward to being able to predict the future!
I suppose you could join the two diagrams with something like:
EDIT: Oh wait a minute are you talking about the same (flashing) light? So it's either off, flashing on or flashing off isn't it?
In terms of programming, LED blinking at every 1 second in main loop when user turn on switch means external interrupt will generate and in interttupt routine LED should be off
Don't understand a word of that. But this is the thing - you need to start with a clear description of exactly what it is you are trying to achieve. Don't try to implement or even get to the level of state description until you have a very clear explanation/picture of what you intend the thing to to. From that you add increasing detail until at some stage you reach the level of state description and even further on you reach the point of actual implementation. Don't be tempted to "jump ahead".
Mike,
In reference to your post
N.Winterbottom Did you download the code? The scaffolding is there, I just didn't put all the code in the article.
The way I did it was only one way it could have been done, there is always a better way.
Do I have to login into jaxcoder in order to download your fms.zip. I searched the jaxcoder article for the word 'download' and the zip file's name and did not find any link
Alan
allano
In the upper right corner of page there's a box "Available Downloads" click on the icon to download!
Happy Trails,
Mike
JaxCoder.com
It took me a minute or two or searching to find it also.
BTW: Why is every page titled "Index" ?
N.Winterbottom
The site was written in ASP.Net MVC and by default all the routing pages are named Index, I just never changed them.
Short answer "Lazy" :)
Happy Trails,
Mike
JaxCoder.com
Now that you pointed to the icon, it is obvious. I hovered over a lot of items on the page to see if the cursor changed but not that icon.
Thanks,
Alan
I want to flash led every 1 seconds but when user press button , flashings should be off
Then you break it down:
state flash
state off
and button move between(press one way release the other).
then perhaps you can break flash down to
led off
led on
sec_counter change to odd
sec_counter change to even
will then change the state
....
timer handling
...
...
So I guess you are saying the LED effectively has 3 states:
LED_OFF_PERMANENTLY
LED_OFF_WHILE_FLASHING
LED_ON_WHILE_FLASHING
If that's the case I'd maybe try and sketch out a state diagram that takes that into account and how it might transition between those states.
In your other thread, i pointed you to a tutorial. did you read it?
We seem to be spending an inordinate amount of time on a very fundamental subject........
Is it show
No need for state machines or any code other than that needed to set-up a 1Hz timer output to a pin...
#1 Hardware Problem? https://www.avrfreaks.net/forum/...
#2 Hardware Problem? Read AVR042.
#3 All grounds are not created equal
#4 Have you proved your chip is running at xxMHz?
#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."
Agreed - This example is too trivial to warrant or teach a state diagram. It in essence an On/Off switch controlling a LED flasher.
An often quoted FSM example is a pedestrian light controlled crossing. Without RADAR or Traffic loops etc. it's about the right level of complexity to demonstrate the concepts.
I'll see if I can locate a diagram...
When I did research for my article, virtually the only examples I could find where of the stop light.
Happy Trails,
Mike
JaxCoder.com
Quadrature encoder knob is a good example
An elevator is one often used as a school example
When in the dark remember-the future looks brighter than ever. I look forward to being able to predict the future!
That's always a fun one; not just from an FSM point of view, but also from an optimisation perspective. One place I used to work had 6 elevators/lifts serving around 20 floors. You would punch the number of the desired floor and it would tell you which elevator to take, presumably trying to group people together to avoid each one stopping at every floor.
I recently worked on a "destination based" elevator system, it addition to that method, when you swiped your entry badge, it would look up what floor you worked on and direct you to the designated lift that would take you to that floor or if authorized to more then one, then present a menu of floors to choose from you were authorized to enter.
(Possum Lodge oath) Quando omni flunkus, moritati.
"I thought growing old would take longer"
I remember the pre-historic lifts (aka elevators) at university. We raced to use the Goods Lift because it was fast and about 50 people could fit inside, but there was still competition for the nearby passenger lift. Both had an electro-mechanical control system, the algorithm was first-come-first-served without any memory. We engineers quickly discovered this and could easily "game the controller".
You had to listen carefully for the motor stopping, listen even more carefully for the waiting passenger to open the manual doors and after stepping aboard; closing them. At that instant; before the new passenger had pressed the button for his floor, you could press your call button. Whatever button the new passenger pressed, it didn't matter. You had called the lift. It became increasingly difficult for us to keep straight faces when we met the unfortunate passenger we had played the trick on.
I did Mike, looks well done, thanks!
(Possum Lodge oath) Quando omni flunkus, moritati.
"I thought growing old would take longer"
Thanks for the kind words.
Happy Trails,
Mike
JaxCoder.com
I am trying to convert my state diagram into a state processing diagram.
How to make state task processing diagram
Ready means task is not active at yet
Running means task is active at time and running
Blocked means task is deactivated
i don't understand transition that's why I have not completed
Having two states named the same is not a good idea. There's got to be some good tutorials on fundamental like finite state machines - I'd suggest you try to find these and get the basics under control. At the moment you've got half an idea.
Again, you're confusing yourself. I have no idea what problem you are trying to solve - why is there task states mixed in?
There's various tools you can test your codes with. Python and javascript come to mind. But, I'd suggest getting the basics first.
very simple---I have two variables, current_state and next_state
Here are some ideas, you can have a look, however no endless questions, you must think
The conditionals are formed, however you like: if else, else if, elif, case , switch, whatever you like.
This is just to give the overall idea..YOU provide the details and actual workings
When in the dark remember-the future looks brighter than ever. I look forward to being able to predict the future!
Hi, I have came across Wikipedia page https://en.m.wikipedia.org/wiki/....
There is a diagram given in page.
I understand given diagram theoretical, but when it comes to implementing it in a real practical, I do not understand it.
I have spent a lot of time on this to understand. I have given my best to understand with real example. But it is my bad luck that I am unable to understand it even after my many of efforts
Can someone give me a real time example so that I can understand the diagram by comparing this diagram with real time example
Maybe if I have a real time example, then I can also try to create a diagram as given in page
This is the lifecycle of a process on a traditional computer under the control of an operating system, e.g. Windows, Linux, ...
I don't believe it's a helpful example for your learning, as it doesn't show the events that lead to the state changes. The states are controlled by the operating system's scheduler, which is trying to share finite resources (processor cycles, memory, ...) between multiple competing processes. It has little to do with embedded design and development.
This might be more applicable:
https://www.freertos.org/RTOS-ta...
You might want to work through the tutorials and other documents to get a better grasp on the basics.
This thread is a bit like this:
https://www.youtube.com/watch?v=...
I agree with you, I have searched many pages and links, There is more information about the state, they describe what happens in which state but doesn't gives real example. But I have not yet found any example in which explained state with real example.
Real example means an example that represents the objective of the project.
How about this:
It's from this article:
https://www.drdobbs.com/architecture-and-design/uml-statecharts-at-1099/188101799
This looks like a really good write-up on hierarchical state machines. The author delivers a walk-though of his state machine design. It's lengthy but if you sit down and read it carefully; there's much to learn there.
The diagram is on the 2nd page:
https://www.drdobbs.com/architecture-and-design/uml-statecharts-at-1099/188101799?pgno=2
The diagram above is a statechart. That's not a place to start.
How about this problem: write a c function that looks at characters in a string to determine if the string is a legal integer or float. The end of the string is denoted by end of string, a space, or non-character, non-digit. This is how regular expressions are parsed.
start in state1: if character is minus, or a digit, go to state 2, otherwise return error
in state 2: if digit stay in state 2. If end char, then go to state 11 and you are done: you have an integer. If the character is '.' (period), proceed to state 3, other wise return an error.
in state3: if you read digits, stay in state 3; if 'e' goto state 4 (exponent notation), if end char, then goto state 12 and you are done: you have a float (w/o exponent), otherwise return an error.
in state4 (you've read 'e' in the floating point): if minus or digit go to state 5, else return error
state5: if digit stay in state 5, if end-char goto state 12, you are done, else signal error.
state 11: return "integer"
state 12: return "float"
EDIT: Part of the exercise is to find the errors in the above state machine. :)
A number of us have suggested possible projects which lend themselves to learning about FSMs. However the OP seems fixed on learning by reading rather than learning by doing, and in so doing keeps running up against the fact that 95% of stuff online is garbage.
#1 Hardware Problem? https://www.avrfreaks.net/forum/...
#2 Hardware Problem? Read AVR042.
#3 All grounds are not created equal
#4 Have you proved your chip is running at xxMHz?
#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."
Agreed - It's a step beyond that, but I don't believe that's a reason to dismiss it as a place to start - Especially when reading the linked article, it wasn't meant as a stand-alone diagram.
Looks like you haven't read my last post 87. Everyone has given me advice on how to create a state diagram. Right now I have no problem in creating a state diagram, I have got the idea how to create this
My question was that I have an FSM #87 and I do not understand how it is actually used in real projects.
The state diagram in post #87 is of no use to you, since you will never write an operating system.
You don't seem interested at all in any help offered, do you go through #86 or other examples?
When in the dark remember-the future looks brighter than ever. I look forward to being able to predict the future!
@OP Good luck in your learning. I'm out.
#1 Hardware Problem? https://www.avrfreaks.net/forum/...
#2 Hardware Problem? Read AVR042.
#3 All grounds are not created equal
#4 Have you proved your chip is running at xxMHz?
#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."
There is no doubt that you have given a great answer. I not saying now how to make a state diagram because I understand how to create
My question was how to understand the process state diagram with a real example. I have read all the states in the process state diagram and I understand it But I am not able to imaging process state diagram with any real project.
My request was to help me how you can understand process state diagram by comparing it with a real embedded project.
A process can go from Blocked to Suspended, but not the other way around.
That could be deliberate.
FreeRTOS might require that the "owner" of a suspended process deal with blocking.
If so, that should be stated.
Iluvatar is the better part of Valar.
Then use one of the examples given that represents a real-world device you're familiar with, e.g. traffic light, elevator, turnstile, rather than something abstract or invisible.
If you can imagine the device operating whilst reading the diagram, you're over 50% of the way there. Even better if it's a device that you can physically interact with, maybe as a car driver or pedestrian, or taking an elevator at your home or office.
OT ... I appreciate that some people are happy with abstract technical concepts, but I tend to want to relate things to a real-world example.
Pages