CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Better way of Digi Volume, PWM sound output

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
neochrome32



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

Better way of Digi Volume, PWM sound output
PostPosted: Wed Aug 27, 2014 6:32 pm     Reply with quote

CCS C 4.130
dsPIC 33 EP 512 GP 806

i have here a project that is going to use a single mono output (not enough pins for stereo, and for the application, not a big deal).

anyways, i am running a PWM at 400Khz for use in an 8BIT Unsigned PWM Duty style sound out.

Currently i am able to control the Volume via changing that 400Khz from 23khz - 400khz it affectively changes the volume (crude i think) BUT on a lower frequency i get a whistling sound, which i realise is because it really is 23Khz! not quite beyond human hearing....... ANYWAYS

I don't want to use analogue potentiometers to variate the output... i haven't been successful enough to use a DAC that appears to be available on this chip, it sounds muffled most of the time...


Other than mixing the sound output with the buffer, is there another. more hardware way to do this without using (outf * vol) method?

run down:
PWM at 23Khz - 400Khz

and i change DUTY for sound data out..


thanks for any advice, comments and << slaps >> :D
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 27, 2014 9:12 pm     Reply with quote

How many people can hear 23 KHz ? Very few. If you can hear it, then
put a low-pass filter on it. Limit the output frequency to 15 KHz. That's
fine for most people. A lot of people can't even hear that, especially if
they are older. You can easily do a low-pass filter with an opamp and
some resistors and capacitors.
Ttelmah



Joined: 11 Mar 2010
Posts: 19433

View user's profile Send private message

PostPosted: Thu Aug 28, 2014 1:59 am     Reply with quote

First, have you absolutely verified, that your PIC _is_ running at the frequency you expect. 23KHz directly is not normally audible. I can (just) hear some bat calls, at about 22KHz, and of about a hundred people who tried, only two could do this. So one thing to 'put to bed' first, is that you genuinely are generating 23K...

Then you haven't told use anything about the circuitry 'downstream'. One way you'd get a whistle, is if there is something else, that is acting to produce aliasing. So the signal is generating a 'beat'.

Then moving on, what is the input impedance of the circuitry being fed?. My guess is that it has perhaps a significant capacitive component. Using the DAC, you have a relatively high impedance source, so the high frequencies get more attenuated, hence 'muffled'....

Start by being a bit more careful how you process your signal. Buffer it, and possibly have something like a 15K low pass filter (both very easy with a single op-amp, if you aren't after anything too precise).

Try feeding signal in, through two (series) 10K resistors, to the +ve input of an op-amp.
Then connect the junction between these resistors to the op-amp output, through a 1nF capacitor. Have a second identical capacitor, from the +ve input to 'ground' (see below). Then have the output of the op-amp also connect back to the -ve input, through a 22K resistor, and the -ve input also connect to the 'ground' (whatever you use as the 'signal' ground - so possibly half way between the supply rails), through a 39K resistor.
This gives a second order filter rolling off at about 16KHz, with about 1.6* voltage gain, and a nice low impedance output to feed the following circuitry.

Now, there are many 'digital potentiometer' chips, and really these make the whole thing far easier. Quad I2C controlled units could give you all the controls you want, in a single small package. However you still have quite a bit of other circuitry involved. Consider using a chip designed to do it all. There are chips like the LM4832, which give bass, treble, volume controls, and an audio amplifier all in one package.
yerpa



Joined: 19 Feb 2004
Posts: 58
Location: Wisconsin

View user's profile Send private message Visit poster's website

PostPosted: Thu Aug 28, 2014 3:15 pm     Reply with quote

To get volume control, you can multiply your PWM value by a number between 0 (lowest volume) and 0xff (highest volume), then output the high byte of the 16-bit product.

You could read a potentiometer into an a/d pin to get the volume setting.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group