generating an interrupt for the loaded values in ARR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-03-01 2:52 AM
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); } }- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-10 9:07 AM
That's a relief, because I did test it.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-29 12:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-29 5:02 AM
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);
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-29 5:55 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-29 5:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-29 6:26 AM
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?Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-29 6:53 AM
Hi
I didn't get it........can you please explain- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-29 7:08 AM
I didn't get it........can you please explain
Read the words again slowly, and think harder.Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-29 10:30 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-04-30 6:50 AM
void TIM3_IRQHandler(void) ??
Up vote any posts that you find helpful, it shows what's working..
