Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] FSM style with PIC16F877A

Status
Not open for further replies.

gidp

Newbie level 5
Joined
May 20, 2009
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,366
Hello guys,

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.

Thanks.

The code:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
switch (state)
   {
      case idle:                      // Idle state
       while(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 flag1
         break;
       }
 
      case detect_a:                  // detect_a state
       while(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 flag12
         break;
       }
 
      case detect_ab:                 // detect_ab state
       while(1)
       {
         state = idle;
         if ((PORTB.F0==1)&&(PORTB.F1==0)&&(flag12==1))
         {  state=detect_b; flag123=1; }
         break;
       }
 
      case detect_b:                  // detect_b state
       while(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 enter
            break;
         }
       }
    }

 
Last edited by a moderator:

andre_teprom

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,236
Helped
1,151
Reputation
2,321
Reaction score
1,127
Trophy points
1,403
Location
Brazil
Activity points
53,762
Can someone advise why this code behave differently in the simulator and in the real system
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
 

gidp

Newbie level 5
Joined
May 20, 2009
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,366
Thanks a lot and sorry for the TAG's issue.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top