Hi
I am trying to write a program that has synchronized generation and acquisition.
After much reading I decided I needed to use an external signal.
I have connected DIO1_P to DIO0_P ( Pins 5 and 3 on E1 ), setting DIO1_P as out and DIO0_P as input.
I have tested this out using the following code, and it works as expected, toggles between 0 and 1, 8 times
if ( rp_DpinReset( ) != RP_OK )
{ fprintf ( stderr, "rp_DpinReset failed\n" ) ; }
if ( rp_DpinSetDirection( RP_DIO0_P, RP_IN ) != RP_OK )
{ fprintf ( stderr, "rp_DpinSetDirection failed\n" ) ; }
if ( rp_DpinSetDirection( RP_DIO1_P, RP_OUT ) != RP_OK )
{ fprintf ( stderr, "rp_DpinSetDirection failed\n" ) ; }
for ( Loop = 0; Loop < 8; Loop++ )
{ if ( rp_DpinSetState( RP_DIO1_P, RP_LOW ) != RP_OK )
{ fprintf ( stderr, "rp_DpinSetState failed\n" ) ; }
sleep ( 1 ) ;
if ( rp_DpinGetState( RP_DIO0_P, &PinState ) != RP_OK )
{ fprintf ( stderr, "rp_DpinGetState failed\n" ) ; }
fprintf( stderr, "Pin state = %d\n", PinState ) ;
if ( rp_DpinSetState( RP_DIO1_P, RP_HIGH ) != RP_OK )
{ fprintf ( stderr, "rp_DpinSetState failed\n" ) ; }
sleep ( 1 ) ;
if ( rp_DpinGetState( RP_DIO0_P, &PinState ) != RP_OK )
{ fprintf ( stderr, "rp_DpinGetState failed\n" ) ; }
fprintf( stderr, "Pin state = %d\n", PinState ) ;
}
So I can produced a signal that goes to the external trigger (I think)
However the following code never triggers
if ( rp_DpinReset( ) != RP_OK )
{ fprintf ( stderr, "rp_DpinReset failed\n" ) ; }
if ( rp_DpinSetDirection( RP_DIO0_P, RP_IN ) != RP_OK )
{ fprintf ( stderr, "rp_DpinSetDirection failed\n" ) ; }
if ( rp_DpinSetDirection( RP_DIO1_P, RP_OUT ) != RP_OK )
{ fprintf ( stderr, "rp_DpinSetDirection failed\n" ) ; }
rp_DpinSetState( RP_DIO1_P, RP_LOW ) ;
for ( Loop = 0; Loop < 1000; Loop++ )
{ rp_GenReset( ) ;
rp_GenWaveform( RP_CH_1, RP_WAVEFORM_ARBITRARY ) ;
rp_GenArbWaveform( RP_CH_1, out, buff_size ) ;
rp_GenAmp( RP_CH_1, 1.0 ) ;
if (( RP_Err = rp_GenGetFreq( RP_CH_1, &freq )) != RP_OK )
{ fprintf( stderr, "Rp_GenGetFreq failed %d\n", RP_Err ) ; }
fprintf( stderr, "Current frequency = %f\n", freq ) ;
if (( RP_Err = rp_GenFreq( RP_CH_1, 15259.0 )) != RP_OK )
{ fprintf( stderr, "Rp_GenFreq failed %d\n", RP_Err ) ; }
if (( RP_Err = rp_GenGetFreq( RP_CH_1, &freq )) != RP_OK )
{ fprintf( stderr, "Rp_GenGetFreq failed %d\n", RP_Err ) ; }
fprintf( stderr, "New frequency = %f\n", freq ) ;
rp_GenBurstCount( RP_CH_1, 1 ) ;
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 ) ;
rp_AcqReset( ) ;
rp_AcqSetDecimation( RP_DEC_1 ) ;
rp_AcqSetTriggerLevel( 0 ) ;
rp_AcqSetTriggerDelay( 0 ) ;
rp_AcqStart( ) ;
rp_AcqSetTriggerSrc( RP_TRIG_SRC_EXT_PE ) ;
rp_DpinSetState( RP_DIO1_P, RP_HIGH ) ;
rp_DpinSetState( RP_DIO1_P, RP_HIGH ) ;
rp_DpinSetState( RP_DIO1_P, RP_LOW ) ;
fprintf ( stderr, "Triggering generation and signal acquisition\n" ) ;
rp_acq_trig_state_t state = RP_TRIG_STATE_WAITING ;
while ( state != RP_TRIG_STATE_TRIGGERED )
{ sleep( 1 ) ;
fprintf( stderr, "Trigger state is %d\n", state ) ;
rp_AcqGetTriggerState( &state ) ;
}
rp_AcqGetOldestDataV( RP_CH_1, &buff_size, in ) ;
BuffStop = buff_size ;
if ((( SkipTime + PulseTime + SkipTime ) * usecPoints ) < BuffStop )
{ BuffStop = ( SkipTime + PulseTime + SkipTime ) * usecPoints ; }
for ( i = 0; i < BuffStop; i++ )
{ printf( "%5d %5d %8.5f\n", Loop, i, in[ i ] ) ; }
}
The program never gets a trigger start, just repeats the line "Trigger state is 1"
Can someone please explain what I have done wrong, it must be very simple.
I have not been able to find any examples that use external triggering.
Thanks
John Parry
synchronized generating and acquiring
- redpitaya
- Site Admin
- Posts: 926
- Joined: Wed Mar 26, 2014 7:04 pm
Re: synchronized generating and acquiring
Hi John,
So to clarify.
1. You want to have synchronized signal generation and acquisition
2. Signal generation and acquisition is triggered by external triggering signal on DIO0_P digital pin
3. The triggering signal is generated on digital output DIO1_P which is connected to trigger input DIO0_P
Electrical connection between trigger signal output (DIO1_P) and trigger input (DIO0_P) should be something like this:
Now, you are able to generate trigger signal on DIO1_P and get that signal on DIO0_P.
Can you try this two simple examples:
1. Acquire on external trigger
2. Generate on external trigger
and then if they works try to merge them
Best, RP
So to clarify.
1. You want to have synchronized signal generation and acquisition
2. Signal generation and acquisition is triggered by external triggering signal on DIO0_P digital pin
3. The triggering signal is generated on digital output DIO1_P which is connected to trigger input DIO0_P
Electrical connection between trigger signal output (DIO1_P) and trigger input (DIO0_P) should be something like this:
Code: Select all
DIO1_P __________________DIO0_P
|
1K Resistor
|
GND
Can you try this two simple examples:
1. Acquire on external trigger
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");
}
int selected_frequency=1000.0;
int min_periodes = 8;
int signal_decimation;
float wait;
if (selected_frequency == 100000.0) { wait = 200; }
else if (selected_frequency == 10000.0) { wait = 2000; }
else if (selected_frequency == 1000.0) { wait = 20000; }
else if (selected_frequency == 100.0) { wait = 200000; }
/*Generate LOOP BACK signal FOR TESTING*/
rp_GenReset();
rp_GenFreq(RP_CH_2, selected_frequency);
rp_GenAmp(RP_CH_2, 0.2);
rp_GenOffset(RP_CH_2, 0.25);
rp_GenWaveform(RP_CH_2, RP_WAVEFORM_SINE);
rp_GenOutEnable(RP_CH_2);
usleep(100000);
rp_AcqReset();
if (selected_frequency == 100000.0) { rp_AcqSetDecimation(RP_DEC_1); signal_decimation = 1; }
else if (selected_frequency == 10000.0) { rp_AcqSetDecimation(RP_DEC_8); signal_decimation = 8; }
else if (selected_frequency == 1000.0) { rp_AcqSetDecimation(RP_DEC_64); signal_decimation = 64; }
else if (selected_frequency == 100.0) { rp_AcqSetDecimation(RP_DEC_1024); signal_decimation = 1024; }
uint32_t buff_size = ((min_periodes*125e6)/(selected_frequency*signal_decimation));
float *buff_in1 = (float *)malloc(buff_size * sizeof(float));
float *buff_in2 = (float *)malloc(buff_size * sizeof(float));
rp_AcqSetTriggerLevel(0);
rp_AcqSetTriggerDelay(8192);
rp_AcqStart();
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;
}
}
usleep(wait);
rp_AcqGetOldestDataV(RP_CH_1, &buff_size, buff_in1);
rp_AcqGetOldestDataV(RP_CH_2, &buff_size, buff_in2);
}
2. Generate on external trigger
Code: Select all
/* Red Pitaya external trigger pulse generation Example */
#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_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
rp_GenFreq(RP_CH_1, 200);
rp_GenAmp(RP_CH_1, 1);
/* Enable output channel */
rp_GenOutEnable(RP_CH_1);
rp_GenTriggerSource(RP_CH_1, RP_GEN_TRIG_SRC_EXT_PE);
/* Release rp resources */
rp_Release();
return 0;
}
Best, RP
-
- Posts: 2
- Joined: Tue Feb 16, 2016 2:39 am
Re: synchronized generating and acquiring
Thanks for the replay,
Your first code worked until I changed the frequency to 100,000
To start with I added a couple of blocks of code to your example so that I could generate the signal from the Red Pitaya
the following lines of code were added before rp_GenReset()
the following lines of code were added after rp_AcqSetTriggerSrc(RP_TRIG_SRC_EXT_PE);
Before I changed the line
the program works fine.
As soon as I change it to
The program never comes out of the waiting for trigger loop.
As I am working for 2usec pulses I really need the frequency to be as high as possible.
Can someone please help with this issue.
Regards
John Parry
Your first code worked until I changed the frequency to 100,000
To start with I added a couple of blocks of code to your example so that I could generate the signal from the Red Pitaya
the following lines of code were added before rp_GenReset()
Code: Select all
rp_DpinReset( ) ;
rp_DpinSetDirection( RP_DIO0_P, RP_IN ) ;
rp_DpinSetDirection( RP_DIO1_P, RP_OUT ) ;
rp_DpinSetState( RP_DIO1_P, RP_LOW ) ;
Code: Select all
usleep( 50 ) ;
rp_DpinSetState( RP_DIO1_P, RP_HIGH ) ;
usleep( 50 ) ;
rp_DpinSetState( RP_DIO1_P, RP_LOW ) ;
fprintf( stderr, "Triggered\n" ) ;
Code: Select all
int selected_frequency=1000.0;
As soon as I change it to
Code: Select all
int selected_frequency=100000.0;
As I am working for 2usec pulses I really need the frequency to be as high as possible.
Can someone please help with this issue.
Regards
John Parry
- redpitaya
- Site Admin
- Posts: 926
- Joined: Wed Mar 26, 2014 7:04 pm
Re: synchronized generating and acquiring
Hi,
Try this code:
Btw, this "ifs" for wait parameters are used just to have desired number of periods and also to wait enough time for full buffer.
So, i think the problem was in trigger signal. In your case after the acquisition is starter trigger signal was more or less constant and it will not trig the acquisition.
So in order to trigger you need to have "pulses" on your DIO0_P to have positive or negative trigger edge.
I have used while loop to generate such signal on DIO1_P.
Best
Try this code:
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");
}
int selected_frequency=10000000;
int min_periodes = 8;
int signal_decimation;
float wait;
if (selected_frequency >= 100000.0) { wait = 200; }
else if (selected_frequency >= 10000.0) { wait = 2000; }
else if (selected_frequency >= 1000.0) { wait = 20000; }
else if (selected_frequency >= 0) { wait = 200000; }
//Digital pin init.
rp_DpinReset( );
rp_DpinSetDirection(RP_DIO1_P, RP_OUT);
rp_DpinSetState(RP_DIO1_P, RP_LOW );
/*Generate LOOP BACK signal FOR TESTING*/
rp_GenReset();
rp_GenFreq(RP_CH_1, selected_frequency);
rp_GenAmp(RP_CH_1, 1);
rp_GenOffset(RP_CH_1, 0);
rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
rp_GenOutEnable(RP_CH_1);
usleep(100000);
rp_AcqReset();
if (selected_frequency >= 100000.0) { rp_AcqSetDecimation(RP_DEC_1); signal_decimation = 1; }
else if (selected_frequency >= 10000.0) { rp_AcqSetDecimation(RP_DEC_8); signal_decimation = 8; }
else if (selected_frequency >= 1000.0) { rp_AcqSetDecimation(RP_DEC_64); signal_decimation = 64; }
else if (selected_frequency >= 0) { rp_AcqSetDecimation(RP_DEC_1024); signal_decimation = 1024; }
uint32_t buff_size = ((min_periodes*125e6)/(selected_frequency*signal_decimation));
float *buff_in1 = (float *)malloc(buff_size * sizeof(float));
//float *buff_in2 = (float *)malloc(buff_size * sizeof(float));
rp_AcqSetTriggerLevel(0);
rp_AcqSetTriggerDelay(8192);
rp_AcqStart();
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_DpinSetState(RP_DIO1_P, RP_HIGH);
usleep(1);
rp_DpinSetState(RP_DIO1_P, RP_LOW);
}
usleep(wait);
rp_AcqGetOldestDataV(RP_CH_1, &buff_size, buff_in1);
//rp_AcqGetOldestDataV(RP_CH_2, &buff_size, buff_in2);
int i;
for(i = 0; i < buff_size; i++){
printf("%f\n", buff_in1[i]);
}
//Releasing resources
free(buff_in1);
rp_Release();
return 0;
}
Btw, this "ifs" for wait parameters are used just to have desired number of periods and also to wait enough time for full buffer.
So, i think the problem was in trigger signal. In your case after the acquisition is starter trigger signal was more or less constant and it will not trig the acquisition.
So in order to trigger you need to have "pulses" on your DIO0_P to have positive or negative trigger edge.
I have used while loop to generate such signal on DIO1_P.
Best
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 33 guests