Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for a way to create an adjustable PWM controller capable of modulation frequency from 0-100 (more preferably 0-1000) Hz, duty cycle from 0-100%, and able to accept a voltage range of 5-30V DC. I have looked through Sparkfun and Adafruit for product or PWM shields capable of this and I have yet to find one. Some servo shields can be programmed down to 50Hz and arduino itself can be slowed to like 30Hz using timer0 and timer1 changes. However none of these options make it easy to vary frequency and none of them can accept much more than 6V.

I have searched far and wide and found a few interesting things:

1) http://www.instructables.com/id/The-ultimate-PWM-driver-for-many-applications/

This instructable shows an analog un-sensored PWM driver. It would get the job done here however, I need a way to read my Frequency and Duty Cycle

2) https://www.electronicsblog.net/arduino-frequency-counterduty-cycle-meter/

Here there is a way using pulsein() and other arduino functions to read both frequency and duty cycle as seen above. But then this is also assuming you're PWM voltage is 5V. So maybe you use a 5V regulator on the signal into the arduino? Would something that simple work or would it skew the signal and prevent accurate measurements?

Obviously, if anyone has a better idea I'm open to it. I've been searching for a solution for some time. The trouble really seems to be the low frequency PWM request.

share|improve this question
up vote 3 down vote accepted

The ATmega328 in the Arduino Uno has a 16-bit timer (Timer/Counter 1) which can do PWM. It has a prescaler that can divide by 1024. The lowest frequency that it can generate is about 0.12 Hz:

16MHz / 1024 / 65535 / 2 = 0.1192 Hz

We change the PWM frequency by changing the "top" value. For higher frequencies, lower the top value, and/or pick a smaller prescaler.

(And, really, what does 0 Hz PWM even mean?!? :-)

The duty cycle can vary from 0-100%, with the resolution changing with the specific frequency you generate.

As for the high-voltage... use a motor driver, or darlington, or hexfet, or whatever...

I'm confused as to why you're reading the frequency. With the 16MHz crystal, you set it and you get what you asked for (within the crystal tolerances, temperature, etc.)

At least, that's how I think it works. Good luck!

share|improve this answer
    
So for 440Hz at 25% on pins 9&10, you might choose a fast PWM with Wave Generation Mode 14, 16e6 /1/440 = 36363 TOP with /1 prescaling, so: ICR1=36363 ; TCCR1A=0b10100010; TCCR1B=0b00011001; TCCR1C=0; OCR1A=36363/4 – Dave X Nov 23 '15 at 16:11
    
The PWM Waveform Generation Modes with a settable TOP value (e.g. set with the OCR1A or ICR1) are the ones that can achieve these low, adjustable frequencies. Set the Waveform Generation Mode mode and prescaler with the TCCR1* registers and then the duty cycles would be modified by adjusting OCR?B. For frequencies below the threshhold the timers can handle, one could switch over to toggling based on elapsed millis() and handle frequencies down to 1 cycle per 50 days. – Dave X Nov 23 '15 at 16:29
    
@Mike I appreciate the help. However I truly intend on the PWM frequency to be variable. And yes 0Hz is improper but my point is to make it very low. Using prescale factor like shown in this link you can only reach 30Hz using prescale factors. If you also modulate your TOP values I suppose you get any 16-bit value from 1-65535 in resolution. The 2 indicate difference between the two outputs?? link – Austin McShan Nov 25 '15 at 15:58
    
@Mike Either way this looks like I'll be able to modulate frequency easy enough...Now just the high voltage. I'll have to think more about that. But I definitely think you solved my frequency problem. – Austin McShan Nov 25 '15 at 15:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.