View previous topic :: View next topic |
Author |
Message |
ofvy
Joined: 28 Jan 2006 Posts: 42
|
Posted: Thu Sep 21, 2023 7:40 pm Post subject: WS2812 rainbow example not working with atmega328p only with |
|
|
Hi .
I was testing a ws2812 LED strip. With an Arduino mini pro based on the ATmega168P the examples work well. But with the ARduino based on the ATmega 328P the examples do not work. It is not a hardware problem, I have tested the pins that I use to manage the LEDs with other programs and they work without incident.
Maybe someone has had a similar problem?
Greetings
The code with $regfile="m168pdef.dat" works:
Code: | '-------------------------------------------------------------------------------
' rainbow_ws2812_Demo_Softblink.bas
'This demo show RB_OrColor and RB_AndColor which can be used
'for a flashing LED with a fade effect.
'-------------------------------------------------------------------------------
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 64
$swstack = 64
$framesize = 64
R Alias Color(_base) : G Alias Color(_base + 1) : B Alias Color(_base + 2)
Config Rainbow = 1 , Rb0_len = 4 , Rb0_port = Portb , Rb0_pin = 2
' ^ connected to pin 0
' ^------------ connected to portB
' ^-------------------------- 8 leds on stripe
' ^------------------------------------- 1 channel
Const Numled=8
Dim Mask As Dword
Dim Fade as Byte
Dim Color(3) As Byte
Config Portb.2 = Output
'----[MAIN]---------------------------------------------------------------------
Print "mAIN 84"
Rb_selectchannel 0 ' select first channel
R = 0 : G = 0 : B = 0 ' define a color
Rb_setcolor 0 , Color(1) ' update leds
Rb_send
Wait 2
Print "lOOP"
Do
For Fade = 0 to 7
Print "1>" ; Fade
Waitms 100
Shift Mask , Left
Incr Mask
Rb_orcolor 0 , Mask
RB_Send
Next
For Fade = 0 to 7
Print "2>" ; Fade
Waitms 100
Shift MASK , right
RB_ANDColor 0 , MASK
RB_Send
Next
Loop |
(BASCOM-AVR version : 2.0.8.5 , Latest : 2.0.8.6 ) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5922 Location: Holland
|
Posted: Thu Sep 21, 2023 7:59 pm Post subject: |
|
|
The point of BASCOM is that it is using the hardware directly.
This means that you are supposed to use a bare processor without boot loaders or boards that might have various connections.
When you take an arduino board it probably has a boot loader. and there are many variants. also the fuses can be in some unknown state.
It is just fine if you use some cheap boards. Make sure to know how the fuses are set. At least the clock division fuse. Is it programmed or not?
And what kind of crystal does the board have? An external xtal or is the internal oscillator used?
The first test is always to toggle a LED at 1 sec interval to check that.
In your case it probably will not work because either your fuse, $crystal setting is different from what you expect.
When the code works on M168 it for sure will work on M328 too. But only after you made adjustments to the timing.
So yes this is a hardware problem. your hardware is not compatible since the fuse is probably different or the xtal.
in bascom a CONFIG exists to change the clock division to override the fuse value. you might want to try that.
but again, you need to know about your hardware : which oscillator is enabled. _________________ Mark |
|
Back to top |
|
|
ofvy
Joined: 28 Jan 2006 Posts: 42
|
Posted: Thu Sep 21, 2023 8:24 pm Post subject: |
|
|
Hi Mark.
Thanks for your prompt response.
Both cards operate at 16MHz. I added a Print statement to check that the output can be read in a terminal at the speed that was configured in the program and in both cases (atmega168p and atmega328p) the output can be read in the terminal.
I'm going to check the condition of the fuses as you suggest.
Kind regards |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5922 Location: Holland
|
Posted: Thu Sep 21, 2023 9:05 pm Post subject: |
|
|
when the baud is ok it means the $crystal is ok.
you best check the circuits of both boards and compare them.
something must be different. but again, do the led toggle first.
also, try on some other pin. it can be a bad connector or other hardware that interferes.
the provided sample should run on all AVR and certain M88, M168 and M328. But only under the same conditions. _________________ Mark |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Fri Sep 22, 2023 8:08 pm Post subject: |
|
|
To what pin did you connect the data line for the WS2812?
It's always confusing to what real port and pin the Arduino pin number is connected.
Portb.2 is Arduino pin D10 on the Arduino uno with M328P and also Pro mini. _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
|