PSoC Audio: PWM vs DAC

A catchall for PSoC Mixed-Signal Array (microcontroller) discussions not captured by the other forums.

Moderator: ericb

PSoC Audio: PWM vs DAC

Postby kenlem on Fri Sep 02, 2005 4:18 am

Can anyone explain why people use PWM output and filters when generating audio on PSoC instead of just using a DAC?

According to the datasheet for DAC8, it max update rate 128kSec (=16K/Sec) which would be fine for low end applications.

Is it possible to achieve better audio using PWM and filters? I'd like to do 16 bit @ 16Khz.

Thanks,
Ken
User avatar
kenlem
The Big Cheese
The Big Cheese
 
Posts: 370
Joined: Tue Oct 05, 2004 6:55 pm
Location: Maine, USA

Postby graaja on Fri Sep 02, 2005 5:03 am

This is my opinion.

If a DAC is available, then most of the designs will use it. PWMs would be used when the micro does not have any analog resources.
User avatar
graaja
PSoC Master
PSoC Master
 
Posts: 3084
Joined: Thu Dec 18, 2003 4:35 pm
Location: India

Postby kenlem on Fri Sep 02, 2005 5:07 am

If use a DAC, you wouldn't need filters right?

Is there anyway to get a higher resolution DAC? (16bit @ 16Mhz)
User avatar
kenlem
The Big Cheese
The Big Cheese
 
Posts: 370
Joined: Tue Oct 05, 2004 6:55 pm
Location: Maine, USA

Postby graaja on Fri Sep 02, 2005 5:39 am

Even when a DAC is used, you would require a filter to remove the frequency at which the DAC is updated. For example, if you are updating the DAC at 8KHz, then you would require a filter to get rid of this 8KHz component.

I am not sure if a DAC at 16MHz is possible. But DACs with a parallel bus may be faster than the ones with a serial bus because of the bus speed limitations.
User avatar
graaja
PSoC Master
PSoC Master
 
Posts: 3084
Joined: Thu Dec 18, 2003 4:35 pm
Location: India

Postby kenlem on Fri Sep 02, 2005 5:50 am

hmmm... that may explains the results I was getting using an 8bit 16k DAC to generate audio. I used a lookup table to generate a sine wave. It sounds correct if play one sine wave but it sounds rough if I try to play two different sine waves mixed together.

I'll look for the code and post it just in case anyone is interested.
User avatar
kenlem
The Big Cheese
The Big Cheese
 
Posts: 370
Joined: Tue Oct 05, 2004 6:55 pm
Location: Maine, USA

Postby graaja on Fri Sep 02, 2005 5:51 am

MAX541 is a fast DAC with a 1uS settling time. Still, the limitation is on the serial bus. It has a 10MHz serial bus compatible with SPI. So to load a 16 bit word to the DAC, it would require a minimum of 16 cycles of the clock which would bring down the effective update rate to 625KHz. The price is about $10

I doubt if you will get a 16bit DAC at 16MHz update rate.
User avatar
graaja
PSoC Master
PSoC Master
 
Posts: 3084
Joined: Thu Dec 18, 2003 4:35 pm
Location: India

Postby kenlem on Fri Sep 02, 2005 5:56 am

I don't want to add an external DAC. I guess I could do higher resolution audio using PWM as has been discussed on this forum in the past.

As I recall, appnote AN2246 describes a high frequency, high resolution PWM that could be used for better than 8bit 16K. I think their example is 14 bit.
User avatar
kenlem
The Big Cheese
The Big Cheese
 
Posts: 370
Joined: Tue Oct 05, 2004 6:55 pm
Location: Maine, USA

Postby kenlem on Tue Sep 06, 2005 11:27 am

-I am not sure if a DAC at 16MHz is possible.


According to the data sheet the max update rate of DAC8 is 128k/Sec. Isn't that the same as 16K/Sec?

Shouldn't a 8Bit @ 16K DAC be possible on a PSoC? Of course, for audio a 16K filter would also be required.

Thanks,
Ken
User avatar
kenlem
The Big Cheese
The Big Cheese
 
Posts: 370
Joined: Tue Oct 05, 2004 6:55 pm
Location: Maine, USA

Postby IDiod on Tue Sep 06, 2005 1:02 pm

kenlem wrote:I try to play two different sine waves mixed together.


How do you mix two sines? Arithmetical ((s1+s2)/2 ->ADC) or by hardware (s1->ADC1)+(s2->ADC2)?
User avatar
IDiod
The Big Cheese
The Big Cheese
 
Posts: 193
Joined: Thu Jan 08, 2004 11:59 am
Location: Russia

Postby wrightpc on Tue Sep 06, 2005 1:50 pm

Hello,

I have previously mixed two sines to create DTMF. Simply add the two signed values together before pushing to the DAC does the job quite nicely. I was using a DAC6 @ 10kHz for this task, then feeding through a LPF in 2 analog blocks nearby before feeding the output to the phone line.

Thing to note is be make sure that adding the two sines together does NOT cause overflow, otherwise you will get all sorts of harmonics, making it sound awful and failing the DTMF. Pick the two maximum and minimum values, add them together and make sure does not overflow the DAC (+31->-31 for DAC6)

My new project I am using DAC8 @ 8kHz, but same configuration DAC8 -> LPF -> PGA -> Phone Line.

