Go Down

Topic: PWM from Pro Micro (Read 631 times) previous topic - next topic

amadeok

Hi,
I have a Pro Micro - 5V/16MHz (ATmega 32U4) and i need to get a PWM signal between 1000hz and 2000hz for a screen backlight signal input. All i could find about it is that pins 3, 5, 6, 9 and 10 are the ones that do PWM. However i'd like to know at what frequency they operate.
any help?
thanks







pert

From the analogWrite() reference page:
https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/

Board: Leonardo, Micro, Yún
PWM Pins: 3, 5, 6, 9, 10, 11, 13
PWM Frequency: 490 Hz (pins 3 and 11: 980 Hz)

The Pro Micro is functionally the same as the official ATmega32U4-based boards in this respect. So if you can work with 980 Hz, you should just use pins 3 and 11.

amadeok

I see thanks, what if i wanted to use 2000hz?

MartinL

Hi amadeok,

Quote
I see thanks, what if i wanted to use 2000hz?
Then it's necessary to use register manipulation. The following code sets up digital pins 9 and 10 for PWM at 2000Hz:

Code: [Select]
// Set-up hardware PWM on the Arduino UNO/Pro Micro at 2kHz on digital pins D9 and D10
void setup() {
  pinMode(9, OUTPUT);                               // Set digital pin 9 (D9) to an output
  pinMode(10, OUTPUT);                              // Set digital pin 10 (D10) to an output
  TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11);  // Enable PWM outputs for OC1A and OC1B on digital pins 9, 10
  TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11);     // Set fast PWM and prescaler of 8 on timer 1
  ICR1 = 999;                                       // Set the PWM frequency to 2kHz (16MHz / (8 * (999 + 1)))
  OCR1A = 500;                                      // Set duty-cycle to 50% on D9
  OCR1B = 250;                                      // Set duty-cycle to 25% on D10
}

void loop() {}

krupski

I see thanks, what if i wanted to use 2000hz?
The only "important" thing to consider when using PWM to control a backlight is that it doesn't visibly flicker.  490 Hz. is certainly fast enough to satisfy this. Sorry to ask this (because I hate when people do it to me), but why do you need/want 2000 Hz for the backlight?  It won't be any better, worse or different than stock 490 Hz...  Just curious.
Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Go Up