2023-12-05 02:34 AM
Hi
I have a trigger ( the pink trace) who triggers one delay of 200µs with the help of the timer 3 ( a channel toggles each event, the red trace) . A IT is also generated . Another channel of this timer 3 is used to trigger a one pulse mode pwm with a 100µs period and a duty cycle of 50%. This is the green trace. But I would like to have this result for each pulse of the trigger signal( pink trace) . And it' do not !!
How can I rearm this PWM? The file is attached
Thanks for your help !
2023-12-05 02:47 AM
Hello @MichelM38,
To make sure I understood your request, you want the TIM3 that's used in one pulse mode to be triggered at every rising edge of the trigger signal?
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-12-05 04:40 AM
The tmr3 will trigger the tmr4 in one pulse mode. the tmr3 is used to delay the PWM and another signal. The tmr2 is used as an input capture ( later it will be used to determine the periode), the tmr3 is used to delay the PWM and another signal .
So the tmr2 on which the trigger signal is applied will launch the tmr3 which generate a delay of 80µs. At the end of this delay, tmr4 will be triggered for a pwm pulse in one pulse mode. the tmr3 is used to delay the PWM and another signal .
2023-12-05 05:00 AM
You should reset counter in input capture callback too.
__HAL_TIM_SET_COUNTER(htim, 0);
Like this
2023-12-05 05:11 AM
It's already done, for the tmr3 and tmr4. And the result is not ok..
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
if (htim == &htim2)
{
__HAL_TIM_SET_COUNTER(&htim3, 0);
HAL_TIM_OC_Start(&htim3, TIM_CHANNEL_2);
HAL_TIM_OC_Start(&htim3, TIM_CHANNEL_1);
__HAL_TIM_SET_COUNTER(&htim4, 0);
HAL_TIM_OnePulse_Start(&htim4, TIM_CHANNEL_1);
}
}
2023-12-05 05:51 AM
I looks like HAL_TIM_OnePulse_Start is missing the call to actually start the timer. Probably is a reason but I don't know what it is. I suspect the HAL channel state may also be busy. Try stopping the pulse before starting it.
HAL_TIM_OnePulse_Stop(&htim4, TIM_CHANNEL_1);
HAL_TIM_OnePulse_Start(&htim4, TIM_CHANNEL_1);
__HAL_TIM_ENABLE(&htim4);
Or just ignore the HAL state stuff and start the timer directly:
__HAL_TIM_ENABLE(&htim4);
or
SET_BIT(TIM4->CR1, TIM_CR1_CEN);
2023-12-05 05:52 AM
time 2 won't use after first trigger?
it's require reset counter too.
2023-12-05 07:21 AM
Hi TDK,
I tried your suggestion. Now the pwm pulses with each trigger pulse. But it seems that it is the trigger signal applied to the input capture of tmr2 that starts the pwm, not the output capture of tmr3 whereas the trigger of pwm(tmr4) is normally the output comparison of tmr3.
2023-12-05 08:37 AM
Not sure I follow what you want to achieve. Perhaps clearly draw what signals you're trying to get and indicate what's different.
2023-12-05 11:52 AM
Also, if you can't accomplish what you want by clicking in CubeMX, it's better to avoid Cube/HAL entirely and program at register level.
JW