good morning to every one,
i have seen that the pwm signal that can be generated is about 1KHZ or about 470KHZ in arduino. but cant we generate a pwm signal with much higher frequency say 10KHZ on arduino-uno?
is there any method to generate? if there, pls mention it
is it even possible to do such thing ? if, mention why& if not, mention why not ?
thanks for your answers every one
LarryD
February 14, 2016, 2:57am
2
Use the TimerOne library.
I though 470 KHz much higher frequency then 10KHz?
Read this
http://playground.arduino.cc/Main/TimerPWMCheatsheet
https://arduino-info.wikispaces.com/Arduino-PWM-Frequency
Timers and counters
const byte OUTPUT_PIN = 3; // Timer 2 "B" output: OC2B
const byte n = 24; // for example, 10 kHz
void setup()
{
pinMode (OUTPUT_PIN, OUTPUT);
TCCR2A = bit (WGM20) | bit (WGM21) | bit (COM2B1); // fast PWM, clear OC2A on compare
TCCR2B = bit (WGM22) | bit (CS22); // fast PWM, prescaler of 64
OCR2A = n; // from table
OCR2B = ((n + 1) / 2) - 1; // 50% duty cycle
} // end of setup
void loop() { }
LarryD
February 14, 2016, 3:27am
4
#include <TimerOne.h>
//UNO only
void setup()
{
pinMode(9,OUTPUT);
Timer1.initialize(100); //100us = 10khz
Timer1.pwm(9,512); // 50% DC
// You can use 2 to 1023
// 0 & 1 gives a constant LOW
// 1024 gives a constant HIGH
// 2 gives ~125ns HIGH pulses
// 1023 gives ~125ns low pulses
// 512 gives 50us
}
void loop()
{
}