Hello everyone.
I'm new to red pitaya. I got mine this week. I already start using it, doing the basic stuff from the C/C++ tutorials, but I need some help in order to do a project.
I will describe what I need and if someone could steer me in the right direction, I would appreciate.
I need to generate and acquire a sine wave.
The sine wave (80 kHz) should be generated for 10 ms, and after 1 s, generated again for 10 ms, and so on. This wave is generated periodically as long as a button is ON. Button OFF, no sine wave.
I also need to start acquiring samples from both ADC for 15-20 ms, when the sine wave starts being generated.
I need 125 MS/s sampling frequency.
My data (15-20 ms) should be saved in a file (.csv) for post processing. Each set of data (15-20 ms) should provide a new csv file.
Can anyone help me?
Thanks
High speed periodic wave generation and acquisition
-
- Posts: 4
- Joined: Fri Jun 05, 2015 10:32 am
-
- Posts: 55
- Joined: Tue Jun 24, 2014 3:06 pm
- Location: Dourdan (France)
Re: High speed periodic wave generation and acquisition
Hello,
I think you can use the generate.c file to do what you want. But, I don't know if you can generate so much data. Because, with this sample rate, you can generate 2^14 data and it means a 131µs length signal (if I'm right of course).
In my opinion, the buffer used by this function is too small to contain this length, so to perform it, you should decrease the sample rate.
For the acquisition, it's the same problem and you can use the acquire.c file to help you. You will have a buffer problem. If you want to save your data, you can create a file easily in C or C++ where you can save all of them.
For the timing, you can use the libraries "time.h" but the accuracy is not optimal ^^. Otherwise, it's a simple way to make timing operation (with wait function).
If you have others question or if you need more information, I'll try to help you more.
Kev
I think you can use the generate.c file to do what you want. But, I don't know if you can generate so much data. Because, with this sample rate, you can generate 2^14 data and it means a 131µs length signal (if I'm right of course).
In my opinion, the buffer used by this function is too small to contain this length, so to perform it, you should decrease the sample rate.
For the acquisition, it's the same problem and you can use the acquire.c file to help you. You will have a buffer problem. If you want to save your data, you can create a file easily in C or C++ where you can save all of them.
For the timing, you can use the libraries "time.h" but the accuracy is not optimal ^^. Otherwise, it's a simple way to make timing operation (with wait function).
If you have others question or if you need more information, I'll try to help you more.
Kev
-
- Posts: 4
- Joined: Fri Jun 05, 2015 10:32 am
Re: High speed periodic wave generation and acquisition
Hello Kev.
Thanks for your inputs.
Let's start small..
First let's try signal generation.
Is is possible to generate for example, 100 sine waves at a given frequency (80 kHz), and create a loop that will generate this 100 waveform every second?
I already started using burst and a tickcounter incremented at each execution cycle. This tickcounter is incremented inside the while (1) loop. So, every time tickcounter value is 2000000, equivalent to 1 second, I try to generate 100 sine waves. I get some waveform, but it seems something is wrong, the waveform is not a complete sine and it seems I don't have 100 waveform.
This is how I'm trying to do it:
Regards
Thanks for your inputs.
Let's start small..
First let's try signal generation.
Is is possible to generate for example, 100 sine waves at a given frequency (80 kHz), and create a loop that will generate this 100 waveform every second?
I already started using burst and a tickcounter incremented at each execution cycle. This tickcounter is incremented inside the while (1) loop. So, every time tickcounter value is 2000000, equivalent to 1 second, I try to generate 100 sine waves. I get some waveform, but it seems something is wrong, the waveform is not a complete sine and it seems I don't have 100 waveform.
This is how I'm trying to do it:
Code: Select all
while (1){
if (tickcounter==2000000)
{
rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
rp_GenAmp(RP_CH_1, 1);
rp_GenFreq(RP_CH_1, 80000);
rp_GenBurstCount(RP_CH_1, 100);
rp_GenBurstRepetitions(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_INTERNAL);
tickcounter=0;
}
tickcounter++;
}
-
- Posts: 4
- Joined: Fri Jun 05, 2015 10:32 am
Re: High speed periodic wave generation and acquisition
Hi.
Thanks to Kev inputs, I decided to change some things in my requirements.
I'm now trying to generate 1 ms of a 80 kHz sine wave, acquire this sine wave (16k samples at decimation 8) in adc ch1 and other wave on ch2.
After, save acquisition to file. Repeat the process after 100 ms.
I'm using the SDK.
The generate part, I think it's working properly, but the acquire not.
I'm starting the acquire module before activating the ch1 output in order to acquire some samples before the beginning of the wave.
My problem is that sometimes, the first samples are already of the wave, other times, the wave starts a couple of ns after (like I wanted to), other times I only get data till half the buffer (around 8k samples)...
It doesn't behave in a consistent manner.
I'm posting my code.
Can someone help me?
Regards
Thanks to Kev inputs, I decided to change some things in my requirements.
I'm now trying to generate 1 ms of a 80 kHz sine wave, acquire this sine wave (16k samples at decimation 8) in adc ch1 and other wave on ch2.
After, save acquisition to file. Repeat the process after 100 ms.
I'm using the SDK.
The generate part, I think it's working properly, but the acquire not.
I'm starting the acquire module before activating the ch1 output in order to acquire some samples before the beginning of the wave.
My problem is that sometimes, the first samples are already of the wave, other times, the wave starts a couple of ns after (like I wanted to), other times I only get data till half the buffer (around 8k samples)...
It doesn't behave in a consistent manner.
I'm posting my code.
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "rp.h"
#define amplitude 1.5 // desired amplitude
#define frequency 80000 //desired frequency
#define idle 0
#define generate 1
#define acquire 2
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_GenReset();
rp_GenOutDisable(RP_CH_1);
rp_AcqReset();
uint32_t tickcounter=0;
uint32_t buff_size = 16*1024;
float *buff1 = (float *)malloc(buff_size * sizeof(float)); // buffer for channel 1
float *buff2 = (float *)malloc(buff_size * sizeof(float)); // buffer for channel 2
int i=0;
int save=0;
uint32_t time=0;
int z=0;
rp_AcqSetSamplingRate(RP_SMP_15_625M); // sampling rate, decimation 8
rp_AcqSetGain(RP_CH_1, RP_HIGH);
rp_AcqSetGain(RP_CH_2, RP_HIGH);
rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
int state=idle;
while(1){
switch (state) {
case idle:
if(save==1){
FILE *fp;
char filename[20];
sprintf(filename, "test%i.csv",z); // creation of a new file for each set of readings
fp = fopen(filename,"w");
if (fp == NULL)
{ printf("Couldn't open file\n");
exit(0);
}
fprintf(fp,"Reading,Time,CH1,CH2\n"); //File header
for (i=0;i < buff_size; i++)
{fprintf(fp,"%i,%i,%f,%f\n",i,time, buff1[i],buff2[i]); // save data in file
time=time+64; // increments time according with time decimation (decimation 8 - 64 ns)
}
fflush(fp);
fclose(fp);
z++; // increment cycle counter
save=0; //clear save flag
time=0;
}
if (tickcounter>=200000) //100 ms, change state
state=generate;
break;
case generate:
tickcounter=0;
rp_GenAmp(RP_CH_1, (amplitude/2.0)); // set amplitude
rp_GenFreq(RP_CH_1, frequency); //set frequency
rp_GenBurstCount(RP_CH_1, frequency*0.001); // set for the number of sine waves in 1 ms
rp_GenBurstRepetitions(RP_CH_1, 1); // 1 repetition (repetition rate is given by tickcounter)
rp_GenMode(RP_CH_1, RP_GEN_MODE_BURST); // set mode
rp_GenTriggerSource(RP_CH_1, RP_GEN_TRIG_SRC_INTERNAL); // set trigger
rp_AcqStart(); // start acquire
rp_AcqSetTriggerSrc(RP_TRIG_SRC_NOW); // set trigger immediately in order to get some samples before enable output
rp_GenOutEnable(RP_CH_1); // enable ch1 output
state=acquire;
break;
case acquire:
rp_AcqGetOldestDataV(RP_CH_1, &buff_size, buff1); // acquire data from ch1
rp_AcqGetOldestDataV(RP_CH_2, &buff_size, buff2); // acquire data from ch2
save=1; // activate save flag
state=idle;
break;
}
tickcounter++; // increment tickcounter
}
/* Release rp resources */
rp_Release();
free(buff1);
free(buff2);
return 0;
}
Regards
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 103 guests