Elapsed Timer Demo in a PIC12F675


Closed Thread
Results 1 to 17 of 17
  1. #1

    Default Elapsed Timer Demo in a PIC12F675

    Hello,

    How to use the Elapsed Timer Demo in a PIC12F675 to maintain a on led by 5 days and then goes off. ¿It is possible to do this?

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    If you just want 5 days then -

    LED = ON

    For X = 1 to 7200 (60 minutes/hour X 24 hours/day X 5 days)
    PAUSE 60000 ; one minute
    Next X

    LED = OFF
    Charles Linquist

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    If you just want 5 days then -

    LED = ON

    For X = 1 to 7200 (60 minutes/hour X 24 hours/day X 5 days)
    PAUSE 60000 ; one minute
    Next X

    LED = OFF
    Hey Charles,

    Thanks for your answer but my concern is whether you can do with the Elapsed Timer because it seems to me a good idea.

    Thanks

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi, Leonardo

    looks Still some way to reach Leonard's code ...

    ALL you have to do is check each second ( or min, if not so precise required !!!) Days-hours-mins-secs ( which are already existing variables ) and match your own values.

    But forget the // LCD screen ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Leonardo

    looks Still some way to reach Leonard's code ...

    ALL you have to do is check each second ( or min, if not so precise required !!!) Days-hours-mins-secs ( which are already existing variables ) and match your own values.

    But forget the // LCD screen ...

    Alain
    Hello Acetronics,

    You can give me an idea or an example to start.

    Thank you

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    If you just want 5 days then -

    LED = ON

    For X = 1 to 7200 (60 minutes/hour X 24 hours/day X 5 days)
    PAUSE 60000 ; one minute
    Next X

    LED = OFF
    Hello,
    This is the code I've tested with 1 minute and works well, then put 7200 can achieve the 5 days with a good presicion?.

    [HTML]led1 var portb.0
    x var word

    HIGH LED1

    Top:

    For X = 1 to 1 '(60 minutes/hour X 24 hours/day X 5 days)
    PAUSE 60000 ; one minute
    Next X

    LOW LED1

    goto Top[/HTML]


    Thank you

  7. #7
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    The accuracy will be good if you are not using the internal oscillator. You need a crystal or external "can" oscillator for better than 2-3%. If you need really good accuracy, you can (temporarily) shorten the time interval to one day (or so) and compare it to a clock. For example: if you are 1.3% "fast" then increase the value after the PAUSE by 1.3% (60780). That should get you close enough.
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default

    Yup, that'll work.
    As long as it's the only thing the chip will be doing.

    But to answer the original question...
    > How to use the Elapsed Timer Demo in a PIC12F675 to maintain a on led by 5 days and then goes off
    Code:
    CLEAR
    LED        VAR GPIO.0
    CMCON = 7
    ANSEL = 0
    
    Include "Elapsed.bas"
    
    Gosub ResetTime                ' Reset Time to  0d-00:00:00.00
    Gosub StartTimer               ' Start the Elapsed Timer
    
    HIGH LED                         ; Start with LED on
    
    Loop:
        if DaysChanged then  
           DaysChanged = 0
           if Days = 5 then LOW LED  ; Turn off LED
        endif
    Goto Loop
    Or you can add a blinky LED to show that it's still counting...
    Code:
    CLEAR
    LED        VAR GPIO.0
    StatLED    VAR GPIO.1
    CMCON = 7
    ANSEL = 0
    
    Include "Elapsed.bas"
    
    Gosub ResetTime                ' Reset Time to  0d-00:00:00.00
    Gosub StartTimer               ' Start the Elapsed Timer
    
    HIGH LED                         ; Start with LED on
    
    Loop:
        if DaysChanged then  
           DaysChanged = 0
           if Days = 5 then LOW LED  ; Turn off LED
        endif
        
        IF SecondsChanged then
           SecondsChanged = 0
           Toggle StatLED
        endif
    
        ; Rest of the program goes here
    Goto Loop
    And you can still do other stuff at the same time.
    DT

  9. #9


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Yup, that'll work.
    As long as it's the only thing the chip will be doing.

    But to answer the original question...
    > How to use the Elapsed Timer Demo in a PIC12F675 to maintain a on led by 5 days and then goes off
    Code:
    CLEAR
    LED        VAR GPIO.0
    CMCON = 7
    ANSEL = 0
    
    Include "Elapsed.bas"
    
    Gosub ResetTime                ' Reset Time to  0d-00:00:00.00
    Gosub StartTimer               ' Start the Elapsed Timer
    
    HIGH LED                         ; Start with LED on
    
    Loop:
        if DaysChanged then  
           DaysChanged = 0
           if Days = 5 then LOW LED  ; Turn off LED
        endif
    Goto Loop
    Or you can add a blinky LED to show that it's still counting...
    Code:
    CLEAR
    LED        VAR GPIO.0
    StatLED    VAR GPIO.1
    CMCON = 7
    ANSEL = 0
    
    Include "Elapsed.bas"
    
    Gosub ResetTime                ' Reset Time to  0d-00:00:00.00
    Gosub StartTimer               ' Start the Elapsed Timer
    
    HIGH LED                         ; Start with LED on
    
    Loop:
        if DaysChanged then  
           DaysChanged = 0
           if Days = 5 then LOW LED  ; Turn off LED
        endif
        
        IF SecondsChanged then
           SecondsChanged = 0
           Toggle StatLED
        endif
    
        ; Rest of the program goes here
    Goto Loop
    And you can still do other stuff at the same time.
    Hey Darrel,

    In compiling I get this error because it will be.

    <a href="http://imageshack.us"><img src="http://img231.imageshack.us/img231/9863/errorcv5.jpg" border="0" alt="Image Hosted by ImageShack.us"/></a><br/><a href="http://g.imageshack.us/img231/errorcv5.jpg/1/"><img src="http://img231.imageshack.us/img231/errorcv5.jpg/1/w626.png" border="0"></a>

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    open ASM_INTS.bas file, there you'll discover ..
    Code:
    ' --- IF any of these three lines cause an error ??  Simply Comment them out to fix the problem ----
    wsave1      var byte    $A0     SYSTEM          ' location for W if in bank1
    wsave2      var byte    $120    SYSTEM          ' location for W if in bank2
    wsave3      var byte    $1A0    SYSTEM          ' location for W if in bank3
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  11. #11


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    open ASM_INTS.bas file, there you'll discover ..
    Code:
    ' --- IF any of these three lines cause an error ??  Simply Comment them out to fix the problem ----
    wsave1      var byte    $A0     SYSTEM          ' location for W if in bank1
    wsave2      var byte    $120    SYSTEM          ' location for W if in bank2
    wsave3      var byte    $1A0    SYSTEM          ' location for W if in bank3
    Steve,

    Did not take into account the memory banks and compiles well, will do some tests and the results then I said.

    Thank you
    Last edited by Leonardo; - 17th November 2008 at 18:25.

  12. #12


    Did you find this post helpful? Yes | No

    Default

    Steve,

    I've done some testing with minutes and works extremely well using a 4-MHz crystal, the oscillator's internal PIC12F675 is not very accurate there is any way to use it with good presicion?.

    Thank you

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


    Did you find this post helpful? Yes | No

    Default

    Try adding ...
    Code:
    DEFINE OSCCAL_1K 1
    when using the internal OSC.
    DT

  14. #14


    Did you find this post helpful? Yes | No

    Default

    Steve,

    Perform tests on a 4-MHz external crystal setting 1 hour and was led off in 56:41 minutes of taking a delay time of 3:06 minutes. Is it normal that delay?.

    Thank you

  15. #15
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Can't tell, i never used it before. Would be of great help if you could post the whole schematic, code and configuration fuses.

    I would guess you just use the internal OSC... probably where the huge gap come from.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  16. #16


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Can't tell, i never used it before. Would be of great help if you could post the whole schematic, code and configuration fuses.

    I would guess you just use the internal OSC... probably where the huge gap come from.
    Steve,
    I'm using an external 4MHz crystal and the code is this for PIC12F675.

    [HTML]CLEAR
    LED VAR GPIO.0
    CMCON = 7
    ANSEL = 0

    Include "Elapsed.bas"

    Gosub ResetTime ' Reset Time to 0d-00:00:00.00
    Gosub StartTimer ' Start the Elapsed Timer

    HIGH LED ; Start with LED on

    Loop:
    if HoursChanged then
    HoursChanged = 0
    if Hours = 1 then LOW LED ; Turn off LED
    endif
    Goto Loop[/HTML]

    Last edited by Leonardo; - 19th November 2008 at 18:37.

  17. #17


    Did you find this post helpful? Yes | No

    Default Delay 1:20 hours minutes

    Quote Originally Posted by mister_e View Post
    Can't tell, i never used it before. Would be of great help if you could post the whole schematic, code and configuration fuses.

    I would guess you just use the internal OSC... probably where the huge gap come from.
    Hello,

    I doubt arises as to obtain such a delay of 1:20 hours and minutes.

    Thanks

Similar Threads

  1. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 17:39
  2. Get elapsed time while TIMER samples pulses
    By RodSTAR in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th March 2009, 16:27
  3. Totally Baffled with Elapsed Timer
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th June 2008, 21:01
  4. SPWM and Elapsed Timer
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 8th May 2008, 03:16
  5. Darrel Taylor Elapsed Timer
    By rwskinner in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th March 2008, 01:22

Members who have read this thread : 1

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