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

macro syntax to set parameters that must be constants?

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



Joined: 29 Jun 2007
Posts: 62
Location: Raleigh, NC

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

macro syntax to set parameters that must be constants?
PostPosted: Sun Dec 06, 2009 10:02 am     Reply with quote

Using PCD compiler version 4.101, target dsPIC33.

I have written a fairly complex function utilizing set_pwm-duty(). It was my hope to use this function for 4 different pwm outputs using a variable to select the output compare module, the first parameter of set_pwm_duty().

But the compiler requires the first parameter to be a constant; a variable is not allowed. I do not want to cut/paste my function 4 times, requiring me to edit all 4 if I make a change or fix a bug.

Is there a way to use #define, or some other macro method, to get around this problem? I need to set the output compare channel (1 - 4) in my function call, but have the compiler insert a constant, rather than a variable for that parameter. Other parameters in my function, however, are variables.

Thanks for your help.
Jim
soundscu



Joined: 29 Jun 2007
Posts: 62
Location: Raleigh, NC

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

PostPosted: Sun Dec 06, 2009 10:08 am     Reply with quote

For now, I've written a function with the same syntax as set_pwm_duty(), and used switch to call set_pwm_duty() with the required constant inserted. Perhaps this is the best workaround?

Jim
Ken Johnson



Joined: 23 Mar 2006
Posts: 197
Location: Lewisburg, WV

View user's profile Send private message

PostPosted: Sun Dec 06, 2009 1:29 pm     Reply with quote

While reading your 1st post, my mind suggested a switch.

Sounds like you've got it!

Ken
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