AVR128DA48 Event System, CCL, and Driving WS2812B LEDs

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Hello All,

 

I have been working with the Curiosity Nano, and have been attempting to use a USART in master SPI mode, the event system, and CCL to create the drive waveform for the WS2812B LEDs.  I have done this successfully on the ATxmega32E5, but the AVR128DA48 is quite different, especially in the XCL / CCL block.  The AVR CCL has no programmable one-shot timer blocks, so I am trying to use one of the TCBn timers in one-shot mode.

 

The idea is to use the timer to create a fixed-time window triggered by the XCK rising edge, which I can use with the CCL to create a 375ns always-high state, followed by another 375ns state which is 0 or 1, depending upon the value of the TXD bit, and finally, a low state that remains low until the next XCK rising edge starts the whole sequence over.  I will use this one-shot time window with the CCL to create the final output waveform.  The diagram below illustrates my goal.

I have verified the USART SPI TXD and XCK output.  Event channel 1 is assigned to USART XCK.  I configured EVOUTB as an event user and verified the XCK signal is present on EVOUTB; it looks virtually identical to the signal on the XCK output pin.  Unfortunately, I am not having success getting TCB1 to operate as a one-shot timer.

 

I configured TCB1 for one-shot operation, TCMP = 9 counts, 24MHz clock, and enabled the WO output.  I also wrote the TCMP count value to the CNT register, so the timer will not start when it is first enabled.  I set it as an event user of the XCK event.  If I set TCB1 output as asynchronous trigger, the WO output on PA3 goes high on the first rising edge of XCK, but it remains high indefinitely.  If I set TCB1 output as synchronous, the WO output remains low.  In either event, there is no evidence that TCB1 actually counted, as the interrupt flags remain 0.

 

If I leave the CNT register at zero when I enable TCB1, the timer starts and counts up to the terminal count, and stops.  It still doesn't seem to respond to the event trigger.

 

Has anyone had success with what I am attempting?  I would appreciate any suggestions.  Thank you!

 

Altazi

This topic has a solution.
Last Edited: Thu. Mar 18, 2021 - 06:48 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I've already done it.
I wrote it in C.

 

https://www.avrfreaks.net/forum/...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kabasan wrote:

I've already done it.
I wrote it in C.

 

https://www.avrfreaks.net/forum/...

 

Fabulous!  I shall analyze your code concerning the TCBn timers.  Something was eluding me, for sure.

 

Thank you very much!

 

Altazi

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Microchip offers an example that does exactly this: https://github.com/microchip-pic...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I improved the logic using TCB because it deviated greatly from the timing of WS2812B.

The terrible algorithm on that github originated on the CCL of the PIC, was ported to the tiny1617 on AN2387, and went to DA.

 

Last Edited: Fri. Mar 12, 2021 - 03:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you, Kabasan.  I was missing setting CAPTEI in the TCBn blocks.  Your implementation of the WS2812B LED drive with the CCL is simple, but effective.  I was hoping to get by with only one TCB timer, but the logic didn't seem to allow it.  At any rate, I am now successfully driving the WS2812B LEDs.

 

Altazi

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is possible to generate with one TCBn in a limited way.
I've done that with mega0 and tiny0 / 1 before, but I'm not using it now because it reduces the freedom of the main clock.
You are posting in this thread that you also participated in.

 

https://www.avrfreaks.net/forum/...

 

The TCBn filter and CCL filter, or an additional CCL, can be combined to delay the one-shot activation of TCBn by the period of T0H.