Jump to content
  • 0

Having trouble getting 16k samples from Analog In API function


Phil_D

Question

Hello,

I see in the specs that the max buffer size is over 16k points, but it seems that I can only get 8192 samples from this code. "FDwfAnalogInBufferSizeInfo" returns 8192.  How can I get the 16k samples?  I would like to get 16k samples for each ADC channel.  I am using the Analog Discovery 2. Thanks!

int main(int carg, char **szarg)
{
    HDWF hdwf;
    STS sts;
    double* rgdSamples;
    int cSamples;
    int cChannel;
    char szError[512] = { 0 };

    int channum = 0;

    cout << "hello world!";

    remove("ADC_results.txt");

    printf("Open automatically the first available device\n");
    if (!FDwfDeviceOpen(-1, &hdwf)) {
        FDwfGetLastErrorMsg(szError);
        printf("Device open failed\n\t%s", szError);
        return 0;
    }

    // get the number of analog in channels
    FDwfAnalogInChannelCount(hdwf, &cChannel);

    // enable channels
    for (int c = 0; c < cChannel; c++) {
        FDwfAnalogInChannelEnableSet(hdwf, c, true);
    }

    // set 5V pk2pk input range for all channels
    FDwfAnalogInChannelRangeSet(hdwf, channum, 5);

    // 10MHz sample rate
    FDwfAnalogInFrequencySet(hdwf, 10000000.0);


    // get the maximum buffer size
    FDwfAnalogInBufferSizeInfo(hdwf, NULL, &cSamples);
    FDwfAnalogInBufferSizeSet(hdwf, cSamples);

    // acquisition mode set added by Phil
    FDwfAnalogInAcquisitionModeSet(hdwf, acqmodeSingle);

    rgdSamples = new double[cSamples];

    // configure trigger
    FDwfAnalogInTriggerSourceSet(hdwf, trigsrcNone);

    Wait(2);

    // start
    FDwfAnalogInConfigure(hdwf, 0, true);

    printf("Waiting for triggered or auto acquisition\n");
    do {
        FDwfAnalogInStatus(hdwf, true, &sts);
    } while (sts != stsDone);

    FDwfAnalogInStatusData(hdwf, channum, rgdSamples, cSamples);
    fopen_s(&gDatLog, "ADC_results.txt", "a");

    for (int i = 0; i < cSamples; i++)
    {
        fprintf(gDatLog, "%lg\n", rgdSamples);
    }
    fclose(gDatLog);


    // close the device
    FDwfDeviceClose(hdwf);
    //}


    return 0;
}

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...