- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I am trying to do some math involving degrees for my program. I have two values A and B, both 8 bit Std_logic_vector. I need to calculate the angle given by arctan(B/A). Since this is a very expensive operation to do in HW, i have been trying to think of ways to optimize this. luckily i do not need the actual angle, i just need to know the range of the angle to within 45 degrees. I just need to approximate the angle to one of the following : 0,45,90,135. to do so, i am checking to see if the angles fall within certain boundaries. if the angle is less than 22.5 then its seen as 0. between 22.5 and 67.5, its seen as 45 and so on.
to do this compare I want to compare B/A with the tan of those angles. so tan 67.5 is 2.41421 for example. so I wanted to compare 'B' and 'A*2.41421'. The challenge I am having is to deal with the decimal point! I want to avoid using FP here for area and latency reasons. Is there a simple way for me to represent these two sides as 'integers' to do this compare and avoid having to use FP hardware! Thank you!Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With only 8 bit on A and B, it would be very easy to use a look up table to find the values you need.
A LUT is just a rom where you input value is the address (angle)- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use fixed point arithmethic with binary numbers.
A binary number with a comma can esaily be seen as an extension fo conventional interger bnary numbers. As example a 4 bit number with a comma in the middle is B1 B0, B(-1) B(-2) the weights of the 4 bits are B1=2 B0=1 B(-1)=0.5 B(-2)=0.25 In this case the number 1001 = 2.25 in decimal. Then you have to convert the constatnts tha you need in binary. In your example the number 2.141421 in binary is 1001101 with a fictious comma before the last digit (100110,1) that is 38.5. By the way I do not suggest to campare B with A*2.41 this would istantiate a multiplier. Check the literature. This is a well addressed topic. You'll find many HW implementations.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- With only 8 bit on A and B, it would be very easy to use a look up table to find the values you need. A LUT is just a rom where you input value is the address (angle) --- Quote End --- Thank you! unfortunately im in a very space constrained environment so i cant spare the memory for a custom look up table! ironically, i have more programmable LUTs to spare than i do memory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- Use fixed point arithmethic with binary numbers. A binary number with a comma can esaily be seen as an extension fo conventional interger bnary numbers. As example a 4 bit number with a comma in the middle is B1 B0, B(-1) B(-2) the weights of the 4 bits are B1=2 B0=1 B(-1)=0.5 B(-2)=0.25 In this case the number 1001 = 2.25 in decimal. Then you have to convert the constatnts tha you need in binary. In your example the number 2.141421 in binary is 1001101 with a fictious comma before the last digit (100110,1) that is 38.5. By the way I do not suggest to campare B with A*2.41 this would istantiate a multiplier. Check the literature. This is a well addressed topic. You'll find many HW implementations. --- Quote End --- Thanks! thats what i ended up finding out after i posted this too! I am actually ok if it uses multipliers. the chip i am using has a lot of hardwires multipliers and i do not need them for anything else. i have it working ok for positive numbers, but i am trying to figure it out for negative numbers. the next set of compares i am trying to do is B < -A*2.41421. i think that would need some more work to figure out how to deal with 2's complement using this system!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Its quite straight forward if you use the fixed point package from www.vhdl.org/fphdl
as simple as: b <= a* to_sfixed(2.41421, 3, -4); -- 4 bits integer 4 bits fractional- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- Its quite straight forward if you use the fixed point package from www.vhdl.org/fphdl as simple as: b <= a* to_sfixed(2.41421, 3, -4); -- 4 bits integer 4 bits fractional --- Quote End --- Hi, this seems like the best way to go ahead for this! The page says it bridges the gap between VHDL-93 and VHDL-2008. If i directly use VHDL-2008 is there native support for fixed point already in the language? Would you be able to tell me how i can include this package in my quartus project when i compile? If i try to download the file and include it in my project i get an error saying library IEEE does not contain primary unit "fixed_pkg"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- Its quite straight forward if you use the fixed point package from www.vhdl.org/fphdl as simple as: b <= a* to_sfixed(2.41421, 3, -4); -- 4 bits integer 4 bits fractional --- Quote End --- Hi, How can i add this capability to my quartus project? If i added the file to my project, i get an error saying it cant find fixed_pkg cannot be found in library IEEE.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- Hi, this seems like the best way to go ahead for this! The page says it bridges the gap between VHDL-93 and VHDL-2008. If i directly use VHDL-2008 is there native support for fixed point already in the language? Would you be able to tell me how i can include this package in my quartus project when i compile? If i try to download the file and include it in my project i get an error saying library IEEE does not contain primary unit "fixed_pkg" --- Quote End --- The compatability package makes the package that was created for the 2008 revision of the language work (mostly) in tools that only support '93. Quartus 2008 support is rather limited, so you still need the compatability package even if you turned the compile option to 2008. The easiest thing to do is just include the files and either hand edit everything to the work library, or modify your scripts to put the package in the IEEE library. IIRC, the code on that link works around an IEEE-proposed library?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- The compatability package makes the package that was created for the 2008 revision of the language work (mostly) in tools that only support '93. Quartus 2008 support is rather limited, so you still need the compatability package even if you turned the compile option to 2008. The easiest thing to do is just include the files and either hand edit everything to the work library, or modify your scripts to put the package in the IEEE library. IIRC, the code on that link works around an IEEE-proposed library? --- Quote End --- I think fundamentally im not sure how to used types defined in a file outside of the IEEE library. Yes, the link works to the IEEE-proposed library but even adding the files and including the ieee_proposed library gives me the same error!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
post up a .qar of the project.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- post up a .qar of the project. --- Quote End --- Hi, I've actually found a way to work around this. someone on another forum gave me some code they've used in the past to do just this, so i can work around the problem now. Thank you very much for your help!

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page