Examine the DTMF module in the designer for another information source. Also, there was an appnote on a polyphonic piano that used the MAC to scale and combine up to 10 notes before playing them - neat! Search Cypress for "polyphonic".

Paul :)
User avatar
wrightpc
The Big Cheese
The Big Cheese
 
Posts: 736
Joined: Thu Jul 28, 2005 7:56 pm
Location: Christchurch, New Zealand

Postby graaja on Tue Sep 06, 2005 5:21 pm

Ken,

All my earlier comments were based on your requirement of 16MHz update rate. 16Ksps update rate is very much possible with PSoC. As per spec, you can update the DAC at 128Ksps.

At higher update rates, the processor overhead for updating the DAC (because of DAC_WriteBlind or WriteStall functions) and calculation of DAC value will be high. But at 16K update rate, this will not matter.
User avatar
graaja
PSoC Master
PSoC Master
 
Posts: 3084
Joined: Thu Dec 18, 2003 4:35 pm
Location: India

Postby kenlem on Tue Sep 06, 2005 5:44 pm

Ahhh.... I see that I had a typo. No, I do not need 16Mhz but 16Khz.

The spec actually says 125k/sps.

I'm just trying to figure out the best was to produce audio with a PSoC.
User avatar
kenlem
The Big Cheese
The Big Cheese
 
Posts: 370
Joined: Tue Oct 05, 2004 6:55 pm
Location: Maine, USA

Postby graaja on Tue Sep 06, 2005 6:32 pm

If you limit the frequency range of your audio to 4KHz and use a sampling frequency of 32Ksps, that would give you an 8x oversampling at 4KHz and will give you good results.
User avatar
graaja
PSoC Master
PSoC Master
 
Posts: 3084
Joined: Thu Dec 18, 2003 4:35 pm
Location: India

Postby kenlem on Wed Sep 07, 2005 5:01 am

It never occured to me that I needed to oversample. I was just running the DAC at 8K and the results were horrible.
User avatar
kenlem
The Big Cheese
The Big Cheese
 
Posts: 370
Joined: Tue Oct 05, 2004 6:55 pm
Location: Maine, USA

Postby kenlem on Wed Sep 07, 2005 5:24 am

IDiod -
>>How do you mix two sines? Arithmetical ((s1+s2)/2 ->ADC) or by hardware (s1->ADC1)+(s2->ADC2)?

I'm mixing in software ((s1+s2)/2 ->DAC).


Paul, what is the PGA for, additional amplication or can you use it as a volume control?

I have seen the AppNote that uses the MAC to sum channels but to be honest, I didn't understand it. Isn't the resolution of the DAC the limitation anyway? What does the MAC do in this appliation that you couldn't do without it?
User avatar
kenlem
The Big Cheese
The Big Cheese
 
Posts: 370
Joined: Tue Oct 05, 2004 6:55 pm
Location: Maine, USA

Postby IDiod on Wed Sep 07, 2005 8:44 am

I'm mixing in software ((s1+s2)/2 ->DAC).


Ken, can you speed up your sample rate (16k sps to 32k sps)?

There are a trick how to mix two or more samples without software efforts:

s1.1->ADC, s2.1->ADC, s1.2->ADC, s2.2->ADC, s1.3->ADC, s2.3->ADC, ...

in other words, trick is to interlive the samples incoming from a different channels without any mathematic processing. All of them will be averaged by filter or by ear.
User avatar
IDiod
The Big Cheese
The Big Cheese
 
Posts: 193
Joined: Thu Jan 08, 2004 11:59 am
Location: Russia

Postby IDiod on Wed Sep 07, 2005 8:57 am

Reason:
for example, if you mix (by software) four 8-bit channels using a 8-bit ADC you have 8-bit output and lose 2 LSB from every channel.

In case of interliving you don't lose LS bits and have 10-bit clear audio on 8-bit ADC' output.
Last edited by IDiod on Wed Sep 07, 2005 9:01 am, edited 1 time in total.
User avatar
IDiod
The Big Cheese
The Big Cheese
 
Posts: 193
Joined: Thu Jan 08, 2004 11:59 am
Location: Russia

Postby kenlem on Wed Sep 07, 2005 8:59 am

Interesting. Thanks for the tip.

I do plan to do a general purpose synthesizer at some point but I'm focuing on 1 channel audio for the moment. Right now, I'm just trying to determine what the best way to do audio output on a PSoC is.

Someone in another thread has demonstrated 10bit audio with 2 lpf in succession with great results.
User avatar
kenlem
The Big Cheese
The Big Cheese
 
Posts: 370
Joined: Tue Oct 05, 2004 6:55 pm
Location: Maine, USA

Postby kenlem on Wed Sep 07, 2005 9:11 am

That sounds like a great trick. I'll have to try it once this project is over.
User avatar
kenlem
The Big Cheese
The Big Cheese
 
Posts: 370
Joined: Tue Oct 05, 2004 6:55 pm
Location: Maine, USA

Postby IDiod on Wed Sep 07, 2005 9:30 am

Sorry, read the "ADC" as "DAC" in all my previous posts :)

ADC occupies the most significant area in my brain than DAC :)
User avatar
IDiod
The Big Cheese
The Big Cheese
 
Posts: 193
Joined: Thu Jan 08, 2004 11:59 am
Location: Russia

Next

Return to PSoC1 General

Who is online

Users browsing this forum: Bing [Bot] and 4 guests