|
发表于 2022-4-8 19:04:59
|
显示全部楼层
不记得贴图用的代码是哪份了,反正都差不多,供参考
- Do
- ' --------------- Wait the Convert ---------------
- FontSet F0HD
- iBusystp = 0
- Do
- iBusystp = iBusystp + 1
- WaitMs 1
- Loop While IO_ADC_DAT = 1 ' the Analog to Digtial Convert Busy Bit at ADChipset DOUT Pin
-
- GLcd (80,7), "Setp:"; Hex(iBusystp)
- ' --------------- Wait the Convert ---------------
-
- ' --------------- Read the ADC ---------------
- ' Read all Analog to Digtial Convert Byte
- iDa = ReadSPI()
- iDb = ReadSPI()
- iDc = ReadSPI()
- ' Config the Negative numbers from the Complement Code.
- 'If iDa > 128 Then
- 'iDraw = iDa - 128
- 'Else
- 'iDraw = iDa
- 'End If
- iDa = iDa - 128
- ' Set the ADChipset Busy-wait Bit
- IO_ADC_CLK = 1 : WaitUs 1 : IO_ADC_CLK = 0
- ' --------------- Read the ADC ---------------
-
- ' --------------- Automatic theRange ---------------
- ' --------------- Automatic theRange ---------------
-
- ' --------------- Print the Convert Result ---------------
- 'Print the Current Convert Result
- FontSet F0HD
- Format (1,5)
- fTrn = 2.5 * (65536 * iDa + 256 * iDb + iDc - 8388608) / 8388608
- 'Print fTrn
- 'GLcd (0,4), "Cur:"; fTrn; " VDC"
- ' --------------- Print the Convert Result ---------------
- fOut = fTrn / Gainerr - Offseterr
- FontSet F3HD
- Format(2,4)
- GLcd(0, 2), fOut
-
- For i = 0 To bSmthlength - 1
- bREGc(i) = bREGc(i + 1)
- bREGb(i) = bREGb(i + 1)
- bREGa(i) = bREGa(i + 1)
- Next i
- bREGc(bSmthlength) = iDc
- bREGb(bSmthlength) = iDb
- bREGa(bSmthlength) = iDa
- '排查最大最小值
- lrec = 65536 * iDa + 256 * iDb + iDc - 8388608
- lMax = lrec
- lMin = lrec
- iMax = 1
- iMin = 1
- fOut = 0
- For i = 1 To bSmthlength
- iTa = bREGa(i)
- iTb = bREGb(i)
- iTc = bREGc(i)
-
- lrec = 65536 * iTa + 256 * iTb + iTc - 8388608
- fTrn = 2.5 * (65536 * iTa + 256 * iTb + iTc - 8388608) / 8388608
- If lrec > lMax Then ' 找到最大值
- lMax = lrec
- iMax = i
- End If
- If lrec < lMin Then ' 找到最小值
- lMin = lrec
- iMin = i
- End If
- fOut = fOut + fTrn
- Next i
-
- fOut = fOut / bSmthlength
- fOut = fOut / Gainerr - Offseterr
- 'fOut = 2.5 + fOut
- 'GLcd (1,1), "SMT:"; fOut; " VDC"
- FontSet F0HD
- Format(2,6)
- GLcd (0,4), "SMT:"; fOut; " VDC"
- 'FontSet F3HD
- 'Format(1,6)
- 'GLcd(0, 2), fOut
- FontSet F0HD
- Format(1,6)
- iTa = bREGa(iMax)
- iTb = bREGb(iMax)
- iTc = bREGc(iMax)
- fMax = 2.5 * (65536 * iTa + 256 * iTb + iTc - 8388608) / 8388608
- 'GLcd (1,2), "MIN:"; fMax; " VDC"
- iTa = bREGa(iMin)
- iTb = bREGb(iMin)
- iTc = bREGc(iMin)
- fMin = 2.5 * (65536 * iTa + 256 * iTb + iTc - 8388608) / 8388608
- 'GLcd (1,3), "MAX:"; fMin; " VDC"
- GLcd(0, 5), fMin; " ~ "; fMax
- fOut = 1000000 * (fMax - fMin)
- Format(3,1)
- GLcd (0, 6), "Noise:"; fOut; " uVpp"
-
-
- Loop
复制代码 |
|