Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielgarcia@gmail.com <danielgarcia@gmail.com@4ad4ec5c-605d-bd5c-5796-512c9b60011b>2013-02-18 14:59:19 +0400
committerdanielgarcia@gmail.com <danielgarcia@gmail.com@4ad4ec5c-605d-bd5c-5796-512c9b60011b>2013-02-18 14:59:19 +0400
commit6fbfd3f17e67dcb8164486b6c06985a3a3cc0732 (patch)
treec7ea54e34fea21eac0321bf1e92e1d043f5ba509
parent5555154f3ae88082deb071f0e36a4c2c39d85d98 (diff)
Some timing adjustments for ws2811 - account for the fact that teensy 3 at 96Mhz appears to really be 48Mhz
-rw-r--r--FastSPI_LED2.h4
-rw-r--r--clockless.h25
-rw-r--r--examples/Fast2Dev/Fast2Dev.ino8
3 files changed, 21 insertions, 16 deletions
diff --git a/FastSPI_LED2.h b/FastSPI_LED2.h
index 015dc6b8..f9e6781d 100644
--- a/FastSPI_LED2.h
+++ b/FastSPI_LED2.h
@@ -95,8 +95,8 @@ class TM1809Controller800Mhz : public ClocklessController<DATA_PIN, NS(350), NS(
// 350n, 350ns, 550ns
template <uint8_t DATA_PIN>
-class WS2811Controller800Mhz : public ClocklessController<DATA_PIN, NS(350), NS(350), NS(550)> {};
-#if NO_TIME(350, 350, 550)
+class WS2811Controller800Mhz : public ClocklessController<DATA_PIN, NS(320), NS(320), NS(550)> {};
+#if NO_TIME(320, 320, 550)
#pragma message "No enough clock cycles available for the UCS103"
#endif
diff --git a/clockless.h b/clockless.h
index 53a7760c..8f665044 100644
--- a/clockless.h
+++ b/clockless.h
@@ -5,7 +5,12 @@
#include <avr/interrupt.h> // for cli/se definitions
// Macro to convert from nano-seconds to clocks
-#define NS(_NS) (_NS / (1000 / (F_CPU / 1000000L)))
+// #define NS(_NS) (_NS / (1000 / (F_CPU / 1000000L)))
+#if F_CPU < 96000000
+#define NS(_NS) ( (_NS * (F_CPU / 1000000L))) / 1000
+#else
+#define NS(_NS) ( (_NS * (F_CPU / 2000000L))) / 1000
+#endif
// Macro for making sure there's enough time available
#define NO_TIME(A, B, C) (NS(A) < 3 || NS(B) < 2 || NS(C) < 6)
@@ -79,30 +84,30 @@ public:
#if defined(__MK20DX128__)
register uint32_t b = *data++;
- while(data != end) {
+ while(data <= end) {
for(register uint32_t i = 7; i > 0; i--) {
Pin<DATA_PIN>::fastset(port, hi);
- delaycycles<1 + T1 - 4>(); // 4 cycles - 2 store, 1 test, 1 if
+ delaycycles<T1 - 3>(); // 4 cycles - 1 store, 1 test, 1 if
if(b & 0x80) { Pin<DATA_PIN>::fastset(port, hi); } else { Pin<DATA_PIN>::fastset(port, lo); }
b <<= 1;
- delaycycles<1 + T2 - 5>(); // 5 cycles, 2 store, 2 store/skip, 1 shift
+ delaycycles<T2 - 3>(); // 3 cycles, 1 store, 1 store/skip, 1 shift
Pin<DATA_PIN>::fastset(port, lo);
- delaycycles<1 + T3 - 5>(); // 5 cycles, 2 store, 1 sub, 2 branch backwards
+ delaycycles<T3 - 3>(); // 3 cycles, 1 store, 1 sub, 1 branch backwards
}
// extra delay because branch is faster falling through
delaycycles<1>();
// 8th bit, interleave loading rest of data
Pin<DATA_PIN>::fastset(port, hi);
- delaycycles<1 + T1 - 4>();
+ delaycycles<T1 - 3>();
if(b & 0x80) { Pin<DATA_PIN>::fastset(port, hi); } else { Pin<DATA_PIN>::fastset(port, lo); }
- delaycycles<1 + T2 - 4>(); // 4 cycles, 2 store, store/skip
+ delaycycles<T2 - 2>(); // 4 cycles, 2 store, store/skip
Pin<DATA_PIN>::fastset(port, lo);
b = *data++;
- delaycycles<1 + T3 - 8>(); // 2 store, 2 load, 1 cmp, 2 branch backwards, 1 movim
- }
+ delaycycles<T3 - 6>(); // 1 store, 2 load, 1 cmp, 1 branch backwards, 1 movim
+ };
#else
- while(data != end) {
+ while(data <= end) {
register uint8_t b = *data++;
bitSetFast<7>(port, hi, lo, b);
bitSetFast<6>(port, hi, lo, b);
diff --git a/examples/Fast2Dev/Fast2Dev.ino b/examples/Fast2Dev/Fast2Dev.ino
index 7038858e..7a976c08 100644
--- a/examples/Fast2Dev/Fast2Dev.ino
+++ b/examples/Fast2Dev/Fast2Dev.ino
@@ -31,7 +31,7 @@
// #include <FastSPI_LED2.h>
#define NUM_LEDS 86
-struct CRGB { byte r; byte g; byte b; };
+struct CRGB { byte g; byte r; byte b; };
struct CRGB leds[NUM_LEDS];
@@ -67,8 +67,8 @@ struct CRGB leds[NUM_LEDS];
// TM1809Controller800Mhz<6> LED;
// UCS1903Controller400Mhz<7> LED;
-// WS2811Controller800Mhz<12> LED;
-WS2811Controller800Mhz<5> LED;
+WS2811Controller800Mhz<12> LED;
+// WS2811Controller800Mhz<5> LED;
// TM1803Controller400Mhz<5> LED;
// struct aLED { void init() { FastSPI_LED.setLeds(NUM_LEDS, (unsigned char*)leds); FastSPI_LED.setPin(8); FastSPI_LED.setChipset(CFastSPI_LED::SPI_LPD8806); FastSPI_LED.init(); FastSPI_LED.start();}; void showRGB(byte *, int) { FastSPI_LED.show();} } LED;
@@ -118,7 +118,7 @@ void setup() {
void loop() {
#if 0
- memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
+ memset(leds, 255, NUM_LEDS * sizeof(struct CRGB));
LED.showRGB((byte*)leds, NUM_LEDS);
delay(20);
#else