Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Advice on multiplexing ten 7-segment display

Status
Not open for further replies.
ljcox said:
Edit 3. The PIC programming may be a bit complicated as you are muxing on the segment side

I would suggest using table lookup. My idea is like the following, untested:

First, we isolate the special case of digit value=8(all segments ON) and 9(one segment OFF) in initial check routine and handle them separately.

If the current digit value is not 8 or 9, then we do a table lookup(or rotate 1 left by n times) for 0-7 to get an eight bit number which has a single nth bit set as per the digit value.

Next do another table lookup (0 for segment "a" and 6 for segment "g") and obtain a 8-bit return value which determine which digit value(0-7) the segment should be ON. We AND the two values together and set or clear the corresponding port bit according to whether the result is zero or not.
 
eblc1388 said:
ljcox said:
Edit 3. The PIC programming may be a bit complicated as you are muxing on the segment side

I would suggest using table lookup.

Yes, it's no more difficult either way, it's normal to use a lookup table anyway, it makes your layout so much easier if it doesn't matter which segments connect to which pin.

Again, my seven segment tutorial uses a lookup table!.
 
In my previous post, I wrote that you don't need Darlingtons. But I forgot that the PNP segment transistors (I'll call them Qa ~ Qg) have to switch up to 420 mA. So they will have to be Darlingtons.

I have also thought about the PIC programme. It is relatively easy. Briefly:-

Connect Qa:g to outputs 1:7 of the 74LS138. Set the address counter to 1. This will turn Qa on.

Do a lookup for each of the 10 digits to be displayed in order to convert them to the 7 segment format and store them in files say digit_1 : digit_10.

0. Turn all of the Q1:10 transistors off.

1. test bit 0 of digit_1 and if set, set the output that turns on the Q1 transistor.

2. Then test bit 0 of digit_2 and if set, turn on Q2.

3. Repeat this for all digits

4. delay for say 3 ms

5. then goto 0. and repeat for bit 1, etc.

It may be easier to decrement the counter and skip on zero, thus the above would be done in reverse, but the result will be the same.
 
Here is an improvement on what I outlined in the previous post.
Connect the bases of Q1:8 via resistors to portd and Q9,10 to porte.

Allocate 2 temporary regs temp_1-8 & temp_9-10.

Use a lookup table to store the 7 segment data into the data1:10 regs as before.

Move all of the bit 0's from the digit1:8 regs into temp_1-8 & the 0 bits from digit9,10 into temp_9-10.

This can be done using the rrf instruction. eg.

rrf digit1 ;moves bit 0 of reg digit1 into C
rrf temp_1-8 ; moves this bit into reg temp_1-8

rrf digit2 ;moves bit 0 of reg digit2 into C
rrf temp_1-8 ; moves this bit into reg temp_1-8

etc. until reg temp_1-8 is full, then move the remaining two 0 bits into reg temp_9-10.

Then (after the 3 ms delay)

movfw temp_1-8
movwf portd
movfw temp_9-10
movwf porte

Hence all of the Q1 ~ 10 transistors are turned on or off. And there is no need to previously clear portd or porte.

Then advance the address counter and repeat the above so all of the bit 1's are moved into temp_1-8 & temp_9-10.
This can be done during the 3 ms delay.

At the end of the mux cycle, the data1:10 regs are refreshed since the rotating will have destroyed the data.

So I'll leave you to evaluate the options we have suggested. If you need any further advice, just ask.
 
ljcox said:
In my previous post, I wrote that you don't need Darlingtons. But I forgot that the PNP segment transistors (I'll call them Qa ~ Qg) have to switch up to 420 mA. So they will have to be Darlingtons.

If 7445 is used, with its open collector and 80mA current sinking capability, a darlington PNP setup would not be needed. This also enable LED supply operation at higher than +5V.

ljcox said:
I have also thought about the PIC programme. It is relatively easy.

A far as I understand, there is no easy coding method in PIC(16Fxxx) to test a certain bit position according to value of a variable, instead the data to be tested has to be "rotated" certain times beforehand so that the required bit is in the designated position to be tested or there are separate codings for eight individual testing routines. It can be done, but the coding could be longer and more involved than just using table lookup.
 
thanks guys for all your feedbacks. I really appreciate it. Though I still haven't decide which method i should use coz I wanted to make sure my s/w part can "interface" with the hardware.
 
eblc1388 said:
ljcox said:
In my previous post, I wrote that you don't need Darlingtons. But I forgot that the PNP segment transistors (I'll call them Qa ~ Qg) have to switch up to 420 mA. So they will have to be Darlingtons.

If 7445 is used, with its open collector and 80mA current sinking capability, a darlington PNP setup would not be needed. This also enable LED supply operation at higher than +5V. Good thought. Operation at > 5V should not be necessary. Open collector drivers will require 2 resistors per transistor to by pass Icbo.

ljcox said:
I have also thought about the PIC programme. It is relatively easy.

