Hello again,

So I've been looking at calibrating custom built low rpm bldc motors with a magnetic rotatory encoder. I've been investigating different encoders and have settled on the as5600. I've found some code here which has an example of how to trigger an ISR whenever the encoded has a change in the clock pulse:


I have some experience configuring the ADC of a teensy 4.0 and have some working code which triggers some adc measurements, currently this code gets a trigger from a PWM trigger and uses xbar to connect the PWM trigger to the ADC trigger like this:

xbarConnect(XBARA1_IN_FLEXPWM1_PWM1_OUT_TRIG0, XBARA1_OUT_ADC_ETC_TRIG00); // pwm module 1.0 pin 1 phase A PWMING
So happy with the ADC/ADC-ETC configuration. However for my purposes I would like to trigger the ADC(to measure the voltage of 4 pins) automatically everytime that the encoder detects a change of state. Looking at the websites code above this is how the interrupt is configured:

attachInterrupt(digitalPinToInterrupt(RotaryCLK), RotaryEncoder, CHANGE);
The RotaryEncoder callback has the logic making a comparison with the CLK:

CLKNow = digitalRead(RotaryCLK)
Checking for CLKNow changing compared to an old stored value indicates that we do have a new encoder value that we can read if we choose via the I2C Wire commands in ReadRawAngle().

RotaryCLK is pin 3 in the code. Now for simplicity lets say we will use pin 0 on a teensy 4.0, looking at core_pins.h, I can see this entry

Looking at imxrt.h I can see two entries for this:

Or from the manual about page 303:

So I think that pin 0 can be somehow configured as a GPIO port (AD_B0_03 specifically). And I believe I could somehow use XBARA1_IN_IOMUX to connect GPIO to one of the XBAR inputs and then XBar connect this input to the ADC_ETC trigger. Could anyone advice on how I might configure the CLK pin having a change of state leading to the triggering of the ADC via XBAR?

I've found some useful information from this post: https://forum.pjrc.com/threads/57359...ators-and-XBAR
But could really use a little advice as to what at a high-level i must configure, I know i need to and am confident in configuring the ADC for measurement, I am not confident about how to configure xbar such that it triggers ADC-ETC when there is a rising or falling edge on the CLK pin.

Any pointers even at a high level could greatly help me.

Best regards