Jump to content

led matrix - program code?


*jOi~
 Share

Recommended Posts

hey guys,

ive just finished building my little LED matrix, for some fancy response from my computer.

planning on making it display a few things from ableton live, as well as doing some fancy visuals from max/msp..

but nonetheless, i've hooked it all up similarly to the matrix from the SID (8x8 though), as the SID LED diagram shows. I'm now however struggling to cut down the code to what I actually need. I found the SID matrix test in the downloads section of ucapps, but I'm a little unsure of how to adapt it for 8x8 and not 7x8.

im much more of an electronics person, than programmer... still trying to learn these things, but its just a little over my head atm.

there is currently nothing else connected to the core, and I really want it to be refreshed as fast as possible - though right now, i'd be happy just to see my little LEDs light up.

cheers for the suggestions guys,

trent

Link to comment
Share on other sites

After a quick look at that code, it looks like it already handles 8x8. You probably could cut out some unused bits of cs_menu_matrix.inc but there's no real point as it does what you want already. If it ain't broke, don't fix it.

Wire it up like in the MB-SID step C connection diagram, and then change which shift registers you are using, most likely you only have two connected so in main.asm:


;; define the shift registers to which the LED matrix is connected
;; (note: HERE the shift register begins with 0: 1st SR is 0, 2nd is 1, 3rd is 2, ...)
#define MOD_MATRIX_ANODES 6 ; shift register with anodes (HERE: 7th shift register in the chain)
#define MOD_MATRIX_CATHODES 7 ; shift register with cathodes (HERE: 8th shift register in the chain)
[/code] replace 6 with 0 and 7 with 1. Further down, change 56 to 64:
[code]
;; increment counter, wrap at 56
incf LED_SELECT_CTR, F
movlw 56
IFGEQ LED_SELECT_CTR, ACCESS, clrf LED_SELECT_CTR
Note this is just some sample code that appears to turn on one LED at a time, cycling through them all, i.e. you don't need this counter to do what you want later. The code in cs_menu_matrix.inc manages turning on LEDs in a single row and incrementing the row counter. Once you've got this demo working, replace this code with just:

USER_SR_Service_Prepare
;; branch to LED Matrix code
goto CS_MENU_MATRIX_Handler
[/code] You should also clear the matrix in the USER_Init routine:
[code]
;; clear LED matrix
clrf CS_MENU_MATRIX_BEGIN+0
clrf CS_MENU_MATRIX_BEGIN+1
clrf CS_MENU_MATRIX_BEGIN+2
clrf CS_MENU_MATRIX_BEGIN+3
clrf CS_MENU_MATRIX_BEGIN+4
clrf CS_MENU_MATRIX_BEGIN+5
clrf CS_MENU_MATRIX_BEGIN+6
clrf CS_MENU_MATRIX_BEGIN+7
Then elsewhere (perhaps in USER_MPROC_NotifyReceivedEvent) you should toggle bits in the registers CS_MENU_MATRIX_BEGIN+0 to CS_MENU_MATRIX_BEGIN+7 (each byte is a row of the matrix). You'll have to learn enough assember to do that bit yourself. In short, you're probably wanting to turn a number like 0-63 into the byte to change (CS_MENU_MATRIX_BEGIN+0 to CS_MENU_MATRIX_BEGIN+7) and a bit within that byte. The code in the demo does this already:

lfsr FSR2, CS_MENU_MATRIX_BEGIN
movf LED_SELECT_CTR, W
andlw 0x07
addwf FSR2L, F

rrf LED_SELECT_CTR, W
rrf WREG, W
rrf WREG, W
andlw 0x07
call MIOS_HLP_GetBitORMask
movwf INDF2
[/code]

The register LED_SELECT_CTR is used to calculate which byte to change. You'll need to adjust this to suit your purposes, and learn about using a mask to toggle one bit in a byte. Basically you will need to understand how this little bit of code works, using indirect registers to change one register in a register range, i.e. called an array in other programming languages.

Link to comment
Share on other sites

hey wilba,

thanks for the help, but so much of that went over my head. ive been reading through the code and things are very slowly starting to make sense how they work, but i doubt i can do it by staring at the code for days.

do you have any suggestions where would be the best place to start in getting a grasp of the assembler code? any sites or something where i might find some lessons?

thanks for the help, and for the suggestions, i only hope i can understand them soon!  :P

nonetheless, i got the leds to turn on with the led digits sample program, so that was quite exciting...

cheers

trent

Link to comment
Share on other sites

I've had the advantage of being a programmer long before looking at PIC assember... and then I basically learn by looking at the code, looking at the PIC datasheet to see what each instruction does, and then understanding what the code does.

If you think you could grasp C better than assembler, perhaps try using the C interface to MIOS, although I don't yet and have no idea how hard it is to setup. At least with assember, what you write is what you get, down to individual instructions on the CPU.

But even though assembler is a bit harder to code than C, it is also all you would need to know, and learning C is just another level of stuff that you don't need just to get your creation going.

Why don't you tell us a little more about what you're trying to achieve, because you might be able to use, with a little modification, some existing MIOS application. If it is quite generic and might be a useful demonstration application for others (and it wouldn't take too long to write) then maybe I can quickly hack together the basics to show you how it's done. Then it's up to you to learn assember and customize it to your specific needs.

Link to comment
Share on other sites

Thanks for the thoughts, and it's so wonderful to have people here so willing to help and teach.

Essentially ive got 2 dout registers setup just like the midibox SID matrix except 8x8. The aim of the application is to create a 1bit digital display that can be controlled via MIDI messages.

Im using MAX/MSP to control the output, but just need a way to discretely access each LED separately. Really it's just a quick reference of specific things, like output monitors for 8 different tracks, or for equalizer display, or spectrum analysis etc. Most importantly though I just need a way to address each LED, whether it be each row on a separate channel, or simply just 0-63 like you had mentioned earlier.

Writing up the mios_table file is at least part of what I need to (if i understand correctly), but it's the handling of the matrix that I don't know enough about.

If you have the time to write up a short sample for me to have a look at, that'd be fantastic just so i can get a little insight as to how to approach the code. Looking at the other example apps has been good, but they're all more complex than I think I need, and I can't help but get lost in all the code.

Nonetheless, I will try to hack through a bit more tomorrow.

Cheers,

Trent

Link to comment
Share on other sites

Essentially ive got 2 dout registers setup just like the midibox SID matrix except 8x8. The aim of the application is to create a 1bit digital display that can be controlled via MIDI messages.

Im using MAX/MSP to control the output, but just need a way to discretely access each LED separately. Really it's just a quick reference of specific things, like output monitors for 8 different tracks, or for equalizer display, or spectrum analysis etc. Most importantly though I just need a way to address each LED, whether it be each row on a separate channel, or simply just 0-63 like you had mentioned earlier.

OK, that sounds pretty easy, but you need to give more detail about how each LED is going to be turned on and off. I have no idea what protocol MAX/MSP uses for external control of hardware like this. Maybe it's as easy as MIDI Note On/Note Off events with the note being the LED. If that's the case, it's easy to hook it up to the same LED matrix demo program.

Writing up the mios_table file is at least part of what I need to (if i understand correctly), but it's the handling of the matrix that I don't know enough about.

I don't think you need to do this. The MIOS tables would be used if you were not using a matrix, if each LED was connected to its own DOUT pin, and you wanted MIOS to process the MIDI event and turn on/off the LEDs. Since you are using a LED matrix, you would have to do the MIDI event handling yourself. Turning the note number into the index of the LED to change is pretty simple.

Link to comment
Share on other sites

In MAX you can simply address the LEDs as MIDI note-ons. That's how I ran my first prototype of only 8 LEDs. If you don't think the tables are neccessary than all the better!

Argh.. you make it sound so easy, which makes it that much more frustrating that I'm just sitting here staring at the screen with no progress.. haha

Oh well. thanks again for the help.

Link to comment
Share on other sites

Argh.. you make it sound so easy, which makes it that much more frustrating that I'm just sitting here staring at the screen with no progress.. haha

Well it is easy if you write code for a living and started programming when you were six.

But I still don't fully grasp analog electronics... which I started at the same time.

Anyway, when I get a bit of spare time I'll bash out something to help you out... although I won't have the hardware to test it... just PM me your email and we'll take this outside the forum and not bother all these other nice people with our rambings.

Link to comment
Share on other sites

I think a real monome clone using a LED matrix and button scanning matrix should be done via a patch to MIDIO128. I mean you could do it now with 8x DOUT and 8x DIN... but with a LED matrix and button scanning matrix, you can do it with just 2x DOUT and 1x DIN, where one DOUT is both the current sink of the common cathodes of one LED row/column and also the sink to ground for one row/column of switches. I'm using this technique for my new MB-SID control surface PCB...  ;D

Link to comment
Share on other sites

Well I can say a huge thanks to Wilba for helping me out with that code! It's working on a grass roots level, and after I figure out how it works I'm sure it'll do more than I think.

I've got the hardware here to do a hacked monome, with my switch matrix just needing to be attached to the registers, along with figuring out how to integrate that scanning matrix demo on the ucapps page with this wonderful little led matrix handler.

When I get some time (Uni exams this week) I'll try to put together a program that allows full control.

I do just want to say though, that Brian Crabtree (the mastermind behind the monome) has been a wonderful help to me, and I encourage you to think about buying one for the look and feel alone! I'm just waiting for the 16x16 to come out...

trent

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...