Author Topic: 12b adc to Q2.10 fixed point conversion  (Read 2284 times)

0 Members and 1 Guest are viewing this topic.

Offline SpikeeTopic starter

  • Frequent Contributor
  • **
  • Posts: 568
  • Country: nl
12b adc to Q2.10 fixed point conversion
« on: March 30, 2017, 03:25:06 am »
Hello,

I'm experimenting with ADC->matlab filter -> DAC and have it all implemented at this moment
but having trouble with the adc binary to fixed point conversion. Searching on google did not bring me closer to an answer.

Adc 12 b -> 4096 steps
Reference 2.048 V
So so the float would be = 0.0005V * adc_binary_val

I set my matlab fiter IO to be word length 12 bit , fractional length 10 bit fixed point.

In C/C++ I would have this working in no time but with me being fairly new to VHDL it is where i'm stuck at this moment.

Technically I could do something like this:
real resolution = 0.0005;
ADC_OUT std_logic_vector(11 DOWNTO 0);
real ADC_Vout = ADC_OUT * resolution;

But that does not seem the most logical / best to implement in VHDL , there must be an better and easier way to do this ?

Any tips / help is greatly appriciated.

« Last Edit: March 30, 2017, 03:27:28 am by Spikee »
Freelance electronics design service, Small batch assembly, Firmware / WEB / APP development. In Shenzhen China
 

Offline cyberfish

  • Regular Contributor
  • *
  • Posts: 240
  • Country: gb
Re: 12b adc to Q2.10 fixed point conversion
« Reply #1 on: March 30, 2017, 01:21:08 pm »
It will take much less logic to multiply by m/n instead, where n is a power of two.

Maybe ADC_OUT * 1 / 2048 as an approximation?
 

Offline ehughes

  • Frequent Contributor
  • **
  • Posts: 409
  • Country: us
Re: 12b adc to Q2.10 fixed point conversion
« Reply #2 on: March 30, 2017, 01:35:03 pm »
I think you may be missing the point (no pun intended) of fixed point.      The point is an imaginary concept that you carry through your computations.     Your your case, you literally have to do nothing.   



For your VHDL,  if you are using a common format through out the pipeline, the only scaling you may need is after multiplies.  (And even then you may retain precision in any accumulation, etc you may do).

Now,   technical speaking when you say Q2.10,   that is really a 13-bit number.     The Q format generally implies you are working with signed number.

If you are filtering,   you don't have to even work about your 0.0005v scaling to volts.   That is somewhat meaningless for the purposes of the filter.   All you have to worry about is how you scale factor may change in your filter pipeline.

Here is a point to ponder.    What is the difference between a Q2.10, Q3.9 and Q4.8 number?   Absolutely nothing.   They are all 13-bit integers.   It is purely how we chose to interpret them.




 

Offline SpikeeTopic starter

  • Frequent Contributor
  • **
  • Posts: 568
  • Country: nl
Re: 12b adc to Q2.10 fixed point conversion
« Reply #3 on: March 30, 2017, 02:56:52 pm »
I Think I'm doing something completely the wrong way ... Will come back in a few days with the solution
Freelance electronics design service, Small batch assembly, Firmware / WEB / APP development. In Shenzhen China
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf