Possible ringing issue

CRNorris

Member
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:

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):
DS1Z_QuickPrint10.png


After adding capacitor:
DS1Z_QuickPrint11.png



Thanks
 
Need to see the circuit, it looks like you have inadequate groundplane or something like that that's contributing a lot of inductance, I'd try adding 100R on the output of the 74LVC14 to dampen it down a bit.
I'm using a breadboard so I know it's not ideal for signal condition
Ah, that's why then. You can improve things by using flat wires against the breadboard surface (no looping wiring) which is easiest done with 0.65mm solid core hookup wire (AWG22), and add a ground grid across the breadboard to help provide current return paths close to the signal wiring in question. Capacitance won't damp an oscillation much, just slow it down, resistance will provide damping as well. Ensure the 74LVC14 has proper decoupling as close to the chip as possible (which for breadboard means a ~100nF ceramic cap straddling across it or similar arrangement).
 
Thanks for the reply.

You're right, the capacitance wasn't doing the trick on its own and it did need resistance on the output of the SN74LVC14A.

I read in the datasheet for the SN74LVC14A:

The high drive capability of this device creates fast edges into light loads so routing and load conditions should be considered to prevent ringing. Additionally, the outputs of this device are capable of driving larger currents than the device can sustain without being damaged.

I wondered if this was a problem with the Teensy's pin having too high impedance and causing reflections, so I tried putting a resistor to ground at the Teensy's input pin that should have resulted in 10mA being sunk but it didn't make any difference to the waveform on the scope. So I think this problem is actually just caused by inductance inherent in the breadboard (and the SOIC breakout board I'm using...).

I had already tried putting resistance in line between the Schmitt trigger IC and the Teensy and I got up to 750R before it started to really improve which seemed wrong. But I think the mistake I made there was I used a short wire to go to another row of the breadboard, then used a resistor to connect that to the Teensy. There wasn't anything else connected to that row, but I guess just involving one more breadboard row was exacerbating the breadboard parasitics issue. The situation hugely improved when I got a resistor with long legs and just spanned the full distance without also using another wire as well.

I ended up with 150R in line because that's the lowest value I had on hand, and it was dramatically better. 100R as you suggest might have been even better.

Unfortunately I then had a problem with random extra counts of one or two per thousand, but I think that was actually noise, presumably caused by the increased resistance. I occasionally saw weird extra shapes on the scope with the intensity turned to max. So I put the 220pF capacitor back in across the Teensy's input pin and ground. The random extra shapes dissappeared from the scope, and I have now had it count 34 million pulses in a row perfectly. (I think a much lower capacitance would be acceptable, this is the smallest I had on hand.)
 
Back
Top