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?