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.
What would be the best approach create ADC to a DAC fuction?
An input span of 0 to 700 mv voltage curve, converted to a output of 0 to 2.5 volt linear span.
Basically, a look up table, that translates the 700 mv scale to a linear output of 2.5 volts, using 250 steps.
Yes. that's fastest (well better use 255 steps). Doing complex math at runtime isn't a good idea. The MSP is not a math genius. It can't even do simple divisions in hardware (and part of the family doesn't even have a hardware multiplier). The required floating point math would be a plain software solution (compiler-provided, but still software) and slooow.ken benkert said:Basically, a look up table, that translates the 700 mv scale to a linear output of 2.5 volts, using 250 steps.
Set up an excel sheet that does the calculation, export the results as CSV (one column output value, already truncated to output resolution) and paste it into a
const unsigned int mapping[256] ={
<paste here>
};
array. If done right (only 256 comma separated values) it directly compiles into your lookup table. You only need to right-shift the ADC value if you have more than 8 bit reading. Or e.g. if your input is 0..0.7V on 1.5V reference, then the maximum reading is 477 on ASC10 or 1911 on 12 bit ADC12. So you can shift it down by 1 or 3 bit (then index 238 matches 0.7V input) or use a larger table (more than 256 values)
On an MSP with ADC12 and DAC12 (e.g. the 1611), it could be as easy as
DAC12OUT0 = mapping[ADC12MEM0>>1];
each time a new conversion is done.
Jens-Michael Gross said:Set up an excel sheet that does the calculation, export the results as CSV (one column output value, already truncated to output resolution) and paste it into aconst unsigned int mapping[256] ={
<paste here>
};
You could even include the preamble & post-amble text in the spreadsheet - no need for pasting!
Attached is an example spreadsheet, and the result of Save As CSV, and the result of Save As Text
(the forum wouldn't allow me to attach a .csv file - so I renamed it to .csv.txt)
/* Lookup Table */ const unsigned int mapping[256] ={ 0 1 2 3 4 5 6 7 8 9 10 11 12 };
/* Lookup Table */, const unsigned int mapping[256] ={, ,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 };,
You don't mention what kind of error you can tolerate Ken. You want a gain of 3.57: that is, Vout = 3.57Vin. But suppose you can live with a gain of 3.5. That's a 2% gain error. Then you can calculate Vout as Vout = (4)*Vin) - (1/2)*Vin -- both multiplies being simple shifts, one left and one right. (Of course, some scaling will need to happen depending on the ADC and DAC resolutions you have). Not a look up table, but might get the job done for you without doing a lot of math, while saving you the table space.
To make the problem more clear:
The effort is to have possible non linear - low range of voltage input from a sensor. Error would be the number of steps.
That sensor is paced through its range of response, and data collected. Results - a manually generated as normalized and linear output. (Fixed scale)
Now that table is loaded back into the MSP and the sensor is now calibrated to a known scaled output.
As previous stated, no math required, and for a non-linear input, not possible to calulate for an MSP.
End reslut: A simple look up table for volt in - coresponding to - a voltage out.
Similar effort if one needed a digital out. But this effort is all analog.
Right. Pasting wasn't the correct word... You can #include the file right from the Excel export.Andy Neil said:You could even include the preamble & post-amble text in the spreadsheet - no need for pasting!
If you put the surrounding code into Excel too, it will screw the text up with superfluous commata, requiring additional manual corrections. Also, it's completely outside the C file then, so you'll have to take a look onto another source file when checking the code :)
back to the problem: received sensor metering from the calibration software can be captured on the PC into proper form and inserted into the Excel table, before outputting the new mapping table result. Been there, done that, worked.
Well, the calibration code, including the math, has now been moved into the MSP itself. And runs automatically, if the mapping table is empty - reprogramming the table without external software.
**Attention** This is a public forum