I was getting random resets of the code below when I used a DO ... LOOP rather than the main: .... goto main instruction the random resets have stopped.
The switch activites every 30-60 seconds, the switch may stay closed during a cycle hence the loop exits for the display.
Any thoughts? Have I messed up the PULLUP command?
Thank you,
Anobium
I have a relative simple circuit in the AXE091 board with an external switch - the purpose of the application is to count the switch on/off cycle. The switch has a 10k pull down and I also have fitted a cap to the switch contacts. I have then tied the switch to c.3 via a 1k.
Also have a LED and an additional push switch of the AXE091 board. A piezo sounder on b.2
I have connected the SEROUT on c.0 to my PC via 180r (there is no serin connected)
Also have a LED and an additional push switch of the AXE091 board. A piezo sounder on b.2
I have connected the SEROUT on c.0 to my PC via 180r (there is no serin connected)
The switch activites every 30-60 seconds, the switch may stay closed during a cycle hence the loop exits for the display.
Any thoughts? Have I messed up the PULLUP command?
Thank you,
Anobium
Code:
#Picaxe 14m2
#Terminal 38400
' reset EEPROM
EEPROM 2,(0,0)
' reset to current count value. load the two bytes into the EEPROM
EEPROM 0,(144,0)
' OutPorts
symbol ledport = b.1
symbol soundport = b.2
symbol commsport = c.0
' InPorts
symbol switchmonitorport = pinc.3 'Has 10k pull down resistor fitted
symbol showcurrentvaluesswitchpushed = pinc.4 'Has 10k pull down resistor fitted AXE 091 SW3
' constants
symbol mem_lobyte = 0
symbol mem_hibyte = 1
symbol mem_switchstate = 2
symbol mem_resetcount = 3
symbol blink = 20
' memory mapping
symbol currentcount = w0
symbol lbyte_currentcount = b0
symbol hbyte_currentcount = b1
symbol countdots = b2
symbol currentstate = b3
symbol restartcount = w3
' initialise
{
' bits 7654321076543210
pullup %0000011100111110
' conn ---XX------XX---
low ledport
countdots = 0
setfreq m32
}
' Read current reset count from EEPROM
{read mem_resetcount, restartcount
inc restartcount
write mem_resetcount, restartcount
serout commsport,n4800, ("On @ ", #restartcount, 13, 10 )
gosub show2
gosub pout1:gosub pout1
}
' Main loop
main:{
setfreq m32
' call Sub as this Sub routine is reused below
gosub show1
read mem_switchstate, currentstate
if switchmonitorport = 1 then
high ledport
if currentstate = 0 then
write mem_switchstate, 1
serout commsport,n4800, (27,"[1GIncrement Count ")
read mem_lobyte, lbyte_currentcount
read mem_hibyte, hbyte_currentcount
inc currentcount
write mem_lobyte, lbyte_currentcount
write mem_hibyte, hbyte_currentcount
gosub pout
do while switchmonitorport = 1
pause blink
gosub show1
loop
end if
end if
if switchmonitorport is off then
write mem_switchstate, 0
low ledport
end if
}
goto main
' Output current reading value
{
pout:
' current value
serout commsport,n4800, (#currentcount, " @ ", #restartcount)
pout1:
' output sound
serout commsport,n4800, (13,10)
setfreq m4
Sound soundport,(50,10,0,10,125,10,0,10)
setfreq m32
return
}
' Output text to the current line
{
dotout:
if countdots = 127 then
serout commsport,n4800, (27,"[1G.")
end if
if countdots = 255 then
serout commsport,n4800, (27,"[1G")
end if
return
}
' Tidy up the current display line
{
tidyout:
if countdots > 127 then
serout commsport,n4800, (27,"[1G")
end if
return
}
' Handle current reading
{
show1:
if showcurrentvaluesswitchpushed = 1 then
gosub show2
do while showcurrentvaluesswitchpushed = 1
gosub dotout
pause blink
inc countdots
loop
else
gosub dotout
inc countdots
end if
return
}
' Show current reading
{
show2:
serout commsport,n4800, (27,"[1GCurrent Count " )
read mem_lobyte, lbyte_currentcount
read mem_hibyte, hbyte_currentcount
gosub pout
return
}
Attachments
-
29.9 KB Views: 28