Arduino uno rev 3---PWM

Hi , is the following possible.

A square wave output with a continuously variable duty cycle using an external pot that does not effect the frequency.

At the same time using another external pot to change the frequency without effecting the duty cycle.

Frequency in the audio range , 20hz to 20khz.

Here's the catch------i want 16 outputs all with the same facility.

Best regards (got my flame suit on) :slight_smile:

Square wave must be how square? Those 16 pins will all be output through resistors.

You have to bit-bang to get that many pins pulsing, 20KHz for 16 pins is pushing it on an Uno but not on a Due or other ARM chip Arduino or compatible like the Teensy 3.x boards.

Flame suit... has it got hip boots too?

thanks for your reply GFS.
It looks like it can be done then. Just not with the Uno.
I've already built the hardware version , 1 channel only , just thought if it can be built in hardware then it must be programmable----problem is i'm code challenged!!.
Hardware version has pretty good square wave , so i'd hope arduino could spit out the same.
Not sure what you mean by "hip length"----sounds a bit kinky.
Best regards
PS are you a fireman?

The hip boots are for standing hip deep in... mud when they're not used for fishing.

Not a fireman though I put a lot of camp fires out in the 60's and 70's.

I don't know what your hardware version is, a 555 circuit?

To make PWM in code you have to switch current twice per cycle. I could do that reliably at 20KHz with 1 or 2 pins on an Uno but not while reading analog pots since a single analog read takes 105 microseconds and a 20KHz cycle takes 50.

I don't understand how the "square" shape question entered this thread. A digital output can not produce anything but square waves.

Also ADC runs autonomously, it's only a single bit test to know when the conversion is complete.

Yup the pin turns ON and OFF very quickly and then the circuit that the current flows through changes that very square edge.

Try timing a call to analogRead() using micros().

Also digitalRead() and digitalWrite() are far slower than direct port manipulation.

Hi , DrD and GFS

Thanks for your replies

Please bear with me as i know f all about programming , but i intend to learn , hoping this can be my first go.

The hardware version i built was using a Lm393 , worked great , freq and duty cycle changed without effecting each other. Building 16x these is do able.

Now all i hope for is this can be done using Arduino uno/due etc.

Best regards

PWM chips for multiple channels exist, but I don't know which allow for individually adjustable frequency.

Controller hardware solutions require 1 timer per channel, because the timer determines the frequency. Software solutions depend on the chosen controller (speed...) and requirements.