2017-03-12 10:33 AM
I can't seem to get TIM1's CC channel 1 ISR to fire.
FanTimerHandle.Instance =TIM1;
memset(&sConfig, 0, sizeof(sConfig));
/* Initialize TIMx peripheral as follow: + Period = 0xFFFF + Prescaler = 0 + ClockDivision = 0 + Counter direction = Up */ FanTimerHandle.Init.Period = 0xFFFF; FanTimerHandle.Init.Prescaler = 512; FanTimerHandle.Init.ClockDivision = 0; FanTimerHandle.Init.CounterMode = TIM_COUNTERMODE_UP; FanTimerHandle.Init.RepetitionCounter = 0; if(HAL_TIM_IC_Init(&FanTimerHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /* Configure the Input Capture of channel 1 */ sConfig.ICPolarity = TIM_ICPOLARITY_RISING; sConfig.ICSelection = TIM_ICSELECTION_DIRECTTI; sConfig.ICPolarity = TIM_ICPSC_DIV1; sConfig.ICFilter = 0; if(HAL_TIM_IC_ConfigChannel(&FanTimerHandle, &sConfig, TIM_CHANNEL_1) != HAL_OK) { /* Configuration Error */ Error_Handler(); }/*##-4- Start the Input Capture in interrupt mode ##########################*/
if(HAL_TIM_IC_Start_IT(&FanTimerHandle, TIM_CHANNEL_1) != HAL_OK) { /* Starting Error */ Error_Handler(); }and GPIO :
__HAL_RCC_TIM1_CLK_ENABLE();
/* Enable GPIO channels Clock */ FAN_TIMER_CHANNEL_PORT(); /* Configure (TIMx_Channel) in Alternate function, push-pull and 100MHz speed */ GPIO_InitStruct.Pin = GPIO_PIN_8; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = GPIO_AF1_TIM1; HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);/*##-2- Configure the NVIC for TIMx #########################################*/
/* Sets the priority grouping field */ HAL_NVIC_SetPriority(TIM1_CC_IRQn, 1, 1); /* Enable the TIM4 global Interrupt */ HAL_NVIC_EnableIRQ(TIM1_cc_IRQn);2017-03-12 04:07 PM
What's the stimulus? What is the observed behaviour and how does it depart from the expected one?
JW
2017-03-13 06:08 AM
Purpose is to measure the frequency of a square wave. I have a 50hz square wave on the input pins and nothing triggers. If I switch everything to timer 3 I get the expected interrupt.
2017-03-13 07:46 AM
yeah, the comment 'TIM4' was a left over comment from when I used Timer4 to prove out that interrupts do work for my application.
2017-03-13 07:57 AM
PE8 is TIM1_CH1N (The negated output), you'd want to be using PE9 TIM1_CH1
2017-03-13 08:09 AM
that was my first observation after my original post so I changed to PE9. Same result, no trigger. To test this code before incorporating it in my target board, I am running this code on an STM32F407 discovery devkit. I have my function generator negative lead on the devkit's ground and the positive on PE9. With the following code change:
from
GPIO_InitStruct.Pin = GPIO_PIN_8;
to
GPIO_InitStruct.Pin = GPIO_PIN_9;
seems I have something misconfigured with the capture compare register(s) relative to Timer1.
2017-03-13 08:16 AM
TIM1 is an advanced timer, it has more registers/fields
sConfig.ICPolarity = TIM_ICPSC_DIV1; // This seems wrong ICPrescaler perhaps?
2017-03-13 08:38 AM
Observe the related capture register (TIM1_CCR1) in debugger.
Not changing? Then problem is on the input side: incorrect GPIO setting or incorrect CCMR/CCER settings.
Changing? Then problem is on the output side: incorrect DIER setting, not enabled interrupt, wrong ISR name.
JW
PS.
/* Enable the TIM
4
global Interrupt */ HAL_NVIC_EnableIRQ(TIM1_cc_IRQn);?
2017-03-13 08:56 AM
That too, but I meant mainly the lowercase cc