CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

oscillator clock and delay

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








oscillator clock and delay
PostPosted: Wed Feb 16, 2005 10:17 am     Reply with quote

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,
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Wed Feb 16, 2005 10:55 am     Reply with quote

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!
theMagni



Joined: 21 May 2004
Posts: 48
Location: Victoria, BC

View user's profile Send private message Visit poster's website

PostPosted: Wed Feb 16, 2005 10:58 am     Reply with quote

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. ;)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group