Maker Pro
Maker Pro

PwM using microcontroller

pica

Jul 7, 2017
36
Joined
Jul 7, 2017
Messages
36
Hello All,

I am working on one project which requires following condition.

Analog voltage and PWM on same pin of microcontroller.

Does it possible??

Currently I am using one pin of microcontroller. If analog voltage at that pin is 0-5V . I am converting 0-5V from internal ADC and getting values between 0-1023 as my adc is of 10 bit. Using those values, I am generating PWM and varying duty according to analog value.

Now I wanted to use the same pin which should accept pwm and according to the duty cycle of i/p pwm it should vary the duty cycle of o/p Pwm.

In case I am using analog then it should work as analog control and if I am using PWM then it should work as PWM control.

Does it possible using one pin.

Please let me know How??
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
On all microcontrollers I'm aware of, an analog output is PWM. To make it an actul analog voltage you need to integrate the output over time (essentially employ an RC time constant much greater than the period of the PWM)
 

pica

Jul 7, 2017
36
Joined
Jul 7, 2017
Messages
36
Hello Steve,

What I wanted to do is,

if the i/p is PWM with 1000Hz and 30% duty then I wanted to generate o/p with 100HZ with 30% duty.
if the i/p is PWM with 10Hz and 80% duty then I wanted to generate o/p with 100HZ with 80% duty.
if the i/p is PWM with 500Hz and 56% duty then I wanted to generate o/p with 100HZ with 56% duty.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Convert the pwm input to a voltage, read that voltage and use it to control the output pwm.

How fast you want the circuit t respond.
 

kellys_eye

Jun 25, 2010
6,514
Joined
Jun 25, 2010
Messages
6,514
You can't do the measurement and output on the same pin unless you have some form of 'switching' to differential between the two.
 

pica

Jul 7, 2017
36
Joined
Jul 7, 2017
Messages
36
Yes Steve,

I had did that using RC low pass filter but I am getting fluctuations.

Also by using RC low pass filter. The o/p is coming only 4.5V not 5V
 

pica

Jul 7, 2017
36
Joined
Jul 7, 2017
Messages
36
Yes Kellys,

For analog voltage 0-5V I will use internal ADC.

But what for i/p PWM? How I can measure the duty cycle.
 

kellys_eye

Jun 25, 2010
6,514
Joined
Jun 25, 2010
Messages
6,514
Also by using RC low pass filter. The o/p is coming only 4.5V not 5V
The output voltage will depend on the duty cycle and the RC time constant. You would only ever get the full 5V at 100% duty cycle (i.e. permanently 'on').

But what for i/p PWM? How I can measure the duty cycle.
Use another timer - triggered by the rising/falling edge of the i/p PWM signal.
 

pica

Jul 7, 2017
36
Joined
Jul 7, 2017
Messages
36
Hello Kellys,

I was thinking in the same way but i am using ATtiny 10 controller of ATMEL.

I read the datasheet, It has one 16 bit timer. I have to capture i/p PWM also i have to generate o/p PWM.

Dose my operation is possible.
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
Depends on the frequencies involved and the accuracy required.

If slow enough, you don't need any hardware peripherals.

Bob
 

pica

Jul 7, 2017
36
Joined
Jul 7, 2017
Messages
36
Hello Kellys and BobK,

Then how to do it?

I have only one 16 bit timer.
 
Top