Gymnast544
Member
I'm currently working on making a capture card for a DSi console and am currently working on the part where I get the input from the screen. The screen is an 18-bit display with a parallel RGB interface. I have to read the 18 bits with a window of .00016 ms multiple times in succession (for a total of ~60,000 readings per frame). Between frames I have about 4ms to send the frame data to a computer, but I'm not focusing on that part yet. I'm using a Teensy 4.1 board.
The timing pin I have is the DCLK pin. I have to read the 18 bits and store them somewhere every time the DCLK pin changes (during the frame, it changes every ~.00016 ms). I've calculated that I have ~100 clock cycles of the Teensy board when running it at 600 Mhz.
I was able to easily get 1 bit of the 18 working with all the timing, but when I added the digitalRead of 5 other bits, it wasn't able to keep up at 600 Mhz, and was somewhat able to keep up when overclocked at 816 Mhz (some pixels were missing, but most were there). Since I was able to get 1 bit of color working, I know that the hardware is correct.
Pin Descriptions:
GSP - When it falls it marks the start of a new frame
GCK - Marks the beginning/end of rows
DCLK - Pixel Clock - changes and iterates through pixels, row by row
R0-R5 - 6 of the 18 bits of color. These update each time DCLK changes.
I have been using FASTRUN and interrupts in order to solve this, though I could change to a loop which constantly checks waiting for the DCLK signal to change until the frame is over (the only things that change between frames are the 18 bits of color, all other pins repeat).
Please let me know if you have any advice. I'm using the Arduino IDE with Teensyduino, though I'm open to switching to another method - I just haven't figured out how to.
The timing pin I have is the DCLK pin. I have to read the 18 bits and store them somewhere every time the DCLK pin changes (during the frame, it changes every ~.00016 ms). I've calculated that I have ~100 clock cycles of the Teensy board when running it at 600 Mhz.
I was able to easily get 1 bit of the 18 working with all the timing, but when I added the digitalRead of 5 other bits, it wasn't able to keep up at 600 Mhz, and was somewhat able to keep up when overclocked at 816 Mhz (some pixels were missing, but most were there). Since I was able to get 1 bit of color working, I know that the hardware is correct.
Pin Descriptions:
GSP - When it falls it marks the start of a new frame
GCK - Marks the beginning/end of rows
DCLK - Pixel Clock - changes and iterates through pixels, row by row
R0-R5 - 6 of the 18 bits of color. These update each time DCLK changes.
I have been using FASTRUN and interrupts in order to solve this, though I could change to a loop which constantly checks waiting for the DCLK signal to change until the frame is over (the only things that change between frames are the 18 bits of color, all other pins repeat).
Please let me know if you have any advice. I'm using the Arduino IDE with Teensyduino, though I'm open to switching to another method - I just haven't figured out how to.
Code:
#include <SD.h>
File myFile;
const int chipSelect = BUILTIN_SDCARD;
volatile int state = 0;
#define DCLK 2//Pixel Clock
#define GCK 3//Essentially HSYNC
//SP__ are speaker pins
#define GSP 5//Essentially VSYNC
#define R0 23
#define R1 22
#define R2 21
#define R3 20
#define R4 19
#define R5 18
//GSP should be the same as SPS
volatile int numgck = 0;
volatile int numclk = 0;
FASTRUN volatile int filestream[100000];
volatile int currentindex = 0;
FASTRUN void gspinterrupt(){
if (state==0){
//This right here is just making sure it only reads one frame - for testing purposes
Serial.println("Started2");
state=1;
addfilestream(4);
}else{
Serial.println("Writing files");
detachInterrupt(GSP);
detachInterrupt(GCK);
detachInterrupt(DCLK);
Serial.println("Writing files");
for(int i=0;i<=currentindex;i++){
myFile.print(filestream[i]);
}
myFile.close();
Serial.println("File Closed");
while(1){
}
}
}
void gckrisinginterrupt(){
//This isn't relevant to the problem I'm having, I just have it write a "3" in the file so I know when the GCK pin changes
addfilestream(3);
}
FASTRUN void dclkinterrupt(){
addfilestream(digitalRead(R5));
//It was able to keep up with the screen before I added these digitalReads
digitalRead(R4);
digitalRead(R3);
digitalRead(R2);
digitalRead(R1);
digitalRead(R0);
}
FASTRUN void addfilestream(int toAdd){
filestream[currentindex]=toAdd;
currentindex++;
}
//Have just under 4 ms between frames
void setup() {
// put your setup code here, to run once:
pinMode(DCLK, INPUT);
pinMode(GCK, INPUT);
pinMode(GSP, INPUT);
pinMode(R0, INPUT);
pinMode(R1, INPUT);
pinMode(R2, INPUT);
pinMode(R3, INPUT);
pinMode(R4, INPUT);
pinMode(R5, INPUT);
for(int i=0;i>100000;i++){
filestream[i] = 6;
}
Serial.begin(115200);
while (!Serial) {
}
SD.begin(chipSelect);
myFile = SD.open("tost.txt", FILE_WRITE);
attachInterrupt(GSP, gspinterrupt, FALLING);
attachInterrupt(GCK, gckrisinginterrupt, RISING);
attachInterrupt(DCLK, dclkinterrupt, CHANGE);
}
void loop(){
}