5
\$\begingroup\$

I'm trying to read an audio signal from an Android phone as a serial input to an MSP430G2553, adapting this design to use the MSP430's onboard comparator module instead of an LM324. The Android code to make a square wave out of the audio jack is available here. The output is a rather noisy square wave which is converted to a logic-level digital signal by the comparator. I'm shooting for a 4800 baud signal to the UART. The audio sample rate in the Android code is set to 41 kHz.

In my case, the comparator's positive input is the internal precision voltage reference (0.5*VCC) instead of an external pot. I have applied a DC bias to the audio signal in order to center it around the 0.5*VCC mark before going to the comparator's negative input on P1.5 (CA5). The "AUDIO" net is CA5 on the MSP430. C1 is a tantalum capacitor for no reason other than it's what I had on hand. DC bias circuit

I'm having some DC wander issues with the beginning of each signal which are causing the comparator to not trip properly at the beginning of the signal: square wave DC wander

Zooming in on the beginnig of the comparator input signal (now on scope CH2), you can see the undesired rapid switching on the comparator output on CH1:

comparator switching

I tried increasing the value of C1 to 0.47uF, but it takes an unacceptably long time to discharge (I forgot to save a graph of this with C1=0.1uF but it was shorter) at the end of the signal: long capacitor discharge

I suspect that the comparator toggling would be partially remedied by setting up the comparator as a Schmitt trigger, but I'm not sure it would work for the first few bits of the signal with the DC wander still in place. What do I need to change to get rid of the DC wander without a long capacitor discharge at the end of the signal?

Edit: Here's what the raw input looks like (left side of C1, scope CH1) compared to the biased signal on CH2. The biased output climbs a little more over the course of the signal. unbiased input and biased output

\$\endgroup\$
3
\$\begingroup\$

It looks as though the DC wander is caused by the android phone output, which is switching from 0V when the signal is off to some mixture of 0V and some negative voltage when the signal is on. The mean value when the signal is on is therefore a negative voltage (roughly half the peak voltage), which constitutes a DC offset from the no-signal value.

If you can change the android phone output, try making the signal symmetric (off bits at -1V, on bits at 1V, for example), which will remove this offset.

It looks as though you have an additional problem, which is that your biasing network sets the DC point of the android output to the same (Vcc/2) as the other input of the comparator; thus noise is causing unwanted transitions. Looking at your first scope trace, note that if the comparator threshold was instead set to the value of the thicker horizontal grid line across the centre of the screen (0V?), it would detect every transition without needing to modify the android code or use a Schmitt trigger.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ The total amplitude is dependent on the Android multimedia playback volume, let me dig into the code and see what I can figure out in terms of centering it that way. \$\endgroup\$ – Joe Baker Jan 8 '13 at 12:19
  • \$\begingroup\$ Bingo, there's byte variables for logic high and logic low. Sure enough, they were set to -128 and 16. I kept the same 144 range and centered it, getting good data now. \$\endgroup\$ – Joe Baker Jan 8 '13 at 17:01
4
\$\begingroup\$

This isn't DC wander, it's just AC coupling of a signal which has DC content. There are three common solutions to this problem :

(1) remove the AC coupling. This may not be possible; the Android may incorporate its own AC coupling. You can test this by looking ahead of the coupling cap C1. Unless your scope traces are inverted, if you see DC when idle then you can do this.

Then you need to replace the DC offset somehow... easiest way is to connect the bottom of R2 to the audio jack (LHS of C1) instead of to ground, removing C1 altogether.

Your last photo shows this option won't work; your input signal is also AC coupled, with a longer time constant. So, moving on:

2) A "DC restorer" (also known as a diode clamp in the analog TV days) You need a reference voltage, at 1.65V minus a diode drop, and a diode from "Audio" to this reference. As the signal drifts positive, the diode conducts, clamping it to prevent the drift. The negative peaks remain close to 0V. Details left as an exercise...

3) The way communications links are designed : eliminate the DC component of the signal so you can AC couple it without problem. There are any number of ways to do this - wiki Manchester coding for one, 8B10B code for another. The basic idea is that both 0 and 1 are represented by square waves (say, of different period) and the signal doesn't ever rest at either rail for any length of time. I'll go into more details of a simple scheme if you wish.

A benefit of a DC-free signal and AC coupling is that the comparator is set to a local "0V" point (like your supply/2) and works regardless of the signal amplitude (cable length, Android volume setting)

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.