VP-7720A 改造・修理 自動測定化プロジェクト 実動開始 ― 2025/11/12
VP-7720Aの自動化の続きです.実働試験を始めました.下は12BH7AのSRPPの測定結果です.
約40V出力までの歪を測ってみました.自動化自体はうまくいっているようですが,VP-7720Aの問題点が表面化しました.測定結果に段々が見えていて,電圧か歪測定のレンジ切替,またはメータードライブ回路のオフセットに問題があるようです.こういった微妙な問題点は自動化するまで気付いていませんでした.オフセットであればソフト的に対処できますが,これから調査します.
さて,Arduinoのスケッチについては何度か記述しましたが,Excel-VBAの話はしていませんでした.VBAにはAgilentのVISA COMライブラリーを用いました.今までもGP-IB通信に使っていたので,多少慣れがあったからです.他にもEASY COMという便利なものも公開されているようです.
また,対数グラフの描画にはhttps://qiita.com/mori_toma/items/8281596a2537fdc8cd56の@mori_tomaさんが公開されているものを使っています.これらの有益な情報を公開されている皆様に深く感謝します.
なお,上図測定に使った歪率/電圧のVBAプログラムは以下の通りです.(グラフ描画部分は省略します.) これも素人の作ですし,不使用の変数,定数,バグなど残っていると思いますが,ご容赦ください.
----------以下VBA ---------
Sub ボタン1_Click()
Dim strVal As String
Dim strArr() As String
Dim MaxOutStr, MaxDistStr, StepStr, JMaxStr, VoutStr, DistStr As String
Dim JMax, JJMax As Integer
Dim InputdB, Vin, Vout, Coef, MaxOut, MinOut, MiniInput, MaxDist As Single
Dim InputAP, InputAPMax, InputStart, Step, yMax, yMin As Single
Dim dstSheet As Worksheet
Set dstSheet = Worksheets("Sheet1")
Dim RM As New VisaComLib.ResourceManager
Dim TB As New VisaComLib.FormattedIO488 'TB : Target Board
Set TB.IO = RM.Open("ASRL3::INSTR")
Dim sfc As VisaComLib.ISerial 'RS232C通信設定
Set sfc = TB.IO
sfc.BaudRate = 9600
sfc.DataBits = 8
sfc.Parity = ASRL_PAR_NONE
sfc.StopBits = ASRL_STOP_ONE
sfc.FlowControl = ASRL_FLOW_NONE
TB.IO.TerminationCharacter = 10
TB.IO.Timeout = 10000 'タイムアウト10秒
Sleep (200) '何故か185〜240いるようだ?
' Gain測定
TB.WriteString "A" 'AMPTD/DISTによる測定の初期化実行
Sleep (5000) 'Range切り替えに時間を要する
Vout = Val(TB.ReadString) ' Arduinoから受信
InputdB = Val(TB.ReadString) ' Arduinoから受信
Vin = 2# * 10 ^ (InputdB / 20#)
Coef = Vout / Vin
Cells(8, 2) = Coef
Cells(9, 2) = InputdB
Cells(9, 3) = Vin
' 最大値など計算
MiniOut = 0.2 '最小電圧
MaxOut = Cells(1, 2)
MaxOut = MaxOut * 1.1
MaxDist = Cells(2, 2)
If MaxOut > 100 Then MaxOut = 100
MaxInput = MaxOut / Coef
Cells(6, 3) = MaxInput
InputAPMax = 20# * Log(MaxInput * 0.5) / Log(10#)
Cells(6, 2) = InputAPMax
JMax = Cells(3, 2) 'りかえしの最大回数
Step = Round((InputAPMax - InputdB) / JMax, 1)
Cells(7, 2) = Step
yMax = Cells(4, 2)
yMin = Cells(5, 2)
' 表から測定条件読み込んでArduinoに送る
Sleep (200)
MaxOutStr = Str(Cells(1, 2)) '最大電圧
MaxDistStr = Str(Cells(2, 2)) '最大歪率
StepStr = Str(Cells(7, 2))
JMaxStr = Str(JMax)
TB.WriteString Str(MaxOutStr)
Sleep (20)
TB.WriteString Str(MaxDistStr)
Sleep (20)
TB.WriteString Str(StepStr)
Sleep (20)
TB.WriteString Str(JMax)
JJMax = 0
For j = 1 To JMax
TB.WriteString "D" ' 出力電圧, 歪率測定
Cells(j + 10, 2) = InputdB + Step * j
Sleep (600) ' Arduino側のdelay+100
VoutStr = TB.ReadString
Vout = Val(VoutStr) '電圧読み込み
Cells(j + 10, 3) = Vout
If Vout >= MaxOut Then GoTo Label1
Sleep (5100) ' Arduino側のdelay+100
DistStr = TB.ReadString
Dist = Val(DistStr)
If Dist >= MaxDist Then GoTo Label1
Cells(j + 10, 4) = Dist
JJMax = JJMax + 1
If StopFlag = True Then
Cells(1, 4) = "Cancelled"
GoTo Label1
End If
Next j
Label1:
TB.WriteString "E"
TB.IO.Close
Set TB = Nothing
Set RM = Nothing
' ###### グラフ表示開始 #######
Dim strVal As String
Dim strArr() As String
Dim MaxOutStr, MaxDistStr, StepStr, JMaxStr, VoutStr, DistStr As String
Dim JMax, JJMax As Integer
Dim InputdB, Vin, Vout, Coef, MaxOut, MinOut, MiniInput, MaxDist As Single
Dim InputAP, InputAPMax, InputStart, Step, yMax, yMin As Single
Dim dstSheet As Worksheet
Set dstSheet = Worksheets("Sheet1")
Dim RM As New VisaComLib.ResourceManager
Dim TB As New VisaComLib.FormattedIO488 'TB : Target Board
Set TB.IO = RM.Open("ASRL3::INSTR")
Dim sfc As VisaComLib.ISerial 'RS232C通信設定
Set sfc = TB.IO
sfc.BaudRate = 9600
sfc.DataBits = 8
sfc.Parity = ASRL_PAR_NONE
sfc.StopBits = ASRL_STOP_ONE
sfc.FlowControl = ASRL_FLOW_NONE
TB.IO.TerminationCharacter = 10
TB.IO.Timeout = 10000 'タイムアウト10秒
Sleep (200) '何故か185〜240いるようだ?
' Gain測定
TB.WriteString "A" 'AMPTD/DISTによる測定の初期化実行
Sleep (5000) 'Range切り替えに時間を要する
Vout = Val(TB.ReadString) ' Arduinoから受信
InputdB = Val(TB.ReadString) ' Arduinoから受信
Vin = 2# * 10 ^ (InputdB / 20#)
Coef = Vout / Vin
Cells(8, 2) = Coef
Cells(9, 2) = InputdB
Cells(9, 3) = Vin
' 最大値など計算
MiniOut = 0.2 '最小電圧
MaxOut = Cells(1, 2)
MaxOut = MaxOut * 1.1
MaxDist = Cells(2, 2)
If MaxOut > 100 Then MaxOut = 100
MaxInput = MaxOut / Coef
Cells(6, 3) = MaxInput
InputAPMax = 20# * Log(MaxInput * 0.5) / Log(10#)
Cells(6, 2) = InputAPMax
JMax = Cells(3, 2) 'りかえしの最大回数
Step = Round((InputAPMax - InputdB) / JMax, 1)
Cells(7, 2) = Step
yMax = Cells(4, 2)
yMin = Cells(5, 2)
' 表から測定条件読み込んでArduinoに送る
Sleep (200)
MaxOutStr = Str(Cells(1, 2)) '最大電圧
MaxDistStr = Str(Cells(2, 2)) '最大歪率
StepStr = Str(Cells(7, 2))
JMaxStr = Str(JMax)
TB.WriteString Str(MaxOutStr)
Sleep (20)
TB.WriteString Str(MaxDistStr)
Sleep (20)
TB.WriteString Str(StepStr)
Sleep (20)
TB.WriteString Str(JMax)
JJMax = 0
For j = 1 To JMax
TB.WriteString "D" ' 出力電圧, 歪率測定
Cells(j + 10, 2) = InputdB + Step * j
Sleep (600) ' Arduino側のdelay+100
VoutStr = TB.ReadString
Vout = Val(VoutStr) '電圧読み込み
Cells(j + 10, 3) = Vout
If Vout >= MaxOut Then GoTo Label1
Sleep (5100) ' Arduino側のdelay+100
DistStr = TB.ReadString
Dist = Val(DistStr)
If Dist >= MaxDist Then GoTo Label1
Cells(j + 10, 4) = Dist
JJMax = JJMax + 1
If StopFlag = True Then
Cells(1, 4) = "Cancelled"
GoTo Label1
End If
Next j
Label1:
TB.WriteString "E"
TB.IO.Close
Set TB = Nothing
Set RM = Nothing
' ###### グラフ表示開始 #######
コメント
トラックバック
このエントリのトラックバックURL: http://colorkonan16.asablo.jp/blog/2025/11/12/9816642/tb
※なお、送られたトラックバックはブログの管理者が確認するまで公開されません。

コメントをどうぞ
※メールアドレスとURLの入力は必須ではありません。 入力されたメールアドレスは記事に反映されず、ブログの管理者のみが参照できます。
※なお、送られたコメントはブログの管理者が確認するまで公開されません。
※投稿には管理者が設定した質問に答える必要があります。