Strange problem for trigger
Posted: Thu May 19, 2016 8:46 pm
Hello,
I have a strange problem about the trigger in data sampling.
Test environment: A sinewave is generated using OUT1 of RP (frequency 5kHz, Amplitude 0.5V). The data is sampled using IN1 of RP (Decimation 8, trigger level 0.2V, trigger delay 8191, acquire trigger at positive edge of CHA)
I briefly modified the C program provided on the example to achieve above test environment.
The codes are
I plot the sampled data in the following figure. The amplitude and frequency for the sampled data are right. However, the trigger seems to be wrong. In addition, the beginning and ending of the data are different for repetitive testing.
Then, I use the Matlab to sample data with same test environment.
The matlab codes are
The result is right, shown in the following figure.
I repetitively check the difference between the C and Matlab programs. The functions of both programs are same. It is quite strange and I can’t find the problem with C program.
My system is Ubuntu 14.04. The version of ecosystem I used is ecosystem-0.95-1-6deb253.
Could you please kindly check this problem?
Thank you very much!
I have a strange problem about the trigger in data sampling.
Test environment: A sinewave is generated using OUT1 of RP (frequency 5kHz, Amplitude 0.5V). The data is sampled using IN1 of RP (Decimation 8, trigger level 0.2V, trigger delay 8191, acquire trigger at positive edge of CHA)
I briefly modified the C program provided on the example to achieve above test environment.
The codes are
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "redpitaya/rp.h"
int main(int argc, char **argv){
/* Print error, if rp_Init() function failed */
if(rp_Init() != RP_OK){
fprintf(stderr, "Rp api init failed!\n");
}
rp_GenReset();
rp_GenFreq(RP_CH_1, 5000.0);
rp_GenAmp(RP_CH_1, 0.5);
rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
rp_GenOutEnable(RP_CH_1);
uint32_t buff_size = 16384;
float *buff = (float *)malloc(buff_size * sizeof(float));
rp_AcqReset();
rp_AcqSetDecimation(RP_DEC_8);
rp_AcqSetTriggerLevel(0.2); //Trig level is set in Volts while in SCPI
rp_AcqSetTriggerDelay(8191);
rp_AcqStart();
sleep(1);
rp_AcqSetTriggerSrc(RP_TRIG_SRC_CHA_PE);
rp_acq_trig_state_t state = RP_TRIG_STATE_TRIGGERED;
while(1){
rp_AcqGetTriggerState(&state);
if(state == RP_TRIG_STATE_TRIGGERED){
sleep(1);
break;
}
rp_AcqGetOldestDataV(RP_CH_1, &buff_size, buff); //get the raw data
FILE *fp;
fp=fopen("acq_data.txt","w");
int i;
for(i = 0; i < buff_size; i++){
fprintf(fp,"%f\n",buff[i]);
}
fclose(fp);
/* Releasing resources */
free(buff);
rp_Release();
return 0;
}
}
The matlab codes are
Code: Select all
IP= 192.168.128.1; % Input IP of your Red Pitaya...
port = 5000;
tcpipObj=tcpip(IP, port);
tcpipObj.InputBufferSize = 16384*32;
%% Open connection with your Red Pitaya
flushinput(tcpipObj);
flushoutput(tcpipObj);
fopen(tcpipObj);
tcpipObj.Terminator = 'CR/LF';
fprintf(tcpipObj,'GEN:RST');
fprintf(tcpipObj,'SOUR1:FUNC SINE'); % Set function of output signal
fprintf(tcpipObj,'SOUR1:FREQ:FIX 5000'); % Set frequency of output signal
fprintf(tcpipObj,'SOUR1:VOLT 0.5'); % Set amplitude of output signal
fprintf(tcpipObj,'OUTPUT1:STATE ON'); % Set output to ON
fprintf(tcpipObj,'ACQ:RST');
fprintf(tcpipObj,'ACQ:DEC 8');
fprintf(tcpipObj,'ACQ:TRIG:LEV 0.2');
fprintf(tcpipObj,'ACQ:TRIG:DLY 8191');
fprintf(tcpipObj,'ACQ:START');
pause(1)
fprintf(tcpipObj,'ACQ:TRIG CH1_PE');
while 1
trig_rsp=query(tcpipObj,'ACQ:TRIG:STAT?')
if strcmp('TD',trig_rsp(1:2)) % Read only TD
break
end
end
% Read data from buffer
signal_str=query(tcpipObj,'ACQ:SOUR1:DATA?');
signal_num=str2num(signal_str(1,2:length(signal_str)-3));
plot(signal_num); grid on; ylabel('Voltage / V');xlabel('samples')
%% Close connection with Red Pitaya
fclose(tcpipObj);
My system is Ubuntu 14.04. The version of ecosystem I used is ecosystem-0.95-1-6deb253.
Could you please kindly check this problem?
Thank you very much!