Get timer value (duty cycle) when OCxRef-clear (OCREF_CLR) was activated by the comparator
Hi,
I am using the OCxRef-clear + comparator to do cycle-by-cycle current regulation and it is working as intended, limiting the delivered duty-cycle despite the value set in software, but I also need to know in software if this is happening and know the real duty cycle delivered to the load, how can I do this?
My first thought was to set another channel of the same timer as input compare and link it to the same comparator output, but none of the other channels of this timer are linked to the comparator, so I thought in 3 other possible ways, each one of them not ideal for a reason:
- Enable comparator interrupt and get the timer value by software, but this would not work properly as it depends on the interrupt latency and priority
- Connect the comparator GPIO output to the IC GPIO input, but this solution is ugly and is prone to hardware failure
- Run a second timer in parallel synced with the first timer (seems to be possible thru timer sync mechanisms) and use its IC channel linked to the comparator output (can I do this? link the comparator to more than one timer?), but this solution does not seems ideal as this second timer cannot run at the same clock frequency of the first one (the first one is running at 128MHz, 2x the main clock frequency), so it would be impossible to get acurate values at higher PWM frequencies
More information about my setup:
- STM32FG071KB
- Running the core @64MHz and the TIM1 @128MHz
- Using TIM1 Channel 1 for PWM generation (now @ 20KHz, but it will probably change), with complementary output & dead time
- Using COMP1 for cycle-by-cycle current control, linked to the OCREF_CLR
- Using COMP2 for another feature (asking about it @ this thread: https://community.st.com/s/question/0D50X0000AlcqWASQY/using-the-comparator-break-input-to-control-the-complementary-output-in-the-advanced-control-timer)
So, I would like to ask for sugestions and other possible ways of getting the real duty-cycle value, is there any other solution?
Thanks!
