# Problem with Up/Down Counter?

Discussion in 'Embedded Systems and Microcontrollers' started by hazim, Aug 2, 2013.

1. ### hazim Thread Starter Active Member

Jan 3, 2008
419
13
Dear all.

I want to make a PIC based 2 digit Up/Down counter with two switchs, and I found the circuit below, on this web page.

As you see in the picture, both 7-segment displays are connected in parallel, so they will display the same number. It will count like this: 11, 22, 33.... or so.

I don't know if this is what they meant by 2-digit! and I can't figure if the PIC's program is wrote according for this output, i.e. for one digit actually.

I rarely work with programming and I really forgot what I've learned in my uC course.. due to the lack of practice.
I thought IC 74191 would work for me but it's a 4-bit counter meaning it's maximum counting number is 16, while I need a higher number, 8-bit counter is fine / any number in tens is fine...

Any Idea? or please suggest for me another circuit if possible.

Regards,
Hazim

Last edited: Aug 3, 2013
2. ### bance Member

Aug 11, 2012
315
34
The digits are multiplexed, only one is on at a time (relying on persistance of vision). It appears to the eye that both are on and are different when that is the required output.

That circuit/programme will do what you ask!

3. ### RRITESH KAKKAR Senior Member

Jun 29, 2010
2,831
91
i have done this use 7447 it will save data wires..
for two digit binary to int conversion...
if(sw1==1){
count++;
}

count=count%10; // for unit only dispalying 0-9
count=count%100/10; // for ten....

4. ### Dodgydave AAC Fanatic!

Jun 22, 2012
6,474
1,024
The displays are switched (Multiplexed) on and off one at a time so they each have a seperate value in the display, thats what the two Npn transistors are for, or port A,0 and A,1.

multiplexing

5. ### elec_mech Senior Member

Nov 12, 2008
1,513
194
If you use a microcontroller (uC), you'll save parts and board space but you'll have to program. You can take a look at one of MMcLaren's projects for an example on how to program a multiplex display.

If you don't want to program and aren't terribly concerned about board space or parts count, I've done a few of these using a CD40110. Here is one I helped another member with recently. This may be bigger and have more options than you want, but you can easily use a smaller display with less parts and features.

6. ### tracecom AAC Fanatic!

Apr 16, 2010
3,925
1,424
The diagram you posted is not from the link you listed; the diagram is from talkingelectronics.com and uses a 16F628, but the link you posted is to a similar project that uses a 16F877A. You may be able to use either one, but don't try to mix them together.

7. ### Anthony_Harder New Member

Nov 26, 2007
7
0
they are multiplexed; for example, if you want to show any number with this circuit lets say "40" the uC will send a "4" to both displays tru portB, but it will set ra1 to saturate transistor connected to the right display in order to activate it (the left one is OFF), then the uC will clear ra1 and will send a "0" to both displays again, but this time it will set ra0 to saturate the second transistor in order to activate the second display, and this process repeats very quickly you'll see both numbers correctly showed, however both numbers are never showed at the same time just one by one but very very fast

8. ### hazim Thread Starter Active Member

Jan 3, 2008
419
13
Thanks all for your great help. tracecom, I've corrected the link .
Any general propose NPN would work right? ex. 2N2222 or 2N3904... etc.

Regards and thank you again.
Hazim

9. ### tracecom AAC Fanatic!

Apr 16, 2010
3,925
1,424
Yes, any small NPN should be fine.

10. ### hazim Thread Starter Active Member

Jan 3, 2008
419
13
Hi again.

I implemented the circuit on a bread board for testing it, and of course I programmed the PIC using the available hex file. I used common cathode 7-segment displays.
The problem now is that nothing is displayed. I tested the voltage on the PIC, it's 5V. I tested the switches and they are working fine. No output voltage on RA0 and RA1 if I pressed the switches or didn't, I think the voltage there should measure around 3V as it's a digital signal output...
I think the problem would be with the configuration of the IC.
Any advice or help??

Regards,
Hazim

File size:
244.5 KB
Views:
198
11. ### hazim Thread Starter Active Member

Jan 3, 2008
419
13
Do I need to put a crystal or what?

12. ### bance Member

Aug 11, 2012
315
34
From the look of your breadboard I imagine you have a short somewhere...

It's not a good idea to use uninsulated wires like that

13. ### hazim Thread Starter Active Member

Jan 3, 2008
419
13
They are isolated, the isolation is transparent

14. ### tshuck Well-Known Member

Oct 18, 2012
3,527
675
To be clear, you did program the chip, right?

15. ### tracecom AAC Fanatic!

Apr 16, 2010
3,925
1,424
I can't see anything wrong with your breadboard wiring. What transistors did you use? It looks like if they are 2N2222 or 2N3904, the wiring is correct, but if they are something else (BC547 e.g.,) recheck the pinout.

And of course we can't see the code since it is a hex file, but I bet there is something wrong with the configuration bits.

16. ### tracecom AAC Fanatic!

Apr 16, 2010
3,925
1,424
Looking at the original code, it seems that he has low voltage programming turned off. What are you using for a programmer?

17. ### hazim Thread Starter Active Member

Jan 3, 2008
419
13
Ofcourse I programmed the chip
I used 2N2222 transistors. I'm using "TOP2007" USB programmer.

I think the problem would be with the configuration bits as you said, but I don't know how should I set them exactly.

18. ### tshuck Well-Known Member

Oct 18, 2012
3,527
675
It looks like your configuration bits should be 0b11110111010101. Try that And report back...

19. ### hazim Thread Starter Active Member

Jan 3, 2008
419
13
Where and how to do that? In the programmer's software there is a tab for the buffer and another tab for the configuration, there I set the configuration of the PIC (pwrte, cp1, cp2, wdt, mclre.. etc), as clear for the software I should set each one alone by choosing what I want.

20. ### absf Senior Member

Dec 29, 2010
1,658
444
Yes, use configuration to set the above bit pattern. The result should look like "3DD5" after setting the bits.

See the attached picture.....

Allen

• ###### 16f628 config Hazim.PNG
File size:
51.6 KB
Views:
69
Last edited: Aug 8, 2013