10 years, 3 months ago.

PWM signal with period and duty cycle controlled by potentiometers?

I am looking to create a PWM signal (that I can observe on an oscilloscope) whereby both the PWM.period and PWM values are controlled by 2 potentiometers. The period should be variable between 10-50ms and the duty cycle from 20-80%.

I have wrapped my head around the idea that I need to map the minimum and maximum of each potentiometer to correspond with the maximum and minimum values of the period and duty cycle above, but I lack the "coding" knowledge to actually write it out.

Help would be greatly appreciated!

Edit: I will be using two 10k potentiometers that I am pretty OK with, 1 pin to ground, 1 to Vout and the middle one to a designated AnalogIn pin.

1 Answer

10 years, 3 months ago.

How far did you get yourself? Can you already just use a PWM signal without anything special around it?

For example you want duty cycle between 20% and 80% (so 0.2 and 0.8), and AnalogIn returns between 0 and 1. So first you add 0.2, then it is between 0.2 and 1.2, If you then make sure the AnalogIn is mulitplied by 0.6, it is between 0.2 and 0.8:

out = 0.2 + in * 0.6;