Triggering ADC measurements via a digital interrupt from a rotary encoder. Teensy 4.0

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:

https://curiousscientist.tech/blog/as5600-nema17-speed-and-position


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

#define CORE_PIN0_CONFIG IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_03

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

#define IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_03 (IMXRT_IOMUXC.offset0C8)
#define IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B0_03 (IMXRT_IOMUXC.offset2B8)

Or from the manual about page 303:

GPIO1_IO03 GPIO_AD_B0_03 ALT5

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-T4-Comparators-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
J
 
Back
Top