Presentation is loading. Please wait.

Presentation is loading. Please wait.

4-13 ETM輸出PWM HT66F50.

Similar presentations


Presentation on theme: "4-13 ETM輸出PWM HT66F50."— 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

5 TM1C1,TM1C2,TM1C0三個特殊暫存器設定工作模式,計數時脈源
ETM 模式有CCR暫存器 (TM1A, TM1B) TM1C1,TM1C2,TM1C0三個特殊暫存器設定工作模式,計數時脈源 TM1C0 T1PAU T1CK2 T1CK1 T1CK0 T1ON T1RP2 T1RP1 T1RP0 TM1C1 TM1C2

6

7

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

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

10 TM1C1 控制暫存器(表2-5-25) Bit 7 6 5 4 3 2 1 0 Bit [7 6] ; T1AM[1 0]
T1AM1 T1AM0 T1AIO1 T1AIO0 T1AOC T1APOL T1CDN T1CCLR Bit Bit [7 6] ; T1AM[1 0] = 00, CCRA 為 compare match output mode = 01, CCRA 為 input capture mode = 10, CCRA 為 pwm/single pulse output mode = 11, CCRA 為 timer/counter mode Bit [5 4] ; TP1A 功能選擇 CCRA 為 compare match output mode, T1AM[1 0]=00 , TP1A為輸出 : 比對吻合時 TP1A 不變 : 比對吻合時TP1A 輸出1 01:比對吻合時TP1A 輸出0 11: 比對吻合時TP1A 轉態 CCRA 為 input capture mode, T1AM[1 0]=01 , TP1A為輸入 00: 在TP1A 正緣, 記錄當前TM1D之值 01: 在TP1A 負緣, 記錄當前TM1D之值 10: 在TP1A 負緣及正緣, 記錄當前TM1D之值 11: 停止input capture mode

11 TM1C1 控制暫存器(表2-5-25) Bit 7 6 5 4 3 2 1 0 Bit [5 4] ; TP1A 功能選擇
T1AM1 T1AM0 T1AIO1 T1AIO0 T1AOC T1APOL T1CDN T1CCLR Bit Bit [5 4] ; TP1A 功能選擇 CCRA 為 pwm/single pulse output mode, T1AM[1 0]=10 00: 強制 TP1A 為 inactive : PWM 輸出 01:強制 TP1A 為 active : 單脈衝輸出 CCRA 為 timer/counter mode, T1AM[1 0]=11 無作用 Bit [0] ; T1CCLR 1: 當 TM1A 比對吻合時清除計數器 0: 當 TM1RP 比對吻合或計數器溢位時清除計數器

12 TM1C2 控制暫存器(表2-5-26) T1BM1 T1BM0 T1BIO1 T1BIO0 T1BOC T1BPOL T1PWM1 T1PWM0 Bit Bit [7 6] ; TM1 CCRB 模式控 功能選擇 = 00, CCRB 為 compare match output mode = 01, CCRB 為 input capture mode = 10, CCRB 為 pwm/single pulse output mode = 11, CCRB 為 timer/counter mode Bit [5 4] ; T1BIO 為 TP1B_0, TP1B_1, TP1B_2功能選擇 CCRB 為 compare match output mode, T1BM[1 0]=00 00: 比對吻合時輸出不變 : 比對吻合時 輸出1 01:比對吻合時 輸出 : 比對吻合時輸出1轉態 CCRB 為 input capture mode, T1BM[1 0]=01 ,為輸入 00: 在輸入信號為正緣, 記錄當前TM1D之值 01: 在輸入信號為負緣, 記錄當前TM1D之值 10: 在輸入信號為負緣及正緣, 記錄當前TM1D之值 11: 停止input capture mode

13 TM1C2 控制暫存器(表2-5-26) T1BM1 T1BM0 T1BIO1 T1BIO0 T1BOC T1BPOL T1PWM1 T1PWM0 Bit Bit [5 4] ; T1BIO 為 TP1B_0, TP1B_1, TP1B_2功能選擇 CCRB 為 pwm/single pulse output mode, T1BM[1 0]=10 00: 強制輸出 為 inactive : PWM 輸出 01:強制輸出 為 active : 單脈衝輸出 CCRA 為 timer/counter mode, T1AM[1 0]=11 無作用 Bit [3] ; T1BOC 為 TP1B_0, TP1B_1, TP1B_2 輸出控制位元 CCRB 為 compare match output mode, T1BM[1 0]=00 ,輸出功能 1: 首次比對吻合前使輸出維持在 1 0: 首次比對吻合前使輸出維持在 0 1:輸出 為1 active high 0 :輸出 為0 active low

14 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 H ;HT-66XX RESET VECTOR

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

16 MOV A,10000001B ;TM1A in PWM o/p mode
MOV TM1C1,A ;TM1D is cleared by TM1A compare match MOV A, B ;TP1B is working in PWM o/p mode MOV TM1C2,A ;active high, non-invert, edge-aligned MOV A,LOW ;SET DUTY 1024 us MOV TM1AL,A MOV A,HIGH MOV TM1AH,A MOV A, B ; 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

17 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

18 DARKER: DECA INDEX ;yes. Index-1 SZ ACC. 7 ;less than 0
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

19 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

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

21 TMPC0 T1ACP0 T1BCP2 T1BCP1 T1BCP T0CP1 T0CP0


Download ppt "4-13 ETM輸出PWM HT66F50."

Similar presentations


Ads by Google