Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

TCB0 Single Shot Mode

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Mon Feb 22, 2021 8:56 am    Post subject: TCB0 Single Shot Mode Reply with quote

Hi
I noticed that at TCB0 the manufacturer cloned the "single shot" function.
This involves generating a pulse of a given length without repeating.
The downside is that the operation of this function is via the Event system but we have already shown this with the TCD how it works.
I was thinking of a simple way to use it and I thought of writing a program to control the RGB LED tape. The standard RGB LED strip has 105 diodes per meter.
Since I had one lying around my house, I tried. Writing for 500 LEDs takes 7.2ms. Which I don't think is such a bad time. It's just a skeleton to do it.
You could even shorten it, control the brightness, etc. It would probably be quicker to use SPI for this purpose, just to demonstrate the functionality of this mode.
Code:

 $regfile = "atXtiny412.dat"
$crystal = 20000000
$hwstack = 16
$swstack = 16
$framesize = 24

'set the system clock and prescaler
Config Sysclock = 20mhz , Prescale = 1

dim color(3) as byte
dim delka as word


Declare sub vys(byval color(1) as byte,color(2) as byte,color(3) as byte, byval delka as byte)


config porta.6=output

' Configured event system
evsys_asyncuser0=0x02
'Output Assignment
portmux_ctrld=0x01
'Configured TCB0
tcb0_ctrlb=0b01010110
tcb0_evctrl=0b00010001
tcb0_ctrla=0b00000011
'Number of LEDs  x3
delka = 1500
'Configured color
color(1)=36
color(2)=125
color(3)=196
do
call vys (color(1),color(2),color(3),delka)


waitms 2
loop




sub vys(byval color(1) as byte,color(2) as byte,color(3) as byte, byval delka as byte)
 dim maska as byte
 dim i as word
 dim pom as byte
 dim pom1 as byte
 tcb0_ccmp=65534    'Comparison Registry Settings
 pom1=0
  disable interrupts    'Turn off interrupts to be sure
  for  i= delka to 0 step -1
  pom1=pom1+1
      maska = 0b10000000
      while maska > 0
        while tcb0_status.0=1   'Wait if the timer is running
        wend
        pom=color(pom1)
        pom=maska and pom
         if pom>0 then
            tcb0_cnt=65524    'Number of timer pulses for state H(in catalogue sheet 550-850ns,for 20MHz-10)
            evsys_syncstrobe=0x01   'Generating SW event for timer start
         else
            tcb0_cnt=65528     'Number of timer pulses for state L(in catalogue sheet 200-500ns,for 20MHz-6)
            evsys_syncstrobe=0x01   '  Generating SW event for timer start
         end if
        shift maska,right

      wend
      if pom1=3 then
      pom1=0
      end if
  next i
  enable Interrupts
 while tcb0_status.0=1
 wend
 waitus 70                     'Latch WS
 end sub


RS
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Feb 22, 2021 10:11 am    Post subject: Reply with quote

great example of the one shot. Thanks !

i modded your code a bit.
Are these the ws2812 leds ?



Code:

$regfile = "atXtiny412.dat"
$crystal = 20000000
$hwstack = 16
$swstack = 16
$framesize = 24
'set the system clock and prescaler
Config Sysclock = 16_20mhz , Prescale = 1
Dim Color(3) As Byte
Dim Delka As Word

Declare Sub Vys(color() As Byte , Byval Delka As Word)

Config Porta.6 = Output
' Configured event system
Evsys_asyncuser0 = &H02
'Output Assignment
Portmux_ctrld = &H01
'Configured TCB0
Tcb0_ctrlb = &B01010110
Tcb0_evctrl = &B00010001
Tcb0_ctrla = &B00000011
'Number of LEDs  x3
Delka = 1500
'Configured color
Color(1) = 36
Color(2) = 125
Color(3) = 196
Do
   Call Vys(color(1) , Delka)
   Waitms 2
Loop


Sub Vys(color() As Byte , Byval Delka As Word)
   Dim Maska As Byte
   Dim I As Word
   Dim Pom As Byte
   Dim Pom1 As Byte
   Tcb0_ccmp = 65534                                        'Comparison Registry Settings
   Pom1 = 0
   Disable Interrupts                                       'Turn off interrupts to be sure
   For I = Delka To 0 Step -1
      Pom1 = Pom1 + 1
      Maska = &B10000000
      While Maska > 0
         While Tcb0_status.0 = 1                            'Wait if the timer is running
         Wend
         Pom = Color(pom1)
         Pom = Maska And Pom
         If Pom > 0 Then
            Tcb0_cnt = 65524                                'Number of timer pulses for state H(in catalogue sheet 550-850ns,for 20MHz-10)
            Evsys_syncstrobe = &H01                         'Generating SW event for timer start
         Else
            Tcb0_cnt = 65528                                'Number of timer pulses for state L(in catalogue sheet 200-500ns,for 20MHz-6)
            Evsys_syncstrobe = &H01                         '  Generating SW event for timer start
         End If
         Shift Maska , Right
      Wend
      If Pom1 = 3 Then
         Pom1 = 0
      End If
   Next I
   Enable Interrupts
   While Tcb0_status.0 = 1
   Wend
   Waitus 70                                                'Latch WS
End Sub
 

_________________
Mark
Back to top
View user's profile Visit poster's website
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Mon Feb 22, 2021 10:22 am    Post subject: Reply with quote

Hi
I forgot to rewrite it to the Bascom custom.Very Happy
Yes WS2812. Should of course work WS2812C,2813,2813C,2811,OST34020,OSTW3535. It's all about adjusting the time.
RS
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum