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.

TMS320F280049C: Sample frequency calculation for sine wave generation using LUT?

Part Number: TMS320F280049C
Other Parts Discussed in Thread: C2000WARE

I have generated a sine wave using LUT.
1) initialized phase to -pi

2)incremented phase in steps of 0.1*pi till phase = 1*pi

3)find the sine of the phase using LUT and stored it in an array (total 21 values in the array)

4)load the values in the array to DACVALS reg (DAC_setShadowValue(DACA_BASE, dacval)) and observed the sine wave on picoscope 6

  set device_delay_us(2) after setting the shadow value

I've observed 15.067KHz sine wave.



From this I've calculated sampling frequency as Fs=(15067)*21=316400

Now, I 've generated a sine wave of desired frequency as follows:
a) f=3000 (3 KHz), Fs=316400
b) no of samples n = round(Fs/f)
c) stepPhase = (2.0/n)*pi
d) followed steps 1 to 4 with stepPhase obtained in the above step

Now I"ve observed 2.995KHz sine wave when I set f=3KHz
9.887KHz sine wave when f=10KHz
4.07KHz sine wave when f=4KHz



Q1) Does my sample frequency calculation approach make sense?
Q2) Is there a reason why the exact frequency is not observed? and how to get it?
Q3) when i removed the device delay of 2us after setting the shadow value, the frequency of the observed sine wave changed drastically. What is the reason for that?
 

  • Hello,

    Thank you for your patience.

    I'll work on your questions and get back to you quickly.

    Regards,

    Hadi

  • Hello, 

    I appreciate you giving me the time to work on this.

    Regarding your method, generally it is not recommended to use software delay to read the values from the buffered DAC. It's better to time-based cpu interrupt or use EPWM trigger to load the sine values from the array to the the buffered DAC.

    Also, I'm not sure if you are reading the values from Flash or RAM. If you are using Flash, the wait state can contribute to the error in your frequency measurement.

    As far as the frequency is concerned, using an external crystal can improve the accuracy of measurement since the frequency of the internal oscillator has ±3 % tolerance. 

    Regards,

    Hadi

  • Loading the sine waves from the array to the buffered DAC using the timer interrupt reduced the %error but the exact frequency of the sine waves is still not achieved in some cases

  • Hello Ram,

    Thanks for updating me .

    Please let me know if : 1) you are using the internal oscillator or external crystal. 2) you are reading the values from Flash or RAM.

    Regards,

    Hadi

  • Hello Hadi,

    1) Configured cpu timer using DEVICE_SYSCLK_FREQ = ((DEVICE_OSCSRC_FREQ * 10 * 1) / 2)  ; DEVICE_OSCSRC_FREQ = 20MHz XTAL

    2)  I am reading the values from RAM

  • Hello Ram,

    Thanks for your patience. I'm working with other colleagues on this issue.

    Regards,

    Hadi

  • Hi Ram,

    Sorry about the delay. Still looking into this and wanted to give you an update. 

    We have a dac sine wave example in C2000Ware for the F28004x device (C2000Ware_version\driverlib\f28004x\examples\dac\buffdac_ex3_sine). 

    This example generates a sine wave on the buffered DAC output, DACOUTA/ADCINA0 (HSEC Pin 9) and uses the default DAC reference setting of VDAC.

    There is another example using DMA (to reduce CPU load in sine wave generation) to transfer sine values stored in a sine table in GSRAM to DACVALS,

    DACOUTA/ADCINA0. Please refer examples from F2837xd at
    <C2000Ware>\device_support\f2837xd\examples\cpu1\buffdac_sine_dma (Uses DMA)

    This should work with minor modifications for the F28004x device.

    Can you give that a try and let us know?

    Thanks,

    Hadi