A far as I understand, there is no easy coding method in PIC(16Fxxx) to test a certain bit position according to value of a variable, instead the data to be tested has to be "rotated" certain times beforehand so that the required bit is in the designated position to be tested or there are separate codings for eight individual testing routines. It can be done, but the coding could be longer and more involved than just using table lookup. There are the btfss & btfsc instructions which allow testing particular bits. That the way I suggested doing it initially, but if the rrf instruction is used to shuffle the bits, the transistors can be switched in parallel. I don't understand your point re a table lookup as both of my suggestions need a table lookup anyway.
 
ljcox said:
Open collector drivers will require 2 resistors per transistor to by pass Icbo.

Good point. I forget that.

ljcox said:
There are the btfss & btfsc instructions which allow testing particular bits.
Code:
0. Turn all of the Q1:10 transistors off.

1. test bit 0 of digit_1 and if set, set the output that turns on the Q1 transistor.

2. Then test bit 0 of digit_2 and if set, turn on Q2.

3. Repeat this for all digits

4. delay for say 3 ms

5. then goto 0. and repeat for bit 1, <<<<<<

Yes, but unless you want to code the same testing routine six more times with diffenent bit position to be tested, or it won't work. My point is: PIC 16Fxxx instruction set does not allow testing of a certain bit position according to the value of a counter.

ljcox said:
That the way I suggested doing it initially, but if the rrf instruction is used to shuffle the bits, the transistors can be switched in parallel.

What do you meant by switching transistors in parallel? I would set/clear bits first on a file register and then output it to the port so it is in effect parallel.
 
eblc1388 said:
Code:
4. delay for say 3 ms

How do you actually know the delay is 3ms?
I mean while I was using 3.58Mhz of crystal, in order to ensure no flicker for 10 digits, I put in arbituary value and finally get a loop of AA (hexa value) times...but still i couldn't calculate out the exact time delay.

I know that the instruction time = crystal freq / 4. but how to link to time delay?
 
taengi said:
I know that the instruction time = crystal freq / 4. but how to link to time delay?

The 3ms delay is suggested by ljcox.

You know how long an instruction takes, you just divide 3ms by instruction timing and get no. of total instructions required. You then write a wait loop doing nothing to just wait out the required 3ms.

For example, the instuction timing is 4/ 3.58MHz = 1.12 us. There are 3ms/1.12us = 2685 instructions executed in 3ms. So you turns on the digit, do a looping for 2685 instructions doing nothing, then turn off the digit.

Or, you can use interrupt technique to generate an interrupt every 3ms and switch the digits On/OFF.
 
eblc1388 said:
ljcox said:
There are the btfss & btfsc instructions which allow testing particular bits.
Code:
0. Turn all of the Q1:10 transistors off.

1. test bit 0 of digit_1 and if set, set the output that turns on the Q1 transistor.

2. Then test bit 0 of digit_2 and if set, turn on Q2.

3. Repeat this for all digits

4. delay for say 3 ms

5. then goto 0. and repeat for bit 1, <<<<<<

Yes, but unless you want to code the same testing routine six more times with diffenent bit position to be tested, or it won't work. My point is: PIC 16Fxxx instruction set does not allow testing of a certain bit position according to the value of a counter. Agreed. Now I undestand what you mean. I had intended to do the same testing routine six more times to test each bit in turn.

ljcox said:
That the way I suggested doing it initially, but if the rrf instruction is used to shuffle the bits, the transistors can be switched in parallel.

What do you meant by switching transistors in parallel? I would set/clear bits first on a file register and then output it to the port so it is in effect parallel. That's what I mean. I could not think of a better way to express it. Perhaps I should have written:- turn on Q1:8 simultaneously, then Q9:10 simultaneously.
 
taengi said:
eblc1388 said:
Code:
4. delay for say 3 ms

How do you actually know the delay is 3ms?
I mean while I was using 3.58Mhz of crystal, in order to ensure no flicker for 10 digits, I put in arbituary value and finally get a loop of AA (hexa value) times...but still i couldn't calculate out the exact time delay.

I know that the instruction time = crystal freq / 4. but how to link to time delay?

My understanding is that the mux rate needs to be at least 40 Hz in order to prevent flicker. So I chose 3 ms as an example since 3 * 7 = 21 ms which is a frequency of 1000/21 = 47.6 Hz

Nigel's tutorials have delay sub routines in them.

Incidentally, it is much easier if you use a 4 MHz crystal, then each instruction takes 1 us.

The MPLAB simulator has a Stopwatch function so you can measure the delays. It defaults to a 20 MHz clock, so you have set it to whatever clock frequency you are using.
 
The Darlington arrays ULN2003 (7 transistors) and ULN2803 (8 transistors) have internal resistors so they can be connected directly to the PIC.

So for Q1:10, you could use either two ULN2003 (and have 4 spare transistors) or one ULN2803 and two single Darlingtons such as the MPSA14 (with a resistor on each base)

At the top end, you could use PNP Darlingtons such as the MPSA65 or BD682. However, you will need +9V and suitable level shifting. Let me know which hardware option you want to use and I'll assist with the design.

I have asumed that you can change the software if necessary to suit which ever hardware option you prefer. Is this true?
 
