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 support@ccsinfo.com

# use delay function

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








# use delay function
PostPosted: Mon Sep 03, 2007 7:55 am     Reply with quote

HI
Can somebody please tell me why mplab doesnt want to compile when i use DELAY_MS(20) function but when i use #USE DELAY(CLOCK = 2000) it works. Iwould prefer adressing the pic in seconds rather than cycles.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Mon Sep 03, 2007 9:08 am     Reply with quote

The compiler needs to know the clock frequency . CCS uses
#use delay(clock=xxxxxxx) to inform the compiler of the application hardwares frequency. As you would expect built in functions delay_us(x) delay_ms(x) also require knowledge of the clock frequency to compute the delays. You have to work with the compiler you have not the compiler you want. The compiler you have needs to see the #use delay before it can generate the timing you want.
Ttelmah
Guest







PostPosted: Mon Sep 03, 2007 9:15 am     Reply with quote

Understand first of all, that #use_delay, is a 'defintion', not a 'function'. It tells a wole lot of other parts of the code what values to use, to do things. The value in it, _must_ be the clock rate that the CPU is using, or timing delays won't work, nor will the serial interface (which is dependant on the clock rate), etc etc..
You need to set the delay to 20000000, assuming this is the rate you are using, or a whole lot of other parts will give problems.
Now, if you want a delay in seconds, then just write one.
Code:

void delay_seconds(int16 ctr) {
   while(ctr--) delay_m(1000);
}

As a comment, 'MPLAB', doesn't compile anything. It is not a compiler. It is a development enviroment, that can use 'MPASM' (included with it), or a huge range of compilers (including CCS). As such, talking about MPLAB 'compiling', could mislead people if you are using a different compiler 'behind' this.

Best Wishes
Ttelmah
Guest







PostPosted: Mon Sep 03, 2007 9:17 am     Reply with quote

Simultaneous replies I see. :-)
Should be 'delay_ms', not 'delay_m' in my code.

Best Wishes
Guest








PostPosted: Mon Sep 03, 2007 12:40 pm     Reply with quote

Thanks.

So just to make sure i understand corectly: The #use delay is not necesarily a delay before the next instruction, it is more involved with overall clock frequency. Is the delay_ms function one that actualy puts a delay before the next function??
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Mon Sep 03, 2007 2:11 pm     Reply with quote

Yes #use delay(clock=xxxxx) is to inform the compiler of your target device frequency thats all. Since frequency is essential to the delay_ms(x) delay_us(x) that may have been the reason for the choice of the syntax #use delay(clock=xxxx) but as others have mentioned any built in function dependent on the clock timing will make use of it also. The example given was a software UART . I include #use delay(clock=xxxx) it in all code since it at a minimum indicates the internal frequency of the device. The external clock can be different when using PLL capabilities of certain devices. If the external Xtal was 10mhz and a 4x increase is achieved by a devices PLL then code #use delay(clock=40000000) PICs are designed to complete almost all instructions in 4 clocks ( goto takes 8 clocks) so if you are running at an internal clock of 40000000 then 10 million instructions will absorb one second of time. For delay-ms and delay-us the compiler generates instructions to have the device execute enough NOP instructions to absorb the time and create the delay.
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