2019-03-14 03:21 AM
2019-03-14 03:50 AM
Config GPIO value .
if you are using STM32cube MX set these value in that .
e.g
/* TIM14 init function */
static void MX_TIM14_Init(void)
{
TIM_OC_InitTypeDef sConfigOC;
htim14.Instance = TIM14;
htim14.Init.Prescaler = 16;
htim14.Init.CounterMode = TIM_COUNTERMODE_UP;
htim14.Init.Period = 100;
htim14.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
if (HAL_TIM_Base_Init(&htim14) != HAL_OK)
{
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4,GPIO_PIN_SET);
HAL_Delay(100);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4,GPIO_PIN_RESET);
HAL_Delay(100);
}
if (HAL_TIM_PWM_Init(&htim14) != HAL_OK)
{
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4,GPIO_PIN_SET);
HAL_Delay(100);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4,GPIO_PIN_RESET);
HAL_Delay(100);
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 0;
//sConfigOC.OCIdleState=TIM_OCIDLESTATE_SET;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH ;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_PWM_ConfigChannel(&htim14, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4,GPIO_PIN_SET);
HAL_Delay(50);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4,GPIO_PIN_RESET);
HAL_Delay(50);
}
HAL_TIM_MspPostInit(&htim14);
}
this is example of pwm of timer 14 channel1.