Re: corrected: Analog Input, Comedi+RTAI+Matlab

On 10/11/2005 17:54, Roland Riepl wrote:
> I am currently working on a driver for the precision microdynamic's card
> MFIO-3A for comedi support. Some of the functions are already working
> and I am using comedi in combination with RTAI and Matlab. For one
> special application however, I need the integer value from the channel's
> register of an analog input in my matlab simulink simulation.

Surely it's already an integer until you call comedi_to_phys()?

If it's getting scaled to a floating point value in some code outside 
your control, can't you just scale it back to the original integer 
value.  It should be possible as long as you are careful with rounding, 
as there should be enough precision in the floating point value to 
distinguish all the raw sample values.

> First i tried to uncomment the s->maxdata and s->range_table hoping that
> the values would not be scaled between -10 to 10. When i started my
> files (code generated by Matlabs Real Time Workshop), the analog input
> was automatically scaled between 0 to 1 and I when I use xrtailab to
> watch the analog input with a scope or meter I get an error message
> similar to "out of range" (i cant remember exactly at the moment).
> 
> Here's a part of the driver's code.
> 
> s = dev->subdevices + 0;
> /* ai subdevice */
> s->type = COMEDI_SUBD_AI;
> s->subdev_flags = SDF_READABLE;
> s->n_chan = 3;
> s->insn_read = mfio_ai_insn_read;
> //s->maxdata = 0x7fff;
> //s->range_table = &range_bipolar10;

Commenting out maxdata and range_table is a bad idea!  The maxdata value 
looks a little odd.  Is it _really_ a 15-bit A-to-D converter?  If it is 
a 16-bit bipolar A-to-D converter then maxdata should be 0xffff, and if 
necessary you should mangle the data so that 0 is -fullscale and 0xffff 
is +fullscale.  If your A-to-D converter produces 2's-complement bipolar 
values, this mangling just involves inverting the most significant bit. 
  (If your application needs the unmangled raw value, it should take 
account of this mangling.)

-- 
-=( 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 2005-11-11Z10:59:20