synchronized generating and acquiring
Posted: Wed Feb 24, 2016 8:20 am
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
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