Difference: NeoPixel (1 vs. 12)

Revision 122022-10-10 - PeterSchmid

Line: 1 to 1
 
META TOPICPARENT name="MecrispCubeF405"
%DASHBOARD{ section="banner"
Line: 33 to 33
 
  • flashing red: file write operation
  • flashing yellow: file read operation
Changed:
<
<
For the STM32WB Nucleo Board I use D6 for the Neopixel
>
>
For the STM32WB Nucleo Board I use D6 for the Neopixel. It takes about 30 us to set one Neopixel, during this time the interrupts are disabled.
 
3 6 dmod           \ D6 output

Line: 59 to 59
 pixels 32 neopixels
Added:
>
>
It takes about 30 us to set one Neopixel, for 32 Pixels it takes nearly 1 ms, during this time the interrupts are disabled. Consider this for RT programs and interrupt latency.
 
Added:
>
>
 

Implementation

Revision 112022-03-03 - PeterSchmid

Line: 1 to 1
 
META TOPICPARENT name="MecrispCubeF405"
%DASHBOARD{ section="banner"
Changed:
<
<
image="/twiki/pub/Cosmac/ForthSTM32WB/nucleo-header.jpg"
>
>
image="%PU<blockquoteBURLPATH%/Cosmac/ForthSTM32WB/nucleo-header.jpg"
  title="Neopixel" titlestyle="color:#F00000;" }%
Changed:
<
<
Intro
>
>
Intro
https://en.wikipedia.org/wiki/Adafruit_Industries#NeoPixel
NeoPixel is Adafruit's brand of individually addressable red-green-blue (RGB) LED. They are based on the WS2812 LED and WS2811 driver, where the WS2811 is integrated into the LED, for reduced footprint. Adafruit manufactures several products with NeoPixels with form factors such as strips, rings, matrices, Arduino shields, traditional five-millimeter cylinder LED and individual NeoPixel with or without a PCB. The control protocol for NeoPixels is based on only one communication wire.
 
Changed:
<
<
Contents
>
>
Contents
 

How To Use

Changed:
<
<

Single Pixel

>
>

Single Pixel

  The Adafruit Feather STM32F405 Board has its own Neopixel (GPIO PC0, D8) :

Line: 38 to 40
 $ff0000 neopixel! \ red LED 100 % brightness
Changed:
<
<

Neopixel Wing with 32 Pixels

>
>

Neopixel Wing with 32 Pixels

 NeoPixelWing uses the D6 as datapin for the Neopixels:
3 6 dmod                       \ D6 output

Line: 58 to 60
 

Deleted:
<
<

NeoPixel Wing

 
Changed:
<
<
2945-01.jpg

3 6 dmod                       \ D6 output
32 cells buffer: pixelbuffer    \ create buffer for the neopixels
$ff0000 pixelbuffer !            \ 1st Neopixel red
$00ff00 pixelbuffer 1 cells + !   \ 2nd Neopixel green
$0000ff pixelbuffer 2 cells + !    \ 3th Neopixel blue
$7f7f7f pixelbuffer 3 cells + !     \ 4th Neopixel white 50 %
pixelbuffer 4 neopixels

create pixels 
$010000 , $020000 , $040000 , $080000 , $100000 , $200000 , $400000 , $800000 , \ 1st row red
$008000 , $004000 , $002000 , $001000 , $000800 , $000400 , $000200 , $000100 , \ 2nd row green
$000001 , $000002 , $000004 , $000008 , $000010 , $000020 , $000040 , $000080 , \ 3th row blue
$808080 , $404040 , $202020 , $101010 , $080808 , $040404 , $020202 , $010101 , \ 4th row white
pixels 32 neopixels

>
>
 

Implementation

Timing

Line: 224 to 194
 
Deleted:
<
<
 
Deleted:
<
<

 
Added:
>
>
 
Added:
>
>
-- Peter Schmid - 2022-03-03
 
Changed:
<
<

NeoPixel

>
>
Creative Commons License
This work by Peter Schmid is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
 

Revision 102021-12-06 - PeterSchmid

Line: 1 to 1
 
META TOPICPARENT name="MecrispCubeF405"
Changed:
<
<

NeoPixel

>
>
Neopixel
Intro
 
Added:
>
>
 

How To Use

Line: 45 to 57
 pixels 32 neopixels
Added:
>
>

NeoPixel Wing

2945-01.jpg

3 6 dmod                       \ D6 output
32 cells buffer: pixelbuffer    \ create buffer for the neopixels
$ff0000 pixelbuffer !            \ 1st Neopixel red
$00ff00 pixelbuffer 1 cells + !   \ 2nd Neopixel green
$0000ff pixelbuffer 2 cells + !    \ 3th Neopixel blue
$7f7f7f pixelbuffer 3 cells + !     \ 4th Neopixel white 50 %
pixelbuffer 4 neopixels

create pixels 
$010000 , $020000 , $040000 , $080000 , $100000 , $200000 , $400000 , $800000 , \ 1st row red
$008000 , $004000 , $002000 , $001000 , $000800 , $000400 , $000200 , $000100 , \ 2nd row green
$000001 , $000002 , $000004 , $000008 , $000010 , $000020 , $000040 , $000080 , \ 3th row blue
$808080 , $404040 , $202020 , $101010 , $080808 , $040404 , $020202 , $010101 , \ 4th row white
pixels 32 neopixels

 

Implementation

Timing

Line: 178 to 225
 
Added:
>
>

 
META FILEATTACHMENT attachment="timing-neopixel.png" attr="" comment="" date="1617633491" name="timing-neopixel.png" path="timing-neopixel.png" size="19590" user="PeterSchmid" version="1"

Revision 92021-12-06 - PeterSchmid

Line: 1 to 1
 
META TOPICPARENT name="MecrispCubeF405"

NeoPixel

Changed:
<
<
NeoPixelWing
>
>

How To Use

Single Pixel

The Adafruit Feather STM32F405 Board has its own Neopixel (GPIO PC0, D8) :

neopixel!    ( rgb -- )  sets the neopixel RGB led ($ff0000 red, $00ff00 green, $0000ff blue)

On the STM32WB Feather Development Board the NeoPixel shares the LED D12 pin. It is easy to add an Adafruit pixel breakout board or a Flora Pixel at the top of the shield. The LED can be used concurrently.

  • green: successfull USB enumeration
  • blue: BLE connected
  • flashing red: file write operation
  • flashing yellow: file read operation

For the STM32WB Nucleo Board I use D6 for the Neopixel

3 6 dmod           \ D6 output
$ff0000 neopixel!   \ red LED 100 % brightness

Neopixel Wing with 32 Pixels

NeoPixelWing uses the D6 as datapin for the Neopixels:
3 6 dmod                       \ D6 output
32 cells buffer: pixelbuffer    \ create buffer for the neopixels
$ff0000 pixelbuffer !            \ 1st Neopixel red
$00ff00 pixelbuffer 1 cells + !   \ 2nd Neopixel green
$0000ff pixelbuffer 2 cells + !    \ 3th Neopixel blue
$7f7f7f pixelbuffer 3 cells + !     \ 4th Neopixel white 50 %
pixelbuffer 4 neopixels

create pixels 
$010000 , $020000 , $040000 , $080000 , $100000 , $200000 , $400000 , $800000 , \ 1st row red
$008000 , $004000 , $002000 , $001000 , $000800 , $000400 , $000200 , $000100 , \ 2nd row green
$000001 , $000002 , $000004 , $000008 , $000010 , $000020 , $000040 , $000080 , \ 3th row blue
$808080 , $404040 , $202020 , $101010 , $080808 , $040404 , $020202 , $010101 , \ 4th row white
pixels 32 neopixels

Implementation

 

Timing

Revision 82021-06-18 - PeterSchmid

Line: 1 to 1
 
META TOPICPARENT name="MecrispCubeF405"

NeoPixel

Added:
>
>
NeoPixelWing
 

Timing

WS2812B Neopixel

Revision 72021-06-17 - PeterSchmid

Line: 1 to 1
 
META TOPICPARENT name="MecrispCubeF405"

NeoPixel

Line: 60 to 60
 .equ T0L, 5 // 0.85 us / (3 * 31.25 ns) = 9.07 -> 5 (4 turns less) .equ T1L, 1 // 0.45 us / (3 * 31.25 ns) = 4.53 -> 1 (4 turns less)
Added:
>
>
.equ RESTIME, 533 // 50 us / (3 * 31.25 ns) = 533
 // Registers .equ GPIO_BSRR, 0x18 // GPIOx->BSRR bit set/reset
Line: 77 to 79
  lsl r3, r1, #16 // clear port pin for BSRR mov r6, #24 // 24 bits
Added:
>
>
// set DOUT pin low and wait reset time str r3, [r0, #GPIO_BSRR] ldr r4, =RESTIME 1: subs r4, r4, #1 1 bne 1b
  cycles bit_loop: lsls r2, r2, #1 // get the next bit -> set the carry bit 1

Revision 62021-06-17 - PeterSchmid

Line: 1 to 1
 
META TOPICPARENT name="MecrispCubeF405"

NeoPixel

Line: 6 to 6
 

WS2812B Neopixel

Added:
>
>
 
Changed:
<
<
T0H 0code, high voltage time 0.4us ±150ns
T1H 1code, high voltage time 0.8us ±150ns
T0L 0code, low voltage time 0.85us ±150ns
T1L 1code, low voltage time 0.45us ±150ns
RES low voltage time Above 50μs
>
>
    WS2812B SK6812
T0H 0 code, high voltage time 0.4 us ±150 ns 0.3 us ±150 ns
T1H 1 code, high voltage time 0.8 us ±150 ns 0.6 us ±150 ns
T0L 0 code, low voltage time 0.85 us ±150 ns 0.9 us ±150 ns
T1L 1 code, low voltage time 0.45 us ±150 ns 0.6 us ±150 ns
RES low voltage time Above 50 us 80 us
 

timing-neopixel.png

Changed:
<
<
  • 1 bit takes 1.25 us, 24 bit take 30 us
>
>
  • 1 bit takes 1.25 us (800 kHz), 24 bit take 30 us
 
  • Timer resolution 0.25 us
  • MSB first
  • GRB
Added:
>
>
  • 3 cycles for a wait loop
 


Line: 35 to 38
 HTML Color 0xRRGGBB

F405

Added:
>
>
https://github.com/spyren/Mecrisp-Cube/blob/F405/Forth/cube/wings.s
 
Cycle = 1 / 168 MHz = 6 ns
0.4 us / 6 ns = 66.7 -> max. 66 cycles

Changed:
<
<
Timer Resolution = 1 / 42 MHz = 23.8 ns

#define T0H 15 // 0.4 us, 0.4 us / 23.8 ns = 16.8 #define T1H 32 // 0.8 us, 33.6 #define T0L 34 // 0.85 us, 35.7 #define T1L 17 // 0.45 us, 18.9 #define TRES 420 // 10 us, 420

max. deviation = timer_resolution + 2 cycles = 23.8 ns + 2 * 6 ns = 35.8 ns

>
>
.equ T0H, 16 // 0.3 us .equ T1H, 40 // 0.8 us .equ T0L, 36 // 0.8 us .equ T1L, 12 // 0.3 us
 

WB55

Line: 55 to 54
 Cycle = 1 / 32 MHz = 31.25 ns 0.4 us / 31.25 ns = 12.8 -> max 12 cycles
Deleted:
<
<
Timer Resolution = 1 / 32 MHz = 31.25 ns
 
Changed:
<
<
#define T0H 11 // 0.4 us, 0.4 us / 31.25 ns = 12.8 #define T1H 24 // 0.8 us, 25.6 #define T0L 26 // 0.85 us, 27.4 #define T1L 13 // 0.45 us, 14.5 #define TRES 323 // 10 us, 323
>
>
.equ T0H, 4 // 0.4 us / (3 * 31.25 ns) = 4.27 -> 4 .equ T1H, 8 // 0.8 us / (3 * 31.25 ns) = 8.53 -> 8 .equ T0L, 5 // 0.85 us / (3 * 31.25 ns) = 9.07 -> 5 (4 turns less) .equ T1L, 1 // 0.45 us / (3 * 31.25 ns) = 4.53 -> 1 (4 turns less)

// Registers .equ GPIO_BSRR, 0x18 // GPIOx->BSRR bit set/reset

.global BSP_neopixelDataTx BSP_neopixelDataTx: push {r4-r6, lr} lsl r2, r2, #8 // r2 = rrggbb00 mov r3, r2 // r3 = rrggbb00 bfc r3, #16, #16 // r3 = 0000bb00 rev16 r2, r2 // r2 = ggrr00bb bfc r2, #0, #16 // r2 = ggrr0000 add r2, r2, r3 // r2 = ggrrbb00

lsl r3, r1, #16 // clear port pin for BSRR mov r6, #24 // 24 bits

cycles bit_loop: lsls r2, r2, #1 // get the next bit -> set the carry bit 1 ittee cs 1 movcs r4, #T1H 1 movcs r5, #T1L 1 movcc r4, #T0H 1 movcc r5, #T0L 1

// set DOUT pin high str r1, [r0, #GPIO_BSRR] 2 1: subs r4, r4, #1 1 bne 1b 1 (2)

// set DOUT pin low str r3, [r0, #GPIO_BSRR] 2 2: subs r5, r5, #1 1 bne 2b 1 (2)

subs r6, r6, #1 1 bne bit_loop 2

pop {r4-r6, pc}

 
Deleted:
<
<
max. deviation = timer_resolution + 2 cycles = 31.25 ns ns + 2 * 31.25 ns = 93.75 ns
 
Line: 84 to 123
 
Deleted:
<
<

Timer

TIM6

Set Counter

TIM6->CNT;

Set Time Period

TIM6->ARR; // autoreload

Clear Update Flag

TIM6->SR; // UIF update interrupt flag

Enable/Disable Timer Interrupt

TIM6->DIER; // UIE update interrupt enable

Start/Stop Timer

TIM6->CR1; // UDIS update disable, CEN counter enable

 
META FILEATTACHMENT attachment="timing-neopixel.png" attr="" comment="" date="1617633491" name="timing-neopixel.png" path="timing-neopixel.png" size="19590" user="PeterSchmid" version="1"

Revision 52021-04-12 - PeterSchmid

Line: 1 to 1
 
META TOPICPARENT name="MecrispCubeF405"

NeoPixel

Line: 23 to 23
 


Changed:
<
<
lsls r3, r3, #1 ittee c movwc r5, #T1H movtc r5, #T1L movwnc r5, #T0H movtnc r5, #T0L
>
>
lsls r3, r3, #1 // set carry bit ittee cs movwcs r5, #T1H movtcs r5, #T1L movwcc r5, #T0H movtcc r5, #T0L
 
Added:
>
>
6 cycles.
  HTML Color 0xRRGGBB

F405


Changed:
<
<
Cyclus = 1 / 168 MHz = 6 ns
>
>
Cycle = 1 / 168 MHz = 6 ns 0.4 us / 6 ns = 66.7 -> max. 66 cycles
 Timer Resolution = 1 / 42 MHz = 23.8 ns

#define T0H 15 // 0.4 us, 0.4 us / 23.8 ns = 16.8

Line: 43 to 46
 #define T0L 34 // 0.85 us, 35.7 #define T1L 17 // 0.45 us, 18.9 #define TRES 420 // 10 us, 420
Added:
>
>
max. deviation = timer_resolution + 2 cycles = 23.8 ns + 2 * 6 ns = 35.8 ns
 

WB55


Changed:
<
<
Cyclus = 1 / 32 MHz = 31 ns Timer Resolution = 1 / 32 MHz = 31 ns
>
>
Cycle = 1 / 32 MHz = 31.25 ns 0.4 us / 31.25 ns = 12.8 -> max 12 cycles

Timer Resolution = 1 / 32 MHz = 31.25 ns

#define T0H 11 // 0.4 us, 0.4 us / 31.25 ns = 12.8 #define T1H 24 // 0.8 us, 25.6 #define T0L 26 // 0.85 us, 27.4 #define T1L 13 // 0.45 us, 14.5 #define TRES 323 // 10 us, 323

max. deviation = timer_resolution + 2 cycles = 31.25 ns ns + 2 * 31.25 ns = 93.75 ns

 

Revision 42021-04-12 - PeterSchmid

Line: 1 to 1
 
META TOPICPARENT name="MecrispCubeF405"

NeoPixel

Line: 21 to 21
 
  • MSB first
  • GRB
Added:
>
>
   lsls     r3, r3, #1
   ittee    c
   movwc    r5, #T1H
   movtc    r5, #T1L   
   movwnc   r5, #T0H
   movtnc   r5, #T0L
 HTML Color 0xRRGGBB

F405

Revision 32021-04-10 - PeterSchmid

Line: 1 to 1
 
META TOPICPARENT name="MecrispCubeF405"

NeoPixel

Added:
>
>

Timing

 
Changed:
<
<
>
>

WS2812B Neopixel

 
T0H 0code, high voltage time 0.4us ±150ns
T1H 1code, high voltage time 0.8us ±150ns
Line: 11 to 13
 
T1L 1code, low voltage time 0.45us ±150ns
RES low voltage time Above 50μs
Added:
>
>
timing-neopixel.png
 
  • 1 bit takes 1.25 us, 24 bit take 30 us
  • Timer resolution 0.25 us
  • MSB first
Line: 18 to 23
  HTML Color 0xRRGGBB
Changed:
<
<

Set/Reset Portpin

>
>

F405

Cyclus = 1 / 168 MHz = 6 ns
Timer Resolution = 1 / 42 MHz = 23.8 ns

#define T0H		15	// 0.4 us, 0.4 us / 23.8 ns = 16.8
#define T1H		32	// 0.8 us, 33.6
#define T0L		34	// 0.85 us, 35.7
#define T1L		17	// 0.45 us, 18.9
#define TRES  	420	// 10 us, 420

WB55

Cyclus = 1 / 32 MHz = 31 ns
Timer Resolution =  1 / 32 MHz = 31 ns

Set/Reset Portpin

  GPIO port bit set/reset register GPIOx_BSRR
Changed:
<
<
  • Address offset: 0x18, x = A..K
>
>
  • Address offset: 0x18, x = A..K, D8 = PC0
 
  • bit0 .. bit15 bit set
  • bit16 .. bit31 bit reset
Changed:
<
<
D8 =
>
>
#define GPIOC_BASE            (AHB1PERIPH_BASE + 0x0800UL)
#define AHB1PERIPH_BASE       (PERIPH_BASE + 0x00020000UL)
#define PERIPH_BASE           0x40000000UL /*!< Peripheral base address in the alias region                                */

 
Changed:
<
<

Set Counter

>
>
GPIOC->BSRR
 
Deleted:
<
<

Set Time Period

 
Changed:
<
<
autoreload
>
>

Timer

 
Changed:
<
<

Clear Update Flag

>
>
TIM6
 
Changed:
<
<

Enable/Disable Timer Interrupt

>
>

Set Counter

 
Changed:
<
<

Start/Stop Timer

>
>
TIM6->CNT;
 
Added:
>
>

Set Time Period

 
Added:
>
>
TIM6->ARR; // autoreload
 
Added:
>
>

Clear Update Flag

TIM6->SR; // UIF update interrupt flag

Enable/Disable Timer Interrupt

TIM6->DIER; // UIE update interrupt enable

Start/Stop Timer

TIM6->CR1; // UDIS update disable, CEN counter enable

 
Deleted:
<
<
-- Peter Schmid - 2021-04-05
  • timing-neopixel.png:
    timing-neopixel.png
 
META FILEATTACHMENT attachment="timing-neopixel.png" attr="" comment="" date="1617633491" name="timing-neopixel.png" path="timing-neopixel.png" size="19590" user="PeterSchmid" version="1"

Revision 22021-04-10 - PeterSchmid

Line: 1 to 1
 
META TOPICPARENT name="MecrispCubeF405"

NeoPixel

Line: 18 to 18
  HTML Color 0xRRGGBB
Added:
>
>

Set/Reset Portpin

GPIO port bit set/reset register GPIOx_BSRR

  • Address offset: 0x18, x = A..K
  • bit0 .. bit15 bit set
  • bit16 .. bit31 bit reset

D8 =

Set Counter

Set Time Period

autoreload

Clear Update Flag

Enable/Disable Timer Interrupt

Start/Stop Timer

 -- Peter Schmid - 2021-04-05
  • timing-neopixel.png:
    timing-neopixel.png

Revision 12021-04-05 - PeterSchmid

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="MecrispCubeF405"

NeoPixel

T0H 0code, high voltage time 0.4us ±150ns
T1H 1code, high voltage time 0.8us ±150ns
T0L 0code, low voltage time 0.85us ±150ns
T1L 1code, low voltage time 0.45us ±150ns
RES low voltage time Above 50μs

  • 1 bit takes 1.25 us, 24 bit take 30 us
  • Timer resolution 0.25 us
  • MSB first
  • GRB

HTML Color 0xRRGGBB

-- Peter Schmid - 2021-04-05

  • timing-neopixel.png:
    timing-neopixel.png

META FILEATTACHMENT attachment="timing-neopixel.png" attr="" comment="" date="1617633491" name="timing-neopixel.png" path="timing-neopixel.png" size="19590" user="PeterSchmid" version="1"
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback