+ Post New Thread
Results 21 to 33 of 33

18th June 2018, 09:53 #21
Awards:
 Join Date
 Apr 2014
 Posts
 13,151
 Helped
 3037 / 3037
 Points
 64,787
 Level
 62
Re: Verilog code for BCD to Floating point representation
Hi,
What´s the problem with "updating your own drawing" with the requested informations?
I will come back if I see that you  at least try to  do what you have been toold.
KlausPlease don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.

18th June 2018, 17:16 #22
 Join Date
 Nov 2012
 Posts
 2,661
 Helped
 620 / 620
 Points
 14,383
 Level
 28
Re: Verilog code for BCD to Floating point representation
The scaling and display has to be done in software.
I am not going to write the code for you but I shall show the way.
Let us assume that the ADC max scaling is set at 3.3V. I assume that your ADC is configured at 12bits, single ended (unsigned).
In that case 3.3V > 2^121 (4095)
any arbitrary voltage between 04095 will be scaled linearly > x*3.3/4096 (this will be a float value)
But you will have to compute this in integer mode; so need some tricks.
Fix the decimal point at the 2nd position from the left (X.ABC) your display will tell how to do that.
Now scale the result by 1000; you will get x*3300/4096 (dividing by 4096 in binary is not difficult)
Hence multiply x*3300 (the result must be long int) shift the result 12 bit to get the final result (with a factor of 1000)
Put the result in 16 bits. This is the required result. You will have to split in four digits.
Let the result, call that res. digit1 (rightmost) = remainder (res/10); res1=quotient(res/10)
digit2=remainder(res1/10); res2=quotient(res1/10)
digit3=remainder(res2/10); res3=quotient(res2/10)
digit4=remainder(res3/10); res4=quotient(res3/10)
res4 should be zero; test for it!!
Send digit1, digit2, digit3 and digit4 to the display (low 4bits; as needed; high 4bits should be zero)
Test with some random value for x (03.3) just to convince yourself.

Advertisment

18th June 2018, 17:57 #23
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 42,978
 Helped
 13079 / 13079
 Points
 247,205
 Level
 100
Re: Verilog code for BCD to Floating point representation
First part of your answer (ADC result scaling to integer millivolt) has been already discussed in post #6 and #7.
BCD conversion with /10 division isn't particularly effective in FPGA, that's why post #6 suggests double dabble algorithm.

18th June 2018, 21:28 #24
 Join Date
 Apr 2018
 Location
 Gdańsk, Poland
 Posts
 76
 Helped
 13 / 13
 Points
 487
 Level
 4
 Blog Entries
 3
Re: Verilog code for BCD to Floating point representation
I am sure this is obvious, but I would like to point that if we want to be precisely, it should be x*max_analog/max_digital. That is x*3.3/4095
but we use FPGA, so it is the best if we would divide by the power of 2 (then we use shifting instead of division). That is if we approximate the value 4095 to its near power of 2 value, which is 2^12 = 4096, we get the above equation: x*3.3/4096

18th June 2018, 22:47 #25
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 42,978
 Helped
 13079 / 13079
 Points
 247,205
 Level
 100
Re: Verilog code for BCD to Floating point representation
if we want to be precisely, it should be x*max_analog/max_digital. That is x*3.3/4095
but we use FPGA, so it is the best if we would divide by the power of 2 (then we use shifting instead of division). That is if we approximate the value 4095 to its near power of 2 value, which is 2^12 = 4096, we get the above equation: x*3.3/4096

19th June 2018, 01:15 #26
Awards:
 Join Date
 Apr 2014
 Posts
 13,151
 Helped
 3037 / 3037
 Points
 64,787
 Level
 62
Re: Verilog code for BCD to Floating point representation
Hi,
Most 12bit ADC have a quantization step of Vref/4096
They all use digital_value = analog_value × 2^n / VRef.
Since the digital value is 0...4095, the most highest voltage it can represent is VRef × 4095 / 4096.
In detail one needs to consult the datasheet.
KlausPlease don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.

Advertisment

19th June 2018, 02:41 #27
 Join Date
 Nov 2012
 Posts
 2,661
 Helped
 620 / 620
 Points
 14,383
 Level
 28
Re: Verilog code for BCD to Floating point representation
I would like to point that if we want to be precisely, it should be x*max_analog/max_digital. That is x*3.3/4095...
In reality, you may find the last digit fluctuating and practically unreadable. In fact, ADC results 123 will just appear as zero in the display...

19th June 2018, 06:08 #28
 Join Date
 Mar 2018
 Posts
 14
 Helped
 0 / 0
 Points
 10
 Level
 1

19th June 2018, 07:30 #29
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 42,978
 Helped
 13079 / 13079
 Points
 247,205
 Level
 100
Re: Verilog code for BCD to Floating point representation
Regarding the text in "updated diagram", seems like you are repeating questions that have been already answered throughout this thread.

19th June 2018, 09:29 #30
 Join Date
 Apr 2018
 Location
 Gdańsk, Poland
 Posts
 76
 Helped
 13 / 13
 Points
 487
 Level
 4
 Blog Entries
 3
Re: Verilog code for BCD to Floating point representation
We really want to help you, but you don't step forward and don't cooperate.
My last attempt to help you: how FPGA is connected with a 7segs?
Please attach the drawings.

Advertisment

20th June 2018, 04:58 #31
 Join Date
 Feb 2015
 Posts
 912
 Helped
 263 / 263
 Points
 5,510
 Level
 17
Re: Verilog code for BCD to Floating point representation
I think I would just use a small FSM with maybe a 32b accumulator, a 4b counter, and a binary to bcd circuit.
1V = 1241.21 repeating counts. adding 20 bits of fractional precision gives:
1V = 1301505242 (must round up if not exactly an integer).
100mV = 130150525.
10mV = 13015053.
1mV = 1301505 (can round normally.)
From there you have a FSM that loads the 32b accumulator with the 12b sample in the 12msb and 0's for the lower 20 bits. each cycle where the accumulator is greater than the accumulator for 1V, subtract that value and add 1 to the counter. When the accumulator is less than the 1V value, the counter has the 1's place for voltage. The counter is then reset. Then the fsm does the same thing with the 100mV value. This is why the 100mV value was rounded up  it had to avoid ever getting a value of "10". The process repeats for the 10mV and then the 1mV case. It takes around 2 + 9 + 9 + 9 = 29 cycles to convert the value in the worst case. a little longer if the fsm has extra states. (32b is also much larger than needed, but is fine for modern devices).

20th June 2018, 06:29 #32
 Join Date
 Nov 2012
 Posts
 2,661
 Helped
 620 / 620
 Points
 14,383
 Level
 28
Re: Verilog code for BCD to Floating point representation
Updated diagram...
Each bcd will need 4 data lines and 4 digits will take 16 data connections. But most come will multiplex facility. In that case, 4 data lines and 4 display select lines (total 8; not counting the ground).
The driver may have the brightness (current control) but that can be seen later.

20th June 2018, 06:30 #33
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 42,978
 Helped
 13079 / 13079
 Points
 247,205
 Level
 100
Re: Verilog code for BCD to Floating point representation
A Verilog implementation of double dabble algorithm can be e.g. found here (didn't check the code) https://www.nandland.com/vhdl/module...ledabble.html
+ Post New Thread
Please login