Can anyone tell me why nap & sleep won't work with the 18F452?


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks Bruce,

    I think I understand what was happening now. After implementing your code example I found that the NAP's were giving me the same pause period as the sleep command. I was using a bunch of nap's in my mainloop and that's why my program slowed down so much. I do need shorter delays in sleep than the 2.3 seconds @ 128 so I guess I'll have to lower the WTD timer postscaler to the smallest delay that I anticipate using then use multiple commands for the required longer delays that I need. I hope that doesn't increase my current draw but I guess I'll know soon enough.

    I changed the sleep times just to see what I'd get and I found that a setting of sleep 5 would give me approximately 6 seconds and then sleep 6 would give the same results. Then sleep 7 gave me a pause time of approx. 8 seconds and sleep 8 & 9 yielded the same. Is there any rhythm or rime to that? I guess I'll have to check the times for whatever values I'm using to be sure. Also I read somewhere that the sleep times will change with temperature as well.

    I've never seen code like your While X Wend code, I compiled a For..Next to compare and the for..next uses 2 bytes more to compile, is that why you used it? Another question, why did you use PORTD = PORTD ^ 1 in that code snip? I couldn't understand what it was doing in there and also if you could tell me, what does PORTD = 1 and TRISD = 0 do in pbp code? I'll be interested to hear your reply on that.

    Thanks Again
    jessey

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Jessey,

    Also I read somewhere that the sleep times will change with temperature as well.
    SLEEP uses the PIC WDT (watchdog timer) that's clocked by an internal RC oscillator. RC oscillators are affected by temperature, so timing can/will vary like the wind depending on temperature.

    Look in the Electrical Characteristics section of the data sheet (Table 22-7 in mine for the 18F452). You'll notice the WDT time-out period can be anywhere from 7mS min to 33mS max, so you should never expect precise time periods when using the WDT.

    I've never seen code like your While X Wend code, I compiled a For..Next to compare and the for..next uses 2 bytes more to compile, is that why you used it?
    Not really. I just used it as a quick example. There are several ways to get similar results. I just prefer using WHILE..WEND.

    Another question, why did you use PORTD = PORTD ^ 1 in that code snip? I couldn't understand what it was doing in there and also if you could tell me, what does PORTD = 1 and TRISD = 0 do in pbp code?
    I used PORTD because I used a LAB X1 board for the test, and it has an LED bargraph on PORTD.

    PORTD = 1 is the sames as PORTD = %00000001. This just writes a 1 to the port to control the LED on PORTD.0.

    TRISD = 0 simply makes all of the PORTD pins outputs, but all this stuff is covered in the PIC data sheet.

    PORTD = PORTD ^ 1 is Exclusive ORing PORTD with 1 & toggling the LED on & off. The LED was used for a visual timing indicator.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 10:00
  2. Sleep & nap
    By keymuu in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 4th December 2008, 19:45
  3. Char. LCD and 18F452 on 20 MHz not work
    By samettin in forum General
    Replies: 11
    Last Post: - 28th July 2008, 10:59
  4. How do I get DATA @ to work with a 18F452?
    By jessey in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 2nd February 2006, 11:35
  5. Why doesn't my code for 18f452 work on 18f252?
    By senojlr in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 23rd December 2005, 03:42

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