|
|
View previous topic :: View next topic |
Author |
Message |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
re: built in functions- set_pwm_duty query |
Posted: Sun Sep 21, 2008 9:15 pm |
|
|
When trying to associate an action or variable with a given combination of pwm channel and my desired duty cycle - I seem to need to code it awkwardly owing to the different function names associated with the channel
I'm grateful for the clean solid pwm functions I'm using now
but does anybody know why the compiler could not
persuaded to accept input with a syntax of
set_pwm_duty( int channel number, unsigned long duty_cycle_var)
to pass 2 vars instead of one to a buncha different functions? ?
ditto the setup .h files
Is there a sys var or some way to resolve channel differences in a
simple default way?
Is it more than TTWIW?
If so - I am suitably abashed. |
|
|
Ttelmah Guest
|
|
Posted: Mon Sep 22, 2008 2:34 am |
|
|
You will just have to write a wrapper.
The reason', is size/speed.
The 'functions', are not really functions, but macros, which directly access the registers associated with a single PWM. The setup, just puts the values given, directly into the specified registers, and hence at runtime, are tiny. To make it support multiple channels, adds the test for 'which channel', and requires the 'function', to have code for all the channels present. Not 'huge', but a lot larger than the supplied macros. If you want the flexibility, then all you have to do, is provide this yourself. So something like:
Code: |
#separate
void set_pwm_duty(int chan, int16 cycle){
switch (chan) {
case 1:
set_pwm1_duty(cycle);
break;
case 2:
set_pwm2_duty(cycle);
break;
case 3:
set_pwm3_duty(cycle);
break;
case 2:
set_pwm3_duty(cycle);
break;
case 2:
set_pwm4_duty(cycle);
break;
}
}
|
Many users, will only ever code perhaps a single PWM, and adding the full wrapper, supporting all the PWM channels (change to match your chip/needs), makes the call both much larger, and slower (using #separate, means the whole thing won't be duplicated 'inline', if only used a couple of times, but expect this to be perhaps 70 to 80 instructions, and involve perhaps 20 instructions in a typical 'use', against less than 10 for the 'single channel' version). You 'pays your money'...
Best Wishes |
|
|
|
|
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
|