> For the complete documentation index, see [llms.txt](https://mujoseph.gitbook.io/mujoseph-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mujoseph.gitbook.io/mujoseph-docs/emma-mk1-drsstc/drsstc_driver-firmware-overview/high-resolution-timer-hrtim/timf-feedback-timeout-watchdog.md).

# TIMF: Feedback Timeout Watchdog

## Role

TIMF is responsible for shutting down an active burst if [ZCD](/mujoseph-docs/emma-mk1-drsstc/hardware-overview/electrical-design/pcb-design/current-sense.md#zero-crossing-detection-zcd) feedback ([EEV6](/mujoseph-docs/emma-mk1-drsstc/drsstc_driver-firmware-overview/high-resolution-timer-hrtim/external-event-eev-configuration.md#eev6-zero-crossing-detection-zcd-feedback-signal)) is not received before the timeout period via a [Compare 3](#timf-compare-3-role) interrupt service request (IRQ). [TIMF resets alongside TIMA](/mujoseph-docs/emma-mk1-drsstc/drsstc_driver-firmware-overview/high-resolution-timer-hrtim/tima-resonant-cycle-timing-reference.md#tima-update-event-overview).

TIMF output TF2 serves as a blanking source for [TIME's resonant period capture](/mujoseph-docs/emma-mk1-drsstc/drsstc_driver-firmware-overview/high-resolution-timer-hrtim/time-resonant-frequency-capture.md#time-capture-1-role) trigger (EEV6). If the capture trigger falls outside the minimum (highest tracked frequency) and maximum (lowest tracked frequency) [period limits](/mujoseph-docs/emma-mk1-drsstc/drsstc_driver-firmware-overview/serial-interface.md#start-frequency-max-positive-negative-deviation), the capture trigger is ignored. This ensures the captured resonant period is not corrupted by spurious EEV6 events that were caused by noise at the [COMP1](/mujoseph-docs/emma-mk1-drsstc/drsstc_driver-firmware-overview.md#comp1-zcd) input.

## Overview

<div data-with-frame="true"><figure><img src="https://2297250131-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzNHSl7dsTOS0XjlMXnIe%2Fuploads%2FyErY4dm5t9AjUCKBMerg%2Femma_mk1_hrtim_timf_overview.svg?alt=media&amp;token=867ea702-be3a-46a7-835b-f3d9c77f05df" alt=""><figcaption><p>HRTIM TIMF high-level overview</p></figcaption></figure></div>

## TIMF Output TF2 Role

<div data-with-frame="true"><figure><img src="https://2297250131-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzNHSl7dsTOS0XjlMXnIe%2Fuploads%2FPEheQGvyCM40hfDG2M43%2Fimage.png?alt=media&amp;token=f2ff6729-cbce-4b54-814b-e2fc55205d60" alt="" width="563"><figcaption><p>Output TF2 block diagram sub-section from <a href="#overview">overview</a></p></figcaption></figure></div>

TF2 is used as a blanking source for TIME [EEV6](/mujoseph-docs/emma-mk1-drsstc/drsstc_driver-firmware-overview/high-resolution-timer-hrtim/external-event-eev-configuration.md#eev6-zero-crossing-detection-zcd-feedback-signal) event processing.&#x20;

When TF2 is inactive/low, EEV6 events are ignored by TIME.&#x20;

TF2 is active/high when the TIME counter is between [TIME Compare 2 and TIME Compare 3](/mujoseph-docs/emma-mk1-drsstc/drsstc_driver-firmware-overview/high-resolution-timer-hrtim/time-resonant-frequency-capture.md#time-compare-2-and-3-roles) (EEV6 events are unmasked). TF2 makes use of the external event crossbar feature similar to [TIMA output TA2](/mujoseph-docs/emma-mk1-drsstc/drsstc_driver-firmware-overview/high-resolution-timer-hrtim/tima-resonant-cycle-timing-reference.md#tima-output-ta2-role).

TIME Compare 2 contains the period for the maximum frequency (smallest period) that can be tracked during the closed loop cycle.

TIME Compare 3 contains the period for the minimum frequency (largest period) that can be tracked during the closed loop cycle.

Note that the TIMF Update event and [EEV7](/mujoseph-docs/emma-mk1-drsstc/drsstc_driver-firmware-overview/high-resolution-timer-hrtim/external-event-eev-configuration.md#eev7-interrupter-prf-source-idle) (interrupter source low, i.e., between PRF burst cycles) are also valid TF2 reset sources.

EEV6 serves as a capture trigger for TIME Capture 1, therefore TF2 prevents spurious ZCD crossings from corrupting the tracked resonant frequency within the [TIME Capture 1](/mujoseph-docs/emma-mk1-drsstc/drsstc_driver-firmware-overview/high-resolution-timer-hrtim/time-resonant-frequency-capture.md#time-capture-1-role) register by only acknowledging ZCD events that map to frequencies that fall between the aforementioned min/max bounds.

## TIMF Compare 3 Role

TIMF Compare 3 is used to set the timeout period for the ZCD current feedback. If TIMF counts to the Compare 3 value before ZCD feedback is received, the TIMF ISR function will be invoked, culminating in the resonant driver terminating the active burst operation.

{% code title="stm32g4xx\_it.c" lineNumbers="true" expandable="true" %}

```c
void HRTIM1_TIMF_IRQHandler(void)
{
    // Check if the Compare 3 interrupt flag for Timer F is set.
    if (LL_HRTIM_IsActiveFlag_CMP3(HRTIM1, LL_HRTIM_TIMER_F))
    {
        // Clear the interrupt flag to prevent re-entry.
        LL_HRTIM_ClearFlag_CMP3(HRTIM1, LL_HRTIM_TIMER_F);
        // Sets RESDRV_EVT_FEEDBACK_TIMEOUT event within the 
        // resDrvTsk context
        resDrvTsk_notifyFeedbackTimeout();
    }

    if (LL_HRTIM_IsActiveFlag_CMP4(HRTIM1, LL_HRTIM_TIMER_F))
    {
        LL_HRTIM_ClearFlag_CMP4(HRTIM1, LL_HRTIM_TIMER_F);
    }
}// HRTIM1_TIMF_IRQHandler
```

{% endcode %}

The ISR above sets the `RESDRV_EVT_FEEDBACK_TIMEOUT` within the `resDrvTsk` context, invoking the event handler below, which in turn calls `mujoe_resdrv_handleFeedbackTimeout`:&#x20;

{% code title="resDriveTask.c" lineNumbers="true" expandable="true" %}

```c
static void feedbackTimeout_evtHdlr( void* arg )
{
	RESDRIVETASK_CTX ctx = (RESDRIVETASK_CTX)arg;
	mujoe_err_t err = MUJOE_ERR_NONE;

	LOG_INFO("feedbackTimeout_evtHdlr:: Current feedback timed out. Halting operation...");

	// Handle the ZCD feedback timeout: Terminate burst operation
	err |= mujoe_resdrv_handleFeedbackTimeout( &ctx->resDrvCtx );

	if( err == MUJOE_ERR_NONE )
	{
		LOG_INFO("feedbackTimeout_evtHdlr:: Current feedback timeout handled successfully!");
	}
	else
	{
		LOG_ERROR("feedbackTimeout_evtHdlr:: Current feedback timeout FAILURE!");
	}

}// feedbackTimeout_evtHdlr
```

{% endcode %}
