Get negative voltage from DAC

The DAC on my microcontroller can produce a voltage in the range 0 - 3.3 volts.

I want to connect the DAC to the "microphone in" of another module, but of course the other module is expecting a microphone signal that goes positive and negative, from about -2.2v + 2.2v.

So I was thinking, I could use two pins on my microcontroller, one as a digital out and the other as a DAC, and swap the pins back and forth like this:

In theory it looks like this should work . . . Has anyone done this before?

My microcontroller would output a voltage on the DAC pin of 0v to 3.3v, and so in order to get that in the range 0v to 2.2v, I would use a resistor ladder as follows:

The code inside my interrupt routine would be something like:

void InterruptRoutine(void)
{
    char unsigned const value = *samples++;

    if ( value >= 128u )
    {
        pinMode( 1, DAC );
        dacWrite( 1, (value - 128u) * 2u );

        pinMode( 2, OUTPUT );
        digitalWrite( 2, LOW );
    }
    else
    {
        pinMode( 2, DAC );
        dacWrite( 2, value * 2u );

        pinMode( 1, OUTPUT );
        digitalWrite( 1, HIGH );
    }
}

Do you reckon this will work?

Most people just use a capacitor (1 to 10 uF) to block the average DC voltage. If the DAC audio output swings between 1 and 3V, the output after the capacitor will swing from -1 to 1 V.

The grounds must be shared, of course.

Thanks @jremington, I stuck a 5 uF capacitor going from the DAC to the 'MIC in' of the SIM800L module, and then in my interrupt routine I write the 8-Bit audio samples from my global array to the DAC. It's working :slight_smile: I phoned my device just now, it answered and played a wave file :smiley:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.