cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
fmousse
Contributor
Contributor
11,009 Views
Registered: ‎10-09-2015

How to use an ADC output in VHDL

Jump to solution

Hi everyone !

 

I made an ADC and I would like to work with the output data.

The output data from the ADC is :
Data : std_logic_vector(13 downto 0)

My objective is to do something like :

Interesting_output = A x Data(n-1) + B x Data(n) + C x Data(n+1)

But I don't know how to use the output from my ADC and convert it into a number (for example 11111111111111 = 2 [Volts] and 00000000000000 = 0,4 [Volts])

 

Can someone help me?

0 Kudos
1 Solution

Accepted Solutions
eilert
Teacher
Teacher
19,500 Views
Registered: ‎08-14-2007

Hi,

oh, that's all? :-)

You don't need to spend a full entity for that.

 

ADC_converted <= to_integer(signed(ADC_output));

 

You need to use the numeric_std package, of course.

 

Have a nice synthesis

  Eilert

View solution in original post

9 Replies
fmousse
Contributor
Contributor
10,997 Views
Registered: ‎10-09-2015

I mean : 

 

Data &colon; std_logic_vector(13 downto 0)

 

not

 

Data &colon; std_logic_vector(13 downto 0)

 

Don't know how to edit my post, sorry for doublepost :)

 

0 Kudos
eilert
Teacher
Teacher
10,987 Views
Registered: ‎08-14-2007

Hi,

assuming that your hardware works correctly, all you need is to do some math exercise.

 

In your example the 13 bit range of your ADC spans over 1.6V (2V - 0.4V).

That means you have a resolution of 1.6/2^14 = 97.65µV per digit.

 

Looks like you want to build sth. like a digital filter (e.g. some FIR-Filter).

One of the most simple steps would be to take the resolution as the reference value.

Then you can eliminate the offset by simply adding 0.4V/97,65µV/digit = 4096.

Your result then needs to have at least 15 bits, you might want to add a 16th bit to allow the use of signed two's complement data&colon;

 

So you need something like this:

 

const offset : signed(15 downto 0) := to_signed(4096,16);

 

signal FilterInput : signed(15 downto 0) ;

 

---

FilterInput <= offset + signed("00"&Data);

 

Now you can feed this signal to some Filter.

The use of signed datatypes is important, because you may have negative coefficients and your result can become negative too then.

 

----------------------------------------------------------

Converting the binary output of your ADC or (later on) filter design is something different.

It depends on the output device.

Do you have some sort of display attached to the FPGA?

Do you send the data to some host computer?

 

In the first case you have to do the conversion inside the FPGA.

There are several possible approaches, but in the end it depends on how the data will be sent to the display device(s).

In the second case you just need to call some binary to decimal routine in the program that receives the data, or convert the data after storing it and display it afterwards.

 

 

Have a nice synthesis

   Eilert

 

0 Kudos
eilert
Teacher
Teacher
10,986 Views
Registered: ‎08-14-2007

Hi

when you open your posts for reading you find "OPTIONS" in a field top right.

There you can klick on edit post (or reply) and then you are back in the editor mode.

 

Kind regards

   Eilert

0 Kudos
fmousse
Contributor
Contributor
10,980 Views
Registered: ‎10-09-2015

@eilert : 

 

I don't know if my explaination was good enough

 

I have that :

entity converter is

Port ( ADC_output : in STD_LOGIC_VECTOR (13 downto 0);

ADC_converted : out integer);

end converter;

 

And I would like to convert my ADC_output

For example : If I've 11111111111111 in ADC_output, I would like to see my ADC_converted with 8192 (it's signed)

 

And if I've 00000000000000, I would like to see my ADC_converted with 0

0 Kudos
muzaffer
Teacher
Teacher
10,957 Views
Registered: ‎03-31-2012

it seems you want ADC_output <= ADC_converted / 2; ?

 

 

- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
eilert
Teacher
Teacher
19,501 Views
Registered: ‎08-14-2007

Hi,

oh, that's all? :-)

You don't need to spend a full entity for that.

 

ADC_converted <= to_integer(signed(ADC_output));

 

You need to use the numeric_std package, of course.

 

Have a nice synthesis

  Eilert

View solution in original post

fmousse
Contributor
Contributor
10,945 Views
Registered: ‎10-09-2015

Thank you very much for your answers ! It's only a part of my project of course but I simulate and try step by step because I'm new in VHDL (I started learning a month ago)...

 

Last thing : When I simulate it, I have a binary number (and not an integer) is that normal in VHDL?

 

Here's what I get : 

 

Simulation_ADC_Converted.PNG

0 Kudos
eilert
Teacher
Teacher
10,935 Views
Registered: ‎08-14-2007

Hi,

the simulator GUI often allows to choose the radix of a signal.

 

While the default often is binary, you can choose between signed and unsigned decimal, octal, hex, and sometimes even analog.

 

Have a nice simulation

  Eilert

0 Kudos
fmousse
Contributor
Contributor
10,930 Views
Registered: ‎10-09-2015

Thank you very much for the time that you spent for me !

0 Kudos