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

HELP! can #use delay=xxx take a #define value?

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



Joined: 26 Apr 2005
Posts: 7

View user's profile Send private message

HELP! can #use delay=xxx take a #define value?
PostPosted: Tue Apr 26, 2005 3:36 am     Reply with quote

In an effort to make my code configurable by a customer I want them only to have to change one define to enable the on board clock multiplier ( x 4) on a PIC18F452. This is done elsewhere in my code and works fine. The problem is that I want the '#use delay=xxx' preprocessor command to take a calculated value and not a constant. i.e.

This works fine...

#define _CRYSTAL_FRQ 16000000 //system clock frequency
#use delay(clock= _CRYSTAL_FRQ ) //Tells compiler the crystal speed

What I want to do is...

#define _CRYSTAL_FRQ 4000000 //system clock frequency
#define _PLL_ENABLED //hardware clock multiplier

#ifdef _PLL_ENABLED
#define _DELAY ( _CRYSTAL_FRQ * 4 )
#else
#define _DELAY _CRYSTAL_FRQ
#endif

#use delay(clock= _DELAY ) //Tells compiler the crystal speed

If I compile this I get "USE parameter value is out of range Expecting number: "

Can anybody help. Time is a factor now
Ttelmah
Guest







PostPosted: Tue Apr 26, 2005 4:38 am     Reply with quote

You can use a #define to set a clock frequency, but the 'result', must be a fixed number, not a 'sum'.
The problem is that the internal code for #use delay(clock=xxx), will only accept a number. The macro expansion, does not actual generate a 'number', but a sum, which then has to be solved. So:

#define CFREQ 4000000
#use delay(clock=CFREQ)

will work fine, but:

#define CFREQ 4000000*4
#use delay(clock=CFREQ)

won't...
Could you work the input 'backwards'?.
If you put in the processor frequency, with a statement like:

#define PROC_FREQ 16000000
#define PLL
#ifdef PLL
#define CRYSTAL PROC_FREQ/4
#else
#define CRYSTAL PROC_FREQ
#endif

#use delay(clock=PROC-FREQ)

will then work, and 'CRYSTAL' will be available elsewhere.
The other way would be to explicitly generate the values for the particular clock rates available, and test for each possible value...

Best Wishes
Bangheadondesk



Joined: 26 Apr 2005
Posts: 7

View user's profile Send private message

PostPosted: Tue Apr 26, 2005 4:48 am     Reply with quote

Thanks Ttelmah, I see now why it wont work. Unfortunately I cant implement what you were pondering. The idea is to specify the external crystal frequency (which must match the actual physical crystal) and just toggle that PLL define. Oh well, dont suppose theres any way of altering that CCS code?
Ttelmah
Guest







PostPosted: Tue Apr 26, 2005 7:11 am     Reply with quote

It is a pity, and it really should not be that difficult to change.
However it is worth saying, that provided the range of possible frequencies is not too large, you could do it (bulkily), with something like:
Code:

#define FREQ 4000000
#define PLL
#ifdef PLL
#if (FREQ == 1000000)
   #undef FREQ
   #define FREQ 4000000
#elif (FREQ == 2000000)
   #undef FREQ
   #define FREQ 8000000
#elif (FREQ == 3000000)
   #undef FREQ
   #define FREQ 12000000
#elif (FREQ == 4000000)
   #undef FREQ
   #define FREQ 16000000
#elif (FREQ== 5000000)
   #undef FREQ
   #define FREQ 20000000
#elif (FREQ== 6000000)
   #undef FREQ
   #define FREQ 24000000
#endif
#endif

#use delay(clock=FREQ)


Best Wishes
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