Re: [PATCH 2/4] staging: comedi: ii_pci20kc: only bipolar ao ranges are 2's complement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/10/15 19:09, H Hartley Sweeten wrote:
According the the PCI-2006M user's manual, bipolar ranges use 2's
complement coding and unipolar ranges are straight binary. Fix
ii20k_ao_insn_write() to use the correct coding based on the range.

For aesthetics, use the comedi_offset_munge() helper to handle the
munging of the data.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
  drivers/staging/comedi/drivers/ii_pci20kc.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ii_pci20kc.c b/drivers/staging/comedi/drivers/ii_pci20kc.c
index 4d3f89c..6e2ce93 100644
--- a/drivers/staging/comedi/drivers/ii_pci20kc.c
+++ b/drivers/staging/comedi/drivers/ii_pci20kc.c
@@ -146,6 +146,7 @@ static int ii20k_ao_insn_write(struct comedi_device *dev,
  {
  	void __iomem *iobase = ii20k_module_iobase(dev, s);
  	unsigned int chan = CR_CHAN(insn->chanspec);
+	unsigned int range = CR_RANGE(insn->chanspec);
  	int i;

  	for (i = 0; i < insn->n; i++) {
@@ -153,9 +154,9 @@ static int ii20k_ao_insn_write(struct comedi_device *dev,

  		s->readback[chan] = val;

-		/* munge data */
-		val += ((s->maxdata + 1) >> 1);
-		val &= s->maxdata;
+		/* munge the offset binary to 2's complement if needed */
+		if (comedi_range_is_bipolar(s, range))
+			val = comedi_offset_munge(s, val);

  		writeb(val & 0xff, iobase + II20K_AO_LSB_REG(chan));
  		writeb((val >> 8) & 0xff, iobase + II20K_AO_MSB_REG(chan));


I'm not sure about that as there are discrepancies in the manual. The one I found was at:

https://www.uni-due.de/~hp0259/agwiki/lib/exe/fetch.php?media=anleitungen:pci-20006m.pdf

In "5. Specifications" it has:

CODE
	UNIPOLAR		Binary
	BIPOLAR			Complementary Binary

But then under "D/A Codes" it has:

OUTDATA		Volts Unipolar		Volts Bipolar
-------		--------------		-------------
32767		+Full Scale		-1 LSB *
0		+½ Full Scale		0
-1		+½ F.S. - 1 LSB		-1 LSB
-32768		0       		-Full Scale

± 5V Range: OUTDATA = VOLTS * (65536 / 10)
± 10V Range: OUTDATA = VOLTS * (65536 / 20)
0 to 10V Range: OUTDATA = (VOLTS * (65536 / 10)) - 32768

* I think that's a typo and should be "+Full Scale - 1 LSB".

The table (with typo corrected) and formulae indicate that for both unipolar and bipolar, -32768 is the lowest voltage and +32767 is the highest voltage, so we should munge comedi sample values regardless of range.

--
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@xxxxxxxxx> )=-
-=(                          Web: http://www.mev.co.uk/  )=-
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux