Help needed: Converting polling-based proximity sensor to interrupt-based reading on GEVCU7

Lucifer D

Member
Hi everyone,

I'm working on a proximity sensor implementation for the GEVCU7 board. Currently, I have a working polling-based implementation, but I need to convert it to interrupt-based reading for better performance.Here's my current polling-based code:

Code:
// ProximitySensor.cpp
void ProximitySensor::setup() {
    Logger::console("PROX: Setup called");
    tickHandler.detach(this);
    Device::setup();
    tickHandler.attach(this, CFG_TICK_INTERVAL_PROX);
    Logger::console("PROX: Initial state of Pin 0: %d", systemIO.getDigitalIn(0));
}

void ProximitySensor::handleTick() {
    uint8_t newState = systemIO.getDigitalIn(0);
    currentState = newState;
    if (currentState == 1) {
        Logger::console("PROX: Object Detected! Pin State: %d", currentState);
    }
}

The code reads DIN0 (Digital Input 0) on the GEVCU7 board. I need help understanding:
  1. Which interrupt vector should I use for DIN0?
  2. What's the proper way to set up the interrupt handler given GEVCU7's hardware architecture?
  3. How to properly integrate the interrupt handler with the existing Device framework?
Any guidance would be greatly appreciated!

Note: The GEVCU7 uses an IMXRT1062 processor (Teensy 4.x), and the digital inputs are handled through sys_io.cpp. If anyone has experience with interrupt-based input reading on this platform, I'd love to hear your insights.
 
Looks like this product is based on MicroMod Teensy. Quick search turned up this website, but I couldn't find a schematic or hardware reference that tells what Teensy pin "DIN0" really is.

If I found the wrong thing and you really have something other than this picture, please let me know. Your question didn't have any links, so I'm not 100% sure I really found the right info?

1736513895773.png
 
Hi PaulStoffregen,

Thank you for your prompt response.

Yes, this is indeed the board I am currently working with. You can find the link to the board [here]. You're correct—I'm using this board at the moment.

I can successfully read its digital Pin 0, and my code is working fine for that functionality. However, I'm unsure how to integrate the logic for the interrupt.

Whenever, the interrupt occurs on the Digital Pin 0, I have to read it.
 
I don't know anything about these software libraries it uses, like "systemIO". Can't help with that.

Using the normal Arduino functions, you would use the attachInterrupt function.

But is it really (Arduino) pin 0 on Teensy? I saw this in the PDF on page 38.

1736515750700.png
 
Thank you for your response. I understand your concern about not being familiar with the software libraries, such as "systemIO."

Perhaps @CollinK could help us out since he's the one who developed these software libraries for GEVCU and is highly experienced in this area. His insights might be invaluable for resolving this issue.
 
Sorry, I missed this thread. The bad news is that it isn't going to be as easy as you wanted. You see, I liked the MicroMod format for a variety of reasons but one downside is that it does NOT have nearly as many exposed pins as a Teensy 4.1. In all likelihood, I should have integrated the chips right on the board and gotten more I/O but I wanted both to better support PJRC by buying their products directly (this isn't a high quantity item so any cost saving would have been negligible anyway) and the use of a MicroMod board means that replacing the MCU is extremely easy. In fact, since it uses the standard MicroMod port, one could use something else in place there. A variety of MM processor boards exist.

So, that long story out of the way, I used a board with limited I/O and needed more I/O. I used an I/O expander chip -> PCA9535. The schematic for the board is here: https://github.com/collin80/GEVCU7/blob/main/GEVCU-7c_Schematic.pdf

What that means is that the first 8 digital inputs run through that I/O expander. The interrupt pin of the expander chip is connected to the micromod D0 pin. I don't remember what that corresponds to in the Teensy world but you can find the MicroMod pinout in the schematic. I don't currently use the interrupt pin but it is there and you can use it to get interrupts when I/O changes state so this could work for you. Alternatively, the last 4 digital inputs actually do bypass the I/O expander and are connected straight to TeensyMM.

Here is the relevant code:
Code:
            case 8:
                return !(digitalRead(40));
                break;
            case 9:
                return !(digitalRead(41));
                break;
            case 10:
                return !(digitalRead(42));
                break;
            case 11:
                return !(digitalRead(9));
                break;

So, you could use one of those pins (alas, the actual Teensy digital pin numbers!) and ask Arduino to set a pin interrupt for you.

I suppose I should mention, look above how all the digital reads are inverted. All digital inputs on the board are opto-isolated and work with passive pull up and the isolator pulls the line down when active. So, logic is inverted. GEVCU7 code hides this from you but electrically it's backward so keep that in mind if you go asking for interrupts. You want to interrupt on the line going down, not up.
 
On Arduino's attachInterrupt() documentation page, there is example code. Just scroll down to find it. Maybe trying to run that example might help? Of course, edit the interruptPin number!

That example needs a LED. Pin 13 should be the LED on MicroMod. Not sure if you're able to see that LED?

But one caveat is Teensy runs at extremely high speed, so it will easily respond to mechanical chatter. So if the LED seems to sometimes change, like 50-50 chance each time you change the input by touching a wire or pressing a button, just be aware that sort of result would be expected due to the interrupt detecting the mechanical chatter many times even though you only tried to change the signal once.
 
Back
Top