FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > Verilog

Verilog comp.lang.verilog newsgroup / usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-05-2004, 10:25 PM
weizbox
Guest
 
Posts: n/a
Default 8-bit word to 4-digit, 7-segment display

Hello,

Im pretty new to FPGAs in general and so far have gotten some basic
things down such as get data from my ADC and be able to hardwire
certin values into my 4 digit 7-segment display, but now I need to
combine the two and Im not sure how. Basicly I get an 8-bit binary
number from my ADC, from there how would I turn that number into
usable values to display on my 4-digit 7-segment display? Im using a
refence voltage value of 2.55 V just to make it easier for the time
being, but how do I turn "11111111" into "2.550" on ym display?

Thank you much for your time,
Mark
Reply With Quote
  #2 (permalink)  
Old 10-05-2004, 11:18 PM
Carl W.
Guest
 
Posts: n/a
Default Re: 8-bit word to 4-digit, 7-segment display

weizbox wrote:
> Im pretty new to FPGAs in general and so far have gotten some basic
> things down such as get data from my ADC and be able to hardwire
> certin values into my 4 digit 7-segment display, but now I need to
> combine the two and Im not sure how. Basicly I get an 8-bit binary
> number from my ADC, from there how would I turn that number into
> usable values to display on my 4-digit 7-segment display? Im using a
> refence voltage value of 2.55 V just to make it easier for the time
> being, but how do I turn "11111111" into "2.550" on ym display?


* Slam dunk: Learn to read voltages in hex :-).

* Easy way: 256-word 12-bit lookup ROM on FPGA :-)

* Not too hard: Set up two counters, a binary one &
a decimal one. Initialize the decimal
counter to 0. While the binary counter
is >0, decrement it & increment the
decimal counter. Hold this state machine
until the binary value changes, then
count down/up both counters until it
matches again.

* Just a little
more difficult: Use the counting above, except 2 loops --
one for the 100's digits, one for the
10's digit and you should be able to use
the remainder directly for the last digit.

This is similar to the way we used to do division on the
early microprocessors which didn't have a DIVide instruction.
Reply With Quote
  #3 (permalink)  
Old 10-07-2004, 02:54 PM
weizbox
Guest
 
Posts: n/a
Default Re: 8-bit word to 4-digit, 7-segment display

"Carl W." <[email protected]> wrote in message news:<[email protected]>...
> weizbox wrote:
> > Im pretty new to FPGAs in general and so far have gotten some basic
> > things down such as get data from my ADC and be able to hardwire
> > certin values into my 4 digit 7-segment display, but now I need to
> > combine the two and Im not sure how. Basicly I get an 8-bit binary
> > number from my ADC, from there how would I turn that number into
> > usable values to display on my 4-digit 7-segment display? Im using a
> > refence voltage value of 2.55 V just to make it easier for the time
> > being, but how do I turn "11111111" into "2.550" on ym display?

>
> * Slam dunk: Learn to read voltages in hex :-).
>
> * Easy way: 256-word 12-bit lookup ROM on FPGA :-)
>
> * Not too hard: Set up two counters, a binary one &
> a decimal one. Initialize the decimal
> counter to 0. While the binary counter
> is >0, decrement it & increment the
> decimal counter. Hold this state machine
> until the binary value changes, then
> count down/up both counters until it
> matches again.
>
> * Just a little
> more difficult: Use the counting above, except 2 loops --
> one for the 100's digits, one for the
> 10's digit and you should be able to use
> the remainder directly for the last digit.
>
> This is similar to the way we used to do division on the
> early microprocessors which didn't have a DIVide instruction.




Any site that you know of in which it tells you how to set up a ROM? I
have a table I could use, but as far as getting it on the ROM, im a
little cluesless.

-Mark
Reply With Quote
  #4 (permalink)  
Old 10-07-2004, 04:48 PM
John_H
Guest
 
Posts: n/a
Default Re: 8-bit word to 4-digit, 7-segment display

> Any site that you know of in which it tells you how to set up a ROM? I
> have a table I could use, but as far as getting it on the ROM, im a
> little cluesless.
>
> -Mark


The FPGA manufacturer should have information on how to set up the memory
contents, both as application notes and in their device library reference.
For instance, the Xilinx Libraries Guide (in the online Software Manual)
describes the use of the INIT_00 to INIT_0F constraints to initialize the
RAMB4_S16 which would provide 16 bits of output for your 8 bits of input.


http://toolbox.xilinx.com/docsan/xil...b0344_330.html

You only have 3 digits for 0.01 to 2.55. To avoid using binary to 7-segment
conversion, I'd just code the bottom 2 digits as the 7 segments - 14 bits
total - and use the other 2 bits for the 0/1/2 indication with a simple
wiring to get your elements.

There's a little bit of work in getting the data formatted, but it's pretty
straight-forward.

If, on the other hand, you don't want to bother with the memory at all you
could figure out the digits through logic and do the binary to BCD and BCD
to 7-segment conversions in the chip. The binary-to-BCD is a bit tough
because it involves division through the three stages to get your digits.

Dig1 = int(Val/100)
Dig2 = int((Val-Dig1*100)/10)
Dig3 = Val-Dig1*100-Dig2*10

Since the math isn't simple, the "direct" approach probably isn't the way to
go.

I loved the suggestion of using a BCD counter to read the binary value and
decrement it to zero, each decrement causing an increment on the BCD counter
starting from zero. Your result is a BCD count in less than 256 cycles.
The BCD to 7-segment conversion is a simple case statement.

- John_H


Reply With Quote
  #5 (permalink)  
