CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Driving a LED bar
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

Driving a LED bar
PostPosted: Sat Apr 09, 2005 10:37 am     Reply with quote

Hello,

I want to build a digital meter, its output will be shown with a 20 led bar.

I don't want to waste many outputs with this, so a multiplex scheme/chip will be needed.

How would you drive a 20 led bar?

Thank you.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sat Apr 09, 2005 11:11 am     Reply with quote

You didnīt mention what PIC are you going to use, if it has a built in ADC or not.
If you don't want to use many pins, you will need a serial-in/paralell-out
IC with latched outputs and the code will depends on how do you want to
show the bar, a solid bar or a shifted dot.

Tell us more details regarding your hardware.

Humberto
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Sat Apr 09, 2005 11:24 am     Reply with quote

Well, there is no harware yet.

It is a solid bar, it must be digitally driven.. a DAC + lm3914 is not enough.

The data comes via serial port, so ADC is not needed.

I want to use the PIC18F452 and many pins will be used for other things.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sat Apr 09, 2005 2:00 pm     Reply with quote

Ok, we have more info now but not enough.

1) What kind of info is coming in the serial port ?
2) The magnitude you are going to show is linear or log ?
3) Signed or unsigned.

Once you know that, you will know also what is the max expected
value. Dividing the max expected value in 20 increments you get ONE step.
Then it's a matter of calculate how many steps represent each received value.

Humberto
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Sat Apr 09, 2005 2:53 pm     Reply with quote

The serial port routine is not the problem, neither the others...

What I am asking is from the PIC port to the 20 leds, certainly I could use 20 pins and drive the bar but they are not available.

I can write the mux routines, the routine to generate the 20bit pattern and everything else.

So the question translates to hardware architecture, ways to use less pins and don't be expensive.
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Sat Apr 09, 2005 3:16 pm     Reply with quote

CD74HC/HCT299 8-bit Universal Shift Register. Search for it on digikey.com. Cheap (about $.70 US), but you'll need quite a few pins on the PIC to drive 3 of them, even though you'll be able to mux their data lines together. The really nice thing about this chip is that it can shift right or left, ideal for creating an LED bargraph.

There is also a '194, 4-bit version of the chip.

If you want to use as few i/o pins as possible, then you can use the SN54/74164/LS164 series of serial in/parallel out shift registers. No choice of shift direction, but it shouldn't be a problem if the shifting is done quickly - the user shouldn't be able to see any flicker of the bargraph. They run about $.50 US or so.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sat Apr 09, 2005 7:21 pm     Reply with quote

Quote:

The serial port routine is not the problem, neither the others...

What I am asking is from the PIC port to the 20 leds, certainly I could use 20 pins and drive the bar but they are not available.
I can write the mux routines, the routine to generate the 20bit pattern and everything else.
So the question translates to hardware architecture, ways to use less pins and don't be expensive.

This had been answered in my first post:

Quote:
If you don't want to use many pins, you will need a serial-in/paralell-out IC with latched outputs.


I believe you will translate this to the specific IC like 74HC595 or whatever you want.

Humberto
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

PostPosted: Sun Apr 10, 2005 1:07 am     Reply with quote

future wrote:
Well, there is no harware yet.

It is a solid bar, it must be digitally driven.. a DAC + lm3914 is not enough.

The data comes via serial port, so ADC is not needed.

I want to use the PIC18F452 and many pins will be used for other things.


If required, there is a CCS driver for the 74595 family, 74595.c

For hardware, I have used the HDSP-4830 ten-led HE (high efficiency) red bargraphs.
These can be joined together for a larger display - in one project I used four.
The bargraphs were mounted on the solder side of the pcb and poked through the front panel.
The led resistors were 680 ohm (eight in each DIL package).

Coding is pretty straightforward.
1. Scale input value to the number of leds.
2. Shift a '1' left by this scaled value (in an int32 variable).
3. Subtract 1 from the int32 value - this will clear the top bit and set all the lower bits as required.

The moving spot (dot) case is a bit different.
1. Scale input value to the number of leds minus one ( this is the number of gaps between the leds).
2. Shift a '1' left by this scaled value (in an int32 variable).
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

PostPosted: Sun Apr 10, 2005 8:35 am     Reply with quote

You have asked about scanning/mutiplexing an array, so I'll try to handwave my way through a quick description. Since you want 20 LEDs, your array could be 4 by 5. This will require 9 pins on your processor. We will assume that the LEDs do not have integral resistors. This will be a requirement actually, since when scanning, the current must be higher that in a continuous application.

Here's the hardware description:

To do this properly, you will need a PNP pullup transistor such as a 2N3906 for each of the 4 columns, and an NPN pulldown transistor such as a 2N3904 for each of the 5 rows. To make visualization easier, let's scan the columns. To keep the description simple we will use a resistor with each LED. It is possible to simplify this by using a single resistor for each row, but let's keep this simpler for now. Let us also set up the resistor/LED series pair with the resistor connected to the Anode of the LED.
Now connect up the matrix. Connect the emitters of the PNPs to +5 and the emitters of the NPNs to ground. Connect the bases of each transistor to a processor pin through a resistor (something around 2k perhaps). When you initialize the processor, the PNP drive pins should idle high and the NPN drive pins should idle low. Now connect the open pin of the resisors in the first column to the collector of the first PNP transistor. Then the open pin of the resistors in the second column to the second transistor, etc. Next, connect the Cathodes of the LEDs in the first row to the collector of the first NPN transistor. Then connect the Cathodes of the LEDs in the second row to the collector of the second NPN transistor, etc.

To drive the matrix, just turn on (high) the pattern you want in the rows, then pulse (low) the column. After the column is turned off, turn on the pattern for the next column in the rows and pulse that column and so forth. You will need to experiment with the scanning frequency to reduce flicker. You may need to add some dead time between columns to reduce shadowing or ghosting of one column into the next. Also, you will need to look at the specs for your LEDs to see how much current is allowed when scanning. You may need to set the resistors such that about 4x the current is used since the LEDs are only on 1/4 of the time.

Hope this helps. Let us know how it turns out.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Apr 10, 2005 9:50 am     Reply with quote

Hi Charlie U,

You just wrote a bright and very descriptive method on how to drive a
LEDīs array matrix, but future ask for this:
Quote:

its output will be shown with a 20 led bar

Hope you donīt missundertand my comments. Very Happy

Best wishes,

Humberto
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sun Apr 10, 2005 10:09 am     Reply with quote

Humberto wrote:
Hi Charlie U,

You just wrote a bright and very descriptive method on how to drive a
LEDīs array matrix, but future ask for this:
Quote:

its output will be shown with a 20 led bar

Hope you donīt missundertand my comments. Very Happy

Best wishes,

Humberto


You could still line them up all in a row though
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

PostPosted: Sun Apr 10, 2005 10:45 am     Reply with quote

Thanks Mark, I did forget to mention putting them in a row, but at least to you and me it was fairly obvious that the physical orientation of the individual LEDs was a matter of user design. They could be put in a row to form the bar, or in a circle as a decoration with chasing patterns or in a true n by m matrix to form characters or other designs.

Humberto: Future wrote:

Quote:
I don't want to waste many outputs with this, so a multiplex scheme/chip will be needed.


So that's what I think I presented, isn't it?

Charlie
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Apr 10, 2005 11:14 am     Reply with quote

Chalie U, Mark and others:

Surely there are many ways to do the same, the discusing key is how to
do it using only a few pins from the PIC.


Charlie U wrote:
Quote:

Since you want 20 LEDs, your array could be 4 by 5. This will require 9 pins on your processor.


Using any of the serial-in/paralell-out technique proposal, the
problem is fully solved using only 3 PIC PINs

Humberto
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Sun Apr 10, 2005 1:01 pm     Reply with quote

I liked the 595 chip, they can be cascaded and are very cheap.

I'll use some 7-seg displays too.. look what I found.

http://www.piclist.com/techref/io/led/8x7s8pin.htm
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sun Apr 10, 2005 4:10 pm     Reply with quote

Humberto wrote:
Chalie U, Mark and others:

Surely there are many ways to do the same, the discusing key is how to
do it using only a few pins from the PIC.


Charlie U wrote:
Quote:

Since you want 20 LEDs, your array could be 4 by 5. This will require 9 pins on your processor.


Using any of the serial-in/paralell-out technique proposal, the
problem is fully solved using only 3 PIC PINs

Humberto


You are assuming this. 9 pins may be acceptable to the poster. He just didn't want to use 20. The choice is his to make and Charlie U's suggestion is just as appropriate as any other. Heck, if its about fewest number of pins, then I could stick another PIC on there and only use 1 pin to do 1-way communication. Then have the other PIC drive the LED's directly. So I guess this solution would be the best since it only uses 1 pin right? Laughing
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group