View previous topic :: View next topic |
Author |
Message |
soundscu
Joined: 29 Jun 2007 Posts: 62 Location: Raleigh, NC
|
macro syntax to set parameters that must be constants? |
Posted: Sun Dec 06, 2009 10:02 am |
|
|
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
|
|
Posted: Sun Dec 06, 2009 10:08 am |
|
|
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
|
|
Posted: Sun Dec 06, 2009 1:29 pm |
|
|
While reading your 1st post, my mind suggested a switch.
Sounds like you've got it!
Ken |
|
|
|