Skip to content

[ADC & HRTIM] Measurment trigger #140

@jalinei

Description

@jalinei

At the moment measurement instant trigger is hardcoded to 6% inside PwmHAL.cpp

void PwmHAL::enableAdcTrigger(hrtim_tu_number_t pwmX)
{
	/* Initial trigger value when you enable the adc trigger */
	uint16_t initial_trigger_value;
	hrtim_adc_trigger_en(pwmX);
	if (hrtim_get_modulation(pwmX) == UpDwn)
	{
		initial_trigger_value = 0.06 * hrtim_period_get(pwmX);
		hrtim_tu_cmp_set(pwmX, CMP3xR, initial_trigger_value);
	}
	else
	{
		initial_trigger_value = 100;
		hrtim_tu_cmp_set(pwmX, CMP3xR, initial_trigger_value);
	}
}

We could rather define that in the devicetree.
Also for now it is a bit defined as dark magic. 6% of period actually set the trigger just before the center of the upDown carrier, but it is not easy to understand. The real logic is explained below. We should at least document this somewhere, and preferably tweak the calculation so it is easy to set the trigger instant without black magic involved.

In the STM32 HRTIM block “rollover” doesn’t mean crossing the compare value; it means which counter rollover event is used to latch the ADC trigger: PER when the timer hits its PERIOD value, or RST when it hits zero.

EdgeTrigger_up maps to LL_HRTIM_ROLLOVER_MODE_PER, so the ADC trigger is refreshed right after the counter reaches its top (PER). Once the counter reverses and starts counting down, it encounters the CMP3 value almost immediately—hence the trigger appears on the descending slope right after the peak.

EdgeTrigger_down maps to LL_HRTIM_ROLLOVER_MODE_RST, so the trigger refresh waits until the counter wraps at zero; the next time the counter comes up, the compare match happens on the rising slope.

So the “up/down” labels refer to which rollover event (PER vs RST) updates the trigger, not to the slope on which the compare match occurs in center-aligned mode.

Metadata

Metadata

Labels

bugSomething isn't workingdocumentationImprovements or additions to documentationenhancementNew feature or request

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions