Logxen

Getting PWM to work

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!

Share this post


Link to post
Share on other sites

The digitalWrite works normally. If I comment it out like in the example there the led is off, if I uncomment it the led will turn on and stay on.

Share this post


Link to post
Share on other sites

Yeah that seems like the logical next step... I'll try actually wiring an led up to one of the wings and see what happens next chance I get.

Share this post


Link to post
Share on other sites

well that would certainly explain it then. ;)

 

when I read the source it appeared to be hooked up based on my limited understanding of the hdl... thanks for clearing that up.

Share this post


Link to post
Share on other sites

Although nice to have PPS on the LED pin, it has very limited functionality compared to the amount of resources needed to do it... No need to redirect audio output to the LED, for example, right ? :P

 

Best,

Alvie

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now