keithv
- 23rd September 2014, 19:24
I'm having trouble with this project. I'm using a PIC12F609 and a pushbutton to turn a dual latching 2formC relay on and off. An LED comes on when the relay is on. This is being used to route an audio signal. The "mute" part of the code uses a MOSFET to short the signal path to ground so that you cannot hear the relay contacts when it switches.
Everything functions exactly the way I want it to. The problem I'm having is that after 30 minutes or so of sitting idle, the circuit will spontaneously change from the "on" state to the "off" state, or vice versa. And eventually, the program will lock up after sitting idle for about an hour.
I guess I'm doing something wrong in the configuration/define, but I can't figure out what I'm doing wrong. Any help would be greatly appreciated.
'************************************************* ***************'* Name : relayswitch2.BAS *
'* Author : Keith Vonderhulls *
'* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 9/23/2014 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
#config
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _IOSCFS_4MHZ & _CP_OFF
#endconfig
DEFINE OSCCAL_1k 1
ANSEL = 0 ' Set all digital
CMCON0 = 7 ' Analog comparators off
CMCON1 = 7 ' Analog comparators off
TRISIO = %10001000
LATCH0 var GPIO.2 'ON latch coil of relay
LATCH1 var GPIO.1 'OFF latch coil of relay
LED var GPIO.4
MUTE var GPIO.0
PB Var GPIO.3 ' Alias GPIO.3 to push button
LED = 0
MUTE = 0
LATCH1 = 1 'initiate program with LED, MUTE and relay off
pause 10 'allow 10ms pulse to relay coil to turn off
LATCH1 = 0 'end pulse to relay coil to conserve power
main:
if PB = 0 then
MUTE = 1 'mute while switching occurs
TOGGLE LED 'change LED status
pause 30 'mute & debounce
gosub activaterelay
pause 30 'allow another 30ms to mute
MUTE = 0
gosub switchrelease
pause 50 'debounce
endif
goto main
End
activaterelay: 'change state of relay base upon state of LED
if LED = 1 then
LATCH0 = 1
elseif LED = 0 then
LATCH1 = 1
endif
pause 10 ' send 10ms pulse to relay coil
if LED = 1 then ' end pulse to relay coil to conserve power
LATCH0 = 0
elseif LED = 0 then
LATCH1 = 0
endif
return
switchrelease: 'wait for footswitch to be released
do until PB = 1
pause 10
loop
return
Everything functions exactly the way I want it to. The problem I'm having is that after 30 minutes or so of sitting idle, the circuit will spontaneously change from the "on" state to the "off" state, or vice versa. And eventually, the program will lock up after sitting idle for about an hour.
I guess I'm doing something wrong in the configuration/define, but I can't figure out what I'm doing wrong. Any help would be greatly appreciated.
'************************************************* ***************'* Name : relayswitch2.BAS *
'* Author : Keith Vonderhulls *
'* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 9/23/2014 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
#config
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _IOSCFS_4MHZ & _CP_OFF
#endconfig
DEFINE OSCCAL_1k 1
ANSEL = 0 ' Set all digital
CMCON0 = 7 ' Analog comparators off
CMCON1 = 7 ' Analog comparators off
TRISIO = %10001000
LATCH0 var GPIO.2 'ON latch coil of relay
LATCH1 var GPIO.1 'OFF latch coil of relay
LED var GPIO.4
MUTE var GPIO.0
PB Var GPIO.3 ' Alias GPIO.3 to push button
LED = 0
MUTE = 0
LATCH1 = 1 'initiate program with LED, MUTE and relay off
pause 10 'allow 10ms pulse to relay coil to turn off
LATCH1 = 0 'end pulse to relay coil to conserve power
main:
if PB = 0 then
MUTE = 1 'mute while switching occurs
TOGGLE LED 'change LED status
pause 30 'mute & debounce
gosub activaterelay
pause 30 'allow another 30ms to mute
MUTE = 0
gosub switchrelease
pause 50 'debounce
endif
goto main
End
activaterelay: 'change state of relay base upon state of LED
if LED = 1 then
LATCH0 = 1
elseif LED = 0 then
LATCH1 = 1
endif
pause 10 ' send 10ms pulse to relay coil
if LED = 1 then ' end pulse to relay coil to conserve power
LATCH0 = 0
elseif LED = 0 then
LATCH1 = 0
endif
return
switchrelease: 'wait for footswitch to be released
do until PB = 1
pause 10
loop
return