EM78P459
EM78P459
EM78P459
OTP ROM
EM78P458/459
8-BIT MICRO-CONTROLLER
Version 1.4
EM78P458/459
OTP ROM
Application Note
AN-001 A/D Pre-amplifier
AN-002 Calibration Offset on A/D
AN-003 Example of Microcomputer Digital Thermometer
AN-004 Tips on how to apply EM78P458
AN-005 Tips on how to apply A/D Converter
AN-006 AD & R4
AN-007 Enhancing Noise Immunity
1. GENERAL DESCRIPTION
EM78P458 and EM78P459 are 8-bit microprocessors designed and developed with low-power and
high-speed CMOS technology. It is equipped with a 4K*13-bit Electrical One Time Programmable Read
Only Memory (OTP-ROM).
With its OTP-ROM feature, it is able to offer a convenient way of developing and verifying user’s programs.
Moreover, user can take advantage of EMC Writer to easily program his development code.
2. FEATURES
3. PIN ASSIGNMENT
P56/CIN+ 1 24 P55/CIN-
P57/CO 2 23 P54/TCC
P56/CIN+ 1 20 P55/CIN- P60/ADC1 3 22 OSCI
P57/CO 2 19 P54/TCC P61/ADC2 4 21 OSCO
P60/ADC1 3 18 OSCI ENTCC 5 20 RESET
EM78P459
P61/ADC2 4 17 OSCO Vss 6 19 VDD
EM78P458
4. FUNCTION DESCRIPTION
Instruction ALU
Sleep RAM Decoder
&
Wake Up
Control
R3 ACC
R4
P P P P PP P P P PPPPPP P
5555 55 55 66666666
0123 45 67 01234567
R0 is not a physically implemented register. Its major function is to perform as an indirect addressing
pointer. Any instruction using R0 as a pointer, actually accesses data pointed by the RAM Select
Register (R4).
• "JMP" instruction allows the direct loading of the lower 10 program counter bits. Thus, "JMP" allows
PC to jump to any location within a page.
• "CALL" instruction loads the lower 10 bits of the PC, and then PC+1 is pushed into the stack. Thus,
the subroutine entry address can be located anywhere within a page.
• "RET" ("RETL k", "RETI") instruction loads the program counter with the contents of the top of stack.
• "ADD R2, A" allows a relative address to be added to the current PC, and the ninth and tenth bits of
the PC are cleared.
• "MOV R2, A" allows to load an address from the "A" register to the lower 8 bits of the PC, and the
ninth and tenth bits of the PC are cleared.
• Any instruction that is written to R2 (e.g. "ADD R2, A", "MOV R2, A", "BC R2, 6",⋅⋅⋅⋅⋅) will cause the
ninth bit and the tenth bit (A8~A9) of the PC to be cleared. Thus, the computed jump is limited to the
first 256 locations of a page.
• In the case of EM78P458/459, the most two significant bits (A11 and A10) will be loaded with the
content of PS1 and PS0 in the status register (R3) upon the execution of a "JMP", "CALL", or any
other instructions set which write to R2.
• All instructions are single instruction cycle (fclk/2 or fclk/4) except for the instructions which write to
R2, need one more instruction cycle.
400
01 Stack Level 1
Space
Page 1
7FF Stack Level 2
800
10 Stack Level 3
Page 2 Stack Level 4
BFF
C00
Stack Level 5
11
Page 3 Stack Level 6
FFFH FFF Stack Level 7
On-chip Program Memory
︰ Bank 0 Bank 1
3F
4. R3 (Status Register)
7 6 5 4 3 2 1 0
CMPOUT PS1 PS0 T P Z DC C
• Bit 7 (CMPOUT) the result of the comparator output.
• Bit 6 (PS1) ~ 5 (PS0) Page select bits. PS0~PS1 are used to select a program memory page. When
executing a "JMP", "CALL", or other instructions which cause the program counter to be changed
(e.g. MOV R2, A), PS0~PS1 are loaded into the 11th and 12th bits of the program counter where it
selects one of the available program memory pages. Note that RET (RETL, RETI) instruction does
not change the PS0~PS1 bits. That is, the return will always be to the page from the place where the
subroutine was called, regardless of the current setting of PS0~PS1 bits.
PS1 PS0 Program memory page [Address]
0 0 Page 0 [000-3FF]
0 1 Page 1 [400-7FF]
1 0 Page 2 [800-BFF]
1 1 Page 3 [C00-FFF]
• Bit 4 (T) Time-out bit. Set to 1 by the "SLEP" and "WDTC" commands, or during Power on and reset
to 0 by WDT time-out.
• Bit 3 (P) Power-down bit. Set to 1 during power-on or by a "WDTC" command and reset to 0 by a
"SLEP" command.
• Bit 2 (Z) Zero flag. Set to "1" if the result of an arithmetic or logic operation is zero.
• Bit 1 (DC) Auxiliary carry flag
• Bit 0 (C) Carry flag
6. R5 ~ R6 (Port 5 ~ Port 6)
• R5 and R6 are I/O registers.
7. R7 ~ R8
• All of these are 8-bit general-purpose registers.
When the A/D conversion is complete, the result is loaded into the ADDATA. The START//END bit is
cleared, and the ADIF is set.
10. RB
11. RC
12. RD
13. RE
7 6 5 4 3 2 1 0
- CMPIF PWM2IF PWM1IF ADIF EXIF ICIF TCIF
“1” means interrupt request, and “0” means no interrupt occurs.
• Bit 7 Unemployed, read as ‘0’;
• Bit 6 (CMPIF) High-compared interrupt flag. Set when a change occurs in the output of Comparator,
reset by software.
• Bit 5 (PWM2IF) PWM2 (Pulse Width Modulation) interrupt flag. Set when a selected period is
reached, reset by software.
• Bit 4 (PWM1IF) PWM1 (Pulse Width Modulation) interrupt flag. Set when a selected period is
reached, reset by software.
• Bit 3 (ADIF) Interrupt flag for analog to digital conversion. Set when AD conversion is completed,
reset by software.
• Bit 2 (EXIF) External interrupt flag. Set by falling edge on /INT pin, reset by software.
• Bit 1 (ICIF) Port 6 input status change interrupt flag. Set when Port 6 input changes, reset by
software.
• Bit 0 (TCIF) TCC overflow interrupt flag. Set when TCC overflows, reset by software.
• RF can be cleared by instruction but cannot be set.
• IOCF0 is the interrupt mask register.
• Note that to read RF will result to "logic AND" of RF and IOCF0.
001 = IS x 2;
010 = IS x 4;
011 = IS x 8;
100 = IS x 16;
101 = IS x 32;
Legend: IS = the input signal
• Bit 2:Bit 0 (G12 and G10 ): Select the gain of OP1.
000 = IS x 1 (default value);
001 = IS x 2;
010 = IS x 4;
011 = IS x 8;
100 = IS x 16;
101 = IS x 32;
Legend: S = the input signal
5. IOCA0 ( AD-CMPCON ):
7 6 5 4 3 2 1 0
VREFS CE COE IMS2 IMS1 IMS0 CKR1 CKR0
• Bit 7: The input source of the Vref of the ADC.
0 = The Vref of the ADC is connected to Vdd (default value), and the P53/VREF pin carries out the
function of P53;
1 = The Vref of the ADC is connected to P53/VREF.
• Bit 6 (CE): Comparator enable bit
0 = Comparator is off (default value);
1 = Comparator is on.
• Bit 5 ( COE ): Set P57 as the output of the comparator
0 = the comparator acts as an OP if CE=1.
1 = act as a comparator if CE=1.
• Bit4:Bit2 (IMS2:IMS0):
Input Mode Select. ADC configuration definition bit. The following Table describes how to define the
characteristic of each pin of R6.
011 A A A A D D D D
100 A A A A A D D D
101 A A A A A A D D
110 A A A A A A A D
111 A A A A A A A A
• Bit 1: Bit 0 (CKR1: CKR0): The prescaler of oscillator clock rate of ADC
00 = 1: 4 (default value);
01 = 1: 16;
10 = 1: 64;
11 = The oscillator clock source of ADC is from WDT ring oscillator frequency.
( frequency=256/18ms≒14.2Khz)
• Bit 1 (OD1) Control bit is used to enable the open-drain of the P65 pin.
• Bit 0 (OD0) Control bit is used to enable the open-drain of the P64 pin.
• IOCC0 register is both readable and writable.
12. IOC61 ( DT1L: the Least Significant Byte ( Bit 7 ~ Bit 0) of Duty Cycle of
PWM1 )
A specified value keeps the output of PWM1 to stay at high until the value matches with TMR1.
13. IOC71 ( DT1H: the Most Significant Byte ( Bit 1 ~ Bit 0 ) of Duty Cycle of
PWM1 )
7 6 5 4 3 2 1 0
CALI1 SIGN1 VOF1[2] VOF1[1] VOF1[0] - PWM1[9] PWM1[8]
• Bit 7 (CALI1): Calibration enable bit
0 = Calibration disable;
1 = Calibration enable.
• Bit 6 (SIGN1): Polarity bit of offset voltage
0 = Negative voltage;
1 = Positive voltage.
• Bit 5:Bit 3 (VOF1[2]:VOF1[0]): Offset voltage bits.
• Bit 1:Bit 0 (PWM1[9]:PWM1[8]): The Most Significant Byte of PWM1 Duty Cycle
A specified value keeps the PWM1 output to stay at high until the value matches with TMR1.
The content of IOC81 is a period (time base) of PWM1. The frequency of PWM1 is the reverse of the
period.
15. IOC91 ( DT2L: the Least Significant Byte ( Bit 7 ~ Bit 0 ) of Duty Cycle of
PWM2 )
A specified value keeps the of PWM1 output to stay at high until the value matches with TMR2.
16. IOCA1 ( DT2H: the Most Significant Byte ( Bit 1 ~ Bit 0 ) of Duty Cycle of
PWM2 )
7 6 5 4 3 2 1 0
CALI2 SIGN2 VOF2[2] VOF2[1] VOF2[0] - PWM2[9] PWM2[8]
• Bit 7 (CALI2): Calibration enable bit
0 = Calibration disable;
1 = Calibration enable.
• Bit 6 (SIGN2): Polarity bit of offset voltage
0 = Negative voltage;
1 = Positive voltage.
• Bit 5:Bit 3 (VOF2[2]:VOF2[0]): Offset voltage bits
• Bit 1:Bit 0 (PWM2[9]:PWM2[8]): The Most Significant Byte of PWM1 Duty Cycle
A specified value keeps the PWM2 output to stay at high until the value matches with TMR2.
The content of IOCB1 is a period (time base) of PWM2. The frequency of PWM2 is the reverse of the
period.
18. IOCC1 ( DL1L: the Least Significant Byte ( Bit 7 ~ Bit 0 ) of Duty Cycle Latch of
PWM1 )
19. IOCD1 ( DL1H: the Most Significant Byte ( Bit 1 ~ Bit 0 ) of Duty Cycle Latch of
PWM1 )
20. IOCE1 ( DL2L: the Least Significant Byte ( Bit 7 ~ Bit 0) of Duty Cycle Latch of
PWM2 )
21. IOCF1 ( DL2H: the Most Significant Byte ( Bit 1 ~ Bit 0 ) of Duty Cycle Latch of
PWM2 )
• R1(TCC) is an 8-bit timer/counter. The TCC clock source can be internal or external clock input (edge
selectable from TCC pin). If TCC signal source is from internal clock, TCC will increase by 1 at every
instruction cycle (without prescaler). Referring to Fig. 5, selection of CLK=Fosc/2 or CLK=Fosc/4
depends on the CODE Option bit CLKS. CLK=Fosc/2 if CLKS bit is "0", and CLK=Fosc/4 if CLKS bit is
"1".
• If TCC signal source is from external clock input, TCC will increase by 1 at every falling edge or rising
edge of TCC pin.
• The watchdog timer is a free running on-chip RC oscillator. The WDT will keep on running even after
the oscillator driver has been turned off (i.e. in sleep mode). During normal operation or sleep mode, a
WDT time-out (if enabled) will cause the device to reset. The WDT can be enabled or disabled at any
time during the normal mode by software programming. Refer to WDTE bit of IOCE0 register. Without
presacler, the WDT time-out period is approximately 18 ms1.
1
NOTE: VDD=5V,Setup time period = 18ms ± 30%.
VDD=3V,Setup time period = 22ms ± 30%.
0 1
M M
TCC U U SYNC TCC (R1)
Pin X X 2 cycles
1 0
TCC overflow
TE TS PAB interrupt
M
0 8-bit Counter
U
WDT X
1
PSR0 ~ PSR2
PAB 8-to-1 MUX
0 1
WDTE PAB
(in IOCE) MUX
WDT timeout
PCRD
Q D
_ CLK PCWR
Q C
L
P
PORT Q R D IOD
CLK
_ PDWR
Q C
L
PDRD
0
M
U
1
X
P
Q R D
_ CLK PCWR
Q C
L
P50, /INT
P
PORT Q R D IOD
_ CLK
PDWR
Q C
L
Bit 6 of IOCE0
M
0
D P Q U
R
CLK
X
_ 1
C
L Q
PDRD
TI 0
P
D R
Q
CLK
_
C
L
Q
INT
NOTE: Pull-high (down) and Open-drain are not shown in the figure.
Fig. 7 The Circuit of I/O Port and I/O Control Register for P50(/INT)
PCRD
P
Q R D
_ CLK PCWR
Q C
L
P60 ~ P67
P
PORT Q R D IOD
_ CLK
PDWR
Q C
L
M
0 U
X
1
PDRD
TI n
P
D R
Q
CLK
_
C
L
Q
NOTE: Pull-high (down) and Open-drain are not shown in the figure.
Fig. 8 The Circuit of I/O Port and I/O Control Register for P60~P67
IOCE.1
D P Q
R
CLK Interrupt
_
C Q
L
RE.1
ENI Instruction
T10
P
D R Q
T11
P
Q R
CLK D
_
C
L Q CLK
_
Q C
L
T17
DISI Instruction
Interrupt
(Wake-up from SLEEP)
/SLEP
Next Instruction
(Wake-up from SLEEP)
The device is kept in a RESET condition for a period of approximately 18ms (one oscillator start-up
timer period) after the reset is detected. Once the RESET occurs, the following functions are
performed.
Executing the “SLEP” instruction will assert the sleep (power down) mode. While entering sleep mode,
the WDT (if enabled) is cleared but keeps on running. The controller can be awakened by-
The first two cases will cause the EM78P458/459 to reset. The T and P flags of R3 can be used to
determine the source of the reset (wake-up). Case 3 is considered the continuation of program
execution and the global interrupt ("ENI" or "DISI" being executed) decides whether or not the
controller branches to the interrupt vector following wake-up. If ENI is executed before SLEP, the
instruction will begin to execute from the address 0x8 after wake-up. If DISI is executed before SLEP,
the execution will restart from the instruction right next to SLEP after wake-up.
Only one of the Cases 2, to 4 can be enabled before entering into sleep mode. That is,
[a] if Port 6 Input Status Change Interrupt is enabled before SLEP , WDT must be disabled by
software. However, the WDT bit in the option register remains enabled. Hence, the
EM78P458/459 can be awakened only by Case 1 or 3.
[b] if WDT is enabled before SLEP, Port 6 Input Status Changed Interrupt must be disabled. Hence,
the EM78P458/459 can be awakened only by Case 1 or 2. Refer to the section on Interrupt for
further details.
[c] if Comparator High Interrupt is enabled before SLEP, WDT must be disabled by software.
However, the WDT bit in the option register remains enabled. Hence, the EM78P458/459 can
be awakened only by Case 1 or 4.
If Port 6 Input Status Change Interrupt is used to wake up the EM78P458/459 (as in Case [a] above),
the following instructions must be executed before SLEP:
CONTW
CONTW
IOW RE
IOW RF
SLEP ; Sleep
NOP
Similarly, if the Comparator High Interrupt is used to wake up the EM78P458/459 (as in Case [c]
above), the following instructions must be executed before SLEP:
CONTW
CONTW
IOW RE
IOW RF
SLEP ; Sleep
NOP
One problem user must be aware of, is that after waking up from the sleep mode, the WDT function
will enable automatically. The WDT operation (being enabled or disabled) should be handled
appropriately by software after waking up from the sleep mode.
The values of T and P, as listed in Table 5 below, are used to check how the processor wakes up.
Table 6 shows the events, which may affect the status of T and P.
VDD
D Q CLK
Oscillator CLK
CLR
Power-On Reset
Voltage Detector
W
WDT Timeout
/RESET
4.6 Interrupt
The EM78P458/459 has six interrupts as listed below:
Before the Port 6 Input Status Change Interrupt is enabled, reading Port 6 (e.g. "MOV R6,R6") is
necessary. Each Port 6 pin will have this feature if its status changes. Any pin configured as output or
P50 pin configured as /INT, is excluded from this function. Port 6 Input Status Change Interrupt will
wake up the EM78P458/459 from the sleep mode if it is enabled prior to going into the sleep mode by
executing SLEP. When the controller is wake-up, it will continue to execute the succeeding program if
the global interrupt is disabled, or branches out to the interrupt vector 008H if the global interrupt is
enabled.
RF, the interrupt status register that records the interrupt requests in the relative flags/bits. IOCF0 is
an interrupt mask register. The global interrupt is enabled by the ENI instruction and is disabled by the
DISI instruction. When one of the interrupts (when enabled) occurs, the next instruction will be
fetched from address 008H. Once in the interrupt service routine, the source of an interrupt can be
determined by polling the flag bits in RF. The interrupt flag bit must be cleared by instructions before
leaving the interrupt service routine to avoid recursive interrupts.
The flag (except ICIF bit) in the Interrupt Status Register (RF) is set regardless of the status of its
mask bit or the execution of ENI. Note that the outcome of RF will be the logic AND of RF and IOCF0
(refer to Fig. 11). The RETI instruction ends the interrupt routine and enables the global interrupt (the
execution of ENI).
When an interrupt is generated by the INT instruction (when enabled), the next instruction will be
fetched from address 001H.
The ADC module utilizes successive approximation to convert the unknown analog signal into a
digital value. The result is fed to the ADDATA. Input channels are selected by the analog input
multiplexer via the ADCON register Bits ADIS0, ADIS1, and ADIS2.
ADC8 Vref
ADC7
8-1 Analog Switch
ADC6
ADC5 + Power-Down
-
OP2 ADC
Start to Convert
( successive approximation )
ADC4
ADC3
Fsco
ADC2
4-1
ADC1 +
OP1 MUX
-
Internal
RC
4 3 2 5 4 3 2 1 0 2 1 0 1 0 3 7 6 5 4 3 2 1 0 4 3
AD-CMPCON ADCON AD-CMPCON RF ADDATA ADCON
GCON
DATA BUS
The ADCON register controls the operation of the A/D conversion and decides which pin should
be currently active.
BIT 7 6 5 4 3 2 1 0
SYMBOL - - IOCS ADRUN ADPD ADIS2 ADIS1 ADIS0
*Init_Value 0 0 0 0 0 0 0 0
*Init_Value: Initial value at power on reset
1.2 AD-CMP-CON/IOCA0
The AD-CMP-CON register defines the pins of Port 6 as analog inputs or as digital I/O,
individually.
BIT 7 6 5 4 3 2 1 0
SYMBOL VREFS CE COE IMS2 IMS1 IMS0 CKR1 CKR0
*Init_Value 0 0 0 0 0 0 0 0
*Init_Value: Initial value at power on reset
• VREFS (Bit 7): The input source of the Vref of the ADC.
0 = The Vref of the ADC is connected to Vdd (default value), and the P53/VREF pin carries out
the function of P53;
• CKR1 and CKR0 (Bit 1 and Bit 0): The conversion time select.
00 = Fosc/4;
01 = Fosc/16;
10 = Fsco/64;
11 = The oscillator clock source of ADC is from WDT ring oscillator frequency.
( frequency=256/18ms≒14.2Khz)
1.3 GCON/IOC90
As shown in Fig. 12, OP1 and OP2, the gain amplifiers, are located in the middle of the analog
input pins (ADC1 and ADC5) and the 8-1analog switch. The GCON register controls the gains.
Table 7 Table 7 Shows the Gains and the Operating Range of ADC.
BIT 7 6 5 4 3 2 1 0
SYMBOL OP2E OP1E G22 G21 G20 G12 G11 G10
*Init_Value 0 0 0 0 0 0 0 0
When the A/D conversion is complete, the result is loaded to the ADDATA. The START/END bit is
clear, and the ADIF is set.
The accuracy, linearity, and speed of the successive approximation A/D converter are dependent on
the properties of the ADC and the comparator. The source impedance and the internal sampling
impedance directly affect the time required to charge the sample holding capacitor. The application
program controls the length of the sample time to meet the specified accuracy. Generally speaking,
the program should wait for 1 μs for each KΩ of the analog source impedance and at least 1 μs for
the low-impedance source. After the analog input channel is selected, this acquisition time must be
done before the conversion can be started.
CKR0 and CKR1 select the conversion time (Tct), in terms of instruction cycles. This allows the MCU
to run at the maximum frequency without sacrificing the accuracy of A/D conversion. For the
EM78P458/459, the conversion time per bit is about 4μs. Table 8 shows the relationship between
Tct and the maximum operating frequencies.
In order to reduce power consumption, the A/D conversion remains operational during sleep mode,
and is obligated to implement the internal RC clock source mode. As the SLEP instruction is executed,
all the operations of the MCU will stop except for the A/D conversion. The RUN bit will be cleared and
the result will be fed to the ADDATA when the conversion is completed. If the ADIE is enabled, the
device will wake up. Otherwise, the A/D conversion will be shut off, no matter what the status of
ADPD bit is.
6. Programming Steps/Considerations
1. Programming steps
(1) Write to the three bits (IMS2:IMS0) on the AD-CMP-CON1 register to define the characteristics
of R6: Digital I/O, analog channels, and voltage reference pin;
(5) Wait for either the interrupt flag to be set or the ADC interrupt to occur.
(8) For next conversion, go to Step 1 or Step 2 as required. At least 2 Tct is required before next
acquisition starts.
<Note>: To obtain an accurate value, it is necessary to avoid any data transition on I/O pins during
AD conversion.
PORT5 == 5
PORT6 == 6
ADCONC== 0xA ; 7 6 5 4 3 2 1 0
GCON == 0x9 ; 7 6 5 4 3 2 1 0
;In ADCONR
JMP INITIAL ;
(User program)
RETI
INITIAL:
IOW C_INT
CONTW
En_ADC:
MOV A, @0BXXXXXXX1 ; To define P60 as an input pin, and the others are dependent
IOW GCON
; If the interrupt function is employed, the following three lines may be ignored
POLLING:
(User program)
In PWM mode, both PWM1 and PWM2 pins produce up to a 10-bit resolution PWM output (see. Fig.
13 for the functional block diagram). A PWM output has a period and a duty cycle, and it keeps the
output in high. The baud rate of the PWM is the inverse of the period. Fig. 14 depicts the relationships
between a period and a duty cycle.
latch
DL1H + DL1L To PW M 1IF
DT1H
Fosc +
DT1L Duty Cycle
1:2 M atch
Com parator
1:8 PW M 1
1:32 M UX
R Q
1:64 TM R1H + TM R1L
reset S
IOC51
Com parator
T1P0 T1P1 T1EN Period
M atch
PRD1
Data Bus Data Bus
latch
DL2H + DL2L To PW M 2IF
DT2H
+
T2P0 T2P1 T2EN Duty Cycle
DT2L
Com parator M atch
PW M 2
Fosc R Q
TM R2H + TM R2L
1:2 reset
1:8 S
M UX
1:32 IOC51
1:64 Com parator
Period
M atch
PRD2
Period
Duty Cycle
PRD1 = TMR1
DT1 = TMR1
TMRX are ten-bit clock counters with programmable prescalers. They are designed for the PWM
module as baud rate clock generators. TMRX can be read, written, and cleared at any reset
conditions. If employed, they can be turned down for power saving by setting T1EN bit
[PWMCON<4>] or T2EN bit [PWMCON<5>] to 0.
The PWM period is defined by writing to the PRDX register. When TMRX is equal to PRDX, the
• TMRX is cleared.
• The PWMX pin is set to 1.
• The PWM duty cycle is latched from DT1/DT2 to DTL1/DTL2.
< Note > The PWM output will not be set, if the duty cycle is 0;
• The PWMXIF pin is set to 1.
The following formula describes how to calculate the PWM period:
4. PWM Duty Cycle ( DTX: DT1H/ DT1L and DT2H/ DT2L; DTL: DL1H/DL1L and
DL2H/DL2L )
The PWM duty cycle is defined by writing to the DTX register, and is latched from DTX to DLX while
TMRX is cleared. When DLX is equal to TMRX, the PWMX pin is cleared. DTX can be loaded at any
time. However, it cannot be latched into DTL until the current value of DLX is equal to TMRX.
The following formula describes how to calculate the PWM duty cycle:
5. Comparator X
To change the output status while the match occurs, the TMRXIF flag will be set at the same time.
4.9 Timer
1. Overview
Timer1 (TMR1) and Timer2 (TMR2) (TMRX) are 10-bit clock counters with programmable prescalers,
respectively. They are designed for the PWM module as baud rate clock generators. TMRX can be
read, written, and cleared at any reset conditions.
2. Function description
Fig. 15 shows TMRX block diagram. Each signal and block are described as follows:
Fosc
1:2
1:8 To PWM1IF
1:32 MUX
reset
1:64 TMR1X Period
Match
Comparator
T1P0 T1P1 T1EN
PRD1
Data Bus Data Bus
PRD2
T2P0 T2P1 T2EN
Comparator
Period
Fosc reset Match
1:2 TMR2X
1:8
1:32 MUX
To PWM2IF
1:64
Prescaler ( T1P0 and T1P1/T2P1 and T2P0 ): Options of 1:2, 1:8, 1:32, and 1:64 are defined by
TMRX. It is cleared when any type of reset occurs.
ComparatorX ( Comparator 1 and Comparator 2 ): To reset TMRX while a match occurs and the
TMRXIF flag is set at the same time.
When defining TMRX, refer to the related registers of its operation as shown in Table 9.It must be
noted that the PWMX bits must be disabled if their related TMRXs are employed. That is, bit 7 and bit
6 of the PWMCON register must be set to ‘0’.
4.10 Comparator
EM78P458/459 has one comparator, which has two analog inputs and one output. The comparator
can be employed to wake up from the sleep mode. Fig. 16 shows the circuit of the comparator.
Cin- -
CO
CMP
Cin+
+
The analog signal that is presented at Cin- compares to the signal at Cin+, and the digital output (CO)
of the comparator is adjusted accordingly.
2. Comparator Outputs
• The compared result is stored in the CMPOUT of R3.
• The comparator outputs is output to P57 by programming bit5<COE> of the AD-CMPCON register
to 1.
To C0
From OP I/O
CMRD
EN EN
Q D Q D
To CMPOUT
RESET
To CPIF
CMRD
From other
comparator
The comparator can be used as an operation amplifier if a feedback resistor is connected from the
input to the output externally. In this case, the Schmitt trigger can be disabled for power saving by
setting CE to 1 and COE to 0.
4. Interrupt
• CMPIE (IOCF0.6) must be enabled.
• Interrupt occurs at the rising edge of the comparator output pin.
• The actual change on the pin can be determined by reading the Bit CMPOUT, R3<7>.
• CMPIF (RF.6), the comparator interrupt flag, can only be cleared by software.
Address Name Reset Type Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
(DT2H) Power-on 0 1 1 0 0 0 0 0
/RESET and WDT 0 1 1 0 0 0 0 0
Wake-up from Pin Changed P P P P P 0 P P
Bit Name - - - - - - - -
IOCB1 Power-on 0 0 0 0 0 0 0 0
N/A
(PRD2) /RESET and WDT 0 0 0 0 0 0 0 0
Wake-up from Pin Changed P P P P P P P P
Bit Name Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
IOCC1 Power-on 0 0 0 0 0 0 0 0
N/A
(DL1L) /RESET and WDT 0 0 0 0 0 0 0 0
Wake-up from Pin Changed P P P P P P P P
Bit Name X X X X X X Bit1 Bit0
IOCD1 Power-on 0 0 0 0 0 0 0 0
N/A
(DL1H) /RESET and WDT 0 0 0 0 0 0 0 0
Wake-up from Pin Changed 0 0 0 0 0 0 P P
Bit Name Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
IOCE1 Power-on 0 0 0 0 0 0 0 0
N/A
(DL2L) /RESET and WDT 0 0 0 0 0 0 0 0
Wake-up from Pin Changed P P P P P P P P
Bit Name X X X X X X Bit1 Bit0
IOCF1 Power-on 0 0 0 0 0 0 0 0
N/A
(DL2H) /RESET and WDT 0 0 0 0 0 0 0 0
Wake-up from Pin Changed 0 0 0 0 0 0 P P
Bit Name INTE INT TS TE PAB PSR2 PSR1 PSR0
Power-on 1 0 1 1 1 1 1 1
N/A CONT
/RESET and WDT 1 0 1 1 1 1 1 1
Wake-up from Pin Changed P P P P P P P P
Bit Name - - - - - - - -
Power-on U U U U U U U U
0x00 R0(IAR)
/RESET and WDT P P P P P P P P
Wake-up from Pin Changed P P P P P P P P
Bit Name - - - - - - - -
Power-on 0 0 0 0 0 0 0 0
0x01 R1(TCC)
/RESET and WDT 0 0 0 0 0 0 0 0
Wake-up from Pin Changed P P P P P P P P
Bit Name - - - - - - - -
Power-on 0 0 0 0 0 0 0 0
0x02 R2(PC)
/RESET and WDT 0 0 0 0 0 0 0 0
Wake-up from Pin Changed Jump to address 0x08 or continue to execute next instruction
Bit Name GP2 PS1 PS0 T P Z DC C
Power-on 0 0 0 1 1 U U U
0x03 R3(SR)
/RESET and WDT 0 0 0 t t P P P
Wake-up from Pin Changed P P P t t P P P
Bit Name BS7 BS6 - - - - - -
Power-on 0 0 U U U U U U
0x04 R4(RSR)
/RESET and WDT 0 0 P P P P P P
Wake-up from Pin Changed P P P P P P P P
Bit Name P57 P56 P55 P54 P53 P52 P51 P50
Power-on 1 1 1 1 1 1 1 1
0x05 P5
/RESET and WDT 1 1 1 1 1 1 1 1
Wake-up from Pin Changed P P P P P P P P
Bit Name P67 P66 P65 P64 P63 P62 P61 P60
Power-on 1 1 1 1 1 1 1 1
0x06 P6
/RESET and WDT 1 1 1 1 1 1 1 1
Wake-up from Pin Changed P P P P P P P P
Bit Name - - - - - - - -
Power-on U U U U U U U U
0x7~0x8 R7~R8
/RESET and WDT P P P P P P P P
Wake-up from Pin Changed P P P P P P P P
0x9 R9 Bit Name X X IOCS ADRUN ADPD ADAS2 ADAS1 ADAS0
(ADCON) Power-on 0 0 0 0 0 0 0 0
/RESET and WDT 0 0 0 0 0 0 0 0
Address Name Reset Type Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
Wake-up from Pin Changed P P P P P P P P
Bit Name - - - - - - - -
RA Power-on 0 0 0 0 0 0 0 0
0xA
(ADDDATA) /RESET and WDT 0 0 0 0 0 0 0 0
Wake-up from Pin Changed P P P P P P P P
Bit Name Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
RB Power-on 0 0 0 0 0 0 0 0
0xB
(TMR1L) /RESET and WDT 0 0 0 0 0 0 0 0
Wake-up from Pin Changed P P P P P P P P
Bit Name X X X X X X Bit1 Bit0
RC Power-on 0 0 0 0 0 0 0 0
0xC
(TMR1H) /RESET and WDT 0 0 0 0 0 0 0 0
Wake-up from Pin Changed 0 0 0 0 0 0 P P
Bit Name Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
RD Power-on 0 0 0 0 0 0 0 0
0xD
(TMR2L) /RESET and WDT 0 0 0 0 0 0 0 0
Wake-up from Pin Changed P P P P P P P P
Bit Name X X X X X X Bit1 Bit0
RE Power-on 0 0 0 0 0 0 0 0
0xE
(TMR2H) /RESET and WDT 0 0 0 0 0 0 0 0
Wake-up from Pin Changed 0 0 0 0 0 0 P P
Bit Name X CMPIF PWM2IF PWM1IF ADIF EXIF ICIF TCIF
RF Power-on 0 0 0 0 0 0 0 0
0xF
(ISR) /RESET and WDT 0 0 0 0 0 0 0 0
Wake-up from Pin Changed 0 P P P P P P P
Bit Name - - - - - - - -
Power-on U U U U U U U U
0x10~0x3F R10~R3F
/RESET and WDT P P P P P P P P
Wake-up from Pin Changed P P P P P P P P
t: check Table 5
4.12 Oscillator
1. Oscillator Modes
The EM78P458 and EM78P459 can be operated in four different oscillator modes, such as High
XTAL oscillator mode (HXT), Low XTAL oscillator mode (LXT), External RC oscillator mode (ERC),
and RC oscillator mode with Internal capacitor (IC). Users can select one of them by programming the
MASK Option. The up-limited operation frequency of crystal/resonator on the different VDDs is listed
in Table 11.
EM78P458/459 can be driven by an external clock signal through the OSCI pin as shown in Fig. 18
below.
Ext.
OSCI
Clock
EM78P458
EM78P459
OSCO
In the most applications, pin OSCI and pin OSCO can be connected with a crystal or ceramic
resonator to generate oscillation. Fig. 19 depicts such circuit. The same applies to the HXT mode and
the LXT mode. Table 12 provided the recommended values of C1 and C2. Since each resonator has
its own attribute, user should refer to their specifications for appropriate values of C1 and C2. RS, a
serial resistor, may be necessary for AT strip cut crystal or low frequency mode.
C1
OSCI
EM78P458
EM78P459 XTAL
OSCO
RS C2
For some applications that do not require precise timing calculation, the RC oscillator (Fig. 20) could
offer users with an effective cost savings. Nevertheless, it should be noted that the frequency of the
RC oscillator is influenced by the supply voltage, the values of the resistor (Rext), the capacitor(Cext),
and even by the operation temperature. Moreover, the frequency also changes slightly from one chip
to another due to the manufacturing process variation.
In order to maintain a stable system frequency, the values of the Cext should not be less than 20pF,
and that the value of Rext should not be greater than 1M ohm. If they cannot be kept in this range, the
frequency can be affected easily by noise, humidity, and leakage.
The smaller the Rext in the RC oscillator, the faster its frequency will be. On the contrary, for very low
Rext values, for instance, 1 KΩ, the oscillator becomes unstable because the NMOS cannot
discharge the current of the capacitance correctly.
Based on the above reasons, it must be kept in mind that all supply voltage, the operation
temperature, the components of the RC oscillator, the package types, and the way the PCB is layout,
have certain effect on the system frequency.
Vcc
Rext
OSCI
Cext
EM78P458
EM78P459
If both precision and cost are taken into consideration, EM78P257A/B also offers a special oscillation
mode. It is equipped with an internal capacitor and an external resistor (connected to Vcc). The
internal capacitor functions as temperature compensator. In order to obtain more accurate frequency,
a precise resistor is recommended.
Vcc
Rext
OSCI
EM78P458
EM78P459
EM78P458/459 POR voltage range is 1.2V~1.8V. Under customer application, when power is OFF,
Vdd must drop to below 1.2V and remains OFF for 10us before power can be switched ON again.
This way, the EM78P458/459 will reset and work normally. The extra external reset circuit will work
well if Vdd can rise at very fast speed (50 ms or less). However, under most cases where critical
applications are involved, extra devices are required to assist in solving the power-up problems.
The circuit shown in Fig. 22 implements an external RC to produce a reset pulse. The pulse width
(time constant) should be kept long enough to allow Vdd to reach minimum operation voltage. This
circuit is used when the power supply has a slow rise time. Because the current leakage from the
/RESET pin is about ±5µA, it is recommended that R should not be great than 40 K. In this way, the
voltage at Pin /RESET is held below 0.2V. The diode (D) acts as a short circuit at power-down. The
capacitor, C, is discharged rapidly and fully. Rin, the current-limited resistor, prevents high current
discharge or ESD (electrostatic discharge) from flowing into Pin /RESET.
VDD
/RESET R
D
EM78P458
EM78P459
Rin
C
2. Residue-Voltage Protection
When battery is replaced, device power (Vdd) is taken off but residue-voltage remains. The
residue-voltage may trips below Vdd minimum, but not to zero. This condition may cause a poor
power on reset. Fig. 23 and Fig. 24 show how to build a residue-voltage protection circuit
VDD VDD
EM78P458 33K
EM78P459 Q1 10K
/RESET
100K 1N4684
VDD VDD
EM78P458 R1
EM78P459
Q1
/RESET
R3 R2
Word 0 Word 1
Bit12~Bit0 Bit12~Bit0
Code option12~0 Code option12~0
1: High frequency
• Bit 7 (RCT): Resistor Capacitor
0: Inter C, External R
1: External RC
• Bit 6 (HLP): Power consumption selection.
0: Low power.
1: High power.
• Bit 5 ~ Bit 0 (ID[5]~ID[0]): Customer’s ID.
(1) Every bit of any register can be set, cleared, or tested directly.
(2) The I/O registers can be regarded as general registers. That is, the same instruction can operate
on I/O registers.
The symbol "R" represents a register designator that specifies which one of the registers (including
operational registers and general-purpose registers) is to be utilized by the instruction. The symbol
"b" represents a bit field designator that selects the value for the bit located in the register "R" that is
affected by the operation. The symbol "k" represents an 8 or 10-bit constant or literal value.
2.4
2.0 2.0
TEST POINTS
0.8 0.8
0.4
AC Testing : Input is driven at 2.4V for logic "1",and 0.4V for logic "0".Timing measurements are
made at 2.0V for logic "1",and 0.8V for logic "0".
CLK
/RESET
Tdrh
CLK
TCC
Ttcc
Items Rating
Temperature under bias 0°C to 70°C
Storage temperature -65°C to 150°C
Input voltage -0.3V to +6.0V
Output voltage -0.3V to +6.0V
6. ELECTRICAL CHARACTERISTICS
2.5
Vih max(0℃ to 70℃ )
1.5
2.5
Vih max(0℃ to 70℃ )
1.5
1.5
1
Vil max(0℃ to 70℃ )
0.5
Vil typ 25℃
0 0
-5 -2
-10 -4
Min 70 ℃
Ioh(mA)
Ioh(mA)
-15 Min 70 ℃ -6
Typ 25 ℃
Typ 25 ℃
-20 -8
Max 0 ℃ Max 0 ℃
-25 -10
-30 -12
0 1 2 3 4 5 0 0.5 1 1.5 2 2.5 3
Voh(Volt) Voh(Volt)
Fig.28 Port5, Port6, Voh vs. Ioh, VDD=5V Fig.29 Port5, Port6, Voh vs. Ioh, VDD=3V
Max 0 ℃
80 Max 0 ℃ 35
70 Typ 25 ℃ 30 Typ 25 ℃
60
Min 70 ℃ 25
Min 70 ℃
50
20
Iol(mA)
40 Iol(mA)
15
30
10
20
10 5
0
0
0 1 2 3 4 5 0 0.5 1 1.5 2 2.5 3
Vol(Volt) Vol(Volt)
Fig. 30 Port5, and P60~P63,P66,P67 Vol, VDD=5V Fig. 31 Port5, and P60~P63,P66,P67 Vol , VDD=3V
50 50
45 Max 0 ℃ 45 Max 0 ℃
40 40
Typ 25 ℃
Typ 25 ℃ 35
35
30 Min 70 ℃ 30 Min 70 ℃
Iol(mA)
Iol(mA)
25 25
20 20
15 15
10 10
5 5
0 0
0 0.5 1 1.5 2 2.5 3 0 0.5 1 1.5 2 2.5 3
Vol(Volt) Vol(Volt)
Fig. 32 P64,P65 Vol vs. Iol, VDD=5V Fig. 33 P64,P65 Vol vs. Iol, VDD=3V
WDT Time_ o u t
35
30
Max 70 ℃
25
Typ 25 ℃
WDT period (mS)
20
Min 0 ℃
15
10
0
2 3 4 5 6
VDD (Volt)
1.4
R = 3.3 k
1.2
1
R = 5.1 k
Frequency(M Hz)
0.8
0.6
R = 10 k
0.4
0.2
R = 100 k
0
2.5 3 3.5 4 4.5 5 5.5
VDD(Volt)
Four conditions exist with the operating current ICC1 to ICC4. these conditions are as follows:
21 Typ ICC2
18 Typ ICC1
Current (uA)
15
12
9
0 10 20 30 40 50 60 70
Temperature (℃)
Max ICC2
27
24
Current (uA)
Max ICC1
21
18
15
0 10 20 30 40 50 60 70
Temperature (℃)
1.9
1.7
Typ ICC4
Current (mA)
1.5
1.3
1.1
Typ ICC3
0.9
0.7
0.5
0 10 20 30 40 50 60 70
Temperature (℃)
1.8
1.6
Max ICC3
1.4
1.2
1
0 10 20 30 40 50 60 70
Temperature (℃)
Two conditions exist with the standby current ISB1 and ISB2. these conditions are as follow:
9
Current (uA)
Typ ISB2
6
3
Typ ISB1
0
0 10 20 30 40 50 60 70
Temperature (℃)
12
9
Current (uA)
Max ISB2
6
3
Max ISB1
0
0 10 20 30 40 50 60 70
Temperature (℃)
25
20
Frequency(M Hz)
15
10
0
2 2.5 3 3.5 4 4.5 5 5.5 6
VDD(Volt)
2.5
2
1.5
1
0.5
0
2 2.5 3 3.5 4 4.5 5 5.5 6
2.5
2
1.5
1
0.5
0
2 3 4 5 6
200
150
100
50
0
2 3 4 5 6
140
120
100
80
60
40
20
0
2 3 4 5 6
APPENDIX
Package Types:
OTP MCU Package Type Pin Count Package Size
EM78P458AP DIP 20 pin 300mil
EM78P458AM SOP 20 pin 300mil
EM78P459AK Skinny DIP 24 pin 300mil
EM78P459AM SOP 24 pin 300mil
Package Information
20-Lead Plastic Dual in line (PDIP) — 300 mil