Showing posts with label MSP430. Show all posts
Showing posts with label MSP430. Show all posts

Wednesday, January 12, 2011

ASCII Experimenter's Coding and Process, Part 1

First blog of the new year, I am excited.


All inventions start with an idea. That idea is grown over time into a design. The design is formalized and then you can start building, prototyping, discovering those things you may have missed and need to be fixed. That's where I am right now, redesigning portions of my little device. Originally I was thinking I could drive whole rows with the 74HC08's. These devices have a maximum current rating of about 25mA, which frankly isn't enough to run 4 x 20mA LEDs simultaneously. I say 4 because the 8 are split across 2 chips. Luckily I can still use them, I just need to be a bit creative.

By arranging my 2 shift registers (74HC164) in a rectangular fashion I can form a grid space of 64 states. Conveniently I have 64 LEDs I may be interested in driving, what providence! Now my 74HC08's can only drive 1 LED at a time each because the Red LEDs in my matrix run at 20 mA and I'd like to maximize this current flow for the effect of viewing the LEDs.

So if I shift in a 1 into both the row and column registers and set the OUT_EN, output enable (which ties into the 74HC08s), HIGH and then the first LED in the corner will turn on. The row register activates the current sinking transistor which will sink the current sourced from the selected 74HC08 pin.

So let's look at how to do this in code. Unfortunately I've skipped the process of designing and watching this code fail (a lot), so I will only be sharing the more decidedly interesting parts of the program in the articles to come. Most of which revolves around getting the data into the chip to begin with. Keeping in mind this is my first ever electronics project of my own design.