Old 10-07-2004, 09:23 PM
John_H
Guest
 
Posts: n/a
Default Re: 8-bit word to 4-digit, 7-segment display

"John_H" <[email protected]> wrote in message
news:[email protected]
[snip]
> If, on the other hand, you don't want to bother with the memory at all you
> could figure out the digits through logic and do the binary to BCD and BCD
> to 7-segment conversions in the chip. The binary-to-BCD is a bit tough
> because it involves division through the three stages to get your digits.

[snip]

I integrated the conversion into a divider-like structure. Getting the BCD
bits out directly is a few stages of add/subtract cascaded together.
Apologies to those who don't like to see lots of code. The file looks best
in fixed space font.

The "top" module is a quick testbench to show that everything works. The
resources and delays are a little excessive for the 8-bit binary to bcd
conversion but the result can be combinatorial. No clock required.

If there are questions about the code, feel free to ask but please don't
repost the whole code to be kind to others.

Thanks,
- John_H

module SevenSeg ( bin
, Seg7_2, Seg7_1, Seg7_0
);
input [7:0] bin;
output [6:0] Seg7_2;
output [6:0] Seg7_1;
output [6:0] Seg7_0;

wire [8:0] res200;
wire [7:0] res100;
wire [6:0] res80;
wire [5:0] res40;
wire [4:0] res20;
wire [3:0] res10;
wire [1:0] bcd2;
wire [3:0] bcd1;
wire [3:0] bcd0;
assign {bcd2[1],res200} = 9'd199 - bin; // 1 offset makes sign work
assign {bcd2[0],res100} = res200 + (bcd2[1] ? 9'd100 : 9'd100-9'd200);
assign {bcd1[3],res80 } = res100 + (bcd2[0] ? 8'd80 : 8'd80 -8'd100);
assign {bcd1[2],res40 } = res80 + (bcd1[3] ? 7'd40 : 7'd40 -7'd80 );
assign {bcd1[1],res20 } = res40 + (bcd1[2] ? 6'd20 : 6'd20 -6'd40 );
assign {bcd1[0],res10 } = res20 + (bcd1[1] ? 5'd10 : 5'd10 -5'd20 );
assign bcd0 = (bcd1[0] ? -4'd1 : 4'd9) - res10;
assign Seg7_2 = hex_to_7( bcd2 );
assign Seg7_1 = hex_to_7( bcd1 );
assign Seg7_0 = hex_to_7( bcd0 );

function [6:0] hex_to_7;
input [3:0] digit;
case(digit) // common anode: {t,rt,rb,b,lb,lt,m}
4'h0: hex_to_7 = 7'b0000001; // ---t---
4'h1: hex_to_7 = 7'b1001111; // | |
4'h2: hex_to_7 = 7'b0010010; // lt rt
4'h3: hex_to_7 = 7'b0000110; // | |
4'h4: hex_to_7 = 7'b1001100; // ---m---
4'h5: hex_to_7 = 7'b0100100; // | |
4'h6: hex_to_7 = 7'b0100000; // lb rb
4'h7: hex_to_7 = 7'b0001111; // | |
4'h8: hex_to_7 = 7'b0000000; // ---b---
4'h9: hex_to_7 = 7'b0001100;
4'hA: hex_to_7 = 7'b0001000;
4'hb: hex_to_7 = 7'b1100000;
4'hC: hex_to_7 = 7'b0110001;
4'hd: hex_to_7 = 7'b1000010;
4'hE: hex_to_7 = 7'b0110000;
4'hF: hex_to_7 = 7'b0111000;
endcase
endfunction

endmodule


module top();

integer i;
wire [6:0] Seg7_2, Seg7_1, Seg7_0;

initial
for( i=0; i<256; i=i+1 )
begin
#1 $display( " %c %c %c", Seg7_2[6] ? " " : "_"
, Seg7_1[6] ? " " : "_"
, Seg7_0[6] ? " " : "_"
);
$display( "%3d %c%c%c%c%c%c%c%c%c", i
, Seg7_2[1]? " ":"|", Seg7_2[0]? " ":"_", Seg7_2[5]? " ":"|"
, Seg7_1[1]? " ":"|", Seg7_1[0]? " ":"_", Seg7_1[5]? " ":"|"
, Seg7_0[1]? " ":"|", Seg7_0[0]? " ":"_", Seg7_0[5]? " ":"|"
);
$display( " %c%c%c%c%c%c%c%c%c"
, Seg7_2[2]? " ":"|", Seg7_2[3]? " ":"_", Seg7_2[4]? " ":"|"
, Seg7_1[2]? " ":"|", Seg7_1[3]? " ":"_", Seg7_1[4]? " ":"|"
, Seg7_0[2]? " ":"|", Seg7_0[3]? " ":"_", Seg7_0[4]? " ":"|"
);
end

SevenSeg Disp ( .bin(i)
, .Seg7_2(Seg7_2)
, .Seg7_1(Seg7_1)
, .Seg7_0(Seg7_0)
);

endmodule


Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inconsistency With Format Specification with $display and $sformat Russell Fredrickson Verilog 5 09-30-2004 08:09 PM
Why syntax error when accessing bits of an array word? Gammaburst Verilog 3 10-31-2003 09:05 AM
How to get a module to display it's own instance name? Mike Sendrove Verilog 3 10-21-2003 07:31 PM
How to display upcase char in verilog? Ensoul Chee Verilog 5 08-05-2003 06:33 PM
Word or Adobe Framemaker? Andrew Mazin Verilog 7 07-16-2003 01:02 PM


All times are GMT +1. The time now is 12:52 PM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved