I was hoping to get a few tips on how I can improve my current data acquisition system. I started with the single buffer acquisition system http://redpitaya.com/examples-new/singl ... r-acquire/ (using the C-api). I was wondering how long it takes to restart the acquisition system after it has been triggered? (Reasoning: I would like to trigger on events that are 5 ms apart and not have the chance of missing an event).
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <time.h>
//for clock_gettime
#include "redpitaya/rp.h"
struct timespec program_start;
#define BILLION 1000000000ULL
struct timespec timer_start()
{
//CLOCK_REALTIME
//CLOCK_MONOTONIC
//CLOCK_PROCESS_CPUTIME_ID
//CLOCK_THREAD_CPUTIME_ID
//CLOCK_MONOTONIC_RAW (not subject to NTP adjustments)
struct timespec start_time;
clock_gettime(CLOCK_MONOTONIC_RAW, &start_time);
return start_time;
}
unsigned long long int timer_end_ns(struct timespec start_time)
{
struct timespec end_time;
clock_gettime(CLOCK_MONOTONIC_RAW, &end_time);
unsigned long long int diff_in_sec = end_time.tv_sec - start_time.tv_sec;
unsigned long long int diff_ns = end_time.tv_nsec - start_time.tv_nsec;
return diff_in_sec * BILLION + diff_ns;
}
int main(int argc, char * argv[])
{
program_start = timer_start();
if ( rp_Init() != RP_OK )
{
fprintf(stderr, "%s\n", "Red Pitaya API initialization failed\n");
return EXIT_FAILURE;
}
rp_AcqReset();
rp_AcqSetDecimation(1);
const float trigger_threshold = 0.05;
rp_AcqSetTriggerLevel(trigger_threshold);
//Trig level is set in Volts
rp_AcqSetTriggerDelay(0);
rp_AcqStart();
usleep(135);//sleep for 135 uS (so buffer can be populated)
rp_AcqSetTriggerSrc(RP_TRIG_SRC_CHA_PE);
rp_acq_trig_state_t state = RP_TRIG_STATE_WAITING;
unsigned int trigger_count = 0;
printf("New Acquisition\n");
start = timer_start();
struct timespec last;
while(trigger_count < 100)//currently an arbitrary limit (this will change)
{
if (trigger_count == 0)
{
last = timer_start();
}
rp_AcqGetTriggerState(&state);
if (state == RP_TRIG_STATE_TRIGGERED)
{
rp_AcqSetTriggerSrc(RP_TRIG_SRC_DISABLED);//as a precaution
rp_AcqGetOldestDataV(RP_CH_1, &buffer_size, buff);
if (trigger_count == 0)
{
//** output **
//** CLIPPED **
}
int i;
for ( i = 0; i < buffer_size; ++i)
{
//** do something with the buffer **
//** CLIPPED **
}
printf("TSLP[%u]: %llu\n", trigger_count, timer_end_ns(last)/1000 );
last = timer_start();
++trigger_count;
usleep(1);
state = RP_TRIG_STATE_WAITING;
rp_AcqSetTriggerSrc(RP_TRIG_SRC_CHA_PE);
rp_AcqStart();
usleep(135);
}
}
// Output details from all trigger events;
// .. CLIPPED ..
free(buff);
rp_Release();
return EXIT_SUCCESS;
}
Greg
edit: Added signature