Timer up to 48hours, 50Hz interrupt driven

cebersp

New Member
This is my very first project with a PICAXE.
I am very impressed of the simplicity of the handling of this little system!

This is a timer for up to 48 hours, which is used to shut off a dryer for shoes after the chosen time.

The hardware consists of:
1. Mains power supply with a converter that gives the power and a 50Hz timer signal. The power for the relay is not stabil.
2. A FET-driver for the relay and the relay.
3. A two colour LED to give feedback of the remaining time.
4. A reset switch (short cut) and a potentiometer to start the timer and to have input for the time.

The software consists of
1. Reading the potentiometer and calculating the desired time, which is nonlinear to have fine adjustment for short times.
2. The time counter (down) which is interrupt driven from the 50Hz signal. – I don’t know, if sometimes some impulses are lost, but for times of about one minute it seemed to work correct. And for this application this is not critical.
3. The relay is not simply switched but the pwm output is used for lower power consumption. At the start the “on-percentage” is higher than for the long remaining “on” time.
4. Time signal using the two colour LED.
• First the green led blinks n times
• Then the red led blinks f times f stands for a factor which is 1*, 5* or 25*
• Third the green led blinks one time for minutes and two times for hours.
• Example: 2 blinks green, 2 blinks red, 2 blinks green stands for: 2*5= 10 Minutes left.

Has anyone other good ideas showing a number with blinking lights?

Have fun with the picaxe.:D
21.10.2007 CWE
 

cebersp

New Member
Code and circuit

Sorry I have problems with the attachment, that is very limited in size. I would have posted the circuit.
Christof



Code:
' Zeitschalter
' CWE 11.10.2007


' PORTS
symbol prelais= 2 'out via FET
symbol prot = 0 'LED
symbol pgruen = 4 'LED
symbol ppoti = 1 'Potentiometer in
symbol pnetz = 3 '50Hz Netzfrequenz

'Vars
symbol sec50 = w6
symbol mins = b11
symbol hours = b10


symbol code = b6
symbol numc = b7
symbol numb = b8
symbol i = b9





Start:
low prelais
low prot
low pgruen
pause 500 ' Spannung stabilisieren

adc:
readadc ppoti,w0

w1= w0/7
w2 = w1*w1*w1
w3 = w2/16
hours = w3/60
mins= w3//60


debug
'goto adc ' nur zum Kalibrieren

if hours=0 and mins=0 then
end
endif

pwmout prelais, 50, 100
pause 50 ' funktioniert ab 20

pwmout prelais, 50, 50 ' erste Zahl *4 = Zykluszeit, zweite Zahl ist Anteil "ein" funktioniert ab 35/200 = 1,83V bei 11,2V an 5V Relais


setint %00001000, %00001000 ' warte auf positiv an Netzfrequenzeingang

main:
if hours = 255 then
pwmout prelais, 0, 0
low prelais
setint 0,0
end
endif


ledcode: ' Zunächst Grüne LED: Zahl, dann Rote: 1=Faktor1, 2=Faktor 5, 3=Faktor25, damm Grün: 1=Minuten, 2=Stunden

numb= mins + 1
code= 1

if hours>0 then
numb= hours
code= 2
endif

'codeausgabe
numc= 1
if numb > 25 then
numb = numb/25
numc = 3
elseif numb > 5 then
numb = numb/5
numc= 2
endif

'zahlenwert
for i = 1 to numb
high pgruen
gosub delayk
low pgruen
gosub delayk
next i

gosub delay1

'faktorcode
for i = 1 to numc
high prot
gosub delayk
low prot
gosub delayk
next i

gosub delay1

'Einheitencode
for i = 1 to code
high pgruen
gosub delayk
low pgruen
gosub delayk
next i



gosub delay5

debug

gosub delay5


goto main



end








delay5:
w0= sec50 + 250 ' 5 sec
goto delay

delayk: ' Zeitverzögerung kurz
w0= sec50 + 15
goto delay

delay1: ' Zeitverzögerung 0,5 sekunde
w0= sec50 + 25
delay:
if w0 > 2999 then
w0=w0-3000
endif
delay11: if w0<>sec50 then delay11
return


interrupt: ' sec50 wird mit Netzfrequenz erhöht
inc sec50
if sec50 = 3000 then
sec50 = 0
dec mins
if mins = 255 then
mins= 59
dec hours
endif
endif
iloop: ' Warten auf negativ
if pin3 = 1 then iloop
setint %00001000, %00001000 ' warte auf positiv
return
 
Top