|
NetBurner 3.5.7
PDF Version |
Example Path: examples/PlatformSpecific/MODRT1171/ACMP
This example exercises the two on-chip analog comparators (ACMP1 and ACMP2) of the i.MX RT1171 processor on the MODRT1171 module. Each comparator is set up with an external analog input on its positive side and the chip's internal 8-bit DAC on its negative side, so the comparator fires when the input crosses a programmable threshold. The example also shows how to route a comparator's digital output through the XBARA1 crossbar to a general-purpose pin, and how to wire edge-triggered interrupts.
A simple serial console lets you retune the ACMP1 threshold at runtime and watch the comparator output respond on the scope or logic analyzer.
MIMX_ACMP objects wrapping the RT1171 CMP peripherals:0x7F (~ VREF/2 ~ 1.65 V). Default filter/hysteresis.0xA0, inverted output polarity, digital output filter with period 240 and sample count 7.Inout17 of the signal crossbar, which is then routed to pin P1[13]. This demonstrates reaching an internal signal that would otherwise stay on-die.P1[4] -> ACMP1_IN1 (ACMP1 positive input)P1[24] -> ACMP2_IN2 (ACMP2 positive input)P2[6] -> ACMP1_CMPO (ACMP1 direct output)P1[13] -> XBAR_INOUT17 (ACMP1 output via XBARA)P2[7] -> ACMP2_CMPO, open-drain – combined with an external RC network, this can form a relaxation oscillator (variable-frequency pulse generator).irqCounts[HwIdx()]:s** (or S) and type a decimal or 0x-prefixed hex value 0-255; the ACMP1 DAC threshold is updated live with acmp.SetDacVal(...).MIMX_ACMPDefined in src/mimx11xx_acmp.h.
| Call | Purpose |
|---|---|
MIMX_ACMP(idx, posCh, negCh, dac, ...) | Construct + configure one comparator (see header for defaults). |
Enable() / Disable() | Turn the comparator on/off. |
SetInputs(pos, neg) | Select positive and negative input channels at runtime. |
SetDacVal(v) | Change the internal-DAC threshold (0-255, v / 256 x VREF). |
SetOutputPolarity(p) | p < 0 inverts the output; otherwise non-inverting. |
SetFilter(period, count) | Enable the digital output filter (majority filter on samples). |
RegisterIsr(handler) | Install a callback invoked on edge interrupts. |
EnableIrq(falling, rising) | Enable interrupt on either or both edges. |
GetState() | Sample the current comparator output. |
The ISR signature is:
cmp.HwIdx() returns 0 for ACMP1, 1 for ACMP2, etc., which the example uses to fan out into the irqCounts[] array.
SUPPORTED_PLATFORMS = MODRT1171).P1[4] from a signal source in the 0-VREF range (default VREF is the chip's 1.65 V internal reference, so useful input range is roughly 0-1.65 V unless you change VRSEL).P1[24] similarly.P2[6] – ACMP1 direct compare output (push-pull).P1[13] – ACMP1 output routed through XBARA1.P2[7] – ACMP2 open-drain output (needs a pull-up to observe a logic high; shorting to a cap + resistor on the ACMP2 input will produce a self-sustained pulse train).After programming the board, open the serial console. You should see:
Then drive the ACMP1 input. The P2[6] and P1[13] pins will toggle as the input crosses the threshold. To move the threshold:
ACMP1 now compares against 0x40 / 0x100 x VREF. The ISR counter in irqCounts[0] will tick up on every edge as the input crosses the new threshold.
filtPer = 240, filtCount = 7) is a majority filter over 7 samples taken every 240 clock ticks of the filter's sampling clock. It's intended to suppress chatter near the threshold; disable it by passing 0 for either value if you want raw response.0xA0) and not updated.EnableSystemDiagnostics() is left on for convenience. Remove it from production code.