int trigger_setup(TriggerMode tMode, TriggerSource tSource, double trigLevel)
{
	rs = SetTriggerMode(tMode);
	ReturnCheck(rs);
	rs = SetTriggerSource(tSource);
	ReturnCheck(rs);
	rs = SetIFPowerTriggerLevel(trigLevel);
	ReturnCheck(rs);
	return 0;
}
Пример #2
0
void TiePieHS3::sample_after_external_trigger(double _rate, size_t _samples, double _sensitivity ,size_t _resolution) {
  ADC_Abort();
  /* set autoranging off */
  SetAutoRanging(Ch1,0);
  SetAutoRanging(Ch2,0);

  samples=_samples;
  if (samples==0 || _rate<=0) return;
  unsigned short int retval;
  //samples=1024*1024*1024; // impossible value... provoke error
  retval=SetRecordLength(samples);
  if (0!=retval) {
    char buffer[256];
    snprintf(buffer, sizeof(buffer), "could not set record length: SetRecrodLength(%d) returned %d", samples, retval);
    throw ADC_exception(std::string(buffer));
  }
  if (0!=SetPostSamples(samples)){
    throw ADC_exception("could not set post sample number");
  }
  fprintf(stderr,"set sample number to %d\n",samples);

  /* set sampling frequency */
  unsigned int freq=(unsigned int)fabs(floor(_rate)+0.5);
  unsigned int freq_req=freq;
  SetSampleFrequency(&freq_req);
  if (freq!=freq_req)
    throw ADC_exception("requested frequency could not be set");
  rate=freq_req;
  fprintf(stderr,"set rate to %g\n",rate);

  /* set resolution */
  if (0!=SetResolution(_resolution))
    throw ADC_exception("could not set resolution");
  unsigned char resolution_set;
  GetResolution(&resolution_set);
  if (_resolution!=resolution_set)
    throw ADC_exception("requested resolution not supported");
  resolution=_resolution;
  fprintf(stderr,"set resolution to %d\n",resolution);

#if 0
  /* set DC level value to zero */
  const double dclevel_req=-2.0;
  if (E_NO_ERRORS!=SetDcLevel(1, dclevel_req))
    throw ADC_exception("could not set dc level for channel 1");
  if (E_NO_ERRORS!=SetDcLevel(2, dclevel_req))
    throw ADC_exception("could not set dc level for channel 2");
#endif

  /* set input sensitivity for both channels */
  double sensitivity_req1=_sensitivity;
  SetSensitivity(1,&sensitivity_req1);
  double sensitivity_req2=_sensitivity;
  SetSensitivity(2,&sensitivity_req2);
  if (sensitivity_req1!=_sensitivity || sensitivity_req2!=_sensitivity)
    throw ADC_exception("requested sensitivity could not be set");
  sensitivity=_sensitivity;
  fprintf(stderr,"set sensitivity to %g\n",sensitivity);

  /* set input coupling to DC */
  if (0!=SetCoupling(Ch1, ctDC) || 0!=SetCoupling(Ch2, ctDC))
    throw ADC_exception("could not set coupling to dc");

  /* what to measure */
  if (E_NO_ERRORS!=SetMeasureMode(mmCh12))   /* Channel 1 and 2 */
    throw ADC_exception("could not set measurement mode");
  /* the trigger source */
  if (E_NO_ERRORS!=SetTriggerSource(tsExternal)) /* external trigger */
    throw ADC_exception("could not set trigger source");
  /* which slope to trigger */
  if (E_NO_ERRORS!=SetTriggerMode(tmRising))   /* 0=Rising slope */
    throw ADC_exception("could not set trigger source");
  /* set transfer mode */
  if (E_NO_ERRORS!=SetTransferMode(tmBlock))
    throw ADC_exception("could not set transfer mode");

  /* finally start the measurement */
  if (0!=ADC_Start())
    throw ADC_exception("could not start triggered adc measurement");
   fprintf(stderr,"started triggered adc measurement with %d samples, rate=%g, sensitivity=%g, resolution=%d\n",samples,rate,sensitivity,resolution);
}