Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Rainbow INstruction difficulty on the XTiny 402
Goto page 1, 2, 3  Next
 
Post new topic   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
JC

Bascom Member



Joined: 15 Dec 2007
Posts: 586
Location: Cleveland, OH

usa.gif
PostPosted: Fri Feb 05, 2021 4:47 am    Post subject: Rainbow INstruction difficulty on the XTiny 402 Reply with quote

Hello Everyone,

I love the WS2812B Digital LEDs.
I am thankful for their support in Bascom using the Rainbow Libraries.
I have used them on several projects with Mega328P's, (Nano's), without difficulty.

I now have a project using the new XTiny402, (for which I have the new Bascom Add On), and I am having difficulty in getting the WS2812B LED to work.
Bascom Version: 2.0.8.3.005

The program is simple, it flashes a normal LED to show that the XTiny is running.
It then flashes some colors on the WS2812B LEDs, (except that is the problem, they never light up).

The T402 is running, as the normal LED flashes correctly at startup.
The T402 is running at 10 MHz, checked by flashing the normal LED at 1 Hz in a separate test program.

The two programs, the test program for the M328P, and the test program for the T402 are almost the same.
The M328P, (Nano), version runs correctly.
The T402 version won't turn on or flash the WS2812B LEDs.

The normal LED and the WS2812B LEDs are on different I/O pins, and the T402 requires an additional instruction to sets it clock from the default to 10 MHz.

I have REM'd out the Nano config, for the T402 config, as provided below.

If anyone has an XTiny micro and a WS2812B digital LED I'd sure appreciate it if you could test the program below.
I am likely making some simple mistake, but having another person look at the code, and/or test the program on their hardware, would be great.

I appreciate any help!

JC




Code:


'File:   T402 Rainbow Test 2021 V2.bas
'JC   Bascom
'Feb. 2021

'This program runs on an XTiny402, 10 MHz, 5V.

'This program demos the Bascom Rainbow (WS2812B Digital LED)
'instructions on a single string of LEDs.

'This is a simple test program, no interrupts or other code
'is running.

'+++++++++++++++++++++++++++++++++++++++++++++++++
'+++  This program fails to flash the WS2812B Digital LEDs                      +++
'+++  The T402 is running, it flashes the normal LED at the correct speed  +++
'+++  Could be hardware, as it has never worked yet                               +++
'+++  Could be the Rainbow Library isn't functioning on the XTiny Series   +++
'+++++++++++++++++++++++++++++++++++++++++++++++++

'Hardware:
'XTiny402, 10 MHz, 5V
'Dig LED on PortA.7
'PCB LED on PortA.6

'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   'Config for XTiny402:
   $regfile = "atxtiny402.dat"    'Micro being used
   $crystal = 10000000            '10.0 MHz, Internal RC Osc

   'Config for Nano, M328P:
   '$regfile = "m328pdef.dat"                                'Micro being used
   '$crystal = 16000000                                      '16 MHz Clock Freq

   $hwstack = 64                                            'Hardware Stack
   $swstack = 64                                            'Software Stack
   $framesize = 64                                          'Frame Space

   $lib "RAINBOWBSCN.lib"                                   'Force new Rainbow LED Library

   'Config for XTiny402:
   'Config I/O Pins:
   Config PortA.6 = Output                                  'PCB LED
   Config PortA.7 = Output                                  'Dig LED string

   'Config for Nano, M328P:
   'Config I/O Pins:
   'Config PortB.5 = Output                                  'NANO PCB LED
   'Config PortD.7 = Output                                  'Dig LED string

   'XTiny402:
   LED Alias PortA.6                                        'PCB Led

   'Nano:
   'LED Alias PortB.5                                        'Nano PCB Led

   'Variable Definitions:
   Dim LpCnt As Word                                        'Loop Counter

   'Dig LED Variables:
   Dim Color(3) as Byte                                     'Color array for digital leds

'===============================================================================
   'Hardware Startup Delay:
   Waitms 100

   'Config the Clock for the XTiny402:
   'Config Internal RC 20 MHz Osc for 10.0 MHz System Clock
   'Set Clock to 10.0 MHz:
   Config Sysclock =20MHZ, Prescale = 2

   'Config the WS2812B Digital LED Rainbow Instruction Driver:
   'Use 1 string of LEDs
   '2 LEDs in the string
   'Use PortD.7
   'Use the new Rainbow Library
   'This is Channel #0

   'XTiny402:
   Config Rainbow = 1 , RGB = 3 , RB0_LEN = 2 , RB0_Port = PortA , RB0_Pin = 7

   'Nano:
   'Config Rainbow = 1 , RGB = 3 , RB0_LEN = 2 , RB0_Port = PortD , RB0_Pin = 7

Main:
   'Flash the Normal LED to show that the XTiny or Nano is running:
   Gosub FlashLED

   'Now turn on the two digital LEDs:
   Gosub DigLEDTest1                        'All ON, Low Intensity Blue
   Waitms 1000

   'Now alternate the 2 digital LEDs Red and White:
   Do
      Gosub DigLEDTest2          'LEDs: Red and White
      Waitms 200
      Gosub DigLEDTest3          'LEDs: White and Red
      Waitms 200
   Loop                          'Forever

