0
\$\begingroup\$

I'm using the ADC of a STM32F4DISCOVERY to sample a signal. The sampled values are directly written to the DAC. I tested this and it worked absolutely fine, just as I would expect.

Now I wanted to control the application via a web interface. After the code was added for the ethernet interface, the sampled signal is messy. See picture below. (When I only use the DAC to generate a signal from software this ripple is not present, so it must by ADC related)

enter image description here

The input signal's level is shifted so it lies between 0 and 3V. This signal looks as I would expect. (I don't have a picture of this)

When I tie the input to 0V, the sampled signal looks like the picture below.

enter image description here

It looks like the ripple is added to the ADC pin by the code for the ethernet. Could a signal on a certain IO port mess with other signals on that port?

enter image description here

As shown in above picture, the ADC is connected to Port C, Pin 2. Also connected to Port C are: ETH_RXD0, ETH_RXD1 and ETH_MDC. I suspect one of these signal to mess with the ADC reading, as the signal looks perfectly normal without the ethernet code.

Has anyone else ever had such a problem?

Edit: Some extra information:

The input signal comes from an 60 Hz AC source, see schematic below.

enter image description here

This is run through a transformer, then it's level shifted and de-amplified. When testing I bypass the transformer and use a signal generator to generate the signal(60Hz, 20Vp-p). This is the input signal from the first picture!

Also, I can produce a neat, clean signal from a look-up-table with only the DAC, the DAC is working fine (no interference on the DAC output).

The input signal is sampled at 50kHz. If the timer runs irregularly, it would not matter, because it has to write the ADC value of that particular moment to the DAC. If the timer was interrupted a few times per second and, let's say, only runs at 48kHz or 40kHz for that matter. This would still produce a decent sine wave. At least it won't explain the oscillations on the output.

When I debug the code, I see the value, read from the ADC, shifting up and down when I tie the input to zero.

I will try some of the suggestions in the answers later today.

\$\endgroup\$
3
  • \$\begingroup\$ I do have a similar problem. My ADC readings gets very noisy when I enable the timer 2 to calibrate the Low Speed Internal (LSI) oscillator. Not 100 % sure that this alone is what does it, but when I disable the TIM2, the ADC works fine. I have not found a solution to this problem. \$\endgroup\$ Commented Apr 2, 2014 at 13:52
  • \$\begingroup\$ I'm unfamiliar with the STM32 but things like interrupts can introduce timing issues / odd delays / conflicts in other code that runs normally when it has 100% of the CPU cycles to itself. \$\endgroup\$
    – John U
    Commented Apr 2, 2014 at 14:15
  • 1
    \$\begingroup\$ The signal is still not perfect but it is better now. I haven't been able to locate the source of the problem yet, but I know it is a analog interference. To clean the signal a little bit I used an averaging algorithm which takes multiple ADC reading and averages this before it is send to the DAC. Also I placed capacitors on the supply rails of the circuits and a capacitor on the ADC and DAC lines. \$\endgroup\$
    – Matthijs
    Commented Apr 4, 2014 at 7:37

2 Answers 2

2
\$\begingroup\$

All DACs require a voltage or current reference. The reference can be supplied by an external chip, or be built-in to the DAC.

Here is one thing you should check: Is your reference oscillating?

Causes of reference oscillation include:

  1. not using a filter capacitor that a manufacturer recommends on the reference output of DACs with built-in references

    1.1 not using a filter capacitor that a manufacturer recommends on a external reference output

  2. using a filter capacitor with the wrong ESR (Equivalent Series Resistance)- consult the data-sheet of the reference
  3. oscillation in an op-amp circuit which "buffers" the reference due to capacitive loading or design error.

    3.1 Not using an op-amp "buffer" circuit when one is required. Are you drawing too much current from the reference?

  4. Excessive noise on any power supply (try powering up your circuit from the appropriate combination of batteries)

It does not look like a digital interference problem because the disturbance seems to be very steady, and there are no "spikes" or other discontinuities in the waveform. To be sure, please measure the frequency of the disturbance and find interference that varies at the same frequency or an i/o port read or write that occurs at the same frequency

\$\endgroup\$
0
\$\begingroup\$

You hold all the aces dude so I'll just scatter gun a few ideas and observations: -

  1. Your first picture shows the input to ADC and the output from DAC - presumably ADC and DAC use same voltage reference so why are their p-p amplitudes different? If in fact the input is not at the pin of the ADC then be prepared to slap yourself on the wrist!!
  2. The ripple from the DAC when 0V on input - what frequency is it and what frequency is your input waveform? Also what sampling rate are you running at and presumably you are doing 1:1 ADC conversions to DAC outputs?
  3. If you magnified the DAC scope trace, can you identify flat portions that correspond to individual samples - if you can see samples on the trace but they are not flat but rounded like the "ripple" then this is an external analogue noise issue.
  4. Your voltage reference - if external you may need a 10uF capacitor from it to analogue ground.
  5. Where is the analogue ground and where is the analogue Vcc pins on the device?
  6. Are you aware that although you may have selected the internal analogue reference on your MCU, the reference pins will likely still emerge as pins and might need decoupling. I'm not saying definitely just possibly.
  7. Does the ripple/noise go away when the ethernet connection is physically disconnected i.e. the plug removed or the wires made open circuit (all of them)?
  8. "It looks like the ripple is added to the ADC pin by the code for the ethernet." Code can't add ripple to an ADC pin to my knowledge.

Good luck and let us know what you find.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Re: 8 - Code can't add ripple, but turning on peripherals can, particularly if the grounding isn't great, and the peripheral you're turning on is both clocked and power hungry. \$\endgroup\$ Commented May 3, 2014 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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