cancel
Showing results for 
Search instead for 
Did you mean: 

ADC scan mode problem, STM32F407

rgrimes
Associate II
Posted on June 16, 2014 at 17:35

The original post was too long to process during our migration. Please click on the attachment to read the original post.
6 REPLIES 6
Posted on June 16, 2014 at 17:57

Not sure I have time to go over this completely, but the most obvious issues are:

tinit.TIM_Period = (84000000 / 553) - 1; // 152 KHz

Should be

tinit.TIM_Period = (84000000 / 152000) - 1; // 152 KHz

(number of ticks at 84MHz for a 152KHz period)

Stream ONE so IF1, not IF0

void DMA2_Stream1_IRQHandler(void)

{

  if(DMA_GetITStatus(DMA2_Stream1, DMA_IT_HTIF1)) {

    DMA_ClearITPendingBit(DMA2_Stream1, DMA_IT_HTIF1);

    STM_EVAL_LEDOff(LED2);

  }

  if(DMA_GetITStatus(DMA2_Stream1, DMA_IT_TCIF1)) {

    DMA_ClearITPendingBit(DMA2_Stream1, DMA_IT_TCIF1);

    STM_EVAL_LEDOn(LED2);

  }

}

Describes only half the buffer, the point is to describe the whole buffer and have interrupts at each half (HT/TC)

dinit.DMA_BufferSize = SAMPLES_BUFFER_HALF;

Should be

dinit.DMA_BufferSize = SAMPLES_BUFFER;

TIM2 is on APB1 NOT AHB1

// Enable peripheral clocks

  RCC_AHB1PeriphClockCmd(  RCC_AHB1Periph_DMA2  | RCC_AHB1Periph_GPIOA

                         | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOF

                         | RCC_APB1Periph_TIM2, ENABLE);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
rgrimes
Associate II
Posted on June 16, 2014 at 18:22

Hi Clive1,

1. Yeah, I blew the period - not worth explaining.

2. Yeah, missed the correct stream number for the ADC3 DMA ISR.

3. Buffer size, yeah.

4. And of course, the biggie!  That TIM2 peripheral clock mistake!  One lousy character - though it is more than one bit - and everything is broken!

Thanks to you, everything now appears to be working correctly!

Best regards,

Bob

rgrimes
Associate II
Posted on June 16, 2014 at 18:43

Not sure it matters to my app, but the TIM2 interrupt doesn't appear to be happening. Is it possible to generate interrupts using

TIM_IT_Trigger

? Or am I missing yet something else? Excerpts:

NVIC_InitTypeDef ninit;
TIM_TimeBaseInitTypeDef tinit;
. . .
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
. . .
ninit.NVIC_IRQChannel = TIM2_IRQn;
ninit.NVIC_IRQChannelPreemptionPriority = 0;
ninit.NVIC_IRQChannelSubPriority = 0;
ninit.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&ninit);
. . .
TIM_TimeBaseStructInit(&tinit);
tinit.TIM_Period = (84000000 / 152000) - 1; // 152 KHz
tinit.TIM_Prescaler = 0;
tinit.TIM_ClockDivision = 0;
tinit.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &tinit);
TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update); // ADC_ExternalTrigConv_T2_TRGO
TIM_ITConfig(TIM2, TIM_IT_Trigger, ENABLE);
TIM_Cmd(TIM2, ENABLE);
. . .
void TIM2_IRQHandler(void)
{
if (TIM_GetITStatus(TIM2, TIM_IT_Trigger) != RESET) {
TIM_ClearITPendingBit(TIM2, TIM_IT_Trigger);
STM_EVAL_LEDToggle(LED3);
}
}

Posted on June 16, 2014 at 18:43

If 152 KHz is critical, you could run the processor at 152 MHz rather than 168 MHz, although this would be problematic for using USB.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 16, 2014 at 18:49

I don't know, I'd perhaps just use the Update rather than the Trigger, but 152 KHz is getting a bit on the high side to be interrupting unless you have too. I'd probably check the pin was configure right, and then see if can toggle a pin directly with one of the TIM2_CHx pins.

You should also be able to measure the TIM2 frequency indirectly via the HT/TC interrupts. A glance suggests they get called at 1 KHz, so a toggle should give 500 Hz at the LED
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
rgrimes
Associate II
Posted on June 16, 2014 at 19:38

Yeah, you're right - that is too fast!  I really just wanted to confirm that TIM2 was running, because at the time I wasn't sure what was broken.  So, forget about it.

Thanks for your help!