Programming 20M2 simulation to reality

jackbec18

New Member
I've programmed a circuit and it works in a simulation, but once it's downloaded onto the chip, it runs, but loops around constantly in one specific section of the program, and doesn't progress any further, I've tested all real life components and track connections and they all seem to be fine, but still the problem persists. Any idea to why this is happening?
 

Buzby

Senior Member
Welcome to the forum !.

Please post your code, I'm struggling to see it without my crystal ball.
 

Buzby

Senior Member
Hi jackbec18,

Thanks for the code, but you didn't need to send it by PM, you can post code in the forum, like this :

Code:
Start:
Touch16 b.5, w0 'Calibrating touch switch
Touch16 b.4, w1 'Calibrating touch switch
Touch16 b.3, w2 'Calibrating touch switch
Touch16 b.2, w3 'Calibrating touch switch
Touch16 b.1, w4 'Calibrating touch switch
debug
start2:
high c.4 'activates green tri-colout led
if pinc.1 = 1 then alarm1 'If the microswitch is opened when opened, set off the initial alarm
goto start2 'If it is closed do not activate the alarm'
'Continuously loop around keeping the green led perminantly active
alarm1:
high c.5 'Red tri-colour led activates creating amber colour'
high c.0 'buzzer is activated to warn consumer, sound command
delay:
b14=0
delay2:
b14=b14+1
pause 25
if b14>25 then Alarm2
goto delay2

Alarm2:
low c.4 'amber led to then red
high b.0 'Siren activates'
high c.3 'both white leds activate'
w9=w4 'If switch one is pressed, begin resetting the alarm sytem sequence
touch16 b.1, w5
If w9>w5 then
w6=w9-w5
else
w6=w5-w9
endif
If w6>250 then secondreset 'checking reset'
goto Alarm2 'If switch one isn't pressed, alarm system 2 remains active

deactivate:
w9=w4
touch16 b.1, w5
gosub differentvalue2
wait 1
low b.0 'Siren deactivated
wait 3
high c.4 'Green tri-colour led activated
w9=w1
touch16 b.4, w5
gosub differentvalue2
pinc.1 = 0 'microswitch deactivated
goto start 'Return to beginning of process

checkloop:
w9=w0
touch16 b.5, w5 'tamper switch
gosub differentvalue
w9=w1
touch16 b.4, w5 'Activate and deactivate
gosub differentvalue2
w9=w2
touch16 b.3, w5 'tamper switch
gosub differentvalue
w9=w3
touch16 b.2, w5 'tamper switch
gosub differentvalue
w9=w4
touch16 b.1, w5 'Activate and deactivate'
gosub differentvalue2

differentvalue: 'New values for the calibration of each capacitive switch after they've been pressed'
If w9>w5 then
w6=w9-w5
else
w6=w5-w9
endif
If w6>250 then Alarm2 'If any of the switches, other than the activation and de-activation switches are pressed, alarm system will activate
return

differentvalue2:
If w9>w5 then
w6=w9-w5
else
w6=w5-w9
endif
If w6>250 then deactivate
return

secondreset:
b15=0
low b.0 'Siren deactivated
second2:
w9=w1
touch16 b.4, w5
If w9>w5 then
w6=w9-w5
else
w6=w5-w9
endif
If w6>250 then
goto start2 'Return to green tri-colour led being green, and monitoring the microswitch
else
b15=b15 +1
pause 25 'added counter as a timer'
endif
if b15>200 then Alarm2
goto second2 'check reset'
You can use the option to 'Copy for Forum' in PE, or type in the [ Code ] and [ /code ] tags, or use the '#' button on the Advanced tab in the forum.

Anyway, now the code is on show, let's see what suggestions come up !

Cheers,

Buzby
 

hippy

Ex-Staff (retired)
The problem may be with the "Start2:" label. On an M2 that will start a second parallel task along with the first and that is probably not what was intended in this program. The solution may be to rename the "Start2:" label to something else.

Simulation may have made it appear that everything was working as it only simulates one task by default; adding "#simtask all" at the start of the program allows simultaneous simulation of all tasks to be observed.
 
Top