cancel
Showing results for 
Search instead for 
Did you mean: 

How can an ADC input read influence the encoder input ?

sde c.1
Senior II

Hi!

we use STM32G473 with 4 timers for 2 motors, for each motor we use 2 timers connected with ITR , the first timer is used as encoder input to hold the position, the second timer interrupts on each edge of of the encoders and calculate the speed.

When only 1 motor is running speed measurement is fine. But once i enabled the second motor, the speed measurement of motor 1 was messed up.

Searched for 2 days to find the cause.

It turned out that each ADC read causes 28µs spikes occuring every 3ms in one of my encoder pulses of motor 1. (I scan the ADC every 3ms). Once i disable the ADC reads , the spikes disappear, and speed measurements stay stable.

The spikes become much bigger with 2 motors enabled which caused the input capture interrupt to trigger .

We took a look at the PCB at the encoder line we we don't see a posibility for crosstalk.

the code to read the MotorCurrent is this :

uint16_t adc_get_integer_value(AnalogSelect_t select){
	uint16_t ADCresult;
	HAL_StatusTypeDef result;
 
	result = HAL_ADC_ConfigChannel(analog_inputs[select].phandleradc, &analog_inputs[select].config);
	if (result != HAL_OK) {
		Error_Handler();
		return 0;
	}
 
	HAL_ADC_Start(analog_inputs[select].phandleradc);
	HAL_ADC_PollForConversion(analog_inputs[select].phandleradc,2);
	ADCresult = HAL_ADC_GetValue(analog_inputs[select].phandleradc);
	HAL_ADC_Stop(analog_inputs[select].phandleradc);
	return ADCresult;
}

This feels like a bad layout of PCB, but i was wondering if STM32G473 have any known issues with encoder inputs when using the Analog inputs?

0693W00000YAAegQAH.png

3 REPLIES 3
LCE
Principal

You could try changing sample rate and / or sample & hold, DIF/SE settings and see what changes.

Important: any capacitors at the ADC inputs?

That's why I like the good old PI-filter, works in both directions...

I'd try some pF / nF at both the ADC and the encoder inputs.

PCB grounding near ADC really good? No broken GND?

If the scope picture shows encoder signal + spikes, then the encoder signal routing seems to be good, but heck what spikes!

yeah, it almost look like the encoder inputs are briefly set as output.

The adc goes directly to the sense resister of the motor driver without any cap, resistor ,

buffer or filter.0693W00000YAE6YQAX.png

That's bad. An ADC is a switching device, esp. if it's working with a sample & hold circuit. Always put a capacitor to an ADC input.

I would put a small cap (depends on signal freq, but I guess 100pF .. 10nF would be okay) close to the STM32 ADC input, and - just in case - another cap parallel to R13.

Important: use C0G / NP0 caps.