2020-06-21 07:35 AM
Hi,
I am trying for a while now to configure a one pulse timer with cubeMX without success. I am using a nucleo-L433RC for my tests.
I was able to make the one pulse work by manually configure it. I used the example of the L432KC in the package to do so. The function HAL_TIM_OnePulse_ConfigChannel seems to never be called with the cubeMX configuration.
I followed several examples I found on the forum without success:
https://community.st.com/s/question/0D50X00009XkXgN/retriggerable-one-pulse-mode-in-cubemx
https://community.st.com/s/question/0D50X00009XkY3D/cubemx-and-one-pulse-mode
https://community.st.com/s/question/0D50X00009XkeN1/cubemx-support-of-one-pulse-modes-for-timers
There is also an example with cubeMX on a F0 but the generated code from cubeMX in the example does not match the source code in the example. It seems to have been manually changed.
I am lost at this point. Could you provide me information on how to properly configure cubeMX to have a one pulse timer working please?
Thank you!
2020-10-20 09:48 PM
I have spent a couple of days to solve a similar problem and was disappointed that the answers were not easily available in internet. The official ST documentation was quite cryptic and difficult to use. What I wanted was to learn
I did my investigations using a STM32H750 board running at 400 Mhz. Here are the answers for the last three questions:
At the end, I was surprised how simple the solution was. In STM32CudeIDE Device Configuration Tool for TIM5, I entered the following parameters for a 20 MHz counter clock.
Slave Mode: Trigger Mode
Trigger Source: ETR1
Clock Source: Internal Clock
Channel1: Output Compare CH1
Channel2: Output Compare CH2
Channel3: Output Compare CH3
Channel4: Output Compare CH3
One Pulse Mode, checked
Counter Settings
Prescaler: 9
Counter Mode: Down
Counter Period: 0xffff
Internal Clock Division: No Division
auto-reload preload: Disable
Slave Mode Control: Trigger Mode
Trigger Output Parameters
Master/Slave Mode: Disable
Trigger Event Selection: Enable
Clear Input
Clear Input Source: Disable
Trigger
Trigger Polarity: non inverted
Trigger Prescaler: Prescaler not used
Trigger Filter: 0
Output Compare Channels (1..4)
Mode: Retriggerable OPM1
Pulse: 0
Output compare preload: Disable
CH Polarity: High
In the application code, I had to enable the channels before the main loop
TIM5->CCER |= 0x1111;
For the main loop, I had a function to update the CCRx registers and generate the trigger pulse with GPIO macros.
uint32_t ccr1 = pwm1 * T5_FREQ_MHZ;
uint32_t ccr2 = pwm2 * T5_FREQ_MHZ;
uint32_t ccr3 = pwm3 * T5_FREQ_MHZ;
uint32_t ccr4 = pwm4 * T5_FREQ_MHZ;
TIM5->CCR1 = ccr1; // Set PWM targets
TIM5->CCR2 = ccr2;
TIM5->CCR3 = ccr3;
TIM5->CCR4 = ccr4;
GPIO_set(TIM5_Start); // Generate trigger pulse
GPIO_clr(TIM5_Start);
The H750 supports the floating point values. The pwm1 .. pwm4 variable are floats as numbers in microseconds, such as 1000.0 and 2000.0 used for servo control. The T5_FREQ_MHZ is a constant (20).
In my application, I use PID controls with the following goals
The timer is a good solution to minimize the CPU loading. If a faster or more precise control is required, then a software based fast protocol is used to drive the control value in few microseconds. The H750 has enough computing power for that unless the application uses large displays with fast update requirements.