C Code for acquiring data with external trigger

Just about everything about Red Pitaya
Post Reply
siva12357
Posts: 1
Joined: Fri Apr 03, 2020 8:02 am

C Code for acquiring data with external trigger

Post by siva12357 » Fri Apr 03, 2020 8:05 am

Hi,

In the examples there is no C code for acquiring data with external trigger. I tried the following code, the code acquires but it's not triggered properely can anyone help me ?

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "redpitaya/rp.h"


int main(int argc, char **argv){
	
	FILE *fp;
	uint32_t t;
	fp=fopen("data3.txt", "w");
        /* Print error, if rp_Init() function failed */
        if(rp_Init() != RP_OK){
                fprintf(stderr, "Rp api init failed!\n");
        }

        /*LOOB BACK FROM OUTPUT 2 - ONLY FOR TESTING*/
        rp_GenReset();
        rp_GenFreq(RP_CH_1, 20000.0);
        rp_GenAmp(RP_CH_1, 1.0);
        rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
	rp_GenBurstCount(RP_CH_1, 10);
        rp_GenOutEnable(RP_CH_1);
	rp_GenMode(RP_CH_1, RP_GEN_MODE_BURST);
	rp_GenTriggerSource(RP_CH_1, RP_GEN_TRIG_SRC_EXT_PE);

        uint32_t buff_size = 16384;
        float *buff = (float *)malloc(buff_size * sizeof(float));

        rp_AcqReset();
        rp_AcqSetDecimation(2);
        rp_AcqSetTriggerLevel(RP_CH_1, 0.5);
        rp_AcqSetTriggerDelay(0);
	rp_AcqSetArmKeep(0);
	rp_AcqStart();
        

        /* After acquisition is started some time delay is needed in order to acquire fresh samples in to buffer*/
        /* Here we have used time delay of one second but you can calculate exact value taking in to account buffer*/
        /*length and smaling rate*/

        sleep(1);
        rp_AcqSetTriggerSrc(RP_TRIG_SRC_EXT_PE);
        rp_acq_trig_state_t state = RP_TRIG_STATE_TRIGGERED;

        while(1){
                rp_AcqGetTriggerState(&state);
                if(state == RP_TRIG_STATE_TRIGGERED){
                break;
                }
        }
	rp_AcqGetWritePointerAtTrig(&t);
	
	rp_AcqGetDataV(RP_CH_1,0, &buff_size, buff);      
        //rp_AcqGetOldestTrigDataV(RP_CH_1, &buff_size, buff);
	//acq_GetOldestTrigDataV(RP_CH_1, &buff_size, buff);
        int i;
        for(i = 0; i < buff_size; i++){
                //printf("%f\n", buff[i]);
		fprintf(fp,"%f\n", buff[i]);
        }
        /* Releasing resources */
        free(buff);
        rp_Release();
        return 0;
}


Thanks in advance

BeRenz
Posts: 6
Joined: Mon Aug 10, 2020 6:05 pm

Re: C Code for acquiring data with external trigger

Post by BeRenz » Sat Aug 15, 2020 1:19 am

Hi,
first of all I notice that you are not using the predefined enum decimations in the rp.h file for:

Code: Select all

rp_AcqSetDecimation(2);
it should be something like

Code: Select all

rp_AcqSetDecimation(RP_DEC_8);
.
Does this code work for you with other trigger sources?

Have you added something like

Code: Select all

rp_DpinSetState(RP_LED1,RP_HIGH);
after your while loop yet? This way you can easily see if you have triggered...
You also might run in the same problem:
viewtopic.php?f=8&t=24709
Greetings,
Benjamin

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 28 guests