Getting PWM to work


Logxen

Recommended Posts

Right now I am trying to get the timer0 pwm hooked up to the led on a papilio pro using pps. I can toggle the led with digitalWrite() in the sketch just fine, but I can't seem to get the timer and pwm to start up.

 

Here's my sketch, I assume I've just misunderstood something in the zpuino spec sheet. I'm not even sure if my problem is with the timer or with pps. :)

#define FREQUENCY 100000void setup(){  pinMode(49, OUTPUT);  pinModePPS(49, HIGH);  outputPinForFunction(49, 1);//  digitalWrite(49, HIGH);  TMR0CNT = 0;  TMR0CMP = (CLK_FREQ / FREQUENCY) - 1;  TMR0CTL = _BV(TCTLENA)|_BV(TCTLDIR)|_BV(TCTLCCM);  TMR0PWMLOW(0) = 0;  TMR0PWMHIGH(0) = 400;  TMR0PWMCTL(0) = 1;}int v = 0;int d = 1;void loop(){  v += d;  if(v >= 900) d = -1;  else if(v <= 0) d = 1;  TMR0PWMHIGH(0) = v;  delay(10);}

Thanks in advance!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.