Verilog - FloatingPoint

Guest #2432049
Hi,

i want to create a sinus generator in verilog. My problem is that i dont 
know how i can connect the output of my module with a floating point 
number.

Perhaps someone can give me an small example how to work with floating 
point and the output. I tried to use "real" but i dont work as output.

Greetings
Moderator (Company: Titel) #2432108
> i want to create a sinus generator in verilog.
What is your actual problem?
Do you want to do DDFS?
Then the usual way is to read values out of a sins table.
The other way would be a cordic calculation.

> I tried to use "real" but i dont work as output.
Real numbers are not for snthesis. You can use them for testbenches, but 
you will encounter problem with them on real hardware...
Guest #2432205
I'd suggest you get the datasheet of, for instance, the AD9835. There is 
explained how digital synthesis works (in case you do not know). With 
that and a very few lines of Verilog (you will need two registers, one 
for the phase accumulator and another one for the period of the signal 
and a fully populated RAM block, i.e. with a sinus) you get a sinus 
generator :).
Guest #2447192
I got a sinus already using a LUT. But my Problem is that I multiplied 
the floating point values with 1000, so that i dont need a point.

Ok, i got an sinus and an amplitude of 1000. But i want an amplitude of 
1. And the problem is if i use floating point values my reg dont save 
the values.
Moderator (Company: Titel) #2447205
> And the problem is if i use floating point values my reg dont save
> the values.
No. The problem is, that you don't understand how numbers are 
represented in hardware. Or: do you know what a floating point number 
looks like and how difficult it is to handle simple operations like 
addition or multiplication on it in hardware?

To keep it short: I don't think you need a floating point number. But 
you must rearrange your mind for a different presentation of the 
numbers. Lets say: take a 8 bit number in a range from 
1000000...00000000...01111111 then you get a decimal value of 
-128...0...+127. And then divide this number in your mind by 128 and 
you get -1...0...+0.992 for the SAME bit pattern. Think thoroughly about 
that!

> an amplitude of 1000
Never ever take decimal numbers in hardware. A multiplication with 1000 
takes a lot of effort. A multiplication with 1024 instead is just a 
different wiring and brings zero overhead...  :-o
Guest #2447226
So it makes no difference in hardware if i implement the sin without 
floating points, btw. this way is much easier?

1024 would just be a shift, thats true
Moderator (Company: Titel) #2447232
> if i implement the sin without floating points
I didn't get this... :-/

But you said, you already have a sine function (via LUT).
So why do you need floating points further on? For scaling the sine?
Moderator (Company: Titel) #2447447
As I said: -1...+1 isn't possible:
With a 16 bit word you can get  0x1000 ... 0x0000 ... 0x7fff
That is decimal                 -32768 ...      0 ... 32767
If you divide it mentally by     32768
then you get virtually              -1 ...      0 ... +0.999969

So, what do you get out of your sine LUT/algorithm?

Reply

A question of your own? This thread is over 15 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.