trouble with Arduino speed

hi everyone, this is my first post so be gentle, also i am sorry if this is in the wrong place, i am not sure if it is a hardware or software problem.

anyway i have a device with a 4mhz crystal, at the moment i am just trying to read the data going to the LCD (4 bit data high or low, nothing complex) and then pass it straight back out to the LCD, i am using the clock signal for the LCD to trigger an interupt on the arduino and all it does is this:

void clockCounter() {  
  digitalWrite(d1outPin, digitalRead(d1inPin));
  digitalWrite(d0outPin, digitalRead(d0inPin));


this is all the arduino is doing at the moment, there is nothing in the void loop, it is just reading the data and passing it back out, but the arduino (nano 5v AT328) doesn't seem to be able to keep up,

surely it should be fast enough considering it is 4 times faster than the LCD?

any help would be great

thanks everyone

by the way i forgot to put, i am pretty sure it is a speed issue because if i just put my code in the void loop the screen is just fuzz, but if i use the interrupt then it is stable, but still out of time and not displaying correctly

You might want to use port read/write, rather than pin read/writes; your pin levels could change between, otherwise.

i have a device with a 4mhz crystal

I can only assume you mean "MHz", otherwise, there's your answer ;D

thanks guys, how do i use PortRead?

yea i ment Mhz lol,

Kind of depends how often said device is sending this 4 bits of data, if its being send at 4Mhz (4 million times a second) I can't see an arduino coping with that no matter how slick the coding.

ok, but if it is just the two lines of code that i posted above, nothing else, and the arduino CPU is running at 16Mhz, surely it should be able to work with that? or is there a bottle neck somewhere?

nothing else

What about the call to the code above? What about "loop ()"?

int clockPin =  2;
int d1inPin =  4;
int d0inPin =  3;
int d1outPin =  12;
int d0outPin =  11;

void setup()   {                

  pinMode(d1outPin, OUTPUT); 
  pinMode(d0outPin, OUTPUT);
  pinMode(d1inPin, INPUT); 
  pinMode(d0inPin, INPUT); 
  pinMode(clockPin, INPUT); 
  attachInterrupt(0, clockCounter, FALLING);

void loop()                     

void clockCounter() {

  digitalWrite(d1outPin, digitalRead(d1inPin));
  digitalWrite(d0outPin, digitalRead(d0inPin));

ok this is all the code

Being able to cope would imply that calling an interrupt, reading 2 digital pins, writing 2 digital pins and returning can be achieved in 4 clock cycles. Not a hope. I'm no expert in Atmega chip programming, but I'd be surprised if it could do that inside 20 clock cycles even in low level assembly never mind compiled C.

Ya got a point there, pluggy; I keep forgetting to think like this - I haven't had to do it since I was writing mode 13h rasterizers in 80x86 assembler, which was a long time ago.

NeX, heed pluggy's wisdom - you likely haven't a chance at being successful with a standard Arduino; it isn't fast enough (hmm, maybe you might want to try overclocking it? Just kidding...or am I?)...


ok thanks for the help guys, i think i might need to try using the arduino to edit the data in the graphics buffer instead, but at least i know what the arduino limits are now,

thanks again!