Timing issues ?


hello

im using following function lets me shift our 64bits of data:

code: [select]
void setoutputs(unsigned long val_one, unsigned long val_two) { //function shift out 2 x 32bit fast enough prevent flicker!

  // ------------warning!--------------------
  // functions operates directly on ports, not via digitalwrite()
  // because digitalwrite() slow, , display flicker
  // if different pins used, maybe hav change variable "theport"
  // matching i/o port letter of controller!
 
  serial.print("start:");
  serial.print(millis());
 
 
  digitalwrite(oe, low); //disable outputs prevent flicker

  //send first 32-bit variable value

  ( int = 0; < 32; i++) {
    theport &= ~_bv(data);  //data low
    if ( bitread(val_one, i) == 1) {
      theport |= _bv(data);  //data high
    }
    theport |= _bv(clk);  //clk high
    theport &= ~_bv(clk); //clk low
  }

  //send second 32-bit variable value
  ( int = 0; < 32; i++) {
    theport &= ~_bv(data);  //data low
    if ( bitread(val_two, i) == 1) {
      theport |= _bv(data);  //data high
    }
    theport |= _bv(clk);  //clk high
    theport &= ~_bv(clk); //clk low
  }
  digitalwrite(oe, high); //enable outputs


    serial.print("end:");
  serial.print(millis());
}



in normal conditions, start , end time differs in around 1ms. in cases differs in 20ms, cause major flicker on outputs.

i think be, because other parts of code take longer or interrupting function.

is there way find out causes slowdown?
is there way code function in way cant interrupted anything?


thanks

you make critical code isr , use software interrupt execute it.


Arduino Forum > Using Arduino > Programming Questions > Timing issues ?


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor