cancel
Showing results for 
Search instead for 
Did you mean: 

Timer external clock with interrupt

hdemi.1
Associate III

I have connected an external clock to TIM1 and I want to count the values ​​where the counter register is overflow with interrupt. My code is like this, but it doesn't work.

TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;

 TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;

 TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

 TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;

 TIM_ICInitStructure.TIM_ICFilter = 0x0;

 TIM_ICInit(TIM1, &TIM_ICInitStructure);

TIM_SelectInputTrigger(TIM1, TIM_TS_TI2FP2);

 /* Select the slave Mode: Reset Mode */

 TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_External1);

 /* Enable the Master/Slave Mode */

 TIM_SelectMasterSlaveMode(TIM1 ,TIM_MasterSlaveMode_Enable);

 /* Enable the CC2 Interrupt Request */

 TIM_ITConfig(TIM1, TIM_IT_Trigger, ENABLE);

NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_UP_TRG_COM_IRQn;

 NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;

 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

 NVIC_Init(&NVIC_InitStructure);

uint32_t tut ;

void TIM1_BRK_UP_TRG_COM_IRQHandler(void){

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

if(TIM1->CNT == RESET)

tut++ ;

}

TIM_ClearITPendingBit(TIM1, TIM_IT_Trigger);

}

0 REPLIES 0