Dear all, I am interfacing 16-bit ADC(parallel) to TMS320vc33 DSP, and need to perform floating point operations on the received data. My doubts are: 1. Do I need to convert the ADC o/p to a DSP floating point format before doing my computations. Can i get any sample programs for this particular processor. I am new to this processor, and help needed desperately. regards, Bhaktavatsala |
|
How to give floating point data to DSP
Started by ●May 22, 2004
Reply by ●May 23, 20042004-05-23
Hello Bhaktavatsala No problem for signed 2's compliment, signed magnitude or simple binary converters. But, you do need to convert to a 2's compliment value before converting to floating point. Therefor if you connect to the lower bits (say D0-D15) you will need to make sure the sign bit is handled properly. For 2's compliment you might do the following LDI @extern,Rx ; load to a register (upper bits are junk) LSH 16,Rx ; extend to top (+/- 2^15 range) ASH -16,Rx ; sign extend down (+/-2^15 range) FLOAT Rx,Rx ; convert to float with +/-2^15 range For a binary converter (that is, unsigned) you need to mask the upper bits LDI @extern,Rx ; load to a register (upper bits are junk) AND 0FFFFh,Rx ; Only bottom bits, 0 to 2^16 range FLOAT Rx,Rx ; convert to a float with 2^16 range But if you sit back and think a moment, D31-D16 might be a better choice. Why, because the top bit is already in the signed position so all you need to do is shift down. For 2's compliment you might do the following. This basically sign extends as the bottom LSB's are shifted out. LDI @extern,Rx ; load to a register (+/- 2^31 range, plus LSB's as junk) ASH -16,Rx ; sign extend down (+/-2^15 range) FLOAT Rx,Rx ; convert to float with +/-2^15 range A binary (unsigned) converter is similar, but this time a logical shift is used. LDI @extern,Rx ; load to a register (top bit is NOT sign bit, plus LSB's as junk) LSH -16,Rx ; Only bottom 16 bits, 0 to 2^16 range FLOAT Rx,Rx ; convert to a float with 2^16 range OK, say I need to convert several values from a FIFO. Can this be improved? LDI -16,Ry ; shift value will be register mode LDI 15,RC ; convert 16 values from a fifo RPTB CONVERT ; ASH @EXTERN,Ry,Rx ; shift to +/- 2^15 range FLOAT Rx,Rx ; convert to float CONVERT STF Rx,*AR0++ ; save result But this is still not the only, or even best way. Furthermore, it is also not likely that you want to deal with values that are scaled by +/- 2^15. So why not scale to the desired range as the values are read in? LDI 15,RC ; convert 16 values from a fifo RPTB CONVERT ; FLOAT @EXTERN,Rx ; convet directly to +/- 2^31 range float MPYF @INSCALE,Rx ; convert to desired range CONVERT STF Rx,*AR0++ ; save result The only undesirable aspect to this is that the free floating LSB's have now become signal noise, and this may or may not be OK. And in C, the last example (convert 32b to float) might look something like this. You may also notice the use of 'volatile'. This is needed to tell the optimizer that it should not read the inport one time and then copy that first value to *dest++ sixteen times. void Long32toFloat(volatile long *INPORT, float *dest) { for(x=0;x<16;x++) { *dest++ = *INPORT; } } void Short16toFloat(volatile long *INPORT, float *dest) { for(x=0;x<16;x++) { *dest++ = (*INPORT<<16)>>16); } } Hope this helps, Keith Larson DSP and Analog Consulting http://home.comcast.net/~klarsondsp Note: Rather than using 'Logical Shift', in my own head, I like to use 'Left Shift' for the LSH instruction since positive shift values are for left shifts :-) sbhaktavatsala wrote: Dear all, |