'+++++++++++++++++++++++++++++++++++++++++++++
DigLEDTest1:
   'Turn On All (Two) LEDs, Low Intensity Blue
   'Select the Active string of digital LEDs
   RB_SelectChannel 0                 'Channel #0
   Gosub LEDColor4                     'Low intensity Blue
   RB_FILL color(1)                    'Turn on ALL Leds in strip
   Return

DigLEDTest2:
   'Channel #0, (2 LEDs)
   'Turn On Dig LED 1 Red
   'Turn On Dig LED 2 White
   RB_SelectChannel 0                 'Channel #0
   Gosub LEDColor3                     'Low intensity Red
   RB_SetColor 0, color(1)             'LED 1, Red
   Gosub LEDColor2                     'Low intensity White
   RB_SetColor 1, color(1)             'LED 2, White
   RB_Send                             'Update the LEDs
   Return

DigLEDTest3:
   'Channel #0, (2 LEDs)
   'Turn On Dig LED 1 White
   'Turn On Dig LED 2 Red
   RB_SelectChannel 0                 'Channel #0
   Gosub LEDColor2                     'Low intensity White
   RB_SetColor 0, color(1)             'LED 1, Red
   Gosub LEDColor3                     'Low intensity Red
   RB_SetColor 1, color(1)             'LED 2, White
   RB_Send                             'Update the LEDs
   Return

LEDColor1:
   'This sets up the data for the digital LEDs
   'Color #1 = Off
   Color(1) = 0                                             'Red
   Color(2) = 0                                             'Green
   Color(3) = 0                                             'Blue
   Return

LEDColor2:
   'This sets up the data for the digital LEDs
   'Color #2 = Low Intensity White (All 3 colors equal intensity)
   Color(1) = 30                                            'Red
   Color(2) = 30                                            'Green
   Color(3) = 30                                            'Blue
   Return

LEDColor3:
   'This sets up the data for the digital LEDs
   'Color #3 = Low Intensity Red
   Color(1) = 0                                             'Red
   Color(2) = 20                                            'Green
   Color(3) = 0                                             'Blue
   Return

LEDColor4:
   'This sets up the data for the digital LEDs
   'Color #4 = Low Intensity Blue
   Color(1) = 0                                             'Red
   Color(2) = 0                                             'Green
   Color(3) = 10                                            'Blue
   Return

FlashLED:
         'This flashes the normal, non-digital LED, on the Nano, PortB.5
         'This shows that the Nano is running.
         For LpCnt = 1 to 5
             Set Led
             Waitms 100
             Reset Led
             Waitms 100
         Next LpCnt
         Return

 


(BASCOM-AVR version : 2.0.8.3 , Latest : 2.0.8.3 )
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Fri Feb 05, 2021 7:36 am    Post subject: Reply with quote

Xtinys are similar to Xmegas so maybe you can try to cheat the lib Very Happy
In library there are only one statement "#IF _XMEGA=0" in line 170 so not much to work with.

So maybe copy the lib and save on another name like "Rainbowbscn2". Then change _XMEGA into _XTINY and compile the lib after save in Lib Manager.

Sorry. I dont have time to test this. This is only idea.
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Fri Feb 05, 2021 9:12 am    Post subject: Reply with quote

EDC wrote:
Sorry. I dont have time to test this. This is only idea.

The idea is clever, however it won't work, there's another change required.

Change this
Code:
#IF _XMEGA=0
   CLR ZH
#ELSE
   LDI ZH, &H06
#ENDIF

into this
Code:
#IF _XMEGA=1
   LDI ZH, &H06
#ELSEIF _XTINY=1
   LDI ZH, &H04
#ELSE
   CLR ZH
#ENDIF

considered it actually runs on XMega, which I can't test.
Back to top
View user's profile
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Fri Feb 05, 2021 9:24 am    Post subject: Reply with quote

I don't know how to do you
Config Sysclock = 20MHZ, Prescale = 2
warns me of an error.
Should be
Config Sysclock = 16_20MHZ, Prescale = 2
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Fri Feb 05, 2021 9:48 am    Post subject: Reply with quote

SZTRAD wrote:
Config Sysclock = 20MHZ, Prescale = 2

It compiles ok on 2.0.8.3
Quote:
warns me of an error.

What exactly does it tell?
Back to top
View user's profile
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Fri Feb 05, 2021 10:05 am    Post subject: Reply with quote

MWS wrote:
EDC wrote:
Sorry. I dont have time to test this. This is only idea.

The idea is clever, however it won't work, there's another change required.

Change this
Code:
#IF _XMEGA=0
   CLR ZH
#ELSE
   LDI ZH, &H06
#ENDIF

into this
Code:
#IF _XMEGA=1
   LDI ZH, &H06
#ELSEIF _XTINY=1
   LDI ZH, &H04
#ELSE
   CLR ZH
#ENDIF

considered it actually runs on XMega, which I can't test.

