65 seconds.


Closed Thread
Results 1 to 3 of 3

Thread: 65 seconds.

  1. #1
    Tomas's Avatar
    Tomas Guest

    Default 65 seconds.

    Hi everybody,
    I'm storing some A2D results to my 24LC256 using I2CWRITE, it is working perfectly.
    When a particular pin is set i want the program to jump to a small routine, some loop, and excute the loop for 65 seconds.
    My question is how do i get roughly 65 seconds. I'm using a
    @ SLEEP command in other part of my code and i don't want to enable watchdog timer because i want the PIC to wake up when an RB.0 interrupt occurs, this part is working and i want to leave it as it is.
    I tried to count the firaction of seconds when TMR0 overflow interrupt occurs but for some reason, i think i'm using @ sleep, TMR0 interrupt is not working. Does Timer0 runs when the PIC is sleeping?
    So how can i get 65 second without using TMR0 interrupt. The time doesn't necessarly be exact but around a minute.

    Regards,
    Tom.

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Hi,

    You could try this...

    FOR i = 1 to 65000
    'Do stuff in loop
    PAUSE 1 'ms
    NEXT i

    Also, you could time exactly how long it takes to do the task in your loop, subtract that from 1000us and then use PAUSEUS.
    For instance, if it takes 100us to perform the code in the loop, simply use "PAUSEUS 900" for your delay.

    To time the loop code, write a quick program that simply performs the loop code endlessly and toggle a pin each time through the loop. You should be able to check it out on the scope and get a rough idea of how many microseconds it takes.

    Cheers.
    Last edited by picnaut; - 31st March 2004 at 05:34.
    ---> picnaut

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    It's not going to happen the way you want. TMR0 even with the prescaler attached will not be able to give you 65 seconds. The same applies for TMR1 and TMR2. Futher, the obvious clock souces for the Timers are also halted during sleep.

    But there's heaps of alternate solutions... here's one to get you thinking...

    To achieve Low-Power consumption for the majority of the time, use NAP (example NAP 4 which is approximately 288mS), poll the keyboard to see if a button has been pressed, increment a timeout counter and go take another Nap...

    TimeOut var Byte
    .. ..

    ' Nap Entry Point
    NapStart:
    TimeOut=0
    ' Main Nap Loop
    NapLoop:
    NAP 4 ' Suspend reality for 288mS
    If PortB.0=0 then goto KeyPressed
    TimeOut=TimeOut+1
    If TimeOut < 225 then Goto NapLoop
    ' Process 65 Second Timeout here

    In this example, every approx quarter of a second, you poll the keyboard and check for key depression, and if less than 65 seconds have elapsed (0.288mS x 225 loop counts) then you simply just Nap again. This way, about 99.9% of the time you'll be asleep in low-power mode.

    If polling the keyboard every 288mS is insufficient, then go to NAP 3, but you'll have to increase the loop-count for the 65 second timeout appropriately (if you do this then you'll have to make the TimeOut variable a WORD rather than a BYTE).

    Melanie

Similar Threads

  1. Virtual LED Clock For Windows By Trent Jackson
    By T.Jackson in forum Code Examples
    Replies: 8
    Last Post: - 10th November 2009, 08:20
  2. 1 minute 30 seconds
    By Leonardo in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 28th November 2008, 15:51
  3. new and need help
    By smeghead in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2008, 20:19
  4. DS1994 Memory/Time iButton
    By NavMicroSystems in forum mel PIC BASIC Pro
    Replies: 47
    Last Post: - 22nd October 2006, 11:55
  5. Pin High for 13 seconds while....
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th June 2005, 00:36

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