I have an arduino uno. And I wanted to set out put frequencies. But I can get the required result on pins 6,9,10,11. This is the code is used. Please help
Below I have the code I am using.
#include <PWM.h>
//use pin 11 on the Mega instead, otherwise there is a frequency cap at 31 Hz
int pwm1 = 3;
int pwm2 = 5;
int pwm3 = 6;
int pwm4 = 9;
int pwm5 = 10;
int pwm6 = 11;
int32_t frequency = 20000; //frequency (in Hz)
void setup()
{
//initialize all timers except for 0, to save time keeping functions
InitTimersSafe();
InitTimers();
//sets the frequency for the specified pin
bool success1 = SetPinFrequencySafe(pwm1, frequency);
bool success2 = SetPinFrequency(pwm2, frequency);
bool success3 = SetPinFrequency(pwm3, frequency);
bool success4 = SetPinFrequencySafe(pwm4, frequency);
bool success5 = SetPinFrequencySafe(pwm5, frequency);
bool success6 = SetPinFrequencySafe(pwm6, frequency);
}
void loop()
{
//use this functions instead of analogWrite on 'initialized' pins
pwmWrite(pwm1, 125);
pwmWrite(pwm2, 125);
pwmWrite(pwm3, 125);
pwmWrite(pwm4, 125);
pwmWrite(pwm5, 125);
pwmWrite(pwm6, 125);
}
Frequency.ino (974 Bytes)