ljcox said:
My understanding is that the mux rate needs to be at least 40 Hz in order to prevent flicker. So I chose 3 ms as an example since 3 * 7 = 21 ms which is a frequency of 1000/21 = 47.6 Hz

It's simple to change the multiplexing rate, and I suggest doing that in my tutorials, to show what it actually means - I would suggest doing it too slowly at first, this will show any problems up, which might not be visible at normal refresh rates. Once it's all working perfectly increase the refresh rate until you can't see it flicker - then increase it a fair bit more, some people are more sensitive to flicker than others.
 
Hi ljcox,
I have decided to use 1x10 method you've suggested since I couldn't visualise and understand fully how the other 2 options function in term of s/w and h/w.

for this 1x10 method, I still have a few curiosity. I've never use a PNP before so I'm thinking is the current flow from Vcc to PIC?? If so, by setting Ic = 50mA, I'm sure PIC will damaged? That's mean I need another IC, like what eblc1388 suggest use a 7445 connected to PIC?

As for the R value, I'm not too sure since it's PNP, is the calculation as follow correct?

Ic = 5mA (1 segment) x 10 = 50mA
Ib = 50mA/100 = 0.5mA
base voltage Vb = 5 - [0.5mA x 560] = 4.7V (but the output port from PIC measured is 2.7v not 5v???)
Ve = Vb - Vbe = 4.7 - 0.7 = 4v
R = [Ve - 1.7 (1 segment)]/50mA = 46ohm

On the driver side, how do you come up with 5.6kohm?? I'm clueless. From the connection, does it mean that the total current of a digit is sinked through GND via transistor NPN?
 

Attachments

  • muxing_1_821.gif
    muxing_1_821.gif
    31.9 KB · Views: 424
taengi said:
Hi ljcox,
I have decided to use 1x10 method you've suggested since I couldn't visualise and understand fully how the other 2 options function in term of s/w and h/w. Do you want to ask questions about these options to help you understand them?

for this 1x10 method, I still have a few curiosity. I've never use a PNP before so I'm thinking is the current flow from Vcc to PIC?? If so, by setting Ic = 50mA, I'm sure PIC will damaged? No, the current into the PIC is determined by the 560 Ohm resistors. It will be about 4/0.56 = 7 mA That's mean I need another IC, like what eblc1388 suggest use a 7445 connected to PIC?

As for the R value, I'm not too sure since it's PNP, is the calculation as follow correct?

Ic = 5mA (1 segment) x 10 = 50mA Correct
Ib = 50mA/100 = 0.5mA To ensure saturation, you should make it about Ic/10 = 5 mA, hence my 7 mA above

base voltage Vb = 5 - [0.5mA x 560] = 4.7V No, Vb = 5 - 0.7. (but the output port from PIC measured is 2.7v not 5v???) I don't know why you measured 2.7V. Without any load, the PIC should switch between 0V and 5V.

Ve = Vb - Vbe = 4.7 - 0.7 = 4v No, Ve = +5V. The emitter is the one with the arrow.

R = [Ve - 1.7 (1 segment)]/50mA = 46ohm No, R = (5 - 0.2 - 1.7 - 1.6)/0.05 = 30 Ohm. Where 0.2 V is the PNP saturation voltage, 1.7 is the LED voltage and 1.6 is the saturation voltage of the Darlington transistors.


On the driver side, how do you come up with 5.6kohm?? The Darlington transistors have a very high gain, so they don't need much base current. See the data sheet. However, see my comments below. I'm clueless. From the connection, does it mean that the total current of a digit is sinked through GND via transistor NPN? Yes

The Darlington arrays ULN2003 (7 transistors) and ULN2803 (8 transistors) have internal resistors so they can be connected directly to the PIC.

So for Q1:10, you could use either two ULN2003 (and have 4 spare transistors) or one ULN2803 and two single Darlingtons such as the MPSA14 (with a resistor on each base)
 
The 7445 does not have enough current sink capability for your purpose.

So here is my suggestion. Note that I accidentally left the "S" out of MSPA14 in the note.
 

Attachments

  • muxing_4.gif
    muxing_4.gif
    34.9 KB · Views: 383
if i don't use these darlington transistor but the general purpose transistor, will the configuration still be the same? like if i use BC327 for PNP and 2N2222 for NPN
 
taengi said:
if i don't use these darlington transistor but the general purpose transistor, will the configuration still be the same? like if i use BC327 for PNP and 2N2222 for NPN
If you use the 2N2222, you will need 10 PNP transistors to drive them since the 2N2222 will need a base current of about 42 mA in order to ensure saturation with a collector current of 420 mA. The PIC cannot source 42 mA.

So if you want to do it that way, let me know.
 
ljcox,

You are very conservative in estimating the voltage drop across the LED segment at 60mA current. The following is a typical graph from the datasheet of the 7-seg LEDs I'm using. It shows quite a large voltage drop. The "HER" in the graph means "high efficiency red".
 

Attachments

  • led_drop.gif
    led_drop.gif
    8.8 KB · Views: 375
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top