2018-10-25 08:44 PM
void MX_TIM5_Init(void)
{
TIM_ClockConfigTypeDef sClockSourceConfig;
TIM_MasterConfigTypeDef sMasterConfig;
htim5.Instance = TIM5;
htim5.Init.Prescaler = 84;
htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
htim5.Init.Period = 99; //interrupt in 100 micro sec
// htim5.Init.Period = 50; //interrupt in 50 micro sec
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
if (HAL_TIM_Base_Init(&htim5) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
}
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
{
if(tim_baseHandle->Instance==TIM5)
{
/* USER CODE BEGIN TIM5_MspInit 0 */
/* USER CODE END TIM5_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_TIM5_CLK_ENABLE();
/* Peripheral interrupt init */
HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM5_IRQn);
/* USER CODE BEGIN TIM5_MspInit 1 */
/* USER CODE END TIM5_MspInit 1 */
}
}
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
{
if(tim_baseHandle->Instance==TIM5)
{
/* USER CODE BEGIN TIM5_MspDeInit 0 */
/* USER CODE END TIM5_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_TIM5_CLK_DISABLE();
/* Peripheral interrupt Deinit*/
HAL_NVIC_DisableIRQ(TIM5_IRQn);
}
/* USER CODE BEGIN TIM5_MspDeInit 1 */
/* USER CODE END TIM5_MspDeInit 1 */
}
This is how i have initialised the timer now i am looking to put delay between
SetPWM(x,dutycycle);
SetPWM(y,dutycycle);
SetPWM(z,dutycycle);
delay();
SetPWM(x,0);
SetPWM(y,0);
SetPWM(z,0);
when iam using timer delay or normal delay the system is hanging as i am changing the PWM during delay is there any solution for this.
2019-12-27 11:12 PM
do you use the cube ?
do you have a scope ?
google this "stm32 timer cookbook
5 PDFs are presented.
2019-12-27 11:26 PM
No, I am using Keil. Got the solution for this, thank You
2019-12-28 01:28 AM
Thannks @Community member