Help with altering borrowed code

2gttalon

New Member
I have borrowed some code from Ken Lee with assistance from Hippy. The code was originally for 20 LEDs but i have fgured out how to change it for 32 LEDs. Now i am looking to figure out the addition of other colors. It is primarily red/blue/green currently. I would like some yellow/orange, purple, white....etc. I am very new to picaxe but seem to be learning quickly on my 08m2 with protoboard. Could someone help me understand it better ?
 

Attachments

hippy

Ex-Staff (retired)
The code outputs data held within the PICAXE RAM so all you need to do is to set the values you want in RAM, then call the 'Send_LED_Data' routine. The best example already in the code is ...

for b1 = FIRST_LED to LAST_LED step 3
:
bPtr = LED_NUM + BLUE: @bPtr=FULL
bPtr = LED_NUM + GREEN: @bPtr=FULL
bPtr = LED_NUM + red: @bPtr=FULL

Instead of FULL set whatever values are required to get the colour you want.
 

2gttalon

New Member
I have come far since the last post but could use some help. I have been battling an issue for about 3 months and i do not want to give up. Can someone look over this code and teach me how to convert it to run 78 LEDS ? I have tried the following things in parenthesis next to each line.

'Define Constants
Symbol LED_TOT = 32 'Number of LEDs in pattern (tried just switching this to 78)
Symbol RAM_START = 256-96 'Start of RAM Storage for 20 LED Data sets. 3 bytes per LED in order BGR (tried changing to 256-234)


If anyone can offer any tips or tell me is this is even possible you will make my day.

using 08m2 with picaxe proto board with 5v 1A supply. strip i am using has ws2801 IC
 

Attachments

lanternfish

Senior Member
Hi 2gttalon

I have been out of touch with the PICAXE for a while but can help a litle bit with your problem, I hope!

Your code:

Code:
Symbol LED_TOT = 32		'Number of LEDs in pattern   (tried just switching this to 78)
Symbol RAM_START = 256-96 	'Start of RAM Storage for 20 LED Data sets. 3 bytes per LED in order BGR (tried changing to 256-234)
would become, as you have suggested:

Code:
Symbol LED_TOT = 78 	'Number of LEDs in pattern   (tried just switching this to 78)
Symbol RAM_START = 256-234	'Start of RAM Storage for 20 LED Data sets. 3 bytes per LED in order BGR (tried changing to 256-234)
as 78 x 3 = 234.

The problem I think you now have is that you will used up ALL the available RAM in the 08M and so it no longer has room for the stack and a few other variables. Of course I could be completely wrong!

Cheers
 

2gttalon

New Member
Hi 2gttalon

The problem I think you now have is that you will used up ALL the available RAM in the 08M and so it no longer has room for the stack and a few other variables. Of course I could be completely wrong!

Cheers
Thank you for the comments. What Micro controller would allow me to easily continue with his code a have enough ram to support my requirements. One thing that just clicked to me looking at the other models is that the 08m2 says 128 bytes ram on this chart but runs 256 in my code. That doesn't add up to me. So correct me if i am wrong, but it looks like the next model 14m2 should run what i am trying to do.

Feature 08M2 14M2 18M2 20M2 20X2 28X2 40X2
Memory Capacity (bytes) 2048 2048 2048 2048 4096 4096 4096
RAM (bytes) 128 512 256 512 256 1280 1280
 

lanternfish

Senior Member
Hi

Not sure about why the 128 bytes vs 256 bytes thing works. Does it really work okay or is it a fluke? Maybe wiser heads have the answer.

If you move up to a 14M2 and change:

Code:
Symbol RAM_START = 256-96
to


Code:
Symbol RAM_START = 512-96
you should be fine.
 

hippy

Ex-Staff (retired)
Not sure about why the 128 bytes vs 256 bytes thing works. Does it really work okay or is it a fluke?
Both. Not sure how it came about but probably in moving the code for a different PICAXE to 08M2 no one spotted a change was required.

Because the PICAXE truncates values, the 128 byte RAM can be addressed 0 to 127 or 128 to 255 etc. 256-90 is the same as 128-90, both use RAM at locations 38 to 127.
 
Top