Author Topic: 16 bit to 4 digit 7 segment decoder  (Read 15415 times)

0 Members and 1 Guest are viewing this topic.

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1718
  • Country: gb
Re: 16 bit to 4 digit 7 segment decoder
« Reply #50 on: December 23, 2019, 07:35:38 pm »
Wow, these solutions are varied but have run away.   I'm unsure of the exact restrictions, but 30 5V IO, ease of use and cost, I will stand by an Atmega8515.  $2.50, has Arduino support if you're up for fast development, easily available etc.. you just need current limiting resistors for the segments and maybe transistors for the commons (but often you can just drive from the IO) and thats it.  Why all the glue logic and memories?

Sure you could use a CPLD, but quite a lot of the cells will be used to store your 16-bit data, plus they tend to be more expensive than an MCU (especially the 5V tolerant ones).
 

Offline GeorgeOfTheJungle

  • Super Contributor
  • ***
  • !
  • Posts: 2699
  • Country: tr
Re: 16 bit to 4 digit 7 segment decoder
« Reply #51 on: December 23, 2019, 09:15:02 pm »
Wow, these solutions are varied but have run away.   I'm unsure of the exact restrictions, but 30 5V IO, ease of use and cost, I will stand by an Atmega8515.  $2.50, has Arduino support if you're up for fast development, easily available etc..

A blue pill can do it as well and it's faster, smaller and only $1. Just sayin'  :)
The further a society drifts from truth, the more it will hate those who speak it.
 

Online westfw

  • Super Contributor
  • ***
  • Posts: 4349
  • Country: us
Re: 16 bit to 4 digit 7 segment decoder
« Reply #52 on: January 04, 2020, 08:09:30 am »
Lots of ~40pin micros are in the $1 range and could do this fine.  Some in DIPs, even (Atmega4809 is currently cheaper than ATmega8515, and ATmega32as are available for about $0.75 on Aliexpress...

Or two smaller microcontrollers with a serial link between them (extensible!) - it's a human-readable display, right?  It doesn't need to update as fast as the inputs can change...
 

Offline obiwanjacobiTopic starter

  • Super Contributor
  • ***
  • Posts: 1013
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: 16 bit to 4 digit 7 segment decoder
« Reply #53 on: January 04, 2020, 09:01:09 am »
Yep, just for debugging and verification at very low clock rates. I also want a latch signal on there as well in order to be able to capture specific bus events.

I have ordered the ATmega8515 to give it a try. (waiting...)

Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline obiwanjacobiTopic starter

  • Super Contributor
  • ***
  • Posts: 1013
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: 16 bit to 4 digit 7 segment decoder
« Reply #54 on: January 26, 2020, 04:49:09 pm »
Made a breadboard test setup and used an Arduino Uno to program the Atmega8515. Came up with something like this.



Have a quick and dirty Arduino sketch that demonstrates it working.

I have setup a timer interrupt to do the multiplexing and the main loop just reads in the two ports and bit-shifts it into 4 digit (volatile) variables that are used by the timer interrupt to display.

I am now building a perf board to test it further and actually use it - see if I come up with more features.

I made a quick PCB layout and routing and could get all traces on one side  8)

I will put it on my github when its a little less rough...

Code: [Select]
const uint8_t DecoderTable_size = 17;
uint8_t DecoderTable[DecoderTable_size] =
    {
        0b00000001,
        0b01111110,
        0b00001100,
        0b10110110,
        0b10011110,
        0b11001100,
        0b11011010,
        0b11111010,
        0b00001110,
        0b11111110,
        0b11001110,
        0b11101110,
        0b11111000,
        0b01110010,
        0b10111100,
        0b11110010,
        0b11100010,
};

uint8_t decode7(uint8_t value)
{
  if (value >= DecoderTable_size)
    return DecoderTable[0];

  return DecoderTable[value + 1];
}

void outputDigit4(uint8_t value, int digit)
{
  uint8_t cathode = ~(1 << digit) & 0x0F;
  uint8_t b = (PORTB & 0xF0);

  PORTD = 0;
  PORTB = b | cathode;
  PORTD = decode7(value);
}

// digit values that will be displayed
// timer interrupt will drive 7-seg
const uint8_t digitValue_size = 4;
// 0-3 => left to right
volatile uint8_t _digitValue[digitValue_size];

// what digit are we writing?
volatile uint8_t _digitIndex;

// called when ORC1A is reached
ISR(TIMER1_COMPA_vect)
{
  outputDigit4(_digitValue[_digitIndex], _digitIndex);

  if (_digitIndex < digitValue_size)
  {
    _digitIndex++;
  }
  else
  {
    _digitIndex = 0;
  }
}

