bigal_scorpio
Active Member
Hi to all,
I have just written a simple program to control 2 separate latching relays, the kind with just a single coil that needs a reverse voltage to switch over.
All I wanted was for the pic to detect a button pressed, either on GP4 or GP3 then if it was GP3 it would pulse GP1 high and GP2 low for a second, then store the state of B1 so another press of GP3 would change its state and so on, the same applies for GP4 controlling the pulse to relay 2 from GP0 and GP5.
The program compiles ok and burns but on my test board the only lights ever to pulse are on GP0 and GP1! GP2 and GP5 are never lit which I would expect to work on every other press.
What am I missing here? Also on powering the circuit GP0, 1, 2 and 5 are all lit permanantly until a switch is pressed, then its back to how I described earlier.
I am puzzled although this is the usual feeling after a Friday night out
Anyone see whats wrong with the code please?
Al
I have just written a simple program to control 2 separate latching relays, the kind with just a single coil that needs a reverse voltage to switch over.
All I wanted was for the pic to detect a button pressed, either on GP4 or GP3 then if it was GP3 it would pulse GP1 high and GP2 low for a second, then store the state of B1 so another press of GP3 would change its state and so on, the same applies for GP4 controlling the pulse to relay 2 from GP0 and GP5.
The program compiles ok and burns but on my test board the only lights ever to pulse are on GP0 and GP1! GP2 and GP5 are never lit which I would expect to work on every other press.
What am I missing here? Also on powering the circuit GP0, 1, 2 and 5 are all lit permanantly until a switch is pressed, then its back to how I described earlier.
I am puzzled although this is the usual feeling after a Friday night out
Anyone see whats wrong with the code please?
Al
Code:
'* Name : latching relay1.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 18/06/2011 *
'* Version : 1.0 *
'* Notes : 12F629 latching relay controller for latching
'* : relays with single coil *
'* : *
'****************************************************************
Include "ALLDIGITAL.PBP"
TRISIO = %011000
B1 var byte
B2 var byte
MAIN:
If GPIO.3 = 0 then gosub sw1 'get switch input
if GPIO.4 = 0 then gosub sw2 'get switch input
Goto MAIN
sw1:
READ 0,B1 'read stored value from eeprom
B1 = NOT B1 'change B1 value
WRite 0,B1 'write new value to eeprom
If B1 = 0 then 'send pulse to relay
GPIO.1 = 1
GPIO.2 = 0
pause 1000
GPIO.1 = 0 'stop pulse
ENdif
IF B1 = 1 then 'send opposite pulse to relay
GPIO.1 = 0
GPIO.2 = 1
pause 1000
GPIO.2 = 0 'stop pulse
endif
return
sw2:
READ 1,B2
B2 = NOT B2
WRite 1,B2
If B2 = 0 then
GPIO.0 = 1
GPIO.5 = 0
pause 1000
GPIO.0 = 0 'stop pulse
endif
IF B2 = 1 then
GPIO.0 = 0
GPIO.5 = 1
pause 1000
GPIO.5 = 0 'stop pulse
endif
return
end