TCD1201D 를 이용한 아두이노
C코드
/*
Linear CCD readout
lCCD: Toshiba TCD 1201D, 2048 pixel
Pinmap: 22 DIL
Chip Arduino Pin
1 : OS (Output Signal) A0
2 : DOS (Compensation Output) A1
3 : OD (Power +5V) +5V
4 : RS (Reset Gate) 6
5 : BT (Boost Pulse) 7
6 : P2 (clock Phase 2) 5
19 : P1 (clock Phase 1) 4
21 : SH (Shift Gate) 3
all other pins connected to GND GND
*/
#define OS_PIN A0
#define DOS_PIN A1
#define SH_PIN 3
#define P1_PIN 4
#define P2_PIN 5
#define RS_PIN 6
#define BT_PIN 7
int bt_time = 50; // length of boost
int rs_time = 50; // length of reset
int p1_time = 1; // length of P1
int p2_time = 1; // length of P2
int sf_time = 1; // shift between BT and RS
int sadc[256]; // signal output values read
int sdummy1[32];
int sdummy2[14];
void setup() {
Serial.begin(9600);
Serial.println("Setup start");
for (int i=3;i<8;i++) pinMode(i,OUTPUT);
pinMode(OS_PIN,INPUT);
pinMode(DOS_PIN,INPUT);
// take all to LOW
PORTD = B00000000;
Serial.println("Setup Complete");
}
void loop() {
// do nothing - all done via SerialEvent
Serial.println("start loop");
readCCD();
delay(5000);
}
void readCCD() {
int dos = 300;
int dwt = 1;
int j;
int val;
for (int i=0; i<256;i++) sadc[i]=0;
// start read cycle
Serial.println("Start read cycle");
// take all to LOW
PORTD = B00000000;
delay(1);
// set inital state
// BRPPSxxx
// TS21H
PORTD = B10011000;
delay(1);
// take BT low
// TS21H
PORTD = B00011000;
delayMicroseconds(bt_time);
// take RS high
// TS21H
PORTD = B01011000;
delayMicroseconds(rs_time);
// take BT high
// TS21H
PORTD = B11011000;
delayMicroseconds(bt_time);
// take RS low
// TS21H
PORTD = B10011000;
delayMicroseconds(rs_time);
//
Serial.println("read dummy output");
// take gate to low
// TS21H
PORTD = B10010000;
for (int i=0; i<16;i++){
// read cylce part 1 (p1=high,p2=low)
// wait integration time
delayMicroseconds(dos);
sdummy1[i*2] = analogRead(DOS_PIN) - analogRead(OS_PIN);
// p1 high - BT/RS cycle (4 steps)
PORTD = B00010000;
delayMicroseconds(bt_time);
PORTD = B01010000;
delayMicroseconds(rs_time);
PORTD = B11010000;
delayMicroseconds(bt_time);
PORTD = B10010000;
delayMicroseconds(rs_time);
// switch P1/P2 state
PORTD = B10110000;
PORTD = B10100000;
// PORTD = B10110000; // take p2 high
// delayMicroseconds(p2_time);
// PORTD = B10100000; // take p1 low
// read cylce part 2 (p1=low,p2=high)
// wait integration time
delayMicroseconds(dos);
sdummy1[i*2+1] = analogRead(DOS_PIN) - analogRead(OS_PIN);
// p1 low - BT/RS cycle (4 steps)
PORTD = B00100000;
delayMicroseconds(bt_time);
PORTD = B01100000;
delayMicroseconds(rs_time);
PORTD = B11100000;
delayMicroseconds(bt_time);
PORTD = B10100000;
delayMicroseconds(rs_time);
// switch P1/P2 state
PORTD = B10110000;
PORTD = B10010000;
// PORTD = B10000000; // take p2 low
// delayMicroseconds(p2_time);
// PORTD = B10010000; // take p1 high
}
for (int i=0; i<32;i++){
Serial.print(sdummy1[i]);
Serial.print(" ");
}
Serial.println();
Serial.println("read sensor output");
for (int i=0; i<1024;i++){
j = i / 4;
// read cylce part 1 (p1=high,p2=low)
// wait integration time
delayMicroseconds(dos);
sadc[j] += analogRead(DOS_PIN) - analogRead(OS_PIN);
// p1 high - BT/RS cycle (4 steps)
PORTD = B00010000;
delayMicroseconds(bt_time);
PORTD = B01010000;
delayMicroseconds(rs_time);
PORTD = B11010000;
delayMicroseconds(bt_time);
PORTD = B10010000;
delayMicroseconds(rs_time);
// switch P1/P2 state
PORTD = B10110000;
PORTD = B10100000;
// PORTD = B10110000; // take p2 high
// delayMicroseconds(p2_time);
// PORTD = B10100000; // take p1 low
// read cylce part 2 (p1=low,p2=high)
// wait integration time
delayMicroseconds(dos);
sadc[j] += analogRead(DOS_PIN) - analogRead(OS_PIN);
// p1 low - BT/RS cycle (4 steps)
PORTD = B00100000;
delayMicroseconds(bt_time);
PORTD = B01100000;
delayMicroseconds(rs_time);
PORTD = B11100000;
delayMicroseconds(bt_time);
PORTD = B10100000;
delayMicroseconds(rs_time);
// switch P1/P2 state
PORTD = B10110000;
PORTD = B10010000;
// PORTD = B10000000; // take p2 low
// delayMicroseconds(p2_time);
// PORTD = B10010000; // take p1 high
}
for (int i=0; i<256;i++){
sadc[i] /= 8;
Serial.print(sadc[i]);
Serial.print(" ");
if ((i%16)==0) Serial.println();
}
Serial.println();
Serial.println("read second dummy output");
for (int i=0; i<7;i++){
// read cylce part 1 (p1=high,p2=low)
// wait integration time
delayMicroseconds(dos);
sdummy2[i*2] = analogRead(DOS_PIN) - analogRead(OS_PIN);
// p1 high - BT/RS cycle (4 steps)
PORTD = B00010000;
delayMicroseconds(bt_time);
PORTD = B01010000;
delayMicroseconds(rs_time);
PORTD = B11010000;
delayMicroseconds(bt_time);
PORTD = B10010000;
delayMicroseconds(rs_time);
// switch P1/P2 state
PORTD = B10110000;
PORTD = B10100000;
// PORTD = B10110000; // take p2 high
// delayMicroseconds(p2_time);
// PORTD = B10100000; // take p1 low
// read cylce part 2 (p1=low,p2=high)
// wait integration time
delayMicroseconds(dos);
sdummy2[i*2+1] = analogRead(DOS_PIN) - analogRead(OS_PIN);
// p1 low - BT/RS cycle (4 steps)
PORTD = B00100000;
delayMicroseconds(bt_time);
PORTD = B01100000;
delayMicroseconds(rs_time);
PORTD = B11100000;
delayMicroseconds(bt_time);
PORTD = B10100000;
delayMicroseconds(rs_time);
// switch P1/P2 state
PORTD = B10110000;
PORTD = B10010000;
// PORTD = B10000000; // take p2 low
// delayMicroseconds(p2_time);
// PORTD = B10010000; // take p1 high
}
for (int i=0; i<14;i++){
Serial.print(sdummy1[i]);
Serial.print(" ");
}
Serial.println();
Serial.println("read cycle complete");
}
PDF 센서 :
TCD1209DG 정보 (0) | 2022.04.01 |
---|---|
아두이노 Linear CCD project (0) | 2022.04.01 |
TCD1304AP + 아두이노 자료 (0) | 2022.04.01 |
[비] TCD1201D Code (0) | 2022.04.01 |
[비] FCCD 143A PDF 관련 자료 모음 (2) | 2022.04.01 |