nucleo version

Fork of PololuLedStrip by David Grayson

Files at this revision

API Documentation at this revision

Comitter:
DavidEGrayson
Date:
Wed Oct 09 01:13:49 2013 +0000
Parent:
18:34ba573573df
Child:
20:656bbcb64e3b
Commit message:
Changed the timing so that this library only supports the high-speed strips now.

Changed in this revision

PololuLedStrip.cpp Show annotated file Show diff for this revision Revisions of this file
PololuLedStrip.h Show annotated file Show diff for this revision Revisions of this file
led_strip_write_color.s Show annotated file Show diff for this revision Revisions of this file
--- a/PololuLedStrip.cpp	Fri Mar 01 05:17:02 2013 +0000
+++ b/PololuLedStrip.cpp	Wed Oct 09 01:13:49 2013 +0000
@@ -2,8 +2,8 @@
 
 bool PololuLedStrip::interruptFriendly = false;
 
-// The three timed delays, in units of half-cycles.
-uint8_t led_strip_write_delays[3];
+// The two timed delays, in units of half-cycles.
+uint8_t led_strip_write_delays[2];
 
 void PololuLedStrip::calculateDelays()
 {
@@ -11,28 +11,26 @@
 
     if (f_mhz <= 48)
     {
-        // The delays below result in 800/1590 ns pulses and a 2500 ns period on the mbed NXP LPC11U24.        
+        // The delays below result in 360/1120 ns pulses and a 1880 ns period on the mbed NXP LPC11U24.        
         led_strip_write_delays[0] = 0;
         led_strip_write_delays[1] = 0;
-        led_strip_write_delays[2] = 5;
     }
     else
     {
         // Try to generally compute what the delays should be for a ide range of clock frequencies.
         
         // The fudge factors below were experimentally chosen so that we would have
-        // ~700/1300 ns pulses and a ~2500 ns period on the mbed NXP LPC1768 (96 MHz Cortex-M3).
+        // ~100/840 ns pulses and a ~1430 ns period on the mbed NXP LPC1768 (96 MHz Cortex-M3).
         // There seem to be some ~100 ns inconsistencies in the timing depending on which example program is
         // running; the most likely explanation is some kind of flash caching that affects the timing.
         // If you ever change these numbers, it is important to check the the subtractions below
-        // will not overflow in the worst case, which is f_mhz = 49.
-        led_strip_write_delays[0] = 700*f_mhz/1000 - 23;
-        led_strip_write_delays[1] = 600*f_mhz/1000 - 18;
-        led_strip_write_delays[2] = 1200*f_mhz/1000 - 33;    
+        // will not overflow in the worst case (smallest possible f_mhz).
+        led_strip_write_delays[0] = 750*f_mhz/1000 - 33;
+        led_strip_write_delays[1] = 550*f_mhz/1000 - 20;    
     }
  
     // Convert from units of cycles to units of half-cycles; it makes the assembly faster.   
-    for(int i = 0; i < 3; i++)
+    for(int i = 0; i < 2; i++)
     {
         led_strip_write_delays[i] <<= 1;
     }
--- a/PololuLedStrip.h	Fri Mar 01 05:17:02 2013 +0000
+++ b/PololuLedStrip.h	Wed Oct 09 01:13:49 2013 +0000
@@ -45,7 +45,7 @@
         To update all the LEDs in the LED strip, count should be equal to or greater than the number of LEDs in the strip.
         If count is less than the number of LEDs in the strip, then some LEDs near the end of the strip will not be updated.
         
-        The colors are sent in series and each color takes about 60 microseconds to send.
+        The colors are sent in series and each color takes about 45 microseconds to send.
         This function disables interrupts temporarily while it is running.
         This function waits for over 10 us at the end before returning to allow the colors to take effect.
         */
--- a/led_strip_write_color.s	Fri Mar 01 05:17:02 2013 +0000
+++ b/led_strip_write_color.s	Wed Oct 09 01:13:49 2013 +0000
@@ -49,29 +49,36 @@
 send_led_strip_bit
     str r3, [r1]       ; Drive the line high.
     
-    delay #0
+    ; It doesn't really matter exactly how long we delay here as long as it is
+    ; less than 540 microseconds.
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
     
     ldr r4, =0x80000000
     tst r6, r4
-    bne delay1
+    bne delay0
     str r3, [r2]       ; If the bit to send it 0, drive the line low.
-delay1
+delay0
 
-    delay #1
+    delay #0
 
     ldr r4, =0x80000000
     tst r6, r4
-    beq delay2
+    beq delay1
     str r3, [r2]       ; If the bit to send is 1, drive the line low.
-delay2
+delay1
     
-    delay #2
+    delay #1
     
     lsls r6, r6, #1           ; Shift color bits.
     subs r7, r7, #1           ; Decrement the loop counter.
     bne send_led_strip_bit    ; Send another bit if we have not reached zero.   
     pop {r4, r5, r6, r7, pc}  ; Otherwise, restore the registers and return.
-    
+    bx lr;
 
 delay_region
     ; The following is 128 nops.