![創(chuàng)維特試驗箱上實現(xiàn)步進(jìn)電機的運轉(zhuǎn)_第1頁](http://file4.renrendoc.com/view/5dd65e72eddc29776a1f4f55e4c814bf/5dd65e72eddc29776a1f4f55e4c814bf1.gif)
![創(chuàng)維特試驗箱上實現(xiàn)步進(jìn)電機的運轉(zhuǎn)_第2頁](http://file4.renrendoc.com/view/5dd65e72eddc29776a1f4f55e4c814bf/5dd65e72eddc29776a1f4f55e4c814bf2.gif)
![創(chuàng)維特試驗箱上實現(xiàn)步進(jìn)電機的運轉(zhuǎn)_第3頁](http://file4.renrendoc.com/view/5dd65e72eddc29776a1f4f55e4c814bf/5dd65e72eddc29776a1f4f55e4c814bf3.gif)
![創(chuàng)維特試驗箱上實現(xiàn)步進(jìn)電機的運轉(zhuǎn)_第4頁](http://file4.renrendoc.com/view/5dd65e72eddc29776a1f4f55e4c814bf/5dd65e72eddc29776a1f4f55e4c814bf4.gif)
![創(chuàng)維特試驗箱上實現(xiàn)步進(jìn)電機的運轉(zhuǎn)_第5頁](http://file4.renrendoc.com/view/5dd65e72eddc29776a1f4f55e4c814bf/5dd65e72eddc29776a1f4f55e4c814bf5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
-.z嵌入式系統(tǒng)實驗報告一、實驗時間 2015年5月5日14:30~21:30二、實驗地點 一實驗樓401機房三、實驗?zāi)康?1、在創(chuàng)維特試驗箱上實現(xiàn)步進(jìn)電機的運轉(zhuǎn)。四、實驗步驟1、了解步進(jìn)電機的運作方式。2、編譯驅(qū)動代碼代碼:staticstructtimer_listttimer;staticintDevice_Open=0;staticintnum=2;/*usedtocontrolthespeedofthestepper*/staticenum{off,clockwise,anticlockwise}status=off;/*usedtoindicateandsetthestatusofthestepper*/staticintrow=0;unsignedcharpulse_table[]={ 0*05,0*09,0*0a,0*06,};staticchar*out_base; /*kerneladdr*/int device_ioctl(structinode*,structfile*,unsignedint,unsignedlong); staticvoidtime_tick(unsignedlongdata){ staticinti=0;// printk("time_tick\n"); switch(status) { caseoff: break; caseclockwise: if(++i==num){ i=0; if(row==4)row=0; writeb(pulse_table[row++],out_base); } ttimer.e*pires=jiffies+5; //settimer add_timer(&ttimer); //addtimer break; caseanticlockwise: if(++i==num){ i=0; if(row==-1)row=3; writeb(pulse_table[row--],out_base); } ttimer.e*pires=jiffies+5; //settimer add_timer(&ttimer); //addtimer break; default: break; }}/*Thisfunctioniscalledwheneveraprocessattempts*toopenthedevicefile*/staticintdevice_open(structinode*inode,structfile*file){printk("DeviceOpen\n");/*Wedon'twanttotalktotwoprocessesatthe*sametime*/if(Device_Open)return-EBUSY;Device_Open++;MOD_INC_USE_COUNT;return0;}/*Thisfunctioniscalledwhenaprocessclosesthe*devicefile.Itdoesn'thaveareturnvaluebecause*itcannotfail.Regardlessofwhatelsehappens,you*shouldalwaysbeabletocloseadevice(in2.0,a2.2*devicefilecouldbeimpossibletoclose).*/staticintdevice_release(structinode*inode,structfile*file){printk(("DeviceRelease\n"));/*We'renowreadyforourne*tcaller*/Device_Open--;MOD_DEC_USE_COUNT;return0;}/*Thisfunctioniscalledwheneveraprocesswhich*hasalreadyopenedthedevicefileattemptsto*readfromit.*/staticssize_tdevice_read(structfile*file,char*buffer, /*Thebuffertofillwiththedata*/size_tlength, /*Thelengthofthebuffer*/loff_t*offset) /*offsettothefile*/{ return0;}/*Thisfunctioniscalledwhensomebodytriesto*writeintoourdevicefile.*/staticssize_tdevice_write(structfile*file,constchar*buffer,size_tlength,loff_t*offset){ return0;};/*Thisfunctioniscalledwheneveraprocesstriesto*doanioctlonourdevicefile.Wegettwoe*tra*parameters(additionaltotheinodeandfile*structures,whichalldevicefunctionsget):thenumber*oftheioctlcalledandtheparametergiventothe*ioctlfunction.**Iftheioctliswriteorread/write(meaningoutput*isreturnedtothecallingprocess),theioctlcall*returnstheoutputofthisfunction.*/intdevice_ioctl(structinode*inode,structfile*file,unsignedintioctl_num,/*Thenumberoftheioctl*/unsignedlongioctl_param)/*Theparametertoit*/{structstepper*s;printk(("DeviceIoctl\n"));/*Switchaccordingtotheioctlcalled*/switch(ioctl_num){caseIOCTL_SET_MSG:/*Receiveapointertoamessage(inuserspace)*andsetthattobethedevice'smessage.*//*Gettheparametergiventoioctlbytheprocess*/ s=(structstepper*)ioctl_param; printk("CmdID=%d\n",s->CmdID); switch(s->CmdID) { case0:/*start*/ status=clockwise; ttimer.e*pires=jiffies+1;//startthetimer add_timer(&ttimer);//addtimer printk("clockwise\n"); break; case1:/*stop*/ status=off;//changethestatusofthestepper printk("off\n"); break; case2:/*reverse*/ if(status==clockwise){ status=anticlockwise; //changethestatusofthestepper printk("anticlockwise\n"); } elseif(status==anticlockwise){ status=clockwise; printk("clockwise\n"); } break; case3:/*speedup*/ if(num!=1)num--; break; case4:/*speeddown*/ num++; break;}break;caseIOCTL_GET_MSG:printk(("DeviceIoctlGET_MSG\n"));break;}return0;};/*ModuleDeclarations****************************//*Thisstructurewillholdthefunctionstobecalled*whenaprocessdoessomethingtothedevicewe*created.Sinceapointertothisstructureiskeptin*thedevicestable,itcan'tbelocalto*init_module.NULLisforunimplementedfunctions.*/structfile_operationsFops={ .read =device_read, .write =device_write, .open =device_open, .release =device_release, .ioctl =device_ioctl };/*Initializethemodule-Registerthecharacterdevice*/staticint__initstepper_module_init(void){intret_val;/*Registerthecharacterdevice(atleasttry)*/ret_val=register_chrdev(MAJOR_NUM,DEVICE_NAME,&Fops);/*Negativevaluessignifyanerror*/if(ret_val<0){printk("%sfailedwith%d.\n","Sorry,registeringthecharacterdevice",ret_val);returnret_val;}printk("%sThemajordevicenumberis%d.\n","Registerationisasuccess.",MAJOR_NUM);printk("Ifyouwanttotalktothedevicedriver,\n");printk("you'llhavetocreateadevicefile.\n");printk("Wesuggestyouuse:\n");printk("mknod/dev/stepperc%d0\n",MAJOR_NUM);printk("Thedevicefilenameisimportant,because\n");printk("theioctlprogramassumesthat'sthe\n");printk("fileyou'lluse.\n");if(check_region(0*28000006,1)){printk("Thestepperportisusedbyanothermodule.\n");return-1;}/*I/Oaddrmap*/request_region(0*28000006,1,DEVICE_NAME);out_base=(char*)ioremap(0*28000006,1);init_timer(&ttimer);//initializetimerttimer.function=time_tick;//timerprocessingfunctionreturn0;};/*Cleanup-unregistertheappro
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 機房設(shè)備維護(hù)與保養(yǎng)培訓(xùn)教程
- 2024秋七年級語文上冊 第四單元 13《植樹的牧羊人》說課稿 新人教版
- 環(huán)保理念在商業(yè)空間設(shè)計中的應(yīng)用研究
- 5琥珀說課稿-2023-2024學(xué)年四年級下冊語文統(tǒng)編版
- 現(xiàn)代學(xué)校管理體系中的遠(yuǎn)程教育策略
- 環(huán)保材料在現(xiàn)代建筑設(shè)計中的應(yīng)用
- 2024年五年級英語下冊 Unit 2 Can I help you Lesson 9說課稿 人教精通版(三起)
- 18富饒的西沙群島 第二課時(說課稿)-2024-2025學(xué)年語文三年級上冊統(tǒng)編版
- 8《蝴蝶的家》說課稿-2024-2025學(xué)年四年級上冊語文統(tǒng)編版 -
- 現(xiàn)代商業(yè)綜合體的綠色建筑與節(jié)能技術(shù)分享
- 城市基礎(chǔ)設(shè)施修繕工程的重點與應(yīng)對措施
- 油氣勘探風(fēng)險控制-洞察分析
- GB 12710-2024焦化安全規(guī)范
- 2022年中考化學(xué)模擬卷1(南京專用)
- 【??途W(wǎng)】2024秋季校園招聘白皮書
- 2024-2025銀行對公業(yè)務(wù)場景金融創(chuàng)新報告
- 2025屆鄭州市高三一診考試英語試卷含解析
- 《我國個人所得稅制下稅收征管問題研究》
- 建筑工程三通一平技術(shù)方案
- 水庫工程施工組織設(shè)計
- 氣流粉碎機課件
評論
0/150
提交評論