int main(int argc, char **argv){

	/* Burst count */
	int i;

	/* Print error, if rp_Init() function failed */
	if(rp_Init() != RP_OK){
		fprintf(stderr, "Rp api init failed!\n");
	}
	
	rp_GenFreq(RP_CH_1, 100);
	rp_GenAmp(RP_CH_1, 1.0);
	rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);

	/* Enable output channel */
	rp_GenOutEnable(RP_CH_1);

	for(i = 0; i < 100; i++){
		usleep(200000);
		rp_GenBurstCount(RP_CH_1, 1);
		usleep(200000);
		rp_GenMode(RP_CH_1, RP_GEN_MODE_BURST);
	} 

	/*
	usleep(50000000);
	rp_GenBurstCount(channel, 1);
	rp_GenMode(channel, gen_mode);
	usleep(5000000);
	*/

	/* Releasing resources */
	rp_Release();
}
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");
        }

        /*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_GenOutEnable(RP_CH_1);


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

        rp_AcqReset();
        rp_AcqSetDecimation(1);
        rp_AcqSetTriggerLevel(0.1); //Trig level is set in Volts while in SCPI 
        rp_AcqSetTriggerDelay(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_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);
        int i;
        for(i = 0; i < buff_size; i++){
                printf("%f\n", buff[i]);
        }
        /* Releasing resources */
        free(buff);
        rp_Release();
        return 0;
}

        }
