2024-02-15 12:24 AM
Hello,
I have been experiencing a problem with the usage of the internal ADC on my STM32L476RG Nucleo64 development board. Unfortunately I have not been able to find similar problems online or in the forums.
I would like to use the highest possible sampling rate (5.33 MSps according to https://wiki.st.com/stm32mcu/wiki/Getting_started_with_ADC). However, this wiki article uses the clock divisor of 64x and sample time of 92.5 cycles.
For testing purposes, I am generating a 1Hz 3.3Vpp sine wave with an Agilent 33250A waveform generator and measuring the signal on the wire to the ADC pin with an oscilloscope. As sample rate increases, the signal is distorted immensely.
The signal at 64x clock divisor.
The signal at 8x clock divisor.
The signal at 1x clock divisor.
It seems odd to me that the ADC is strong enough to overpower a waveform generator.
I am using DMA sampling across five channels (though this signal is only on the first one) and writing into a 500x5 buffer.
void OptionReadAllRaw() {
eprints("Option 0: Read Raw Data From All Sensors\r\n");
OpMode = ReadAllRaw;
HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);
HAL_ADC_Start_DMA(&hadc1, (uint32_t*) SensorData,
SENS_BUF_LEN * SENS_BUF_WID);
}
void TickReadAllRaw() {
if (SensorDataLastProcessed != SensorDataFresh) {
uint16_t offset = SENS_BUF_LEN / 2 * SensorDataFresh;
SensorDataLastProcessed = SensorDataFresh;
char interm[100];
ClearString(sbuf);
for (int i = 0; i < SENS_BUF_LEN / 2; i++) {
sprintf(interm, "%i %i %i %i %i\r\n",
SensorData[i * SENS_BUF_WID + offset + 0],
SensorData[i * SENS_BUF_WID + offset + 1],
SensorData[i * SENS_BUF_WID + offset + 2],
SensorData[i * SENS_BUF_WID + offset + 3],
SensorData[i * SENS_BUF_WID + offset + 4]);
strcat(sbuf, interm);
eprints(sbuf);
}
}
HAL_Delay(200);
}
I am aware that this will not be sending all of the data; my main issue for now is that the data is bad.
The ConvCplt and ConvHalfCplt callbacks only flip a flag.
Could anyone explain what is happening, and how I can ensure that the ADC readings of values are accurate at the highest possible sample rates?
Please let me know if I can provide any more information on the setup.
Thanks in advance.
Solved! Go to Solution.
2024-02-15 01:23 AM - edited 2024-02-15 01:25 AM
50 ohm is perfect ! (standard for sig.gen. also...)
But when you see the adc switching its 5pF sampling cap to the pin and this giving a visible jump: you have maybe 50K ohm ... 1Mohm impedance at the input pin !
NEVER 51 ohms !
Look again, what you connected and take a DMM to check the resistance of the cabels you use.
btw some sig. generators have output switch : hi-impedance / 51 ohm --- look at your setting there.
2024-02-15 01:01 AM
Hi,
Whats the output impedance from the generator ?
Because i see no distortion, the signal is just getting small...looks like high impedance there.
-> ADC here is " Capacitive Charge Redistribution ADC " ,
read about :
The higher the sampling rate, the lower its input impedance ! So you have to drive it with low impedance buffer amp, if you want hi speed sampling.
See ds -> adc...
2024-02-15 01:05 AM - edited 2024-02-15 01:09 AM
I will look at the impedances, thank you.
Here are some more images:
I suspect that the smearing in the big wave and the jumps in the close up are caused by individual samples - this is at 256x clock divisor, so the slowest that DMA continuous read will go.
The waveform generator has a (fixed) output impedance of 50 Ohm - is that alright?
2024-02-15 01:19 AM
This looks like a problem with the high output impedance of the generator. There may be a problem in the generator or its settings, in the wiring, in the PCB. I would try to load the generator circuit through a resistor, using the unchanged wiring. I would also try measuring with an oscilloscope at different points in the signal path (generator output, PCB connection, MCU pin)
2024-02-15 01:23 AM - edited 2024-02-15 01:25 AM
50 ohm is perfect ! (standard for sig.gen. also...)
But when you see the adc switching its 5pF sampling cap to the pin and this giving a visible jump: you have maybe 50K ohm ... 1Mohm impedance at the input pin !
NEVER 51 ohms !
Look again, what you connected and take a DMM to check the resistance of the cabels you use.
btw some sig. generators have output switch : hi-impedance / 51 ohm --- look at your setting there.
2024-02-15 01:35 AM
Thank you both for your answers... I see now it was a brain moment - the waveform generator itself has 50Ohm impedance, but I was using a 1MOhm Probe... :grimacing_face:
The signal generator was a test, I will update further if I encounter similar problems on sensors...
Thanks again