acquire_trigger_posedge.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Red Pitaya C API example Acquiring a signal from a buffer
  2. * This application acquires a signal on a specific channel */
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include "rp.h"
  7. int main(int argc, char **argv){
  8. /* Print error, if rp_Init() function failed */
  9. if(rp_Init() != RP_OK){
  10. fprintf(stderr, "Rp api init failed!\n");
  11. }
  12. /*LOOB BACK FROM OUTPUT 2 - ONLY FOR TESTING*/
  13. rp_GenReset();
  14. rp_GenFreq(RP_CH_1, 20000.0);
  15. rp_GenAmp(RP_CH_1, 1.0);
  16. rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
  17. rp_GenOutEnable(RP_CH_1);
  18. rp_GenTriggerOnly(RP_CH_1);
  19. uint32_t buff_size = 16384;
  20. float *buff = (float *)malloc(buff_size * sizeof(float));
  21. rp_AcqReset();
  22. rp_AcqSetDecimation(RP_DEC_8);
  23. rp_AcqSetTriggerLevel(RP_CH_1, 0.1);
  24. rp_AcqSetTriggerDelay(0);
  25. rp_AcqStart();
  26. /* After acquisition is started some time delay is needed in order to acquire fresh samples in to buffer*/
  27. /* Here we have used time delay of one second but you can calculate exact value taking in to account buffer*/
  28. /*length and smaling rate*/
  29. sleep(1);
  30. rp_AcqSetTriggerSrc(RP_TRIG_SRC_CHA_PE);
  31. rp_acq_trig_state_t state = RP_TRIG_STATE_TRIGGERED;
  32. while(1){
  33. rp_AcqGetTriggerState(&state);
  34. if(state == RP_TRIG_STATE_TRIGGERED){
  35. break;
  36. }
  37. }
  38. bool fillState = false;
  39. while(!fillState){
  40. rp_AcqGetBufferFillState(&fillState);
  41. }
  42. rp_AcqGetOldestDataV(RP_CH_1, &buff_size, buff);
  43. int i;
  44. for(i = 0; i < buff_size; i++){
  45. printf("%f\n", buff[i]);
  46. }
  47. /* Releasing resources */
  48. free(buff);
  49. rp_Release();
  50. return 0;
  51. }