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
I want to change the If....end If statement shown below to a Do While ….. Loop statement instead. This change alone causes the freeze:
So if I replace this snippet of code with
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
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
;=========================================
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
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
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