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.

TMS320F28379D: signed 16-bit to un-signed 12-bit format

Part Number: TMS320F28379D


Hi all,

I want to convert a signed 16-bit to un-signed 12-bit format,

The real sinusoidal waveform varies between -200 and 200  [0,...,200,...,0,...,-200,...,0], this wave is stored in a signed 16-bit (int16)

I want to convert the 16 bits signed to 12bit un-signed format, the idea is to use the 12-bit DAC to output this waveform,

I found this code in the TI labs, this code does the same thing for a waveform  varies between -90 and 90  [0,...,90,...,0,...,-90,...,0].,

dacOutput = dacOffset + ((QuadratureTable[resultsIndex % 0x20] ^ 0x8000) >> 5);

int QuadratureTable[40] = {
		0x0000,		// [0]  0
		0x18F8,	        // [1]  11.25
		0x30FB,	        // [2]  22.50
		0x471C,	        // [3]  33.75
		0x5A81,	        // [4]  45.00
		0x6A6C,	        // [5]  56.25
		0x7640,	        // [6]  67.50
		0x7D89,	        // [7]  78.75
		0x7FFF,	        // [8]  90.00
		0x7D89,	        // [9]  78.75
		0x7640,	        // [10] 67.50
		0x6A6C,	        // [11] 56.25
		0x5A81,	        // [12] 45.00
		0x471C,	        // [13] 33.75
		0x30FB,	        // [14] 22.50
		0x18F8,	        // [15] 11.25
		0x0000,	        // [16] 0
		0xE708,	        // [17] -11.25
		0xCF05,	        // [18] -22.50
		0xB8E4,	        // [19] -33.75
		0xA57F,        	// [20] -45.00
		0x9594,	        // [21] -56.25
		0x89C0,	        // [22] -67.50
		0x8277,	        // [23] -78.75
		0x8000,        	// [24] -90.00
		0x8277,	        // [25] -78.75
		0x89C0,	        // [26] -67.50
		0x9594,	        // [27] -56.25
		0xA57F,	        // [28] -45.00
		0xB8E4,         // [29] -33.75
		0xCF05,	        // [30] -22.50
		0xE708,	        // [31] -11.25
		0x0000,		// [32] 0
		0x18F8,	        // [33] 11.25
		0x30FB,	        // [34] 22.50
		0x471C,	        // [35] 33.75
		0x5A81,	        // [36] 45.00
		0x6A6C,	        // [37] 56.25
		0x7640,	        // [38] 67.50
		0x7D89 	        // [39] 78.75
		};

Could someone explain to me the idea behind the shift, xor and mod operations in the first line of code?

How i could create my look up table "QuadratureTable" for  [0,...,200,...,0,...,-200,...,0], sinus waveform ? 

Best regards,

S.Tarik

  • S. Tarik,

    In the look-up table, the numbers in the comments column are the input angles in degrees and the hexadeximal numbers to the left are the corresponding sine values in signed Q15 format. The sine values vary between 0x0000 and 0x7FFF, or -1.0 and +0.99996948 in Q15 format. The table contains 1.25 quadrants of sine wave data in 40 points, so the first 32 points are a full quadrant. Now, the code:

    dacOffset + QuadratureTable[resultsIndex % 0x20] ^ 0x8000) >> 5

    ...wraps "resultsIndex" after 32 points (hence the modulo 0x20), XORs the MSB (to convert from signed to unsigned 16-bit format), then right-shifts the corresponding entry in "QuadratureTable" by 5 bits so the output is in unsigned Q10 format. "dacOffset" shifts the output to the middle of the DAC range. You could write this number directly to the 12-bit DAC on F28379D via the (right justified) DACVALA register.

    From your post, you say you want to represent a range of -200 to +200 in unsigned 12-bit format, which is not possible. You need to decide what numerical format to use and what voltage you want 200 to correspond to at the output of the DAC, then modify the line of code accordingly.

    I hope this helps. Feel free to post back if you're still unclear about this.

    Regards,

    Richard
  • Richard,

    I thank you for considering my request,

    It helps a lot,

    S.Tarik