Possible PE6 Simulator fault, or is it me?

mortifyu

New Member
Hi Guru's,

I am finding the SIMULATOR not operating as expected. Is it me, or is this an error in the SIMULATOR?

Code:
HSerSetup B9600_8, %01

settimer t1s_8
HSerFlag=0
HserPtr=0
ptr=0
.
.
...Receive three Bytes of DATA
.
.
ptr=0
sertxd(@ptrinc," ",@ptrinc," ",@ptr,cr)    'Displays DATA as expected
HSerFlag=0
timer=0
.
.
...Receive no DATA yet
.
.
Ready:                                              'At this point SIMULATOR shows System variables FLAGS=0, TIMER=0
if timer<2 and HSerFlag=0 then
      goto Ready                               'Should come here and goto Ready
else
     goto received                            'Comes here instead.
endif

received:
.
.
.

With the real life PIC, this seems to do as it should, but is difficult debugging without the STEP by STEP benefit of the SIMULATOR.

Any suggestions?


Regards,
Mort.
 

AllyCat

Senior Member
Hi,

It's obviously an X2 (but you haven't indicated which) so I can't help much. However, the code structure is at least "unnecessarily complex", but I don't know if actually "potentially wrong". The "problem" area could be written as simply:
Code:
Ready:                                              'At this point SIMULATOR shows System variables FLAGS=0, TIMER=0
if timer<2 and HSerFlag=0 then {goto} Ready            'Should come here and goto Ready or Fall Through"
received:
Or you should be able to add a GOTO received in the intervening line if the received: label doesn't follow immediately. Alternatively, you might expand out the conditional line to see if it's the timer or HSerFlag which is causing the issue.

But with such a "tight" loop and flags changing in the "background", I guess the Simulator might be getting "confused".

Cheers, Alan.
 

mortifyu

New Member
Hi,

It's obviously an X2 (but you haven't indicated which)...
Hi Alan,

Sorry, it is a 40X2. The 'received:' label is much further down in the program. I wrote the CODE example to show the problem I am having.

As a matter of interest...

if timer<2 and HSerFlag=0 then goto Ready

is equivalent to

if timer<2 and HSerFlag=0 then
goto Ready


Is this correct? I understood there is essentially no difference other than the formatting.


The SIMULATOR reacting incorrectly has me totally stumped at this stage.


Regards,
Mort.
 

AllyCat

Senior Member
Hi,

To be pedantic, the equivalent should be:
Code:
if timer<2 and HSerFlag=0 then
          goto Ready
ENDIF
The "problem" might be that the Editor/Compiler sometimes tries to be "helpful" and tolerates some Formatting/Syntax errors to make it "easier" for novices. Maybe in this case it "thinks" that a novice has accidentally inserted a <CR> (or colon) in the one-line "GOTO" version, i.e. IF ... THEN Ready (although then I would expect it to throw a syntax error on the ENDIF).

In the absence of hippy, Technical or somebody else, I can only suggest that you expand out the parts of the Simulated code until it works "as expected". Simulator errors are certainly not unknown. ;)

Cheers, Alan.
 

Flenser

Senior Member
mortifyu,

There is nothing wrong with the code in your original post and it works exactly as you expect it should

This is a limitation of the simulation.
- At very slow simulation speeds you can see the lines being highlighted as they are executed but the timer is being inncremented to a value greater than 1 between when you set it to 0 and when the IF statement tests if timer<2.
- At very fast simulation speeds the IF THEN case is jumping back to Ready one or more times but if the simulation speed is too fast for the lines to be highlighted as they are executed then you can't see this.

The #simulation directive is described as deprecated in PE6 but it still works so I can use this to show you what I mean

Add this to the top of your program:
#simulation 1000 ; 1000 ms I think
With the simulation speed set to 1000ms the simulation slowly steps through the code and the s_w7 variable increments about 1 sec per step.
s_w7 is reset to zero at the statement timer=0 but the debug variables go to zero at the if statement (I don't know why) and the IF test fails and goes directly to the else case as you describe.
After the program has stopped the s_w7 value is 7, much greater than 1

By default the program delays (and the timers will be incremented) for labels
Next go to into File -> Options -> Simulation and unset the option "Highlight (and delay) over program labels"
Rerun the simulation with "#simulation 1000" set
Now the first time through the IF statement the test is true and the simulation goes to the THEN case once (and jumps back to the Ready label)
and the second time through the IF statement the test fails and goes to the else case.
So it looks like the simulation delay for the ready label is a part of what is incrementing the timer to a value > 1
After the program has stopped the s_w7 value is 6

Now run the program with #simulation 200
This speed is still slow enough for PE to highlight lines as they are executed.
The IF statement test is now true twice and jumps back to the Ready label before the IF statement tests false the third time through.
After the program has stopped the s_w7 value is 3

Now run the program with #simulation 100
This speed is still slow enough for PE to highlight lines as they are executed.
The IF statement tests true six times and jumps back to the Ready label before the IF test fails the seventh time through.
After the program has stopped the s_w7 value is 2

Now run the program with #simulation 0
With very fast simulation speeds PE 6 does not have time to highlight the lines during the simulation.
The IF condition is testing true many times we just can't see it.

Adding extra commands takes extra time but at the fastest simulation speed we can add a counter to the IF THEN case.
Try this code in simulation and add the b0 variable to the watch panel.
After the program has stopped the b0 counter is 14 so the IF statement THEN case was executed 14 times
Rich (BB code):
#PICAXE 40X2
#simspeed 0
HSerSetup B9600_8, %01

settimer t1s_8
HSerFlag=0
HserPtr=0
ptr=0
b0=0

ptr=0
sertxd(@ptrinc," ",@ptrinc," ",@ptr,cr)    'Displays DATA as expected
HSerFlag=0
timer=0

Ready:                                              'At this point SIMULATOR shows System variables FLAGS=0, TIMER=0
if timer<2 and HSerFlag=0 then
    inc b0
      goto Ready                               'Should come here and goto Ready
else
     goto received                            'Comes here instead.
endif

received:
 

mortifyu

New Member
Hi Flenser,

I did as you told me and indeed you are bang on. Jumping right in with the '#SIMULATION 100' line solved the issue.

Thank you very much for your assistance guys. ALWAYS! very much appreciated more than words on your screen can describe.

Coming here asking questions is like an automatic encyclopedia for gaining knowledge to resolve things that trouble me at times.


That being said, moving right along... How do I turn $500K into $50M in a relatively short period of time? 😁:unsure:;)


Regards,
Mort.
 
Top