Other Parts Discussed in Thread: DIR9001
Tool/software: Code Composer Studio
hello,I want to generate a sin wave by PCM1744,but how can I generate a Variable frequency sin wave?Can you help me?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi Chu Zhuo,
None of our audio DACs have a built-in tone generator, they all require that the digital signal be applied externally. This means that you will need to have some I2S source that can generate a sine wave. This could be something like an audio DSP, an S/PDIF to I2S converter (DIR9001), or a USB to I2S bridge. Then you can use a PC with a USB or SPDIF output to play the tone.
Thanks,
Paul
I want to sweep frequency from 100Hz to 1000Hz,step is 0.1Hz. but I can not make this come true.I do not konw the reason that it is in fact due to the samplerate only 96KHz.
the program generate the sin rom data as fllow:
double t=0.0;
double f=200.5;
u16 i=0;
u16 DA_SampleNum=0;
u32 SampleRate=96000;
u32 SIN_BASE_BUF[4096];
DA_SampleNum=SampleRate*1.0/f;
i=0;
while(i<DA_SampleNum)
{
t=(double)i/SampleRate;
SIN_BASE_BUF[i]=16777215/2.0*(arm_sin_f32(2.0*PI*f*t)+1.0);
i++;
}
Hi Paul,
I want to sweep frequency from 100Hz to 1000Hz,step is 0.1Hz. but I can not make this come true.I do not konw the reason that it is in fact due to the samplerate only 96KHz.
the program generate the sin rom data as fllow:
double t=0.0;
double f=200.5;
u16 i=0;
u16 DA_SampleNum=0;
u32 SampleRate=96000;
u32 SIN_BASE_BUF[4096];
DA_SampleNum=SampleRate*1.0/f;
i=0;
while(i<DA_SampleNum)
{
t=(double)i/SampleRate;
SIN_BASE_BUF[i]=16777215/2.0*(arm_sin_f32(2.0*PI*f*t)+1.0);
i++;
}
Hi,
I think you have two main options:
1. You could dynamically create SIN_BASE_BUF for other rates,
2. You could create a very large SIN_BASE_BUF with many points, and then make your firmware increment through the array at different intervals. For example, create a BUF with 96000 points representing a single sinewave period. Then, if you want a 1000kHz sine wave, at a 96ksps rate, then you increment that array at 1000 code increments. If you want a 100Hz sine wave, then you increment at 100kHz increments.
Thanks,
Paul
Hi,Paul
I can not understand your example.I want to sweep frequency from 100Hz to 1000Hz.step is 0.1Hz by PCM1744.The PCM1744 maxmium samplerate is 96ksps.
For example,Create a f=100Hz sinewave,at 96ksps rate,LRCIN is fs=96kHz,so need fs/f=96000/100=960 points;
Create a f=100.1Hz sinewave,at 96ksps rate,LRCIN is fs=96kHz,so need fs/f=96000/100.1=959.04,in round numbers 959 points;
Create a f=100.2Hz sinewave,at 96ksps rate,LRCIN is fs=96kHz,so need fs/f=96000/100.2=958.08,in round numbers 958 points,and so on.
But Create f=1000Hz sinewave,at 96ksps rate,LRCIN is fs=96kHz,so need fs/f=96000/1000=96 points ;
Create a f=999.9Hz sinewave,at 96ksps rate,LRCIN is fs=96kHz,so need fs/f=96000/999.9=96.009,in round numbers 96 points;
Create a f=999.8Hz sinewave,at 96ksps rate,LRCIN is fs=96kHz,so need fs/f=96000/999.8=96.019,in round numbers 96 points;
Create a f=998Hz sinewave,at 96ksps rate,LRCIN is fs=96kHz,so need fs/f=96000/998=96.192,in round numbers 96 points;
Create a f=990Hz sinewave,at 96ksps rate,LRCIN is fs=96kHz,so need fs/f=96000/990=96.969,in round numbers 96 points,and so on.
Due to the constant samplerate,the time intervals that send DA data is constant.Control sinewave frequency only by the number points.but the number points can not do this.
This will be a difficult problem to solve unless your microprocessor can calculate the sine value as the data is transmitted. If that were the case, you could just have it calculate the new value on each individual sample.
Consider this: create a very large array of output codes for 1 period of a sine wave, for example, 96,000 points. (96k samples/period)
Consider if you used every sample in the array at 96k samples/second, then you have 1 period every second, or 1Hz.
If you skip every other code in the array, then you have 48k samples/period and played at 96k samples/second you have 2Hz.
If you play every 100th code, then you have 100kHz. If you skip 100.1 codes then you have 100.1Hz, etc.
Now you will have some distortion as there is a finite amount of resolution built into the array, but you could reduce that by using an even larger array, 9,600,000. You do not need to use an array that is a multiple of 96k, but it does make the math easier.
Thanks,
Paul