PE6 freezing

Chris Kelly

Well-known member
Hi guys

Running PE6 on Windows 10. I'm working on some code which works fine, but when I try to alter one of the sections it freezes during simulation.

Here is the code

Code:
#picaxe 20m2
#no_data

main:

symbol StepLen    = b0
symbol Pulses    = b1
symbol StepLenADC    = b2
symbol PulsesADC    = b3
symbol StepLenChk = b4
symbol PulsesChk  = b5
symbol NewTotal     = b6
symbol Total     = b7
symbol Remainder    = b8
symbol StepPosn     = b9
symbol DrumHit    = b10

bptr    = 32

gosub CheckStepLenADC
gosub CheckPulsesADC

do

if    StepPosn < StepLen then

    NewTotal = Total + Pulses
    
    if     NewTotal >= StepLen then
        Remainder = NewTotal - StepLen
        DrumHit = 1
        @bptr = DrumHit
        NewTotal = Remainder
        Remainder = 0
    
    else    DrumHit = 0
        @bptr = Drumhit
    
    end if
    
    Total = NewTotal
    inc bptr
    inc StepPosn
    DrumHit = 0
end if

readadc C.1, b2
if StepLenADC != StepLenChk then
    gosub CheckStepLenADC
end if

readadc C.2, b3
if PulsesADC != PulsesChk then
    gosub CheckPulsesADC
end if

if    StepPosn = StepLen then
    Total     = 0
    NewTotal     = 0
    Remainder     = 0
    StepPosn    = 0
    bptr = 32
end if
loop

;=========================================
CheckStepLenADC:
tablecopy 32,47
readadc C.1,b2

Select StepLenADC
    Case <16
    StepLen = 1
    Case 16 to 31
    StepLen = 2
    Case 32 to 47
    StepLen = 3
    Case 48 to 63       
    StepLen = 4
    Case 64 to 79       
    StepLen = 5
    Case 80 to 95       
    StepLen = 6
    Case 96 to 111       
    StepLen = 7
    Case 112 to 127       
    StepLen = 8
    Case 128 to 143       
    StepLen = 9
    Case 144 to 159       
    StepLen = 10
    Case 160 to 175       
    StepLen = 11
    Case 176 to 191       
    StepLen = 12
    Case 192 to 207       
    StepLen = 13
    Case 208 to 223       
    StepLen = 14
    Case 224 to 239       
    StepLen = 15
    Case > 240       
    StepLen = 16
end select
StepLenChk = StepLenADC
return

;=========================================
CheckPulsesADC:
tablecopy 32,47
readadc C.2,b3

Select PulsesADC
    Case <16
    Pulses = 1
    Case 16 to 31
    Pulses = 2
    Case 32 to 47
    Pulses = 3
    Case 48 to 63       
    Pulses = 4
    Case 64 to 79       
    Pulses = 5
    Case 80 to 95       
    Pulses = 6
    Case 96 to 111       
    Pulses = 7
    Case 112 to 127       
    Pulses = 8
    Case 128 to 143       
    Pulses = 9
    Case 144 to 159       
    Pulses = 10
    Case 160 to 175       
    Pulses = 11
    Case 176 to 191       
    Pulses = 12
    Case 192 to 207       
    Pulses = 13
    Case 208 to 223       
    Pulses = 14
    Case 224 to 239       
    Pulses = 15
    Case > 240       
    Pulses = 16
end select
PulsesChk = PulsesADC
return
;=========================================
I want to change the If....end If statement shown below to a Do While ….. Loop statement instead. This change alone causes the freeze:

Code:
if    StepPosn < StepLen then

    NewTotal = Total + Pulses
    
    if     NewTotal >= StepLen then
        Remainder = NewTotal - StepLen
        DrumHit = 1
        @bptr = DrumHit
        NewTotal = Remainder
        Remainder = 0
    
    else    DrumHit = 0
        @bptr = Drumhit
    
    end if
    
    Total = NewTotal
    inc bptr
    inc StepPosn
    DrumHit = 0
end if
So if I replace this snippet of code with

Code:
do while StepPosn < StepLen

    NewTotal = Total + Pulses
    
    if     NewTotal >= StepLen then
        Remainder = NewTotal - StepLen
        DrumHit = 1
        @bptr = DrumHit
        NewTotal = Remainder
        Remainder = 0
    
    else    DrumHit = 0
        @bptr = Drumhit
    
    end if
    
    Total = NewTotal
    inc bptr
    inc StepPosn
    DrumHit = 0
loop
this change causes the freeze during simulation.

Is my change inherently bad, or is the rest of the code unwieldy and causing the freeze?

I always make sure there are no other programs running in the background.

Hope you can help?

Cheers

Chris
 

Aries

New Member
Unwieldy code should not be the problem. The likely explanation is that the do...while is never terminating. Add some sertxd statements within the loop and see what happens. Alternatively, step through the simulation, watching what happens and where it goes.
 

Buzby

Senior Member
Hi Chris,

As Aries says, it's not the code that freezes PE6, it's more likely due to your simulation speed setting.

On my Win 10 laptop, if I set the slider to 100mS or less, PE6 goes very unresponsive.

Sometimes the code is still running, and the variables in the Code Explorer pane update nice and quickly, even though the main window has 'frozen'.

But usually I just get the 'Not responding' message in the title bar, and the little blue 'waiting' wheel. I then need to use Task Man to kill PE6.

This behaviour has been discussed in the forum, but no solution seems forthcoming, so I don't run simulations faster than 100mS.

It is a real problem, as PE5 ran faster, but had a limit at 20mS, that's why I asked for a 'run with no GUI' in the PE6 wishlist.


Cheers,

Buzby
 
Top