Combining the PWM with the DAC

Thread Starter

Roto

Joined Jul 13, 2011
23
Hi Folks

I'm using a 16F1825 pic to output an audio signal on a PWM pin to drive an OP amp with a resistor in between plus the cap etc. into the amp.
Top resolution is 10 bits or 1024 voltage levels when averaged.
What if I added the DAC using a resistor (1024 x the resistance of the PWM resistor?)
I could brush up on the basics to answer this but it's a simple question for some of you.
Could you then divide the output a lot finer (1024 x 32)?
So if I'm setting my PWM at a certain value but it should really be that value plus say 25% of an increment can I increase the voltage to that level by introducing additional voltage from the DAC. Can it be done with just 2 resistors?
The additional voltage would be present throughout the PWM cycle until new values are written.
But would be very small. Not sure if the PWM pin would sink some or all of it? Maybe a 3rd high ohm resistor to ground? Possible be below or close to the lower thresh hold of the amp?
 
Last edited:

Thread Starter

Roto

Joined Jul 13, 2011
23
Thanks Markd77.

I'm not much of an analog guy but I understand (from your post) that it's just a bit of rearranging for my OP amp input.
I'm looking to get good voice output and will resort to this (or something else?) if I have to. I imagine just upping the sample rate will accomplish this but it will require a bigger SD card to store the audio.
I'm just sort of throwing the idea out their to see if it's possible and maybe of some practical use?
 

ErnieM

Joined Apr 24, 2011
8,377
(I misread OP post where he said D2D and I saw A2D)

I don't understand what you mean. The A2D has a 10 bit resolution, that's the most you can get out of the system.

When sampling the audio, you want to bias the A2D input so with no audio it sees 1/2 the reference voltage.

Similarly, with the PWM, a zero volt signal should be set to 1/2 the PWM bit resolution. So nothing in gives you a square wave out. You can then just copy the A2D result into the PWM duty cycle.

The frequency of that square wave should be as high as you can go but a minimum of the sampling rate.

The output of the PWM needs to go thru a capacitively coupled (to get rid of the DC) low pass filter & amplifier so the high frequency square wave gets tossed and just the low frequency audio goes thru.

However, I've just put a speaker thru a cap to a PIC pin and got intelligible audio from it. Not high quality, not loud, but I could make out the sounds.
 
Last edited:

MrChips

Joined Oct 2, 2009
30,808
Roto, I don't understand what you are saying. Can you draw a circuit diagram?
Why use PWM and DAC together? Why not use the DAC alone to output your audio wave?
 

Thread Starter

Roto

Joined Jul 13, 2011
23
The ADC is not used, the audio files come from an SD card connected to the spi lines.
The DAC can only output 32 different voltage levels.
The idea is to some how combine the PWM output with some output from the DAC to increase the possible output voltage levels.
I think MarkD77 has it right when he suggests a summing amp circuit to drive the speaker.
 

kubeek

Joined Sep 20, 2005
5,795
The ADC is not used, the audio files come from an SD card connected to the spi lines.
The DAC can only output 32 different voltage levels.
The idea is to some how combine the PWM output with some output from the DAC to increase the possible output voltage levels.
I think MarkD77 has it right when he suggests a summing amp circuit to drive the speaker.
Why not use the pwm as a sigma-delta DAC and get any resolution you need? I don´t know how much better sound you need, but lets say 11kHz sampling rate with 16x oversampling should be more than enough for a nice sound. That would mean your PWM running at 176kHz which should be very easy to achieve and still have plenty of clock cycles left.
 

Thread Starter

Roto

Joined Jul 13, 2011
23
I've attached a BMP.

If you imagine a 3 level PWM and a 3 level DAC.
The drawing shows that you can get more settings than the PWM alone can provide.
The voltage from the DAC is not seen until the off cycle of the PWM.
As shown if you want a 1/3 duty cycle (PWM) or a 1/3 voltage (DAC) the average result should be the same.
This is the same at 2/3 and also at 100%.
The filter would prefer the DAC output but on my PIC the DAC has only 32 levels. I'm decoding compressed data (about 250 instruction cycles per sample) and I'm reading in from a SD card at 5600 times per sec. I can not run the DAC at a tremendously high speed to compensate for poor resolution.
But I can run the PWM at a very high rate (say > 500khz at 5 bit resolution) and I can lean on the off cycle with a 5 bit DAC output.
That gives 1024 levels which is no better than 31.25khz on this chips PWM. But by including the DAC input I can run the PWM considerable faster.
I'm assuming that if this is the only gain it will at least reduce the low pass filter requirements?
I haven't thought about other options eg. 6 bit PWM and a 5 bit DAC etc.?


 

Attachments

Last edited:
Top