Skip to main content
shopping_basket Basket 0
Login

Little help with PWM

Hi !

I have been using pin 9 for PWM and require at least a range of  4 octaves .

I'm using a linear 100k pot to analog pin A0 to vary the frequency.

The ADC is 10 bit and has a resolution of 1024.

the results are as follows.

110hz = 0volts

220hz = 0.625volts

440hz = 1.25volts

880hz = 2.5volts

1760hz = 5volts.

That's as expected .

This is exponential and causes very small changes in the second half of the pots travel.

In short a PITA when trying to tune a lower  frequency.

This is more like hertz/volt.

Is there some way i can make the ADC deliver a 1volt/octave response?

Thanks for listening.

Comments

May 21, 2020 07:42

Some things aren't clear here.
What is fairly clear: You have a pot feeding the input of a 10-bit A/D, giving you 1024 output levels as you rotate the pot.
You want something with a four octave output frequency range.
The output you are getting matches the range you expect, but it is hard to use because in some parts of the range small rotation of the pot produces a big change in output relative to what you want, and in other portions of the range, a small change in output relative to what you want.
What isn't clear:
You say the output is PWM on pin 9. Pin 9 doesn't tell us much, because we don't know if it is pin 9 of a board or module, or a processor, and if a processor, which processor.
PWM stands for Pulse Width Modulation, changing the width of pulses at a given frequency to control duty cycle. That can be used to control things like the position of a servo, or the speed of some types of motors. Or can be fed into a filter to generate an analog value. But what varies in PWM is the width, not the frequency, of the pulses.
If you fed it (via a capacitor for ac coupling) to an audio amplifier, you would hear a sound that was always the same frequency, but had different timbre as the width changed.
You also say you need a four octave range, but don't specify what the starting frequency of that range should be. An octave is a doubling in frequency, so 4 octaves represents varying the frequency over a range of 16:1 (two to the fourth power).
One hertz to sixteen hertz is four octaves. But so is 100 hertz to 1600 hertz.

Most processors have some built-in timers, that can usually be set to operate in a number of different modes. Some include extra logic to enable generating variable pulse width output (PWM) using the timer. I suspect you happen to be using one of those timers (which is why you are describing it as PWM output), but are actually not using the PWM capability of the timer. Rather, you are just using the timer to output a square wave, or an asymmetrical waveform with a fixed time for the output pulse being low and a variable time for it being high, essentially a narrow pulse at a variable frequency.
I think the next steps toward clarity and a solution would be to define what output frequencies you want at different rotations of the pot - maybe at 0, 1/8, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8 and full rotation, respectively. And secondarily, what your processor or board is, and whether you are trying to get square wave or narrow pulse output at the desired frequency.

0 Votes
DesignSpark Electrical Logolinkedin