Foe the FSM that listed below, the issue is the following:
1. When I do not use while (1) at the beginning of each CASE statement the code runs perfectly in the MikroC simulator, and function as its intend.
2. But when I run the same code on EVB (Evaluation Board) with the PIC 16F877A its do not function as its intend, I think it’s moving from idle to detect_a and to detect_ab and then to idle again, and not passing the last state.
3. Can someone advise why this code behave differently in the simulator and in the real system.
4. When I use while(1) at the beginning of each CASE statement the simulation and the real system function the same.
can anyone advise why w/o the while(1) the code behaves differently in the simulation and the EVB.
switch(state){case idle:// Idle statewhile(1){// wait till sensor A or B detect
state = idle;if((PORTB.F0==0)&&(PORTB.F1==1))// move from A to B{ state=detect_a; flag1=1;}// if detect A , set flag1break;}case detect_a:// detect_a statewhile(1){
state = idle;if((PORTB.F0==0)&&(PORTB.F1==0)&&(flag1==1)){ state=detect_ab; flag12=1; delay_ms(filter);}// if detect A & B set flag12break;}case detect_ab:// detect_ab statewhile(1){
state = idle;if((PORTB.F0==1)&&(PORTB.F1==0)&&(flag12==1)){ state=detect_b; flag123=1;}break;}case detect_b:// detect_b statewhile(1){
state = idle;if((PORTB.F0==1)&&(PORTB.F1==1)&&(flag123==1)){
state=idle;// next state is Idle
flag1=0; flag12=0; flag123=0;
enter=1;// detect enterbreak;}}}
The code seems consistent, there is no apparent reason to behave differently. I presume there is something related to inputs, that probably are not sensitizing input register in the simulation environment