2024-08-05 01:58 AM
Hello, I'm using STM32F030C8 and I have created 4 PWM waveforms.
I want to create PWM and stop it after one cycle.
I'm thinking of how to create PWM and stop directly after one cycle.
Is there any other way?
Thank you.
2024-08-05 03:29 AM
JW
2024-08-05 07:06 PM
Hi,
htim5.Instance->CR1 |= (1 << 3);
HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_1);
I wrote the code like this, but it doesn't work. -> The signal will remain at the High level only.
Do you happen to have an example code?
2024-08-05 07:24 PM - edited 2024-08-05 07:31 PM
I'm changing pwm mode and opm mode using external buttons.
When entering opm mode, keep high level and generate pulse. I want to keep low level and generate pulse.
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
switch(GPIO_Pin)
{
case GPIO_PIN_13 :
{
if (opm_mode)
{
StartPWM();
opm_mode = 0;
}
else
{
StartOPM();
}
}
}
}
void StartPWM(void)
{
HAL_TIM_PWM_Stop(&htim5, TIM_CHANNEL_1); // ???��머�?? 먼�? 중�?
htim5.Instance->CR1 &= ~TIM_CR1_OPM; // OPM 비트�??? ?��리어?��?�� 반복 모드 ?��?��
if (HAL_TIM_Base_Init(&htim5) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
}
void StartOPM(void)
{
HAL_TIM_PWM_Stop(&htim5, TIM_CHANNEL_1); // ???��머�?? 먼�? 중�?
htim5.Instance->CR1 |= (1 << 3); // OPM 비트�??? ?��?��?��?�� ?��?�� ?��?�� 모드 ?��?��
if (HAL_TIM_Base_Init(&htim5) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
}
2024-08-06 03:50 AM
> I want to keep low level
Then you have either use the other PWM mode, or invert the output signal using TIMx_CCER.CCxP.
You may need to change also TIMx_ARR and TIMx_CCRx between the PWM and one-pulse mode to fit your expected output waveform.
JW