Go Down

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


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);
  bool success = SetPinFrequency(3,20000);

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


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


Well this lib for sure aint working anymore, even if I fixed the issue according to post #135. I could get one timer working at the same time, after the fix I got another working, but then I couldnt get the first working.



I am thinking about converting an old inverter welder to use an Arduino to switch on/off the two IGBT:s that control the welding current by sending a positive or a negative voltage to a transformer, to create the MMA welding current.

The idea is to start with just mimicking the existing welder control electronics that gives a PWM signal at 19 kHz. This works fine with the pwm.h library. However, I need to control two IGBT:s in the welder with two pins on the Arduino in such a way that when one pin goes high the other one goes low. So essentially, I want to invert the time axis for the output to one of the two PWM pins. Any idea about if this can be done by tweaking the library?

An other way to do it would to phase shift one of the signals, but then the phase shift has to be recalculated when the duty cycle is changed, since the two pins must never be high simultaneously.

If I can get this to work the next step would be to fine tune the welder behaviour with the welding current as input data.

Go Up