Hi -
My project uses a fiber optics sensor to detect holes on a film strip, and after X amount of holes detected, a signal is sent to a camera to take a picture. This happens fast and continuously, up to 96 holes detected per second.
This is the sensor amplifier I use:
https://www.keyence.com/products/sensor/fiber-optic/fs-n40/models/fs-n41p/
..and this is the fiber optics sensor:
https://www.keyence.com/products/sensor/fiber-optic/fu/models/fu-20/
I chose the Teensy 4.1 for this project because of it's speed. The hardware for my machine is hooked up and working properly.
The code I have is very flawed and I can see issues when I run my machine - I should mention that I am very novice at coding.
This is the code I currently use, it detects 4 holes and then takes a picture.
I understand this is probably the wrong way to do this and that I am not using the fast timers on the Teensy. This is where I need some help.
How could I make this efficient and precise.
Also not sure if it's appropriate to ask here but I would offer this as a paid gig for anyone interested. Please let me know if that's not within the forum rules here and I'll delete this bit. If it's ok - and anyone is interested please PM me.
Picture of the prototype machine below:
thanks!
My project uses a fiber optics sensor to detect holes on a film strip, and after X amount of holes detected, a signal is sent to a camera to take a picture. This happens fast and continuously, up to 96 holes detected per second.
This is the sensor amplifier I use:
https://www.keyence.com/products/sensor/fiber-optic/fs-n40/models/fs-n41p/
..and this is the fiber optics sensor:
https://www.keyence.com/products/sensor/fiber-optic/fu/models/fu-20/
I chose the Teensy 4.1 for this project because of it's speed. The hardware for my machine is hooked up and working properly.
The code I have is very flawed and I can see issues when I run my machine - I should mention that I am very novice at coding.
This is the code I currently use, it detects 4 holes and then takes a picture.
Code:
const int sensor = 23;
int perf = 0;
int var = 0;
int frame_counting = 0;
int cameraTrigger= 32;
void setup() {
Serial.begin(115200);
pinMode(led, OUTPUT);
attachInterrupt(digitalPinToInterrupt(sensor), count, FALLING);
}
//
void count() {
if(digitalRead(sensor) > var)
{
var = 1;
perf++;
if((perf % 1) == 0){
frame_counting++;
digitalWrite(cameraTrigger, HIGH);
delay(1);
digitalWrite(cameraTrigger, LOW);
Serial.print(frame_counting);
Serial.print(" perf");
Serial.println(" detected.");
}
}
if(digitalRead(sensor) == 0) {
var = 0;}
delay(1);
}
void loop() {
}
I understand this is probably the wrong way to do this and that I am not using the fast timers on the Teensy. This is where I need some help.
How could I make this efficient and precise.
Also not sure if it's appropriate to ask here but I would offer this as a paid gig for anyone interested. Please let me know if that's not within the forum rules here and I'll delete this bit. If it's ok - and anyone is interested please PM me.
Picture of the prototype machine below:
thanks!