I've been reworking my pwm fan control a bit. I have a bit of ADC jitter when the fan is inside my computer - on the bench it works fine. So I added averaging to the thermistor input. While I'm at it I thought I could rework the alarms too.
What I want is the fan pwm control to work normally while an alarm is sounding and I want the alarm to sound no more than once every ten minutes - and alarm progressively as the temp continues to rise (alarm point one beeps the horn once, two twice, three thrice, etc..)
Could someone peruse my code and see how I can compact the code a bit to eliminate the 7 bytes over? I'm no software wizz so there's probably some obvious better way to do it.
What I want is the fan pwm control to work normally while an alarm is sounding and I want the alarm to sound no more than once every ten minutes - and alarm progressively as the temp continues to rise (alarm point one beeps the horn once, two twice, three thrice, etc..)
Could someone peruse my code and see how I can compact the code a bit to eliminate the 7 bytes over? I'm no software wizz so there's probably some obvious better way to do it.
Code:
'08M
'This should average the thermistor 60 times over the course of .6 seconds
'Then the pwm should continue normally while high temp alarms go off
'The high temp alarms should only alarm once every ten minutes
'Error: Memory full - 7 bytes over. Reduce program length by 7 bytes
symbol analogcontrol = 1 'This is the ADC input pin
symbol anaval = w1 'raw analog value
symbol anaavg = w2 'averaged analog value
symbol pwmport = 2 'pwm output on out#2
symbol buzzer = 4 'alarm buzzer output on out#4
goto runn
runn:
for b11=1 to 60 'averages 60 readings of thermistor
readadc10 analogcontrol ,anaval
anaval = anaval + anaval
pause 10
Next
anaavg = anaval / 60 'calculate average
anaavg = anaavg *2 'massage values to something the fan can use
anaavg = anaavg -790
if anaavg <= 10 then alarmx 'sensor failure alarm (open)
if anaavg>= 700 then alarmx 'sensor failure alarm (shorted)
if anaavg <= 120 then stop1 'fan stops if temp too low
pwmout pwmport, 100, anaavg 'on/off pwm ratio based on temperature
if anaavg<= 415 then runn 'no alarms proceed normally
pause 2350 'necessary pause to limit alarms to every 10 minutes
if anaavg>= 415 then gosub setflag
' if anaavg>= 495 then alarm5 'temperature critical
if anaavg>= 475 then alarm4
if anaavg>= 455 then alarm3
if anaavg>= 435 then alarm2
if anaavg>= 415 then alarm1 'temperature warm
goto runn
setflag: 'increments a counter (b12)
b12 = b12 + 1
return
resetflag: 'clears counter (b12)
b12 = 0
return
stop1:
pwmout pwmport, 0, 0 'stops fan entirely when temperature is low
goto runn
alarm1:
if b12 <= 254 then runn 'alarm once every `10 minutes (or greater)
if b12 >= 254 then gosub resetflag '2350 ms pause multiplied by 254 times
high buzzer 'turn on buzzer for 1/3 second
pause 300
low buzzer 'buzzer hi temp alarm
goto runn
alarm2:
if b12 <= 254 then runn 'the alarm once every `10 minutes (or greater)
if b12 >= 254 then gosub resetflag '2350 ms pause multiplied by 254 times
for b13=1 to 2
high buzzer
pause 200 'turn on buzzer for 2/10 second
low buzzer 'buzzer hi temp alarm
pause 200
next
goto runn
alarm3:
if b12 <= 254 then runn 'the alarm once every `10 minutes (or greater)
if b12 >= 254 then gosub resetflag '2350 ms pause multiplied by 254 times
for b13=1 to 3
high buzzer 'turn on buzzer for 2/10 second
pause 200
low buzzer 'buzzer hi temp alarm
pause 200
next
goto runn
alarm4:
if b12 <= 254 then runn 'the alarm once every `10 minutes (or greater)
if b12 >= 254 then gosub resetflag '2350 ms pause multiplied by 254 times
for b13=1 to 4
high buzzer 'turn on buzzer for 2/10 second
pause 200
low buzzer 'buzzer hi temp alarm
pause 200
next
goto runn
alarm5:
if b12 <= 254 then runn 'the alarm once every `10 minutes (or greater)
if b12 >= 254 then gosub resetflag '2350 ms pause multiplied by 254 times
for b13=1 to 5
high buzzer 'turn on buzzer for 2/10 second
pause 200
low buzzer 'buzzer hi temp alarm
pause 200
next
goto runn
alarmx:
pwmout pwmport, 0, 0 'stops pwm
high pwmport 'sends DC voltage to fan (no pwm)
high buzzer
pause 1000
low buzzer 'buzzer sensor failure alarm
pause 400
low pwmport
goto runn