I think you are making this way to complicated. To the best of my knowledge, the speaker is controlled by a single bit and a square wave is sent to it to produce the tones. The speaker has a limited response and the volume will start decreasing at some higher frequency as the mechanical parts of the speaker can only move so fast. By decreasing the on time of the input to speaker you will effectively be increasing the frequency that the speaker responds to, and at some point the volume should start decreasing. So by knowing what on pulse time produces full volume and what on pulse width produces no sound, you can control volume with the on pulse width while keeping the original frequency. Bill ----- Original Message ----- From: "Hector Martin" To: "Microcontroller discussion list - Public." Sent: Saturday, May 07, 2005 6:37 AM Subject: Re: [EE]: PWM for volume control > Gerhard Fiedler wrote: > > I'm not sure about using PWM for controlling audio volume in general. Most > > PWM frequencies are within the audio range, and you'd need to do some good > > filtering to get rid of this unwanted artefact in the output. Maybe in the > > case of the PC speaker this is less of a problem, but maybe not. The ear is > > pretty good in hearing those things over several decades. > > Yeah, of course I need to have decent filtering so that the signal is > not audible (or barely audible, since when the PC speaker is beeping a > very weak PWM tone would not be noticeable, and the tone would be off > when the speaker is idle). > > > > > What's your overall objective? Does it have to be PWM? If you just want to > > manually control it, a simple pot would be enough :) If you want to be able > > to do electronic control, some kind of multiplying DAC could do it. That > > can be as simple as a bunch of resistors that form a 5 bit divider (which > > should be enough steps). Depending on how you want to control it, it may > > not even have to be a PIC -- an up/down counter for example could do it. > > Of course I want to use do electronic control ;) A multiplying DAC is > a good solution, but I do not want to add much complexity to the > circuit (besides, I'm already running out of PIC pins for other > stuff). I think this really should use an easier solution, since the > PC speaker sound is binary sound only. It really should be something > like using PWM to generate an analog voltage and then modulate it > according to the PC speaker input, simpler than a full-blown > multiplying DAC. So, really, it boils down to three points: > > 1. Smoothing out PWM to a decent analog voltage > 2. Modulating that voltage on/off according to the PC speaker input > 3. Amplifying the whole thing > > > -- > Hector Martin (hector@marcansoft.com) > Public Key: http://www.marcansoft.com/hector.asc > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist