Setting up TIM8 strange issue
Hi All,
I am setting up TIM8 CH1 and CH3 on a STM32G431 and am seeing a strange result. First of all, I am using an external signal coming in on PC6 TIM8 CH1. For TIM8 CH3 I am only using a software trigger internal to the MCU, I'm not using any external pin for TIM8 CH3. I am looking for a input capture on CH1 and CH3 only.
First. is this configuration okay for the G431?
When I enable TIM8 I immediately get SR bits set on : UIF, CC1F, CC2F, CC4F, CC1OF, CCI5 and CCI6. I expect the result for CC1F and CC1OF as CH1 input is active.
Is there something I need to do in initialization to make sure erroneous flags don't get set on an enable? Would any of these erroneous flags interfere with the DMA I have set up for CH1 and CH3?
Here is my TIM8 initialization code:
static void MX_TIM8_Init(void)
{
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_IC_InitTypeDef sConfigIC = {0};
//TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
htim8.Instance = TIM8;
htim8.Init.Prescaler = 170; // 1MHz
htim8.Init.CounterMode = TIM_COUNTERMODE_UP;
htim8.Init.Period = 10000; // 100Hz
htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim8) != HAL_OK) // enables timer in RCC register // what is HAL_TIM_IC_Init
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET; // added 4/30
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim8, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
// next 18 lines added 4/30
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 0;
if (HAL_TIM_IC_ConfigChannel(&htim8, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_IC_ConfigChannel(&htim8, &sConfigIC, TIM_CHANNEL_3) != HAL_OK)
{
Error_Handler();
}
}Here is the code I use to start TIM8:
// TIM8_CH1 is capture/compare from input pin and
// TIM8_CH3 is capture/compare FW triggered by TIM8_EGR.CCG3
// enable TIM8 DMA interrupts
TIM8->DIER |= (TIM_DIER_CC3DE | TIM_DIER_CC1DE) ;
/* enable TIM8 capture / compare */
TIM8->CCER |= ( TIM_CCER_CC1E | TIM_CCER_CC3E ) ;
/* enable TIM8 */
TIM8->CR1 |= TIM_CR1_CEN;