Thank you to the guys at HEGE supporting Badcaps [ HEGE ] [ HEGE DEX Chart ]

Announcement

Collapse
No announcement yet.

suggestions for 3 digit 7-segment display counter.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    suggestions for 3 digit 7-segment display counter.

    Hello,

    I wanted some ideas to see if there's a better way to accomplish this. Let's say I have 3 digit 7-segment LED display and I wanted to have it either count up or down from a predetermined number.

    I had some ideas on how to do this but I'm thinking maybe there's a better way. I was thinking I'd need a PIC with at least 12 I/O pins and I'd set them to output. Then I'd need three BCD (binary coded decimal) to 7-segment decoder / drivers, something like the IC7447, one for each digit.

    The PIC would send out BCD on the I/O pins.

    Is there a better way? Something that doesn't require so many I/O pins? I was thinking maybe one of those LCD dispalys instead of an LED display. What do you guys think?

    In the PIC, I'd have a value set, 100, for example. And then I'd probably have some variable that says either count up or count down. The PIC would then read the variable and then either count up from 0 to whatever value was set or count down from whatever value was set to 0. It'd just loop and either increment or decrement every second. If we're counting up, when the far right display reaches 9, after a second, that display will show 0 and then the middle will show 1.

    I just basically want to make a counter that can display numbers between 0 and 999 (or maybe FFF).

    Thanks.
    -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

    #2
    Re: suggestions for 3 digit 7-segment display counter.

    I wonder if something like the MM74C926 might work: http://www.jameco.com/z/74C926-Major...-18_44599.html

    I don't know if something like that will work though. I don't think I could say hey, start at 57 and count down. From what I've been reading, I think they're just for counting up. Maybe I'm wrong though.
    -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

    Comment


      #3
      Re: suggestions for 3 digit 7-segment display counter.

      Shouldn't be a problem to multiplex the digits together with a PIC, only would need 10 pins with a basic implementation (not charlieplexing them). The other pins could be used to detect buttons or be used to count. Based on my stockpile of microcontrollers, an old Atmel 90S2313 (outdated, replaced with Tiny2313) should do just fine. With a bit of pin sharing it shouldn't be too hard to even do 4 digits and still have control buttons.

      The 74C926 should work fine too if you want to go that route. Less programming needed, but yeah up only...
      Last edited by eccerr0r; 05-14-2017, 08:24 PM.

      Comment


        #4
        Re: suggestions for 3 digit 7-segment display counter.

        This question still plagues me: what exactly do you want to do with this unit? "Serving number X" sign? "X people in queue" sign?

        At one point I was trying to design a 90S2313/Tiny2313 tachometer for the heck of it. I didn't finish it as I didn't really have a need for the device, but it had one tachometer input, RS232 communication, and controlled four 7-seg displays in digital mode or 32 discrete LEDs in "fake" analog mode (where you could place the LEDs in a semicircle to emulate an analog tachometer). In both cases there were enough pins since the 90S2313 had 15 user programmable pins (12 for LEDs, one for tach input, two for rs232)... and no 7447's needed.

        If you wanted to use an even fewer micro controller pins, you'd need to latch extra bits externally and program them serially... but more ICs and board space needed.

        Comment


          #5
          Re: suggestions for 3 digit 7-segment display counter.

          use a serial OLED display.

          or go oldschool, 7segment displays, bcd>7segment drivers and cascaded 4bit up/down counters.

          3 displays,6 chips and about 24 resistors.

          Comment


            #6
            Re: suggestions for 3 digit 7-segment display counter.

            Originally posted by eccerr0r View Post
            At one point I was trying to design a 90S2313/Tiny2313 tachometer for the heck of it.
            forget AVR, ARM is the new baseline. and dirt cheap!
            http://www.ebay.co.uk/itm/291693366485

            Comment


              #7
              Re: suggestions for 3 digit 7-segment display counter.

              A simple PIC would do.

              You don't even need binary to decimal converters or whatever you want.
              Think of it like this.. you receive a number between 0 and let's say 999 into the microcontroller and then you have 3 variables.

              nr = 123;
              digit1 = nr / 100; nr = nr - (digit1 * 100); // or nr = nr mod 100;
              digit2 = nr / 10 ; nr = nr - (digit2*10);
              digit3 = nr;

              Now no matter if your led digit is common annode or common cathode, the digits have 8 leds (the 7 segments and the dot).
              So you can just define an array of 10 elements each element being one char / byte that says which segments should be on for each digit from 0 to 9
              IO pins in the microcontroller are arranged in 8 bit ports, so you can simply say something like PORTAbits = mapping[digit1]; to set all i/o pins in PORT A to value from the array called mapping.

              For example, here's a common cathode led digit (meaning all the grounds of leds are tied together): http://uk.farnell.com/broadcom-limit...-cc/dp/1830006




              maybe pin 6 is at the bottom and 10 at the top.. anyway, it's something you can easily figure out with a multimeter in diode mode.

              And to keep things simple, get any PIC that has a full 8 bit port, the first one I found was PIC16F886 : http://uk.farnell.com/microchip/pic1...-28/dp/1439539

              So you have RC0 to RC7 on the micro, which you can set to 0 or 1 in one shot by setting a byte on the PORTC variable.
              So you connect the 8 segments to the RC0 to RC 7 pins in whatever way you want.. for example like this:

              RC0 : 2 (segment F)
              RC1 : 3 (segment G)
              RC2 : 4 (segment E)
              RC3 : 5 (segment D)
              RC4 : 7 (segment DP)
              RC5 : 8 (segment C)
              RC6 : 9 (segment B)
              RC7 : 10 (segment A)

              Whatever you put in the PORTC variable, it will then be like this [ RC7 | RC6 | RC5 ... | RC0 ] ... so basically with one byte you set all segments on or off [ A | B | C | DP | D | E | G | F ]

              So now you can create a 10 element array, from 0 to 9 in memory.

              The first element in the array would hold the mapping for the digit 0 for which you have to turn on all segments except G and DP, so your variable will be

              mapping[0] = 0b11101101; // digit 0
              mapping[1] = 0b01100000; // digit 1 all segments off except B and C
              ...
              mapping[9] = 0b11101011; // digit 9 all segments on except E and DP

              and if you want to write A, B, C, D, E, F you can just extend this array up to 15..

              Pins 1 and 6 are common cathode. What you do is find a npn transistor, connect the common cathode pins to the collector and the emitter goes to ground.. the npn transistor becomes a switch.. when you send power in the base through a resistor to prevent it from burning up, then the segments connect to ground and light up.



              Then in your code you just have a loop and set the segments for a digit, send 1 through the pin connected to the base of a digit's transistor to enable the digit, wait a few ms, turn off the transistor to disable the digit, set the segments for the next digit and enable the transistor for that digit and so on and then loop back to the first digit.

              You'll need 8 + 3 pins, one for each digit. Or 7 + 3 if you ignore the dot.
              There's also displays with 3 or 4 digits that have 10-12 pins or 8 pins per digit + one for each anode or cathode (you'd use something like ULN2003A for common anode digits as would be quite cheap) and you could link the segments of all digits together and multiplex the digits if you want to reduce the number of wires.
              Attached Files
              Last edited by mariushm; 05-15-2017, 07:35 PM.

              Comment


                #8
                Re: suggestions for 3 digit 7-segment display counter.

                You can also use some more advanced tricks when it comes to multiplexing leds. For example, here's a way to control 6 leds using 3 io pins.. and it can be extended to 12 leds using 4 io pins, and so on ... but it's more difficult as you can't light up more than 2 leds at a single time (and that's only by accident), so for a 8 digit number, you'd have to go through 8 "refreshes" of the digit in order to draw the digit.



                Here's a project where the guy uses 4 io pins to control 12 leds : https://catmacey.wordpress.com/2011/...ived/#more-511

                It's often not worth it, you have more source code and it's more difficult to multiplex the leds, unless you're really restricted by size it's easier to just go with a larger microcontroller with more io pins.
                Attached Files
                Last edited by mariushm; 05-15-2017, 07:52 PM.

                Comment


                  #9
                  Re: suggestions for 3 digit 7-segment display counter.

                  Originally posted by eccerr0r View Post
                  Shouldn't be a problem to multiplex the digits together with a PIC, only would need 10 pins with a basic implementation (not charlieplexing them). The other pins could be used to detect buttons or be used to count. Based on my stockpile of microcontrollers, an old Atmel 90S2313 (outdated, replaced with Tiny2313) should do just fine. With a bit of pin sharing it shouldn't be too hard to even do 4 digits and still have control buttons.

                  The 74C926 should work fine too if you want to go that route. Less programming needed, but yeah up only...
                  I want to look more into this multiplexing. I've been trying to be careful about using google. I want advice, like you gave (ie, multiplexing), but I don't want to see a schematic of how someone else did it. Kinda want to see if I can do it myself from scratch and everything. I appreciate the advice.

                  I really like how you suggest the Atmel 90S2313. I want to add buttons so I can enter the numbers on a touch pad (0 - 9). Thanks!
                  -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                  Comment


                    #10
                    Re: suggestions for 3 digit 7-segment display counter.

                    Originally posted by eccerr0r View Post
                    This question still plagues me: what exactly do you want to do with this unit? "Serving number X" sign? "X people in queue" sign?

                    At one point I was trying to design a 90S2313/Tiny2313 tachometer for the heck of it. I didn't finish it as I didn't really have a need for the device, but it had one tachometer input, RS232 communication, and controlled four 7-seg displays in digital mode or 32 discrete LEDs in "fake" analog mode (where you could place the LEDs in a semicircle to emulate an analog tachometer). In both cases there were enough pins since the 90S2313 had 15 user programmable pins (12 for LEDs, one for tach input, two for rs232)... and no 7447's needed.
                    When I was going through college, I took a digital logics class. We had to do a final project. I got an A for mine but never finished it because I lacked the knowledge. Originally, the idea was to make a count-down timer for a very large model rocket I built. Because of the size of the rocket, it was dangerous for us to be near it when the engine ignited, so I was going to make a device where I could enter a number and start a count down, kinda like in the movies where they have those terrorists or some government trained solder setting off bombs (ie, Rambo 3, where Rambo sneaks into the Russian base camp and sets all those little explosives around the base and has them set to 10 minutes).

                    I felt finally my level of electronic design had progressed enough where I finally might be able to finish the project, although I don't have a use for the device anymore. More or less to see if I actually learned anything over the years and challenge my mind a bit, that's all.

                    Originally posted by eccerr0r View Post
                    If you wanted to use an even fewer micro controller pins, you'd need to latch extra bits externally and program them serially... but more ICs and board space needed.
                    More stuff to look into I guess. I'd like to use fewer micro controller pins, because I do want to add a touch pad or whatever they're called. I have one lying around, with the buttons 0-9, * and # on it. Was gonna try using that to get the input eventually. To me, I think conserving pins is important. Maybe once I get a prototype running, I'll upload the schematic and you guys could suggest optimizations?
                    -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                    Comment


                      #11
                      Re: suggestions for 3 digit 7-segment display counter.

                      Originally posted by stj View Post
                      use a serial OLED display.

                      or go oldschool, 7segment displays, bcd>7segment drivers and cascaded 4bit up/down counters.

                      3 displays,6 chips and about 24 resistors.
                      I'll look into the OLED display. That might be the best way to go. I was thinking "old school" because that's what I was taught. We learned about 7-segment displays, etc. We didn't get too in depth with that stuff though. It was more of a beginners class, to get our feet wet.
                      -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                      Comment


                        #12
                        Re: suggestions for 3 digit 7-segment display counter.

                        Originally posted by mariushm View Post
                        You can also use some more advanced tricks when it comes to multiplexing leds. For example, here's a way to control 6 leds using 3 io pins.. and it can be extended to 12 leds using 4 io pins, and so on ... but it's more difficult as you can't light up more than 2 leds at a single time (and that's only by accident), so for a 8 digit number, you'd have to go through 8 "refreshes" of the digit in order to draw the digit.



                        Here's a project where the guy uses 4 io pins to control 12 leds : https://catmacey.wordpress.com/2011/...ived/#more-511

                        It's often not worth it, you have more source code and it's more difficult to multiplex the leds, unless you're really restricted by size it's easier to just go with a larger microcontroller with more io pins.
                        Thank you! I originally thought of driving the 7-segment displays (or 8) directly from the PIC, but thought I could save pins by using a bcd to decimal IC or something. I appreciate the information on multiplexing. I don't fully understand it though from what you've posted and have to research it a bit more. Maybe after checking out that link it'll make a bit more since.

                        Thanks!
                        -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                        Comment


                          #13
                          Re: suggestions for 3 digit 7-segment display counter.

                          Originally posted by mariushm View Post
                          A simple PIC would do.
                          ...
                          You'll need 8 + 3 pins, one for each digit. Or 7 + 3 if you ignore the dot.
                          There's also displays with 3 or 4 digits that have 10-12 pins or 8 pins per digit + one for each anode or cathode (you'd use something like ULN2003A for common anode digits as would be quite cheap) and you could link the segments of all digits together and multiplex the digits if you want to reduce the number of wires.
                          That last image there, the mcu.png, did you create that yourself? If so, do you mind me asking what program you used? I only have Eagle 7.3.0 light now (the freeware version). I was thinking of saving up and buying a Pro copy, but they switched to a subscription based license. I'm trying to find a semi-easy to use schematic / board layout program now.

                          I tried KiCad but didn't like how I had to pick the package for every single component I added. I found that to be a real pain.
                          -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                          Comment


                            #14
                            Re: suggestions for 3 digit 7-segment display counter.

                            I tried to quickly make a schematic in DipTrace but I was lazy and opened up msPaint and then took out the picture of the PIC and the transistors from a couple of datasheets I opened from Digikey and pasted them on the canvas. Rest is just lines and rectangles and text tool.

                            Literally searched for the first cheap DIP package 28 pin PIC chip on Digikey because these usually have multiple full 8 bit ports. 20 pin or 16 pin or 14 pin parts usually have 2 x 4 pin ports, or they have 2 full 8 bit ports but one port may have an input only pin, and the other port may have more useful pins like the i2c/uart ones which you may want to use for other things.

                            I wanted to keep things as simple as possible.

                            You really can easily modify some code to use 4 pins from one port and 4 pins from another port (would be something as basic as shift left value by 4 or shift right value by 4 etc, but I wanted to explain as easy as possible.

                            The TIP2 picture is from an application note Microchip has something called Tips and Tricks .. i think they even include these pdfs on the PicKit 3 (programmer) CD:

                            1. Microchip Technology Inc. DS01146B Compiled Tips ‘N Tricks Guide https://cdn.badcaps-static.com/pdfs/...740bf3fe08.pdf

                            1.5. New Peripherals Tips ‘n Tricks : The Complementary Waveform Generator (CWG), Configurable Logic Cell (CLC), and the Numerically Controlled Oscillator (NCO) Peripherals https://cdn.badcaps-static.com/pdfs/...cd95914060.pdf

                            2. https://cdn.badcaps-static.com/pdfs/...2b6b382e71.pdf

                            3. https://cdn.badcaps-static.com/pdfs/...98cebbdeeb.pdf
                            Last edited by mariushm; 05-17-2017, 06:15 PM.

                            Comment


                              #15
                              Re: suggestions for 3 digit 7-segment display counter.

                              "fritzing" looks like a fast beginer soft.
                              http://fritzing.org/

                              another member is using it:
                              https://www.badcaps.net/forum/showthread.php?t=62229

                              Comment


                                #16
                                Re: suggestions for 3 digit 7-segment display counter.

                                because you know c / c++ i would use an arm board and a serial display with a matrix keyboard - total cost well under $10

                                Comment


                                  #17
                                  Re: suggestions for 3 digit 7-segment display counter.

                                  I'm trying out some program called PCBWeb. It looks a bit promising. Here's a list to some site that lists the "10 best free" PCB layout / schematic editors. It seems the PCBWeb has a BOM section, which could be nice. I see it lists stuff from DigiKey. Maybe it's customizable and I can edit / add other stores, kinda like how in some browsers (ie, Firefox), you can set custom search engines. You'd go to some site, like badcaps.net, and the browser would say something like type test in the search box at badcaps.net. Afterwards, copy and paste the web address here. Then, in the future, you could just search badcaps.net from the browser without having to physically go to the website and do it manually.

                                  It'd be nice if I could add different sources for the BOM, but if not, that's okay. The program also has board etching services or whatever they're called. So you can just pick one from the drop down menu and it'll tell you how much it'd cost to get that particular design etched from that company.

                                  It's free and I've downloaded it and installed it. Just tried running it and I need to register for free to use it I guess, but if it turns out to be really good, I'll let you guys know. I'll check out fritzing
                                  -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                                  Comment


                                    #18
                                    Re: suggestions for 3 digit 7-segment display counter.

                                    Originally posted by mariushm View Post
                                    I tried to quickly make a schematic in DipTrace but I was lazy and opened up msPaint and then took out the picture of the PIC and the transistors from a couple of datasheets I opened from Digikey and pasted them on the canvas. Rest is just lines and rectangles and text tool.

                                    Literally searched for the first cheap DIP package 28 pin PIC chip on Digikey because these usually have multiple full 8 bit ports. 20 pin or 16 pin or 14 pin parts usually have 2 x 4 pin ports, or they have 2 full 8 bit ports but one port may have an input only pin, and the other port may have more useful pins like the i2c/uart ones which you may want to use for other things.

                                    I wanted to keep things as simple as possible.

                                    You really can easily modify some code to use 4 pins from one port and 4 pins from another port (would be something as basic as shift left value by 4 or shift right value by 4 etc, but I wanted to explain as easy as possible.

                                    The TIP2 picture is from an application note Microchip has something called Tips and Tricks .. i think they even include these pdfs on the PicKit 3 (programmer) CD:

                                    1. Microchip Technology Inc. DS01146B Compiled Tips ‘N Tricks Guide https://cdn.badcaps-static.com/pdfs/...740bf3fe08.pdf

                                    1.5. New Peripherals Tips ‘n Tricks : The Complementary Waveform Generator (CWG), Configurable Logic Cell (CLC), and the Numerically Controlled Oscillator (NCO) Peripherals https://cdn.badcaps-static.com/pdfs/...cd95914060.pdf

                                    2. https://cdn.badcaps-static.com/pdfs/...2b6b382e71.pdf

                                    3. https://cdn.badcaps-static.com/pdfs/...98cebbdeeb.pdf
                                    Originally, I was thinking of using the BCD to decimal ICs because then I could control two 7-segment displays from one port, instead of having a full port dedicated to one display...I gotta research a bit about the keypad as well. It's been a long time since I played with something like that. I figure I'd need at least 8 IO pins to interface with the keypad....

                                    So, without the BCD to decimal ICs, I'd need at least four 8-bit ports, unless I'm missing something.
                                    -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                                    Comment


                                      #19
                                      Re: suggestions for 3 digit 7-segment display counter.

                                      We were trying to use multiplexing where basically we'd flash the 7-seg displays at a high rate, and using persistence of vision to trick people into thinking all the digits are lit at the same time. This trick reduces the number of pins needed such that a single microcontroller with no external decoders needed to display a number - have it all done in software.

                                      Using a 40 pin ARM processor, there are enough pins likely to drive all three digits directly and not need to multiplex... That's sort of what the old 7107 ADC does...

                                      Comment


                                        #20
                                        Re: suggestions for 3 digit 7-segment display counter.

                                        Keypads are easy, and can be done in multiple ways.

                                        The easiest would be to connect every button to an input pin of your microcontroller but that uses a lot of pins.

                                        Another method would be to use the built in ADC (analogue to DC converter) to convert an analogue voltage to a value.

                                        Most PIC micros have 10bit ADC and some have built in voltage references or can use input voltage as maximum voltage. So for example, you can power the PIC with 5v and you can configure the voltage reference to 4.096v and then the ADC will return a number between 0 and 1023, basically 4 mV per step.
                                        If you use the 5v input voltage as "reference", you just divide 5v by 1024 and multiply with the value the ADC gives you, to get the voltage on the ADC pin.

                                        So now you can simply use resistors to create voltage dividers and whenever you push a button, you create a voltage divider which sends a voltage between 0v and 5v on that ADC pin and your microcontroller measures it.




                                        See TIP 7 in the first PDF I linked to :



                                        Whenever you press a button, there's always two resistors on the "top" side in series, and the fixed resistor on the bottom side. So the voltage the ADC pin sees is always (adapting the formula above)

                                        Vout = Vin x [ Rbottom / (Rbottom + Rtop1 + Rtop2) ]

                                        So just by using different resistors for each column and each line on that 4x4 matrix of buttons, you can make it so every time you press a button, you'll get a different voltage on the ADC pin (for example 16 buttons, 16 different levels, so you aim for 1024 / 16 = 64 steps or 64 x 4mV = 256 mv but you want some safety margin on both sides, like around 20mV ...

                                        First button should output something between 0v and 256mV, with safety margins anything between 20mV and 230mV ... let's say aim for 0.15v
                                        Second button should output something between 256mV and 512mV, with safety margins anything between 280mV and 490mV, let's say aim for 0.35v

                                        .. and so on..

                                        The problem with this scheme is obviously that you'd need a lot of 1% tolerance resistors and different values, which increases the cost of this.

                                        You can do a sort of hybrid of this by splitting the matrix in 2 (2x4) and use 2 adc pins and scan half the keyboard first and then scan the other half

                                        Or you can separate the columns at the top and power only one column at the top using a pin for each column (so for 4x4 matrix you'd have 4 output pins and one input pin used) and you'd need 4 consecutive adc conversions to determine if a button is pressed. You save money on resistors and you only need a few different resistors, but it takes more time to scan all the keys.

                                        Note that these schemes save pins but obviously when you press two buttons at the same time, you get garbage, can't detect two or more buttons at same time.

                                        If you want that, cheap options would be to use port extenders or shift registers that can work the other way around, meaning they have 8 or more input pins and you can read the pin states by using two pins on your micro (clock and data) ... this way, each button is connected to an input pin and your microcontroller reads the 8-16 pin states every time into a variable, so multiple buttons pressed at same time is no problem.

                                        Ex 74HC597D https://www.digikey.com/product-deta...2822-ND/763089 (8 parallel in, 2 serial out)

                                        You can also do hybrid style like use one output pin to send voltage to 2x4 buttons and read the 8 bits from the shift register, then turn off pin and use another output pin to power the other 2x4 buttons which are also connected to the same shift register... read the 8 bits again and you have the state of all 16 buttons using one shift register and 4 mcu pins.

                                        Slightly more expensive (but cheaper than microcontrollers) are port expanders: https://www.digikey.com/short/3dcb2j
                                        You get 8/16/16+ i/o ports that you can read state or set state through i2c or spi (2 pins on your micro) but they may also give you some benefits that your micro may not have (if it's on the cheaper side), like interrupt on change (so instead of constantly reading button states in a loop, just let the port expander IC interrupt the cpu through i2c and basically say hey a button state has changed)

                                        Newer PIC micros have interrupt on change on specific ports or pins, so if you connect 8 buttons to 8 io pins on a port and then when someone presses a button, you automatically get an interrupt and make it so a function in your code is executed at that moment, instead of constantly checking if buttons are pressed.
                                        Attached Files
                                        Last edited by mariushm; 05-18-2017, 02:03 PM.

                                        Comment

                                        Working...
                                        X