cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 ADC Triple Mode DMA Interrupt problem

pant
Associate II
Posted on June 24, 2015 at 19:34

The original post was too long to process during our migration. Please click on the attachment to read the original post.
18 REPLIES 18
Posted on June 25, 2015 at 01:06

Finally, concerning the ADC saturation, I saw that you didn't use ContinuousConvMode in your code, however in my code, unless I enable the continuous mode nothing works. I would expect that without using the continuous mode, I should get a measurement everytime the TIM2 triggers my ADC, however it doesn't work.

I don't see where you enable the TIM2 APB clock, so the peripheral's probably not functioning, and not triggering. When you want to debug these issues you break them into small pieces, for example by outputting the TIM clock via one of the Channels in PWM mode. I confirm sample frequencies by toggling pins and scoping those. It's less invasive than using a debugger.

If the DMA FIFO is a concern, you can disable it.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pant
Associate II
Posted on June 25, 2015 at 01:14

Dear Mr Clive,

  Thank you very much for all your help! I will test everything, first thing in the morning. Once I have it tested, I will return to give you some feedback about my progress and whether it worked or not.

Once again thank you.

Regards,

Pantelis

pant
Associate II
Posted on June 25, 2015 at 12:03

Dear Mr Clive,

Just tested the code and of course as you correctly mentioned I had forgotten to enable the timer, which was really stupid!  Excuse me for that.

Thank you very much for your help. Have a nice day!

Regards,

Pantelis

pant
Associate II
pant
Associate II
Posted on June 25, 2015 at 16:20

Just to define my problems of the above post a bit more properly.

Even though the timers as you can see from the PWM pulses have exactly the synchronization I would like, they don't seem to work properly in general.

1. I should enter TIM1 interrupt once every 4 times I enter TIM2 interrupt. However I enter them 1x TIM1 -> 1x TIM2 and again the same.

2. The same more or less happens between TIM1 interrupt and DMA2 Interrupt. Actually between those two, sometimes I can have 2xTIM1 and 1xDMA2.

3. Everytime I enter DMA2 Interrupt, I would expect only three consequtive values of my Buffer (ADCTripleConvertedValues) to change. However, all of them change, and I can't understand why.

Thank you again for your patience and responses!

Regards,

Pantelis

pant
Associate II
Posted on June 25, 2015 at 19:40

Hi again,

I am writing in order to present to you my progress so far. After some reading, I realized that unless if configured otherwise, the timers don't stop working while debugging and going to breakpoint. Therefore I used a LED to turn on and off inside my TIM2 interrupt and compared it with TIM1 PWM outputs. And eventually it works properly. (TIM1 50KHz, TIM2 200KHz)

However that is not the case with the DMA. I changed the DMA code to turn on the LED in Half transfer and off in Full, and the result is a blinking of 10KHz and not of 200KHz, as I would like it, since ADC is being triggered by TIM2.

Moreover as I said before, everytime the code enters DMA Interrupt. Instead of having three new values in my buffer, I have everything changed. (Hope I am don't miss again any debugging configuration as with Timers above).

Thank you in advance for your help.

Regards,

Pantelis

Posted on June 25, 2015 at 20:23

I'd rather not have to wade too deeply into this. One could spend literally hours playing with the master/slave combinations, and triggers.

I perhaps would look at running TIM1 at 200 KHz, and give it a Repetition Count of 4. That would give a Update at 50 KHz, and the ability to control the phase of the channels on TIM1 at 200 KHz. Pulses via PWM modes, phase skewed/shifted clocks at 100 KHz via Toggle mode. The more that can be done autonomously in hardware the better.

Have to look at what trigger sources were available on the ADC side.

The TIM, ADC and DMA don't stop with the debugger, you can play games with DBGMCU but you're likely to get bitten by synchronization issues at some point. Better to output telemetry by other means, like USART, GPIOs, LEDs or DACs

Need to be wary of interrupts in the 100s of KHz, got to watch the number of machine cycles you have to work with very carefully.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pant
Associate II
Posted on June 26, 2015 at 01:30

Dear Mr Clive,

Thank you again for your reply. You are right and I totally agree that the more is done by Hardware the better.

Regarding the idea using the repetition mode, I didn't mention that actually I would like the frequency of the second timer to change in various values and not be constant at 200KHz, and in general the two frequencies to be totally independent with each other (of course always keeping the first smaller than the second). And to be honest with you I didn't exactly understand how to create the delay between the two timers.

An idea I had was if possible to use the three channels of TIM1 for the 3-phase PWM pulses and the fourth output as a master mode compare pulse to trigger TIM2 in the delay I want. Or use it as a PWM output and by setting the duty cycle equal to the delay, trigger TIM2 externally. Or a third idea would be to somehow make a third timer start simultaneously with TIM1 in output compare master one pulse mode and trigger every 1/50000 seconds TIM2.

I don't know if any of the above is feasible. They are ideas I got while studying the reference manual and while trying to understand how everything works.

However, apart from the above which is also a difficult subject. What I can't understand is what is happening with the DMA.

1. I know that the DMA doesn't stop with the debugger, that is why I will assume that it is correct the fact that in two consecutive breakpoint stops of the code in DMA2 interrupt, all the values of my cache are changed and not 3 of these. However am I correct to think that the DMA enters the interrupt everytime three values of the ADCcommon register are transfered? which means everytime the three phases are introduced in my cache?

2. Why if when I output the DMA Interrupt at a LED (using the method you told me with half and full transfer ON/OFF) I see a frequency of 10KHz? According to the reference manual, three DMA requests are generated  once the triple mode ADC capture takes places. As I understand that, the frequency of the LED inside the DMA interrupt should be either 200KHz in case it enters the interrupt once all three are transfered, or 600KHz, if it enters the interrupt separately for every ADC transfer (I'm not sure which of the above is correct). However instead of having that freq I have 10KHz. Which means either that something is wrong with the DMA, or something is wrong at the triggering of the ADCs from TIM2.

Excuse me for the many questions. I don't want you to think that I wait for everything solved without searching. It is just that my time is extremely limited and while trying to solve these problems and understand them in depth, at the same time I try to escape a bit and clear my brain by writing the easier parts of the code.

Again thank you for everything.

Regards,

Pantelis
pant
Associate II
Posted on June 28, 2015 at 17:43

Hello again,

I am sending this as a kind reminder for my question above. Regarding the Timer synchronization, I guess I will probably find a way to synchronize them properly.

However, what concerns me is about the DMA. I can't understand why I have that issue with the DMA and why I enter the DMA interrupt with a frequency of 10KHz. For me it is of great importance to know that I get my measurements exactly at the trigger time of Timer 2. Unfortunately, that doesn't seem to be the case, since the clock used to trigger the triple ADC capture is set at 200KHz and I enter the DMA interrupt function, with a frequency of 10KHz.

Could you please advise me, on what might be the problem and how to investigate it?

Thank you in advance.

Regards,

Pantelis