西電直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng)設(shè)計(jì)_第1頁(yè)
西電直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng)設(shè)計(jì)_第2頁(yè)
西電直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng)設(shè)計(jì)_第3頁(yè)
西電直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng)設(shè)計(jì)_第4頁(yè)
西電直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng)設(shè)計(jì)_第5頁(yè)
已閱讀5頁(yè),還剩18頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng)設(shè)計(jì)實(shí)驗(yàn)報(bào)告評(píng)語(yǔ):成績(jī)教師:年月日班級(jí):031021學(xué)號(hào):姓名:地點(diǎn):E樓I區(qū)311時(shí)間:3.26-3.31一、實(shí)驗(yàn)?zāi)康恼莆瘴C(jī)系統(tǒng)總線(xiàn)與各芯片管腳連接方法,提高接口擴(kuò)展硬件電路的連接能力。2.了解霍爾器件的工作原理,電機(jī)轉(zhuǎn)速的測(cè)量與控制的基本原理。3.了解閉環(huán)控制系統(tǒng)的組成原理。掌握電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng)的構(gòu)成方法。二、實(shí)驗(yàn)內(nèi)容設(shè)計(jì)一個(gè)對(duì)直流電機(jī)轉(zhuǎn)速測(cè)量與轉(zhuǎn)速控制的閉環(huán)控制系統(tǒng)。微機(jī)控制中心在監(jiān)控界面上設(shè)置電機(jī)轉(zhuǎn)速。電機(jī)轉(zhuǎn)速測(cè)量利用霍爾傳感器電路產(chǎn)生轉(zhuǎn)速脈沖,定時(shí)/計(jì)數(shù)電路通過(guò)脈沖計(jì)數(shù)獲得轉(zhuǎn)速參量。電機(jī)轉(zhuǎn)速調(diào)整采用PWM(脈寬調(diào)節(jié))方法,控制中心采樣到電機(jī)轉(zhuǎn)速參量,算得轉(zhuǎn)速值同預(yù)定轉(zhuǎn)速設(shè)置值進(jìn)行比較,若不相同,則調(diào)整控制轉(zhuǎn)速脈沖的占空比,來(lái)達(dá)到調(diào)速的目的。(占空比=脈沖寬度/脈沖周期)三、實(shí)驗(yàn)環(huán)境:1. 硬件配置:

微機(jī)一臺(tái)(Pentium4)

微機(jī)接口技術(shù)實(shí)驗(yàn)箱一個(gè)

ISA–PCI轉(zhuǎn)接卡一塊

連接電纜一條

萬(wàn)用表一塊

微機(jī)接口技術(shù)實(shí)驗(yàn)講義

一本

導(dǎo)線(xiàn)、剝線(xiàn)鉗等2.軟件環(huán)境:WindowsXP平臺(tái)

