Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Which came First A or B?

Status
Not open for further replies.
philba said:
this is a classic application of a finite state machine. put all the logic into a 2 dimensional table with one dimension as the current state and the other as the sensor values. the code is tiny - a simple loop that gets input and uses it plus the current state to determine the new state. then you take actions (inc/dec) based on the new state.

you will probably want to track the progress of a person through the sensors so don't just look for one transition but rather a sequence. the FSM makes that trivial to do. for example you want to see 00 to 01 to 11 to 10 to 00 to count an entrance. that would be accomplished with 4 states. Start in the idle state (00 sensor input), when you see 01 while in the idle state, move to state 1. when you see 11 in state 1, you move to state 2 and so on until you move from state 3 to state 4 which is the completion of the person moving past the sensors. Similar for the other direction.

the beauty of the FSM is you can take action on any sequence of sensor values so you can catch the person that moves into the doorway and then goes pack the way they came.
I'd love to see an example?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top