Hello guys,
I have to generate a sinus of 50Hz and a variable amplitude. I succeded with the rp_GenAmp function, but I would like to be able to change the amplitude each semi-period, which I understand it's not possible with the rp_GenAmp which generates a period for each amplitude I enter. Is there any other way to do this? Also, which is the minimum ampltude I can generate? I would like to generate 1mV, is that possible?
I saw a strange behaviour on the osciloscope, the first period it has just the negative semi-period generated, any ideas why this is happening?
Thank you for your help
Sinus generation
-
- Posts: 1441
- Joined: Sat Jun 07, 2014 12:49 pm
- Location: Königswinter
Re: Sinus generation
Hi,
One problem with this is that the processor clock is not synchronized with the DAC clock, so in the long run you will loose sync. You could remedy that by restarting the generator every so often.
Regarding the minimum amplitude, I believe the full scale voltage of the RF outputs is 1.8Vpp (I may be misremembering it, best check for yourself), so the minimum voltage resolution is 3.6V / 2^14 = 0.22mV.
At your target frequency of 50Hz, you could change the amplitude on the fly. A new amplitude setting becomes active instantaneously, so just observe the time since starting the generator and set a new amplitude when a zero-crossing is due.[...]I would like to be able to change the amplitude each semi-period, which I understand it's not possible with the rp_GenAmp [...]
One problem with this is that the processor clock is not synchronized with the DAC clock, so in the long run you will loose sync. You could remedy that by restarting the generator every so often.
Regarding the minimum amplitude, I believe the full scale voltage of the RF outputs is 1.8Vpp (I may be misremembering it, best check for yourself), so the minimum voltage resolution is 3.6V / 2^14 = 0.22mV.
-
- Posts: 8
- Joined: Fri Apr 03, 2015 3:45 pm
Re: Sinus generation
Hello Nils,
I am having a hard time understanding what it the relation between the buffer size and the frequency, so my sinus is a not really a sinus(see attachement).
I am using 2 LUT, ont positive and one negative. Here is the code :
I am having a hard time understanding what it the relation between the buffer size and the frequency, so my sinus is a not really a sinus(see attachement).
I am using 2 LUT, ont positive and one negative. Here is the code :
Code: Select all
#define F_GEN_SIN_Hz 50/*The signal generated frequency*/
#define BUFF_SIZE 8192/*the lentgh of the LUTs*/
struct ampProp{
float Amplitude;//1.0 for this example
int Repetition;// 50000
};
int main(int argc, char **argv){
float *x = (float *)malloc(BUFF_SIZE * sizeof(float));
float *y = (float *)malloc(BUFF_SIZE * sizeof(float));
int i,j;
int k=0;
rp_GenWaveform(RP_CH_1, RP_WAVEFORM_ARBITRARY); ///< The choice of the WaveForm
rp_GenOutEnable(RP_CH_1);///< Activates the Channel 1
rp_GenAmp(RP_CH_1, 0.0);///< Puts the amplitude of the first Waveform generated at 0, the RedPitaya is generating an aleatory peak at the beginning
//rp_GenOffset(RP_CH_2,0.06);///< The circuit has an offset of 0.06V
rp_DpinSetState(RP_LED2,RP_HIGH);///< Puts the second LED at 1
rp_GenFreq(RP_CH_1,F_GEN_SIN_Hz); ///< Generates the frequency at which the signal will be generated
/*generates a LUT for the positive halfwave (lut_p) and a LUT for the negative halfwave (lut_n)*/
for (int i = 0; i < BUFF_SIZE+1; i++){
x[i] = sin((i*M_PI) / BUFF_SIZE);
y[i] =-sin(( i*M_PI) / BUFF_SIZE);
}
/*Takes every line from the file*/
for (i=0;i<line;i++)
{
rp_GenAmp(RP_CH_1, A[i].Amplitude);
for (j=0;j<A[i].Repetition;j++)
{
/*Generates (repetition x amplitude) for every line of the file */
if (k==0)
{ /*positive half-waveform*/
k=1;
rp_GenArbWaveform(RP_CH_1,x,BUFF_SIZE);
}
else
{ /*negative half-waveform*/
k=0;
rp_GenArbWaveform(RP_CH_1,y,BUFF_SIZE);
}
}
}
You do not have the required permissions to view the files attached to this post.
-
- Posts: 1441
- Joined: Sat Jun 07, 2014 12:49 pm
- Location: Königswinter
Re: Sinus generation
Hi,
Since I do not have access to the sourcecode of the API, I can only make an educated guess:
I would assume that the rp_GenArbWaveform() function does not block until the waveform is actually written to the output. It probably just transforms the input data into DAC-able format and copies it to the AWG buffer, and then returns. The next call will then overwrite the buffer while it is being fed to the DAC, instead of when the halfwave is fully out. This leads to the jumps you can observe in the scope picture.
I still think you should try to just change the amplitude of a running sine wave in timed intervals.
Since I do not have access to the sourcecode of the API, I can only make an educated guess:
I would assume that the rp_GenArbWaveform() function does not block until the waveform is actually written to the output. It probably just transforms the input data into DAC-able format and copies it to the AWG buffer, and then returns. The next call will then overwrite the buffer while it is being fed to the DAC, instead of when the halfwave is fully out. This leads to the jumps you can observe in the scope picture.
I still think you should try to just change the amplitude of a running sine wave in timed intervals.
-
- Posts: 8
- Joined: Fri Apr 03, 2015 3:45 pm
Re: Sinus generation
I've decided to change the amplitude when a zero-crossing was due, as you suggested, and it works perfectly. Thank you for the support!
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 98 guests