2019-04-30 12:40 AM
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:
More information about my setup:
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!
Solved! Go to Solution.
2019-04-30 01:20 AM
Use a different channel for the output than CH1, then you can connect COMP1 to CH1 input in TIM1_TISEL.TI1SEL and use that to capture the counter at the COMP1 edge.
You probably could do the measurement with a different timer, too, but if you are clocking TIM1 from the PLL, there would be issues around synchronicity, unnecessarily complex.
JW
2019-04-30 01:20 AM
Use a different channel for the output than CH1, then you can connect COMP1 to CH1 input in TIM1_TISEL.TI1SEL and use that to capture the counter at the COMP1 edge.
You probably could do the measurement with a different timer, too, but if you are clocking TIM1 from the PLL, there would be issues around synchronicity, unnecessarily complex.
JW
2019-04-30 01:42 AM
I thought about this too, but it's not possible to change the PWM channel as only Channel 1 can be cleared by the OCREF_CLR and have the complementary output
2019-04-30 02:46 AM
> only Channel 1 can be cleared by the OCREF_CLR and have the complementary output
Why would that be so? CHannels 1 to 3 have complementary outputs, and there's an OCxCE bit in TIM1_CCMRy for all 6 channels.
JW
2019-04-30 05:59 AM
Thank you Jan, you are right!
I was looking for these possibilities in CubeMX, and Channel 3 wasn't being listed as an option because it was not enabled, now I changed it and everything is working as intended, with channel 3 generating the waveform and channel 1 as input compare!
Next time I will look better at the reference manual