It wouldn't work for him without changing the library out of 328 if this was necessary. Or am I wrong?
Back to top
View user's profile
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Fri Feb 05, 2021 10:21 am    Post subject: Reply with quote

MWS wrote:
SZTRAD wrote:
Config Sysclock = 20MHZ, Prescale = 2

It compiles ok on 2.0.8.3
Quote:
warns me of an error.

What exactly does it tell?


I have a feeling that Mark and I have dealt with this before
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Fri Feb 05, 2021 10:24 am    Post subject: Reply with quote

MWS is right, that is the right way.
I attached the updated libs.

About the sysclock option : it was 20MHZ first.
But that did not reflect properly that this osc can be changed between 16 and 20 with a fuse.
So it has been renamed into : 16_20MHZ

also in the mcs shop the add on would send a link to the first public version. while the register/update download will give the updated version.
that has been corrected but you should make sure you use the last version.

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

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Fri Feb 05, 2021 10:55 am    Post subject: Reply with quote

SZTRAD wrote:
It wouldn't work for him without changing the library out of 328 if this was necessary. Or am I wrong?

My post was about changing one part within the lib to make it compatible.
Reason of the failure was, that the ports base address starts at &h0400 for XTINY, at &h0600 for XMEGA, and &h05 (&h25) for the ATMega328.
Exchanging XTINY for XMEGA alone wouldn't have worked.
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Fri Feb 05, 2021 12:09 pm    Post subject: Reply with quote

I was reply to this post with my morning cup of coffe when next I must leave work and must get some things done.
I suppose that offset may differ form Xmega but TO can check this too Very Happy
Also Im preffer syntax "If Somehing=1 Elseif..Else..." instead "If Something=0 (not exists like a switch)" but morning answear was supposed to be an idea.
I`m happy that it was, this time, so easy Very Happy
Back to top
View user's profile Visit poster's website
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Fri Feb 05, 2021 12:11 pm    Post subject: Reply with quote

MWS wrote:
SZTRAD wrote:
It wouldn't work for him without changing the library out of 328 if this was necessary. Or am I wrong?

My post was about changing one part within the lib to make it compatible.
Reason of the failure was, that the ports base address starts at &h0400 for XTINY, at &h0600 for XMEGA, and &h05 (&h25) for the ATMega328.
Exchanging XTINY for XMEGA alone wouldn't have worked.


I noticed it in that library.
Again, when I have time, I'll think about how libraries in bascom work. Is there a guide for passing parameters between the program and the library?
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Fri Feb 05, 2021 3:29 pm    Post subject: Reply with quote

SZTRAD wrote:
Is there a guide for passing parameters between the program and the library?

In the help to $EXTERNAL is a small sample, which you find also in the samples folder as libDEMO.bas, the associated lib you find in Bascom's subdir LIB-folder.
The rest becomes obvious if one reads through the existing Libs, while you can write also in Bascom, you should be used to assembler.

Hints:
Use the asterisk (*) as first char in a line, where constants are used, which are only later declared in user code.
This tells the compiler not to evaluate them in the very moment it does error check the lib, and wait for the user code to declare these values.

Optional variables, which are considered by the lib only if they exist can be included using optional compilation #IF/#ENDIF, and VarExist(), you find some info in the help at conditional compilation.
Sample:
Code:
#IF varexist("chrperline")
  LDS   R16. {chrperline}
#ELSE
   LDI   R16, &H20
#ENDIF

Functions with same names, for example as used in MCS.lib, override the previously declared one, this applies also to implicit included libs like MCS.lib
If you write a lib called myDELCHAR.lib, in which you redefine [_DELCHAR], save this myDELCHAR.lib into the LIB-folder, and finally include into your Bas-file the line: $LIB "myDELCHAR.lib", then you did override this special function of the MCS.lib
The parameters are fixed to the same processor registers as in the original lib, you can not change that.
Back to top
View user's profile
JC

Bascom Member



Joined: 15 Dec 2007
Posts: 586
Location: Cleveland, OH

usa.gif
PostPosted: Fri Feb 05, 2021 5:41 pm    Post subject: Reply with quote

Wow!

Thank you, everyone!

I went to bed last night worrying about this, not at all sure how I was going to fix it.

I woke up today and the problem had already been identified and fixed !

Thank you, again, to: Mark, MWS, EDC, and SZTRAD for your help!

It is truly appreciated!

JC
Back to top
View user's profile Visit poster's website
JC

Bascom Member



Joined: 15 Dec 2007
Posts: 586
Location: Cleveland, OH

usa.gif
PostPosted: Fri Feb 05, 2021 6:33 pm    Post subject: Reply with quote

Sorry, unfortunately the correction to the Rainbow Library resulted in a typo error in the library.

The rb-LIB.zip file above is missing a # character in front of the

# If _XMEGA = 1

Adding the # character then makes it all work correctly!

Thank you, again, everyone, for your help!

JC
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Fri Feb 05, 2021 8:07 pm    Post subject: Reply with quote

sorry, i added it back in.
_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Goto page 1, 2, 3  Next
Page 1 of 3

 
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