acquire_trigger_software.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_InitReset(false) != RP_OK){
  10. fprintf(stderr, "Rp api init failed!\n");
  11. }
  12. /*LOOB BACK FROM OUTPUT 2 - ONLY FOR TESTING*/
  13. rp_EnableDebugReg();
  14. rp_GenReset();
  15. rp_GenFreq(RP_CH_1, 1000.0);
  16. rp_GenAmp(RP_CH_1, 1.0);
  17. rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
  18. rp_GenOutEnable(RP_CH_1);
  19. rp_GenTriggerOnly(RP_CH_1);
  20. uint32_t buff_size = 20;
  21. float *buff = (float *)malloc(buff_size * sizeof(float));
  22. rp_AcqReset();
  23. rp_AcqSetDecimation(RP_DEC_1024);
  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. int z = 5;
  30. while(z){
  31. uint32_t c;
  32. rp_AcqGetPreTriggerCounter(&c);
  33. sleep(1);
  34. z--;
  35. printf("Pre counter %d\n",c);
  36. }
  37. sleep(1);
  38. rp_AcqSetTriggerSrc(RP_TRIG_SRC_NOW);
  39. rp_acq_trig_state_t state = RP_TRIG_STATE_TRIGGERED;
  40. while(1){
  41. rp_AcqGetTriggerState(&state);
  42. if(state == RP_TRIG_STATE_TRIGGERED){
  43. sleep(1);
  44. break;
  45. }
  46. }
  47. bool fillState = false;
  48. while(!fillState){
  49. rp_AcqGetBufferFillState(&fillState);
  50. }
  51. rp_AcqStop();
  52. rp_AcqGetOldestDataV(RP_CH_1, &buff_size, buff);
  53. int i;
  54. for(i = 0; i < buff_size; i++){
  55. printf("%f\n", buff[i]);
  56. }
  57. /* Releasing resources */
  58. free(buff);
  59. rp_Release();
  60. return 0;
  61. }