Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days. On MLK Day no orders will be shipped.
0

Interrupts and Pinout
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Interrupts and Pinout

by kyleskom on Tue Dec 07, 2021 9:13 pm

Hi, im trying to do Interrupts without digital read like,
Code: Select all | TOGGLE FULL SIZE
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-files/50/P50_Adafruit_Metrol_v2_0.pdf

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

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

Re: Interrupts and Pinout

by danhalbert on Wed Dec 08, 2021 11:28 am

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.

danhalbert
 
Posts: 2954
Joined: Tue Aug 08, 2017 12:37 pm

Re: Interrupts and Pinout

by kyleskom on Wed Dec 08, 2021 11:47 am

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

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

Re: Interrupts and Pinout

by danhalbert on Wed Dec 08, 2021 12:03 pm

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

danhalbert
 
Posts: 2954
Joined: Tue Aug 08, 2017 12:37 pm

Please be positive and constructive with your questions and comments.