Sinus generation

Applications, development tools, FPGA, C, WEB
Post Reply
adina
Posts: 8
Joined: Fri Apr 03, 2015 3:45 pm

Sinus generation

Post by adina » Wed Apr 15, 2015 11:07 am

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

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Sinus generation

Post by Nils Roos » Wed Apr 15, 2015 10:31 pm

Hi,
[...]I would like to be able to change the amplitude each semi-period, which I understand it's not possible with the rp_GenAmp [...]
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.

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.

adina
Posts: 8
Joined: Fri Apr 03, 2015 3:45 pm

Re: Sinus generation

Post by adina » Tue Apr 28, 2015 4:51 pm

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 :

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.

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Sinus generation

Post by Nils Roos » Wed Apr 29, 2015 1:41 am

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.

adina
Posts: 8
Joined: Fri Apr 03, 2015 3:45 pm

Re: Sinus generation

Post by adina » Wed Apr 29, 2015 2:24 pm

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!

Post Reply
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 99 guests