I have a project where I'm using a Trinket M0 to count logic pulses coming in from another microcontroller, a Teensy 4.1. Both devices are powered from the same source and their grounds are connected.
I'm feeding the signal from the Teensy to pin 1 , and attaching an interrupt routine to that pin:
volatile int motorpositioncounter1;
int motorpos;
const int xstepPin = 1;
const int xdirPin = 2;
/*************************************************************************************/
void countpulse1(void)
{
if (digitalRead(xdirPin)) motorpositioncounter1--;
else motorpositioncounter1++;
}
/*************************************************************************************/
void setup()
{
pinMode(xstepPin, INPUT);
pinMode(xdirPin, INPUT);
// setup interrupt to count pulses
motorpositioncounter1 = 0;
attachInterrupt(digitalPinToInterrupt(xstepPin), countpulse1, FALLING);
motorpos = 0;
}
/*************************************************************************************/
void loop()
{
// Get the motor position.
noInterrupts();
motorpos = motorpositioncounter1;
interrupts();
// display it
DisplayMotorPosition(motorpos);
delay(10);
}
/*************************************************************************************/
This compiles and runs without error, but the pulses are not getting counted. This exact same setup works perfectly with a Teensy LC, but doesn't work with the Trinket M0. The pinout card indicates that I should be able to trigger hardware interrupts on pin1 in this manner, but it doesn't appear to be working. Is there something I'm not doing right here?
Thanks!
Hardware Interrupt?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- JohnKnoll
- Posts: 2
- Joined: Sun May 15, 2022 9:29 pm
Re: Hardware Interrupt?
Sorry, false alarm. It is working. Like an idiot I was hooked up to the wrong pin on the Teensy.
Please be positive and constructive with your questions and comments.