Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem reading analog input with daqmx

I'm using code to record input along 4 different channels of an NI USB 6343.  I'm using a single task and a AnalogMultiChannelReader then after a finite acquisition collecting the data with the ReadMultiSample(-1) command.  However the input along the first channel always starts with a zero.  This happens even if what I'm recording is set to a constant non-zero value and it always occurs on the first channel created even when I try switching this channel.  

If I output the same square wave on every channel then I see an offset on the first channel (see attached image) which makes it seem as though this zero is being appended to the collected data.  Is this a known behavior?  Is there anything I can do about it?  Any help would be greatly appreciated.

0 Kudos
Message 1 of 6
(2,873 Views)

This wouldn't be expected behavior, and I see no particular reason for you to see this behavior, have you verified if this really only happens Multi Channel Reader operations, or if you try running it with only a single channel, it may be a good idea to see if this is only happening specifically in this cases.

 

Other than that have you tried running the Measurement Studio examples and see how those behave, to help rule out something in your implementation resulting in this.

0 Kudos
Message 2 of 6
(2,848 Views)

Thanks for the reply.  

I just tried both with a single channel using an AnalogMultiChannelReader and using an AnalogSingleChannelReader.  I see the same behaviour in both cases.

 

However my tests show a little more information.  Firstly it seems that this first sample is the last sample from the previous step (this persists even after I Dispose of all of my connections to the device and start them up again).  That is, if I was sending 5 volts previously then I see that as the first sample no matter what I send, but after that I get the correct readings. Secondly I see the same behaviour on digital input channels, but I didn't previously notice as it happens on all digital input channels (unlike the analog input which seems to only show this behaviour on the first channel).

0 Kudos
Message 3 of 6
(2,845 Views)

After a further day of testing it appears that what I'm actually seeing is a single sample read from each channel's state as they are started up.  This in itself would not be a problem, except that it happens on all digital channels and the first analog channel, but not on any of the other analog channels.  

This happens even if I put the same input directly into two different analog input channels, whichever is first will have an extra signal at the start.  

I cannot see any reason why this would be and any suggestions about possible approaches for debugging or fixes would be greatly appreciated.

0 Kudos
Message 4 of 6
(2,836 Views)

I'm trying o think of a specific test we can try with the code, but the first thing that comes to mind is verifying the correct functioning of the module and driver outside of the code.

 

Have you tried testing this same tasks from NI MAX? This can help us rule out problems with the hardware or the driver itself, similarly by seeing the behavior with the examples.

 

0 Kudos
Message 5 of 6
(2,825 Views)

Hi Richie, I apologise for the slow reply I wanted to fully investigate the issue before getting back to you.

Currently it looks to me as though it to do with the synchronisation of the analog output to the analog input.  

If I capture a counter generated using the C# .Net examples on 2 analog input channels that I set up then they are perfectly synchronised.  

I've included an abbreviated example which demonstrates how my code works sending data from ao1 to ai1 and ai2.  However I think the relevant part may be where I try to synchronise the channels which I'm copying below:

analogOutputTask.Timing.ConfigureSampleClock("", Convert.ToDouble(sampleRate),
                    SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, numberOfSamples);
analogInputTask.Timing.ConfigureSampleClock("/Dev1/ao/SampleClock", Convert.ToDouble(sampleRate),
                    SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, numberOfSamples);

I then start the input task followed by the output task.

I have tried also adding a trigger to the channels (either a shared trigger or having the analog input use the analog output start trigger) but this did not help.

If there's any advice you can give on this it would be much appreciated.

 

[Sample code is attached, to run it create an instance of the ExampleSyncIssueClass class then call QueueData(null, 1000, true) then call start which will return the analog input signals for comparison]

0 Kudos
Message 6 of 6
(2,806 Views)