View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 14, 2012 9:51 pm |
|
|
What range of index values (i) does your for() loop create ?
Which ones should it create ? Run this test program
to show the indexes that it creates:
Code: |
#include <16F628A.H>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4M)
#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, ERRORS)
//==========================================
void main()
{
int8 i;
for(i=0; i<=8; ++i)
{
printf("%u \n\r", i);
}
while(1);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Your schematic |
Posted: Thu Mar 15, 2012 5:04 am |
|
|
Quote: |
I am making a digital clock using LEDs powered by a shift register instead of a 7 segment display. Anyway, since it's going to be powered by a shift register instead of a 7 seg-display, I have made a routine for numbers from 0 to 12 (I made it up to 12 for a specific reason). Anyway, my code doesn't seem to function right (simulating using Proteus Professional 7.7).
here is my code:
|
OK, so I've got your schematic totally wrong, I read it that you were NOT using a 7 segment display and assumed that you were using some sort of matrix. What I now believe is that you ARE using something similar to a 7 segment display, but driving it from a 74164 rather than directly from a PIC.
So it seems your schematic COULD look like this:-
Code: |
---------------
| |
| 74HC164 Q0 |___|\|___/\/\/\___ GND
| | |/|
| |
| Q1 |___|\|___/\/\/\___ GND
| | |/|
RB6 -------------------| CK |
| Q2 |___|\|___/\/\/\___ GND
| | |/|
RB7 -------------------| DATA |
| Q3 |___|\|___/\/\/\___ GND
| | |/|
| |
| Q4 |___|\|___/\/\/\___ GND
| | |/|
| |
| Q5 |___|\|___/\/\/\___ GND
| | |/|
| |
| Q6 |___|\|___/\/\/\___ GND
| | |/|
| |
| Q7 |___|\|___/\/\/\___ GND
| | |/|
---------------
The LEDs arranged in a pattern:-
1
2 7
3
4 6
5 0
|
please confirm that I have now got somewhere close.
And DO READ PCM programmer's post.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
![](templates/subSilver/images/spacer.gif) |
seifpic
Joined: 11 Mar 2012 Posts: 45 Location: Egypt
|
|
Posted: Thu Mar 15, 2012 9:34 am |
|
|
PCM programmer wrote: | What range of index values (i) does your for() loop create ?
Which ones should it create ? Run this test program
to show the indexes that it creates:
|
Yeah, it was supposed to do 8 loops but it did nine because I set i to 0. I set it to 1 and it's supposed to work now. |
|
![](templates/subSilver/images/spacer.gif) |
seifpic
Joined: 11 Mar 2012 Posts: 45 Location: Egypt
|
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
LEDs |
Posted: Thu Mar 15, 2012 11:39 am |
|
|
Your arrangement for the LEDs is a recipe for disaster.
(1) The triples of LEDs are unlikely to share current equally and will have different brightness. The display will look odd.
(2) The LED currents are limited only by the capability of the 74164.
(3) The scheme may very well APPEAR to work, but will probably have a VERY short life. Either your 74164s, LEDs, or both will self-destruct!
You MUST include a current limiting resistor in series with EACH LED. Read the data sheets to arrive at a value.
Proteus / PSpice and the like don't know about thermal issues and LED forward voltage variation, unless you tell them.
Thanks ckielstra, I hadn't noticed. Keeping to one thread would have been useful.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Mar 15, 2012 11:54 am |
|
|
seifpic wrote: | PCM programmer wrote: | What range of index values (i) does your for() loop create ?
Which ones should it create ? Run this test program
to show the indexes that it creates:
|
Yeah, it was supposed to do 8 loops but it did nine because I set i to 0. I set it to 1 and it's supposed to work now. | So your loop is now from 1 to 8? Check out the parameters for the bit_test function in the manual... |
|
![](templates/subSilver/images/spacer.gif) |
seifpic
Joined: 11 Mar 2012 Posts: 45 Location: Egypt
|
Re: LEDs |
Posted: Thu Mar 15, 2012 4:37 pm |
|
|
Mike Walne wrote: | You MUST include a current limiting resistor in series with EACH LED. Read the data sheets to arrive at a value. |
I have read what I can understand from the datasheets. Should I add a 220 ohm resistor per LED? Because in a normal LED matrix, there is one resistor per row or column, and I personally used one resistor to power multiple LEDs before. If so, can you explain the reason to do so? I'm also sorry about not including the schematic here as it was messy and I didn't think it was necessary for this post (the other post asks a different question) .
Thanks in advance. |
|
![](templates/subSilver/images/spacer.gif) |
seifpic
Joined: 11 Mar 2012 Posts: 45 Location: Egypt
|
|
Posted: Thu Mar 15, 2012 4:40 pm |
|
|
ckielstra wrote: | So your loop is now from 1 to 8? | No, I changed it to loop from 0 to 7 http://codepad.org/RWlRTp20 |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
LEDs and resisitors |
Posted: Fri Mar 16, 2012 3:22 am |
|
|
You CAN use one resistor to limit the current through several LEDs if they are connected as:-
Code: |
+V ___|\|______|\|______|\|______|\|___/\/\/\___ GND
|/| |/| |/| |/|
|
All the LEDs carry the same current.
At the same current, LEDs of the same type, and bin selection SHOULD be reasonably well matched for brightness.
The forward voltage drop across the LEDs depends on colour, and varies for individual LEDs of the same colour.
For red LEDs the Vf varies from ~1V5 to ~2V5. (IR LEDs have lower Vf, green, blue,IR progressively higher.
You can try to connect LEDs in parallel as below:-
Code: |
+V ______|\|________/\/\/\___ GND
| |/| |
| |
|___|\|____|
| |/| |
| |
|___|\|____|
|/|
|
Connected like this all the LEDs have the same voltage across them.
You CANNOT guarantee that ALL the LEDs will pass the same current.
This is because each LED requires a DIFFERENT voltage across it to pass the SAME current.
Look at the Voltage/current curve for typical LEDs. They start with zero current until a minimum voltage is reached, then the current changes rapidly with small voltage changes.
Driving LEDs from 74164 you have two specification limits which come into play.
(1) Maximum current rating for each output pin, 30 to 40 mA.
(2) Total power supply current for the package, 70 to 100mA.
The ratings depend on which device/package you've got and manufacturer.
I'm assuming you're supply is 5V.
With 220R in series with each LED you'll get ~10mA, maybe a bit more.
For three LEDs connected to each output, you're going to be just about at the pin limit.
When your showing a "1" the total chip current will be ~60 to 70mA, getting close to the package limit.
Showing a "7" you'll have passed the package limit.
Showing an "8" your current COULD be around a quarter of an amp! (Heavily depends on the 74164)
From this you have several choices:-
(1) Use larger value resistors and accept the reduced brightness.
(2) Connect LEDs in series and drive with FETs or bipolars from higher voltage source.
(3) Show off your fancy design for as long as it survives.
(4) .............
I'll leave you to work it out.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
seifpic
Joined: 11 Mar 2012 Posts: 45 Location: Egypt
|
Re: LEDs and resisitors |
Posted: Fri Mar 16, 2012 4:08 am |
|
|
Mike Walne wrote: |
(4) .............
|
What if I do it like this:
Code: |
V+ ___________/\/\/\___| \ |___
| | / | |
|__/\/\/\___| \ |______| GND
| | / | | |
|__/\/\/\___| \ |___|
| / |
|
One more question, from what I've learned, electrons start at the anode and go to the cathode, shouldn't the resistors be placed before the LEDs? |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Oh dear |
Posted: Fri Mar 16, 2012 5:04 am |
|
|
Now you've got me really worried!
Quote: |
One more question, from what I've learned, electrons start at the anode and go to the cathode, shouldn't the resistors be placed before the LEDs?
|
You were not paying attention for either lesson on Kirchoff's laws.
I had anticipated a question on quantum mechanics, but you were not at that lesson either.
Conventional current flow is from positive to negative.
Electrons are negatively charged and drift from negative to positive round the outside of an electrical power source.
In a diode the electron flow is from cathode to anode. Had you been brought up on thermionic valves, you would have had no problem with that one.
Try each of these two circuits.
Code: |
+V ______|\|_____/\/\/\_____ GND
| |/| |
| |
|___|\|_____/\/\/\__|
| |/| |
| |
|___|\|_____/\/\/\__|
|/|
+V _____/\/\/\____|\|_______ GND
| |/| |
| |
|__/\/\/\____|\|____|
| |/| |
| |
|__/\/\/\____|\|____|
|/|
|
I really should NOT have to say any more>
Mike |
|
![](templates/subSilver/images/spacer.gif) |
seifpic
Joined: 11 Mar 2012 Posts: 45 Location: Egypt
|
Re: Oh dear |
Posted: Fri Mar 16, 2012 6:54 am |
|
|
Mike Walne wrote: | In a diode the electron flow is from cathode to anode. Had you been brought up on thermionic valves, you would have had no problem with that one. |
Kakin wrote: | depends on what you want the resistor to do.
for example: you have two leds and connect the resistor to voltage and the other side to both leds. no problem here, but if you connect both leds to voltage and both cathodes (negative side) to the resistor then it won't work as nicely.
One of the leds may be dimmer or not on at all, because the current through first is causing a voltage in the resistor, making the second led "see" a smaller voltage or non at all (remeber voltage is a difference between two points) | ^ http://forum.allaboutcircuits.com/showpost.php?p=131024&postcount=3 |
|
![](templates/subSilver/images/spacer.gif) |
seifpic
Joined: 11 Mar 2012 Posts: 45 Location: Egypt
|
|
Posted: Fri Mar 16, 2012 7:35 am |
|
|
I used this calculator http://www.quickar.com/noqbestledcalc.htm to calculate 3 (2.7V) (20mA) LEDs in parallel and it outputs a 39ohm resistor. Do you recommend That I use another setup? Because I am using a wall adapter 5V dc (2A) as a power source. |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Kakin |
Posted: Fri Mar 16, 2012 7:42 am |
|
|
Quote: |
Kakin wrote:
depends on what you want the resistor to do.
for example: you have two leds and connect the resistor to voltage and the other side to both leds. no problem here, but if you connect both leds to voltage and both cathodes (negative side) to the resistor then it won't work as nicely.
One of the leds may be dimmer or not on at all, because the current through first is causing a voltage in the resistor, making the second led "see" a smaller voltage or non at all (remeber voltage is a difference between two points)
|
Without a schematic, I have little idea what Kakin is getting at, neither, it appears, do you.
Try these circuits for yourself. To really make the point use one red and one blue LED.
(If you have not got a blue LED the use a green.)
Code: |
+12V ______|\|___________/\/\/\___ GND
| |/| Red | 1k
| |
|___|\|_______|
|/| Blue
+12V ___/\/\/\______|\|___________ GND
1k | |/| Red |
| |
|___|\|_______|
|/| Blue
+12V ______|\|___________/\/\/\______|\|________GND
|/| Red 1k |/| Blue
+12V ______|\|___________/\/\/\______|\|________GND
|/| Blue 1k |/| Red
+12V ______/\/\/\______|\|___________|\|________GND
1k |/| Red |/| Blue
+12V ______/\/\/\______|\|___________|\|________GND
1k |/| Blue |/| Red
+12V ______|\|_________|\|__________/\/\/\______GND
|/| Red |/| Blue 1k
+12V ______|\|_________|\|__________/\/\/\______GND
|/| Blue |/| Red 1k
|
Mike |
|
![](templates/subSilver/images/spacer.gif) |
|