Re: Question about comedi_{to,from}_phys()

On 01/06/07 17:10, L.C. Karssen wrote:
> Hi list,
> 
> I've got a few questions concerning the conversion functions to and from
> physical units. 
> For the record, I'm working with an NI PCI-6024E card with 12 bits
> analog out and in (a -10V to 10V range). 
> 
> When I use comedi_from_phys() to send 0V to the AO, it sends a bit value
> of 2048. Which seems correct to me. When I send 0V to the AI it reads
> 2048 (which, again, seems correct), but comedi_to_phys() converts it to
> 0.002442V. Which seems incorrect to me. 
> 
> When I looked at the source code of comedi_to_phys() in range.c of
> comedilib, I found that the bit value is divided by maxdata (4095 in my
> case) and not maxdata + 1, which is the total number of bitlevels
> available. 
> Could someone explain to me why that is?

Although there are maxdata+1 bitlevels, there are only maxdata steps 
from the lowest bitlevel to the highest bitlevel.

If -10 V is represented by 0 and +10 V is represented by 4095, then 0 V 
is represented by the value half-way between, i.e. 2047.5, but that is 
not exactly representable by the hardware.

> I see that dividing by maxdata + 1 gives a problem when the maximum bit
> value (4095) is read in. This would (in my case) not be converted to
> 10V, but to 9.995. However, in that case this would be only value that
> is "wrong" (but since the out-of-range behaviour is set to NaN by
> default when the maxdata bit value is measured this would not be a
> problem, I think).

Another way of making 0 V correspond to (maxdata+1)/2 would be to 
increase the negative end of the range slightly, e.g. [-10.0048852,+10] 
for a 12-bit, +/- 10 V range.  The corresponding unipolar range would 
also probably need a similar tweak to keep the voltage steps the same, 
e.g. [0.+20.0048852].  I'm not suggesting this is a good idea though, as 
  you can't expect to measure voltages with better than half a bit of 
accuracy anyway.

-- 
-=( Ian Abbott _at_ MEV Ltd.    E-mail: <abbotti_at_mev.co.uk>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-

Received on 2007-06-04Z12:47:20