I'm reading the source code for the icu module of the avr port (Chibios 17.6.3) but I don't think I get how the function handle_capture_isr() (line 93 of file hal_icu_lld.c) works. On page 133 of the ATMega328p datasheet, it says:
When the ICES1 bit is written to zero, a falling (negative) edge is used as trigger, and when the ICES1 bit is written to one, a rising (positive) edge will trigger the capture.
From this I understand that line 99 of hal_icu_lld.c,
Code: Select all
uint8_t rising = (*tccrb & (1 << ICES1)) ? 1 : 0;
sets the variable rising to 1 if a rising edge occurs in pin ICP1, or to 0 if a falling edge occurs. Hence, the following if on lines 101-105,
Code: Select all
if ((icup->config->mode == ICU_INPUT_ACTIVE_HIGH && rising) ||
(icup->config->mode == ICU_INPUT_ACTIVE_LOW && !rising)) {
icup->width = value;
if (icup->config->width_cb != NULL)
icup->config->width_cb(icup);
calls the width_cb callback function if a rising (activation) edge occurs and the icu module is configured to active high.
However, the Chibios documentation for the ICU module shows a state diagram that indicates that in this situation the period_cb callback should be called instead.
Am I misunderstanding something here?
Thanks.