Dim F2HD As Flash Byte '声明软字体,由编译器提供
Dim F0HD As Flash Byte
Declare Function Setdac(MastDAC As Word, SlavDAC As Word) As Byte '声明用户函数 设置 DAC
Declare Function SetVoltage(fVoltage As Float) As Byte '声明用户函数 设置电压
Declare Function SetChannel(Channel As Byte) As Byte '声明用户函数 设置模拟开关通道
Declare Function Getinlerr(fVoltage As Float) As Word '声明用户函数 获得非线性误差
Declare Interrupt Urxc() '声明使用串口破中断
Enable Interrupts
Enable Urxc
Dim i As Byte
Dim iSmsetp As Byte
Dim iBusystp As Byte
Dim iTrd As Byte
Dim iDraw As Word
Dim CurrentChannel As Byte
Dim itm As Byte
Dim baCalChannel As Bit
Dim bUartset As Bit
Dim tTxt As String *15
Dim tm As String *7
Dim tCmd As String *4
Dim iDa As Byte
Dim iDb As Byte
Dim iDc As Byte
Dim iDd As Byte
Dim iTa As Byte
Dim iTb As Byte
Dim iTc As Byte
Dim iTd As Byte
Dim bREGas(33) As Byte
Dim bREGbs(33) As Byte
Dim bREGcs(33) As Byte
Dim bREGds(33) As Byte
Dim bREGar(33) As Byte
Dim bREGbr(33) As Byte
Dim bREGcr(33) As Byte
Dim bREGdr(33) As Byte
Dim fTrn As Float
Dim fOut As Float
Dim fReference As Float
Dim fSynthesis As Float
Dim fCalsacles As Float
Dim fCalfSynth As Float
Dim fVoltage As Float
Dim fError As Float
Dim fVset As Float
Dim fVtrn As Float
Dim Vseth As Word
Dim Vsetl As Word
'Dim uVseth As Word
'Dim uVsetl As Word
Dim fSetting As Float
Dim fCurerr As Float
Dim fPreerr As Float
Dim fIerr As Float
Dim fDerr As Float
Dim iPv As Word
Dim iIv As Word
Dim iDv As Word
Dim wErr As Word
Pwm2 = 3
Set DDRD.7 'Setting the VLCD Pwm Output
Set DDRB.2 'Setting the CD4094 Strobe Output
Set DDRA.3 'Setting the LCD 12864 PowerUp Reset Pin
Start Timer2
PORTB.2 = 0 'Setting the CD4094 Strobe Basical Status
' Reset and Init. the Graph LCD
PORTA.3 = 0
WaitMs 200
PORTA.3 = 1
GLcdInit
Gcls
fError = fVoltage + fError / 10000
GLcd(0, 5), "Adj:"; fError
SetVoltage(fError)
End If
FontSet F0HD
GLcd(96, 7), Hex(iSmsetp); "/43"
'GLcd(0, 5), "USet: "; tTxt
If bUartset = 1 Then
'GLcd(0, 6), "Usetf:"; fSetting
fVoltage = fSetting
'SetVoltage(fVoltage)
iSmsetp = 0
bUartset = 0
GoTo stt
End If
Loop
Function Setdac(MastDAC As Word, SlavDAC As Word) As Byte '设置 DAC 的子函数,将入口值转换为 MAX515 适合的格式;MAX515 的 CS 接在移位寄存器 CD4094 上
Local bMastMSB As Byte
Local bMastLSB As Byte
Local bSlavMSB As Byte
Local bSlavLSB As Byte
Local Channelset As Byte
Function SetVoltage(fVoltage As Float) As Byte '设置电压的子函数,根据电压合成公式逆运算得到两个 DAC 应当的设置值
' the addsch VOut = Gain * (Vmast * R2 + Vslave * R1) / (R1+R2), Fullscale of the Vm and Vs all = 5V, R1 = 1K ohm, R2 = 1M ohm, Gain = 2.01509
fVtrn = fVoltage
fVset = fVtrn
' Get the MastDAC Voltage Setting Value
fVtrn = fVtrn / 2015090 'the 2015090 is the Buffamp Gain( x2.01509)
fVtrn = fVtrn * 1001000 - 5000 'the 1001000 is the MastRes 1K and the SlaveRes 1M
fVtrn = fVtrn * 4095 / 4995005 'the 4095 is the 12bit DAC Full scale; 4995005 scale by addsch.(added the MastDAC Fullscale Voltage)
Vseth = fVtrn
Function SetChannel(Channel As Byte) As Byte '设置模拟开关的子函数
Local Channelset As Byte
Channelset = &b01100000 + Channel
ShiftOut &b00000000; &b00000000; &b00000000; &b00000000; Channelset
PORTB.2 = 1 : WaitUs 100: PORTB.2 = 0
Return Channelset
End Function
Function Getinlerr(fVoltage As Float) As Word '获得非线性校正数据,它是通过测量和拟合得到的一个二次三项式,不过这没有经过深入的验证
Local bInlerr As Word
但这个计划终于没有实行,因为需要动用的资源实在是太多了 另外我在寻找合适的 ADC 的时候发现 Linear 的官方应用笔记 An86 和我的想法不谋而合:
AN86 - A Standards Lab Grade 20-Bit DAC with 0.1ppm/° Drift: The Dedicated Art of Digitizing One Part Per Million
(http://cds.linear.com/docs/Application%20Note/an86f.pdf)
文档中这样写道:
If the total capacitance at VIN (see Figure 17) is small
(< 0.01mF), relatively large external source resistances (up
to 20k for 20pF parasitic capacitance) can be tolerated
without any offset/full-scale error.
就是说小的输入电容,可以有大的源内阻而没有任何的 offset/full-scale error;