Right... code... I assume all I/O has been correctly setup (and I'll show this in the future) for now I'll make a little function called displayMatrix(), void return type and no arguments. Parameters are passed in global memory space (aka the stack). This function also relies on a delay function, which is a small tight loop to add a short delay of a couple of cycles, I'll include this as well:

#define LEDS P1OUT
#define OUT_EN   1
#define ROW_DATA 2
#define ROW_CLK  4
#define COL_DATA 16
#define COL_CLK  32
#define DELAY_TICKS 30

void displayMatrix(void)
{
        volatile unsigned int row;
        volatile unsigned int col;
        LEDS &= ~(OUT_EN | ROW_DATA | COL_DATA | ROW_CLK | COL_CLK); //Clear data and output enable
        LEDS |= ROW_DATA; //Set row data lines, start at row 1.
        LEDS ^= ROW_CLK; //Clock row data in
        LEDS ^= ROW_CLK;
        LEDS &= ~(ROW_DATA); //Disable row data
        for(row = 0; row < 8; row++) //Rows
        {
                LEDS |= COL_DATA; //Set column data, start at column1.
                LEDS ^= COL_CLK; //Clock column data in
                LEDS ^= COL_CLK;

                LEDS &= ~(COL_DATA); //Disable column data             
                for(col = 8; col > 0; col--)//Columns
                {
                        LEDS |= OUT_EN & (matrix[row] >> (col-1) & 0x01); //Enable output
                        delay();
                        LEDS &= ~(OUT_EN); //Disable output.
                        LEDS ^= COL_CLK; //Next column
                        LEDS ^= COL_CLK;
                }
                LEDS ^= ROW_CLK; //Next row
                LEDS ^= ROW_CLK;
        }
}
void delay(void)
{
        volatile unsigned int k;
        k = DELAY_TICKS;
        while(k>0)
                k--;
}

This does have some requirements, for instance due to the nature of the >> and & logic I use, it requires the OUT_EN (P1.0) to be the LSB. All other pins I believe are safe from this restriction and may be moved about at will, as long as you remember to setup the bits in the #define section correctly. Of interesting note, using the TI MSP430- Launchpad I originally used P1.3 for the COL_CLK, this led to a drastically unreliable display.

As it turns out, there is enough noise on this pin when using the launchpad to trigger the 74HC164 clock an extra time or more when transitioning! This noise is caused by a switch attached to that same pin [image to come]. Rather than adding hardware to fix this, I merely avoided it's use, though I do plan on using it with 74HC151 in the future on that pin, but it'll be as an input instead of an output.

This code turns on 1 pixel at a time and splits the entire on time across all 64 pixels, displaying or not. This gives it a uniform brightness which I believe is desirable. My question to everyone else out there.
Can you see a reasonable way to turn 2 LEDs on at the same time (only 1 per 74HC08)?
I have some ideas on how to do this too and I'm willing to spare another pin for a secondary OUT_EN2. Hopefully I'll get some updated schematics up soon too, to assist anyone interested in my design stuff! Thanks :-D

Thursday, December 9, 2010

IAR Kickstart and MSP430 Launchpad

Well, finally, my toys have arrived. And it's awesome. Naturally the first thing we did was say "Let's hook it up!" We performed the typical unboxing procedure:

1. Tear mail package into many small pieces, remove launchpad box.
2. Tear launchpad box into many small pieces, remove all baggies.
3. Tear anti-static bags into many small pieces, remove all components.
4. Ignore QuickStart guide entirely.
5. Google Getting Started with MSP430 Launchpad.
6. Plug things in without reading any results from search.
7. Lights turn on and off, make 'oooo' and 'aaaa' sounds.
8. Download IAR KickStart and install and try to increase LED duration etc using example code.
9. Realize you skipped a lot of steps and don't have any idea wtf you are doing...

So this was all great and fun, we wired the chip to some opto-isolators with some 1K resistors in series, then use a Darlington array and attach some motors and watch them spin up and down all the while giggling like grade schoolers in recess. Now to download a new program to the MSP430 so we can have a little more control over what's happening and leave H-Bridge design to the mechanical engineer (because this makes sense... right?).

H-Bridge design is less than successful, it rolls into 11pm and it's getting late. We're having issues with the IAR KickStart Software (PEBKAC). The mechanical engineer becomes derailed with gear and motor ideas forgetting entirely that the initial hope was to have a basic prototype within the same day. And now you could analyze the increase of personal tension as a third order derivative.

The issue with downloading the new images to the 430 is as follows:
Failed to initialize device
Well... wtf does that mean? Google yields lots of people saying "Use CCS," and "Make sure your drivers are correct." Not being particularly interested in the first option, due to preference and stubbornness, I check my drivers. Low and behold this is not where my problem lies. So I keep researching, keep researching, finding only more of the same garble... then in the comments on some forum somewhere I see it, the thing I should have known better, the thing that the getting started guides should have explained but didn't.
Project -> Options -> General Options -> Target Device
 Of course, I forgot to set my target device!  Somewhere, I would have thought, they would have mentioned this. But alas they did not, and hopefully if you're reading this you're kicking yourself the same way I did. But with the calm collected realization that your project can continue on. Then it was time to stop and sleep.

Sunday, November 14, 2010

Creating an ASCII Experimenter For Young Scholars

If you're not interested in my opinions on education, skip this paragraph. For those still reading, my boss at work, nice guy, has a couple kids in a Montessori School. Anyone who knows me personally, and this blog should now be included, knows that I hold this form of education in high regard. It seems to me that people of all ages have a natural desire to become better at the things they do. The drives to realize mastery in a skill change with age and the needs your individual has in a their environment. In children, if the given environment is one where most needs are met (ie. physiological, safety, community, and esteem) then a child can grow rapidly and approach intellectual maturity far beyond most adults. Yes, children are in their intellectual prime, and they are our future - share your knowledge with them.

Now, my boss asked if I could develop a device to assist in a lesson concerning binary and computation. I thought for a moment and realized that "Why yes, yes I can." I've always been a fan of near instant feed back. It's mostly why I work with computers. So here's the design needs for now:

1. 8 Bit data entry
2. Display corresponding ASCII character
3. Data entry needs to be easy enough for a child to use.
4. We're not all rich so it needs to be fairly cheap.

So here's the plan:
8 switches of some sort + 1 push button for "Enter" (Multiplexed)
8x8 LED Matrix Display
MSP430Gx2xx (TI Launchpad, for grins)

For the display, we'll use the matrix and we'll drive it with 2 8 bit shift registers (more info) and some AND gates for output enabling. The basic layout in my head looks like this:

Display Driver

Notice we feed the Row Select shift register CLK (outer wire at bottom) with the rising edge of the LSB of the Column Select shift register. This will allow us to do entries into the row select only when we're toggling the LSB of the column, this will present some interesting coding challenges.

Originally I didn't have the transistors in there, and then I kinda remembered that the row shift register won't be able to sink the sourced current of the column shift register due to being in high impedance. So we use npn transistors (3904 because I had a bag of them laying around) to sink the current, controlled by the row select shift register, and series in some 500 ohm resistors on the a collector side to protect our LED matrix (which by the way is the most expensive part of this project!)

For the input, due to I/O constraints on the MSP430 (10 pins), I'm thinking we'll use an 8:1 multiplexer which we'll layout kind of like this:


Data Input (8:1 Mutiplexer)


Notice we use the LSBs of the Column Select shift register to control the select lines of our 8:1 multiplexer, so we can address our 8 switches and to prevent the noise of shifting our select bits in, we'll just turn the OE off and voila no display for a fraction of a second while we poll for data when needed.

Now the MSP430 ties together with these other components to make a near complete schematic.
Whole circuit

When the pushbutton on P1.2 (at top, 1 resistor + pushbutton) is pressed, we'll read in the values through the mux, then we'll a display the corresponding ascii character. So in the next post we'll talk about the shortcomings (if I missed something) and the software to drive this groovy display. I may also look into how to get the chip to turn off the display peripherals when it's been inactive for a couple minutes, and other similar things.