Interrupts and Pinout

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
kyleskom
 
Posts: 2
Joined: Tue Dec 07, 2021 9:10 pm

Interrupts and Pinout

Post by kyleskom »

Hi, im trying to do Interrupts without digital read like,

Code: Select all

void setup() {
  PCICR  |= (1 << PCIE0);  // Set PCIE0 to enable PCM$K0 scan
  PCM$K0 |= (1 << PCINT0); 
  PCM$K0 |= (1 << PCINT1); 
  PCM$K0 |= (1 << PCINT2);
  PCM$K0 |= (1 << PCINT3);

}
void ISR(PCINT0_vect) {
        current_time = micros();

        // Channel 1 -------------------------------------------------
        if (PINB & B00000001) {                                        // Is input 8 high ?
            if (previous_state[CHANNEL1] == LOW) {                     // Input 8 changed from 0 to 1 (rising edge)
                previous_state[CHANNEL1] = HIGH;                       // Save current state
                timer[CHANNEL1] = current_time;                        // Save current time
            }
        } else if (previous_state[CHANNEL1] == HIGH) {                 // Input 8 changed from 1 to 0 (falling edge)
            previous_state[CHANNEL1] = LOW;                            // Save current state
            pulse_length[CHANNEL1] = current_time - timer[CHANNEL1];   // Calculate pulse duration & save it
        }
But don't believe I can do this. Any help here?
Also if you guys provide a pinout diagram for the Metro Express M0 like you do for this
https://cdn-shop.adafruit.com/product-f ... l_v2_0.pdf

Note: Really, P C M S K 0 is banned?

User avatar
danhalbert
 
Posts: 4654
Joined: Tue Aug 08, 2017 12:37 pm

Re: Interrupts and Pinout

Post by danhalbert »

The word censor was matching an overly general wildcard pattern. I've fixed that.

Have you tried https://www.arduino.cc/en/Reference/AttachInterrupt and related routines?

We are working on those nice "prettypins" diagrams for more boards. There are a lot to do :). They are partially machine generated, and then we have to touch them up.

User avatar
kyleskom
 
Posts: 2
Joined: Tue Dec 07, 2021 9:10 pm

Re: Interrupts and Pinout

Post by kyleskom »

Thanks for the response, I have used that and it works but my understanding is that it isn't the most efficient.
Im trying to directly use Port Registers directly like:
https://www.arduino.cc/en/Reference/PortManipulation

User avatar
danhalbert
 
Posts: 4654
Joined: Tue Aug 08, 2017 12:37 pm

Re: Interrupts and Pinout

Post by danhalbert »

The PCMSK0 register is on the "classic" Arduino AVR chips. The interrupt structure on SAMD21 chips is quite different. The interrupt library looks pretty OK to me. I don't think you are going to lose a lot of time using it: https://github.com/adafruit/ArduinoCore ... terrupts.c

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”