PWM using Microcontroller

Thread Starter

Usama_ali143

Joined Jul 17, 2017
27
Hi guys! I have an audio signal and i want to generate PWM modulation of this audio signal. please see attached pic. i want to generate such kind of wave form using ATmega tiny or any other micro controller..please guide me
 

Attachments

alfonsoM

Joined Nov 8, 2017
41
Hi guys! I have an audio signal and i want to generate PWM modulation of this audio signal. please see attached pic. i want to generate such kind of wave form using ATmega tiny or any other micro controller..please guide me
I guess you want to drive the PWM from the output of the ADC. ATmega have a good PWM, most ADC's are slow and you will get an error of 10% at 2KHz and about 50% at 10KHz.
 
Sorry but adc is to read voltage not output a wave or pwm you use a DAC
Hi, yes, you're right but the OP said he wants to convert an audio signal to a PWM representation of that signal.

One way to do that would be to sample the audio signal with an ADC first, compute the PWM duty cycle and then output that somehow. To Alfonso's point, your bandwidth would be limited by the sample rate of your ADC.

There's a better way to do it though without an MPU, it involves a comparator with a triangular (or sawtooth) wave on the + comparator input and the audio signal on the - comparator input. Use your favorite oscillator (555 timer or MCU output) and a cap to generate your triangle wave. This will give a lot better accuracy and bandwidth.


 
Last edited:

alfonsoM

Joined Nov 8, 2017
41
There's a better way to do it though without an MPU, it involves a comparator with a triangular (or sawtooth) wave on the + comparator input and the audio signal on the - comparator input. Use your favorite oscillator (555 timer or MCU output) and a cap to generate your triangle wave. This will give a lot better accuracy and bandwidth.
Your block diagram looks good but only handful of engineers can design a complete circuit that will give less than 10% error. In comparison, every Dick Tom and Henry can do it using mpu. Even I can do it.
It's unusual to get 3 likes to 1 comment.
 
Your block diagram looks good but only handful of engineers can design a complete circuit that will give less than 10% error. In comparison, every Dick Tom and Henry can do it using mpu. Even I can do it.
It's unusual to get 3 likes to 1 comment.
Hi Alfonso, I don't disagree and get that circuit design is beyond a lot of folks who are capable of doing great things with mpus (I myself am an EE who has designed a lot of circuits and worked a lot with embedded systems). At the same time, I always try to use the "best" tool for the job available to me -- "best" in quotes because that depends on so many factors (will it do the job ok? Is it cheap? Can I get it? Do I know how to use it? Can I get away without it? Is there a better way I don't know about?)

I don't know what the OP is really trying to do, but if an mpu does the technical task well enough and it's easy to for him to implement (with help), then that's a good (maybe best) solution. OTOH, if it can't meet the technical (or practical) specs then it might be better to farm that function out to dedicated HW.

And speaking of dedicated hardware, here's a nice little voltage-to-pwm chip (LTC6992) I just found http://www.linear.com/product/LTC6992-1-- takes a 0-1V analog signal input from 4Hz to 1MHz and converts it to PWM ... I've never used it, and gave no idea what it cost, but if the OP needs 20-20kHz bandwidth, this might be worth a look.

 
Top