Professional Documents
Culture Documents
HT66F018 PTM IR Carrier Function Application Example: D/N HA0 326E
HT66F018 PTM IR Carrier Function Application Example: D/N HA0 326E
HT66F018 PTM IR Carrier Function Application Example: D/N HA0 326E
D/N:HA0326E
Introduction
The HT66F018 PTM has rich functionality. After a simple setup procedure, the PTM PWM
function can be selected to output a variety of IR carrier signals, such as 38K or 40K
frequency. When coupled with a timing program, it can send out IR code waveforms, for
example to emulate an NEC format waveform. The following content will explain how to
use the PTM combined with the CTM to achieve the NEC IR coding.
The HT66F018 PTM relevant registers are shown in Table 1. TMnC0 and TMnC1 control
the PTM on/off function, operation mode selection, output function and other settings.
TMnDL and TMDH are read-only registers to store the internal counter current value;
TMnAL and TMnAH configure the CCRA value while the TMnRPL and TMnRPH registers
configure the CCRP value. For more details, refer to the datasheet content.
Table 1
1
HT66F018 PTM IR Carrier Function Application Example
2
HT66F018 PTM IR Carrier Function Application Example
3
HT66F018 PTM IR Carrier Function Application Example
(1) As shown in Figure 1 and Figure 2, the NEC IR coding requires several time widths:
9ms, 4.5ms, 0.56ms, 2.24ms and 108ms. Taking 560s as the minimum time
width, then the other times will be multiples of this value.
(2) 1/(fSYS/4) CCRA= 1/(2MHz) CCRA = 560us, CCRA = 1120 = 460H。
(3) Set TM2Al to 60H and TM2AH to 04H.
5. TM2 interrupt setting: Enable MF1E, T2AE and the global interrupt EMI to enable the
TM2 interrupt.
Setup Note: when a TM2 interrupt occurs, the system will automatically clear the
Multi-Function request flag MF1F. But the CCRA Compare Interrupt flag T2AF will not
be automatically cleared and needs to be manually cleared by the application
program.
4
HT66F018 PTM IR Carrier Function Application Example
(1) The NEC IR coding timing procedure: each time a time-out flag occurs, when the
time is up, the flag will be set high. Because the TM2 has set the minimum time as
560s, then to achieve times of 9ms, 4.5ms, 2.24ms and 108ms, these require 16,
8, 4 and 193 timer cycles respectively.
(2) NEC IR coding waveform transmission:
As the key is pressed, PA7 will output the NEC IR coded waveforms. When
sending the NEC IR coding high level part, it will output the 38kHz carrier, in which
case TM1 and TM2 will be switched on simultaneously. When sending the NEC IR
coded low level part, TM1 will stop generating the 38kHz carrier, and only TM2
continues to execute timing operations.
ISR_2240us:
SNZ f_2240us_start
JMP ISR_108ms
INC r_timer_count ; 2.24ms
MOV A,r_timer_count
SUB A,4
5
HT66F018 PTM IR Carrier Function Application Example
SNZ C
JMP ISR_108ms
CLR r_timer_count
SET f_2240us
ISR_108ms:
SNZ f_108ms_start
JMP ISR_sendcode
INC r_108ms_COUNT
MOV A,r_108ms_COUNT ; 108ms
SUB A,193
SNZ C
JMP ISR_sendcode
CLR r_108ms_COUNT
SET f_108ms
ISR_sendcode:
MOV A,r_INDEX
XOR A,1
SNZ Z
JMP ISR_addr1_send
SNZ f_9ms
JMP ISR_EXIT
CLR f_9ms
CLR T1ON
CLR PA7 ; stop IR carrier generator
CLR PAC7
CLR f_9ms_start
SNZ f_longpress
JMP ISR_4500us_send
CLR f_longpress
SET f_2240us_start
CLR r_timer_count
MOV A,6
MOV r_INDEX,A
JMP ISR_EXIT
ISR_4500us_send:
SET f_4500us_start
CLR r_timer_count
MOV A,2
MOV r_INDEX,A
JMP ISR_EXIT
ISR_addr1_send:
MOV A,r_INDEX
XOR A,2
SNZ Z
JMP ISR_logic_judge
SNZ f_4500us
JMP ISR_EXIT
CLR f_4500us
CLR f_4500us_start
INC r_DATA_COUNT
CLR f_560us
SET T1ON
MOV A,ADDR_1
MOV r_SENDCODE,A
MOV A,3
MOV r_INDEX,A
JMP ISR_EXIT
ISR_logic_judge:
MOV A,r_INDEX
XOR A,3
6
HT66F018 PTM IR Carrier Function Application Example
SNZ Z
JMP ISR_logic_send
SNZ f_560us
JMP ISR_EXIT
CLR f_560us
CLR T1ON
CLR PA7
CLR PAC7
MOV A,r_SENDCODE
CLR C
RRC ACC
SNZ C
JMP LOGIC_0_LOOP
MOV r_SENDCODE,A
SET f_2240us_start
CLRr_timer_count
SET f_logic_1
JMP LOGIC_EXIT
LOGIC_0_LOOP:
MOV r_SENDCODE,A
CLR f_560us
SET f_logic_0
LOGIC_EXIT:
MOV A,4
MOV r_INDEX,A
JMP ISR_EXIT
ISR_logic_send:
MOV A,r_INDEX
XOR A,4
SNZ Z
JMP ISR_108ms_JUDGE
SNZ f_logic_1
JMP LOGIC_0
SNZ f_2240us
JMP ISR_EXIT
CLR f_2240us_start
CLR f_2240us
CLR f_logic_1
JMP ISR_logic_send_EXIT
LOGIC_0:
SNZ f_logic_0
JMP ISR_logic_send_EXIT
SNZ f_560us
JMP ISR_EXIT
CLR f_560us
CLR f_logic_0
ISR_logic_send_EXIT:
SDZ r_COUNT
JMP ISR_DATALOAD_UNFINISHED
INC r_DATA_COUNT
MOV A,r_DATA_COUNT
XOR A,2
SNZ Z
JMP ISR_DATA_LOAD
MOV A,ADDR_2
MOV r_SENDCODE,A
JMP ISR_DATALOAD_FINISHED
ISR_DATA_LOAD:
MOV A,r_DATA_COUNT
XOR A,3
SNZ Z
7
HT66F018 PTM IR Carrier Function Application Example
JMP ISR_DATA_COM_LOAD
MOV A,DATA
MOV r_SENDCODE,A
JMP ISR_DATALOAD_FINISHED
ISR_DATA_COM_LOAD:
MOV A,r_DATA_COUNT
XOR A,4
SNZ Z
JMP ISR_LOAD_EXIT
MOV A,DATA
XOR A,0FFH
MOV r_SENDCODE,A
JMP ISR_DATALOAD_FINISHED
ISR_LOAD_EXIT:
MOV A,r_DATA_COUNT
XOR A,5
SNZ Z
JMP ISR_EXIT
CLR r_DATA_COUNT
MOV A,5
MOV r_INDEX,A
JMP ISR_EXIT
ISR_DATALOAD_FINISHED:
CLR f_560us
SET T1ON
MOV A,8
MOV r_COUNT,A
MOV A,3
MOV r_INDEX,A
JMP ISR_EXIT
ISR_DATALOAD_UNFINISHED:
CLR f_560us
SET T1ON
MOV A,3
MOV r_INDEX,A
JMP ISR_EXIT
ISR_108ms_JUDGE:
MOV A,r_INDEX
XOR A,5
SNZ Z
JMP ISR_SIMPLECODE_2240us
SNZ f_108ms
JMP ISR_EXIT
CLR f_108ms
CLR f_108ms_start
SET f_keycheck
MOV A,1
MOV r_INDEX,A
JMP ISR_EXIT
ISR_SIMPLECODE_2240us:
MOV A,r_INDEX
XOR A,6
SNZ Z
JMP ISR_SIMPLECODE_560us
SNZ f_2240us
JMP ISR_EXIT
CLR f_2240us_start
CLR f_2240us
CLR f_560us
SET T1ON
MOV A,7
8
HT66F018 PTM IR Carrier Function Application Example
MOV r_INDEX,A
ISR_SIMPLECODE_560us:
MOV A,r_INDEX
XOR A,7
SNZ Z
JMP ISR_EXIT
SNZ f_560us
JMP ISR_EXIT
CLR f_560us
CLR T1ON
CLR PA7
CLR PAC7
MOV A,5
MOV r_INDEX,A
ISR_EXIT:
CLR T2AF
MOV A,ISR_STATUS
MOV STATUS,A
MOV A,ISR_ACC
RETI
Program Description
A key is connected to the HT66F018 PA1 pin via a 1K resistor to VSS.
PA7 is setup as a HT66F018 PTM PWM output.
When the key is pressed, PA7 outputs an NEC IR coded waveform; when released,
PA7 outputs a low.
9
HT66F018 PTM IR Carrier Function Application Example
Program Example
The following example is part of the setup procedure for the PTM IR carrier.
When T1ON = 1, PA7 outputs a 38kHz IR carrier. When T1ON = 0, PA7 will cease to
output the carrier signal. However it is necessary to set the PA7 output low and shut down
the IR emitting diodes driven by an NPN transistor. More details are provided in the
attached file.
Conclusion
In this document, the example provided was used to illustrate how to use the HT66F018
PTM function to generate a 38kHz carrier and achieve NEC IR coded waveform output.
Accessory
Users can consult the Holtek website for the program attachment.
10