Go Down

Topic: PWM frequency library (Read 356028 times) previous topic - next topic

dhruvrastogi

Hi everyone,

I want to use the library on my Mega 2560 to generate a PWM of 20kHz. I have been able to do so on my Uno but my waveform is getting distorted in Mega. I will really appreciate some help in understanding where I am going wrong.

The code I used is as follows:

Code: [Select]
#include <PWM.h>


void setup()
{
  // put your setup code here, to run once:
  pinMode(3, OUTPUT);
  InitTimersSafe();
  bool success = SetPinFrequency(3,20000);
}

void loop()
{
  // put your main code here, to run repeatedly:
  pwmWrite(3, 127);
 
}

lucian_v

Hi,
I am using this library to change frequency using pin9 on an arduino mini pro and is working fine but I want to ask if is possible to change pwm resolution using this library?

I mean now I can set values between 1 to 255 for duty cycle, that means 8 bits. Can this be somehow changed to have 10 bits (1024 values) or even more? Is there any way doing that with this library?

Thank you

Go Up