示例#3
0
void setup_output()
{
    /* Generating frequency */
    rp_GenFreq(RP_CH_2, 0.0);

    /* Generating amplitude */
    rp_GenAmp(RP_CH_2, 0.0);

    /* Generating wave form */
    rp_GenWaveform(RP_CH_2, RP_WAVEFORM_DC );
    
    rp_GenOutEnable(RP_CH_2);
}
int main(int argc, char **argv){

        /* Burst count */


        /* Print error, if rp_Init() function failed */
        if(rp_Init() != RP_OK){
                fprintf(stderr, "Rp api init failed!\n");
        }

        rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
        rp_GenFreq(RP_CH_1, 1000);
        rp_GenAmp(RP_CH_1, 1.0);

        rp_GenMode(RP_CH_1, RP_GEN_MODE_BURST);
        rp_GenBurstCount(RP_CH_1, 1);
        rp_GenBurstRepetitions(RP_CH_1, 10000);
        rp_GenBurstPeriod(RP_CH_1, 5000);
        rp_GenTrigger(1);
        sleep(1);
        rp_GenOutEnable(RP_CH_1);
        rp_Release();
}
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");
	}

	/* Generating frequency */
	rp_GenFreq(RP_CH_1, 10000.0);

	/* Generating amplitude */
	rp_GenAmp(RP_CH_1, 1.0);

	/* Generating wave form */
	rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);

	/* Enable channel */
	rp_GenOutEnable(RP_CH_1);

	/* Releasing resources */
	rp_Release();

	return 0;
}
示例#6
0
void *Read_CT_Data(void *arg)
{
    rp_pinState_t heart_beat_state; 
    uint32_t buff_size = RP_BUF_SIZE;
    uint32_t trig_pos;
    float *buff_ch1 = (float *)malloc(buff_size * sizeof(float));
    float *buff_ch2 = (float *)malloc(buff_size * sizeof(float));
    float val_sum_ch1,val_sum_ch2,val_ch1,val_ch2;
    float tmp_val_ch1, tmp_val_ch2;
    float charge_ch1;
    float charge_ch2;  
    int counter;
    clock_t start_time, diff;
    int msec;
    int endpoints;
    int startpoints;
    
    val_sum_ch1=0;
    counter=0;
    msec=0;
    new_data=0;
    
    /* Print error, if rp_Init() function failed */
    if(rp_Init() != RP_OK)
    {
        fprintf(stderr, "Rp api init failed!n");
    }
    
    setup_output();

    //rp_AcqSetDecimation(RP_DEC_8 );
    rp_AcqSetSamplingRate(RP_SMP_125M);
    //rp_AcqSetSamplingRate(RP_SMP_15_625M);
    rp_AcqSetTriggerLevel(trig_level); //Trig level is set in Volts while in SCPI is set in mV
    rp_AcqSetTriggerDelayNs(0);
    //rp_AcqSetTriggerDelay(0);
    rp_AcqSetAveraging(true);
    rp_AcqStart();

    //rp_AcqSetTriggerSrc(RP_TRIG_SRC_EXT_PE);
    //rp_AcqSetTriggerSrc(RP_TRIG_SRC_CHA_NE);			// Trig on signal
    rp_AcqSetTriggerSrc(trig_source);			
    rp_acq_trig_state_t state = RP_TRIG_STATE_TRIGGERED;

    // Get clock
    start_time = clock();

    rp_DpinSetDirection ( RP_LED4, RP_OUT);
    rp_DpinSetDirection ( RP_LED3, RP_OUT);
    rp_DpinSetDirection ( RP_DIO1_P, RP_OUT);
    rp_AcqStart();    
    //Clear count_table
    count_table[0]=0;
    free_counter=0;
    heart_beat_state=RP_LOW;

	while(1)
	{
	    // Wait for trig
	    
	    while(1)
	    {
		diff=clock()-start_time;
		msec=diff*1000/CLOCKS_PER_SEC;
		rp_AcqGetTriggerState(&state);
		if(state == RP_TRIG_STATE_TRIGGERED)
		{
		    usleep(10);
		    triggered=1;
		    break;
		}
		if (msec>2000)
		{
		    rp_AcqStart();
		    rp_AcqSetTriggerSrc(trig_source);
		    rp_GenAmp(RP_CH_2, 0);
		    triggered=0;
		    printf("No trig for 2 s... Set output analog output to zero");
		}

	    }
	    // Get data
	    rp_DpinSetState( RP_LED4, RP_HIGH);
	    rp_AcqGetWritePointerAtTrig(&trig_pos);
	    //printf("Trig pos: %d", trig_pos);
	    // Check if trig_pos is too close to buffer start/end
	    if ((trig_pos+num_data_points_after_trig)>(RP_BUF_SIZE-1))
	    {
		endpoints=(RP_BUF_SIZE-1)-(trig_pos-num_data_points_before_trig);
		startpoints=num_data_points_after_trig-((RP_BUF_SIZE-1)-trig_pos);
		rp_AcqGetDataPosV(RP_CH_1,0,(RP_BUF_SIZE-1),buff_ch1,&buff_size);			// Get entire buffer 
		rp_AcqGetDataPosV(RP_CH_2,0,(RP_BUF_SIZE-1),buff_ch2,&buff_size);			// Get entire buffer

		val_ch1=integrated_charge(buff_ch1,((RP_BUF_SIZE-1)-endpoints),(RP_BUF_SIZE-1));
		tmp_val_ch1=integrated_charge(buff_ch1,0,startpoints);
		val_ch2=integrated_charge(buff_ch2,((RP_BUF_SIZE-1)-endpoints),(RP_BUF_SIZE-1));
		tmp_val_ch2=integrated_charge(buff_ch2,0,startpoints);
		val_ch1=val_ch1+tmp_val_ch1;
		val_ch2=val_ch2+tmp_val_ch2;
	
		//Debug
		//printf("High Ring Buffer overflow\n");
		//printf("ch1: %f ch2: %f\n",val_ch1,val_ch2);
		//printf("Trig pos: %d end %d start %d\n", trig_pos, endpoints, startpoints);
		
	    }
	    else if ((trig_pos-num_data_points_before_trig)<0)
	    {	
		
		endpoints=(trig_pos-num_data_points_before_trig);
		startpoints=num_data_points_after_trig-endpoints;
		rp_AcqGetDataPosV(RP_CH_1,0,(RP_BUF_SIZE-1),buff_ch1,&buff_size);			// Get entire buffer
		rp_AcqGetDataPosV(RP_CH_2,0,(RP_BUF_SIZE-1),buff_ch2,&buff_size);			// Get entire buffer

		val_ch1=integrated_charge(buff_ch1,((RP_BUF_SIZE-1)-endpoints),(RP_BUF_SIZE-1));
		tmp_val_ch1=integrated_charge(buff_ch1,0,startpoints);
		val_ch2=integrated_charge(buff_ch2,((RP_BUF_SIZE-1)-endpoints),(RP_BUF_SIZE-1));
		tmp_val_ch2=integrated_charge(buff_ch2,0,startpoints);
		val_ch1=val_ch1+tmp_val_ch1;
		val_ch2=val_ch2+tmp_val_ch2;
	
		//Debug
		printf("Low Ring Buffer underrun\n");
		printf("ch1: %f ch2: %f\n",val_ch1,val_ch2);
		printf("Trig pos: %d end %d start %d\n", trig_pos, endpoints, startpoints);
	    }
	    else
	    {
		rp_AcqGetDataPosV(RP_CH_1,(trig_pos-num_data_points_before_trig),(trig_pos+num_data_points_after_trig),buff_ch1,&buff_size);
		rp_AcqGetDataPosV(RP_CH_2,(trig_pos-num_data_points_before_trig),(trig_pos+num_data_points_after_trig),buff_ch2,&buff_size);
		val_ch1=integrated_charge(buff_ch1,0,(num_data_points_after_trig+num_data_points_before_trig));
		val_ch2=integrated_charge(buff_ch2,0,(num_data_points_after_trig+num_data_points_before_trig));
	    }
	        
	    val_sum_ch1=val_sum_ch1+val_ch1;
	    val_sum_ch2=val_sum_ch2+val_ch2;
	    counter++;
	    charge[0]=val_ch1+val_ch2;

	    //rp_DpinSetState( RP_DIO1_P, RP_HIGH);
	    //usleep(20);
	    //rp_DpinSetState( RP_DIO1_P, RP_LOW);
	    
	    // Update data each s, 1050 ms to make sure the buffers update even @ 1 Hz trigger rate
	    if (msec>1050)
	    {
		start_time = clock();
		charge_ch1=(val_sum_ch1/(counter-1));
		charge_ch2=(val_sum_ch2/(counter-1));
		pthread_mutex_lock( &mutex1 );
		charge[1]=charge_ch1+charge_ch2;
		// Update table of volt & counters for sec 1-9
		for (int i=9;i>1;i--)
		{
		   count_table[i]=count_table[i-1]+counter;
		   charge[i]=charge[i-1]+charge[1];
		}
		count_table[1]=counter;
		charge[1]=charge[1];
		printf("\nNo of Triggers: %d, Time betweem (msec): %d\n", count_table[1], msec);

		/* Generating amplitude */
		//Check if overflow for the DAC
		if (charge[1]<1)
		{
		    rp_GenAmp(RP_CH_2, charge[1]);
		}
		else
		{
		    rp_GenAmp(RP_CH_2, 1);
		}

		printf("Charge: %f nC, Charge Ch1: %f nC, Charge Ch2: %f nC\n",charge[1], charge_ch1,charge_ch2);
		fflush(stdout);
		val_sum_ch1=0;
		val_sum_ch2=0;
		counter=0;
		free_counter++;
		// Digital output heartbeat
		rp_DpinGetState(RP_DIO1_P, &heart_beat_state);
		if (heart_beat_state==RP_LOW)
		{
		    rp_DpinSetState( RP_DIO1_P, RP_HIGH);
		}
		else
		{
		    rp_DpinSetState( RP_DIO1_P, RP_LOW);  
		}
		// Get FPGA temp
		rp_HealthGetValue(RP_TEMP_FPGA, &fpga_temp);
		printf("FPGA temp: %.01f C\n",fpga_temp);
		
		
	    }
	    new_data=1;
	    pthread_mutex_unlock( &mutex1 );
	    rp_AcqStart();
	    rp_AcqSetTriggerSrc(trig_source);
	    rp_DpinSetState( RP_LED4, RP_LOW);
	    
	    
	}
	/* Releasing resources */

	fflush(stdout);
	free(buff_ch1);
	free(buff_ch2);
	rp_Release();
	
	return NULL;


}