• Content Count

  • Joined

  • Last visited

  1. Thank you for the help, @attila. After some more checks, I recognized that the tested hardware was causing the issue and not the analog discovery. Sorry for that.
  2. Hi @attila I made a mistake in my question. I wrote But actually I meant The pulses are reliably measured. But the number of high samples is always smaller than expected. Most of the time, I expect the measured pulse to be three samples longer than it is. What means the error equals about 30 microseconds.
  3. Hello Community I am using the Analog discovery 2 controlled by a C# Software. At a certain point of the software, I need to check the length of a detected pulse. Before this, I prepare the digital in component of the device. private const uint BUFFER_SIZE = 4000; private const uint DIGITAL_IN_DIVIDER = 1000; private const uint CLOCK_FREQUENCY = 100000000; public void prepareForPulseDetection( int digitalIoIndex ) { checkDigitalIoIndex( digitalIoIndex ); // sampling frequency = 100 MHz / 1000 = 100 kHz (-> 10 us) dwf.FDwfDigitalInDividerSet( device, DIGITAL_IN_DIVIDER ); // just sample DIO pins 0...7 dwf.FDwfDigitalInSampleFormatSet( device, 8 ); dwf.FDwfDigitalInBufferSizeSet( device, (int)BUFFER_SIZE ); dwf.FDwfDigitalInSampleModeSet( device, dwf.DwfDigitalInSampleModeSimple ); // just one acquisition after trigger dwf.FDwfDigitalInAcquisitionModeSet( device, dwf.acqmodeSingle ); // setting triggersource to digital in detector dwf.FDwfDigitalInTriggerSourceSet( device, dwf.trigsrcDetectorDigitalIn ); // take 50 samples before trigger dwf.FDwfDigitalInTriggerPositionSet( device, (uint)BUFFER_SIZE - 50 ); // disable timeout dwf.FDwfDigitalInTriggerAutoTimeoutSet( device, 0 ); // set trigger to rising edge on DIO pin 0 uint triggeredPin = (uint)0x0001 << digitalIoIndex; // high low rising falling dwf.FDwfDigitalInTriggerSet( device, 0x0000, 0x0000, triggeredPin, 0x0000 ); // enable digital in without reconfiguring dwf.FDwfDigitalInConfigure( device, 0, 1 ); } private void checkDigitalIoIndex( int digitalIoIndex ) { if ( ( digitalIoIndex < 0 ) || ( 7 < digitalIoIndex ) ) throw new ArgumentException( "Digital IO index must be in array [0...7]" ); } /// <returns> pulse time in us </returns> public uint getDetectedPulseLength( int digitalIoIndex ) { checkDigitalIoIndex( digitalIoIndex ); var data = new byte[BUFFER_SIZE]; dwf.FDwfDigitalInStatusData( device, data, (int)BUFFER_SIZE ); var numberOfHighSamples = getNumberOfHighSamples( data, digitalIoIndex ); // 1e6 because of us return var usDuration = (uint)( DIGITAL_IN_DIVIDER * 1e6 / CLOCK_FREQUENCY ); usDuration = (uint)( usDuration * numberOfHighSamples ); // reset device, else it is not possible to // recognize if pulse occured dwf.FDwfDigitalInReset( device ); return usDuration; } private int getNumberOfHighSamples( byte[] data, int digitalIoIndex ) { if ( allZero( data ) ) return 1; // means pulse was shorter than samplerate else { int startingIndex = getStartingIndexOfPulse( data, digitalIoIndex ); int endingIndex = getEndingIndexOfPulse( data, digitalIoIndex ); int difference = ( endingIndex - startingIndex + 1 ); return difference + 3; // plus 3 because analog discovery return is inaccurate } } private bool allZero( byte[] data ) { for ( int i = 0 ; i < data.Length ; ++i ) if ( data[i] != 0 ) return false; return true; } private int getStartingIndexOfPulse( byte[] data, int digitalIoIndex ) { int index = 0; for ( ; index < data.Length ; ++index ) if ( checkBit( data[index], (byte)digitalIoIndex ) ) break; return index; } private int getEndingIndexOfPulse( byte[] data, int digitalIoIndex ) { int index = getStartingIndexOfPulse( data, digitalIoIndex ) + 1; for ( ; index < data.Length ; ++index ) if ( !checkBit( data[index], (byte)digitalIoIndex ) ) break; return --index; } private bool checkBit( byte value, byte checkedBit ) { byte shiftedValue = (byte)( (int)value >> (int)checkedBit ); return ( ( shiftedValue & 0x01 ) == 0x01 ); } The pulses are reliably measured. But the number of high samples is always smaller than expected. Most of the time, I expect the measured pulse three microseconds longer than it is. Is this a known issue? Or is there a mistake in my code? I am very sure, that the pulses I am sending to the analog discovery are as long as they should be. I checked it with the analog discovery with the waveforms software and with another osciloscope.
  4. Hello I found a 3D model of the analog discovery 2 that includes the PCB at the following link: https://reference.digilentinc.com/reference/instrumentation/analog-discovery-2/start?redirect=1 Is there a 3D-Model that includes the case as well? kind regards
  5. Hi again @attila Now I moved on to C# and I am facing the same problem again. The function dwf.FDwfDigitalInStatusData( int, byte[], int ); wants an array of bytes to store the sampled data. How is it possible to set the data format on 16 since the type byte represents an unsigned 8 bit integer?
  6. Hi @attila I corrected my code as you suggested and it works fine, thank you once again! But I have got another question about the data format: If I set the data format to 8, no samples would be taken from digital pins 8 to 15? What is stored in the bits on position 16 to 31 with dataformat 32 since I only have 16 DIO lines?
  7. Hello @attila and @JColvin Thank you for both of your answers. I will try out the new code example. I think, I will be able to make it work.
  8. Hello Digilent world First, before I write my questions, I would like to provide some information: - Used device: Analog Discovery 2 (revision 3) - Programming language is C++ - IDE: Visual Studio Community 2013, version 12 - Operating System: Windows 10 I am trying to control the device with the SDK but I got issues with the Digital-In-Instrument. I attached a .cpp file with my code. My aim is to configure digital pin 0 to take 1000 samples as soon as a rising edge on the same pin occurs. To generate a rising edge on this pin, I connect digital pin 0 and digital pin 1 and configure pin 1 to pulse on enabling. I checked if the pulse on pin 0 really occurs: This works fine. Furthermore, I try to read out the logged samples after the triggering and print them on the console. Now the description of my problems: - With the following code I expect the digitalIn Instrument to be armed just one time (setting of acqmodeSingle in row 27). But the print on row 76 prints "DwfStateArmed". I expect it to stay on "DwfStateDone". Do I missunderstand something here? - I totally don't understand the format of the data that I get with FDwfDigitalInStatusData(...) In the digilent examples I saw it like this: FDwfDigitalInStatusData(deviceId, Pointer to array with size of "nrOfSamples", nrOfSamples*sizeof(unsigned short)) Why is there a multiplication with the size of an unsigned short? - Could you please explain me, in which format the logged values are stored in the data-array? Is it a bitfield with the value of each pin or something different? Thank you very much in advance for the given answers. If somethings not clear, don't hesitate to ask. Kind regards Aaron example.cpp