AnsweredAssumed Answered

STM32F429 Timer1 Capture/Compare with IRQ

Question asked by dirkson on Jan 28, 2015
Latest reply on Jan 28, 2015 by dirkson
Hello,

I use the Timer1 in capture compare mode. I want the following function:
1. Timer1 starts to count from 0
2. Timer1 counter register is the same, like in compare register     => IRQ_CC
3. Timer1 counter register is the same, like in auto-reload register => IRQ_Update
And then from the beginning

My code works, but I have the problem, that first triggered IRQ_Update. If it runs a lot of time, its look like:
IRQ_Update
IRQ_CC
IRQ_Update
IRQ_CC
...
I dont understand, why it starts with IRQ_Update and not with IRQ_CC ?

Thank you in advance.

Best regards,

Dirk

TIM_TimeBaseInitTypeDef    TIM_TimeBaseStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

TIM_TimeBaseStructure.TIM_Period = (double) HCLK_MHZ * period / 1000  - 1;
TIM_TimeBaseStructure.TIM_Period = 8100  - 1;
TIM_TimeBaseStructure.TIM_Prescaler = 0;   
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;            
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
   
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCInitStructure.TIM_OCMode            = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState        = TIM_OutputState_Disable;
TIM_OCInitStructure.TIM_OutputNState    = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse            = 1800-1;
TIM_OCInitStructure.TIM_OCPolarity        = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCNPolarity        = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState        = TIM_OCIdleState_Reset; 
TIM_OCInitStructure.TIM_OCNIdleState    = TIM_OCNIdleState_Reset; 
TIM_OC1Init( TIM1, &TIM_OCInitStructure );

TIM_CtrlPWMOutputs(TIM1, ENABLE);
 
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE);

  
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_TIM10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);

Outcomes