Connect with us

Noob getting into it

Discussion in 'Microcontrollers, Programming and IoT' started by The Hammer, Sep 17, 2013.

  1. The Hammer

    The Hammer

    164
    0
    Sep 17, 2013
    I'm no noob to electronics, or hardware electronics. I am not exactly a veteran though. I've done my fair share of modifications, and hacks over the years. So, I'm working on a full sized keyboard circuit board and obviously now that I've designed the vast majority of my PCB I have to take a look at micro controllers. There's more to this question than that, so don't flip at my noob question yet! I will be using Cherry MX Brown key switches that have been modified to accept 2mmx5mmx5mm RGB diffused LEDs which being that I'll have 107 keys means that I will effectively have 321 LEDs that I want to completely independently control. I have no idea where to start with all this, although I have learned a fair chunk.. correct me if I'm wrong, but as far as actually dealing with the keyboard functionality just about any micro controller will work? You dedicate two of the pins for USB data, and program the chip somehow, right?

    So, here's my main questions so far for the tl;dr crowd:

    - 321 LEDs, 3 colors, how do I use a micro controller to control them all independently at 1/10 of their normal power, what kind of micro controller should I use, and are there any good examples? (PWM with some sort of other voltage control besides wasteful resistors would be my guess, but what can I do? Switching Voltage Regulators with PWM?)

    - 107 key switches, and I want all the F* keys to be able to switch to macro keys that can preferably be reprogrammed. There would be one key dedicated to doing the F* key/Macro key switching, another for Mute/Unmute, and the last for turning the LEDs on/off. I would prefer not to use a matrix, and just have each key go directly to the micro controller since those are the traces I've drawn out already. I'm not hell bent on doing that considering how much space that takes up on the PCB, but full N-key rollover is a must. Do I actually need a diode on each key in order for a micro controller to register the key? What are the benefits/negatives to having a diode? Do these diodes prevent any sort of double key press from the switch metals bouncing around inside of them somehow? What are my options for micro controllers?

    Maybe there's some sort of tutorial, or guide to micro controllers I don't know of yet, but there seems to be a HUGE amount of them available with next to no guides to getting started..

    In advance thanks for your time. :) I suppose I'm just lost, and looking for any help. :confused:
     
  2. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,214
    2,695
    Jan 21, 2010
    For controlling a lot of LEDs from very few pins of a microcontroller, check out the 74HC595 chip. Google that and your choice of microcontroller and you'll find more stuff than you can shake a stick at.

    There are other chips that do this sort of thing as well, but these are quite popular.

    I would suggest you use either a pic or an arduino, but there are many other options (including PicAXE). Each differ in their costs, ease of use, etc.
     
  3. The Hammer

    The Hammer

    164
    0
    Sep 17, 2013
    I'll assume you meant Google micro controllers such as the ones you listed after that, such as the PicAXE/Arduino/PIC. Can the same micro controller that's handling keyboard activity handle controlling the chips for driving the LEDs without a latency issue for the keyboard? Something tells me I want them separate.. :eek:

    The 74HC595 chip specs I was looking at doesn't seem to indicate that these chips do any sort of voltage control, and I'll need to supply about 1.9V (1-2ma) to 107 red LEDs, and two different other voltages for the 107 green and 107 blue LEDs. I'm still plowing through the data sheets for the chip, but can I apply any voltage (1.9V) to the Vcc line of a 74HC595 and have that go to the LEDs (aside from the obvious voltage drop from the chip itself)? I am trying to remove all the resistors from this circuit to increase electrical efficiency since it will be running from a 500ma 5V USB source. Is there any way to do that? :confused:

    Thanks for your help so far. You've set me on the right track again! Just need another couple noob pointers I suppose.
     
    Last edited: Sep 17, 2013
  4. Solidus

    Solidus

    349
    4
    Jun 19, 2011
    You can drive each output of the 74HC595 to a FET that gates the LED to the voltage of choice. A FET can take a 5V or 3.3V logic high at its gate but drive a lesser voltage at its output like 1.9V or so.

    As for more efficiency on the 5V/500mA source, I suggest you look into buck/boost circuits and their drivers. This will convert one DC voltage to another without unnecessarily blowing energy as heat.
     
  5. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,214
    2,695
    Jan 21, 2010
    Yeah, like "arduino 74HC595"

    If you do it right, the microcontroller will probably need to spend only a fraction of its time performing both of these tasks. They're pretty fast.

    The trick is, don't add delays to your code and don't poll things in a loop.

    Just place an appropriate value resistor in series with each LED.

    Removing resistors doesn't increase electrical efficiency. Also LEDs don't operate from specific voltages.

    200 LEDs operating at 2mA will be 400mA. That's within your spec. The microcontroller will need a few mA on top of that, not much more.

    There are complex ways to reduce the current required, but I don't think you need them.

    Are you really going to have all 200 LEDs on at once?
     
  6. Solidus

    Solidus

    349
    4
    Jun 19, 2011
    Elaborating on what Steve has said about latency -

    Keyboards and mouse movement typically operate by way of interrupts - that is, an action at a key or movement of the mouse interrupts the CPU to process that data immediately - thereby establishing first priority for that action.

    If you run the keys to an interrupt line on the microcontroller, it will process what key has been pressed first and worry about the LEDs only when it is free to do so. A 20MHz microcontroller can usually process a simple interrupt routine within 10 cycles (and that's a conservative estimate), which equates to about 0.5 microseconds every time a key is pressed. Even if you're the world's fastest typist, I doubt you'll notice any latency on the LEDs or keyboard provided the circuit is constructed correctly.

    To drive this point home, look at it this way. Every time a key is pressed on your computer, you are interrupting its CPU - stopping data processing, graphics handling, RAM access, the whole 9 yards - and it continues to operate at such a blistering rate that you never notice the setback.
     
  7. The Hammer

    The Hammer

    164
    0
    Sep 17, 2013
    Sorry for the long response time guys. Long day, and you gave me a lot of information to chew on.



    Which do you find to be a better option the FETs, or buck/boost circuits? I'm slowly running out of space on this keyboard PCB. lol It's only 5"x17.5", but the key switches require a lot of space. I have enough to do either I think, but what are the advantages/disadvantages to both?

    Gah, I also learned that using ExpressPCB was a big mistake. It's super easy to use, but they wanted $77 for two PCB that were only 4.5 square inches so that I could verify my holes were the correct sizes!!! I found other places that were like $25 for 4 boards! What gives?! Anyway, I have no way to transfer all my work to Eagle, although I can make raw Gerber files from it myself after much time spent with Google.. so lame.



    That's good to know, actually. Like I said I don't have infinite space to work with. lol Will the Arduino variety of the 74HC595 be better than the others somehow, or are all the 74HC595 chips from Arduino? I'm assuming I need something besides that chip such as the ULN2003 which changes the output from a 74HC595 from a positive output to a controlled ground? That's what I gathered that chip did from what this forum poster was depicting with the following image:
    [​IMG]



    Resistors waste energy as heat though, or is there some dynamic to coupling LEDs and resistors that I don't know about?



    I may very well drive them all simultaneously, but at the least I do want the option to drive all 321. With the LED matrix I'll make it should consume at maximum about 400ma. I want it to be capable of this to just show it off. Obviously, during it's normal use by me it won't be having the LEDs so crazy bright.

    This isn't what I've been lead to believe at all. These LEDs are "normal" 5mm RGB LEDs with a 2mmx5mmx5mm rectangular resin diffused casing so they fit with the Cherry MX switches way easier than the typical round 5mm LEDs. So they draw about 60ma for each LED (20ma each color) each at their respected voltage, but that's going to make me go blind and draw way more power for 107 RGB LEDs than a common USB 2.0 connection will be able to supply. 321 LEDs considering the separate colors in each LED.

    [​IMG]
    [​IMG]
    This is the datasheet I downloaded from the manufaturer.

    These are the only Forward Current/Forward Voltage charts I could find in the datasheet, and appears to be for the red LED for the graph. I have requested more information from the manufacturer of the LEDs. Unless I'm mistaken supplying 1.9 volts to the LED should essentially make it consume about 2ma of current, correct?



    These are some very true facts that I often forget, although I had thought that over USB the direct hardware interrupts were done away with for less "interfering" software ones.




    Thanks a ton for the help you've given me so far guys. You've been helping me out tremendously, and I'm almost finished! I'll be sure to post a build log of this sweet thing once it's done and put your usernames on the PCB somewhere. ;)
     
    Last edited: Sep 19, 2013
  8. Solidus

    Solidus

    349
    4
    Jun 19, 2011
    Either way, you'll need to go buck/boost or voltage regulators to generate the +1.9V, if you don't current-limit with resistors. Steve is probably correct in a practical sense that resistors won't dissipate a significant amount of heat, and it's also probably worth saying that I don't believe USB hubs on a computer are fused for exactly 500mA - that is, they can probably take a good amount over it - just don't expect 50A through them!

    However, buck/boost circuits are used where it would be too inefficient to try to cut out voltage using resistors or voltage regulators, i.e. processor supplies. Your computer PSU spits out +5V and 20-25A, but the CPU needs about 1.5V and much more current. Buck/boost converters are used to interchange the two when you don't have the full real-estate nor the extra power to be able to run full inverter circuits. Both are technically correct; buck/boosts admittedly would be more of a stretch for this kind of project.

    As for PCBs,

    Check out Laen's PCB service - HQ'd out of Portland, Oregon. They combine all orders and fab from a sheet to reduce prices - typically $5/sq.in. for double-sided boards, and you get three copies for that price.

    You're probably correct - USB most likely will call the interrupt instructions from the software side. Usually on the DIN-6 PS/2 connectors, the controller hub will flag the CPU INTR pin itself, although on modern processors that in itself is probably deprecated - I haven't seen an interrupt pin on an i7 yet! :rolleyes:

    Either way, you're not looking at significant latency, so don't sweat it.

    Also, the 74-series chips (74HC595) are shift registers; that is, they take a logical input, and shift it (visualize that as going from 11 to 110). They used to be used back in the day when processors were boards of chips, not chips.Their legacy lives on in the form of shift and rotate instructions - modern microprocessors and assembly instructions for processors make use of these instructions in crafty ways - a left shift by one bit (see the example 11 to 110) is the equivalent to multiplying the binary number by 2. For high-speed operations that need to be performed identically on many sets of data, use of tricks like this greatly improve processor efficiency.

    They work in this setting because by modulating the control line sequences, you can take a 1 (logical ON) and shift it through its various outputs, thereby getting a lot more output for a lot less input. Hope that is a rudimentary clarification.
     
    Last edited: Sep 20, 2013
  9. The Hammer

    The Hammer

    164
    0
    Sep 17, 2013
    So I have a question dealing with powering all of these LEDs. Obviously, I'm going to have to create a matrix for them 10x11 lines for 110 LEDs. I decided to add two more LEDs for the longer space bar, and one to light a logo after seeing other keyboard designs Obviously I'm going to need to use a buck circuit to create 2 or 3 separate voltage lines. 1.9 volts for the red LEDs, and I'm guessing 2.9 volts for the green and blue. I'm still waiting on the manufacturer to get back to me with better datasheets.. they're pretty unprofessional and annoying the crap out of me with their inability to use Google translate to increase business.. off topic, sorry. I'll need to use bi-polar junction transistors to allow the 1.9v and 2.9v buses to reach the LEDs I'm assuming. Essentially it'll go like this:

    micro controller > 74HC595#1 > resistor
    . . . . . . . . . . . . . . . . . . . . . . . . . V
    USB 5v > buck circuit 1.9v > transistor > LED > ULN2003 > 74HC595#2 > micro controller
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . V
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . USB ground

    Except that's going to have to be applied to a matrix circuit a little more complex than that. Something like this:

    [​IMG]

    I'm kinda lost with the buck circuits as far as how to go about designing them since I have only the most bare knowledge of magnetics and they seems to require a magnetic coil. I don't even understand half the math that's going on in designing these circuits as described in this guide to buck circuits that I was reading. I kinda wish there was an easy tool to input voltages, and get a circuit schematic design that I could just buy components for..

    So far I have found the MAX8640YEXT19+T-ND package for the 1.9v variety in my Google searches, but obviously I need a slightly higher voltage variety to deal with the transistor voltage drop, and some additional circuity to go about making this buck converter work.

    Am I on the right path here?? :confused:
     
    Last edited: Sep 21, 2013
  10. The Hammer

    The Hammer

    164
    0
    Sep 17, 2013
    I guess I should be using the ULN2803 since those are the 8 pin variety of the ULN2003.. To be honest I'm not sure why that one example was only using the ULN2003 even if they only did need 7 pins I really doubt the cost difference is worth losing a more valuable reusable part.

    Anyway! This was a fantastic video to watch to learn how shift registers work, by the way!

     
    Last edited: Sep 21, 2013
  11. The Hammer

    The Hammer

    164
    0
    Sep 17, 2013
    I made an EXTREMELY terrible logic design of what I think I need to do.

    Obviously there's a couple pins completely unattached. Are there any other parts I can use for just 2 or 3 pins like the ULN2803 and 74HC595?

    Can anyone tell me if this will work, or anything about the buck converters that might help? :confused:

    [​IMG]
     
    Last edited: Sep 21, 2013
  12. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,214
    2,695
    Jan 21, 2010
    OK, we're multiplexing now are we. (330 LEDs?)

    To drive them without multiplexing you will need 42 74HC585's, and 330 resistors. And some VERY simple programming. But it's a lot of chips and lots of wiring.

    Multiplexing is going to have it's own problems, but to make it simpler, I would recommend you make your array narrower so that you can reduce the peak current to the LEDs and increase the time each LED is on. This has the advantage of reducing electrical noise and making your code a lot less time-critical.

    If you have 8 rows (these will require a single 74HC595 and a ULN200x) by 42 columns (6 x 74HC595's and 42 resistors) then you will minimise both the

    The LED current can be switching speed and the number of devices. It also has the advantage that for an average LED current of 1mA, the LED current can be set at 8mA which is safe if the multiplexing ever stops.

    You should also note that the 74HC595 is a latching shift register. You can shift in all the bits and then set them in one operation. This allows the next row to be set up whilst the current row is being displayed, so the row setup does not need to be done especially quickly.
     
  13. Solidus

    Solidus

    349
    4
    Jun 19, 2011
    I'll work up a schematic in a little bit if I can get Eagle to like me, so you can have a starting point.
     
  14. The Hammer

    The Hammer

    164
    0
    Sep 17, 2013
    Your message kinda cut off there? :confused: Fewer rows will help me how? Will it make the LEDs brighter some how? Will I get flicker with the way I'm going? Won't that mean that I'll be getting closer, and closer to what the ULN2803 will be able to drain? I was reading that the tech in them is hindered by the package they're in due to heat build up, so they are very rarely close to what the spec sheets say. To make matters worse I went with the smallest available package I could find. :(

    Anyways, I'm not worried about providing higher peak current to them considering even at the "peak" current I'm going to drive them at will be far, far below what the normal current for these LEDs are.

    Thanks, but I think I've gone a bit further than you were willing to already! I made my own custom packages for the ULN2803 SO-16 chip, the 74HC595 TSSOP-16, and Cherry MX switches. I incorporated a diode and an RGB LED in each key to keep things simpler over all. I'm nearly there, but now I have to figure out what kind of micro controller to use with all this! I'm still a bit lost with that considering everything I've learned about electronics I've been swamped (my brain almost hurts :p) I'm going to need a really good one I think.. I have a couple odd things that I'd like the keyboard to do if possible. Such as programmable macro keys, and reactive key colors.. ect.. ect..

    Anything you can suggest to me while I'm working so I don't waste time? :)

    Oh, and once I'm done working on this, and clean it up really nice I'm going to provide the library files for Cherry MX switches, and the other two chips here so that someone else doesn't have to spend an entire hour and a half messing with it.. I could not find ANYTHING that worked in terms of usable libraries for Eagle. You would think it wouldn't be so hard to find..

    [​IMG]
     
    Last edited: Sep 23, 2013
  15. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,214
    2,695
    Jan 21, 2010
    Yeah, they do tend to stop at the end. I'll try to make this one continue on a little after the end.

    Yes, it will help you get brighter LEDs (but that's not your concern).

    And it will allow you to process the entire array slower. That means less noise, and less difficulty in writing the code to do the multiplexing.

    Actually, the peak current for the ULN2803 will remain approximately the same.

    for an average current of 1mA, the 42 LEDs will require a maximum of 42 * 1 * 8 mA (the 8 is because they are multiplexed 8 ways). This is 336mA.

    I think you were talking about an 18x18 grid last time.

    For an average current of 1mA, 19 LEDs will require a maximum of 19 * 1 * 18 mA. This is 342mA.

    The power dissipated in the ULN2803 will be higher because each output is on for 1/8 of the time rather than 1/18th of the time.

    Keeping at least one dimension a multiple of 8 will make programming simpler too.

    See if the package allows a single output to carry 350mA. If it can, you're fine. The row drivers are only ever active one at a time.

    Point me to a datasheet and tell me what package you have and I'll double-check.

    true.

    edit: but it does save you a couple of chips. and more fully uses the ones you do need.

    And here is the extra I promised:

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
     
  16. Solidus

    Solidus

    349
    4
    Jun 19, 2011
    Would you like me to work up the buck circuit and controller for you?

    In the holy war of Atmel vs. Microchip, I tend to stick to AVRs, so my recommendations will be among that realm. I know the standard AVR-8s go up to about a TQFP-100 (the ATmega2560 and such), so if you need more I/O real estate you can step up to the AVR32 series. I've never specifically coded in AVR32 programming, but for the most part it should be fundamentally similar. The '32s go up to around 144-p QFPs, and there are BGA256 varieties if you're feeling brave, although they may have been EoL'd. I can look into that more if you'd like.

    An advantage to using AVR32s is they are much higher speed (66MHz compared to the AVR's 20), and they have a lot more "headroom" in terms of processing capability - they can do a lot more, so if you're crunched for time and data processing, they may be a good choice.

    The macros/reactions will be handled within code. If your code gets too large (too many features :p) you can offload some of that to SPI flash that is linked up. That being said, I've never written a program that ever challenges 256KB of flash on-chip, and I've written designs that control RF transceivers, displays, and a whole lot of other stuff. You can get a long way with code like this:

    Code:
    if ( MACRO_KEY_ENABLE && MACRO_# )
    {
            // Insert function of that Macro key
    }
    
    if ( KEY )
    {
            // Insert LED reaction code if KEY is pressed
    }
    
    (One will notice I returned Booleans!)

    And Steve, you're making me feel left out of the collective circle with that Latin of yours! haha
     
    Last edited: Sep 24, 2013
  17. The Hammer

    The Hammer

    164
    0
    Sep 17, 2013
    I'm not sure what you mean by less electrical noise exactly, but I assume you mean generally speaking less frequency in shifts between rows which will allow things more time to error correct? I have no idea when it comes to micro controllers, so maybe that's what you meant? I will try and work this in after I finish with my current setup, but I'm just not sure that I have that kind of space on the board. Even though the board is 17.5"x5" there are so many holes in it, and unusable space on top with all the key switches that it takes up a lot of real estate. If I can make this better like you said, then I'll give it a shot.


    Yes, actually an 18x19 grid where one line was not completely filled with 3/4 of the possible LEDs.


    Interesting. I had thought the math would add up to be a lot worse, but I hadn't actually sat down and figured it out.

    This link is a datasheet to the package I was going to use for the ULN2803 darlington array.

    This one is a datasheet on the 74HC595 I was planning on using.

    I kinda forgot where I got them already, but I can sift through my downloads to figure it out.


    Ha! Thank god for Google translate. Although, I still have no idea what it's supposed to mean. Electronics are more like Chinese to me though. At least I understand the symbols when it comes to Latin. ;)

    "我们将是很重要的,有趣的,但因为偶尔的情况下发生的辛劳和痛苦促使他一些伟大的。举一个小例子,我们曾经进行费力的体育锻炼,除了取得一些优势。目前,我们在火车上与生产没有得到的乐趣是在线应用来指手画脚。这些情况是完全的系统故障,他们是在离开车间奎艾软化建议您"


    YES! Yes, please! Though I am not sure of all the voltages I need yet! I'm still waiting on the companies I contacted to get back to me with better data sheets. Goddamn awful Chinese customer service.. I may not be able to figure it out until I get the LEDs and play around with them. :(

    Though I'm positive I will need about 1.9V for one of the LED colors (red), but take into account that this will need to go through a transistor before hitting the LED. That may make me need additional voltage on each line. I haven't had the time to figure out what type of transistor I should use.


    See, since I had to start from scratch in Eagle, because ExpressPCB sucks, I decided to go for a matrix for the keys as well. So, I'm thinking that so long as I get a super fast controller that can handle both matrices I should be set. I would have preferred to save some PCB space without the diodes for each key, but the space I'm saving is about the same as I'll be saving for having a smaller amount of I/O pins on the micro controller.

    That part is the next step after the hardware I'm putting together, and that's really good to know. I know the coding language is very low memory, but I really wasn't sure what I should watch out for. I'm glad that I have room to work! I haven't programmed micro controllers before, but I do have experience with PHP, Java, and several other things in a minor way. I figured it wouldn't be too hard aside from paying attention to specific programing items to watch out for. Like with returning Booleans like you were talking about. :)
     
  18. The Hammer

    The Hammer

    164
    0
    Sep 17, 2013
    Would there be some way to develop a program that can program the micro controller based on color/color function, and desired macro keys? Something that's a little easier than typing all the code out, and programing it myself. What kinds of controller would I be looking at in that regard?
     
  19. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,214
    2,695
    Jan 21, 2010
    Every time you switch the LEDs on and off you generate electrical noise that can interfere with other electronics.

    If you do it less, you generate less noise.

    Less is better.
    :)

    "Lorem ipsum..." is a standard set of text used by typesetters for several centuries as a placeholder. It has its roots in a 45BC document by Cicero ("The extremes of good and evil"). It deals with the theory of ethics and was apparently very popular during the renaissance.

    It certainly loses something in the multiple translation!

    You'll be in a world of hurt if you intend to operate the LEDs from a voltage source. You understand that LEDs should not be operated this way. At the very least (and this effect is magnified at low currents) you'll have significant variability in brightness between LEDs.

    You're starting a massive project for someone without the required experience.

    I would recommend you breadboard something with perhaps a couple of keys and a couple of LEDs (wire up some corner of your matrix). From this you can write code that addresses the entire matrix. You can learn how to do it, perhaps decide you need a larger microcontroller, and figure out any design flaws before you have committed yourself to something that may not work.
     
  20. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,214
    2,695
    Jan 21, 2010
    Other than getting someone else to write your program... Probably not.

    On of the tasks you have is to learn to write efficient and elegant code.

    ...And of course, programming the microcontroller.

    You need to become familiar with how to do this. Have you programmed an Arduino (or similar) before? If not, I'd get one and play with it so I knew what to do.

    You may end up having an atmel microcontroller embedded in your board, so you need to know how to write code to one that doesn't have a bootloader on it. That also means you need to know how to set up the appropriate programming interface on the board.

    A similar (but different) protocol exists for PIC microcontrollers
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-