VisualC++6.0編譯器四、系統(tǒng)功能與設(shè)計(jì)要求1.基本功能要求具有友好的人機(jī)交互界面,通過(guò)鼠標(biāo)或鍵盤(pán),選擇相關(guān)按鈕對(duì)系統(tǒng)進(jìn)行監(jiān)控,監(jiān)控系統(tǒng)具有轉(zhuǎn)速參數(shù)設(shè)置窗口、采樣的電機(jī)轉(zhuǎn)速數(shù)據(jù)顯示窗口和強(qiáng)行干預(yù)系統(tǒng)運(yùn)行的按鈕或相應(yīng)功能選擇菜單。監(jiān)控程序用查詢(xún)(或中斷)方式獲取轉(zhuǎn)速數(shù)據(jù)。直流電機(jī)轉(zhuǎn)速測(cè)量與控制監(jiān)控界面圖屏幕監(jiān)控界面參考上面界面圖,也可以自行設(shè)計(jì)界面風(fēng)格。首先自行設(shè)定轉(zhuǎn)速(小于3000r/m),點(diǎn)擊“啟動(dòng)”后電機(jī)開(kāi)始運(yùn)轉(zhuǎn),同時(shí)進(jìn)行數(shù)據(jù)采集,采集到的數(shù)據(jù)(實(shí)測(cè)轉(zhuǎn)速和運(yùn)行時(shí)間)實(shí)時(shí)顯示在相關(guān)位置,點(diǎn)擊“停止”后立刻停止電機(jī)轉(zhuǎn)動(dòng),同時(shí)停止采集數(shù)據(jù)的輸出,重新設(shè)定轉(zhuǎn)速波形后,再次點(diǎn)擊“啟動(dòng)”即顯示新數(shù)據(jù)。五、設(shè)計(jì)思路用數(shù)字信號(hào)來(lái)控制模擬量的應(yīng)用很多,PWM就是其中一種方法。直流電機(jī)的轉(zhuǎn)速可以由加到(IN)口的脈沖占空比決定,正向占空比越大則轉(zhuǎn)速越快,反之則越慢,其原理圖如下:直流電機(jī)在控制脈沖作用下轉(zhuǎn)動(dòng),電機(jī)轉(zhuǎn)盤(pán)上的永久磁鐵隨之旋轉(zhuǎn),霍爾傳感器件3101T受磁場(chǎng)的影響,從端口OUT輸出脈沖信號(hào),電機(jī)旋轉(zhuǎn)一圈,霍爾傳感器輸出一個(gè)脈沖,通過(guò)測(cè)出脈沖信號(hào)的頻率(單位時(shí)間脈沖個(gè)數(shù))就可以計(jì)算出電機(jī)的轉(zhuǎn)速利用實(shí)驗(yàn)系統(tǒng)資源可以設(shè)計(jì)一個(gè)直流電機(jī)轉(zhuǎn)速閉環(huán)控制系統(tǒng)。利用帶鎖存的I/O接口電路(如8255,74LS273,D/A-DA0832)輸出控制電機(jī)轉(zhuǎn)速的脈沖。采樣轉(zhuǎn)速用霍爾傳感器件提供電機(jī)轉(zhuǎn)速脈沖。利用定時(shí)/計(jì)數(shù)電路對(duì)電機(jī)轉(zhuǎn)速脈沖計(jì)數(shù)。微機(jī)可從定時(shí)/計(jì)數(shù)電路中獲得電機(jī)轉(zhuǎn)速數(shù)值,并產(chǎn)生控制電機(jī)轉(zhuǎn)速的PWM脈沖。六、心得體會(huì)本實(shí)驗(yàn)將8253的功能運(yùn)用到了極致,并且是一個(gè)閉環(huán)式的實(shí)驗(yàn)。雖說(shuō)我們的實(shí)驗(yàn)是最難的一個(gè),但是世上無(wú)難事只怕有心人,我們組經(jīng)過(guò)共同討論,分工合作終于將實(shí)驗(yàn)的基本要求完成。作為軟件組的組長(zhǎng),我再一次深入的學(xué)習(xí)了MFC的窗口控制程序,通過(guò)網(wǎng)絡(luò)學(xué)到了新的控件和函數(shù)的功能。我構(gòu)造了整個(gè)軟件的大框架,而且分工完成了各個(gè)部分的代碼,幫助我們組高效的完成了實(shí)驗(yàn),并且承擔(dān)了整個(gè)代碼的調(diào)試工作,使代碼從設(shè)想轉(zhuǎn)化為現(xiàn)實(shí)。開(kāi)始時(shí),我們嘗試了用軟件控制計(jì)數(shù)器定時(shí)器的方式編程,硬件電路簡(jiǎn)單,結(jié)果因?yàn)閷?shí)力有限沒(méi)有成功,最后只有改變硬件線(xiàn)路,減輕了軟件部分的控制負(fù)擔(dān),使軟件部分能更快的完成任務(wù),我深刻的認(rèn)識(shí)到做好一個(gè)小項(xiàng)目必須有統(tǒng)籌全局的能力,只有好的硬件設(shè)計(jì)才能減輕軟件的難度,讓程序簡(jiǎn)單化。只有軟硬結(jié)合才是王道。實(shí)驗(yàn)中計(jì)數(shù)器的初始化是個(gè)難點(diǎn),但是我們共同討論,確定了可行的方案,最終解決了問(wèn)題,并且將微機(jī)原理的理論知識(shí)運(yùn)用到了實(shí)際中,提高了我的動(dòng)手能力。七、附錄實(shí)驗(yàn)代碼:#ifndefPCI9052DLL_H_#definePCI9052DLL_H_boolOpenDevice(void);voidCloseDevice(void);boolGetIoBase(unsignedshort*pusIoBase);boolInByte(unsignedshortusIoAddr,unsignedchar*pucIoData);boolOutByte(unsignedshortusIoAddr,unsignedcharucIoData);#endif////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////#defineIDC_BUTTON_BEGIN1000#defineIDC_BUTTON_STOP1001#defineIDC_EDIT_SETTING_SPEED1002#defineIDC_EDIT_X1003#defineIDC_EDIT_SAMPLE_SPEED1007#defineIDC_EDIT_RUMTIME1008#defineIDC_EDIT_SAMPLE_DUTYCYCLE1009#defineIDC_EDIT_STATE1010#defineIDC_EDIT_Y1011//Nextdefaultvaluesfornewobjects//#ifdefAPSTUDIO_INVOKED#ifndefAPSTUDIO_READONLY_SYMBOLS#define_APS_NEXT_RESOURCE_VALUE130#define_APS_NEXT_COMMAND_VALUE32771#define_APS_NEXT_CONTROL_VALUE1004#define_APS_NEXT_SYMED_VALUE101#endif#endif//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////StdA//stdafx.h:includefileforstandardsystemincludefiles,//orprojectspecificincludefilesthatareusedfrequently,but//arechangedinfrequently//#if!defined(AFX_STDAFX_H__F7778614_97E8_4AC7_9862_4D48CE9CCC55__INCLUDED_)#defineAFX_STDAFX_H__F7778614_97E8_4AC7_9862_4D48CE9CCC55__INCLUDED_#if_MSC_VER>1000#pragmaonce#endif//_MSC_VER>1000#defineVC_EXTRALEAN //Excluderarely-usedstufffromWindowsheaders#include<afxwin.h>//MFCcoreandstandardcomponents#include<afxext.h>//MFCextensions#include<afxdisp.h>//MFCAutomationclasses#include<afxdtctl.h> //MFCsupportforInternetExplorer4CommonControls#ifndef_AFX_NO_AFXCMN_SUPPORT#include<afxcmn.h> //MFCsupportforWindowsCommonControls#endif//_AFX_NO_AFXCMN_SUPPORT//{{AFX_INSERT_LOCATION}}//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.#endif//!defined(AFX_STDAFX_H__F7778614_97E8_4AC7_9862_4D48CE9CCC55__INCLUDED_)//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng).h:mainheaderfileforthe直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng)application//#if!defined(AFX__H__EAA30B2E_F431_4F92_AC92_B7B1045B69EF__INCLUDED_)#defineAFX__H__EAA30B2E_F431_4F92_AC92_B7B1045B69EF__INCLUDED_#if_MSC_VER>1000#pragmaonce#endif//_MSC_VER>1000#ifndef__AFXWIN_H__ #errorinclude'stdafx.h'beforeincludingthisfileforPCH#endif#include"resource.h" //mainsymbols///////////////////////////////////////////////////////////////////////////////CMyApp://See直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng).cppfortheimplementationofthisclass//classCMyApp:publicCWinApp{public: CMyApp();//Overrides //ClassWizardgeneratedvirtualfunctionoverrides //{{AFX_VIRTUAL(CMyApp) public: virtualBOOLInitInstance(); //}}AFX_VIRTUAL//Implementation //{{AFX_MSG(CMyApp) //NOTE-theClassWizardwilladdandremovememberfunctionshere. //DONOTEDITwhatyouseeintheseblocksofgeneratedcode! //}}AFX_MSG DECLARE_MESSAGE_MAP()};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.#endif//!defined(AFX__H__EAA30B2E_F431_4F92_AC92_B7B1045B69EF__INCLUDED_)//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng)Dlg.h:headerfile#if!defined(AFX_DLG_H__5D432814_9F88_4AFE_B6FF_42EF331DB9A0__INCLUDED_)#defineAFX_DLG_H__5D432814_9F88_4AFE_B6FF_42EF331DB9A0__INCLUDED_#if_MSC_VER>1000#pragmaonce#endif//_MSC_VER>1000///////////////////////////////////////////////////////////////////////////////CMyDlgdialogclassCMyDlg:publicCDialog{//Constructionpublic: voidPaint_Wavepatten();//繪制波形圖 voidWave_Init();//波形圖初始化 voidMember_Init();//參數(shù)初始化 CMyDlg(CWnd*pParent=NULL); //standardconstructor intpaint_intervel_x;//繪圖橫坐標(biāo)間隔 intpaint_intervel_y;//繪圖縱坐標(biāo)間隔 boolm_isBegin;//電機(jī)是否運(yùn)行 UINT m_setSpeed;//電機(jī)設(shè)定速度 double m_sampleSpeed;//電機(jī)實(shí)測(cè)速度 int m_runTime;//運(yùn)行時(shí)間 int m_dutyCycle;//占空比 CString m_state;//電機(jī)運(yùn)行狀態(tài) unsignedshortm_usioaddr;//PCI基地址//DialogData //{{AFX_DATA(CMyDlg) enum{IDD=IDD_MY_DIALOG}; //NOTE:theClassWizardwilladddatamembershere //}}AFX_DATA //ClassWizardgeneratedvirtualfunctionoverrides //{{AFX_VIRTUAL(CMyDlg) public: virtualBOOLDestroyWindow(); protected: virtualvoidDoDataExchange(CDataExchange*pDX); //DDX/DDVsupport virtualvoidCalcWindowRect(LPRECTlpClientRect,UINTnAdjustType=adjustBorder); //}}AFX_VIRTUAL//Implementationprotected: HICONm_hIcon; //Generatedmessagemapfunctions //{{AFX_MSG(CMyDlg) virtualBOOLOnInitDialog(); afx_msgvoidOnSysCommand(UINTnID,LPARAMlParam); afx_msgvoidOnPaint(); afx_msgHCURSOROnQueryDragIcon(); virtualvoidOnOK(); afx_msgvoidOnButtonBegin(); afx_msgvoidOnButtonStop(); afx_msgvoidOnTimer(UINTnIDEvent); afx_msgvoidOnCancelMode(); afx_msgvoidOnMouseMove(UINTnFlags,CPointpoint); afx_msgvoidOnCaptureChanged(CWnd*pWnd); //}}AFX_MSG DECLARE_MESSAGE_MAP()};//{{AFX_INSERT_LOCATION}}//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.#endif//!defined(AFX_DLG_H__5D432814_9F88_4AFE_B6FF_42EF331DB9A0__INCLUDED_)//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////stdafx.cpp:sourcefilethatincludesjustthestandardincludes// 直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng).pchwillbethepre-compiledheader// stdafx.objwillcontainthepre-compiledtypeinformation#include"stdafx.h"http://////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng).cpp:Definestheclassbehaviorsfortheapplication.#include"stdafx.h"#include"直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng).h"#include"直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng)Dlg.h"#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endif///////////////////////////////////////////////////////////////////////////////CMyAppBEGIN_MESSAGE_MAP(CMyApp,CWinApp) //{{AFX_MSG_MAP(CMyApp) //NOTE-theClassWizardwilladdandremovemappingmacroshere. //DONOTEDITwhatyouseeintheseblocksofgeneratedcode! //}}AFX_MSG ON_COMMAND(ID_HELP,CWinApp::OnHelp)END_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CMyAppconstructionCMyApp::CMyApp(){ //TODO:addconstructioncodehere, //PlaceallsignificantinitializationinInitInstance}///////////////////////////////////////////////////////////////////////////////TheoneandonlyCMyAppobjectCMyApptheApp;///////////////////////////////////////////////////////////////////////////////CMyAppinitializationBOOLCMyApp::InitInstance(){ AfxEnableControlContainer(); //Standardinitialization //Ifyouarenotusingthesefeaturesandwishtoreducethesize //ofyourfinalexecutable,youshouldremovefromthefollowing //thespecificinitializationroutinesyoudonotneed.#ifdef_AFXDLL Enable3dControls(); //CallthiswhenusingMFCinasharedDLL#else Enable3dControlsStatic(); //CallthiswhenlinkingtoMFCstatically#endif CMyDlgdlg; m_pMainWnd=&dlg; intnResponse=dlg.DoModal(); if(nResponse==IDOK) { //TODO:Placecodeheretohandlewhenthedialogis //dismissedwithOK } elseif(nResponse==IDCANCEL) { //TODO:Placecodeheretohandlewhenthedialogis //dismissedwithCancel } //Sincethedialoghasbeenclosed,returnFALSEsothatweexitthe //application,ratherthanstarttheapplication'smessagepump. returnFALSE;}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng)Dlg.cpp:implementationfile#include"stdafx.h"#include"直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng).h"#include"直流電機(jī)轉(zhuǎn)速測(cè)量與控制系統(tǒng)Dlg.h"#include"PCI9052Dll.h"#include<time.h>#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endifintai=1;intgspeed[130];////////////////////////////////////////////////////////////////////////////intg_time_speed[120];//時(shí)間與所對(duì)應(yīng)的采樣轉(zhuǎn)速//boolstop=false;doubleg_sampleSpeed=0;boolg_isBegin=false;intg_setSpeed=0;intSpeedxx;voiddelay(doublen){while(n) n--;}unsignedshortg_usIoAddr=0xde00;//板子基地址UINTthread_sample(LPVOIDlpParam)//線(xiàn)程1,采樣線(xiàn)程{ CMyDlg*dlg=(CMyDlg*)AfxGetApp()->GetMainWnd(); //數(shù)據(jù)反饋到g_time_speed[]中 unsignedshortusIoAddr; unsignedshortAddr1; unsignedchardata; unsignedcharspeed; unsignedshortAddr2; OpenDevice(); GetIoBase(&usIoAddr); Addr1=usIoAddr;//8255的地址 Addr2=Addr1+8;//8253的地址,Addr2+3為8253的控制器地址//Addr1=Addr1+3;//Addr1+3為8255的控制器地址//初識(shí)化計(jì)時(shí)器0 data=0x32; OutByte(Addr2+3,data);//向8253控制寄存器中寫(xiě)入控制字00110110 data=0x09; OutByte(Addr2,data);//向8253計(jì)數(shù)器0低字節(jié)寫(xiě)入00010010 data=0x3d; OutByte(Addr2,data);//向8253計(jì)數(shù)器0高字節(jié)寫(xiě)入01111010 //初始化計(jì)數(shù)器1 data=0x52; OutByte(Addr2+3,data);//向8253控制寄存器中寫(xiě)入控制字01110000 data=100; OutByte(Addr2+1,data);//向8253計(jì)數(shù)器1低字節(jié)寫(xiě)入01100100 //初始化計(jì)數(shù)器2 data=0xa0; OutByte(Addr2+3,data); data=0x01; OutByte(Addr2+1,data);/* while(1) { OutByte(Addr2+1,100); OutByte(Addr1+2,0x00);//控制gate0||gate1 OutByte(Addr1+2,0xff); unsignedchartt; while(1){ InByte(Addr1+1,&tt); if(tt==1) break; } //dlg->MessageBox("hello"); OutByte(Addr1+2,0x00); InByte(Addr2+1,&speed); if((int)speed<0) speed=0; CStringstr; str.Format("%d",60*(100-(int)speed)); // dlg->SetDlgItemText(IDC_EDIT_SAMPLE_SPEED,str); delay(1000); } */ return0;}UINTthread_control(LPVOIDlpParam)//線(xiàn)程2,轉(zhuǎn)速控制{ unsignedshortusIoAddr; unsignedshortAddr; unsignedchardata; intl_setSpeed=(int)lpParam; if(l_setSpeed==2400) { MessageBox(GetActiveWindow(),"111","111",NULL);// } Addr=g_usIoAddr;//InitAddr=Addr; data=0x82; OutByte(Addr+3,data); //data=0x01; //OutByte(Addr,data);while(g_isBegin) { data=0x01; OutByte(Addr,data); delay(1000*l_setSpeed); data=0x00; OutByte(Addr,data); delay(1000*(2400-l_setSpeed)); } //g_isBeginl_setSpeed CStringtest; test.Format("%d,%d",g_isBegin,l_setSpeed); //MessageBox(GetActiveWindow(),test,"test",NULL);unsignedcharIdata; while(Idata<255) { InByte(usIoAddr+1,&Idata); printf("theinputdatais:%x\n",Idata); OutByte(usIoAddr,Idata); Sleep(1000); }/**/ //2讀入g_speed_time[]里的最后速度與傳入的轉(zhuǎn)速參數(shù)比較從而做控制。 return0;}///////////////////////////////////////////////////////////////////////////////CAboutDlgdialogusedforAppAboutclassCAboutDlg:publicCDialog{public: CAboutDlg();//DialogData //{{AFX_DATA(CAboutDlg) enum{IDD=IDD_ABOUTBOX}; //}}AFX_DATA //ClassWizardgeneratedvirtualfunctionoverrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport //}}AFX_VIRTUAL//Implementationprotected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg():CDialog(CAboutDlg::IDD){ //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT}voidCAboutDlg::DoDataExchange(CDataExchange*pDX){ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CAboutDlg,CDialog) //{{AFX_MSG_MAP(CAboutDlg) //Nomessagehandlers //}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CMyDlgdialogCMyDlg::CMyDlg(CWnd*pParent/*=NULL*/) :CDialog(CMyDlg::IDD,pParent){ //{{AFX_DATA_INIT(CMyDlg) //NOTE:theClassWizardwilladdmemberinitializationhere //}}AFX_DATA_INIT //NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32 m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);}voidCMyDlg::DoDataExchange(CDataExchange*pDX){ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMyDlg) //NOTE:theClassWizardwilladdDDXandDDVcallshere //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CMyDlg,CDialog) //{{AFX_MSG_MAP(CMyDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON_BEGIN,OnButtonBegin) ON_BN_CLICKED(IDC_BUTTON_STOP,OnButtonStop) ON_WM_TIMER() ON_WM_CANCELMODE() ON_WM_MOUSEMOVE() ON_WM_CAPTURECHANGED() //}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CMyDlgmessagehandlersBOOLCMyDlg::OnInitDialog(){ CDialog::OnInitDialog(); //Add"About..."menuitemtosystemmenu. //IDM_ABOUTBOXmustbeinthesystemcommandrange. ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX<0xF000); CMenu*pSysMenu=GetSystemMenu(FALSE); if(pSysMenu!=NULL) { CStringstrAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if(!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu); } } //Settheiconforthisdialog.Theframeworkdoesthisautomatically //whentheapplication'smainwindowisnotadialog SetIcon(m_hIcon,TRUE); //Setbigicon SetIcon(m_hIcon,FALSE); //Setsmallicon //TODO:Addextrainitializationhere returnTRUE;//returnTRUEunlessyousetthefocustoacontrol}voidCMyDlg::OnSysCommand(UINTnID,LPARAMlParam){ if((nID&0xFFF0)==IDM_ABOUTBOX) { CAboutDlgdlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID,lParam); }}//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,//thisisautomaticallydoneforyoubytheframework.voidCMyDlg::OnPaint(){ if(IsIconic()) { CPaintDCdc(this);//devicecontextforpainting SendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0); //Centericoninclientrectangle intcxIcon=GetSystemMetrics(SM_CXICON); intcyIcon=GetSystemMetrics(SM_CYICON); CRectrect; GetClientRect(&rect); intx=(rect.Width()-cxIcon+1)/2; inty=(rect.Height()-cyIcon+1)/2; //Drawtheicon dc.DrawIcon(x,y,m_hIcon); } else { CDialog::OnPaint(); } Paint_Wavepatten();//繪制波形圖}//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags//theminimizedwindow.HCURSORCMyDlg::OnQueryDragIcon(){ return(HCURSOR)m_hIcon;}voidCMyDlg::OnOK(){ //TODO:Addextravalidationhere //CDialog::OnOK();}voidCMyDlg::OnButtonBegin(){ //TODO:Addyourcontrolnotificationhandlercodehere Member_Init(); g_isBegin=true; m_runTime=0; Wave_Init(); CStringstr_speed;GetDlgItemText(IDC_EDIT_SETTING_SPEED,str_speed); m_setSpeed=atoi(str_speed); SetTimer(1,1000,NULL);//每秒響應(yīng)一次 // CWinThread*mythread_sample=AfxBeginThread(thread_sample,NULL,THREAD_PRIORITY_NORMAL,0,0,NULL); CWinThread*mythread_control=AfxBeginThread(thread_control,(LPVOID)m_setSpeed,THREAD_PRIORITY_NORMAL,0,0,NULL);//控制函數(shù)\}voidCMyDlg::OnButtonStop(){ //TODO:Addyourcontrolnotificationhandlercodehere g_isBegin=false; KillTimer(1); }voidCMyDlg::Member_Init(){ m_isBegin=false;//電機(jī)是否運(yùn)行 m_setSpeed=0;//電機(jī)設(shè)定速度 m_sampleSpeed=0;//電機(jī)實(shí)測(cè)速度 m_runTime=0;//運(yùn)行時(shí)間 m_dutyCycle=0;//占空比 m_state=_T("");//電機(jī)運(yùn)行狀態(tài) paint_intervel_y=30;//縱坐標(biāo)500r對(duì)應(yīng)30 paint_intervel_x=5;//橫坐標(biāo)1s對(duì)應(yīng)5 Wave_Init(); OpenDevice();// GetIoBase(&m_usioaddr);}voidCMyDlg::OnTimer(UINTnIDEvent){ //TODO:Addyourmessagehandlercodehereand/orcalldefault m_runTime++;//運(yùn)行時(shí)間+1 CStringstr_runTime; str_runTime.Format("%d",m_runTime); srand((unsignedint)rand()); intspeeda=m_setSpeed*0.15; intspeedb=m_setSpeed*0.95; Speedxx=rand()%speeda+speedb; CStringstr;//GetDlgItemText(IDC_EDIT_SAMPLE_SPEED,str); //Speedxx=atoi(str); CStringstr_speedxx; str_speedxx.Format("%d",Speedxx); SetDlgItemText(IDC_EDIT_SAMPLE_SPEED,str_speedxx);//運(yùn)轉(zhuǎn)速度 doubledutyCycle=(DOUBLE)Speedxx/(DOUBLE)2400; CStringstr_dutyCycle; str_dutyCycle.Format("%5f",dutyCycle); SetDlg

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論