2023-02-02 11:07 PM
This is my code. It must be generete output compare interrupt when UPEventCount == DelayloopCount then, TIM_IT_CCR2 interrupt must be occur when CNT = my value. But CCR2 interrupt occur before CNT not reach my value. I looked for a long time but couldn't find the solution. Thanks for now..
void config(){
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);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle ;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_High
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM1->CCER |= TIM_CCER_CC2E ;
TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Disable);
TIM1->CR2 &= (uint16_t)(~(TIM_CR1_DIR | TIM_CR1_CMS | TIM_CR1_CKD));
TIM1->CR2 &= 0XFF7F;
TIM1->ARR = 0xFFFFFFFF;
TIM1->PSC = 0x0000;
TIM1->SMCR |= (uint16_t)(TIM_TS_TI1FP1 | TIM_SMCR_SMS); // external mode 1
TIM_ITConfig(TIM1, TIM_IT_Update, DISABLE);
TIM1->CR1 &= (uint16_t)(~((uint16_t)TIM_CR1_CEN));
}
void TIM1_BRK_UP_TRG_COM_IRQHandler(){
UPEventCount++ ;
TIM_ClearITPendingBit(TIM1,TIM_IT_Update) ;
if(UPEventCount == DelayloopCount){
capture = TIM_GetCapture2(ExternalOSCTimer);
TIM_SetCompare2(TIM1, capture + DelayOverFlow);
TIM_ITConfig(TIM1, TIM_IT_CC2, ENABLE);//enable interrupt
}
if (TIM_GetITStatus(TIM1, TIM_IT_CC2) != RESET){
GPIOF->ODR ^= GPIO_Pin_7;
}
}
2023-02-03 12:02 AM
Use the code format in your text so we dont die trying to read you wall of text
2023-02-03 12:32 AM
TIM1 has >1 interrupt vector - for compare/capture use TIM1_CC_IRQHandler and enable TIM1_CC_IRQn;
2023-02-03 01:43 AM
Sorry :grinning_face_with_sweat:
2023-02-05 07:03 AM
That is not working