|
|
View previous topic :: View next topic |
Author |
Message |
manusoftar
Joined: 19 Mar 2022 Posts: 46
|
Problem interfacing 74LS48 with PIC16F877A [Solved] |
Posted: Tue Apr 05, 2022 11:50 am |
|
|
First of all I want to apologize if this question has been answered before, the truth is that I did a thoughtful search on Google about this issue and couldn't find anything 100% useful as most, not to say, all tutorials and guides assume you have a common anode 7 segment display and you are using a 74LS47, which is not my case.
In any case, what I am trying to do is to drive a 7 segment display (C-501H, common CATHODE) with a 74LS48 decoder, first of all I'm trying to show a 0 (zero) on the single 7 segment display I'm using, which would require me to send all zeroes on the pins A, B, C and D of the 74LS48. I'm designing my circuit on Proteus and in the simulation everything works as one would expect, the problem is that when I wired all on my breadboard it didn't work at all.
I set the whole PORTB on my PIC as output ( ) and I connected it to the input pins of the 74LS48, then I do to put all pins to low state (which, if I understood properly would be either 0v or shorted to GND), the thing is that when I check the pins with my multimeter (I don't own an oscilloscope... yet ), I see it is sending about 2v on the 4 pins that are connected to the inputs of the 74LS48 and like 0.8v on the rest...
Let me show you my code and circuit diagram.
Code: |
#include <TesterMultiplexor.h>
//#use fast_io(D)
void dibujarNumero(int numero) {
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
output_low(PIN_B4);
switch (numero) {
case 1:
output_high(PIN_B4);
break;
case 2:
output_high(PIN_B3);
break;
case 3:
output_high(PIN_B4);
output_high(PIN_B3);
break;
case 4:
output_high(PIN_B2);
break;
case 5:
output_high(PIN_B2);
output_high(PIN_B4);
break;
case 6:
output_high(PIN_B3);
output_high(PIN_B2);
break;
case 7:
output_high(PIN_B4);
output_high(PIN_B3);
output_high(PIN_B2);
break;
case 8:
output_high(PIN_B1);
break;
}
}
void main() {
//setup_adc_ports(AN0);
//set_analog_pins(PIN_A0, PIN_A1);
//setup_adc(ADC_CLOCK_INTERNAL);
set_tris_a(0xFF); //Entrada
set_tris_b(0x00); //Salida
set_tris_c(0x00); //Salida
set_tris_d(0xFF); //Entrada
int contador = 0;
int presionado = 0;
//Empiezo con el display en 0
/*output_low(PIN_D1);
output_low(PIN_D2);
output_low(PIN_D3);
output_low(PIN_D4);*/
output_b(0);
//dibujarNumero(8);
while(TRUE){
/*mandarSalidaAlMux(contador);
if (verificoMux(contador)==1) {
output_high(PIN_D0);
} else {
output_low(PIN_D0);
}*/
if (input(PIN_A0) && presionado == 0) { //Si se clickeó el pulsador entonces avanzo una posición
presionado = 1; //Seteo el flag para que solo me tome una presión del pulsador y espere a que lo suelte para volver a avanzar.
contador+=1;
if (contador > 8) {
contador = 0;
}
dibujarNumero(contador);
}
if (!input(PIN_A0)) { //Si se soltó el pulsador reseteo el flag para poder volver a presionarlo
presionado = 0;
}
delay_ms(200);
//TODO: User Code
}
}
|
This is the header file (I used the CCS Wizard to generate the project and it created a header file for these things... anyway)
TesterMultiplexor.h
Code: |
#include <16F877A.h>
//#device ADC=10
#use delay(crystal=8MHz)
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
|
And last, but not least, the circuit diagram:
HERE IS THE DIAGRAM
I would appreciate any insights or ideas to make this work...
Thanks for your time. |
|
|
manusoftar
Joined: 19 Mar 2022 Posts: 46
|
|
Posted: Tue Apr 05, 2022 5:15 pm |
|
|
Researching my circuit I found out that the 74LS48, for some reason (which I'm not sure about) is outputting around 2v on each of the A, B, C and D pins... I'm not sure if that is the intended way of it to work but it seems like if I intend to work with this decoder I should somehow selectively short those pins to gnd rather than directly connecting them to my PIC and doing output_low or output_x(0)....
In any case it would help if someone could verify if the behavior I just described (an output voltage on the selector pins) is normal or if it means that the two decoders I have are somehow broken. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Apr 05, 2022 6:25 pm |
|
|
If you wired according to your diagram you have several problems
1) no VCC (+5) to the 74ls48
2) no ground to the 74ls48
3) no pullup on _BI
4) no pullup on _RBI
5) no pullup on _LT
6) No VDD/gnd to PIC
7) no VCC bypass cap at 74ls48
8) no current limiting resistors on 74ls48 outputs
9) _mclr not pulled up |
|
|
manusoftar
Joined: 19 Mar 2022 Posts: 46
|
|
Posted: Tue Apr 05, 2022 8:20 pm |
|
|
On the circuit design I provided I didn't wire those pins because, first you don't need to connect the PIC to either vcc, gnd or even the crystal on Proteus, by on my fisical circuit I do have all those things connected, I have VCC and GND both on the PIC and on th 74LS48, also I have the resistors on BI, BO and LT on the 74LS48 as you say.
What I don't have is a bypass cap on the 74ls48 and current limiting resistors either. I wonder how should I connect that cap and how many ohms does those resistor have to be???
I looked for circuit examples for the 74LS48 and I couldn't find any where a PIC is connected to a 74LS48. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Apr 05, 2022 8:30 pm |
|
|
I downloaded the datasheet and 220r or 330r resistors should be fine as current limiters.
It is always best to draw schematics as accurately as possible, so that anyone can build a unit that will work.
A simple .1mfd cap at the 74ls48 VCC and GND pins is fine. If yo look at old computer boards that were 7400 series based ,EVERY device had a 'bypass' cap soldered next to it. |
|
|
manusoftar
Joined: 19 Mar 2022 Posts: 46
|
|
Posted: Tue Apr 05, 2022 8:37 pm |
|
|
I assume we are talking about a "regular" electrolytic cap, aren't we?? like a 0.1uF that goes between GND and VCC?
Is it normal that I get almost 2V output at A, B, C, D???
and before somebody wonders why I have these, maybe, noob issues... my field of expertise is not electronics (besides I really like electronics and circuit building), my field of expertise is software, I'm a software engineer although I wish I also took a chance on Electronic Engineering as well... |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Tue Apr 05, 2022 8:45 pm |
|
|
No, not an electrolytic. Ceramic. Electrolytic capacitors only act like a capacitor up to (generally) "tens of kHz". Beyond that, they're not capacitors anymore. Ceramic caps stay capacitive up to "tens of MHz" or beyond.
Bypass caps need to supply a lot of charge in a short period of time: this is high frequency. You need ceramic caps for that.
I didn't look at your schematic but with bypass caps you need to ensure that they're laid out *between* the supply line and the Vcc pin. They don't do any good anywhere else, and no, arranging them as supply line, Vcc pin, then capacitor isn't the same.
There's all sorts of other tidbits you can't learn from a textbook. For instance, X7R ceramic is actually piezoelectric. In a high vibration/shock environment they'll actually create/pump all sorts of nasty noise into your power supply. |
|
|
manusoftar
Joined: 19 Mar 2022 Posts: 46
|
|
Posted: Tue Apr 05, 2022 9:08 pm |
|
|
Thanks for the info newguy, I placed a 0.1uF (104) ceramic cap between VCC and GND pins on my 74LS48, and I also added some 10K pullups on BI, BO, and LT pins.
All that being said I'm facing exactly the same issue, if I check the voltage on the A, B, C and D pins of the decoder I get around 2V on each (and even unplugged from my PIC), so, for some reason I just don't understand, my decoder is outputting current through the pins that should be input only...
Nothing of what has been suggested so far seems to deal with that. The only way it works is when, instead of plugging the decoder inputs to my PIC's PORT B, I plug em directly to GND... I don't know if this is an issue with the PIC itself no setting the pins at exactly 0V (if I unplug the wires and I test each pin of PORT B agains GND I get about 0.8V instad of a direct short to GND) or if the decoders are indeed broken and should not be sending current out those pins.
Thanks to both of you that tried to give me a hand anyway... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Apr 05, 2022 9:20 pm |
|
|
Do you have an 8 MHz crystal and two 20pf ceramic capacitors
installed for the crystal circuit ?
Do you have a 10K resistor between the MCLR pin and +5v ?
Also change your first 3 lines to this, in this order:
Code: | #include <16F877A.h>
#fuses NOWDT, BROWNOUT, PUT, NOLVP, NOPROTECT
#use delay(crystal=8MHz)
|
The way you had it, the 'XT' was over-ridding your #use delay()
statement. XT is not for use above 4 MHz. You use HS for > 4 MHz
for this PIC. Your #use delay() would have done that for you
correctly, except you put the #fuses line after it, and it was over-ridden.
Brownout is a good thing to use. So is PUT for crystals. |
|
|
manusoftar
Joined: 19 Mar 2022 Posts: 46
|
|
Posted: Tue Apr 05, 2022 9:37 pm |
|
|
PCM programmer wrote: | Do you have an 8 MHz crystal and two 20pf ceramic capacitors
installed for the crystal circuit ?
Do you have a 10K resistor between the MCLR pin and +5v ?
Also change your first 3 lines to this, in this order:
Code: | #include <16F877A.h>
#fuses NOWDT, BROWNOUT, PUT, NOLVP, NOPROTECT
#use delay(crystal=8MHz)
|
The way you had it, the 'XT' was over-ridding your #use delay()
statement. XT is not for use above 4 MHz. You use HS for > 4 MHz
for this PIC. Your #use delay() would have done that for you
correctly, except you put the #fuses line after it, and it was over-ridden.
Brownout is a good thing to use. So is PUT for crystals. |
I do have a 10K resistor on the MCLR and +5v and I do have an 8Mhz crystal with to 22pF ceramic camps on each leg to GND
I'll try that immediately, I wonder why the heck it worked like a charm on Proteus if that was the issue...??? |
|
|
manusoftar
Joined: 19 Mar 2022 Posts: 46
|
|
Posted: Tue Apr 05, 2022 9:41 pm |
|
|
PCM programmer I just did what you suggested and as I was expecting it didn't change a thing, I mean, it still doesn't work, and it seems to be related to the fact that the 2v I'm getting on the INPUTS of the 74LS48 already like override the 0v I should be sending, the only way I could get my display to actully show something was by connecting the 74LS48 inputs directly to GND...
By the way, it may be worth to mention that I'm using an HD74LS48P decoder (the older one), I think I said so on my original post but anyway...
Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Apr 05, 2022 9:50 pm |
|
|
Your PIC may not even be running. Setup a circuit it blink an LED
at 1 Hz. |
|
|
manusoftar
Joined: 19 Mar 2022 Posts: 46
|
|
Posted: Tue Apr 05, 2022 10:29 pm |
|
|
PCM programmer wrote: | Your PIC may not even be running. Setup a circuit it blink an LED
at 1 Hz. |
You are right, I tried to do a simple led blinking via B7 and doesn't do a thing, checked my connections, I wonder if my PIC's are dead?? (I have three 16F877A from which one will not program correctly, it always fails on program memory 0002 so I guess that one is DEAD, but the other two do write and read which gives me a little hope that there may still be a chance, yet I can't seem to figure out why are not responding)... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 06, 2022 3:36 am |
|
|
Post your LED blinking program.
If possible, post a link to a photo of your test board. It should be
a close-up photo so we can see all the connections. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Wed Apr 06, 2022 5:04 am |
|
|
One 'glaring' thing leaps out on his original post:
Code: |
#include <16F877A.h>
//#device ADC=10
#use delay(crystal=8MHz)
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
|
Since he has the fuses after the #use delay, these will override the
compiler's settings.
Maximum frequency XT is rated to use is 4MHz.....
He may find it works if he changes XT to HS |
|
|
|
|
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
|