PWM variable freq/duty cycle---revisited

Thread Starter

spuddo

Joined May 2, 2013
17
Hi
Some months ago i built the above pwm with independent variable frequency and duty cycle using an Lm339.
It worked a treat.
Some on this forum suggested it could programmed.
I'm a novice when it comes to programming
i gave it a crack using a tutorial from a site (Engineers Garage).
It only varied the frequency , but a good place to start.
I managed to correct a few lines of code to achieve what i wanted. Freq. adjustment 20hz to 20khz.
But the analog pot (100k linear) produced the following:

5v--------20hz

2.5v------40hz

0v--------20khz

I would like it to be more linear.
Does it need more code in the existing program or could this be achieved using a digital pot (in this case 1024 steps)

lm339 PWM cct.pnglm339 PWM cct.png
 

Attachments

crutschow

Joined Mar 14, 2008
24,130
But the analog pot (100k linear) produced the following:

5v--------20hz

2.5v------40hz

0v--------20khz

I would like it to be more linear.
I'm confused.
Is the analog pot providing a voltage to the micro to adjust the frequency?

If so then can't you just alter the code to change the voltage to frequency factor so the linear voltage change gives the change in frequency with voltage that you want?
 

Thread Starter

spuddo

Joined May 2, 2013
17
Hi crutschow.
Yes the pots wiper is connected to A0 on Arduino uno.

If so then can't you just alter the code to change the voltage to frequency factor so the linear voltage change gives the change in frequency with voltage that you want?
That's what i wanted to hear.


Now i have the task of learning how to do that , can you suggest any tutorials.

Thanks for your input
 

crutschow

Joined Mar 14, 2008
24,130
Now i have the task of learning how to do that , can you suggest any tutorials.
Afraid I'm not that familiar with the Arduino, but a Goggle search should give many example tutorials.

Basically you look at the code that converts the voltage to the frequency and then add some code that changes the factor between the voltage and frequency to give the variation you want.
You could possible use the POW() or SQRT() functions of the voltage for this.
 

Thread Starter

spuddo

Joined May 2, 2013
17
Hi MHR.

At this stage it's just learning.

Build in hardware (thanks to crutschow) , now lets do it in software.

My interest is only audio.

This will produce a binary stream , and who knows where this will lead.

Any help is appreciated.
Thanks for your reply
 
Top