I am attempting to read back the Digital IO pins on the AD3, for tracking the ticks of a rotary encoder, but even with no pins coming in high, im getting non 0 values for my pins(when reading from SDK only, Waveforms app does not show any pins high)
I assume that I am doing something wrong on the read and have attached my test below.
Dwf.DigitalInReset(_deviceManager.GetDevice()!.Id.Value);int leadingPinIndex =0;int trailingPinIndex =1;
var id = _deviceManager.GetDevice()!.Id;
var hzSys =Dwf.DigitalInInternalClockInfo(id.Value);// sample rate to 1MHz
var divider =(uint)(hzSys /1e6);Dwf.DigitalInDividerSet(id.Value, divider);// 16bit WORD formatDwf.DigitalInSampleFormatSet(id.Value,16);Dwf.DigitalInAcquisitionModeSet(id.Value, ACQMODE.Single);// get the maximum buffer size
var cSamples =Dwf.DigitalInBufferSizeInfo(id.Value);// default buffer size is set to maximumDwf.DigitalInBufferSizeSet(id.Value, cSamples);// set trigger position to the middle Dwf.DigitalInTriggerPositionSet(id.Value,(uint)(cSamples /2));// trigger on any pin transitionDwf.DigitalInTriggerSourceSet(id.Value,DigitalTriggerSource.DetectorDigitalIn.MapToWaveFormsSdkType());//_digitalInService.DigitalInTriggerAutoTimeoutSet(id, 10.0);//var triggerBits = SetBits(0, 1);uint triggerBits =0xFFFF;Dwf.DigitalInTriggerSet(id.Value, triggerBits, triggerBits, triggerBits, triggerBits);Dwf.DigitalInTriggerAutoTimeoutSet(id.Value,5);// startDwf.DigitalInConfigure(id.Value,false,true);bool previousLeading =false;bool previousTrailing =false;int count =0;while(count <5){
STATE sts;do{
sts =Dwf.DigitalInStatus(id.Value,false);}while(sts != STATE.Done);
var rgwSamples =Dwf.DigitalInStatusData(id.Value, cSamples);for(int i =0; i < rgwSamples.Length; i +=2){// Ensure there's a pair of bytes to processif(i +1< rgwSamples.Length){
var byte1 = rgwSamples[i];// Even byte - pins [0-7]
var byte2 = rgwSamples[i +1];// Odd byte - pins [8-15]
var byte1BoolArray =ByteToBoolArray(byte1);
var byte2BoolArray =ByteToBoolArray(byte2);bool leadingPin = leadingPinIndex <8? byte1BoolArray[leadingPinIndex]: byte2BoolArray[leadingPinIndex -8];bool trailingPin = trailingPinIndex <8? byte1BoolArray[trailingPinIndex]: byte2BoolArray[trailingPinIndex -8];if(leadingPin != previousLeading || trailingPin != previousTrailing){//This will yield return in actual application//yield return (leadingPin, trailingPin);
previousLeading = leadingPin;
previousTrailing = trailingPin;}}}
count++;}
If I provide a True to the DigitalInStatus call, rgwSamples is [3,0,3,0,3,0,3,....]
If I provide a False to the DigitalInStatus call, rgwSamples is [80,1,145,144,229,1,0,0....] and then the series repeats.
My expectation would be that if I have no high digital pins, my entire rgwSamples would be 0s.
Since I have a 16 bit format and 16 pins, its my assumption that the even elements in rgwSamples would be for pins 0-7 and the odd elements would be for pins 1-15. Is that a misunderstanding?
Question
HasNoCreek
Hello all,
I am attempting to read back the Digital IO pins on the AD3, for tracking the ticks of a rotary encoder, but even with no pins coming in high, im getting non 0 values for my pins(when reading from SDK only, Waveforms app does not show any pins high)
I assume that I am doing something wrong on the read and have attached my test below.
If I provide a True to the DigitalInStatus call, rgwSamples is [3,0,3,0,3,0,3,....]
If I provide a False to the DigitalInStatus call, rgwSamples is [80,1,145,144,229,1,0,0....] and then the series repeats.
My expectation would be that if I have no high digital pins, my entire rgwSamples would be 0s.
Since I have a 16 bit format and 16 pins, its my assumption that the even elements in rgwSamples would be for pins 0-7 and the odd elements would be for pins 1-15. Is that a misunderstanding?
Thanks in advice for any advice/help!
Link to comment
Share on other sites
3 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now