Flora PWM pins

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
tektsu
 
Posts: 18
Joined: Sun Nov 15, 2009 5:07 pm

Flora PWM pins

Post by tektsu »

What pins support PWM on the Flora? I am trying to use analogWrite(), but the pins I have tried (D9 and D11) don't seem to support it.
Thanks

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Flora PWM pins

Post by adafruit_support_bill »


tektsu
 
Posts: 18
Joined: Sun Nov 15, 2009 5:07 pm

Re: Flora PWM pins

Post by tektsu »

I had seen that tutorial, and it *does* say that D9 supports PWM, however, unless I am misunderstanding the code, it's doing the PWM in software, not using analogWrite(). analogWrite() does not seem to work on that pin. Is there a pin which will support analogWrite?

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Flora PWM pins

Post by adafruit_support_bill »

The 32U4 does have hardware PWM. Not sure why analogWrite wouldn't work. I'll look into it.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Flora PWM pins

Post by adafruit »

Try this? its our flora analog output test code :)

Code: Select all

void setup() {
  pinMode(6, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);

  analogWrite(6, 66);
  analogWrite(9, 128);
  analogWrite(10, 194);
}


void loop() {
  delay(100);
}

tektsu
 
Posts: 18
Joined: Sun Nov 15, 2009 5:07 pm

Re: Flora PWM pins

Post by tektsu »

I will give it a try this evening when I get home, and I'll let you know the results.
Thanks

tektsu
 
Posts: 18
Joined: Sun Nov 15, 2009 5:07 pm

Re: Flora PWM pins

Post by tektsu »

I hooked up LEDs and resistors to the pins 6, 9 and 10. I used the same kind of LEDs from the same package, so they should be similar, and I used the same value resistor for each LED. Using your sample program, all three LEDs come on and appear to be the same brightness.

However, using the following code, I can see that there is a slight difference between the three, although the one set at 194 does not appear to blink.

Code: Select all

void setup() {
  pinMode(6, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
}


void loop() {
  analogWrite(6, 66);
  analogWrite(9, 128);
  analogWrite(10, 194);
  delay(500);
  digitalWrite(6, HIGH);
  digitalWrite(9, HIGH);
  digitalWrite(10, HIGH);
  delay(500);
}
So apparently the PWM is working, but perhaps the duty cycle is not as expected.

I recently moved, and of course I can't find my o-scope probes now. :( I'll pick up a new set when I get into town and see if I can see what's up.

Thanks for your help.

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Flora PWM pins

Post by adafruit_support_bill »

LED response in general is not linear. For most of them, you need to reduce the duty cycle considerably before it visibly dims. I wouldn't expect 194 to be much different than 255.

tektsu
 
Posts: 18
Joined: Sun Nov 15, 2009 5:07 pm

Re: Flora PWM pins

Post by tektsu »

Yep, further testing shows everything is working as it should. Thanks for your help!

User avatar
rodrigo_alvarez_i
 
Posts: 7
Joined: Sun Oct 30, 2016 2:11 am

Re: Flora PWM pins

Post by rodrigo_alvarez_i »

Hi, analogWrite does work but it results in a PWM with a 250 Hz frequency and 8-bit duty cycle resolution. This is not very good for driving DC motors because at 250 Hz you can hear the buzz and the 8-bit resolution results in very high-gain control loop on the low end of the range.

Can anyone provide an example of how to use the native Hardware-based PWM timers on the 32U4?

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”