|
发表于 2018-6-11 19:19:16
|
显示全部楼层
这是程序固定点的,我的 Voltgen 是不限点、非固定的
不过代码不是常见的 C,所以仅供参考了
Function GetMultinlerr(fVoltage As Float) As Float
Local iSetvt As Integer
Local x0Point As Byte
Local x1Point As Byte
Local wReadPoint0 As Word
Local wReadPoint1 As Word
Local y0Point As Integer
Local y1Point As Integer
fVtrn = fVoltage
iSetvt = fVtrn
x0Point = iSetvt
If x0Point < 1 Then
x0Point = 0
x1Point = 1
ElseIf x0Point > 9 Then
x0Point = 9
x1Point = 10
Else
x1Point = x0Point + 1
End If
'**************这里是多点校正值,校正值来自 EEPROM 中存储的测量结果**************
wReadPoint0 = iMultinlError(x0Point)
y0Point = wReadPoint0 - 10000
wReadPoint1 = iMultinlError(x1Point)
y1Point = wReadPoint1 - 10000
‘**************根据多点校正值计算出分段拟合参数**************
fLinear = (y1Point - y0Point) / (x1Point - x0Point)
fConstant = (x1Point * y0Point - x0Point * y1Point) / (x1Point - x0Point)
fTrn = fLinear * fVoltage + fConstant
Return fTrn
End Function
|
评分
-
1
查看全部评分
-
|