cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G4 - Using both TIxFPx and Input capture mode on the same channel with advanced timer

AurelienB
Associate

So i'm working on a way to generate pulses with both Timer 1 and 8 (advanced motor control timer) independently in OPM PWM mode 2 with the Slave Gated mode to control a each a stepper motor driver. I want to use as much as possible the hardware because sometimes the frequency of the steps are really high and the interruptions are slowing down the process.
Both are using the TI2FP2 on their channels 2 (to stop the timer when raised) for some home sensors (only enabled when going on the home sensor direction by changing the slave mode) and generating the pulse (pwm) on the channel 3 with use of the RCR register to trigger the amount i want thanks to the OPM mode, and sometimes i change the ARR register to modulate the frequency of the steps and then reload the RCR register to be updated on the next UEV.
I'm also counting the number of pulses done by each timer with a secondary timer using the TRGO OC1 (and that's works perfectly) to see if my motor loose steps when doing a movement to the home sensor, so i can be sure that the stepper motor is doing the good number of step and not loose any.
Also i want to have an interruption occurring when the channel 2 is detection a rising edge (meaning the home sensor has been reached), I opted for using also on those channels the Input Capture Direct mode to have a Capture Compare interruption on top of the TI2FP2. The IOC configurator seems to let me do it on channels 2, so it seems to be doable.

It seems to work fine on the timer 1 but not on the timer 8, sometimes the interruption is not triggered at all. With an oscilloscope i see the pin going up but no interruption is going on.
Is there a better way to capture the TI2FP2 event ? Did i missed something ? 

Here the configuration of timer 8 :

AurelienB_0-1750148425453.png

(Changing also the combined gated reset mode to a simple gated mode, the ioc wont let me do it directly from here)

AurelienB_6-1750148503748.png

 


AurelienB_2-1750148437476.jpeg

AurelienB_3-1750148448465.jpeg

AurelienB_4-1750148467206.jpeg

And the pulse counter timer 20 : 

AurelienB_5-1750148484337.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
AurelienB
Associate

Ok I've totally missed the TRGI events raised by the TIxFPx with the polarity inverted.
That match what i needed, I've to filtered out the first interruption raised at the timer start (with the CEN bit disable). 

I also faced some SR flag issues when starting the timers, I've force the register value 0 just after enabling it with CEN bit. Did this issue is know by ST ? The SR flag are sometimes raised when the timer is started ? 

It's working fine now. 

View solution in original post

2 REPLIES 2
AurelienB
Associate

Ok I've totally missed the TRGI events raised by the TIxFPx with the polarity inverted.
That match what i needed, I've to filtered out the first interruption raised at the timer start (with the CEN bit disable). 

I also faced some SR flag issues when starting the timers, I've force the register value 0 just after enabling it with CEN bit. Did this issue is know by ST ? The SR flag are sometimes raised when the timer is started ? 

It's working fine now. 

waclawek.jan
Super User

I'm not sure what was the original problem. There should be no issue with both triggering the slave-mode controller and capture from the same input.

TIMx_SR.UIF may be set due to Cube/HAL initialization code setting TIMx_EGR.UG to force the ARR/PSC/RCR settings into the working registers.

At any case, Cube/HAL implements only the "usual" working cases, so if you want anything out of "usual" (whatever that means, as perceived by Cube/HAL authors), Cube/HAL may get into your way and you may be better off working directly with registers.

JW