STM32F042 Encoder Problem
I'm using the stm32f042 nucleo board, Atollic truestudio and CubeMX launched from the Atollic GUI (eclipse) to develop code. I am trying to get the encoder interface on timer 3 to function as a step/dir counter. I have used CubeMX to select the encoder function on TIM3 which produces this initialization code -
static void MX_TIM3_Init(void)
{TIM_Encoder_InitTypeDef sConfig;
TIM_MasterConfigTypeDef sMasterConfig;htim3.Instance = TIM3;
htim3.Init.Prescaler = 0; htim3.Init.CounterMode = TIM_COUNTERMODE_UP; htim3.Init.Period = 1800; htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; sConfig.EncoderMode = TIM_ENCODERMODE_TI1; sConfig.IC1Polarity = TIM_ICPOLARITY_RISING; sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI; sConfig.IC1Prescaler = TIM_ICPSC_DIV1; sConfig.IC1Filter = 0; sConfig.IC2Polarity = TIM_ICPOLARITY_RISING; sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI; sConfig.IC2Prescaler = TIM_ICPSC_DIV1; sConfig.IC2Filter = 0; if (HAL_TIM_Encoder_Init(&htim3, &sConfig) != HAL_OK) { Error_Handler(); }sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) { Error_Handler(); }}
I have used the following start before the while loop in main -
TIM3->CNT = 900;
HAL_TIM_Encoder_Start(&htim3,TIM_CHANNEL_ALL);I've also tried TIM_CHANNEL_1 and 2
I set up a global variable 'counter' to monitor the value of the TIM3 cnt register.
counter = TIM3->CNT;
I cannot get the counter variable to move. It returns 900 no matter
how I treat the PA6 and 7 lines. This problem is identical to the question
https://community.st.com/0D50X00009XkexPSAR
with the exception that this is the F042. There are no responses to the referenced question.Any help here is greatly appreciated.
null