void setupTimer()
{
  OCR1A = 0x1FF;
  TCCR1B |= 0b010;        // prescaler: CS1[2:0]
  TCCR1B |= (1 << WGM12); // CTC mode
  TIMSK |= (1 << OCIE1A); // enable interrupt
}

void setupPorts()
{
  // input sampling ports
  DDRA = 0;
  DDRC = 0;

  // 7-seg drivers
  DDRB |= 0x0F;
  DDRD = 255;
}

void setup()
{
  setupTimer();
  setupPorts();
  sei();
}

void printDigit16(uint8_t msb, uint8_t lsb)
{
  _digitValue[0] = msb >> 4;
  _digitValue[1] = msb & 0x0F;
  _digitValue[2] = lsb >> 4;
  _digitValue[3] = lsb & 0x0F;
}

void loop()
{
  uint8_t msb = PINA;
  uint8_t lsb = PINC;

  printDigit16(msb, lsb);
}

int main()
{
  setup();
  while (true)
  {
    loop();
  }
}
« Last Edit: January 26, 2020, 05:01:28 pm by obiwanjacobi »
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 6420
  • Country: de
Re: 16 bit to 4 digit 7 segment decoder
« Reply #55 on: January 26, 2020, 07:00:39 pm »
Where are the common cathode drivers?

 

Offline obiwanjacobiTopic starter

  • Super Contributor
  • ***
  • Posts: 1013
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: 16 bit to 4 digit 7 segment decoder
« Reply #56 on: January 26, 2020, 07:33:27 pm »
Where are the common cathode drivers?

Misread the NSB3881 datasheet.  :palm: So I will need them.

Any recommendations for a logic level FET?
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 6420
  • Country: de
Re: 16 bit to 4 digit 7 segment decoder
« Reply #57 on: January 26, 2020, 07:45:49 pm »
Just use a ULN2003. It doesn't get any simpler or cheaper.

 

Offline bson

  • Supporter
  • ****
  • Posts: 2497
  • Country: us
Re: 16 bit to 4 digit 7 segment decoder
« Reply #58 on: January 27, 2020, 08:27:31 pm »
Many of the 48 pin QFP MSP430's will do this neatly, and have enough 16 bit ports to make life easy.  Since it's a 16-bit processor you can stage the segment output as 16 bit data in a pattern buffer, to be output to a 16-bit port to drive the segments, and just have a DMA controller continuously scan it, possibly triggered by a timer.  When the DMA gets to the end it interrupts and you restart it in the handler. Then to update the segments you write to the pattern buffer.  Since each segment gets the same number of words staged in the pattern buffer this becomes simple and reliable, without potentially weird timing problems as it might if different bits in different GPIO registers are updated in sequence.  Similarly on the input, a GPIO pin interrupts and you read a 16-bit I/O register.  If it has changed you wake the main CPU in the interrupt handler (DMA will run in some sleep modes, and you wake it by modifying the pushed status register; TI-CCS has C macros and functions for this), save the new value (so you can detect changes), translate it to digits, convert to segment I/O words and store them to the pattern buffer, and go back to sleep.
 

Offline edavid

  • Super Contributor
  • ***
  • Posts: 3464
  • Country: us
Re: 16 bit to 4 digit 7 segment decoder
« Reply #59 on: January 27, 2020, 10:15:17 pm »
Where are the common cathode drivers?

Misread the NSB3881 datasheet.  :palm: So I will need them.

What's your peak segment current?  If it's 10mA, 70mA/digit is not all that far from the spec of 40mA per pin.  It would probably work OK.
 

Online oPossum

  • Super Contributor
  • ***
  • Posts: 1472
  • Country: us
  • Very dangerous - may attack at any time
Re: 16 bit to 4 digit 7 segment decoder
« Reply #60 on: January 27, 2020, 11:54:04 pm »
2N7000 and 2N7002 N channel MOSFETs will work with 5 volt CMOS logic. TO-92 or SOT-23 package.
 

Offline obiwanjacobiTopic starter

  • Super Contributor
  • ***
  • Posts: 1013
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: 16 bit to 4 digit 7 segment decoder
« Reply #61 on: January 28, 2020, 06:27:11 am »
Many of the 48 pin QFP MSP430's will do this neatly, and have enough 16 bit ports to make life easy.  Since it's a 16-bit processor you can stage the segment output as 16 bit data in a pattern buffer, to be output to a 16-bit port to drive the segments, and just have a DMA controller continuously scan it, possibly triggered by a timer.  When the DMA gets to the end it interrupts and you restart it in the handler. Then to update the segments you write to the pattern buffer.  Since each segment gets the same number of words staged in the pattern buffer this becomes simple and reliable, without potentially weird timing problems as it might if different bits in different GPIO registers are updated in sequence.  Similarly on the input, a GPIO pin interrupts and you read a 16-bit I/O register.  If it has changed you wake the main CPU in the interrupt handler (DMA will run in some sleep modes, and you wake it by modifying the pushed status register; TI-CCS has C macros and functions for this), save the new value (so you can detect changes), translate it to digits, convert to segment I/O words and store them to the pattern buffer, and go back to sleep.

