Commits

Anonymous committed 7004de6

1K & 10K working

Comments (0)

Files changed (4)

 }
 void fio_shiftOut1(fio_register shift1Register, fio_bit shift1Bit, uint8_t value, boolean noLatch)
 {
-	/*
-	 * this function are based on Shif1 protocol developed by Roman Black (http://www.romanblack.com/shift1.htm)
-	 *
-	 * test sketches:
-	 * 	http://pastebin.com/raw.php?i=2hnC9v2Z
-	 * 	http://pastebin.com/raw.php?i=bGg4DhXQ
-	 * 	http://pastebin.com/raw.php?i=tg1ZFiM5
-	 *    http://pastebin.com/raw.php?i=93ExPDD3 - cascading
-	 * tested with:
-	 * 	TPIC6595N - seems to work fine (circuit: http://www.3guys1laser.com/
-    *                   arduino-one-wire-shift-register-prototype)
-	 * 	7HC595N
-	 */
 	// disable interrupts since timing is going to be critical
 	uint8_t oldSREG;
 	oldSREG = SREG;
       {
 			// LOW = 0 Bit
 			fio_digitalWrite_SWITCHTO(shift1Register,shift1Bit,LOW);
-			// hold pin LOW for 15us
-			delayMicroseconds(15);
+			// hold pin LOW for ... (was 15us)
+			delayMicroseconds(10);
 			fio_digitalWrite_SWITCHTO(shift1Register,shift1Bit,HIGH);
-			// hold pin HIGH for 30us
-			delayMicroseconds(30);
+			// hold pin HIGH for ... (was 30us)
+			delayMicroseconds(20);
 		}
       else
       {
 			fio_digitalWrite_SWITCHTO(shift1Register,shift1Bit,LOW);
 			//hold pin LOW for 1us - done! :)
 			fio_digitalWrite_SWITCHTO(shift1Register,shift1Bit,HIGH);
-			//hold pin HIGH for 15us
-			delayMicroseconds(15);
+			//hold pin HIGH for ... (was 15us)
+			delayMicroseconds(10);
 		}
 		if(!noLatch && i==1)
       {
    {
 		// send last bit (=LOW) and Latch command
 		fio_digitalWrite_SWITCHTO(shift1Register,shift1Bit,LOW);
-		// Hold pin low for 200us
-		delayMicroseconds(210);
+		// Hold pin low for ... (was 200us)
+		delayMicroseconds(96);
 		fio_digitalWrite_HIGH(shift1Register,shift1Bit);
-		// Hold pin high for 300us and leave it that way - using explicit HIGH here, just in case.
-		delayMicroseconds(300);
+		// Hold pin high for ... (was 300us) and leave it that way - using explicit HIGH here, just in case.
+		delayMicroseconds(137);
 	}
 
 	// enable interrupts
 {
 	fio_shiftOut1(fio_pinToOutputRegister(pin, SKIP),fio_pinToBit(pin),value, noLatch);
 }
+
+void fio_shiftOut1_rb(fio_register shift1Register, fio_bit shift1Bit, uint8_t value, boolean noLatch)
+{
+   /*
+    * this function are based on Shif1 protocol developed by Roman Black (http://www.romanblack.com/shift1.htm)
+    *
+    * test sketches:
+    *    http://pastebin.com/raw.php?i=2hnC9v2Z
+    *    http://pastebin.com/raw.php?i=bGg4DhXQ
+    *    http://pastebin.com/raw.php?i=tg1ZFiM5
+    *    http://pastebin.com/raw.php?i=93ExPDD3 - cascading
+    * tested with:
+    *    TPIC6595N - seems to work fine (circuit: http://www.3guys1laser.com/
+    *                   arduino-one-wire-shift-register-prototype)
+    *    7HC595N
+    */
+   // disable interrupts since timing is going to be critical
+   uint8_t oldSREG;
+   oldSREG = SREG;
+   cli();
+
+   // iterate but ignore last bit (is it correct now?)
+   for(int8_t i = 7; i>=0; --i)
+   {
+
+      // assume that pin is HIGH (smokin' pot all day... :) - requires initialization
+      if(LOW==!!(value & (1 << i)))
+      {
+         // LOW = 0 Bit
+         fio_digitalWrite_SWITCHTO(shift1Register,shift1Bit,LOW);
+         // hold pin LOW for 15us
+         delayMicroseconds(15);
+         fio_digitalWrite_SWITCHTO(shift1Register,shift1Bit,HIGH);
+         // hold pin HIGH for 30us
+         delayMicroseconds(30);
+      }
+      else
+      {
+         // HIGH = 1 Bit
+         fio_digitalWrite_SWITCHTO(shift1Register,shift1Bit,LOW);
+         //hold pin LOW for 1us - done! :)
+         fio_digitalWrite_SWITCHTO(shift1Register,shift1Bit,HIGH);
+         //hold pin HIGH for 15us
+         delayMicroseconds(15);
+      }
+      if(!noLatch && i==1)
+      {
+         break;
+      }
+   }
+
+   if(!noLatch)
+   {
+      // send last bit (=LOW) and Latch command
+      fio_digitalWrite_SWITCHTO(shift1Register,shift1Bit,LOW);
+      // Hold pin low for 200us
+      delayMicroseconds(210);
+      fio_digitalWrite_HIGH(shift1Register,shift1Bit);
+      // Hold pin high for 300us and leave it that way - using explicit HIGH here, just in case.
+      delayMicroseconds(300);
+   }
+
+   // enable interrupts
+   SREG = oldSREG;
+}
  */
 void fio_shiftOut1_init(uint8_t pin);
 
+/*!
+ * @method
+ * @abstract one wire shift out - exact implementation of Roman Black's protocol
+ * @discussion protocol needs initialisation (fio_shiftOut1_init)
+ * @param shift1Register[in] pins register
+ * @param shift1Bit[in] pins bit
+ * @param value[in] value to shift out, last byte is ignored and always shifted out LOW
+ */
+void fio_shiftOut1_rb(fio_register shift1Register, fio_bit shift1Bit, uint8_t value, boolean noLatch = false);
+
 #endif // FAST_IO_H

LiquidCrystal_SR1.cpp

    //trying to be compatible to Roman Black's circuit - not working, but why?
    val = mode | (value /* & 0xF0 */);// upper nibble
    val |= SR_UNUSED_BITS;// unused outputs to high (faster)
-   shiftIt(val,SR_SREN_BIT);
+   shiftIt_rb(val,SR_SREN_BIT);
 
    val = mode | SR_SREN_BIT | ((value << 4) /* & 0xF0 */);// lower nibble
    val |= SR_UNUSED_BITS;// unused outputs to high (faster)
-   shiftIt(val,SR_SREN_BIT);
-#else
+   shiftIt_rb(val,SR_SREN_BIT);
+#endif
    //using different outputs on the shift register seems to make it work...
    val = mode | ((value >> 1) /* & 0x78 */); // upper nibble
    val |= SR_UNUSED_BITS; // unused outputs to high (faster)
    val = mode | ((value << 3) /* & 0x78 */); // lower nibble
    val |= SR_UNUSED_BITS; // unused outputs to high (faster)
    shiftIt(val, SR_EN_BIT);
-#endif
-
 }
 // PRIVATE METHODS
 // ---------------------------------------------------------------------------

examples/performanceLCD/performanceLCD.ino

          Serial.println (i);
    }
    
+   float fAllWrites=0;
+   
    for ( i = 0; i < NUM_BENCHMARKS; i++ )
    {   
       Serial.print ( F("benchmark") );
       Serial.print ( F(" write: ") );
       Serial.print ( myBenchMarks[i].benchTime / myBenchMarks[i].numWrites );
       Serial.println ( F(" us") ); 
-      
+      fAllWrites += myBenchMarks[i].benchTime / (float)myBenchMarks[i].numWrites;
    }
-}
-
+   Serial.print( F("avg. write: ") );
+   Serial.println( fAllWrites / (float)NUM_BENCHMARKS );
+ }