cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 TIM->CCR1 value interrupt

hazall
Associate III

I try to generete interrupt when TIM->CNT = OverVal

my code below ;

I am so confused, thanks for now

void Init(){

 TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; //TIM_Channel_3

  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;

  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;

  TIM_ICInitStructure.TIM_ICFilter = 0x0;

  TIM_ICInit(ExternalOSCTimer, &TIM_ICInitStructure);

  NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_UP_TRG_COM_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

TIM1->CCER |= TIM_CCER_CC1E;

  NVIC_EnableIRQ(TIM1_CC_IRQn);

  TIM1->CCMR1 = TIM1_CH1_OUTPUT_MODE_TOGGLE ;

TIM1->CCER &=~ TIM_CCER_CC1E;

TIM1->CCMR1 &=~ (1 << 3);//preload disable

  TIM1->CR2 &= (uint16_t)(~(TIM_CR1_DIR | TIM_CR1_CMS | TIM_CR1_CKD));

  TIM1->CR2 &= 0XFF7F; 

  TIM1->ARR = 0xFFFFFFFF;

  TIM1->PSC = 0x0000; //set prescale value

  TIM1->SMCR |= (uint16_t)(TIM_TS_TI1FP1 | TIM_SMCR_SMS); }

void TIM1_BRK_UP_TRG_COM_IRQHandler(){ /*OverFlow interrupt **/

if(TIM_GetITStatus(TIM1,TIM_IT_Update) != RESET){

TIM_ClearITPendingBit(ExternalOSCTimer,TIM_IT_Update) ;

if(PingCounter ==loopCount){

TIM1->CCR1 = OverFlow ;

TIM1->DIER |= TIM_DIER_CC1IE;

}

}

void TIM1_CC_IRQHandler(){

if(TIM1->SR & TIM_SR_CC1IF){

TIM1->SR = (uint16_t)~TIM_SR_CC1IF;

TIM1->DIER &= (uint16_t)~TIM_DIER_CC1IE;

//do something

}

}

0 REPLIES 0