CONFUSED WITH NUMBERS

T

TheRightInfo

Hi all
Numbers confuse me in VHDL .
For example when a in port receives data from an Analog To Digital
converter that represents fractions numbers smaller then
one like +0.54 or - 0.33 .

In that case how do I define that in port I gues i will use the
NUMERIC_STD package .

Please clarift the subject for me and all newbees to VHDL .

Thanks
EC
 
T

TheRightInfo

A port connected to an analog to digital converter receives bits.  1's
and 0's.  Sometimes parallel, sometimes serially, sometimes a
combination of the two.  And, as it's connected to external hardware,
you'll have the best luck doing that connection using std_logic and
std_logic_vector.

Now you've got bits, and it's your job to come up with an interpretation
of them.  Typically, you'd represent that as either a SIGNED or an
UNSIGNED, based on whether the ADC is bipolar or unipolar.  It's
possible that the ADC is bipolar (SIGNED) but outputs it's information
not in two's compliment but in what's known as offset binary (0 =
-fullscale, '1' followed by all '0's = 0, all '1' = +fullscale), in
which case you'd want to invert the MSB in order to have a normal, two's
compliment SIGNED number.  You could also use the native integer type
for this instead of a NUMERIC_STD, in which case you'd want to use a
bounded one, i.e. x : integer range 0 to 4095.  This will simulate ever
so marginally faster, simplify some tasks, and complicate some others.

So now you've got an entity.  That entity's job is to look on one side
like an interface full of std_logic* types to talk to the physical ADC,
and on the other to be one of the NUMERIC_STD types along with whatever
control signals the rest of your design needs.  The left side talks to
the physical layer, the right side provides semi-abstracted data.

Designing the contents of that entity required you to become fairly
familiar with the data sheet of the specific ADC in question, but you
now get to leave the knowledge of the specific interface details inside
that box, flush your brain cache, bring that entity in as a component of
your larger design, and concentrate on what you wish to do with the data
rather than how you got it.

Whether you've chosen to work with NUMERIC_STD types or integers, you're
now holding data that you've declared to represent integer numbers.
These numbers map linearly onto the voltage applied at the input of the
ADC.  For instance, a 12-bit unipolar ADC with a 4.096V input range.  In
this case, you've got one of the following:
        x : unsigned(11 downto 0);
        x : integer range 0 to 4095;

In either case, 1 LSB (least significant bit) corresponds to 1 mV on the
input.  Keeping track of this is your responsibility, the tools have no
help to offer you.  So it's your job to know that 10 (16#00A#) means 10
mV.  This is where comments are your friend.

If the numbers only matter to you relative to full scale, the
fundamental relationship is, in this case, value = x / 4096.  Notice
that, as x can never exceed 4095, you now have a fractional value
between 0 and 0.99976.  This, once again, has to be kept track of by
you.  It's theoretically possible to use the VHDL2008 fixed point
package for this instead; practically the tool support for doing so is
pretty abysmal and you'll most likely just get yourself in trouble.

Thus concludes the answer to your question.  Now, in exchange for this
lesson, please turn on the damn spell check for whatever method it is
you're using to throw questions out to the Internet.  It's like reading
a train crash in a blender.

Many Many Thanks
EC
 
A

Andy

Many Many Thanks
EC- Hide quoted text -

- Show quoted text -

You should take a look at the new fixed point VHDL packages, for doing
fixed point (integer and fractional) arithmetic in synthesizable
vhdl.

Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,883
Members
47,419
Latest member
ArturoBres

Latest Threads

Top