From 022eedf0cfa83fa0f3cc3b6d759d584594800d9e Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Tue, 22 Jan 2013 11:59:21 +0000 Subject: [PATCH] ni_labpc: correct differential channel sequence for AI commands Tuomas reported problems getting meaningful output from a Lab-PC+ in differential mode for AI cmds, but AI insn reads gave correct readings. He tracked it down to two problems, one of which is addressed by this patch. It seems the setting of the channel bits for particular scanning modes was incorrect for differential mode. (Only half the number of channels are available in differential mode; comedi refers to them as channels 0, 1, 2 and 3, but the hardware documentation refers to them as channels 0, 2, 4 and 6.) In differential mode, the setting of the channel enable bits in the command1 register should depend on whether the scan enable bit is set. Effectively, we need to double the comedi channel number when the scan enable bit is not set in differential mode. The scan enable bit gets set when the AI scan mode is MODE_MULT_CHAN_UP or MODE_MULT_CHAN_DOWN, and gets cleared when the AI scan mode is MODE_SINGLE_CHAN or MODE_SINGLE_CHAN_INTERVAL. The existing test for whether the comedi channel number needs to be doubled in differential mode is incorrect in labpc_ai_cmd(). This patch corrects the test. Thanks to Tuomas for suggesting the fix. Signed-off-by: Ian Abbott --- comedi/drivers/ni_labpc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/comedi/drivers/ni_labpc.c b/comedi/drivers/ni_labpc.c index 12b8bc7a..4b1aba71 100644 --- a/comedi/drivers/ni_labpc.c +++ b/comedi/drivers/ni_labpc.c @@ -1164,7 +1164,9 @@ static int labpc_ai_cmd(comedi_device * dev, comedi_subdevice * s) else channel = CR_CHAN(cmd->chanlist[0]); // munge channel bits for differential / scan disabled mode - if (labpc_ai_scan_mode(cmd) != MODE_SINGLE_CHAN && aref == AREF_DIFF) + if ((labpc_ai_scan_mode(cmd) == MODE_SINGLE_CHAN || + labpc_ai_scan_mode(cmd) == MODE_SINGLE_CHAN_INTERVAL) && + aref == AREF_DIFF) channel *= 2; devpriv->command1_bits |= ADC_CHAN_BITS(channel); devpriv->command1_bits |= thisboard->ai_range_code[range]; -- 2.26.2