4

Any common Audio output on any electronic device is in essence a two-channel Digital-to-Analog converter, where the voltage sent to each of the channels (Left, Right) powers the electromagnet that drives the movement of the speaker membrane. Instead of sending a cyclic waveform like a sine, you generate a "sound" that is in essence one fixed level, silence but with bias against the "zero value". By gradating that level you can use that signal to other purposes - I did use it, driving a DC motor directly from my ISA SoundBlaster16 card in the past (it had some wicked strong on-board amplifier!)

In more modern hardware though, getting there may be more difficult. Codecs and such will often identify constant signal and replace it with zero on output, or such. How is it done in Raspberry Pi? I don't know, I'm asking.

Can I drive the built-in audio output (jack) directly - bypassing codecs, just tell the chip to output certain voltage level to the audio output which then I would use to drive some external components? I realize I can do PWM but that's not entirely the same thing - I'm interested in pushing specific voltage levels, instead of just a full-voltage signal with specific fill. If it's possible, could you write, how - on the software side?

SF.
  • 920
  • 1
  • 8
  • 21

1 Answers1

7

Yes, however, you need to short the two smd capacitors on the back of the PCB right by the Audio output jack (labeled C34 and C48 for me, one for each channel).

You will get an output range from 0-1V. You can keep the sample values constant and get a constant voltage. For example, using a 16bit mode and only the sample value 0 you get a constant 0.5V (0 = mid point in a signed 16bit range).

However, since this was designed for audio, you can't just set an output value like you could on an adc. You need to fill a sample buffer with the sample values that you want. If you want to change the values then you need to wait until the previous buffer has been played.

For source code, see the (in rasperian) included: /opt/vc/src/hello_pi/hello_audio/audio.c

Just change the sample value for each channel to what you want, for example to 0x7FFF for max (1V), use:

for(j=0; j<nchannels; j++)
{
    if (bitdepth == 32)
        *p++ = 0;
    *p++ = 0x7FFF;
}
Nia
  • 136
  • 3