Hello,
I'm using a Teensy 3.2 to receive data from a LightWare SF30/C laser rangefinder (datasheet here). The board receives data (distance measurements) over serial (pins 0, 1) without trouble. I can verify this by reading them in loop(). The board also drives a motor through a Pololu motor driver from pin 23. This also works fine.
The laser has a sync wire which is pulled low at the instant a measurement is taken, which should enable precise timing. I'm attempting to trigger an interrupt when this occurs, in order to capture the time. There's a screen capture from a scope on page 9 of the datasheet, showing that line is pulled low for about 5us (I think?) I don't have a scope, but I can detect the signal by reading from the wire using analogRead(); periodically the level goes to 1. I've connected the sync wire to pin 2.
The problem is this: using attachInterrupt with FALLING, the interrupt is never called. The output on Serial is an endless stream of zeroes (as you'd expect.)
If I use LOW, the program appears to hang, the motor does not move and there's no traffic on Serial.
Here is my working, stripped-down code:
If anyone can suggest what might be happening here, or any information I've omitted I'd be grateful for the input!
Rob
I'm using a Teensy 3.2 to receive data from a LightWare SF30/C laser rangefinder (datasheet here). The board receives data (distance measurements) over serial (pins 0, 1) without trouble. I can verify this by reading them in loop(). The board also drives a motor through a Pololu motor driver from pin 23. This also works fine.
The laser has a sync wire which is pulled low at the instant a measurement is taken, which should enable precise timing. I'm attempting to trigger an interrupt when this occurs, in order to capture the time. There's a screen capture from a scope on page 9 of the datasheet, showing that line is pulled low for about 5us (I think?) I don't have a scope, but I can detect the signal by reading from the wire using analogRead(); periodically the level goes to 1. I've connected the sync wire to pin 2.
The problem is this: using attachInterrupt with FALLING, the interrupt is never called. The output on Serial is an endless stream of zeroes (as you'd expect.)
If I use LOW, the program appears to hang, the motor does not move and there's no traffic on Serial.
Here is my working, stripped-down code:
Code:
#define PWM_1 23 // PWM output pin 1
#define LASER_SYNC 2 // Laser sync pin
volatile unsigned long rangeTime; // Time of next laser pulse on serial.
volatile bool rangeUpdate; // True if a range update is expected.
void setup() {
rangeUpdate = false;
Serial.begin(115200);
pinMode(PWM_1, OUTPUT); // Pin for the drive motor speed
pinMode(LASER_SYNC, INPUT_PULLUP); // Pin for laser sync
attachInterrupt(LASER_SYNC, laserSyncISR, LOW); // Interrupt for laser pulse -- HANGS WITH LOW; NO INTERRUPT WITH FALLING
analogWrite(PWM_1, 64); // Start the motor.
interrupts();
}
void loop() {
Serial.println(rangeTime);
}
void laserSyncISR() {
rangeTime = 1; //micros();
rangeUpdate = true;
}
If anyone can suggest what might be happening here, or any information I've omitted I'd be grateful for the input!
Rob