I'm looking forward to your version!  ;D :popcorn:

What's your peak segment current?  If it's 10mA, 70mA/digit is not all that far from the spec of 40mA per pin.  It would probably work OK.
Yep its 10mA per segement, but the MCU pin is only 20mA. I have it on the breadboard without cathode-driver and I wouldn't mind it being a little brighter.

2N7000 and 2N7002 N channel MOSFETs will work with 5 volt CMOS logic. TO-92 or SOT-23 package.
Don't I need P-Channel here: low-side/cathode?
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline edavid

  • Super Contributor
  • ***
  • Posts: 3464
  • Country: us
Re: 16 bit to 4 digit 7 segment decoder
« Reply #62 on: January 28, 2020, 04:13:40 pm »
What's your peak segment current?  If it's 10mA, 70mA/digit is not all that far from the spec of 40mA per pin.  It would probably work OK.
Yep its 10mA per segement, but the MCU pin is only 20mA. I have it on the breadboard without cathode-driver and I wouldn't mind it being a little brighter.

On the datasheet (http://ww1.microchip.com/downloads/en/devicedoc/doc2512.pdf), page 197, it says 40mA per pin.

A modern display would be at least 10X brighter... just saying  :-//
 

Offline obiwanjacobiTopic starter

  • Super Contributor
  • ***
  • Posts: 1013
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: 16 bit to 4 digit 7 segment decoder
« Reply #63 on: January 28, 2020, 06:46:08 pm »
Yes I see you're right. Wonder how I got 20mA in my head. Thanks!

I have been eyeing some modern 4 digit common cathode displays...
I think I'll design my PCB in such a way that both/multiple can be fitted - if its not too much trouble.
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3508
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: 16 bit to 4 digit 7 segment decoder
« Reply #64 on: January 28, 2020, 07:41:34 pm »
Maybe it is doable using just some logic chips? 74HC164 + 74HC4511 + ULN2003 + 74HCU04/74HC14 + 4x 74LVC4245. The choice of 74HCU04 versus 74HC14 depends on your clock choice, 74HCU04 for crystal and ceramic clocks, 74HC14 for RC clocks.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15797
  • Country: fr
Re: 16 bit to 4 digit 7 segment decoder
« Reply #65 on: January 28, 2020, 07:44:07 pm »
Don't I need P-Channel here: low-side/cathode?

Nope?
 

Offline obiwanjacobiTopic starter

  • Super Contributor
  • ***
  • Posts: 1013
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: 16 bit to 4 digit 7 segment decoder
« Reply #66 on: January 28, 2020, 08:00:12 pm »
Don't I need P-Channel here: low-side/cathode?

Nope?
;D
Thanks, I looked it up again.

Is there a smaller ULN2003. Not 7 darlingtons but less, 4 (or 2x2)?
« Last Edit: January 28, 2020, 08:02:36 pm by obiwanjacobi »
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1718
  • Country: gb
Re: 16 bit to 4 digit 7 segment decoder
« Reply #67 on: January 28, 2020, 08:59:33 pm »
Am I missing some kind of design restriction here or do you just need something to drive the common cathodes of the segment display?  Jellybean NPN transistors with base resistors will do just fine.  2N7000 will also work.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15797
  • Country: fr
Re: 16 bit to 4 digit 7 segment decoder
« Reply #68 on: January 28, 2020, 11:01:22 pm »
Yeah frankly, you're dealing with < 100mA of current here. You can use any small NMOS directly driven by a GPIO. You can add series resistors to the gates for good measure, but even that could be done without...
 

Online macboy

  • Super Contributor
  • ***
  • Posts: 2309
  • Country: ca
Re: 16 bit to 4 digit 7 segment decoder
« Reply #69 on: January 29, 2020, 05:50:15 pm »
I have a (couple of) 4 digit 7 segment display module (NSB3881) and want to use it to plug into data and address buses of hobby projects to display bus values. The 7seg unit is common cathode and has all the segment lines (a-g/dp) connected over all 4 digits.

I want to make a self-contained module with a 0.1" header that can be plugged into breadboards (5V logic).

So I started to try to program a 2-digit version into a GAL22V10 (winCupl) but the segment mapping table generated too many product terms.
My other thought was to use a cheap micro (preferably Atmel/AVR - don't know PIC and don't have the programmer for it) to read the bus signals and output the 7seg data for each digit. It would need 16 (bus data) + 8 (a-g/dp) + 4 (digit common cathodes) = 28 IO pins. (would like a reset and an optional latch too => 30 IO pins).

Then I thought that perhaps there is a(nother) clever way to solve this problem and came here for inspiration.
Suggestions?

I'd say ditch the old display modules and just buy something new. For around $1 you can get a 8 digit 7-segment display which is controlled serially using a MAX7219-alike controller. Then a small cheap micro like Arduino Nano (etc) has just enough I/O for the 16 bit input and to control the display. The extra digits could be used to hold min/max values, display voltage read from an A/D pin, etc. Or use the vertical segments to display the raw bits (4 bits per 7-seg digit).
 

Offline obiwanjacobiTopic starter

  • Super Contributor
  • ***
  • Posts: 1013
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: 16 bit to 4 digit 7 segment decoder
« Reply #70 on: January 30, 2020, 07:26:31 am »
I have a (couple of) 4 digit 7 segment display module (NSB3881) and want to use it to plug into data and address buses of hobby projects to display bus values. The 7seg unit is common cathode and has all the segment lines (a-g/dp) connected over all 4 digits.

I want to make a self-contained module with a 0.1" header that can be plugged into breadboards (5V logic).

So I started to try to program a 2-digit version into a GAL22V10 (winCupl) but the segment mapping table generated too many product terms.
My other thought was to use a cheap micro (preferably Atmel/AVR - don't know PIC and don't have the programmer for it) to read the bus signals and output the 7seg data for each digit. It would need 16 (bus data) + 8 (a-g/dp) + 4 (digit common cathodes) = 28 IO pins. (would like a reset and an optional latch too => 30 IO pins).

Then I thought that perhaps there is a(nother) clever way to solve this problem and came here for inspiration.
Suggestions?

I'd say ditch the old display modules and just buy something new. For around $1 you can get a 8 digit 7-segment display which is controlled serially using a MAX7219-alike controller. Then a small cheap micro like Arduino Nano (etc) has just enough I/O for the 16 bit input and to control the display. The extra digits could be used to hold min/max values, display voltage read from an A/D pin, etc. Or use the vertical segments to display the raw bits (4 bits per 7-seg digit).

That may be the direction this would be going in the end. I did not fully realize how old these modules were and how much the LEDs have improved over the years. The initial idea was to use what I had and for now that will be sufficient (currently building one prototype on perf-board after trying it out on a breadboard) but when I need a couple of them I may well upgrade.

The initial question was more aimed at how to condense the logic needed for a 4-bit to hex-digit decoder. For the idea was to use a GAL to do the decoding. That could also still be a nice option (a lot of people would be happy with) - have a single chip that drives one digit on 4 bits of data.

Thanks guys, for sharing all your ideas.
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15797
  • Country: fr
Re: 16 bit to 4 digit 7 segment decoder
« Reply #71 on: January 30, 2020, 04:45:11 pm »
That may be the direction this would be going in the end. I did not fully realize how old these modules were and how much the LEDs have improved over the years. The initial idea was to use what I had and for now that will be sufficient (currently building one prototype on perf-board after trying it out on a breadboard) but when I need a couple of them I may well upgrade.

Yup, now that you settled for using a MCU, you could "upgrade" this using either more recent LED displays or even an LCD display instead, which would reduce power consumption a lot and could allow some fancier display.
 

Offline obiwanjacobiTopic starter

  • Super Contributor
  • ***
  • Posts: 1013
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: 16 bit to 4 digit 7 segment decoder
« Reply #72 on: January 31, 2020, 08:03:07 am »
Or one of those sexy small SPI OLED displays ...  8)

Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline obiwanjacobiTopic starter

  • Super Contributor
  • ***
  • Posts: 1013
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: 16 bit to 4 digit 7 segment decoder
« Reply #73 on: February 05, 2020, 04:19:24 pm »
I've published my code and schematic.
https://github.com/obiwanjacobi/16BitDigits8515

Also finished the perf-board prototype that is working nicely.
Enjoy.
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 
The following users thanked this post: edavid

Offline Benta

  • Super Contributor
  • ***
  • Posts: 6420
  • Country: de
Re: 16 bit to 4 digit 7 segment decoder
« Reply #74 on: February 05, 2020, 07:27:38 pm »
I've published my code and schematic.
https://github.com/obiwanjacobi/16BitDigits8515

Also finished the perf-board prototype that is working nicely.
Enjoy.

I'm still missing the common cathode drivers...

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf