View previous topic :: View next topic |
Author |
Message |
Guest
|
oscillator clock and delay |
Posted: Wed Feb 16, 2005 10:17 am |
|
|
Iam a newbie to microcontrollers and PIC's
I am using
16F870
MPLAB v6.60
PIC Start Plus
PIC C Compiler
I want to know the relationship between the
Oscillator frequency,
# use delay(clock = ...........) and
delay_ms(......) functions in PICC compiler
Couldnot find any where, any help is appreciated....
Thanks, |
|
![](templates/subSilver/images/spacer.gif) |
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Wed Feb 16, 2005 10:55 am |
|
|
The delay_ms() and delay_us() functions need to know the clock oscillator speed so the compiler can configure the functions and the function calls appropriately.
Enter the wrong value for #use delay(clock=#####) and your software delays (and probably software UART too) will be off by the ratio of the actual clock speed and what you entered. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
![](templates/subSilver/images/spacer.gif) |
theMagni
Joined: 21 May 2004 Posts: 48 Location: Victoria, BC
|
|
Posted: Wed Feb 16, 2005 10:58 am |
|
|
All you have to do is put in the speed of your oscillator in the delay block, and then when you call the function delay_ms(X) or delay_us(X), you delay by X ms or us.
So, for a 4MHz clock, you just put this line somewhere:
#use delay( clock=4000000 )
I put mine up at the top near the #defines, but it's up to your coding style.
From then on in the code, you can just include the line:
use_delay( 500 );
to wait for 1/2 a second. 500 can be any long value.
Note that your watchdog timer may go off during a delay loop. You can change the line to this:
#use delay( clock=4000000, RESTART_WDT )
to prevent that. I had horrible problems resetting my WDT with the #use delay.
You can check out the manual under "#use delay" for more details. _________________ In the 90's, I promised myself I'd never use a so-called "smiley icon". I hate what I've become. ;) |
|
![](templates/subSilver/images/spacer.gif) |
|