目录 Content
[hide]
Basler 相机可以配置 Output Line 为不同的功能,比如 Exposure Active , 即曝光正在进行时,output 会输出一个电平信号。
本文将使用 Arduino UNO R3 设法捕捉这个脉冲信号的时长,以便搞清楚两个关键点:
- 设置曝光时间是否真的有效
- 信号响应有无延迟
一、BASLER 相机的引脚和设置
1. 设置 Input Line
Pin2 为 Input Line,可以配置上升沿或下降沿电平触发拍照。
在软件里打开 Trigger Mode
2. 设置 Output Line
Pin4 为 Output Line,当 Out_1_Ctrl 有输出时,Pin4为低电平。
在软件里将 Exposure Active 分配给 Output Line
二、Arduino 的编程和测试
1. 第一次测试 V0.0.1
这是最初采用的版本,思路是 Arduino 的一个输入引脚作连接触发按钮(需要考虑防抖),用一个输出引脚触发相机拍照。将相机的 Output Line 接入 Arduino 的另一个输入引脚,每当此引脚电平发生改变时,记录下此时的定时器数值,这样每次曝光就会记录两个时间点,间隔时间就包括了信号延迟和曝光设定的时间。
//LED pin const int ledPin = 13; // input pin, HIGH Normal const int buttonPin = 2; int buttonPinState = HIGH; int lastButtonPinState = HIGH; // const int signalPin = 3; int signalPinState = LOW; int lastSignalPinState = LOW; long Time[10]; int indexTime = 0; // const int triggerPin = 13; //press time long lastPressTime = 0; long PressDelayTime = 20; void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(signalPin, INPUT_PULLUP); pinMode(triggerPin, OUTPUT); pinMode(ledPin, OUTPUT); Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } } void loop() { //Button int CurrentButtonPinState = digitalRead(buttonPin); if(CurrentButtonPinState != lastButtonPinState){ lastPressTime = millis(); } if( millis() - lastPressTime > PressDelayTime){ if(CurrentButtonPinState != buttonPinState){ buttonPinState = CurrentButtonPinState; if(buttonPinState == LOW){ //Command //Serial.println("fire!"); digitalWrite(triggerPin,!(digitalRead(triggerPin))); } } } lastButtonPinState = CurrentButtonPinState; //signal int CurrentSignalPinState = digitalRead(signalPin); if(CurrentSignalPinState != lastSignalPinState){ Time[indexTime] = millis(); ++indexTime; if ( indexTime > 9) { indexTime = 0; } } lastSignalPinState = CurrentSignalPinState; // if(Serial.available() > 0){ int readChar = Serial.read(); if(readChar == 'p'){ Serial.println("========================"); for(int i=0;i!=10;++i){ Serial.print(i,DEC); Serial.print(" "); Serial.println(Time[i],DEC); } } } }
a测试结果
设置曝光时间值 | 0.035毫秒 | 35毫秒 | 70毫秒 | 100毫秒 | ||||
记录跳变时间点 | Timer | T-Δ | Timer | T-Δ | Timer | T-Δ | Timer | T-Δ |
T1 | 8384 | 69 | 6538 | 103 | 3410 | 139 | 17078 | 169 |
T2 | 8453 | 6641 | 3549 | 17247 | ||||
T3 | 15754 | 68 | 14909 | 103 | 7177 | 138 | 25994 | 169 |
T4 | 15822 | 15012 | 7315 | 26163 | ||||
T5 | 18361 | 68 | 20587 | 103 | 10236 | 139 | 28321 | 169 |
T6 | 18429 | 20690 | 10375 | 28490 | ||||
T7 | 20577 | 68 | 25542 | 106 | 12707 | 139 | 30224 | 169 |
T8 | 20645 | 25648 | 12846 | 30393 |
b 结果解析
Basler 这个相机最小曝光时间只能设为 0.035 毫秒,最大为 1秒。从统计数据可以看出:
- 曝光时间设置70毫秒的总时间比设置35毫秒的总时间多了35毫秒,说明相机的曝光是按照设定时间进行曝光的
- 曝光时间设为0.035毫秒时,总时间居然为68毫秒,即获取上升沿状态34毫秒,下降沿为34毫秒。貌似不太合理。
三、后续测试
后续进行了数据的验证,没有错误,并且找到了多余68毫秒的来由。具体见《用 Saleae 逻辑分析仪来测量 Basler 相机曝光时间》
扩展阅读
- 用 Arduino 给 PC 上位机程序增加一个按钮输入
http://blog.davidrobot.com/2016/10/pc_io_arduino.html