Here is a little help with using a T4 Analog Comparator. It uses the peripheral ACMP3. Normally, the ACMP3 output is available on pin AD_B1_14 (see page 295 of iMXRT1060 Ref Manual Rev2). But this is on the underside of the T4 board on Teensy 4 pin 26. I like to use breadboard for experimental testing, so I have employed the XBAR1 cross trigger component to re-route ACMP3_OUT to Teensy 4 pin 2, which is available topside and from my breadboard.
Here is a small fully working sketch that you can check out. Its purpose is to take a small analog signal from a signal generator and "threshold" it via the comparator against an internal DAC preset to a voltage set halfway between 3v3 and GND. The input is to pin 18, and the output is then a square wave signal of amplitude 3v3 on pin2...
Code:
//TestT4 ACMP3
//-------------------
//Date: 22 JUL 2020
//Author: TelephoneBill
//Purpose: Test of using the Teensy 4.0 ACMP3 Comparator
//Version: 1v00
//DEFINE variables
//================
int LED = 13;
//SETUP routine
//=============
void setup() {
//Initialize the digital pin 13 as an output for LED.
pinMode(LED, OUTPUT);
//Enable ACMP3 to threshold an analogue a.c. input signal - 9 code steps below
//Note: Signal is via 0.1 mfd into pin 18. 10 turn 10K pot across 3v3 and GND with wiper also to pin 18.
//Set 10K pot to central position (5K). This will bias the d.c. voltage on pin 18 to midway 3v3 and GND.
//ACMP3 input is pin 18 (ACMP3_IN0 = AD_B1_01 : Default connection - no need for muxing)
//Voltage reference (INM7) is 6-bit internal DAC, VIN2 = VDD (3.3v)
//ACMP3_OUT (output) is on T4 pin 2 (via XBAR1 and EMC_04)
//Comparator output state is available if desired - read "CMP3_SCR" register least significant bit
CCM_CCGR2 |= CCM_CCGR2_XBAR1(CCM_CCGR_ON); //(1) turn clock on for xbara1
XBARA1_SEL3 = 0x001C; //(2) this connects XBAR1_INOUT6 to XBAR1_IN28 (ACMP3_OUT)
IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_04 = 3; //(3) ALT3 connects XBAR1_INOUT6 to T4 Pin 2
IOMUXC_GPR_GPR6 |= 0b00000000000001000000000000000000; //(4) IOMUXC_XBAR_DIR_SEL_6 = 1 (direction select for XBAR_INOUT6)
CCM_CCGR3 |= 0x03000000; //(5) enable clocks to CG12 of CGR3 for ACMP3
CMP3_CR0 = 0b00000000; //(6) FILTER_CNT=0; HYSTCTR=0
CMP3_CR1 = 0b00010111; //(7) SE=0, high power, COUTA, output pin, enable; mode #2A
CMP3_DACCR = 0b11011111; //(8) Set DAC = 1/2 of VIN2 (3.3v) = 1.65v
CMP3_MUXCR = 0b00000111; //(9a) CMP_MUX_PSEL(0) | CMP_MUX_MSEL(7) Input pins select;
//(9b) plus = IN0 (pin 18), minus = DAC (code 7). PSTM = 0 (Pass Through Mode Disabled)
}
//MAIN LOOP routine
//=================
void loop() {
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100);
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
delay(900);
}
Here is a screen shot from my scope of the sketch in action, together with a photo of the physical test configuration...

Ignore the copper foil covering the processor (its from another previous experiment). The Teensy input pin needs to be biased very close to the threshold voltage, so I have used a 10 turn 10K pot connected across 3v3 and GND, with the wiper fed to pin 18. Also connected to pin 18 is that yellow 0.1 mfd capacitor from the signal generator, which is the route for the small a.c. signal (100KHz and 500mV pk to pk). The pot has been turned 5 turns so the bias voltage is somewhere near to 1.65 volts.
You can see some noise induced glitches on the scope shot on Trace1 (sine input) when Trace2 changes state (sq wave output). Notice that the point of positive going transition on Trace1 is slightly more positive than that for the negative going transition. This is the hysteresis of the comparator.
You can test the comparator before connecting a sine wave just by carefully twiddling the 10K pot knob around the mid-way position. A voltmeter on the output pin 2 will show a change of logic state as the bias is raised slightly above or slightly below the threshold voltage. This is a good way to make sure you have the bias adjusted correctly before connecting the sine wave input.
Have fun with this "stand-alone" experiment of a T4 Comparator - I did