I have a program where the 16F628A resets intermittently.
The program controls a remote heater using a Dallas DS18B20 temperature sensor.
Initilization:
The circuit breaker is turned on and a relay enegizes keeping the heater off for 30 seconds. The operator then walks to where the heater is which takes about 30 seconds.
The relay then deenegizes to turn the heater on and the operator can verify operation.
After 30 seconds the relay energizes and the heater turns off then then goes to the main part of program.
Main:
The heater cycles as it goes above or below the setpoints.
Problem:
The heater cycles about 15 times per day normally, but about once or twice a day the PIC will reset and go into the initilazation sequence and the continue operation. This is not good for the heater as short on sequences are not good.
Solutions tried:
Used various power supplies, different temperature sensors, shielded and unshielded cable, noise filters all without any change.
I am posting the program as perhaps my logic is not correct or out of sequence.
Any suggestions?
Code:
'*************************************************************
'* Name : Base_new_5.bas *
'****************************************************************
' RA2 as DQ for DS18B20
' RB3 as output to 0AC5A
' for 16F628A
#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _LVP_OFF & _CP_OFF & _PWRTE_ON & _MCLRE_OFF & _BOREN_ON
#ENDCONFIG
'1 - RA2 - DQ for DS18B20
'2 - RA3
'3 - RA4
'4 - RA5
'5 - Vss
'6 - RB0
'7 - RB1
'8 - RB2
'9 - RB3 - output pin for OAC5A
'10 - RB4
'11 - RB5
'12 - RB6
'13 - RB7
'14 - Vdd
'15 - RA6
'16 - RA7
'17 - RA0
'18 - RA1
OPTION_REG.7 = 0 ' turn on weak pullups
CMCON = 7 ' comparitors off port set for digital
VRCON = 0 ' A/D Voltage reference disabled
TRISA = %00000100 ' A2 as input all others outputs
TRISB = %00000000 ' all are outputs
Comm_Pin VAR PortA.2 ' One-wire Data-Pin on PortA.2
Sign VAR BYTE ' +/- sign for temp display
RAWTEMP VAR WORD 'Read raw temperature from DS18B20
VeryCold VAR RAWTEMP.Bit11 ' Sign-Bit for +/- Temp. 1 = Below 0 deg C
Busy VAR BIT
SetPoint var byte
s var byte
setpointhigh var byte
setpointlow var byte
setpointlow = 5
setpointhigh = 7
high portb.3 'no power for 30 seconds
pause 30000
low portb.3 'power for 30 second to verify it is on
PAUSE 30000
high portb.3 'no power until requested
' s = 0
Main:
gosub Start_Convert ' get temperature reading
if VeryCold = 1 then 'if the bit is set then turn heater on for 5 minutes
low portb.3
gosub FiveMinute
endif
RAWTEMP = RAWTEMP */1600
RAWTEMP = RAWTEMP / 100 'convert to degrees C
if RAWTEMP <= setpointlow - 1 then ' on setpoint = turn heater on
low portb.3
gosub TenMinute
endif
if RAWTEMP >= setpointhigh then ' off setpoint = turn heater off
high portb.3
endif
pause 1000 ' wait 1 second
goto Main ' do it again
TenMinute:
for s = 1 to 10
pause 60000
next s
s = 0
return
FiveMinute:
for s = 1 to 5
pause 60000
next s
s = 0
return
Start_Convert:
OWOUT Comm_Pin, 1, [$CC, $44] ' Skip ROM search & do temp conversion
Wait_Up:
OWIN Comm_Pin, 4, [Busy] ' Read busy-bit
' pauseus 25
IF busy = 0 THEN Wait_up
OWOUT Comm_Pin, 1, [$CC, $BE] ' Skip ROM search & read scratchpad memory
OWIN Comm_Pin, 2, [RAWTEMP.LowByte, RAWTEMP.HighByte] ' OWIN can read in a BIT or a BYTE
return
Thanks
Harold
Bookmarks