Synchronous acquisition/generation in C

Applications, development tools, FPGA, C, WEB
Post Reply
npiro
Posts: 6
Joined: Thu May 19, 2016 10:49 am

Synchronous acquisition/generation in C

Post by npiro » Sat Jun 18, 2016 8:28 am

Hi!
I'm trying to implement the Signal Acquiring at 125 Msps > Synchronized one pulse generating and acquiring example in C.
I basically translated the SCPI commands from the Matlab example to API functions in C.
Here's the relevant code: (I define a function Initialize to set up the measurement and run it in the main function as follows)

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <string.h>

#include <sys/types.h> 
#include <sys/socket.h>
#include <netinet/in.h>

#include "redpitaya/rp.h"

void Initialize()
// Initialize acquisition and signal generation for VNA
{

    rp_AcqReset();

    rp_GenReset();
    rp_GenWaveform(RP_CH_1,RP_WAVEFORM_SINE);
    rp_GenMode(RP_CH_1,RP_GEN_MODE_BURST);
    rp_GenBurstRepetitions(RP_CH_1,200);
    
    
    //rp_AcqSetTriggerSrc(RP_TRIG_SRC_AWG_PE);
    rp_GenOutEnable(RP_CH_1);
    rp_AcqSetDecimation(RP_DEC_1024);
    rp_AcqSetTriggerLevel(0.0);
    rp_AcqSetTriggerDelay(8192);


}

void InOut(float Freq, float Amp)
{
    rp_acq_trig_state_t trig_state;
    
    Initialize();
    rp_GenAmp(RP_CH_1,Amp);
    rp_GenFreq(RP_CH_1,Freq);
    rp_AcqStart();
    usleep(10);
    rp_AcqSetTriggerSrc(RP_TRIG_SRC_AWG_PE);

    // Trigger measurement
    //usleep(100);

    int n=0;
    //usleep(1000);
    printf("%d\n",RP_TRIG_STATE_TRIGGERED);
    printf("%d\n",RP_TRIG_STATE_WAITING);

    rp_GenTrigger(1); // Send a trigger to generator on Channel 1
    while (1) { // Wait for trigger
        rp_AcqGetTriggerState(&trig_state);
        if (trig_state == RP_TRIG_STATE_TRIGGERED) break;
        usleep(10); // Sleep for 100 usecs.
        n++;
        if (!(n%100)) printf("%f %d %d\n",Freq,n,trig_state);
    }
    rp_AcqGetOldestDataV(RP_CH_1, &buff_size, buff);
}
The problem is that when I call the InOut() function, it stays stuck in the infinite while loop (the trig_state variable never goes to RP_TRIG_STATE_TRIGGERED state). Any ideas of what I might be doing wrong?

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Synchronous acquisition/generation in C

Post by Nils Roos » Sat Jun 18, 2016 11:35 am

Yes, you fell victim to an unfortunate error in the example code for the generator.

Code: Select all

        rp_GenTrigger(1);
triggers channel 2, the correct command to trigger channel 1 would be

Code: Select all

        rp_GenTrigger(RP_CH_1);

npiro
Posts: 6
Joined: Thu May 19, 2016 10:49 am

Re: Synchronous acquisition/generation in C

Post by npiro » Sat Jun 18, 2016 1:52 pm

Ok, that partially solved the problem. Thanks!

However, I still have a few problems. The acquisition is never triggered if I don't sleep for at least 300 us after the rp_AcqSetTriggerSrc(RP_TRIG_SRC_AWG_PE) is called.

In addition, I'm trying to do a frequency sweep, repeating the synchronous measurement for certain frequency range. It looks like the triggering also fails if I don't rerun the entire Initialize() function each time a repeat the measurement, as opposed to just changing the generator frequency and triggering the acquisition again. Why is this the case?

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Synchronous acquisition/generation in C

Post by Nils Roos » Sat Jun 18, 2016 8:22 pm

Somewhat counterintuitively, RP_TRIG_SRC_AWG_PE is triggered only at the moment the generator is triggered. Do you call rp_GenTrigger(RP_CH_1) after rp_GenFreq(RP_CH_1,Freq), rp_AcqStart(), and rp_AcqSetTriggerSrc(RP_TRIG_SRC_AWG_PE)?

npiro
Posts: 6
Joined: Thu May 19, 2016 10:49 am

Re: Synchronous acquisition/generation in C

Post by npiro » Sun Jun 19, 2016 8:49 am

Yes indeed.
rp_GenTrigger(RP_CH_1) is the last thing I call.
My calling sequence is:
rp_GenFreq()
rp_AcqStart()
rp_AcqSetTriggerSrc(RP_TRIG_SRC_AWG_PE)
rp_GenTrigger(RP_CH_1)

I still don't understand where I need to pause() and for how long, and why... Could you clarify?

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Synchronous acquisition/generation in C

Post by Nils Roos » Sun Jun 19, 2016 12:02 pm

In general, I can only guess why things in the RP api and in the fpga have been designed the way they are. Oftentimes I get the impression that it is just one bolted-on feature atop another, with little overall structural integration into the whole system.

Be that as it may, I believe I have found the cause of your problem. The external trigger input and the ASG trigger are subject to a 0.5ms deadtime after trigger. During that time, further trigger events from the same source are ignored by the oscilloscope. In theory, the deadtime is configurable, but the RP api does not provide access to this configuration value.

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 22 guests