AnsweredAssumed Answered

CCR2 won't update

Question asked by sim1 on Apr 26, 2013
Latest reply on Apr 26, 2013 by sim1
Hello,

I'm trying to count pulse on PB7 using timer TIM4 ch2.

Everything is ok, but I'd like to reset CCR2 so I can start another measure.

I tried with
TIM_SetCompare2(TIM4, 0);

but CCR2 isn't set to 0 after execution.

Here's how I setup TIM4:

GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
 
/* TIM4 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
 
/* GPIOB clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
 
/* TIM4 chennel2 configuration : PB.07 */
GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOB, &GPIO_InitStructure);
 
/* Connect TIM pin to AF2 */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_TIM4);
 
/* Enable the TIM4 global Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
 
TIM_TimeBaseStructure.TIM_Period = 65535;      
TIM_TimeBaseStructure.TIM_Prescaler = 0;   
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
 
TIM_TIxExternalClockConfig(TIM4,TIM_TIxExternalCLK1Source_TI2,TIM_ICPolarity_Rising,0); //TI2FP2
 
/* TIM enable counter */
TIM_Cmd(TIM4, ENABLE);
 
/* Enable the CC2 Interrupt Request */
TIM_ITConfig(TIM4, TIM_IT_CC2, ENABLE);

Thanks,

Simone

Outcomes