• AVR Freaks

Helpful ReplyHot!WS2412B Hardware Driver

Page: 123 > Showing page 1 of 3
Author
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3992
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
2019/01/21 08:48:03 (permalink)
5 (3)

WS2412B Hardware Driver

The WS2412B has always been used with the bit-banging method.
Now it can be done completely in hardware using only 89 instructions.
The following modules are used:
2 x DMA (Duplex)
1 x SPI (Standard)
1 x CCP (Triggered PWM)
1 x CLC (SR Latch + Reset)
1 x Virtual Pin (1 in, 2 out)
1 x External pin for output to first WS2412B in chain
 
There are 4 possible ways to send signals to the leds:
1    Bit-Bang - send data through software, the cpu is kept busy (Manual)
2    Write to SPI(New WS2412B Module), handles 8bits at a time but the cpu is still busy
3    Shape the SPI signal data before refresh but increases data size by a large amount (Manual)
4    DMA to SPI (New WS2412B Module), cpu is not busy.
 

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#1
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3992
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/21 09:52:15 (permalink)
0
A lot of registers need to be configured.
 
There are two possible outputs to the WS2412B
Zero: short duty cycle
One : Long duty cycle
 
Timing:
ZERO: -[]+ 150ns
0.2us [0.36us] 0.5us
        
ONE: -[]+ 150ns
1.21us [1.36us] 1.51us
        
The first thing to decide is the frequency, once you have that you can calculate the period and the duty cycle.
1 / 400KHz (Example) = 2.5us period
 
I use the second cpu because this runs at 100MIPS and makes entering time easy without having to re-calculate. mov  #1000,x  ;10us
 
With a period of 2.5us the cpu is capable of executing 250 instructions per period.
 
1000 rgb leds would take 60ms for a refresh, in that time the cpu can execute 6,000,000 instructions.
 
With double buffering you then have 60ms to update the secondary buffer.
 
24bits x 2.5us = 60 microseconds

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#2
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3992
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/21 10:19:48 (permalink)
0
32bits x 2.5us @400KHz = 80ms

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#3
du00000001
Just Some Member
  • Total Posts : 3942
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/21 10:55:56 (permalink)
0
60 (80) ms is somewhat slow:
You cannot display moving images as the flicker would be perceivable  wink
 
(But this is critics on the very highest level...)

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#4
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3992
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/21 11:01:43 (permalink)
0
The speed can be increased, 400KHz was an example.
800KHz is the max for these chips, the time would then be 30ms refresh time for 1000 rgb leds.
post edited by Gort2015 - 2019/01/21 11:03:02

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#5
du00000001
Just Some Member
  • Total Posts : 3942
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/21 11:08:24 (permalink)
0
For a fluid motion perception, you need an absolute minimum of 24 frames per second. (50 fps would be better.)
OK - 30 ms would give around 30 fps  Smile
The tricky part is that your time frame for any update decreases with the increase in frame rate. . . .

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#6
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3992
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/21 11:28:47 (permalink)
0
You could increase this even more by using more modules.
This chip can support 3 WS2412B modules.
 
Dedicate 1 channel for 333 leds increasing refresh times by a factor of 3.

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#7
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3992
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/21 15:16:14 (permalink)
0
Some Theory
The SPI module clock is used 4 times:
1. SDO clock
2. PWM trigger, every rising edge from SCL causes the period counter to restart.  The purpose of this is to lock PWM to SCL.  PWM duty cycles are always smaller than SCL.  Generated ZERO and ONE can then occur at the same time.  CLC decides which to select.
3. CLC output = SDO & SCL | PWM.  What ever the outcome of SDO [AND] SCL, PWM will always win the day, in other words if there is not a ONE then ZERO is guaranteed.  ZERO is still output when there is a ONE but the ONE has a longer duty cycle so ZERO has no effect.
4. SR Latch Reset.  Reset is used as a gate, if the SPI Clock is not active then SR Latch is held low over-riding the SR Latch output Q.  Without this, the CLC module would output the PWM signal if it is active.
 
The PWM signal represents a ZERO.  It's frequency is 400KHz(for example), a 2.5us period time.  A duty cycle of 0.5us is fine (DC is ZERO)
The SCL represents a ONE, it's frequency is 400KHz.  It's duty cycle is 50% yielding a ONE time of 1.25us.
 
