PDA

View Full Version : Teensy 2.0, Attach interrupt question



keithg
12-05-2012, 06:54 PM
Group,

I have converted a sketch which I was running on an Arduino Mega to teensy 2.0. Most everything works, but I am having a strange problem and wanted to make sure I was coding the interrupt correctly. This is snippets of the code:


int zc_pin = 7; // external interrupt Teensy on int 0-4, pins 5-8 only
...
void setup() { // Begin setup
...
pinMode(zc_pin, INPUT); // 7 Teensy needs this defined
attachInterrupt(zc_pin, zero_cross_detect, RISING); // Attach an Interupt to zc_pin for Zero Cross Detection
...

I am using pin 7 which is interrupt 2 according to the card. With Arduino, the line would be:

attachInterrupt(2, zero_cross_detect, RISING); // Attach an Interupt to zc_pin for Zero Cross Detection

The sketch runs only if the scope lead is attached to the interrupt line or any of the outputs. The problem appears to be that there is not enough drive to the output unless the scope is attached. I do not think the interrupt is causing it and the sketch runs just fine on the Mega, I just wanted to make sure I had this part ciorrect.

Regards,

Keith

PaulStoffregen
12-05-2012, 09:57 PM
Sometimes "only works when 'scope connected" problems are due to grounding. Oscilloscopes have their probe grounds connected to earth ground. Sometimes a system without necessary ground connections works when it gets a ground from the probe, but stops working when you disconnect the probe.

A simple check involves leaving the probe tip disconnected, but the probe ground wire still clipped. If that still works, you know it's a ground issue.

keithg
12-07-2012, 11:38 AM
Thanks for the tip. It wasn't the ground. Even without the scope ground connected, it would run when I touched the scope probe. I put a 0.01 uf cap to ground on that lead and it works consistently, now.