debug

Fork of PololuLedStripx by Michael Koster

Revision:
8:1578776ceac5
Parent:
7:9a088f042ee0
Child:
9:6ffb85d69eaf
--- a/PololuLedStrip.cpp	Fri Mar 01 01:16:48 2013 +0000
+++ b/PololuLedStrip.cpp	Fri Mar 01 02:05:21 2013 +0000
@@ -6,20 +6,30 @@
 
 void PololuLedStrip::calculateDelays()
 {
-    int fmhz = SystemCoreClock / 1000000;
-    led_strip_write_delays[0] = 700*fmhz/1000 - 25;
-    led_strip_write_delays[1] = 600*fmhz/1000 - 19;
-    led_strip_write_delays[2] = 1200*fmhz/1000 - 24;
+    // Get the clock frequency in MHz.
+    int f_mhz = SystemCoreClock / 1000000;
+    
+    // Arrange for a 700 nanosecond delay between the rise time and the fall time for a 0 bit.
+    led_strip_write_delays[0] = 700*f_mhz/1000 - 25;
+    
+    // Arrange for a 600 nanosecond delay between the fall time for a 0 bit and the fall time for a 1 bit.
+    // This means the pulses representing a 1 will be 700+600 = 1300 nanoseconds.
+    led_strip_write_delays[1] = 600*f_mhz/1000 - 19;
+    
+    // Arrange for a 1200 nanosecond delay between the fall time for a 1 bit and rise time of the next bit.
+    // This means the period of the signal will be 2500 nanoseconds.
+    led_strip_write_delays[2] = 1200*f_mhz/1000 - 24;
 }
 
 PololuLedStrip::PololuLedStrip(PinName pinName)
 {
     gpio_init(&gpio, pinName, PIN_OUTPUT);
-    calculateDelays();    // Assumption
 }
 
 void PololuLedStrip::write(rgb_color * colors, unsigned int count)
 {
+    calculateDelays();
+
     __disable_irq();   // Disable interrupts temporarily because we don't want our pulse timing to be messed up.
 
     while(count--)