Go Down

Topic: Introduction, and requests for help with high frequency pulse width modulator. (Read 4875 times) previous topic - next topic


Greetings all,
     I am new to the forum and new to the ARDUINO, after uploading the firmware I am blinking up a storm with a green LED I am reaching out for some help.  Anyway the reason I bought this thing was to make a pulse width modulator for a flyback transformer.  What I need is some direction for creating this code, as I have no experience with coding at all.  What I need to start, is to read a reference voltage off of a potentiometer (0-5 volts) and convert that to a frequency for the PWM, I need a range of 10kHz-100kHz, resolution is not important but if I understand correctly I get exactly 1024 values evenly spaced, more than enough...  Anyway I will also need to ready duty cycle off of another pot, from 0-50%.  Once I work out the bugs I'll have more advanced question later (like converting to half bridge and having a random mode etc.)  Thanks in advance!


The default support in the Arduino library for PWM doesn't give you frequency control, but the hardware can do this.   I think there is probably a library or two out there that can do this, otherwise you will have to read the ATmega328 datasheet for the grizzly details - if so you want 'Phase and frequency correct PWM mode' and timer1 is the 16bit timer (drives pins 9 and 10, but I think only one of these can be used for phase/frequency mode).

The pots are easy, connect wiper to an analog pin, other ends to GND and Vcc, call analogRead().  Pots around 1k to 100k will all work.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]


With some help from my buddy who is a C++ guru, We managed to get variable frequency and duty cycle using two LEDs and a potentiometer alternating.  Using the fast write (digital write?  I can't remember) function and pins 13, and 7, We can't seem to set concrete time values in this regard, and as such I doubt we will get the frequency response I need using this function (not that I could tell anyway using LEDs, I was just happy to get potentiometer control for now.)  I'll take a look at the datasheet, but I'm not sure I'll understand it, as my coding experience consists of a few days of ladder diagrams for PLCs that I did in college, and some very basic html for my website.  I can provide the code we cobbled together if it makes things easier to set the frequency ranges, and make the duty cycle actual percentages, as opposed to just arbitrary time spans...


Hi teslas-intern,

Somewhere below this thread, I've provided the PWM software with either direct coding or timer generation:

You might also look at my friend kas you posted this thread where he was using a method similar to yours:


Go Up