1 / 9

QEI

QEI. QUADRATURE ENCODER INTERFACE (QEI) Ken Wang ~. CNTERR: QESIDL: 0: 繼續動作 1: 閒置模式 UPDN : 0: timer 向下計數 1: timer 向上計數 QEIM<2:0> : QEI Mode Select bit 111: X4 模式與 MAXCNT 對照 110: X4 模式與 INDX 對照 101: X2 模式與 MAXCNT 對照 100: X2 模式與 INDX 對照 001: 開始 16 位元 timer

nola
Download Presentation

QEI

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. QEI QUADRATURE ENCODER INTERFACE (QEI) Ken Wang ~

  2. CNTERR: QESIDL: 0: 繼續動作 1: 閒置模式 UPDN : 0: timer向下計數 1: timer向上計數 QEIM<2:0> : QEI Mode Select bit 111: X4模式與MAXCNT對照 110: X4模式與INDX對照 101: X2模式與MAXCNT對照 100: X2模式與INDX對照 001: 開始16位元timer SWPAB: 0: 不交換 1: QEA與QEB交換 TQGATE: 觸發準位

  3. TQCKPS <1,0> : //11 = 1:256 prescale value //10 = 1:64 prescale value //01 = 1:8 prescale value //00 = 1:1 prescale value PRSRES: 0:不重置繼續計數 1:計數值重置 TQCS:選擇計數源 0:內頻 1:外頻 UDPN SRC: 0: timer計數方向由QEB控制 1: timer計數方向由UPDN控制 POSCNT: 16位元上/下數計數器 MAXCNT: 計數器的最大值

  4. 程 式 部 分 用訊號產生器當作輸入之命令

  5. #include <p30F4011.h> //呼叫p30F3011(IC)指令巨集 • #include <math.h> • unsigned int s=0,icount=0,qot=0; • unsigned int QEI_Old = 0 ; • unsigned int QEI_New = 0 ; • unsigned int QEI_Diff ; • _FWDT(WDT_OFF); • void Init_Timer1( void ) • { • T1CON = 0; • IFS0bits.T1IF = 0; • IPC0bits.T1IP = 7; • IEC0bits.T1IE = 1; • PR1 = XXXXX; // 20MHz/8/XXXXX=?KHz • T1CONbits.TCS = 0; • T1CONbits.TCKPS=X; //TCKPS<1:0>: Timer Input Clock Prescale Select bits • //11 = 1:256 prescale value • //10 = 1:64 prescale value • //01 = 1:8 prescale value • //00 = 1:1 prescale value • T1CONbits.TON=1; • }

  6. void IO_Initial( void ) • { • TRISB = 0x30; // 0b 0000 0000 0011 0000 // bit4.5當成輸入 • TRISE = 0x00; // E全部設為輸出 • } • void _ISR _T1Interrupt(void) • { • if(++icount==N) • { • QEI_Old = QEI_New ; • QEI_New=POSCNT; • if ( QEICONbits.UPDN ) // 馬達正轉時的計算 • { • if ( QEI_New >= QEI_Old ) // 計算單位時間內的旋轉數量 • QEI_Diff = QEI_New - QEI_Old ; • else // 溢位時的處理 • QEI_Diff = QEI_New + ( 65536 - QEI_Old ) ; • } icount=0; //將icount歸0 • qot+=QEI_Diff; //將Diff做的結果給qot做累加 • s++; • } • if(s==10) • { • s=0; //s歸0 • qot/=10; //qot累加十次後取平均值 • PORTE=qot; //從E port輸出 • qot=0; //qot歸0 • } • IFS0bits.T1IF = 0; //中斷關閉 • }

  7. void Qei_Initial(void) • { • QEICON=0x0700; //設定0000 0111 0000 0000 • POSCNT=0x0; //16位元計數初始值設定 • MAXCNT=0xffff; //設定計數器最大值65535 • QEICONbits.CNTERR=1; //設定啟動 • } • int main(void) • { • ADPCFG=0xffff; //設定為一般I/O腳位 • IO_Initial(); • Qei_Initial(); • Init_Timer1(); while(1); • } • 頻率計算:(訊號產生器頻率/Time頻率)*4

  8. 題目: • Time設定

More Related