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.

Two point calibration; 8/16 bit MCU; complex operation

1. I have to measure voltage in 8/16 bit MCU & have to do its calibration also. 
I have selected 2 point calibration as it corrects both gain & offset error.

2. Voltage to measure = 0-5V.
Let measured at two pint: Vm1 & Vm2
Let actual volatge at those point = Vo1 & Vo2

Gain error = (Vm2-Vm1)/ (Vo1-Vo2)
offset error = Vm1 - (gain_error * Vo1)

reading = (Vm - offset_error)/gain_error;

3. Problem is this involves complex math & generally goes to float. Now using float operation on 8/16 bit MCU is very intensive.

Queries:
1. Is there any better method for which I don't have to do such float calculation. If yes any example code?

2. If no to 1, can above method be made less operation intensive like by fixed point math. If yes any example code

  • You can use Q-values, where you multiply the values with a fixed value. For example with Q10 you multiply the value with 1024 and gives a gain with a decimal precision of ~3 digits, at the end you have to divide you value with 1024.

    #define	Q	10
    
    void main (void)
    {
    	unsigned int Gain_error, offset_error, reading;
    
    	// Gain_error = Gain_error * 1024 (Q10)
    	Gain_error = (((unsigned long)Vm2-Vm1)<<Q) / (Vo1-Vo2);
    	offset_error = Vm1 - ((Gain_error * Vo1)>>Q);
    
    	reading = ((unsigned long)(Vm - offset_error) * Gain_error)>>Q;
    
    }
    

    You can find some macro’s for this, where I don’t know for now, seldom used them but can be handy for you.

    In the debugger you can select for the numerical view a Q-value and it shows a converted value.

**Attention** This is a public forum