1 / 18

4-13 ETM 輸出 PWM

4-13 ETM 輸出 PWM. HT66F50. ETM (Standard type TM) 提供 5 種模式. Compare match output Timer/Counter PWM output Input Capture Single pulse output. ETM. 10bit upcounter (TM1D[9:0]) 由 T1CK[2:0] 選擇不同時脈緣 與 TM1A[9:0], TM1B[9:0], T1RP[2:0] 比較. ETM 模式有 CCR 暫存器 (TM1A, TM1B)

herve
Download Presentation

4-13 ETM 輸出 PWM

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. 4-13 ETM輸出PWM HT66F50

  2. ETM (Standard type TM)提供5種模式 • Compare match output • Timer/Counter • PWM output • Input Capture • Single pulse output

  3. ETM • 10bit upcounter (TM1D[9:0]) 由 T1CK[2:0] 選擇不同時脈緣 與 TM1A[9:0], TM1B[9:0], T1RP[2:0] 比較

  4. ETM 模式有CCR暫存器 (TM1A, TM1B) • TM1C1,TM1C2,TM1C0三個特殊暫存器設定工作模式,計數時脈源

  5. 2-5-3 ETM 模式操作於Compare match output • 當T1CCLR=1,PWM之Duty cycle由TM1A及TM1B控制,波型由TP1B腳位輸出,TP1A強制為一般IO • 當T1CCLR=0,支援雙通道PWM輸出,由TP1A,TP1B腳位輸出,週期由T1RP[2:0]決定, TM1A及TM1B控制TP1A,TP1B, PWM之佔空比

  6. TM1C0 控制暫存器 T1PAU T1CK2 T1CK1 T1CK0 T1ON T1RP2 T1RP1 T1RP0 Bit 7 6 5 4 3 2 1 0 Bit [2 1 0 ] ; TnRP2 TnRP1 TnRP0 = 000 , 週期= 1024x fINT-1 =100,週期= 512x fINT-1 = 001 ,週期= 128x fINT-1 =101 ,週期= 640x fINT-1 = 010 ,週期= 256x fINT-1 =110 ,週期= 768x fINT-1 = 011 ,週期= 384x fINT-1 =111 ,週期= 896x fINT-1

  7. TM2C0 控制暫存器(表2-5-18) n=2 for HT66F50 TnPAU TnCK2 TnCK1 TnCK0 TnON TnRP2 TnRP1 TnRP0 Bit 7 6 5 4 3 2 1 0 Bit [7] ; TnPAU = 1, 暫停計數 = 0, 繼續計數 Bit [6 5 4] ; TnCK2 TnCK1 TnCK0 = 000 , fINT= fsys/4 =100, fINT= fINT = 001 , fINT= fsys =101 ,保留 = 010 , fINT= fsys/16 =110 , fINT=TCKn = 011 , fINT= fsys/64 =111 , fINT= TCKn’ Bit [3] ;TnON =1 ,開始計數 =0,停止計數

  8. TM2C0 控制暫存器 TnPAU TnCK2 TnCK1 TnCK0 TnON - - - Bit 7 6 5 4 3 2 1 0 Bit 2:0 保留

  9. TM2C1 控制暫存器 TnM1 TnM0 TnIO1 TnIO0 TnOC TnPOL TnDPX TnCCLR Bit 7 6 5 4 3 2 1 0 Bit [7 6] ; TnM1 TnM0 = 00 , STM為比對吻合輸出模式 = 01 , STM為輸入補捉模式 = 10 , STM為PWM / single pulse mode = 11 , STM為計時/計數

  10. TM2C1 控制暫存器 TnM1 TnM0 TnIO1 TnIO0 TnOC TnPOL TnDPX TnCCLR Bit 7 6 5 4 3 2 1 0 Bit [5 4] ;TnIO[1:0]: TP2_0, TP2_1 為功能選擇位元 若STM為比對吻合輸出 T2M[1:0]=00 TP2_0, TP2_1 為輸出 00: 比對吻合時,輸出不變 10: 比對吻合時,輸出高態 01: 比對吻合時,輸出低態 11: 比對吻合時,輸出轉態 若STM為比對輸入補捉 T2M[1:0]=01 TP2_0, TP2_1 為輸入 00: 在TP2_0, TP2_1輸入為正緣時,記錄TM2D 01: 在TP2_0, TP2_1輸入為負緣時,記錄TM2D 10: 在TP2_0, TP2_1輸入為負緣及正緣時,記錄TM2D 11: 停止輸入補捉功能 若STM為PWM/Single Pulse Mode,T2M[1:0]=10 00: 強制輸出為非啟動 10: PWM輸出 01: 強制輸出為啟動 11: Single Pulse Mode 若STM為計時/計數, T2M[1:0]=11 無作用

  11. TM2C1 控制暫存器 TnM1 TnM0 TnIO1 TnIO0 TnOCTnPOL TnDPX TnCCLR Bit 7 6 5 4 32 1 0 Bit [3] ;TnOC 輸出準位控制位元 若STM為比對吻合輸出 TP2M[1:0]=00 1: 首次比對吻合前,輸出維持在1 0:首次比對吻合前,輸出維持在0 若STM為PWM/Single Pulse Mode,T2M[1:0]=10 1: 輸出啟動準位為1 0: 輸出啟動準位為0 Bit [2] ; TnPOL 輸出極性控制位元 1: 輸出反向 0: 輸出不反向 Bit [0] ; TnCCLR =1, 當比較器A 比對吻合時清除計數器 =0,當比較器p 比對吻合時或計數器溢位清除計數器

  12. 4-13 pwm ;PROGRAM : 4-13.ASM ;FUNCTION: pwm by etm #INCLUDE HT66F50.INC #INCLUDE 4-13.INC ;-------------------------------------------------------------------- MY_DATA .SECTION 'DATA' ;== DATA SECTION == DEL1 DB ? DEL2 DB ? DEL3 DB ? INDEX DB ? ;-------------------------------------------------------------------- MY_CODE .SECTION AT 0 'CODE' ;== PROGRAM SECTION == ORG 00H ;HT-66XX RESET VECTOR

  13. MOV A,08h ; MOV CP0C,A ; Disable cp0 MOV CP1C,A ; Disable cp1 CLR ACERL ;Disable ADC input SET SW_BRIGHTC SET SW_DARKC SET SW_BRIGHTPU SET SW_DARKPU MOV A,01110000B ;set TP1B_[0:2] as TP1 fun. MOV TMPC0,A MOV A,00000000B ;fint=fsys/4 MOV TM1C0,A

  14. MOV A,10000001B ;TM1A in PWM o/p mode MOV TM1C1,A ;TM1D is cleared by TM1A compare match MOV A,10101000B ;TP1B is working in PWM o/p mode MOV TM1C2,A ;active high, non-invert, edge-aligned MOV A,LOW 1024-1 ;SET DUTY 1024 us MOV TM1AL,A MOV A,HIGH 1024-1 MOV TM1AH,A MOV A,11011100B ;SET TP1B[012] as output mode ANDM A,PCC ANDM A,PC ;select non-inverted MOV A,5 MOV INDEX, A SET T1ON ;start ETM

  15. MAIN: MOV A,INDEX ADD A,OFFSET TAB_PWM MOV TBLP, A TABRDL TM1BL ;load TM1CCRB indexed by index MOV A,TBLH MOV TM1BH,A CALL DELAY ;delay 0.5sec WAIT: SNZ SW_BRIGHT ;SW_BRIGHT pressed? JMP BRIGHTER ;yes SNZ SW_DARK ;NO. SW_DARK pressed? JMP WAIT ;NO

  16. DARKER: DECA INDEX ;yes. Index-1 SZ ACC.7 ;less than 0? JMP WAIT ;yes MOV INDEX,A JMP MAIN BRIGHTER: INCA INDEX ;yes. Index+1 SUB A,10 SZ C ;>=10 JMP WAIT ;yes INC INEDX ;NO. INDEX+1 JMP MAIN

  17. 50*10ms DELAY PROC MOV A,50 MOV DEL1,A ;SET DEL1 COUNTER DEL_1: MOV A,30 MOV DEL2,A ;SET DEL2 COUNTER DEL_2: MOV A,110 MOV DEL3,A ;SET DEL3 COUNTER DEL_3: SDZ DEL3 ;DEL3 DOWN COUNT JMP DEL_3 SDZ DEL2 ;DEL2 DOWN COUNT JMP DEL_2 SDZ DEL1 ;DEL1 DOWN COUNT JMP DEL_1 RET DELAY ENDP

  18. ORG LASTPAGE TAB_PWM: DC 100 DC 200 DC 300 DC 400 DC 500 DC 600 DC 700 DC 800 DC 900 DC 1000

More Related