Hi,
I've got a really simple project for a Teensy 4.0 where I use it to count incoming pulses from something else I'm working on. Frequency is <500Hz so should be easy right?
Relevant code below:
The incoming pulses are at 5V logic level, active low, and have very slow transitions so I used a SN74LVC14A Schmitt trigger rather than connecting directly to the Teensy 4.0. So the input pin of the Teensy 4.0 is driven directly by the Schmitt trigger's output.
I found the ISR was being called twice - effectively on both edges.
On my scope it seemed that there was some ringing on the falling edge of the signal I guess when that looked like another rising edge to the Teensy. Sorry I forgot to take a picture. I'm using a breadboard so I know it's not ideal for signal condition, but the solid core wire between the Schmitt trigger's output and the Teensy's input is abut 40mm long, and I have a 100nF capacitor soldered directly to the Vcc and GND pins of the Schmitt trigger - can't get any closer than that! The Schmitt trigger IC is powered from the Teensy's 3.3V regulator but it did the same thing when I powered it externally. I checked the power supply pin on the Schmitt trigger and I didn't see it dipping when the erroneous trigger was happening, so I don't think it was related to that.
I enabled the hysteresis mode as described in here but it didn't make an immediate difference. I put a 220pF ceramic capacitor across the Teensy's GPIO pin and GND and it got a lot better but still rarely I get the ISR called on the falling edge. The transition time is now about 25ns which is the maximum specified in the datasheet, but presumably with hysteresis turned on it's ok to exceed that limit per the datasheet. So I might be able to increase the capacitance further and make the problem fully go away.
It seems a bit weird that I'm having to clean up the output of a Schmitt trigger, since that's kind of its job. I need this to never count any extra so I would really appreciate any advice.
Before adding capacitor (I pulled it out again to take this):
After adding capacitor:
Thanks
I've got a really simple project for a Teensy 4.0 where I use it to count incoming pulses from something else I'm working on. Frequency is <500Hz so should be easy right?
Relevant code below:
C++:
void count_input_pulse_isr() {
input_pulse_count++;
}
void setup() {
pinMode(INPUT_PIN, INPUT);
// Configure external interrupt
attachInterrupt(digitalPinToInterrupt(INPUT_PIN), count_input_pulse_isr, RISING);
The incoming pulses are at 5V logic level, active low, and have very slow transitions so I used a SN74LVC14A Schmitt trigger rather than connecting directly to the Teensy 4.0. So the input pin of the Teensy 4.0 is driven directly by the Schmitt trigger's output.
I found the ISR was being called twice - effectively on both edges.
On my scope it seemed that there was some ringing on the falling edge of the signal I guess when that looked like another rising edge to the Teensy. Sorry I forgot to take a picture. I'm using a breadboard so I know it's not ideal for signal condition, but the solid core wire between the Schmitt trigger's output and the Teensy's input is abut 40mm long, and I have a 100nF capacitor soldered directly to the Vcc and GND pins of the Schmitt trigger - can't get any closer than that! The Schmitt trigger IC is powered from the Teensy's 3.3V regulator but it did the same thing when I powered it externally. I checked the power supply pin on the Schmitt trigger and I didn't see it dipping when the erroneous trigger was happening, so I don't think it was related to that.
I enabled the hysteresis mode as described in here but it didn't make an immediate difference. I put a 220pF ceramic capacitor across the Teensy's GPIO pin and GND and it got a lot better but still rarely I get the ISR called on the falling edge. The transition time is now about 25ns which is the maximum specified in the datasheet, but presumably with hysteresis turned on it's ok to exceed that limit per the datasheet. So I might be able to increase the capacitance further and make the problem fully go away.
It seems a bit weird that I'm having to clean up the output of a Schmitt trigger, since that's kind of its job. I need this to never count any extra so I would really appreciate any advice.
Before adding capacitor (I pulled it out again to take this):
After adding capacitor:
Thanks