Skip to content

6.1 Power Board

Dorothy Ma edited this page Feb 2, 2025 · 3 revisions

Interrupt Pin for Water Detection

Objective: Implement an interrupt that is called by the water detection sensor to shut down the power board.

  1. To use any pin on the Teensy 4.0 as an interrupt, use attachInterrupt(digitalPinToInterrupt(pin), ISR, mode)
  • digitalPinToInterrupt converts the desired pin to the interrupt number recognized by the attachInterrupt function.
  • ISR is the interrupt service routine to be called. Should take 0 parameters and return nothing.
  • mode is the trigger type of the signal. Modes include RISING, FALLING, LOW, and CHANGE for detecting rising signal, falling signal, low signal, or any change in signal.
  • Link to documentation here.
  1. For the rising edge signal of our Water Detection sensor, set up the pinMode to be pinMode(pin, INPUT_PULLDOWN)
  • All digital pins have optional pullup, pulldown, or keeper resistors. PULLDOWN will keep the pin logic at a LOW signal when not driven by external circuitry. Prevents the signal from floating.
  • Our sensor sends a RISING signal, which means the default of the pin should be at LOW logic, such that the interrupt will be called when the sensor triggers a change from LOW to HIGH.
  • Link to pullup, pulldown, and keeper resistors for digital pins here.
  1. Setting the priority of interrupts with NVIC_SET_PRIORITY(iqrn, priority)
  • All pins for Teensy 4.X use the iqrn: IRQ_GPIO6789.
  • There are 16 levels of interrupt, from 0-255, where 0 is the highest priority. The priorities are sorted in intervals of 16, meaning 0-15 will all have the same priority and 16-31 will have the same priority.
  • The default priority is 128.
  • Source: attachInterrupt Priority

Notes:

  • delay() uses interrupts to work, so they will not work if called in the ISR. Use instead delayMicroseconds().
  • To turn off an interrupt, use detachInterrupt(digitalPinToInterrupt(pin)).

more to be added

Clone this wiki locally