Page 1 of 1

C, trigger happens sometimes not, never at the same moment

Posted: Wed Jul 13, 2016 9:53 pm
by h30x
Hello,

This is my first experience with RedPitaya, so maybe my question will be easy to answer.
I have written this code in C using the functions defined in rp.h :

Code: Select all

#include [things to include]
#define [some symbolic defines]
int main(int argc, char **argv){
rp_Init();
/* generate a sine signal in OUT1 linked to IN1 */
	rp_GenReset();
	rp_GenFreq(RP_CH_1, FREQ);
	rp_GenAmp(RP_CH_1, 1);
	rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
	rp_GenOutEnable(RP_CH_1);

/* set the acquisition parameters */
    uint32_t buff_size = 8000;
    float *buff = (float *)malloc(buff_size * sizeof(float));

    rp_AcqReset();
    rp_AcqSetSamplingRate(RP_SMP_125M);
    rp_AcqSetTriggerSrc(RP_TRIG_SRC_CHA_PE); // CHA positive edge
    rp_AcqSetTriggerLevel(0.1);
    
/* start the acquisition and stop it when trigger happened */
	rp_AcqStart();
	sleep(0.001); // waiting to fill the buffer
        rp_acq_trig_state_t state = RP_TRIG_STATE_WAITING;
    
    while(1){ 
		rp_AcqGetTriggerState(&state);
		if(state == RP_TRIG_STATE_TRIGGERED){
			rp_AcqStop();
			break;}
		}
            
    rp_AcqGetLatestDataV(RP_CH_1, &buff_size, buff);
    
    FILE* file;
    file = fopen("/opt/redpitaya/www/apps/output","wb");
    
    fwrite(buff,sizeof(float),buff_size,file);

    fclose(file);
    free(buff);
    rp_Release();
    return 0;
}
But sometimes my program does not trigger (does not stop), and it gives different results like these (sorry for the huge pictures, I do not know how to change their size) :
ImageImageImage

Did I do something wrong ?
Thank you,

H30X

[edit]
after some more tests, it happens that the trigger does not works as expected : sometimes, it does not change its state whereas the voltage passed trough the threshold several times. no idea why it works sometimes and sometimes it does not.

[edit]
the trigger sometimes work, and sometimes not. without any apparent reason