2017-01-08 11:37 PM
Hi,
I'm using XCube for init a SMT32F071CBT6 with Keil V5, I need to use the encoder periphery. (ALL to the last version)
In attachment three file. The project and the 2 file modify after generation.
I've use 4 alternative pins, because the other are use by an other periphery.
When start the encoder the 2 pins become output and go Low. Why?
After this command:
HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL);
I' ve try with tim1 with exactly the same code with no problem.
Please help me.
#encoder-stm32f02017-01-09 08:55 AM
Dear
Bandini.Matteo
,I've use 4 alternative pins ..
Which alternative pins are you using ?
Could you please provide more details about your
GPIO configuration ?
Best Regards
Imen
2017-01-09 11:56 PM
/* TIM2 init function */
void MX_TIM2_Init(void){ TIM_Encoder_InitTypeDef sConfig; TIM_MasterConfigTypeDef sMasterConfig;htim2.Instance = TIM2;
htim2.Init.Prescaler = 0; htim2.Init.CounterMode = TIM_COUNTERMODE_UP; htim2.Init.Period = 65535; htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim2.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(&htim2, &sConfig) != HAL_OK) { Error_Handler(); }sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) { Error_Handler(); }}
/* TIM3 init function */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 = 65535; 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(); }}
2017-01-10 12:29 AM
/* USER CODE END TIM2_MspInit 0 */
/* Peripheral clock enable */ __HAL_RCC_TIM2_CLK_ENABLE(); /**TIM2 GPIO Configuration PA15 ------> TIM2_CH1 PB3 ------> TIM2_CH2 */ GPIO_InitStruct.Pin = GPIO_PIN_15; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Alternate = GPIO_AF2_TIM2; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Alternate = GPIO_AF2_TIM2; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);/* USER CODE BEGIN TIM2_MspInit 1 */
HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_ALL); /* USER CODE END TIM2_MspInit 1 *//* USER CODE BEGIN TIM3_MspInit 0 */
/* USER CODE END TIM3_MspInit 0 */
/* Peripheral clock enable */ __HAL_RCC_TIM3_CLK_ENABLE(); /**TIM3 GPIO Configuration PB4 ------> TIM3_CH1 PB5 ------> TIM3_CH2 */ GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Alternate = GPIO_AF1_TIM3; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);/* USER CODE BEGIN TIM3_MspInit 1 */
HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL); /* USER CODE END TIM3_MspInit 1 */2017-01-10 12:50 AM
And TIM2/TIM3 configuration?
Rather than code, please provide the read-back content of the TIM2/TIM3 registers at the point when the problem occurs.
2017-05-03 08:09 AM
The structure TIM_Base_InitTypeDef does not have a member AutoReloadPreload. However CubeMX does generate this code. The old version of CubeMX doen not generate the autoreload line in tim.c So just comment it out every time you generate new code by CubeMX.