Since there is no library, yet, for PWM I thought I would share my progress/findings for anyone else that is playing with PWM on the Wixel.
After a quick search of the CC2511 page I found a design note that looked helpful, DN115 – Using PWM for Dimmer Function in LED Lighting.
But after trying the code and some head scratching as to why it was not working and more google searches, I eventually came across a forum post about a similar chip the CC2530 and PWM - http://e2e.ti.com/support/low_power_rf/f/156/p/118346/428582.aspx. The code is rather similar so figured that I was on the right track so decided to examine what was acutally happening with the code from DN115.
After looking at the contents of the registers, before and after, the code in DN115 I found that there is something missing. Timer 1 was not actually enabled, granted there is a comment about setting Timer 1 to Modulo Mode but there is no code that actually does it.
So far I have managed to dim a led by a given value, and rather crudely step a led through a few different dim levels.
Without further ado, the registers that need to be altered to get it to work:
[code]/* PWM freq = 13M / 128 / 511 = 198.75 Hz /*
T1CC0L = 0xff;
T1CC0H = 0x01;
// PWM duty cycle about 1/8
T1CC1L = 0x3F;
T1CC1H = 0x00;
/* Timer 1 channel 1 set compare mode 4 */
T1CCTL1 |= 0x24;
/* Prescaler set to Tick Freq / 128 */
T1CTL |= 0x0c;
/* Timer 1 CFG set to Alt 2 location */
PERCFG |= 0x40;
/* P1_1 set peripheral func which associated with Timer 1 output */
P1SEL |= 0x2;
/* set modulo mode */
T1CTL |= 0x02;
[/code]The two lines changing T1CTL can be merged, they are just separate as I was playing with different changes to get it to work.
With this knowledge ideally I would like to write a library for controlling PWM, I’m thinking of something similar to the analogWrite function that the Arduino has http://arduino.cc/en/Reference/AnalogWrite.