cancel
Showing results for 
Search instead for 
Did you mean: 

generating an interrupt for the loaded values in ARR

sanjib
Associate III
Posted on March 01, 2014 at 11:52

Hi,

I want to generate a timer interrupt for 6.25 us, 9.375 us, 0.1 milisec, 0.4 millisecond and so on . I think that it can be done by using DMA taking the array SRC_Buffer_DEC[4] ={200,300,3200,12800} as DMA memory base address and ADC1->ARR as peripheral address therefore the Auto reload value should change everytime and should generate an interrupt for each value. but I am not able to do that . I didn't get any example for this but I think that it can be done. Can anybody help me and say me whether my thinking is right or wrong. whether it is achieveable, if no how it can be done? I have paste my code below please see

#include ''unistd.h''

#include ''stm32f4xx.h''

#include ''stm32f4_discovery.h''

#include ''stm32f4xx_tim.h''

#include ''stm32f4xx_rcc.h''

#include ''stm32f4xx.h''

#include <misc.h>

#include ''stm32f4xx_adc.h''

#include ''stm32f4xx_gpio.h''

#include ''stm32f4xx_dac.h''

#include ''stm32f4xx_tim.h''

#include ''stm32f4xx_dma.h''

#include ''stm32f4xx_usart.h''

#include ''time.h''

uint16_t SRC_Buffer_DEC[4] ={200,300,3200,12800};

int main(void)

{

    STM_EVAL_LEDInit(LED3);

    rcc();

    INTTIM_Config();

    NVIC_Configuration();

    EnableTimerInterrupt();

    while(1);

DMA();

#ifdef DEBUG

  debug();

#endif

}

void rcc()

{

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);

    /**

     * Enable clock for DMA2 (ADC DMA)

     **/

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);

     /**

      * Enable clock for TIM2 (used for ADC Trigger)

      **/

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

}

#if 1

void DMA()

{

    DMA_InitTypeDef DMA_InitStructure;

DMA_InitStructure.DMA_Channel = DMA_Channel_6;

    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&TIM2->ARR;

    DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&SRC_Buffer_DEC;

    DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;

    DMA_InitStructure.DMA_BufferSize = 4;

    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;

    DMA_InitStructure.DMA_MemoryDataSize = DMA_PeripheralDataSize_HalfWord;

    DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

    //DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;

    DMA_InitStructure.DMA_Priority = DMA_Priority_High;

    DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;

    DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;

    DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;

    DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

    DMA_Init(DMA2_Stream4, &DMA_InitStructure);

//    DMA_ITConfig(DMA2_Stream4, DMA_IT_TC | DMA_IT_HT, ENABLE);

    DMA_Cmd(DMA2_Stream4, ENABLE);

    /* TIM8 Update DMA Request enable */

    TIM_DMACmd(TIM2, TIM_DMA_Trigger , ENABLE);

    TIM_DMACmd(TIM2, TIM_DMA_Update, ENABLE);

}

#endif

void INTTIM_Config(void)

{

    TIM_TimeBaseInitTypeDef    TIM_InitStruct;

    TIM_OCInitTypeDef       TIM_OCInitStructure;

  /* TIM2 clock enable */

  /* Time base configuration */

  TIM_InitStruct.TIM_Prescaler = 2 - 1;                // This will configure the clock to 2 kHz

  TIM_InitStruct.TIM_CounterMode = TIM_CounterMode_Up;     // Count-up timer mode

// TIM_InitStruct.TIM_Period = 200 - 1;                    // 2 kHz down to 1 Hz = 1 second

  TIM_InitStruct.TIM_ClockDivision = TIM_CKD_DIV1;        // Divide clock by 1

  TIM_InitStruct.TIM_RepetitionCounter = 0;                // Set to 0, not used

  TIM_TimeBaseInit(TIM2, &TIM_InitStruct);

      TIM_ARRPreloadConfig(TIM2, ENABLE);

      /* TIM8 enable counter */

      TIM_Cmd(TIM2, ENABLE);

  /* TIM2 enable counter */

  TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);

}

void EnableTimerInterrupt()

{

    NVIC_InitTypeDef nvicStructure;

    nvicStructure.NVIC_IRQChannel = TIM2_IRQn;

    nvicStructure.NVIC_IRQChannelPreemptionPriority = 0;

    nvicStructure.NVIC_IRQChannelSubPriority = 0;

    nvicStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&nvicStructure);

}

void TIM2_IRQHandler()

{

        if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)

        {

            TIM_ClearITPendingBit(TIM2, TIM_IT_Update);

             STM_EVAL_LEDToggle(LED3);

    }

}

23 REPLIES 23
Posted on April 10, 2014 at 18:07

That's a relief, because I did test it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sanjib
Associate III
Posted on April 29, 2014 at 09:35

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6bJ&d=%2Fa%2F0X0000000brW%2F5Euiq2G5YR3QBViEsElcDXl2RjTQjpDmApW60hqEVn4&asPdf=false
Posted on April 29, 2014 at 14:02

Perhaps that you don't enable it in the NVIC?

NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the TIM3 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sanjib
Associate III
Posted on April 29, 2014 at 14:55

Hi clive It's working but it's working for only timer 3 timer 15 , 16 and 17 it's not able to generate the interrupt I am not getting it why . I have checked the DMA channel , channel 5 for TIM15_UP , Channel 1 and channel 4 for timer TIM17_UP and TIM16_UP respectively . Why is it so

sanjib
Associate III
Posted on April 29, 2014 at 14:59

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6el&d=%2Fa%2F0X0000000bsZ%2FKN3aSed2OIEUI2BS35_3x.Tf.07t6NNQ75V3syu.vfg&asPdf=false
Posted on April 29, 2014 at 15:26

Why is it so

Do you have the right startup_stm32f03xxxx.s file in the project? Does it describe the vectors you are attempting to use?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sanjib
Associate III
Posted on April 29, 2014 at 15:53

Hi

I didn't get it........can you please explain
Posted on April 29, 2014 at 16:08

I didn't get it........can you please explain

Read the words again slowly, and think harder.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sanjib
Associate III
Posted on April 30, 2014 at 07:30

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6eq&d=%2Fa%2F0X0000000bsa%2Ft0ylEES75je90HeBInJHsO1Gnp1Pbe6zDqNlPhki1pg&asPdf=false
Posted on April 30, 2014 at 15:50

void TIM3_IRQHandler(void) ??

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..