Hi
I am using a pico2203 to build a displacement control system, while it seems that I am confronted with a problem in building the feedback link.
My idea is that: firstly, generate a signal from pico2203 to drive the objects under control, then acquire the output data of it as a sequence and feed the sequence back into the pico, after a subtraction with the input signal and some other operations, a new sequence is acquired as the input sequence of AWG, by this way, a closed-loop control system is build.
But as I debugging the code, the error of overflow occurs, I tried to decrease the amplitude of input signal but it makes no difference.
Here is my codes and I beg someone could help me.
In the code the values_a denotes the input signal, and the values_b denotes the output, actually I am just building a typical PID control system.
Private Sub arbgen()
Dim ok As Integer
Dim i As Integer
Dim delta As Long
Dim frequency As Long
Dim size As Integer
Dim errorput1(501) As Byte
Dim j As Integer
Dim err(501) As Integer
ok = 1
offsetvoltage = Int(Val(Text2(0).Text) * 1000)
pktopk = Int(Val(Text2(1).Text) * 1000)
erri = 0
size = 500
frequency = Int(Val(Text2(2).Text))
arbitrarywavesize = Int(Val(Text2(3).Text))
kp = Val(inputkp.Text)
ki = Val(inputki.Text)
kd = Val(inputkd.Text)
'ReDim arbitraryWaveform(500) As Byte
delta = ((frequency * arbitrarywavesize) / 4096) * 4294967296# * 0.00000002
Open "D:\Documents\Waveforms\ysquare11.csv" For Input As #2
Do While Not EOF(2)
For i = 1 To UBound(arbitraryWaveform)
Input #2, arbitraryWaveform(i)
If closeloop.enabled = False Then
For j = 1 To i
err(j) = (values_a(j) - values_b(j)) / 1000
erri = err(j) + erri
If erri > 3000 Then
erri = 3000
End If
If erri < -3000 Then
erri = -3000
End If
Next j
errorput(i - 1) = (kp * (values_a(i) - values_b(i)) + ki * erri * 1000 * (values_time(i) - values_time(i - 1)) / 1000000 - kd * (values_a(i) - values_b(i) - values_a(i - 1) + values_b(i - 1)) / ((values_time(i) - values_time(i - 1)) / 1000000)) / 32767 * 255
If errorput(i - 1) < 0 Then
errorput(i - 1) = 0
End If
If errorput(i - 1) > 255 Then
errorput(i - 1) = 255
End If
Else
errorput(i - 1) = arbitraryWaveform(i)
End If
errorput1(i - 1) = CByte(errorput(i - 1))
Next i
Loop
Close #2
Select Case Combo2.Text
Case "Up": sweeptype = 0
Case "Down": sweeptype = 1
Case "UpDown": sweeptype = 2
Case "Downup": sweeptype = 3
End Select
If ps2000_handle Then
ok = ps2000_set_sig_gen_arbitrary(ps2000_handle, offsetvoltage, pktopk, delta, delta, 0, 0, errorput1(0), arbitrarywavesize, sweeptype, 0)
End If
End Sub
If you set a breakpoint at that line, perhaps you can loop through until you find the instance at which the overflow occurs.
You can then manually calculate the value using the parameters to see whether the resulting value is greater than the maximum value for the data type you are using for errorput.
Dear Hitesh
As your suggestion, a couple of experiments was conducted, and the fact was that there will be no problem if I put the signal generated by AWG into channel A or B directly without connecting the external load, but if I put the generated signal into an amplifier and driving object under control then detect the output signal of it and pass the detected signal into channel A or B, the overflow error occurs, which really confused me a lot.
A breakpoint was set, the value of variables under observation was listed below when the overflow occurs
i=143; j=144; errorput(i)=50; values_a(i)=90; values_b(i)=-436; values_time(i)=29286400; values_time(i-1)=29081600, err(j)=0
from my poit of view, the error may denotes that value of j is larger than i, for there is a line
And the err(j)=0, indicating that the value at moment j was failed to pass into err(j).
But how can I avoid that error making the value of j always beneath that of i, and why there will be no wrong if i connect the ports of signal out and channel A or B directly.
望眼欲穿您的回复(I am looking for your reply wistfully.)
Yangzhaoshu
dear hitesh
你太厉害了(You are too much )
the errorput(i) was calculated as 33048, beyond the permition value of integer, and can you give me some suggestion about how to transfer this excess value without causing overflow.