I've find some imprecisions about the (current) pwm driver:
in the PWM_COMPUTE_ARR(pwmclk, pwmperiod) macro, the pwmclk argument means the desidered timer counter clock, but the real one achieved can be considerably different because the truncation of division in the psc configuration and then an significantly different pwm period from that indicated in pwmperiod argument.
my code arrangment (a new macro):
Code: Select all
#define _TIMFREQ(clksrc, pwmclk) ((clksrc)/((clksrc)/(pwmclk)))
#define _PNS2FRQ(pwmperiod) (1e9/(pwmperiod))
#define PWM_COMPUTE_ARR_PNS(clksrc, pwmclk, pwmperiod) \
((uint16_t)((_TIMFREQ(clksrc, pwmclk) / _PNS2FRQ(pwmperiod)) - 1))
in the macro PWM_FRACTION_TO_WIDTH(pwmp, numerator, denominator) the names "numerator" and "denominator" are swapped compared with calculation (only the means of argument names, the calculation is correct)
I've integrated in to pwm driver the support of complementary outputs of TIM1, and some little improvements.
In this job i've used (and experimented) a two step inclusion of pwm_lld.h in pw.h to risove the the problem of 'hen egg, for add the low level parts of types definition to high level part of the same.
Because the low level driver include file, is called only from hig level driver, i think that this approach is secure.
IMHO, i think it can be usefull in the chibiOS driver structure.
For your convenience, i add my files, you can give them a look and tell me what you think
http://www.megaupload.com/?d=MMVJ9JUO
(files updated at 30/03 15:37)
Alberto