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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.