The WS2412B period can be contained in three equal time parts:
|--1--|--2--|--3--|
1 High
2 Stay High or go Low
3 Low

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#8
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3992
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/27 06:47:37 (permalink)
0
This is now object based.  If you wish to scroll some text you only need to change the x and y position of the object without having to call a scroll function.
 
Supports Z axis for layers.
 
Fonts are standard mono type.  Characters for a font can go through a color filter for gradients.  (Horizontal, vertical or user change and local to each char or string)
 
Supports RGB, GRB and multi-channels.
 
 
I was surprised by the lack of interest in this since this does not bit-bang.
 
 

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#9
du00000001
Just Some Member
  • Total Posts : 3942
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/27 07:09:08 (permalink)
0
Gort2015... lack of interest ...

As his is no fancy Arduino forum and most of us might yet have to get our handy dirty with the 33C family, I'm not surprised.
As already recommended, publishing this design on Instructables and/or Hackster.io might yield some pile-up. On the Microchip forums, the echo might remain meager. (PIC16/18 users might not even have subscribed to the dsPIC33 forums (although your approach would apply on PIC1xs with CLC as well), and there is a separate forum for the 33E family :(

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#10
cbarn
Starting Member
  • Total Posts : 51
  • Reward points : 0
  • Joined: 2007/01/20 11:02:14
  • Location: 0
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/27 11:58:10 (permalink)
5 (1)
nothing to see here.
post edited by cbarn - 2019/01/27 21:21:02
#11
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3992
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/27 17:30:34 (permalink)
1 (1)
So, your code is not done in hardware is it????
A waste of a post.
 
My code takes two single instructions to fire the refresh of a chain of leds, in hardware.
The cpu is busy to do other things, since it is not locked in software.
Very short code.
 
It's not in the same league mate.
 
post edited by Gort2015 - 2019/01/27 17:57:04

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#12
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3992
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/27 17:32:05 (permalink)
0
Basically what the thread is about.
 

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#13
du00000001
Just Some Member
  • Total Posts : 3942
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/27 19:01:06 (permalink)
0
@ Gort....
cbarn is certainly another league  :)
From what I understand, he's transcoding every 2 bits into a byte, then transmitting the byte(s) via SPI.
So this is a hardware solution as well and could be "DMA'ed", but at the penalty of using a lot of RAM for buffering (4 times the "raw data"). A viable approach, but a bit RAM-intensive.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#14
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3992
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/27 19:51:12 (permalink)
0
No, you want interrupts firing and cpu doing normal stuff while the refresh is in progress.
 
The main idea is to create animations into double buffers.
 
If you had 1000 leds and you were refreshing at 800KHz, that gives you:
cpu at 100MIPS = 10ns
1000 x 3 x (1/800,000) = 3.75ms
3.75ms / 10ns = 375,000 cycles
 
CPU can execute 375,000 instructions in the same time as it takes to refresh.
+Blanking time.
 
 
 
 
 
 
 

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#15
cbarn
Starting Member
  • Total Posts : 51
  • Reward points : 0
  • Joined: 2007/01/20 11:02:14
  • Location: 0
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/27 21:20:15 (permalink)
0
Yeah - thought it was question -asking how to do it.  I did it, gave an answer hoping to help.  I should have read more carefully - as I see my half-ass solution was mentioned.   LOL
 
#16
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3992
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/28 06:05:57 (permalink)
1 (1)
I never ask for help.

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#17
du00000001
Just Some Member
  • Total Posts : 3942
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/28 06:11:39 (permalink) ☄ Helpfulby cobusve 2019/01/30 14:02:05
5 (1)
Gort2015I never ask for help.
but from time to time I tend to rant  grin

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#18
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3992
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/28 06:40:04 (permalink)
1 (1)
From time to time I tend to criticize other members, we all do, like you are now du00000001.
(criticizing me)
 
With this new hardware WS2412B module you could play Spade Invaders, pixels permitting.
 
Remember, no code.
 
 

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#19
du00000001
Just Some Member
  • Total Posts : 3942
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: WS2412B Hardware Driver 2019/01/28 06:45:55 (permalink)
0
   Smile Smile Smile  

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#20
Page: 123 > Showing page 1 of 3
Jump to:
© 2020 APG vNext Commercial Version 4.5