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.

TIDSKC6713 Generating Square Waveform variable frequency 40kHz (Problem)

Hi all
I am trying to generate a square wave on TIDSKC6713 (CCS) by modifying a code from Chassaing book (chapter 2). I want to generate the square wave with variable frequency fo upto 40kHz (by using 96kHz sampling frequency). I am using a buffer of 128 values with half for positive and half for negative amplitudes. I have used two slider GEL; one for variable gain and other for variable frequency. With gain I could get from 50mVpp to 2.8Vpp which seems OK to me but with frequency from 750Hz to 8kHz the output is square (with some ripples) but above that the output is not square any more and starts modifying itself to the shape of sinusoidal waveform.
I have copied the modified code. It would be much appreciated if some one could help me in this regard please.....
Many Thanks

#include "dsk6713_aic23.h" //codec-DSK interface support
Uint32 fs=DSK6713_AIC23_FREQ_96KHZ;                                  //set sampling rate

#define table_size (int)0x80                                                   //size of table=128
short data_table[table_size];                                                   //data table array
int i,k;
int amplitude = 0x7fff;
short gain = 1;
int frequency = 1;
interrupt void c_int11()                                        //interrupt service routine
{

output_sample(data_table[i] / gain);                                                 //output value each Ts

i += frequency;
i = i % table_size;                                                                          //reinitialize counter
return;                                                                  //return from interrupt
}

main()
{
for(i=0; i<table_size/2; i++)                                                   //set 1st half of buffer
data_table[i] = amplitude;                                                 //with max value (2^15)-1
for(i=table_size/2; i<table_size; i++)                                       //set 2nd half of buffer
data_table[i] = -(amplitude + 1);                                                             //with -(2^15)

i = 0;                                                                                    //reinit counter
comm_intr();                                                          //init DSK, codec, McBSP

while (1)

}

  • I do not have schematics for the DSKC6713, but I did find some for the DSKC6711 which is slightly different but the same philosophy.

    There are RC filter components on the DAC outputs to the speakers. I suspect the same is true for your DSK, too.

    If this is the case, you may need to modify your DSK to remove those components (this will invalidate the warranty, if any, on the board) or find another way to implement a DAC function such as by using the expansion connectors and an add-on DAC card.

  • @ RandiP

    Thaks for the help. Yes there is a RC filter at the output of DSK. But if I put 40kHz sinewave at the input and then route it to output using DSP with 0dB gain, I can see the 40kHz sine wave at the output without any distortion, but with square wave I can't see any thing above 8kHz....... Any particular reasons that I can't understand!

     

     

  • As shown in the schematics that Mariana references, there are different RC filter components for the Headphone outputs and for the Line Out outputs. Do you see a different waveform shape if you use the different outputs?

    How high of a square wave can you display on the Headphone output?

    How high of a square wave can you display on the Line Out output?

  • Hi Naeem,

    The (digital) low pass reconstruction filter, i.e. the DAC, in the AIC23 codec cuts off sharply at fs/2 (where fs is the sampling frequency that you are using in your program - 96kHz).

    Think of the Fourier series representation of a square wave of frequency f0 - it comprises harmonic components at the fundamental frequency, f0 and at 3*f0, 5*f0, 7*f0, ...

    Any harmonic components above fs/2 will not appear in your analogue output signal.

    To give a few numerical examples.

    If f0 is 1kHz and fs is 96kHz then the first twenty four harmonic components at 1kHz, 3kHz, 5kHz, 7kHz, ... , 47kHz will appear in your analogue output signal, yielding a fair approximation to a square waveform. The ripples that you refer to are related to Gibb's phenomenon.

    If f0 is 8kHz and fs is 96kHz then only the first three harmonic components at 8kHz, 24kHz, and 40kHz will appear in your analogue output signal, yielding a not very square waveform.

    If f0 is 16kHz and fs is 96kHz then only the first  harmonic component at 16kHz will appear in your analogue output signal, yielding a 16kHz sinewave.*

    The  RC network between the AIC23 line output and the jack socket primarily provides ac coupling, i.e. a high pass effect.  

    Pages 76 and 77 of the second edition of the book describe these effects and have some pictures.

    An audio codec is not going to generate a very sharp-edged square wave.

    Hope this helps,

    Donald

    * The AIC23 reconstruction filter is only approximately 6dB down at fs/2 and so in this case you might see some of the harmonic component at 48kHz in your output signal.

  • Hi Naeem,

    Another way of thinking about this - you say that you'd like to generate square waves with frequencies of up to 40kHz - is that if your sampling frequency is 96kHz then a sample sequence 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, ... might perhaps be thought of as representing a 24kHz 'square wave'. Leaving aside that in the context of DSP 'square wave' is a rather misleading concept, if you wanted to generate a 40kHz 'square wave' what sequence of samples (at fs = 96kHz) would represent that waveform?

    Perhaps 1, 1, -1, 1, -1, 1, -1, -1, ...

    It's hard to see how that sequence could be expected to drive a DAC to generate an analogue square wave.

    What I'm getting at is that even if your DAC was effectively a zero-order-hold (a low-performance LPF) and you were relying on its circuitry to supply the sharp edges of a square wave, at a fixed sample rate of 96kHz you'd be restricted to generating square waves* with frequencies at 96kHz/(2*n), where n is an integer. Only 48kHz, 24kHz, 16kHz, 12kHz, 9600Hz frequencies possible above 8kHz.

    Regards,

    Donald

    * 1:1 mark space ratio

  • @ Donald

    Thanks very much for your help as I was very confused with the concept that output filter wont allow the higher frequency square wave to pass through because as per schematic it is a high pass output filter. But as you mentioned  it is the input low pass filter at DAC that cuts off at fs/2.

    But is there any way to bypass this codec and use any of those external peripheral connectors on DSK that give access directly to one of the DSP I/O pin where I could send high voltage (1) and low (0) at a fixed frequency to generate a square wave?

  • If you go to the Spectrum Digital website that Mariana pointed you to above, you will find the TMS320C6713 DSK Technical Reference which describes the signals on the expansion connectors. These include TOUT0 and TOUT1, the outputs from the two timers. You can use the timers to generate a digital square wave.