PDA

View Full Version : Problems with my "intelligent timer"



fratello
- 5th July 2012, 11:31
I try to make an intelligent timer. Schematic is attached ; I try to explain what I intend to do ...
Conect the PIC to power source. LED is OFF.
When press for the first time the button, the timer begin to counting seconds while GPIO.5 is "0" and the counted seconds becomes the wipe_time, in seconds, while LED is ON.
At next (second) press of button, LED is ON for wipe_time seconds (previously stored).
At next (third) press of button, the timer begin again to counting another value of wipe_time (while GPIO.5 is on).
And so on, and so on ...
Unfortunately the hardware not react as expected ; LED is always ON ...Can figure out what I do wrong :( ... Thanks in advance for support !

@ Device PIC12F675,INTRC_OSC_NOCLKOUT, WDT_OFF,PWRT_ON,PROTECT_OFF,MCLR_OFF,BOD_OFF
Include "C:\WIPPER\Elapsed.bas" ' just wsave(s) removed
CLEAR
DEFINE OSC 4
ANSEL=0
CMCON=7
TRISIO=%00100000

LED VAR GPIO.0 ; sets the GPIO.0 port as LED
wipp_time var byte ; number of seconds while LED=off
nr var bit

nr = 0
wipp_time = 2

Gosub ResetTime ' Reset Time to 0d-00:00:00.00

loop:
led = 0
IF GPIO.5 = 0 THEN
nr=nr+1
if nr=1 then ' Setting wipe_time for the first time
gosub StartTimer
ELSE
GOSUB WIPPER ' use pre-setting of wipe_time
ENDIF
ENDIF
GOSUB END_sett
if nr = 2 then nr = 0 ' ready for another setting of wipe_time
goto loop

END_sett:
gosub StopTimer
wipp_time = seconds ' seconds counts from the beginning of gpio.5 = 0
NR=1
GOSUB WIPPER
Gosub ResetTime
RETURN

wipper:
LED = 1
PAUSE 1000
LED = 0
PAUSE (wipp_time * 1000)
return

END

tasmod
- 5th July 2012, 14:36
Shouldn't it be

Led HIGH and Led LOW

grahamg
- 5th July 2012, 21:57
I do not see any start timer sub routine in your code.

Darrel Taylor
- 5th July 2012, 23:50
Fratello,

You don't wait for the button to be released.
If it's pressed you start the timer, then immediately GOSUB END_sett which stops the timer and stores the number of seconds that have passed.

But no seconds have passed.

If you put a scope on the LED pin, you'll see that it's not "always on". It pulses low very breifly every 1 second.

fratello
- 6th July 2012, 06:59
Thanks for reply !
=============
How can I avoid to stop the timer immediately after pressing buton ?!?
I want to counting seconds while button is pressed ....

fratello
- 6th July 2012, 11:00
I did it again !


@ Device PIC12F675,INTRC_OSC_NOCLKOUT, WDT_OFF,PWRT_ON,PROTECT_OFF,MCLR_OFF,BOD_OFF
Include "C:\WIPPER\Elapsed.bas" ' just wsave(s) removed
CLEAR
DEFINE OSC 4
ANSEL=0
CMCON=7
TRISIO=%00100000

LED VAR GPIO.0 ; sets the GPIO.0 port as LED
wipp_time var byte ; number of seconds while LED=off
nr var bit

nr = 0
low led
Gosub ResetTime ' Reset Time to 0d-00:00:00.00

loop:
IF GPIO.5 = 0 THEN
nr=nr+1
if nr=1 then
gosub memo ' Setting wipe_time
else
GOSUB WIPPER ' use seconds elapsed as wipe_time
nr = 0 ' ready for another setting of wipe_time
endif
if nr > 2 then nr = 0
endif
goto loop

memo:
gosub StartTimer
while gpio.5 = 0
wipp_time = seconds ' seconds counts from the beginning of gpio.5 = 0
wend
Gosub StopTimer
Gosub ResetTime
return


wipper:
while gpio.5 = 0
LED = 1
PAUSE 1000
LED = 0
PAUSE (wipp_time * 1000)
wend
return

END ' of story !
Thanks for support !

fratello
- 30th August 2012, 21:03
Ooooooops !!!
I build the schematic and I found a BIG issue !!! For value of "wipp_time" bigger than 10 seconds or so ..., if gpio.5 return to "1" BEFORE these seconds, then the counter dont increment ?! At next command (gpio.5=1) programs go to wipper instead memo ! Any ideea ?! Thanks !

fratello
- 31st August 2012, 19:37
I think in this subroutine the "pause xxx" commands make problems... It's another way to do this ?

wipper:
while gpio.5 = 0
LED = 1
PAUSE 1000
LED = 0
PAUSE (wipp_time * 1000) ; this command run for (wipp_time * 1000) seconds even gpio.5 is no more = 0 ?!?
wend
return

tasmod
- 3rd September 2012, 18:03
How about something like a 'for next' loop:-

For wipp_time = 1 to 10 ;adjust for your required timing delay
Next wipp_time

fratello
- 3rd September 2012, 21:35
Thanks for reply...but wipp_time dont have just 1 to n value ...It's "seconds elapsed between two pushing of button @gpio.5" !
I dont understand why in "while...wend" command, the failure of condition " gpio.5 = 0" dont stop the "pause (wipp_time * 1000)" command and dont return to master (loop) :( ...

aratti
- 3rd September 2012, 22:39
You have to write:

Delay VAR word

Wipper:
Delay = wipp_time * 1000
While gpio.5 = 0
Pause 1000
Led = !Led
If Delay= 0 then Skip_0
Pause 1
Delay = Delay - 1
Skip_0:
Wend
Return


Cheers

Al.

fratello
- 4th September 2012, 06:57
Thank You !
...but the schematic dont work if I wish :( ...

@ Device PIC12F675,INTRC_OSC_NOCLKOUT, WDT_OFF,PWRT_ON,PROTECT_OFF,MCLR_OFF,BOD_OFF
Include "C:\WIPPER\Elapsed.bas" ' just wsave(s) removed
CLEAR
DEFINE OSC 4
ANSEL=0
CMCON=7
TRISIO=%00100000

maneta var gpio.5
LED var GPIO.2 ' set GPIO.0 port as OUTPUT (LED)
wipp_time var byte ' number of seconds while LED=off
nr var bit
delay var word

nr = 0
low LED
Gosub ResetTime ' reset Time to 0d-00:00:00.00

Main:
IF GPIO.5 = 1 then
nr=nr+1
if nr=1 then
gosub memo ' set wipe_time
else
gosub wipper ' use seconds elapsed as wipe_time
nr = 0 ' ready for another setting of wipe_time
endif
if nr > 2 then nr = 0
ENDIF
Goto Main

memo:
gosub StartTimer
while maneta = 1
wipp_time = seconds ' seconds counts from the beginning of gpio.5 = 0
wend
Gosub StopTimer
Gosub ResetTime
return


Wipper:
Delay = wipp_time * 1000
While gpio.5 = 1
Pause 1000
Led = !Led
If Delay= 0 then Skip_0
Pause 1
Delay = Delay - 1

Skip_0:
Wend
Return

fratello
- 5th September 2012, 20:20
There are other advices ?! Please !

fratello
- 20th September 2012, 07:08
I think it's a problem with the title of my topic ... since me I am not intelligent enough to solve this !
I try another way :

@ Device PIC12F675,INTRC_OSC_NOCLKOUT, WDT_OFF,PWRT_ON,PROTECT_OFF,MCLR_OFF,BOD_OFF

CLEAR
DEFINE OSC 4
ANSEL=0
CMCON=7
TRISIO=%00100000

maneta var GPIO.5
LED var GPIO.2 ' set GPIO.0 port as OUTPUT (LED)
wipp_time var word ' number of seconds while LED=off
nr var word

nr = 0

Main:
IF maneta = 1 then
nr = nr + 1
if nr= 1 then
gosub memo
else
gosub wipper
endif
ENDIF
Goto Main

memo:
while maneta = 1
low led
wipp_time = wipp_time + 1 ' counting in 100 ms steps
pause 100
wend
nr = 1
return

Wipper:
while maneta = 1
high led
pause 1000
low led
pause wipp_time * 100
wend
nr = 0
wipp_time = 0
Return
Without results ! Variable "nr" seems to NOT increase ...I push "maneta", then go to memo, I push again, then go to wipper, I push again, then go to wipper again ?!?

Demon
- 21st September 2012, 18:23
Sorry Fratello, but your thread title excludes me from this discussion. :D

I wish I could help you but this is over my head. I have enough problem keeping concentrated on my own little project.

Robert

fratello
- 21st September 2012, 19:06
Thanks anyway for attention !
How I say :
Re: Problems with my "intelligent timer"
I think it's a problem with the title of my topic ... since me I am not intelligent enough to solve this !
...to note the use of quotes in first row...
This is my working (in Proteus) code, i will try it tomorrow :

MAIN:
led1=0
led2=0
pause 50
if but1=1 then
cnt = cnt+ 1
if cnt = 1 then
while but1=1
gosub memo
wend
endif

if cnt = 2 then
while but1=1
gosub check
wend
endif

if cnt > 2 then cnt=0
endif
Goto MAIN

'================================================= =
check:
high led2
pause 500
low led2
for num = 0 to 500
pause wipper
call breking ' this is the new part added !!!
next num
return

breking:
if but1 = 0 then
wipper = 0
goto main
endif
return

memo:
high led1
wipper = wipper + 1 ' counting in 500 ms steps
pause 500
low led1
pause 500
RETURN
Best regards !