This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PWM Audio with the MSP430

Hello,

   I'm trying to generate some simple tones using PWM and the MSP430.  I'm following this app note: http://www.ti.com/lit/an/slaa405a/slaa405a.pdf

   My PWM frequency is 32kHz as in the app note but I'm getting a lot of static on the output.  I have an audio amp and it doesn't seem like the noise is coming from there.  If I connect a speaker directly to the 430 (I'm using the EXP430F5529 board) I still hear static.  I'm running this single ended, any thoughts as to filtering?  Would this help reduce static or is this just something you live with for PWM audio?  I'm also using fairly long leads which may contribute to the problem.

   I simply converted windows .wav tones to 8-bit to get my sound files.  I'm also getting a significant pop at the end of the tone.  There's no static when the PWM isn't running.  (sorry, trying to give a lot of info).

   Thanks, any thoughts would be appreciated.

Craig

  • How does your RC filter look like? Do you have oscilloscope?

  • Craig Carder1 said:
     My PWM frequency is 32kHz as in the app note but I'm getting a lot of static on the output.

    What kind of low-pass filter do you use? What is cut-off frequency?

    Craig Carder1 said:
     I'm also using fairly long leads which may contribute to the problem.

    Test it! Use fairly short leads and check results.

    Craig Carder1 said:
    I simply converted windows .wav tones to 8-bit to get my sound files

    Do you hear your sound too or just static?

    Craig Carder1 said:
    I'm also getting a significant pop at the end of the tone.

    Possible problems: 1) you "cut" your sound at wrong place. Make fade-out for your PCM audio using some sound-editing software.

    2) you switch off PWM. - Don't! To avoid pop you shall run it continuously at 50% duty cycle ("play silence" PCM audio data) when you are not playing your ".wav tone".

  • I don't currently have a filter on the input.  I tried multiple filters on the output which only seem to reduce the overall volume.

    I'm planning to try a simple RC filter on the input.

  • Ilmars said:

     My PWM frequency is 32kHz as in the app note but I'm getting a lot of static on the output.

    What kind of low-pass filter do you use? What is cut-off frequency?

    I don't have one on the input, but I'm going to try and add a simple RC.

    Craig Carder1 said:
     I'm also using fairly long leads which may contribute to the problem.

    Test it! Use fairly short leads and check results.

    Will do.

    Craig Carder1 said:
    I simply converted windows .wav tones to 8-bit to get my sound files

    Do you hear your sound too or just static?

    I hear the sound, and it sounds fine, there is just a lot of static in the background.

    Craig Carder1 said:
    I'm also getting a significant pop at the end of the tone.

    Possible problems: 1) you "cut" your sound at wrong place. Make fade-out for your PCM audio using some sound-editing software.

    2) you switch off PWM. - Don't! To avoid pop you shall run it continuously at 50% duty cycle ("play silence" PCM audio data) when you are not playing your ".wav tone".

    I may have to fade out the PWM.

    [/quote]

  • PWM without filter will create lot of harmonics, especially when freq is so low, 32khz. You need filter. And filters attenuate signal. if you dont like attenuation of RC filter, you need to add OpAmp.

  • You need a lowpass filter on the output to convert the PWM into the correct signal. The cutoff frequency should be less than 1/2 of your sample frequency.

    If your filter is passive, just use appropriate RC to get the cutoff you want and to match the impedance to the speaker. Your other option is an active filter (op-amp based) in which case you can add in some gain to get your desired volume level. Again you need to match the cutoff frequency and impedance.

    Your pop is due to the abrupt change back to a 0V average DC voltage. Remember that the speaker is inductive and you are also likely to get a spike back into the MSP430 which may not be very nice to the port pin transistors.

    Remember, using PWM, you are basically charging/discharging the capacitor on the filter in the ratio of the pulse width to pulse frequency. This is why the filter is necessary.

  • Brian Boorman said:
    Your pop is due to the abrupt change back to a 0V average DC voltage.

    0V average AC voltage. There can be two kind of pops in digital amplifiers: 1) pop caused by PCM data itself (clipped sine) or 2) pop caused by amplifier, in particular case it most likely could be switched-off PWM. If for example final PWM pin state is continuous logical "0" then output AC voltage quickly goes from 0V average to extreme negative which will result in nasty pop.

  • Ilmars said:

    Your pop is due to the abrupt change back to a 0V average DC voltage.

    0V average AC voltage.

    [/quote]

    Well now, if he has no coupling cap and no RC filter, then aren't the AC and DC voltages one and the same?

  • Brian Boorman said:
    if he has no coupling

    This is just assumption. Yes, he did test using "directly connected speaker" but he mention audio amplifier too. 0VDC as idle state is anyway totally wrong for any audio DAC having unipolar supply & output. Such output shall have coupling by definition.

  • Ilmars said:

    if he has no coupling

    This is just assumption. Yes, he did test using "directly connected speaker" but he mention audio amplifier too. 0VDC as idle state is anyway totally wrong for any audio DAC having unipolar supply & output. Such output shall have coupling by definition.

    [/quote]

    I did connect the speaker directly (no coupling) and through and amp (coupling).  I heard the pop in both cases.

    Thanks for the feedback everyone, I'm in the process of testing some of these idea now.  I'm going to include input filtering on the amp and I'm going to try and 'fade out' the PWM at the end of the tone (I can't keep PWM running the whole time).

    Thanks

    Craig

  • Craig Carder1 said:
    I'm going to include input filtering on the amp and I'm going to try and 'fade out' the PWM at the end of the tone (I can't keep PWM running the whole time).

    Great! But don't forget to implement "fade-in" also. Generic idea is - slowly charge coupling capacitor by increasing PWM duty cycle from 0 to 50%, then play sound, then gradually "switch off" PWM by gradually decreasing duty cycle from 50% to 0% (logical "0" on PWM output). I assume that you will be fine with 1/2 .. 1 sec  transitions and they will not be audible.

**Attention** This is a public forum