Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17259 Discussions

Percentage calculation in VHDL

Altera_Forum
Honored Contributor II
3,282 Views

Hi All, 

 

I am using MAX10 FPGA and need to calculate percentage. My data is 12 bit long. So I take the data, divide it by 100 by using the LPM_DIVIDE IP. I take the Quotient and multiply it to the desired percentage factor through LPM_MULTIPLIER. But LPM_DIVIDE IP produces Quotient and remainder. I am taking Quotient only that's why I am unable to get accurate results. So my question is that how should I use remainder to produce more accurate results. Thanks  

 

Regards 

USMAN
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
2,202 Views

Your 12bit data ranges from 0 to 4095, then if you divide it by 100 you simply lose the last two digits, namely 6-7 less significant bits of original data. 

A better solution would be starting with the multiplication into a 18bit register and THEN dividing by 100.
0 Kudos
Altera_Forum
Honored Contributor II
2,202 Views

ouh...  

first you do multiplication and store intermediate result with more than required bits , then you do division. <- this works well. 

i don't know the number range you deal with. 

 

( but if it doesn't break your accuracy you can replace division by 100 = 2^2 * 25 with division by 96 = 2^5 * 3 it means that at least 5 bits of operand looses)
0 Kudos
Altera_Forum
Honored Contributor II
2,202 Views

Thank you guys... thank you very much. it is working now

0 Kudos
Reply