Shop OBEX P1 Docs P2 Docs Learn Events
PWM+RC Audio Output - R & C values — Parallax Forums

PWM+RC Audio Output - R & C values

hippyhippy Posts: 1,981
edited 2008-09-29 12:17 in Propeller 1
I'm wondering, using a simple RC to turn PWM into an audio output, what are the best R and C values to use ?

I chose the 220R plus 100nF as Jeff uses in the Propeller Cookbook and it sounded okay to me, but I won't deny that, at my age, my ears may well be full of fluff while Punk Rock undoubtedly also took its toll.

I'm thinking of the case where the RC ( via the 10uF electrolytic ) would be fed directly into a Hi-Fi or similar home-AV amplifier. Presumably a multi-filtered RC setup would be best, but I'm just after a single RC.

Comments

  • Ken PetersonKen Peterson Posts: 806
    edited 2008-09-28 00:58
    Hippy: I believe a typical audio amp has an input impedance of about 10Kohm. Therefore, I would choose 10K for R and calculate C based on your desired cutoff frequency. The values on the demo board might be a good start.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"I have always wished that my computer would be as easy to use as my telephone.· My wish has come true.· I no longer know how to use my telephone."

    - Bjarne Stroustrup
  • hippyhippy Posts: 1,981
    edited 2008-09-28 03:07
    With cutoff being, f = 1 / ( 2 * pi * R * C ) as per en.wikipedia.org/wiki/RC_time_constant, and something like 20kHz cutoff I'd guess - lower, higher ?

    Jeff's design has cutoff just above 7kHz. 10K for 20kHz gives 800pF. For the demo board (10K, 10nF ) I make the cutoff just 1600Hz - That seems very low to me. Have I got the maths wrong ?

    Added : Geared up with some new search criteria words I belatedly found this ...

    http://forums.parallax.com/showthread.php?p=606294

    Post Edited (hippy) : 9/28/2008 3:27:06 AM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2008-09-28 03:44
    hippy,

    47nF and 220R gives a frequency roll-off of 15.3kHz
    33nF and 220R gives a frequency roll-off of 21.5kHZ

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • hippyhippy Posts: 1,981
    edited 2008-09-28 13:40
    Thanks Beau, that makes the maths look okay.

    As you can probably tell it's really the electrical aspects of this I have no idea of. I could keep with the 100nF ( convenient as I have them ) and drop the 220R ( easy ) but is it better to go low-R high-C or high-R low-C, or is there really no difference ?

    Does the actual update of the PWM have an impact here ? Updating FRQA/B every 64uS gives 16kHz, so what should the cut-off be in such a case, I'd presume at or lower than 16kHz, 8kHz if thinking about nyquist ( so 220R+100nF is okay ) but I may be off-track in that.
  • Ken PetersonKen Peterson Posts: 806
    edited 2008-09-28 14:06
    Hippy: As I said, your choice of a resistor value depends on the input impedance of your audio amplifier. Then choose your capacitor accordingly. Most line level inputs on amplifiers are about 10K or so. The demo board also uses 10K resistors.

    Yes, the update rate does matter as it is your sampling rate, which should be twice the cutoff frequency of your filter or you will start hearing noise and beat frequencies generated by the sampling frequency mixing with your audio. The PWM frequency should also be much higher than twice the cutoff frequency.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"I have always wished that my computer would be as easy to use as my telephone.· My wish has come true.· I no longer know how to use my telephone."

    - Bjarne Stroustrup
  • hippyhippy Posts: 1,981
    edited 2008-09-28 16:34
    Thanks Ken, it's starting to make sense.
  • AribaAriba Posts: 2,687
    edited 2008-09-28 21:50
    Normally a simple R-C lowpass with 1/2 of the sampling frequency would never be suitable for acceptable Audio quality.
    But with the DUTY mode of the propeller counters, you don't have a fixed PWM sampling frequency. The PWM frequency is very high (40 MHz) at 50% output voltage and goes down to 80MHz/32767 = 2.4 kHz at the Min and Max output voltage (for a 16 bit DAC). Because the ear is only sensible for sampling artefacts at quiet parts of the audio signal, and the PWM frequency is very high then, the DUTY mode is perfect for Audio output.
    It also works without any R-C filter, but then you have 40 MHz RF on the audio cable, and this can produce interferencys on TV and Radio.

    Andy
  • Ken PetersonKen Peterson Posts: 806
    edited 2008-09-29 02:08
    The PWM isn't as much of a problem as the sampling rate. That is the rate at which you change PWM values. This can also cause aliasing and noise if it is not sufficiently higher than the filter cutoff. Probably not a problem if you are just doing speech, but if you want good quality music then it's something to pay attention to.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"I have always wished that my computer would be as easy to use as my telephone.· My wish has come true.· I no longer know how to use my telephone."

    - Bjarne Stroustrup
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2008-09-29 04:55
    "is it better to go low-R high-C or high-R low-C, or is there really no difference ?"

    I wouldn't go to LOW on R, since this aspect is to protect the I/O pin from excessive current.
    Basically you should consider the capacitor regardless of its value as a short circuit during an I/O transition, and the possibility that the I/O could see twice the supply voltage during this transition.

    The typical impedance for a HiZ microphone input is defined as greater than 10,000Ω
    The typical impedance for a MedZ microphone input is defined as 600Ω - 10,000Ω
    The typical impedance for a LoZ microphone input is defined as less than 600Ω

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 9/29/2008 5:10:05 AM GMT
  • hippyhippy Posts: 1,981
    edited 2008-09-29 12:17
    @ Beau : Many thanks again. I did the back-of-a-napkin calculation of current in considering dropping 220R+100nF to 120R+100nF ( takes cutoff up towards 15kHz ) but never thought about I/O seeing twice the voltage on a transition.
Sign In or Register to comment.