Forum Discussion
Altera_Forum
Honored Contributor
14 years agoYes, the audio codec returns a 16bit signed 2s complement sample which I am sending to the Nios system to be printed over JTAG UART (after squaring it).
Input signal: 2.4 Vpp, 500Hz, sine wave Using volatile char *:
audR: 1 audL: -126 audL2: 4
audR: 2 audL: 94 audL2: -124
audR: 1 audL: 110 audL2: 68
audR: 1 audL: 11 audL2: 121
audR: -3 audL: 8 audL2: 64
audR: 2 audL: 7 audL2: 49
audR: -1 audL: -3 audL2: 9
audR: 0 audL: 12 audL2: -112
Using volatile short * (obviously wrong results for audL2 since it is 32 bits but even audL is very different from char results):
audR: 0 audL: 12949 audL2: -30023
audR: 1 audL: 956 audL2: -3568
audR: 1 audL: -12180 audL2: -21104
audR: -3 audL: 5486 audL2: 15172
audR: 0 audL: 11626 audL2: 28644
audR: 2 audL: -6731 audL2: 20985
Using #define USB_Ctrl (volatile char *) 0x00005000
# define Data_in_1 (volatile alt_16 *) 0x00005010 // right channel samples
# define Data_in_2 (volatile alt_16 *) 0x00005020 // left channel samples
# define Data_in_3 (volatile alt_32 *) 0x00005030 // left channel samples squared
# define Data_in_4 (volatile alt_32 *) 0x00005040 // filter results
audR: -2 audL: 165 audL2: 27225 filt: 26076439
audR: -1 audL: 10419 audL2: 108555561 filt: 146741412
audR: -2 audL: -1139 audL2: 1297321 filt: 16184391
audR: -2 audL: 1243 audL2: 1545049 filt: 36079690
Removes the negative results problem, but I don't know how to make sense of this sample data now. how do i properly convert these sample values to a real voltage? Since I'm using 16bits, the ADC has a resolution of -32768 to +32767. The step size would be Q = (3.6 - 1.8 V)/2^16 = 0.0000275 V = 0.0275 mV (I'm a little unsure of the input voltage range for WM8731, the datasheet says the analog supply range is 1.8-3.6V). Is this correct?