Maker Pro
Maker Pro

PwM using microcontroller

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
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)
 
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
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.
 
You can't do the measurement and output on the same pin unless you have some form of 'switching' to differential between the two.
 
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
 
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.
 
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.
 
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.
 
Depends on the frequencies involved and the accuracy required.

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

Bob
 
Top