From a833fb48f06c0c6c2e2627335507fdd47bd2ff8e Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 30 Aug 2019 14:03:02 -0700 Subject: [PATCH] Account For Loop Instruction Cycles (#287) --- src/internal/NeoPixelEsp.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/internal/NeoPixelEsp.c b/src/internal/NeoPixelEsp.c index f28a575..0837073 100644 --- a/src/internal/NeoPixelEsp.c +++ b/src/internal/NeoPixelEsp.c @@ -45,12 +45,13 @@ static inline uint32_t _getCycleCount(void) return ccount; } -#define CYCLES_800_T0H (F_CPU / 2500000) // 0.4us -#define CYCLES_800_T1H (F_CPU / 1250000) // 0.8us -#define CYCLES_800 (F_CPU / 800000) // 1.25us per bit -#define CYCLES_400_T0H (F_CPU / 2000000) -#define CYCLES_400_T1H (F_CPU / 833333) -#define CYCLES_400 (F_CPU / 400000) +#define CYCLES_LOOPTEST (4) // adjustment due to loop exit test instruction cycles +#define CYCLES_800_T0H (F_CPU / 2500000 - CYCLES_LOOPTEST) // 0.4us +#define CYCLES_800_T1H (F_CPU / 1250000 - CYCLES_LOOPTEST) // 0.8us +#define CYCLES_800 (F_CPU / 800000 - CYCLES_LOOPTEST) // 1.25us per bit +#define CYCLES_400_T0H (F_CPU / 2000000 - CYCLES_LOOPTEST) +#define CYCLES_400_T1H (F_CPU / 833333 - CYCLES_LOOPTEST) +#define CYCLES_400 (F_CPU / 400000 - CYCLES_LOOPTEST) void ICACHE_RAM_ATTR bitbang_send_pixels_800(uint8_t* pixels, uint8_t* end, uint8_t pin) {