STM32G474 HRTIM: capture and reset counter from same event - Page 1
Forum section: electronics / general

author: uer166
author_rank: Super Contributor
timestamp: November 05, 2022, 12:31:29 am
content: Does anyone know what happens when the same external (EEV) source is used to both reset the timebase, and capture the timer value, with the goal of capturing the "max" reached value of timer? RM0440 says that reset on a EEV is possible, capture on a EEV is possible, but how do I do both at the same time (reset beingafterthe capture of course).

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 05, 2022, 02:39:59 am
content: For timer:- Set the timer in slave reset mode.- Use internal clock source.- Use the TIxFPx input as trigger source to reset the timer (In this case TI2FP2).- Set up the Input capture using the same channel providing the trigger input (CH2).- DoneTested in a 32F103, works fine.On IRQ call the capture value is correct. The timer counter is also cleared, just slightly increased due the interrupt delay, ~18clocks.

author: uer166
author_rank: Super Contributor
timestamp: November 05, 2022, 04:18:11 am
content: Quote from: DavidAlfa on November 05, 2022, 02:39:59 amMakes sense that your suggestion works since the reset is "filtered", but that is not an HRTIM peripheral. HRTIM is a very different beast from regular STM32 timers, and the reset input to an HRTIM instance I have don't really have a concept of "filtering" on their own.. (the external event input does, but only on some channels, and I use channels that don't have that feature).

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 05, 2022, 04:40:57 pm
content: Just try it out and see what whappens. Isn't going to explode if it doesn't

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 05, 2022, 07:59:32 pm
content: I wouldn't count on that being reliable. And, why would you do that in the first place?

author: uer166
author_rank: Super Contributor
timestamp: November 06, 2022, 12:43:27 am
content: Quote from: SiliconWizard on November 05, 2022, 07:59:32 pmYeah it seems to work sometimes but sometimes not. The goal here is to run a type of hysteretic current converter, such that:2 comparators + DAC reference set the hi and lo bounds of current so that the timer output bounces around between the 2 states when thresholds are hitDuty cycle of waveform is measuredThere is leading edge blanking (i.e. after a transition blank any other transitions for N clocks)By resetting and capturing that highest value, both the duty cycle can be measured, and LEB can be achieved by a compare channel routed to the EEV input blanking circuit.

author: uer166
author_rank: Super Contributor
timestamp: November 06, 2022, 02:01:48 am
content: A-ha I was able to make some semblance of what I imagined. Instead of using an EEV input to simultaneously reset timer and do a capture, one can sequence them with the compare autodelay feature.EEV input->Capture 2 (this captures the event without a race condition)->Compare 4 (CPT2 can trigger CMP4 auto-delay)->Timebase reset (TIM can be reset from a compare channel).All of the above can be combined with EEV input blanking using another compare channel, and it all fits together okay-ish.