Problems with my "intelligent timer"


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582

    Default Problems with my "intelligent timer"

    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 !
    Code:
    @ 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
    Attached Images Attached Images

  2. #2
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Problems with my "intelligent timer"

    Shouldn't it be

    Led HIGH and Led LOW

  3. #3
    Join Date
    May 2009
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Re: Problems with my "intelligent timer"

    I do not see any start timer sub routine in your code.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Problems with my "intelligent timer"

    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.
    DT

  5. #5
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Problems with my "intelligent timer"

    Thanks for reply !
    =============
    How can I avoid to stop the timer immediately after pressing buton ?!?
    I want to counting seconds while button is pressed ....

  6. #6
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Problems with my "intelligent timer"

    I did it again !

    Code:
    @ 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 !
    Last edited by fratello; - 6th July 2012 at 11:04.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts