cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F334 ADC Jumps

jls
Associate II

Hello,

 

I am using a STM32F334 for a project where I am reading several analog channels, specifically connected to thermistors. I am using DMA to read the analog channels and also sending this data out on UART via DMA. 

 

I am seeing some weird jumps in the data, which also correspond with longer than normal intervals between sending UART data.

 

It seems like only analog data is doing this and I'm wondering why. Does it maybe have something to do with DMA? I have different priorities set for the DMA streams in the STM32Cube project configuration. 

 

I am sampling the internal temp sensor channel, Vref, and Vbat channels, if that is useful. I have the longest sampling interval set as well. 

 

Any help or tips appreciated. 

 

 

8 REPLIES 8
TDK
Guru

It seems like you are not sending out in regular intervals, so you are missing out on data when the interval is longer than normal. This would explain your plots.

What is the cause for delays in sending UART data? Has to be something in your code slowing the process down, or causing delays.

If you feel a post has answered your question, please click "Accept as Solution".
jls
Associate II

Thanks for your reply. 

 

I'm not sure why there is this intermittent longer interval in UART sending. I just have one main loop with the same calculations running and then the UART DMA transmit is sending every 150 loop iterations. 

 

I also have another plot from the same data collection which is showing loop speed (see attached) and internal MCU temp. 

 

I wonder why I don't really see this jumpiness in those plots, but only in the thermistor connected ADC channels. 

 

Any other thoughts based on this? 

 

Thanks

Loop speed and mcu temp look to be mostly constant. I don't think the jump would show up on those plots.

Send a timer value such as HAL_GetTick with each UART burst and plot it, I'm sure the problem will be evident there.

It's also possible the thermistor data is just real. Is something happening every 10-15 seconds? Temperature going from +13 to -13 over 2 minutes is weird. Is this in a refrigerator or something?

If you feel a post has answered your question, please click "Accept as Solution".
jls
Associate II

Thanks for the reply. 

 

I can try that, it seems like a good idea. 

 

The thermistor data is real though. I heated it up at the start with hot-air and this data was taken from when it was naturally cooling in the ambient air. 

 

I will see if I can send out a timer value and plot that. 

 

If the timer value is also jumping, what else could I do to make the UART transmit more consistently with DMA?

If the data is from a cooling thermistor, then yeah there's probably delays happening you aren't aware of.

Delays are going to be caused by a code bug. Hard to say what without seeing the code. Do you check return values from HAL send functions? How are you ensuring things are sent out regularly? Details matter here, hard to say anything definitive without looking at code.

Look at overall data output rate vs available bandwidth. How much data per second are you sending vs how much data is able to be sent over UART with your settings? If you're exceeding availably bandwidth, that's your problem.

If you feel a post has answered your question, please click "Accept as Solution".
jls
Associate II

Hello, thanks again. I am sending 48 bytes of data every 150 iterations of the loop. This is at 115,200 baud rate. This should take about 3.3 ms for the data to be sent out. Since my loop speed seems to be around 5000 Hz, I should have around 30ms between each send command. I am not checking the return values from the HAL send functions but I can try doing that. The only interrupts I have enabled are the ADC conversion complete interrupts. So I think nothing else should be affecting the loop running continuously except for possibly that. 

 

I will try running the timer experiment later tonight where I send out a timer value on the UART data burst. I keep thinking there might be some conflict with DMA between ADC and UART, but I have different priorities set for the two of them and have tried a lot of different settings. I should hopefully get some more insight with a few more experiments though. I'll share what I find. 

 

Let me know if anything else comes to mind.

 

Thanks. 

TDK
Guru

> I keep thinking there might be some conflict with DMA between ADC and UART

Why? Think you're chasing the wrong thing here. UART at 115200 baud isn't taxing even 1% of the DMA bandwidth. Priorities won't matter--DMA can service everything quickly enough.

If you feel a post has answered your question, please click "Accept as Solution".
jls
Associate II

I changed some of the priorities of the DMA and interrupts and restructured the code a little bit and was able to get the problem to go away.