<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > 基于Mega128編碼器控制步進(jìn)電機的平衡系統

基于Mega128編碼器控制步進(jìn)電機的平衡系統

作者: 時(shí)間:2016-11-29 來(lái)源:網(wǎng)絡(luò ) 收藏
提起編碼器,可能大家并不陌生,因為這東西真的很常用,現在的主流編碼器一般精度都是比較高的,基本上都是基于光柵的。畢竟用硬件用電刷做到512精度以上是很困難的,而且成本也是很高的,這里我就不多說(shuō)什么了。
編碼器一般共有三個(gè)主通道,每個(gè)主通道有分為兩個(gè)分支;一個(gè)VCC,一個(gè)GND,一條屏蔽線(xiàn)。前兩個(gè)通道一般是比較精確的脈沖信號,且之間有四分之一左右的相位差用來(lái)判斷正反轉的,第三通道基本上是旋轉一周才會(huì )有一個(gè)脈沖信號的那種。

提到步進(jìn)電機,就一定要有一個(gè)合適的電機驅動(dòng),個(gè)人是比較喜歡用L298n這款芯片的,因為它價(jià)格低,操作比較簡(jiǎn)單。
對于這個(gè)系統,我是用128的外部中斷的下降沿觸發(fā)方式來(lái)捕捉編碼器的脈沖的,硬件連接方面電機驅動(dòng)和主控芯片一定要注意地線(xiàn)的連接。
下面是程序的完整代碼下載地址:http://www.51hei.com/f/bmma.rar

這里是delay.h====================================================================//根據CPU時(shí)鐘頻率選擇#ifndef F_CPU//#define F_CPU 7372800//#define F_CPU 8000000//#define F_CPU 11059200//#define F_CPU 12000000#define F_CPU 16000000#endif//------------------------------------------------------------------------------//1、2、3、5和10us的精確延時(shí),用于需要精確時(shí)間的場(chǎng)合,比如DS18B20//------------------------------------------------------------------------------#if   F_CPU == 7372800#define DELAY_1US NOP();NOP();NOP();NOP();NOP();NOP();NOP()#define DELAY_2US DELAY_1US;DELAY_1US#define DELAY_3US DELAY_1US;DELAY_1US;DELAY_1US#define DELAY_5US DELAY_2US;DELAY_3US#define DELAY_10US DELAY_5US;DELAY_5US#elif F_CPU == 8000000#define DELAY_1US NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP()#define DELAY_2US DELAY_1US;DELAY_1US#define DELAY_3US DELAY_1US;DELAY_1US;DELAY_1US#define DELAY_5US DELAY_2US;DELAY_3US#define DELAY_10US DELAY_5US;DELAY_5US#elif F_CPU == 11059200#define DELAY_1US NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP()#define DELAY_2US DELAY_1US;DELAY_1US#define DELAY_3US DELAY_1US;DELAY_1US;DELAY_1US#define DELAY_5US DELAY_2US;DELAY_3US#define DELAY_10US DELAY_5US;DELAY_5US#elif F_CPU == 12000000#define DELAY_1US NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP()#define DELAY_2US DELAY_1US;DELAY_1US#define DELAY_3US DELAY_1US;DELAY_1US;DELAY_1US#define DELAY_5US DELAY_2US;DELAY_3US#define DELAY_10US DELAY_5US;DELAY_5US#elif F_CPU == 16000000#define DELAY_1US NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP()#define DELAY_2US DELAY_1US;DELAY_1US#define DELAY_3US DELAY_1US;DELAY_1US;DELAY_1US#define DELAY_5US DELAY_2US;DELAY_3US#define DELAY_10US DELAY_5US;DELAY_5US#endif//------------------------------------------------------------------------------//函數聲明//------------------------------------------------------------------------------void delay_nus(unsigned int);//<10us時(shí)誤差較大,用于無(wú)須精確延時(shí)的場(chǎng)合void delay_nms(unsigned int);#endif//__DELAY_H====================================================================這里是delay.c====================================================================//|文件名稱(chēng)|delay.c//|--------|--------------------------------------------------------------------//|描    述|延時(shí)文件//|--------|--------------------------------------------------------------------//|說(shuō)    明|delay_us(unsigned int time)用于不需精確定時(shí)的場(chǎng)合,<10us時(shí)誤差較大//|        |若要精確定時(shí)用delay.h里的宏//|--------|--------------------------------------------------------------------//|調用文件|delay.h//|--------|--------------------------------------------------------------------//|作    者|//|--------|--------------------------------------------------------------------//|版    本|//|--------|--------------------------------------------------------------------//|時(shí)    間|//|--------|--------------------------------------------------------------------//|E-mail  |//|--------|--------------------------------------------------------------------//|開(kāi)發(fā)環(huán)境|ICCAVR6.31//==============================================================================#include "delay.h"#if F_CPU == 7372800void delay_nus(unsigned int time){unsigned int i;for(i=0;i
				
            
                
			
							
上一頁(yè) 1 2 下一頁(yè)

評論


技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>