Teensy 2.0, Attach interrupt question

Status
Not open for further replies.

keithg

Well-known member
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:
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:
Code:
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
 
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.
 
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.
 
Status
Not open for further replies.
Back
Top