+ Post New Thread
Page 2 of 2 FirstFirst 1 2
Results 21 to 33 of 33
  1. #21
    Super Moderator
    Points: 64,787, Level: 62
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    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.

    Klaus
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  2. #22
    Advanced Member level 5
    Points: 14,383, Level: 28

    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^12-1 (4095)

    any arbitrary voltage between 0-4095 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 (0-3.3)- just to convince yourself.



    •   AltAdvertisment

        
       

  3. #23
    Super Moderator
    Points: 247,205, Level: 100
    Awards:
    1st Helpful Member

    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.



  4. #24
    Member level 4
    Points: 487, Level: 4
    Achievements:
    Created Blog entry

    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

    Quote Originally Posted by c_mitra View Post
    any arbitrary voltage between 0-4095 will be scaled linearly ---> x*3.3/4096 (this will be a float value)
    ...
    Now scale the result by 1000; you will get x*3300/4096
    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



  5. #25
    Super Moderator
    Points: 247,205, Level: 100
    Awards:
    1st Helpful Member

    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
    Although the OP requested a factor of 1/4095, it's not necessarily the exact solution. Most 12-bit ADC have a quantization step of Vref/4096. If you want a non-power-of-denominator though, you'll recalculate the numerator respectively.



  6. #26
    Super Moderator
    Points: 64,787, Level: 62
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    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 12-bit ADC have a quantization step of Vref/4096
    True, indeed I don't know a single ADC or DAC that uses 4095 (or 1023)
    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.

    Klaus
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



    •   AltAdvertisment

        
       

  7. #27
    Advanced Member level 5
    Points: 14,383, Level: 28

    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...
    Obviously this will be an error term and will be consumed by the +/-1 LSB accuracy of the ADC. But more than that, you will need a 6 or 7 digit display to make out any difference.

    In reality, you may find the last digit fluctuating and practically unreadable. In fact, ADC results 1-2-3 will just appear as zero in the display...



  8. #28
    Newbie level 6
    Points: 10, Level: 1

    Join Date
    Mar 2018
    Posts
    14
    Helped
    0 / 0
    Points
    10
    Level
    1

    Re: Verilog code for BCD to Floating point representation

    Quote Originally Posted by KlausST View Post
    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.

    Klaus
    Updated diagramClick image for larger version. 

Name:	New Doc 2018-06-19_1.jpg 
Views:	9 
Size:	301.6 KB 
ID:	147317



  9. #29
    Super Moderator
    Points: 247,205, Level: 100
    Awards:
    1st Helpful Member

    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.



  10. #30
    Member level 4
    Points: 487, Level: 4
    Achievements:
    Created Blog entry

    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.



    •   AltAdvertisment

        
       

  11. #31
    Advanced Member level 3
    Points: 5,510, Level: 17

    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).



  12. #32
    Advanced Member level 5
    Points: 14,383, Level: 28

    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...
    What is the nature of the display? Does it come with integrated drivers? Most of the 7-seg displays has a decimal and you need not waste one display to show the decimal.

    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.



  13. #33
    Super Moderator
    Points: 247,205, Level: 100
    Awards:
    1st Helpful Member

    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...le-dabble.html



--[[ ]]--