Forum Index > Projects > LED Pegboard and Matrix Projects
 Meggy Jr: talking to the LED matrix
 |  Printable Version
By: Anonymous: denis () on Friday, July 22 2011 @ 09:51 AM PDT (Read 1929 times)  
Anonymous: denis

I'm digging into the Meggy Jr library to understand how Meggy communicates with the LED
matrix. I got the SPI and sink driver parts down, and the only thing I'm confused about is why
Meggy writes 0 to one of PORTD or PORTB to light up a row and 1 to turn it off.

My limited understanding tells me that it should be the other way around - 1 to enable, 0 to
disable and there's nothing in the schematic that tells me why you'd have to invert the values.
I had a suspicion that the transistors used to drive the matrix are normally on and you have
to apply voltage to them to turn them off, but that doesn't seem to be the case...

So, why do you have to write 0 light up a row in the matrix and 1 to turn it off? Here's the
relevant code from the Meggy library:

PHP Formatted Code

    //Turn display off:
    PORTD |= 252U;
    PORTB |= 17U;
 



PHP Formatted Code

    ////////////////////  Now set the row and latch the bits
    byte portbTemp = 0;
    byte portdTemp = 0;

    if (MeggyJr::currentCol == 0)
        portbTemp = 239U;
    else if (MeggyJr::currentCol == 1)
        portbTemp = 254U;
    else
        portdTemp = ~(1 << (9 - MeggyJr::currentCol));

    while (!(SPSR & (1<<SPIF)))  { } // wait for last bitshift to complete

    PORTB |= 4;         //Latch Pulse    

    if (MeggyJr::currentCol > 1)
        PORTD &= portdTemp;
    else
        PORTB &= portbTemp;
 





       
   
By: Windell (offline) on Friday, July 22 2011 @ 03:23 PM PDT  
Windell

The rows are switched on by high-performance PNP transistors, on the "high side" of the LED matrix. A PNP transistor allows current to flow from its emitter (connected to +V) to its collector (connected to the common anode of an LED row) when its base is pulled low such that current can flow from the emitter towards the base.

This polarity of driving is, for a good reason, standard for "high side" drivers, both in LED matrices and in situations like H-bridges for motors. It allows one to create a differential of up to several volts between the emitter and collector (to turn the transistor on fully), which you could not do if you were to use an NPN transistor on the high side.


Windell H. Oskay
drwho(at)evilmadscientist.com
http://www.evilmadscientist.com/

Forum Evil Scientist
Evil Scientist

Status: offline

Registered: 06/15/06
Posts: 1932
Sunnyvale, CA

Profile Email Website  
   
By: Anonymous: denis () on Friday, July 22 2011 @ 05:16 PM PDT  
Anonymous: denis

Thanks, Windell. I believe you have them marked as NPN in the schematic, though.

http://www.evilmadscientist.com/source/MeggyJrASchematics.pdf

I'm really enjoying tinkering with Meggy, great kit!





       
   
By: Windell (offline) on Friday, July 22 2011 @ 05:30 PM PDT  
Windell

>Thanks, Windell. I believe you have them marked as NPN in the schematic, though.

Well, they're not *supposed* to. Wink The schematic symbol there is for a PNP transistor, and the part number given is 2STX2220, a PNP transistor. (Just so you can remember, the symbol for an NPN has the arrow Not Pointing iN.) If you do see an indication there that it's NPN-- and I don't --please let me know and I'll fix it. Big Grin


Windell H. Oskay
drwho(at)evilmadscientist.com
http://www.evilmadscientist.com/

Forum Evil Scientist
Evil Scientist

Status: offline

Registered: 06/15/06
Posts: 1932
Sunnyvale, CA

Profile Email Website  
   
By: Anonymous: denis () on Friday, July 22 2011 @ 06:20 PM PDT  
Anonymous: denis

Not Pointing iN, lesson learned.

"Libraries are boring, I wanna twiddle the bits myself even though I can't tell the difference
between NPN and PNP!" Smile





       
   



 All times are PDT. The time is now 10:33 PM.
Normal Topic Normal Topic
Locked Topic Locked Topic
Sticky Topic Sticky Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Able to Post 
Filtered HTML Allowed 
Censored Content 

Evil Mad Scientist Forum Archives — Read only!

Please visit our new forums for new discussions.


DIY Hardware for Electronic Art


The Original Egg-Bot Kit


Octolively
Interactive LED kits


Meggy Jr RGB
LED matrix game
development kit.


Business-card sized
AVR target boards


Peggy 2
LED Pegboard kits

My Account






Lost your password?