1、指导教师签名:年 月 日一、设计任务测控系统的设计涉及许多技术,其应用领域众多,在现代国防、现代工业、科研教育、机械医疗等领域里有着广泛的应用。另一方面,它的理论性与实践性都很强,需要努力做到理论与实践相结合,为此我们安排此课程设计实验,加深同学们对测试技术理论的理解,加强同学们对实践操作能力的培养。重点是了解测控系统设计的一般流程,掌握设计测控系统的一般方法,树立计算机测控系统的整体概念。在生产过程和科学研究中所接触到的被测量大多数是非电物理量,例如位移,力,转速,扭矩,温度,振动,流量,风速,等等。非电量种类繁多,特性千差万别,很多又是不便于直接测量的模拟信号。为了测量与处理方便,需要把非
2、电量转换为电量,这一步通常是通过各式传感器来转换,常称为一次转换;为适应计算机的统计分析处理,又需要把模拟量转化为数字量,这一步是通过A/D转换来实现的,常称为二次转换。这两方面是测试系统的两个重要环节(在测控领域里,有时还需要把处理好的数字量再转换成模拟量反馈回来控制工作进程,常称为三次转换)。它们的关系如下:本次课程设计实验是设计一套完整的微机实时测控系统,具体内容包括:编写A/D板的初始化程序与采集程序,调试上述程序,绘制波形,可用信号发生器输出的信号调试。注意:图形曲线以及幅值刻度和时间刻度要与实际信号一直。调试程序可参考所给的参考程序。调试成功后可编辑其他相关功能,(如设置采样长度、
3、采样间隔、形成数据文件、FFT分析及波形、统计分析等)。自动检测系统在数据处理功能上除了可进行FFT分析外,还应给出检测信号的最大值、最小值、平均值。自动分析得出信号的频率和周期。所编程序包括菜单的实现及相关功能,如举例所示,其中功能必须包括数据的采集及保存,波形显示,数据显示、FFT变换、信号周期和频率的自动检测。通过DA输出相关波形,由示波器进行观测的内容作为选项,完成基本内容的同学可以设计实习。二、小组分工在这次的课程设计中,为了提高效率,我们小组安排了合理的分工,每人负责50%左右的工作。具体如下:小组成员魏峰负责测控软件中主界面的设计、程序校验和报告的撰写;小组成员刘汉生负责工作菜单
4、的设计及相关程序的编写、主干程序的编写以及程序的调试。三、设计内容1.设计思路接到老师下达的任务后,我们首先完成了主界面和菜单的设计,通过了期中验收。一个好的采集系统程序应有一个方便、实用、友好、快捷的工作界面,因此编制一个好的菜单很重要。而后我们根据界面及工作菜单编写程序。其中包括画频谱图、存取数据、fft变换、A/D板采集数据等等。2.流程图 16位转12位 并转换到相应电压 Y N N N Y 3.主要程序1)FFT变换: Public Function FFT0(AR() As Double, AI() As Double, n As Integer, ni As Integer) D
5、im i As Integer, j As Integer, k As Integer, l As Integer, m As Integer Dim IP As Integer, LE As Integer Dim L1 As Integer, N1 As Integer, n2 As Integer Dim SN As Double, TR As Double, TI As Double, wr As Double, wi As Double Dim UR As Double, UI As Double, US As Double m = NTOM(n) n2 = n / 2 N1 = n
6、 - 1 SN = ni j = 1 For i = 1 To N1 If i j Then TR = AR(j - 1) AR(j - 1) = AR(i - 1) AR(i - 1) = TR TI = AI(j - 1) AI(j - 1) = AI(i - 1) AI(i - 1) = TI End If k = n2 While (k j) j = j - k k = k / 2 Wend j = j + k Next i For l = 1 To m LE = 2 l L1 = LE / 2 UR = 1# UI = 0# wr = Cos(Pi / L1) wi = SN * S
7、in(Pi / L1) For j = 1 To L1 For i = j To n Step LE IP = i + L1 TR = AR(IP - 1) * UR - AI(IP - 1) * UI TI = AI(IP - 1) * UR + AR(IP - 1) * UI AR(IP - 1) = AR(i - 1) - TR AI(IP - 1) = AI(i - 1) - TI AR(i - 1) = AR(i - 1) + TR AI(i - 1) = AI(i - 1) + TI US = UR UR = US * wr - UI * wi UI = UI * wr + US
8、* wi Next j Next l If SN -1 Then For i = 1 To n AR(i - 1) = AR(i - 1) / n AI(i - 1) = AI(i - 1) / nEnd FunctionPublic Function FFT1(AR() As Double, AI() As Double, n As Integer, ni As Integer) TR = AR(j) AR(j) = AR(i) AR(i) = TR TI = AI(j) AI(j) = AI(i) AI(i) = TI TR = AR(IP) * UR - AI(IP) * UI TI =
9、 AI(IP) * UR + AR(IP) * UI AR(IP) = AR(i) - TR AI(IP) = AI(i) - TI AR(i) = AR(i) + TR AI(i) = AI(i) + TI AR(i) = AR(i) / n AI(i) = AI(i) / nEnd Function 2)数据保存和读取:Public Sub load() 数据保存Dim tempDim i, j As Integer If Count 0 Then res = MsgBox(当前数据数否保存?, vbYesNo) If res = 6 Then Call storeCD.ShowOpeni
10、 = 0If CD.FileName ThenOpen CD.FileName For Input As #1Do While Not EOF(1)Input #1, tempdata(i) = tempi = i + 1LoopClose 1Text4 = maxdata()Text5 = mindata()Text6 = avdata()Text7.Text = sample_lengthText8.Text = sample_freMsgBox (数据读取完成!)End IfEnd SubPublic Sub store() 数据读取Dim str As Stringj = 0g = s
11、ample_length If sample_length str = Format(Now, yyyymmddhhmmss) &.txt Open str For Append As #1 Do While j g Print #1, data(j) j = j + 1 Loop Close 1完成数据储存! Else MsgBox (无数据,无法储存!End Sub 3)AD数据采集模块temp = AC_6111_AD(NTportio, cardid(0), 4000 / sample_fre, sample_path, sample_path, 3, 0, 0, 0, 0, 0, 0
12、, Data1(0), sample_length) For i = 0 To sample_length 转换数据,16位转化为12位data(i) = (Data1(i) And &HFFF0&) / 16 - 2048) / 2048# * 10# 设置为显示到-10V到10VNext i4)数据的时域曲线显示和频率周期的计算Public Sub shi()Text10.Visible = FalsePicture2.Visible = TruePicture2.BackColor = RGB(255, 255, 255)Picture2.Scale (0, 10)-(512, -10)
13、Picture2.Line (0, 0)-(512, 0)Picture2.Line (0, 10)-(0, -10)绘制与x轴平行的直线,并标记y轴For i = 0 To 10 Picture2.Line (0, 10 - 2 * i)-(512, 10 - 2 * i) Picture2.CurrentX = 5 Picture2.CurrentY = 10 - 2 * i Picture2.Print (10 - 2 * i) &V 绘制与y轴平行的直线,并标记x轴 Dim j As Single For j = 0 To 512 Step 30 一个格含50个数 Picture2.L
14、ine (j, -10)-(j, 10), vbBlue Picture2.CurrentY = 0 Picture2.CurrentX = j If Abs(j / sample_fre) 1 Then Picture2.Print Format(j / sample_fre, #0.#.#Next j绘制波形Dim t1, t2, t3 As IntegerDim period As Doubleperiod = 1 / sample_freFor i = 1 To sample_length - 1 If data(i) * data(i + 1) = 0 And data(i) 0 A
15、nd t1 = 1 Then 采样值发生负跳变 t3 = iinterv = 2 * Abs(t3 - t2) * period 周期If interv 0 Then frequency = 1 / interv 频率Text4 = maxdata() &Text5 = mindata() &Text6 = avdata() &For i = 1 To sample_length Step 1data(i) = data(i) * zyPicture2.Line (i - 1, data(i - 1)-(i, data(i), vbRedText9.Text = intervText11.Te
16、xt = frequencyCL.Add (data(j) / 10 * s1)DRW.Draw5)FFT曲线显示Public Sub fft() Const fftIn = 2048 Dim i As Integer Dim xr(2048) As Double Dim xi(2048) As Double赋值,IaIn(i)是采得的数据。 For i = 0 To 2048 xr(i) = 100 * data(i) xi(i) = 0 Next Call FFT0(xr(), xi(), 2048, 1)绘图 PicI_FFT.Scale (0, 100)-(fftIn - 1, -10
17、) PicI_FFT.DrawWidth = 2 For i = 0 To fftIn - 1 PicI_FFT.Line (i, Abs(xr(i)-(i + 1, Abs(xr(i + 1), vbBlue6)导出图形Private Sub Command4_Click()CommonDialog3.ShowSave 显示另存为对话框CommonDialog3.Filter = (*.bmp)|*.bmp FileName = CommonDialog3.FileNameSavePicture Picture2.Image, filename.BMP End Sub7)截图Private
18、Sub Command1_Click() DoEvents BitBlt Form2.hDC, 0, 0, Screen.Width, Screen.Height, GetDC(GetDesktopWindow), 0, 0, &HCC0020 SetWindowPos Form2.hWnd, HWND_TOPMOST, 0, 0, Screen.Width Screen.TwipsPerPixelX, Screen.Height Screen.TwipsPerPixelY, SWP_SHOWWINDOW调用模块如下Option ExplicitOption Base 0Public Decl
19、are Function SetWindowPos Lib USER32 (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongPublic Const HWND_TOPMOST = -1Public Const SWP_SHOWWINDOW = &H40Public Type PALETTEENTRY peRed As Byte peGreen A
20、s Byte peBlue As Byte peFlags As ByteEnd TypePublic Type LOGPALETTE palVersion As Integer palNumEntries As Integer palPalEntry(255) As PALETTEENTRY Enough for 256 colors.Public Type GUID Data1 As Long Data2 As Integer Data3 As Integer Data4(7) As BytePublic Const RASTERCAPS As Long = 38Public Const
21、RC_PALETTE As Long = &H100Public Const SIZEPALETTE As Long = 104Public Declare Function CreateCompatibleDC Lib GDI32 (ByVal hDC As Long) As LongPublic Declare Function CreateCompatibleBitmap Lib (ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As LongPublic Declare Function GetDevice
22、Caps Lib (ByVal hDC As Long, ByVal iCapabilitiy As Long) As LongPublic Declare Function GetSystemPaletteEntries Lib (ByVal hDC As Long, ByVal wStartIndex As Long, ByVal wNumEntries As Long, lpPaletteEntries As PALETTEENTRY) As LongPublic Declare Function CreatePalette Lib (lpLogPalette As LOGPALETTE
23、) As LongPublic Declare Function SelectObject Lib (ByVal hDC As Long, ByVal hObject As Long) As LongPublic Declare Function BitBlt Lib (ByVal hDCDest As Long, ByVal XDest As Long, ByVal YDest As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hDCSrc As Long, ByVal XSrc As Long, ByVal YSrc A
24、s Long, ByVal dwRop As Long) As LongPublic Declare Function DeleteDC Lib Public Declare Function SelectPalette Lib (ByVal hDC As Long, ByVal hPalette As Long, ByVal bForceBackground As Long) As LongPublic Declare Function RealizePalette Lib Public Declare Function GetWindowDC Lib (ByVal hWnd As Long) As LongPublic Declare Function GetDC Lib Public Declare Function ReleaseDC Lib (ByVal hWnd As Long, ByVal hDC As Long) As LongPublic Declare Function GetDesktopWindow Lib () As LongPublic Type PicBmp Size As LongType As Long hBmp As Long
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1