Jump to content

CAM C

Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by CAM C

  1. Hello, I am trying to use the waveform generator to generate a pulse and use the analog IN channels to get me data about that pulse. I currently have code that generates one pulse which is what I want, but I am having trouble setting up the trigger and logging the data. I think I am confused on how to actually set up the trigger correctly and how to log data correctly with Csharp.

    Here is what I am after, I want to generate One pulse of desired length and then to read that pulse data. I want the ADC to start reading once it has seen the rising edge of the pulse, maybe even a few milliseconds before. Any help is greatly appreciated. 

    Another way of saying this is, I want code that will grab me data for a desired period of time but starts grabbing the data based on a rising edge trigger. 

    Here is the code that generates one pulse for me. 

    dwf.FDwfDeviceOpen(-1, out HDWF);

    dwf.FDwfDeviceAutoConfigureSet(HDWF, 0);

    dwf.FDwfAnalogOutNodeEnableSet(HDWF, channel1, dwf.AnalogOutNodeCarrier, 0);

    dwf.FDwfAnalogOutNodeEnableSet(HDWF, channel1, dwf.AnalogOutNodeCarrier, 1);

    dwf.FDwfAnalogOutIdleSet(HDWF,channel1, dwf.DwfAnalogOutIdleDisable);

    dwf.FDwfAnalogOutNodeFunctionSet(HDWF,channel1, dwf.AnalogOutNodeCarrier, dwf.funcPulse);

    dwf.FDwfAnalogOutNodeFrequencySet(HDWF,channel1,dwf.AnalogOutNodeCarrier,25.0);

    dwf.FDwfAnalogOutNodeAmplitudeSet(HDWF, channel1, dwf.AnalogOutNodeCarrier, 3.3);

    dwf.FDwfAnalogOutRunSet(HDWF,channel1,.03);

    dwf.FDwfAnalogOutWaitSet(HDWF,channel1,0.1);

    dwf.FDwfAnalogOutRepeatSet(HDWF,channel1,1);

    This generates me a pulse but I cannot get a accurate data to be read. 

    Here is the code I have been trying to use to give me the data of that pulse. 

    dwf.FDwfAnalogInChannelEnableSet(HDWF, 1, 1); //enable channel 1

    dwf.FDwfAnalogInChannelRangeSet(HDWF, -1, 10.0);

    dwf.FDwfAnalogInAcquisitionModeSet(HDWF, dwf.acqmodeRecord);

    double freqeuncy = 100000.0;

    double samples = 200000.0;

    double record = samples / freqeuncy;

    dwf.FDwfAnalogInFrequencySet(HDWF, freqeuncy);

    dwf.FDwfAnalogInRecordLengthSet(HDWF, record);

    dwf.FDwfAnalogInTriggerPositionSet(HDWF, (-0.25) * record);

    //Setting up the trigger
                dwf.FDwfAnalogInTriggerAutoTimeoutSet(HDWF, 10.0);
                dwf.FDwfAnalogInTriggerSourceSet(HDWF, dwf.trigsrcDetectorAnalogIn);
                dwf.FDwfAnalogInTriggerTypeSet(HDWF, dwf.trigtypeEdge);
                dwf.FDwfAnalogInTriggerChannelSet(HDWF, 1);

                dwf.FDwfAnalogInTriggerLevelSet(HDWF, 0.1);
                dwf.FDwfAnalogInTriggerHysteresisSet(HDWF, 0.1);
                dwf.FDwfAnalogInTriggerConditionSet(HDWF, dwf.DwfTriggerSlopeRise);

    Thread.Sleep(2000);

    //Starting Trigger for ADC
                dwf.FDwfAnalogInConfigure(HDWF, 0, 1);

    //Start of pulse
                dwf.FDwfAnalogOutConfigure(HDWF, channel1, 1);

    int index = 0;
                int lost = 0;
                int available = 0;

                int acqState0 = 0;
                while (cSamples < nSamples || acqState == 2)
                {

                    dwf.FDwfAnalogInStatus(HDWF, 1, out acqState);
                    //Console.WriteLine("Aquisition: {0}",acqState);
                    dwf.FDwfAnalogInStatusRecord(HDWF, out cAvailable, out cLost, out cCorrupted);
                    Console.WriteLine("Data Available: {0}", cAvailable);
                    lost += cLost;
                    available += cAvailable;

                    if (cAvailable == 0)
                    {
                        acqState0 += 1;
                        continue;
                    }


                    double[] values = new double[cAvailable];
                    dwf.FDwfAnalogInStatusData2(HDWF, 1, values, index, cAvailable);

                    cSamples += cAvailable;
                    adcValues.AddRange(values.ToList<double>());

                }

    This does not return the desired samples I want. I thought it would be easy to set the amount of data you want for a given period of time which starts grabbing data based on a trigger. 

     

     

×
×
  • Create New...