SONIX reserves the right to make change without further notice to any products herein to improve reliability, function or design. SONIX does not
assume any liability arising out of the application or use of any product or circuit described herein; neither does it convey any license under its patent
rights nor the rights of others. SONIX products are not designed, intended, or authorized for us as components in systems intended, for surgical
implant into the body, or other applications intended to support or sustain life, or for any other application in which the fai lure of the SONIX product
could create a situation where personal injury or death may occur. Should Buyer purchase or use SONIX products for any such unintended or
unauthorized application. Buyer shall indemnify and hold SONIX and its officers, employees, subsidiaries, affiliates and distributors harmless against
all claims, cost, damages, and expenses, and reasonable attorney fees arising out of, directly or indirectly, any claim of pe rsonal injury or death
associated with such unintended or unauthorized use even if such claim alleges that SONIX was negligent regarding the design or manufacture of
the part.
N
X 88--
X
Biitt
B
Miiccrroo--
M
Coonnttrroolllleerr
C
SONiX TECHNOLOGY CO., LTD Page 1 Revision 0.5
Page 2
Preliminary SN8P1702A/SN8P1703A
AMENDMENT HISTORY
Version Date Description
VER 0.1 Jul. 2003 V1.0 Preliminary Version
VER 0.2 Jul. 2003 Change watchdog overflow table
8-bit micro-controller build-in 12-bit ADC
VER 0.3 Jul. 2003
Aug. 2003
VER 0.4 Sep. 2003 1. Add SN8P1702A SSOP20 for Mask Mass production.
VER 0.5 Sep. 2003 1. Modify ADC convert time table
1. Modify selection table
2. DC current chars. Change
3. Feature change
4. Change SN8P1703 part number to SN8P1703A
5. Code option table has been relocated after pin description section.
6. Modify QTP approval sheet
7. Change Register description.
8. Add LVD typical value=1.8V in Elec. Char.
9. Add “Noise Filter” code option
2. Add TC1 Timer in Update table.
3. Modify Chap. 8 table/figure no.
4. Modify TC0/TC1 timer description and table.
5. Modify PWM description and table.
6. Modify electrical characteristic table
2. Modify the description of PEDGE register.
3. Modify the description of INTRQ register.
3. Remove approval sheet.
4. Separate the pin description section of SN8P1702A and SN8P1703A.
5. Remove PCB layout section
6. Add P-DIP 20 and Sop 20 package information.
7. Add SN8A1702B and SN8A1703A related description.
The SN8P1702A/SN8P1703A is a series of 8-bit micro-controller. This chip is utilized with CMOS technology
fabrication and featured with low power consumption and high performance by its unique electronic structure.
This chip is designed with the excellent IC structure including the large program memory OTP ROM, the massive data
memory RAM, two 8-bit timer counters (TC0, TC1), a watchdog timer, three interrupt sources (TC0, TC1, INT0), an
4-channel ADC converter with 8-bit/12-bit resolution, two channels high speed PWM output (PWM0, PWM1), two
channels buzzer output (BZ0, BZ1) and 8-level stack buffers.
Besides, the user can choose desired oscillator configurations for the controller. There are four oscillator configurations
to select for generating system clock, including High/Low Speed crystal, ceramic resonator or cost-saving RC. This
series also includes an internal RC oscillator for slow mode controlled by programming.
♦Input only: P0 Bi-directional: P1, P4, P5Wakeup: P0, P1
Pull-up resisters: P0, P1, P4, P5 External interrupt: P0P4 pins shared with ADC inputs.External high clock: RC type up to 10 MHz External high clock: Crystal type up to 16 MHz
Two 8-bit timer counters. (TC0, TC1).
♦
On chip watchdog timer.
♦
Eight levels stack buffer.
♦Sleep mode: Both high and internal low clock stop
59 powerful instructions
♦Four clocks per instruction cycle All of instructions are one word length.
Most of instructions are one cycle only. SN8P1702A -- PDIP 18 / SOP 18 / SSOP20
All ROM area lookup table function (MOVC) SN8P1703A-- PDIP 20 / SOP 20 / SSOP20
Three interrupt sources
♦
An 4-channel 12-bit ADC
♦
Two channel high speed PWM output.
♦
Two channel Buzzer output. (BZ0/BZ1)
♦
Dual clock system offers four operating modes
♦
Internal low clock: RC type 16KHz(3V), 32KHz(5V)
Normal mode: Both high and internal low cloc k active
Slow mode: Internal low clock only
Green mode: Periodical wake-up by timer
Package (Chip form support)
♦
SONiX TECHNOLOGY CO., LTD Page 10 Revision 0.5
Page 11
Preliminary SN8P1702A/SN8P1703A
SYSTEM BLOCK DIAGRAM
8-bit micro-controller build-in 12-bit ADC
PORT 0
PC
OTP
IR
FLAGS
ALU
ACC
INTERRUPT
CONT ROL
PO RT 1PORT 4PO RT 5
ROM
S YSTEM R E GIST E R
H-OSC
TIMIN G GENERATOR
RAM
Internal
CLK
TIME R & COUNTER
Low Volt
Dete ctor
Watch-Dog
Timer
PWM0
PWM1
ADC
PWM0/Buzzer0
PWM1/Buzzer1
AIN0~AIN3
Figure 1-1.Simplified System Block Diagram
SONiX TECHNOLOGY CO., LTD Page 11 Revision 0.5
Page 12
Preliminary SN8P1702A/SN8P1703A
PIN ASSIGNMENT
Format Description:SN8P170XAY
Y
= P > PDIP, S > SOP,X> SSOP
SN8P1702A Pin Assignment
OTP Type:
SN8P1702AS (SOP 18PIN) / SN8P1702AP (PDIP 18PIN)
Pin compatible to the MASK version (SN8A1702AS/SN8A1702AP)
VDD, VSS P Power supply input pins for digital circuit.
RST I System reset input pin. Schmitt trigger structure, active “low”, normal stay to “high”.
XIN, XOUT I, O External oscillator pins. RC mode from XIN.
P0.0 / INT0 I Port 0.0 and shared with INT0 trigger pin (Schmitt trigger) / Built-in pull-up resisters.
Port 5.3 bi-direction pin, TC1÷2 signal output pin for buzzer or PWM1 output pin.
Built-in pull-up resisters.
Port 5.4 bi-direction pin, TC0÷2 signal output pin for buzzer or PWM0 output pin.
Built-in pull-up resisters.
AVREFH I A/D converter high analog reference voltage.
AIN0 ~ AIN3 I Analog signal input pins for ADC converter.
Table 1-3. Pin Description
PIN CIRCUIT DIAGRAMS
Port1, 4, 5 structure
Port1, 4, 5 structure
Port0 structure
Port0 structure
PUR
Pin
Pin
PUR
Int. bus
Int. bus
Pin
Pin
PnM
PnM
Figure 1-2. Pin Circuit Diagram
Note: All of the latch output circuits are push-pull structures.
PnM
PnM
PUR
PUR
PnM
PnM
Latch
Latch
Int. bus
Int. bus
SONiX TECHNOLOGY CO., LTD Page 15 Revision 0.5
Page 16
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
2
2
2
CODE OPTION TABLE
Code Option Content Function Description
RC Low cost RC for external high clock oscillator
Low frequency, power saving crystal (e.g. 32.768K) for external high
clock oscillator
Force Watch Dog Timer clock source come from INT 16K RC.
Also INT 16K RC never stop both in power down and green mode that
means Watch Dog Timer will always enable both in power down and
green mode.
High_Clk
High_Clk / 2
OSG
Watch_Dog
Security
TC0_Counter
TC1_Counter
Noise Filter
Low Power
INT_16K_RC
32K X’tal
12M X’tal High speed crystal /resonator (e.g. 12M) for external high clock oscillator
4M X’tal Standard crystal /resonator (e.g. 3.58M) for external high clock oscillator
Enable External high clock divided by two, Fosc = high clock / 2
Disable Fosc = hi gh clock
Enable Enable Oscillator Safe Guard function
Disable Disable Os cillator Safe Guard function
Enable Enable Watch Dog function
Disable Disable Watch Dog function
Enable Enable ROM code Security function
Disable Disable ROM code Security function
8-bit TC0 as 8-bit counter.
6-bit TC0 as 6-bit counter.
5-bit TC0 as 5-bit counter.
4-bit TC0 as 4-bit counter.
8-bit TC1 as 8-bit counter.
6-bit TC1 as 6-bit counter.
5-bit TC1 as 5-bit counter.
4-bit TC1 as 4-bit counter.
Enable Enable Noise Filter function to enhance EMI performance
Disable Disable Noise Filter function
Enable Enable Low Power function to save Operating current
Disable Disable Low Power function
Always ON
By_CPUM Enable or Disable internal 16K(at 3V) RC clock by CPUM registe r
Table 2-1. Code Option Table of SN8P1702A/SN8P1703A
Notice:
In high noisy environment, enable “Noise Filter”, “OSG” and disable “Low Power” is strongly
recommended.
The side effect is to increase the lowest valid working voltage level if enable “Noise Filter” or
“OSG” or “Low Power” code option.
Enable “Low Power” option will reduce operating current except in 32K X’tal or slow mode.
If users select “32K X’tal” in “High_Clk” option, assembler will force “OSG” to be enabled.
If users select “RC” in “High_Clk” option, assembler will force “High_Clk / 2” to be enabled.
SONiX TECHNOLOGY CO., LTD Page 16 Revision 0.5
Page 17
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
3
3
3
ADDRESS SPACES
PROGRAM MEMORY (ROM)
OVERVIEW
ROM Maps for SN8P1702A/SN8P1703A devices provide 1K x 16-bit program memory. The SN8P1702A/SN8P1703A
program memory is able to fetch instructions through 12-bit wide PC (Program Counter) and can look up ROM data by
using ROM code registers (R, X, Y, Z). In standard configuration, the device’s 1,024 x 16-bit program memory has four
areas:
1-word reset vector addresses
1-word Interrupt vector addresses
5-words reserved area
1K words (SN8P1702)
All of the program memory is partitioned into three coding areas. The first area is located from 00H to 03H(The Reset
vector area), the second area is a reserved area 04H ~07H, the third area is for the interrupt vector and the user code
area from 0008H to 03FEH. The address 08H is the interrupt enter address point.
0000H
0001H Jump to user start address
0002H Jump to user start address
0003H
0004H
0005H
0006H
0007H
0008H
0009H User program
.
.
000FH
0010H
0011H
.
.
03FEH
03FFH
General purpose area
General purpose area
ROM
Reset vector
Reserved
Interrupt vector
Reserved
User reset vector
Jump to user start address
User interrupt vector
End of user program
Figure 3-1. ROM Address Structure
SONiX TECHNOLOGY CO., LTD Page 17 Revision 0.5
Page 18
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
USER RESET VECTOR ADDRESS (0000H)
A 1-word vector address area is used to execute system reset. After power on reset or watchdog timer overflow reset,
then the chip will restart the program from address 0000h and all system registers will be set as default values. The
following example shows the way to define the reset vector in the program memory.
Example: After power on reset, external reset active or reset by watchdog timer overflow.
CHIP SN8P1702A
ORG 0 ; 0000H
JMP START ; Jump to user program address.
. ; 0001H ~ 0007H are reserved
ORG 10H
START: ; 0010H, The head of user program.
. ; User program
.
.
.
ENDP
; End of program
INTERRUPT VECTOR ADDRESS (0008H)
A 1-word vector address area is used to execute interrupt request. If any interrupt service is executed, the program
counter (PC) value is stored in stack buffer and points to 0008h of program memory to execute the vectored interrupt.
Users have to define the interrupt vector. The following example shows the way to define the interrupt vector in the
program memory.
Example 1: This demo program includes interrupt service routine and the user program is behind the
interrupt service routine.
CHIP SN8P1702A
ORG 0 ; 0000H
JMP START ; Jump to user program address.
. ; 0001H ~ 0007H are reserved
ORG 8
B0XCH A, ACCBUF
B0MOV A, PFLAG
B0MOV PFLAGBUF, A
.
.
.
B0MOV A, PFLAGBUF
B0MOV PFLAG, A
B0XCH A, ACCBUF
START: ; The head of user program.
RETI
.
.
.
.
JMP START
ENDP
; Interrupt service routine
; B0XCH doesn’t change C, Z flag
; Save PFLAG register in a buffer
; Restore PFLAG register from buffer
; B0XCH doesn’t change C, Z flag
; End of interrupt service routine
; User program
; End of user program
; End of program
SONiX TECHNOLOGY CO., LTD Page 18 Revision 0.5
Page 19
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
Example 2: The demo program includes interrupt service routine and the address of interrupt service
routine is in a special address of general-purpose area.
CHIP SN8P1702A
ORG 0 ; 0000H
JMP START ; Jump to user program address.
. ; 0001H ~ 0007H are reserved
ORG 08
JMP MY_IRQ ; 0008H, Jump to interrupt service routine address
ORG 10H
START: ; 0010H, The head of user program.
. ; User program
.
.
.
MY_IRQ: ; The head of interrupt service routine
B0XCH A, ACCBUF
B0MOV A, PFLAG
B0MOV PFLAGBUF, A
.
.
.
B0MOV A, PFLAGBUF
B0MOV PFLAG, A
B0XCH A, ACCBUF
Remark: It is easy to get the rules of SONIX program from demo programs given above. These points are
as following.
1. The address 0000H is a “JMP” instruction to make the program go to general-purpose ROM area. The
0004H~0007H are reserved. Users have to skip 0004H~0007H addresses. It is very important and
necessary.
2. The interrupt service starts from 0008H. Users can put the whole interrupt service routine from 0008H
(Example1) or to put a “JMP” instruction in 0008H then place the interrupt service routine in other
general-purpose ROM area (Example2) to get more modularized coding style.
JMP START
RETI
ENDP
; End of user program
; B0XCH doesn’t change C, Z flag
; Save PFLAG register in a buffer
; Restore PFLAG register from buffer
; B0XCH doesn’t change C, Z flag
; End of interrupt service routine
; End of program
SONiX TECHNOLOGY CO., LTD Page 19 Revision 0.5
Page 20
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
CHECKSUM CALCULATION
The ROM addresses 0004H~0007H and last address are reserved area. User should avoid these addresses
(0004H~0007H and last address) when calculate the Checksum value.
Example:
The demo program shows how to avoid 0004H~0007H when calculated Checksum from 00H to the end of
user’s code
MOV A,#END_USER_CODE$L
B0MOV END_ADDR1,A ; save low end address to end_addr1
MOV A,#END_USER_CODE$M
B0MOV END_ADDR2,A ; Save middle end address to end_addr2
CLR Y ; Set Y to 00H
CLR Z ; Set Z to 00H
@@: CALL YZ_CHECK ; Call function of check yz value
MOVC ;
B0BSET FC ; Clear C flag
ADD DATA1,A ; Add A to Data1
MOV A,R
ADC DATA2,A ; Add R to Data2
JMP END_CHECK ; Check if the YZ address = the end of code
AAA:
INCMS Z ;Z=Z+1
JMP @B ; If Z! = 00H calculate to next address
JMP Y_ADD_1 ; If Z=00H increase Y
END_CHECK:
MOV A,END_ADDR1
CMPRS A,Z ; Check if Z = low end address
JMP AAA ; If Not jump to checksum calculate
MOV A,END_ADDR2
CMPRS A,Y ; If Yes, check if Y = middle end address
JMP AAA ; If Not jump to checksum calculate
JMP CHECKSUM_END ; If Yes checksum calculated is done.
YZ_CHECK: ;check if YZ=0004H
MOV A,#04H
CMPRS A,Z ;check if Z=04H
RET ;if Not return to checksum calculate
MOV A,#00H
CMPRS A,Y ;if Yes, check if Y=00H
RET ;if Not return to checksum calculate
INCMS Z ;if Yes, increase 4 to Z
INCMS Z
INCMS Z
INCMS Z RET ;set YZ=0008H then return
Y_ADD_1:
INCMS Y ;increase Y
NOP JMP @B ;jump to checksum calculate
CHECKSUM_END:
……….
……….
END_USER_CODE: ;Label of program end
SONiX TECHNOLOGY CO., LTD Page 20 Revision 0.5
Page 21
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
GENERAL PURPOSE PROGRAM MEMORY AREA
The 992-word at ROM locations 0010H~0FEFH are used as general-purpose memory. The area is stored instruction’s
op-code and look-up table data. The SN8P1702A/SN8P1703A includes jump table function by using program counter
(PC) and look-up table function by using ROM code registers (R, X, Y, Z).
The boundary of program memory is separated by the high-byte program counter (PCH) every 100H. In jump table
function and look-up table function, the program counter can’t leap over the boundary by program counter
automatically. Users need to modify the PCH value to “PCH+1” as the PCL overflow (from 0FFH to 000H).
LOOKUP TABLE DESCRIPTION
In the ROM’s data lookup function, the X register is pointed to the highest 8-bit, Y register to the middle 8-bit and Z
register to the lowest 8-bit data of ROM address. After MOVC instruction is executed, the low-byte data of ROM then
will be stored in ACC and high-byte data stored in R register.
Example: To look up the ROM data located “TABLE1”.
B0MOV Y, #TABLE1$M ; To set lookup table1’s middle address
B0MOV Z, #TABLE1$L ; To set lookup table1’s low address.
MOVC ; To lookup data, R = 00H, ACC = 35H
;
;
@@:MOVC ; To lookup data, R = 51H, ACC = 05H.
. . ;
TABLE1: DW 0035H ; To define a word (16 bits) data.
DW 5105H ; “
DW 2012H ; “
CAUSION: The Y register can't increase automatically if Z register cross boundary from 0xFF to 0x00.
Therefore, user must take care such situation to avoid loop-up table errors. If Z register overflow, Y
register must be added one. The following INC_YZ macro shows a simple method to process Y and Z
registers automatically.
Note: Because the program counter (PC) is only 12-bit, the X register is useless in the application. Users
can omit “B0MOV X, #TABLE1$H”. SONiX ICE support more larger program memory addressing
capability. So make sure X register is “0” to avoid unpredicted error in loop-up table operation.
INCMS Z ; Z+1
JMP @F ; Not overflow
INCMS Y ; Z overflow (FFH 00), Y=Y+1
NOP ; Not overflow
; Increment the index address for next address
Example: INC_YZ Macro
INC_YZ MACRO INCMS Z ; Z+1
JMP @F ; Not overflow
INCMS Y ; Y+1
NOP ; Not overflow
@@: ENDM
SONiX TECHNOLOGY CO., LTD Page 21 Revision 0.5
Page 22
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
The other coding style of loop-up table is to add Y or Z index register by accumulator. Be careful if carry happen. Refer
following example for detailed information:
Example: Increase Y and Z register by B0ADD/ADD instruction
B0MOV Y, #TABLE1$M ; To set lookup table’s middle address.
B0MOV Z, #TABLE1$L ; To set lookup table’s low address
GETDATA: ;
MOVC ; To lookup data. If BUF = 0, data is 0x0035
; If BUF = 1, data is 0x5105
; If BUF = 2, data is 0x2012
.
.
. . ;
TABLE1: DW 0035H ; To define a word (16 bits) data.
DW 5105H ; “
DW 2012H ; “
B0MOV A, BUF ; Z = Z + BUF.
B0ADD Z, A
B0BTS1 FC ; Check the carry flag.
JMP GETDATA ; FC = 0
INCMS Y ; FC = 1. Y+1.
NOP
SONiX TECHNOLOGY CO., LTD Page 22 Revision 0.5
Page 23
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
JUMP TABLE DESCRIPTION
The jump table operation is one of multi-address jumping function. Add low-byte program counter (PCL) and ACC
value to get one new PCL. The new program counter (PC) points to a series jump instructions as a listing table. The
way is easy to make a multi-stage program.
When carry flag occurs after executing of “ADD PCL, A”, it will not affect PCH register. Users have to check if the jump
table leaps over the ROM page boundary or the listing file generated by SONIX assembly software. If the jump table
leaps over the ROM page boundary (e.g. from xxFFH to xx00H), move the jump table to the top of next program
memory page (xx00H). Here one page mean 256 words.
Example : If PC = 0323H (PCH = 03H、PCL = 23H)
ORG 0X0100 ; The jump table is from the head of the ROM boundary
B0ADD PCL, A ; PCL = PCL + ACC, the PCH can’t be changed.
JMP A0POINT ; ACC = 0, jump to A0POINT
JMP A1POINT ; ACC = 1, jump to A1POINT
JMP A2POINT ; ACC = 2, jump to A2POINT
JMP A3POINT ; ACC = 3, jump to A3POINT
In following example, the jump table starts at 0x00FD. When execute B0ADD PCL, A. If ACC = 0 or 1, the jump
table points to the right address. If the ACC is larger then 1 will cause error because PCH doesn't increase one
automatically. We can see the PCL = 0 when ACC = 2 but the PCH still keep in 0. The program counter (PC) will
point to a wrong address 0x0000 and crash system operation. It is important to check whether the jump table
crosses over the boundary (xxFFH to xx00H). A good coding style is to put the jump table at the start of ROM
boundary (e.g. 0100H).
Example: If “jump table” crosses over ROM boundary will cause errors.
ROM Address
. .
. .
. .
0X00FD
0X00FE
0X00FF
0X0100
0X0101
. .
. .
SONIX provides a macro for safe jump table function. This macro will check the ROM boundary and move the jump
table to the right position automatically. The side effect of this macro is maybe wasting some ROM size. Notice the
maximum jump table number for this macro is limited fewer than 254.
@JMP_A MACRO VAL IF (($+1) !& 0XFF00) !!= (($+(VAL)) !& 0XFF00)
JMP ($ | 0XFF) ORG ($ | 0XFF)
ENDIF
ADD PCL, A
ENDM
Note: “VAL” is the number of the jump table listing number.
Example: “@JMP_A” application in SONIX macro file called “MACRO3.H”.
B0MOV A, BUF0 ; “BUF0” is from 0 to 4.
@JMP_A 5 ; The number of the jump table listing is five.
JMP A0POINT ; If ACC = 0, jump to A0POINT
JMP A1POINT ; ACC = 1, jump to A1POINT
JMP A2POINT ; ACC = 2, jump to A2POINT
JMP A3POINT ; ACC = 3, jump to A3POINT
JMP A4POINT ; ACC = 4, jump to A4POINT
If the jump table position is from 00FDH to 0101H, the “@JMP_A” macro will make the jump table to start from 0100h.
SONiX TECHNOLOGY CO., LTD Page 24 Revision 0.5
Page 25
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
DATA MEMORY (RAM)
OVERVIEW
The SN8P1702A/SN8P1703A has internally built-in the data memory up to 256 bytes for storing the general-purpose
data.
128 * 8-bit general purpose area in bank 0
128 * 8-bit system special register area
The memory is separated into bank 0 and bank 1. The user can program RAM bank selection bits of RBANK register to
access all data in any of the two RAM banks. The bank 0, using the first 128-byte location assigned as
general-purpose area, and the remaining 128-byte in bank 0 as system register.
BANK 0
Note: The undefined locations of system register area are logic “high” after executing read instruction
“MOV A, M”.
000h 000h~07Fh of Bank 0 = To store general-
“ purpose data (128 bytes).
“
“
“
“
07Fh
080h 080h~0FFh of Bank 0 = To store system
“ registers (128 bytes).
“
“
“
“
0FFh
Figure 3-2. RAM Location
RAM location
General purpose area
System register
End of bank 0 area
SONiX TECHNOLOGY CO., LTD Page 25 Revision 0.5
Page 26
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
WORKING REGISTERS
The locations 82H to 84H of RAM bank 0 in data memory stores the specially defined registers such as register R, Z, Y,
respectively shown in the following table. These registers can use as the general purpose of working buffer and be
used to access ROM’s and RAM’s data. For instance, all of the ROM’s table can be looked-up with R, Y and Z
registers. The data of RAM memory can be indirectly accessed with Y and Z registers.
82H 83H 84H
RAM
R/W R/W R/W
Y, Z REGISTERS
The Y and Z registers are the 8-bit buffers. There are three major functions of these registers. First, Y and Z registers
can be used as working registers. Second, these two registers can be used as data pointers for @YZ register. Third,
the registers can be address ROM location in order to look-up RO M data.
Y initial value = 0000 0000
084H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
Y
R/W R/W R/W R/W R/W R/W R/W R/W
Z initial value = 0000 0000
083H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
Z
R/W R/W R/W R/W R/W R/W R/W R/W
The @YZ that is data point_1 index buffer located at address E7H in RAM bank 0. It employs Y and Z registers to
addressing RAM location in order to read/write data through ACC. The Lower 4-bit of Y register is pointed to RAM bank
number and Z register is pointed to RAM address number, respectively. The higher 4-bit data of Y register is truncated
in RAM indirectly access mode.
Example: If want to read a data from RAM address 25H of bank 1, it can use indirectly addressing mode to
B0MOV Y, #01H ; To set RAM bank 1 for Y register
B0MOV Z, #25H ; To set location 25H for Z register
B0MOV A, @YZ ; To read a data into ACC
Example: Clear general-purpose data memory area of bank 1 using @YZ register.
MOV A, #1
B0MOV Y, A ; Y = 1, bank 1
MOV A, #07FH
B0MOV Z, A ; Y = 7FH, the last address of the data memory area
CLR_YZ_BUF: CLR @YZ ; Clear @YZ to be zero
DECMS Z ; Y – 1, if Y= 0, finish the routine
JMP CLR_YZ_BUF ; Not zero
CLR @YZ
END_CLR: ; End of clear general purpose data memory area of bank 0
Note: Please consult the “LOOK-UP TABLE DESCRIPTION” about Y, Z register look-up table application.
R Z Y
YBIT7 YBIT6 YBIT5 YBIT4 YBIT3 YBIT2 YBIT1 YBIT0
ZBIT7 ZBIT6 ZBIT5 ZBIT4 ZBIT3 ZBIT2 ZBIT1 ZBIT0
access data as following.
SONiX TECHNOLOGY CO., LTD Page 26 Revision 0.5
Page 27
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
R REGISTERS
There are two major functions of the R register. First, R register can be used as working registers. Second, the R
registers can be store high-byte data of look-up ROM data. After MOVC instruction executed, the high-byte data of a
ROM address will be stored in R register and the low-byte data stored in ACC.
R initial value = 0000 0000
082H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
R
R/W R/W R/W R/W R/W R/W R/W R/W
Note: Please consult the “LOOK-UP TABLE DESCRIPTION” about R register look-up table application.
RBIT7 RBIT6 RBIT5 RBIT4 RBIT3 RBIT2 RBIT1 RBIT0
PROGRAM FLAG
The PFLAG includes carry flag (C), decimal carry flag (DC) and zero flag (Z). If the result of operating is zero or there is
carry, borrow occurrence, then these flags will be set to PFLAG register.
PFLAG initial value = xxxx x000
086H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
PFLAG
- - - - - R/W R/W R/W
- - - - - C DC Z
CARRY FLAG
C = 1: If executed arithmetic addition with occurring carry signal or executed arithmetic subtraction without borrowing
signal or executed rotation instruction with shifting out logic “1”.
C = 0: If executed arithmetic addition without occurring carry signal or executed arithmetic subtraction with borrowing
signal or executed rotation instruction with shifting out logic “0”.
DECIMAL CARRY FLAG
DC = 1: If executed arithmetic addition with occurring carry signal from low nibble or executed arithmetic subtraction
without borrow signal from high nibble.
DC = 0: If executed arithmetic addition without occurring carry signal from low nibble or executed arithmetic subtraction
with borrow signal from high nibble.
ZERO FLAG
Z = 1: After operation, the content of ACC is zero.
Z = 0: After operation, the content of ACC is not zero.
SONiX TECHNOLOGY CO., LTD Page 27 Revision 0.5
Page 28
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
ACCUMULATOR
The ACC is an 8-bits data register responsible for transferring or manipulating data between ALU and data memory. If
the result of operating is zero (Z) or there is carry (C or DC) occurrence, then these flags will be set to PFLAG register.
ACC is not in data memory (RAM), so ACC can’t be access by “B0MOV” instruction during the instant addressing
mode.
Example: Read and write ACC value.
; Read ACC data and store in BUF data memory
MOV BUF, A
. .
; Write a immediate data into ACC
MOV A, #0FH
. .
; Write ACC data from BUF data memory
MOV A, BUF
. .
The system doesn’t store ACC and PFLAG value as any interrupt service executed. ACC must be exchanged to
another data memory defined by users. Thus, once interrupt occurs, these data must be stored in the data memory
based on the user’s program as follows.
Example: ACC and working registers protection.
ACCBUF EQU 00H ; ACCBUF is ACC data buffer in bank 0.
INT_SERVICE:
B0XCH A, ACCBUF
B0XCH A, ACCBUF ; Store ACC value
B0MOV A, PFLAG ; Store PFLAG value
B0MOV PFLAGBUF,A
.
B0MOV A, PFLAGBUF ; Re-load PFLAG value
B0MOV PFLAG,A
B0XCH A, ACCBUF ; Re-load ACC
B0XCH A, ACCBUF ; Re-load ACC
RETI ; Exit interrupt service vector
Notice: To save and re-load ACC data must be used “B0XCH” instruction, or the PLAGE value maybe
modified by ACC.
; B0XCH doesn’t change C, Z flag
SONiX TECHNOLOGY CO., LTD Page 28 Revision 0.5
Page 29
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
STACK OPERATIONS
OVERVIEW
The stack buffer of SN8P1702A/SN8P1703A has 8-level high area and each level is 12-bits length. This buffer is
designed to save and restore program counter’s (PC) data when interrupt service is executed. The STKP register is a
pointer designed to point active level in order to save or restore data from stack buffer for kernel circuit. The STKnH
and STKnL are the 12-bit stack buffers to store program counter (PC) data.
STACK BUFFER
STACK BUFFER
PCL
PCL
PCLPCL
STK0L
STK0L
STK0L
RET /
RET /
RETI
RETI
CALL /
CALL /
interrupt
interrupt
STKP = 7
STKP = 7
STKP = 7
PCH
PCH
PCHPCH
STK0H
STK0H
STK0H
STKP + 1
STKP + 1
STKP + 1
STKP - 1
STKP - 1
STKP - 1STKP - 1
STKP = 6
STKP = 6
STKP = 6
STKP = 5
STKP = 5
STKP = 5
STKP = 4
STKP = 4
STKP = 4
STKP = 3
STKP = 3
STKP = 3
STKP = 2
STKP = 2
STKP = 2
STKP = 1
STKP = 1
STKP = 1
STKP = 0
STKP = 0
STKP = 0
STKP
STKPSTKP
STK1H
STK1H
STK1H
STK2H
STK2H
STK2H
STK3H
STK3H
STK3H
STK4H
STK4H
STK4H
STK5H
STK5H
STK5H
STK6H
STK6H
STK6H
STK7H
STK7H
STK7H
STKP
STKPSTKP
Figure 3-3 Stack-Save and Stack-Restore Operation
STK1L
STK1L
STK1L
STK2L
STK2L
STK2L
STK3L
STK3L
STK3L
STK4L
STK4L
STK4L
STK5L
STK5L
STK5L
STK6L
STK6L
STK6L
STK7L
STK7L
STK7L
SONiX TECHNOLOGY CO., LTD Page 29 Revision 0.5
Page 30
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
STACK REGISTERS
The stack pointer (STKP) is a 4-bit register to store the address used to access the stack buffer, 12-bits data memory
(STKnH and STKnL) set aside for temporary storage of stack addresses.
The two stack operations are writing to the top of the stack (Stack-Save) and reading (Stack-Restore) from the top of
stack. Stack-Save operation decrements the STKP and the Stack-Restore operation increments one time. That makes
the STKP always points to the top address of stack buffer and writes the last program counter value (PC) into the stack
buffer.
The program counter (PC) value is stored in the stack buffer before a CALL instruction executed or during interrupt
service routine. Stack operation is a LIFO type (Last in and first out). The stack pointer (STKP) and stack buffer
(STKnH and STKnL) are located in the system register area bank 0.
STKP (stack pointer) initial value = 0xxx 1111
0DFH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
STKP
R/W - - - R/W R/W R/W R/W
STKPBn: Stack pointer. (n = 0 ~ 3)
GIE: Global interrupt control bit. 0 = disable, 1 = enable. More detail information is in interrupt chapter.
0F0H~0FFH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
STKnH
- - - - - - R/W R/W
0F0H~0FFH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
STKnL
R/W R/W R/W R/W R/W R/W R/W R/W
STKnH: Store PCH data as interrupt or call executing. The n expressed 0 ~7.
STKnL: Store PCL data as interrupt or call executing. The n expressed 0 ~7.
GIE - - - STKPB3 STKPB2 STKPB1 STKPB0
- - - - - - SnPC9 SnPC8
SnPC7 SnPC6 SnPC5 SnPC4 SnPC3 SnPC2 SnPC1 SnPC0
SONiX TECHNOLOGY CO., LTD Page 30 Revision 0.5
Page 31
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
STACK OPERATION EXAMPLE
The two kinds of Stack-Save operations to reference the stack pointer (STKP) and write the program counter contents
(PC) into the stack buffer are CALL instruction and interrupt service. Under each condition, the STKP is decremented
and points to the next available stack location. The stack buffer stores the program counter about the op-code address.
The Stack-Save operation is as following table.
Table 3-1. STKP, STKnH and STKnL relative of Stack-Save Operation
The RETI instruction is for interrupt service routine. The RET instruction is for CALL instruction. When a Stack-Restore
operation occurs, the STKP is incremented and points to the next free stack location. The stack buffer restores the last
program counter (PC) to the program counter registers. The Stack-Restore operation is as following table.
Table 3-2. STKP, STKnH and STKnL relative of Stack-Restore Operation
SONiX TECHNOLOGY CO., LTD Page 31 Revision 0.5
Page 32
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
PROGRAM COUNTER
The program counter (PC) is a 12-bit binary counter separated into the high-byte 4 bits and the low-byte 8 bits. This
counter is responsible for pointing a location in order to fetch an instruction for kernel circuit. Normally, the program
counter is automatically incremented with each instruction during program exe cu tion.
Besides, it can be replaced with specific address by executing CALL or JMP instruction. When JMP or CALL instruction
is executed, the destination address will be inserted to bit 0 ~ bit 11.
PC Initial value = xxxx 0000 0000 0000
Bit 15 Bit 14 Bit 13 Bit 12 Bit 11 Bit 10 Bit 9Bit 8Bit 7Bit 6Bit 5Bit 4 Bit 3 Bit 2Bit 1Bit 0
PC
PCH Initial value = xxxx 0000
PCL Initial value = 0000 0000
- - - - - - 0 0 0 0 0 0 0 0 0 0
0CFH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
PCH
- - - - - - R/W R/W
0CEH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
PCL
R/W R/W R/W R/W R/W R/W R/W R/W
- - - - - - PC9 PC8
PC7 PC6 PC5 PC4 PC3 PC2 PC1 PC0
PCH PCL
SONiX TECHNOLOGY CO., LTD Page 32 Revision 0.5
Page 33
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
ONE ADDRESS SKIPPING
There are 9 instructions (CMPRS, INCS, INCMS, DECS, DECMS, BTS0, BTS1, B0BTS0, B0BTS1) with one address
skipping function. If the result of these instructions is matched, the PC will add 2 steps to skip next instruction.
If the condition of bit test instruction is matched, the PC will add 2 steps to skip next instruction.
JMP C0STEP ; Else jump to C0STEP.
.
C0STEP: NOP
B0MOV A, BUF0 ; Move BUF0 value to ACC.
JMP C1STEP ; Else jump to C1STEP.
.
C1STEP: NOP
If the ACC is equal to the immediate data or memory, the PC will add 2 steps to skip next instruction.
JMP C0STEP ; Else jump to C0STEP.
.
C0STEP: NOP
If the result after increasing or decreasing by 1 is 0xFF or 0x00, the PC will add 2 steps to skip next instruction.
INCS instruction:
JMP C0STEP ; Jump to C0STEP if ACC is not zero.
…
C0STEP: NOP
INCMS instruction:
JMP C0STEP ; Jump to C0STEP if BUF0 is not zero.
…
C0STEP: NOP
DECS instruction:
JMP C0STEP ; Jump to C0STEP if ACC is not zero.
…
C0STEP: NOP
DECMS instruction:
JMP C0STEP ; Jump to C0STEP if BUF0 is not zero.
…
C0STEP: NOP
B0BTS1
B0BTS0
CMPRS
INCS
INCMS
DECS
DECMS
FC ; Skip next instruction, if Carry flag = 1
FZ ; Skip next instruction, if Zero flag = 0.
A, #12H ; Skip next instruction, if ACC = 12H.
BUF0
BUF0
BUF0
BUF0
SONiX TECHNOLOGY CO., LTD Page 33 Revision 0.5
Page 34
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
MULTI-ADDRESS JUMPING
Users can jump round multi-address by either JMP instruction or ADD M, A instruction (M = PCL) to activate
multi-address jumping function. If carry signal occurs after execution of ADD PCL, A, the carry signal will not affect
PCH register.
Example: If PC = 0323H (PCH = 03H、PCL = 23H)
; PC = 0323H
MOV A, #28H
B0MOV PCL, A ; Jump to address 0328H
. .
. .
; PC = 0328H . .
MOV A, #00H
B0MOV PCL, A ; Jump to address 0300H
Example: If PC = 0323H (PCH = 03H、PCL = 23H)
; PC = 0323H B0ADD PCL, A ; PCL = PCL + ACC, the PCH cannot be changed.
JMP A0POINT ; If ACC = 0, jump to A0POINT
JMP A1POINT ; ACC = 1, jump to A1POINT
JMP A2POINT ; ACC = 2, jump to A2POINT
JMP A3POINT ; ACC = 3, jump to A3POINT
. . ;
SONiX TECHNOLOGY CO., LTD Page 34 Revision 0.5
Page 35
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
4
4
4
ADDRESSING MODE
OVERVIEW
The SN8P1702A/SN8P1703A provides three addressing modes to access RAM data, including immediate addressing
mode, directly addressing mode and indirectly address mode. The main purpose of the three different modes is
described in the following:
IMMEDIATE ADDRESSING MODE
The immediate addressing mode uses an immediate data to set up the location (MOV A, #I, B0MOV M,#I) in ACC or
specific RAM.
Immediate addressing mode
MOV A, #12H ; To set an immediate data 12H into ACC
DIRECTLY ADDRESSING MODE
The directly addressing mode uses address number to access memory location (MOV A,12H, MOV 12H,A).
Directly addressing mode
B0MOV A, 12H ; To get a content of location 12H of bank 0 and save in ACC
INDIRECTLY ADDRESSING MODE
The indirectly addressing mode is to set up an address in data pointer registers (Y/Z) and uses MOV instruction to
read/write data between ACC and @YZ register (MOV A,@YZ, MOV @YZ,A).
Example: Indirectly addressing mode with @YZ register
CLR Y ; To clear Y register to access RAM bank 0.
B0MOV Z, #12H ; To set an immediate data 12H into Z register.
B0MOV A, @YZ ; Use data pointer @YZ reads a data from RAM location
; 012H into ACC.
SONiX TECHNOLOGY CO., LTD Page 35 Revision 0.5
Page 36
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
TO ACCESS DATA in RAM BANK 0
In the RAM bank 0, this area memory can be read/written by these three access methods.
Example 1: To use RAM bank0 dedicate instruction (Such as B0xxx instruction).
B0MOV A, 12H ; To move content from location 12H of RAM bank 0 to ACC
Example 3: To use indirectly addressing mode with @YZ register.
CLR Y ; To clear Y register for accessing RAM bank 0.
B0MOV Z, #12H ; To set an immediate data 12H into Z register.
B0MOV A, @YZ ; Use data pointer @YZ reads a data from RAM location
; 012H into ACC.
SONiX TECHNOLOGY CO., LTD Page 36 Revision 0.5
Page 37
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
5
5
5
SYSTEM REGISTER
OVERVIEW
The system special register is located at 80h~FFh. The main purpose of system registers is to control the peripheral
hardware of the chip. Using system registers can control I/O ports, SIO, ADC, PWM, timers and counters by
programming. The Memory map provides an easy and quick reference source for writing application program. To
accessing these system registers is controlled by the select memory bank (RBANK = 0) or the bank 0 read/write
instruction (B0MOV, B0BSET, B0BCLR…).
@HL = RAM HL indirect addressing index pointer. PCH, PCL = Program counter.
STK0~STK7 = Stack 0 ~ stack 7 buffer.
@YZ = RAM YZ indirect addressing index pointer.
Note:
a). All of register names had been declared in SONiX 8-bit MCU assembler.
b). One-bit name had been declared in SONiX 8-bit MCU assembler with “F” prefix code.
c). It will get logic “H” data, when use instruction to check empty location.
d). The low nibble of ADR register is read only.
e). “b0bset”, “b0bclr”, ”bset”, ”bclr” instructions only support “R/W” registers.
Note:
a). To avoid system error, please be sure to put all the “0” as it indicates in the above table
b). All of register name had been declared in SONiX 8-bit MCU assembler.
c). One-bit name had been declared in SONiX 8-bit MCU assembler with “F” prefix code.
d). “b0bset”, “b0bclr”, ”bset”, ”bclr” instructions only support “R/W” registers.
SONiX TECHNOLOGY CO., LTD Page 38 Revision 0.5
Page 39
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
6
6
6
OVERVIEW
This series provides two system resets. One is external reset and the other is low voltage detector (LVD). The external
reset is a simple RC circuit connecting to the reset pin. The low voltage detector (LVD) is built in internal circuit. When
one of the reset devices occurs, the system will reset and the system registers become initial value. The timing
diagram is as following.
POWER ON RESET
VDD
External Reset
LVD
LVD Detect Level
External Reset Detect Level
End of LVD Reset
Internal Reset Signal
Figure 6-1 Power on Reset Timing Diagram
End of External Reset
SONiX TECHNOLOGY CO., LTD Page 39 Revision 0.5
Page 40
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
EXTERNAL RESET DESCRIPTION
The external reset is a low level active device. The reset pin receives the low voltage and resets the system. When the
voltage detects high level, it stops resetting the system. Users can use an external reset circuit to control system
operation. It is necessary that the VDD must be stable.
VDD
External Reset
Internal Reset Signal
Figure 6-2 External Reset Timing Diagram
Users must to be sure the VDD stable earlier than external reset (Figure 5-2) or the external reset will fail. The external
reset circuit is a simple RC circuit as following.
R
20K ohm
C
0.1uF
External Reset Detect Level
End of External ResetSystem Reset
VDD
RST
MCU
VSS
VCC
GND
Figure 6-3. External Reset Circuit
SONiX TECHNOLOGY CO., LTD Page 40 Revision 0.5
Page 41
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
In worse power, condition as brown out reset. The reset pin may keep high level but the VDD is low voltage. That
makes the system reset fail and chip error. To connect a diode from reset pin to VDD is a good solution. The circuit can
force the capacitor to release electric charge and drop the voltage, and solve the error.
DIODE
R
20K ohm
C
0.1uF
VDD
RST
MCU
VSS
VCC
GND
Figure 6-4. External Reset Circuit with Diode
SONiX TECHNOLOGY CO., LTD Page 41 Revision 0.5
Page 42
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
7
7
7
OSCILLATORS
OVERVIEW
The SN8P1702A/SN8P1703A highly performs the dual clock micro-controller system. The dual clocks are high-speed
clock and low-speed clock. The high-speed clock frequency is supplied through the external oscillator circuit. The
low-speed clock frequency is supplied through on-chip RC oscillator circuit.
The external high-speed clock and the internal low-speed clock can be system clock (Fosc). And the system clock is
divided by 4 to be the instruction cycle (Fcpu).
Fcpu = Fosc / 4
The system clock is required by the following peripheral modules:
0 = Fcpu ÷ 2
1 = Fcpu ÷ 2
(The detail information is in watchdog timer chapter.)
0 = Non reset,
1 = clear the watchdog timer’s counter.
(The detail information is in watchdog timer chapter.)
0 = Fcpu,
1 = internal RC low clock.
14
8
SONiX TECHNOLOGY CO., LTD Page 43 Revision 0.5
Page 44
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
EXTERNAL HIGH-SPEED OSCILLATOR
This series can be operated in four different oscillator modes. There are external RC oscillator modes, high
crystal/resonator mode (12M code option), standard crystal/resonator mode (4M code option) and low crystal mode
(32K code option). For different application, the users can select one of satiable oscillator mode by programming code
option to generate system high-speed clock source after reset.
Example: Stop external high-speed oscillator.
B0BSET FSTPHX ; To stop external high-speed oscillator only.
B0BSET FCPUM0 ; To stop external high-speed oscillator and internal low-speed
; oscillator called power down mode (sleep mode).
OSCILLATOR MODE CODE OPTION
This series has four oscillator modes for different applications. These modes are 4M, 12M, 32K and RC. The main
purpose is to support different oscillator types and frequencies. High-speed crystal needs more current but the low one
doesn’t. For crystals, there are three steps to select. If the oscillator is RC type, to select “RC” and the system will
divide the frequency by 2 automatically. User can select oscillator mode from Code Option table before compiling. The
table is as follow.
Code Option Oscillator Mode Remark
00
01
10
11
RC mode Output the Fcpu square wave from Xout pin.
32K 32768Hz
12M 12MHz ~ 16MHz
4M 3.58MHz
OSCILLATOR DEVIDE BY 2 CODE OPTION
This series has an external clock divide by 2 function. It is a code option called “High_Clk / 2”. If “High_Clk / 2” is
enabled, the external clock frequency is divided by 8 for the Fcpu. Fcpu is equal to Fosc/8. If “High_Clk / 2” is disabled,
the external clock frequency is divided by 4 for the Fcpu. The Fcpu is equal to Fosc/4.
Note: In RC mode, “High_Clk / 2” is always enabled.
OSCILLATOR SAFE GUARD CODE OPTION
This series builds in an oscillator safe guard (OSG) to make oscillator more stable. It is a low-pass filter circuit and
stops high frequency noise into system from external oscillator circuit. This function makes system to work better under
AC noisy conditions.
SONiX TECHNOLOGY CO., LTD Page 44 Revision 0.5
Page 45
Preliminary SN8P1702A/SN8P1703A
SYSTEM OSCILLATOR CIRCUITS
8-bit micro-controller build-in 12-bit ADC
20PF
CRYSTAL
20PF
Figure 7-2. Crystal/Ceramic Oscillator
R
C
Figure 7-3. RC Oscillator
VDD
XIN
XOUT
VSS
VDD
XIN
XOUT
VSS
MCU
MCU
External Clock Input
Figure 7-4. External clock input
Note1: The VDD and VSS of external oscillator circuit must be from the micro-controller. Don’t connect
them from the neighbor power terminal.
Note2: The external clock input mode can select RC type oscillator or crystal type oscillator of the code
option and input the external clock into XIN pin.
Note3: In RC type oscillator code option situation, the external clock’s frequency is divided by 2.
Note4: The power and ground of external oscillator circuit must be connected from the micro-controller’s
VDD and VSS. It is necessary to step up the performance of the whole system.
VDD
XIN
XOUT
VSS
MCU
SONiX TECHNOLOGY CO., LTD Page 45 Revision 0.5
Page 46
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
External RC Oscillator Frequency Measurement
There are two ways to get the Fosc frequency of external RC oscillator. One measures the XOUT output waveform.
Under external RC oscillator mode, the XOUT outputs the square waveform whose frequency is Fcpu. The other
measures the external RC frequency by instruction cycle (Fcpu). The external RC frequency is the Fcpu multiplied by 4.
We can get the Fosc frequency of external RC from the Fcpu frequency. The sub-routine to get Fcpu frequency of
external oscillator is as the following.
Example: Fcpu instruction cycle of external oscillator
B0BSET P1M.0 ; Set P1.0 to be output mode for outputting Fcpu toggle
signal.
@@: B0BSET P1.0 ; Output Fcpu toggle signal in low-speed clock mode.
B0BCLR P1.0 ; Measure the Fcpu frequency by oscilloscope.
JMP @B
SONiX TECHNOLOGY CO., LTD Page 46 Revision 0.5
Page 47
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
INTERNAL LOW-SPEED OSCILLATOR
The internal low-speed oscillator is built in the micro-controller. The low-speed clock’s source is a RC type oscillator
circuit. The low-speed clock can supplies clock for system clock, timer counter, watchdog timer, SIO clock source and
so on.
Example: Stop internal low-speed oscillator.
B0BSET FCPUM0 ; To stop external high-speed oscillator and internal low-speed
; oscillator called power down mode (sleep mode).
Note: The internal low-speed clock can’t be turned off individually. It is controlled by CPUM0 bit of OSCM
register.
The low-speed oscillator uses RC type oscillator circuit. The frequency is affected by the voltage and temperature of
the system. In common condition, the frequency of the RC oscillator is about 16KHz at 3V and 32KHz at 5V. The
relative between the RC frequency and voltage is as following.
Internal RC vs. VDD
40
35
30
25
20
15
10
Fintrc (KHz)
5
0
1.802.002.503.003.504.004.505.005.506.006.50
7.329
25.338
22.003
18.668
15.333
11.998
8.663
32.008
28.673
VDD (Volts)
Figure 7-5. Internal RC vs. VDD Diagram
Example: To measure the internal RC frequency is by instruction cycle (Fcpu). The internal RC frequency is
the Fcpu multiplied by 4. Therefore, we can get the Fosc frequency of internal RC from the Fcpu
frequency.
B0BSET P1M.0 ; Set P1.0 to be output mode for outputting Fcpu toggle signal.
B0BSET FCLKMD ; Switch the system clock to internal low-speed clock mode.
@@:
B0BSET P1.0 ; Output Fcpu toggle signal in low-speed clock mode.
B0BCLR P1.0 ; Measure the Fcpu frequency by oscilloscope.
JMP @B
38.678
35.343
SONiX TECHNOLOGY CO., LTD Page 47 Revision 0.5
Page 48
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
SYSTEM MODE DESCRIPTION
OVERVIEW
The chip is featured with low power consumption by switching around three different modes as followi ng.
In actual application, the user can adjust the chip’s controller to work in these three modes by using OSCM register. At
the high-speed mode, the instruction cycle (Fcpu) is Fosc/4. At the low-speed mode and 3V, the Fcpu is 16KHz/4.
NORMAL MODE
In normal mode, the system clock source is external high-speed clock. After power on, the system works under normal
mode. The instruction cycle is fosc/4. When the external high-speed oscillator is 3.58MHz, the instruction cycle is
3.58MHz/4 = 895KHz. All software and hardware are executed and working. In normal mode, system can get into
power down mode and slow mode.
SLOW MODE
In slow mode, the system clock source is internal low-speed RC clock. To set CLKMD = 1, the system switch to slow
mode. In slow mode, the system works as normal mode but the slower clock. The system in slow mode can get into
normal mode and power down mode. To set STPHX = 1 to stop the external high-speed oscillator, and then the system
consumes less power.
GREEN MODE
The green mode is a less power consumption mode. Under green mode, there are only TC0 still counting and the other
hardware stopping. The external high-speed oscillator or internal low-speed oscillator is operating. To set CPUM1 = 1
and CPUM0 = 0, the system gets into green mode. To set TC0GN = 1 (bit 1 of T0M) will enable TC0 green mode
wakeup function. The system can be waked up to last system mode by TC0 timer timeout and P0 trigger signal.
The green mode provides a time-variable wakeup function. Users can decide wakeup time by setting TC0 timer. There
are two channels into green mode. One is normal mode and the other is slow mode. In normal mode, the TC0 timer
overflow time is very short. In slow mode, the overflow time is longer. Users can select appropriate situation for their
applications. Under green mode, the power consumption is 5u amp in 3V condition.
POWER DOWN MODE
The power down mode is also called sleep mode. The chip stops working as sleeping status. The power consumption
is very less almost to zero. The power down mode is usually applied to low power consuming system as battery power
productions. To set CUPM0 = 1, the system gets into power down mode. The external high-speed and low-speed
oscillators are turned off. The system can be waked up by P0, P1 trigger signal.
SONiX TECHNOLOGY CO., LTD Page 48 Revision 0.5
Page 49
Preliminary SN8P1702A/SN8P1703A
SYSTEM MODE CONTROL
SYSTEM MODE BLOCK DIAGRAM
P0, P1 wake-up function active.
P0, P1 wake-up function active.
External reset circuit active.
External reset circuit active.
Normal Mode
Normal Mode
P0, P1 wake-up function active.
P0, P1 wake-up function active.
TC0 time out.
TC0 time out.
External reset circuit active.
External reset circuit active.
Power Down Mode
Power Down Mode
(Sleep Mode)
(Sleep Mode)
CPUM1, CPUM0 = 01
CPUM1, CPUM0 = 01
CLKMD = 1
CLKMD = 1
CLKMD = 0
CLKMD = 0
CPUM1, CPUM0 = 10
CPUM1, CPUM0 = 10
Green Mode
Green Mode
8-bit micro-controller build-in 12-bit ADC
Slow Mode
Slow Mode
P0, P1 wake-up function active.
P0, P1 wake-up function active.
TC0 time out.
TC0 time out.
External reset circuit active.
External reset circuit active.
Figure 7-6. System Mode Block Diagram
Operating mode description
MODE NORMAL SLOW GREEN
POWER DOWN
(SLEEP)
REMARK
HX osc. Running By STPHX By STPHX Stop
LX osc. Running Running Running Stop
CPU instruction Executing Executing Stop Stop
TC0 timer *Active *Active *Active Inactive
* Active by
program
Watchdog timer Active Active By INT_16K_RCBy INT_16K_RC
Internal
interrupt
External
interrupt
Wakeup source - -
All active All active TC0 All inactive
All active All active All active All inactive
P0, P1, TC0
Reset
P0, P1, Reset
Table 7-1. Operating Mode Description
SONiX TECHNOLOGY CO., LTD Page 49 Revision 0.5
Page 50
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
SYSTEM MODE SWITCHING
Switch normal/slow mode to power down (sleep) mode.
CPUM0 = 1
B0BSET FCPUM0 ; Set CPUM0 = 1.
During the sleep, only the wakeup pin and reset can wakeup the system back to the normal mode.
Switch normal mode to slow mode.
B0BSET FCLKMD ;To set CLKMD = 1, Change the system into slow mode
B0BSET FSTPHX ;To stop external high-speed oscillator for power saving.
Note: To stop high-speed oscillator is not necessary and user can omit it.
Switch slow mode to normal mode (The external high-speed oscillator is still running)
B0BCLR FCLKMD ;To set CLKMD = 0
Switch slow mode to normal mode (The external high-speed oscillator stops)
If external high clock stop and program want to switch back normal mode. It is necessary to delay at least 10mS for
external clock stable.
B0BCLR FSTPHX ; Turn on the external high-speed oscillator.
B0MOV Z, #27 ; If VDD = 5V, internal RC=32KHz (typical) will delay
@@: DECMS Z ; 0.125ms X 81 = 10.125ms for external clock stable
JMP @B
;
B0BCLR FCLKMD ; Change the system back to the normal mode
Example: Go into Green mode and enable TC0 wakeup function.
; Set TC0 timer wakeup function.
B0BCLR FTC0IEN ; To disable TC0 interrupt service
B0BCLR FTC0ENB ; To disable TC0 timer
MOV A,#20H ;
B0MOV TC0M,A ; To set TC0 clock = Fcpu / 64
MOV A,#74H
B0MOV TC0C,A ; To set TC0C initial value = 74H (To set TC0 interval = 10
B0BCLR FTC0IEN ; To disable TC0 interrupt service
B0BCLR FTC0IRQ ; To clear TC0 interrupt request
B0BSET FTC0ENB ; To enable TC0 timer
B0BSET FTC0GN ; To enable TC0 wakeup function
; Go into green mode
B0BCLR FCPUM0 ;To set CPUMx = 10
B0BSET FCPUM1
Note: If TC0ENB = 0 or TC0GN = 0, TC0 will not wakeup from green mode to normal/slow mode function.
ms)
SONiX TECHNOLOGY CO., LTD Page 50 Revision 0.5
Page 51
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
WAKEUP TIME
OVERVIEW
The external high-speed oscillator needs a delay time from stopping to operating. The delay is very necessary and
makes the oscillator to work stably. Some conditions during system operating, the external high-speed oscillator often
runs and stops. Under these conditions, the delay time for external high-speed oscillator restart is called wakeup time.
There are two conditions need wakeup time. One is power down mode to normal mode. The other one is slow mode to
normal mode. For the first case, SN8P1702A/SN8P1703A provides 2048 oscillator clocks to be the wakeup time. But in
the last case, users need to make the wakeup time by themselves.
HARDWARE WAKEUP
When the system is in power down mode (sleep mode), the external high-speed oscillator stops. When waked up from
power down mode, MCU waits for 2048 external high-speed oscillator clocks as the wakeup time to stable the oscillator
circuit. After the wakeup time, the system goes into the normal mode. The value of the wakeup time is as the followi ng.
The Wakeup time = 1/Fosc * 2048 (sec) + X’tal settling time
The x’tal settling time is depended on the x’tal type. Typically, it is about 2~4mS.
Example: In power down mode (sleep mode), the system is waked up by P0 or P1 trigger signal. After the
wakeup time, the system goes into normal mode. The wakeup time of P0, P1 wakeup function is
as the following.
The wakeup time = 1/Fosc * 2048 = 0.57 ms (Fosc = 3.58MHz)
The total wakeup time = 0.57ms + x’tal settling time
Under power down mode (sleep mode), there are only I/O ports with wakeup function wake the system up to normal
mode. The Port 0 and Port 1 have wakeup function. Port 0 wakeup function always enables, but the Port 1 is controlled
by the P1W register.
P1W initial value = xxxx xx00
0C0H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
P1W
- - - - - - W W
Bit[1:0] P11W,P10W:Port 1 wakeup function control bits.
0 = Disable each pin of Port1 wakeup function,
1 = Enable each pin of Port 1 wakeup function
0 0 0 0 0 0 P11W P10W
SONiX TECHNOLOGY CO., LTD Page 51 Revision 0.5
Page 52
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
EXTERNAL WAKEUP TRIGGER CONTROL
In the SN8P1702A/SN8P1703A, the wakeup trigger direction is control by PEDGE register.
PEDGE initial value = 0xx0 0xxx
0BFH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
PEDGE
R/W - - R/W R/W - - -
Bit7 PEDGEN: Interrupt and wakeup trigger edge control bit.
Bit[4:3] P00G[1:0]: Port 0.0 edge select bits.
PEDGEN - - P00G1 P00G0 - - -
0 = Disable edge trigger function.
Port 0: Low-level wakeup trigger and falling edge interrupt trigger.
Port 1: Low-level wakeup trigger.
1 = Enable edge trigger function.
P0.0: Wakeup and interrupt trigger is controlled by P00G1 and P00G0 bits.
Port 1: Level change (falling or rising edge) wakeup trigger.
The watchdog timer (WDT) is a binary up counter designed for monitoring program execution. If the program gets in
the unknown status by noise interference, The WDT’s overflow signal will reset this chip and restart operation. The
instruction that clear the watch-dog timer (B0BSET FWDRST) should be executed at proper points in a program
within a given period. If an instruction that clears the watchdog timer is not executed within the period and the
watchdog timer overflows, reset signal is generated and system is restarted with reset status. In order to generate
different output timings, the user can control watchdog timer by modifying the Wdrate control bits of OSCM register.
The watchdog timer will be disabled at green and power down modes.
OSCM initial value = 0000 000x
0CAH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
OSCM
R/W R/W R/W R/W R/W R/W R/W -
Bit1 STPHX: External high-speed oscillator control bit.
Bit2 CLKMD: System high/Low speed mode select bit.
Bit[4:3] CPUM[1:0]: CPU operating mode control bit.
Bit5 Wdrate: Watchdog timer rate select bit.
Bit6 WDRST: Watchdog timer reset bit.
Bit7 WTCKS: Watchdog clock source select bit.
WTCKS WDRST Wdrate CPUM1 CPUM0 CLKMD STPHX -
0 = free run,
1 = stop.
Note: This bit only controls external high-speed oscillator. If STPHX=1, the internal low-speed RC
oscillator is still running.
The timer counter 0 (TC0) is us e d to generate an interrupt request when a specified time interval has elapsed. TC0 has
a auto re-loadable counter that consists of two parts: an 8-bit reload register (TC0R) into which you write the counter
reference value, and an 8-bit counter register (TC0C) whose value is automatically incremented by counter logic.
TC0out
TC0out
PWM0OUT
PWM0OUT
TC0 Time out
TC0 Time out
Fcpu
Fcpu
INT0
INT0
(schmitter trigger)
(schmitter trigger)
(8-TC0Rate)
(8-TC0Rate)
÷2
÷2
TC0CKS
TC0CKS
TC0enb
TC0enb
CPUM0
CPUM0
TC0R reload
TC0 R reload
data buffer
data buffer
load
load
TC0C
TC0C
8-bit binary counter
8-bit bi nary count er
Internal P5.4 I/O circuit
Aload0
Aload0
Compare
Compare
Internal P5.4 I/O circuit
Buzzer
Aut o. reloadP5.4
Aut o. reloadP5.4
Buzzer
÷2
÷2
R
R
S
S
PWM
PWM
Figure 8-1. TC0 Block Diagram
The main purposes of the TC0 timer counter is as following.
8-bit programmable timer: Generates interrupts at specific time intervals based on the selected clock frequency.
Arbitrary frequency output (Buzzer output): Outputs selectable clock frequencies to the BZ0 pin (P5.4).
PWM function: PWM output can be generated by the PWM1OUT bit and output to PWM0OUT pin (P5.4).
SONiX TECHNOLOGY CO., LTD Page 55 Revision 0.5
Page 56
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
TC0M MODE REGISTER
The TC0M is the timer counter mode register, which is an 8-bit read/write register. By loading different value into the
TC0M register, users can modify the timer counter clock frequency dynamically when program executin g.
Eight rates for TC0 timer can be selected by TC0RATE0 ~ TC0RATE2 and TC0X8 bits of T0M register. If TC0X8=1 the
TC0 will faster 8 times than TC0X8=0 (Initial value). The bit7 of TC0M named TC0ENB is the control bit to start TC0
timer.
TC0M initial value = 0000 0000
0DAH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
TC0M
R/W R/W R/W R/W R/W R/W R/W R/W
Bit7 TC0ENB: TC0 counter/BZ0/PWM0OUT enable bit.
Bit [6:4] TC0RATE[2:0]: TC0 clock source selection bits. TC0X8 is bit 2 of T0M register.
0 = Fcpu,
1 = External clock comes from INT0/P0.0 pin.
Bit2 ALOAD0: TC0 auto-reload function control bit.
0 = none auto-reload,
1 = auto-reload.
Bit1 TC0OUT: TC0 time-out toggle signal output control bit.
0 = to disable TC0 signal output and to enable P5.4’s I/O function,
1 = to enable TC0’s signal output and to disable P5.4’s I/O function. (Auto-disable the PWM0OUT function.)
Bit0 PWM0OUT: TC0’s PWM output control bit.
0 = to disable the PWM output,
1 = to enable the PWM output (The TC0OUT control bit must = 0 )
Note: When TC0CKS=1, TC0 became an external event counter. No more P0.0 interrupt request will be
raised. (P0.0IRQ will be always 0)
SONiX TECHNOLOGY CO., LTD Page 56 Revision 0.5
Page 57
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
TC0C COUNTING REGISTER
TC0C is an 8-bit counter register for the timer counter (TC0). TC0C must be reset whenever the TC0ENB is set “1” to
start the timer counter. TC0C is incremented by one with a clock pulse which the frequency is determined by
TC0RATE0 ~ TC0RATE2. When TC0C has incremented to “0FFH”, it is will be cleared to “00H” in next clock and an
overflow is generated. Under TC0 interrupt service request (TC0IEN) enable condition, the TC0 interrupt request flag
will be set “1” and the system executes the interrupt service routine.
TC0C initial value = xxxx xxxx
0DBH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
TC0C
R/W R/W R/W R/W R/W R/W R/W R/W
TC0C7 TC0C6 TC0C5 TC0C4 TC0C3 TC0C2 TC0C1 TC0C0
TC0 Overflow Time
TC0 rate is determinate by TC0Rate and Code Option TC0_Counter, TC0Rate can set TC0 clock frequency and
TC0_Counter set TC0 became 8-bit, 6-bit, 5-bit or 4-bit counter.
The equation of TC0C initial value is as following.
TC0C initial value = N
Which N is determinate by code option: TC0_Counter
TC0_Counter N Max. TC0C value
8-bit 256 255
6-bit 64 63
5-bit 32 31
4-bit 16 15
Note: TheTC0C must small or equal than Max. TC0 value.
Example: To set 10ms interval time for TC0 interrupt at Fosc = 3.58MHz
000 Fcpu/256 73.2 ms 286us 8000 ms 31.25 ms
001 Fcpu/128 36.6 ms 143us 4000 ms 15.63 ms
010 Fcpu/64 18.3 ms 71.5us 2000 ms 7.8 ms
011 Fcpu/32 9.15 ms 35.8us 1000 ms 3.9 ms
100 Fcpu/16 4.57 ms 17.9us 500 ms 1.95 ms
101 Fcpu/8 2.28 ms 8.94us 250 ms 0.98 ms
110 Fcpu/4 1.14 ms 4.47us 125 ms 0.49 ms
111 Fcpu/2 0.57 ms 2.23us 62.5 ms 0.24 ms
TC0_Counter=6-bit , TC0X8=0
TC0RATE TC0CLOCK
000 Fcpu/256 18.3 ms 286us 2000 ms 31.25 ms
001 Fcpu/128 9.15 ms 143us 1000 ms 15.63 ms
010 Fcpu/64 4.57 ms 71.5us 500 ms 7.8 ms
011 Fcpu/32 2.28 ms 35.8us 250 ms 3.9 ms
100 Fcpu/16 1.14 ms 17.9us 125 ms 1.95 ms
101 Fcpu/8 0.57 ms 8.94us 62.5 ms 0.98 ms
110 Fcpu/4 0.285 ms 4.47us 31.25 ms 0.49 ms
111 Fcpu/2 0.143 ms 2.23us 15.63 ms 0.24 ms
TC0_Counter=5-bit, TC0X8=0
TC0RATE TC0CLOCK
000 Fcpu/256 9.15 ms 286us 1000 ms 31.25 ms
001 Fcpu/128 4.57 ms 143us 500 ms 15.63 ms
010 Fcpu/64 2.28 ms 71.5us 250 ms 7.8 ms
011 Fcpu/32 1.14 ms 35.8us 125 ms 3.9 ms
100 Fcpu/16 0.57 ms 17.9us 62.5 ms 1.95 ms
101 Fcpu/8 0.285 ms 8.94us 31.25 ms 0.98 ms
110 Fcpu/4 0.143 ms 4.47us 15.63 ms 0.49 ms
111 Fcpu/2 71.25 us 2.23us 7.81 ms 0.24 ms
TC0_Counter=4-bit, TC0X8=0
TC0RATE TC0CLOCK
000 Fcpu/256 4.57 ms 286us 500 ms 31.25 ms
001 Fcpu/128 2.28 ms 143us 250 ms 15.63 ms
010 Fcpu/64 1.14 ms 71.5us 125 ms 7.8 ms
011 Fcpu/32 0.57 ms 35.8us 62.5 ms 3.9 ms
100 Fcpu/16 0.285 ms 17.9us 31.25 ms 1.95 ms
101 Fcpu/8 0.143 ms 8.94us 15.63 ms 0.98 ms
110 Fcpu/4 71.25 us 4.47us 7.81 ms 0.49 ms
111 Fcpu/2 35.63 us 2.23us 3.91 ms 0.24 ms
Max overflow intervalOne step = max/16Max overflow interval One step = max/16
SONiX TECHNOLOGY CO., LTD Page 58 Revision 0.5
Page 59
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
TC0_Counter=8-bit, TC0X8=1
TC0RATE TC0CLOCK
000 Fosc/128 9.153 ms 35.754us 1000 ms 3.91 ms
001 Fosc/64 4.58 ms 17.877us 500 ms 1.95 ms
010 Fosc/32 2.29 ms 8.939us 250 ms 0.977 ms
011 Fosc/16 1.14 ms 4.470us 125 ms 0.488 ms
100 Fosc/8 0.57 ms 2.235us 62.5 ms 0.244 ms
101 Fosc/4 0.29 ms 1.117us 31.25 ms 0.122 ms
110 Fosc/2 0.14 ms 0.587us 15.63 ms 0.061 ms
111 Fosc 71.5 us 0.279us 7.81ms 0.03 ms
TC0_Counter=6-bit , TC0X8=1
TC0RATE TC0CLOCK
000 Fosc/128 2.29 ms 35.754us 250 ms 3.91 ms
001 Fosc/64 1.14 ms 17.877us 125 ms 1.95 ms
010 Fosc/32 0.57 ms 8.939us 62.5 ms 0.977 ms
011 Fosc/16 0.29 ms 4.470us 31.25 ms 0.488 ms
100 Fosc/8 0.14 ms 2.235us 15.63 ms 0.244 ms
101 Fosc/4 71.5 us 1.117us 7.81ms 0.122 ms
110 Fosc/2 35.75 us 0.587us 3.905 ms 0.061 ms
111 Fosc 17.875 us 0.279us 1.953 ms 0.03 ms
TC0_Counter=5-bit, TC0X8=1
TC0RATE TC0CLOCK
000 Fosc/128 1.14 ms 35.754us 125 ms 3.91 ms
001 Fosc/64 0.57 ms 17.877us 62.5 ms 1.95 ms
010 Fosc/32 0.29 ms 8.939us 31.25 ms 0.977 ms
011 Fosc/16 0.14 ms 4.470us 15.63 ms 0.488 ms
100 Fosc/8 71.5 us 2.235us 7.81ms 0.244 ms
101 Fosc/4 35.75 us 1.117us 3.905 ms 0.122 ms
110 Fosc/2 17.875 us 0.587us 1.953 ms 0.061 ms
111 Fosc 8.936 us 0.279us 0.976 ms 0.03 ms
TC0_Counter=4-bit, TC0X8=1
TC0RATE TC0CLOCK
000 Fosc/128 0.57 ms 35.754us 62.5 ms 3.91 ms
001 Fosc/64 0.29 ms 17.877us 31.25 ms 1.95 ms
010 Fosc/32 0.14 ms 8.939us 15.63 ms 0.977 ms
011 Fosc/16 71.5 us 4.470us 7.81ms 0.488 ms
100 Fosc/8 35.75 us 2.235us 3.905 ms 0.244 ms
101 Fosc/4 17.875 us 1.117us 1.953 ms 0.122 ms
110 Fosc/2 8.936 us 0.587us 0.976 ms 0.061 ms
111 Fosc 4.468 us 0.279us 0.488 ms 0.03 ms
Max overflow intervalOne step = max/16Max overflow interval One step = max/16
Table 8-2. The Timing Table of Timer Counter TC0
SONiX TECHNOLOGY CO., LTD Page 59 Revision 0.5
Page 60
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
TC0R AUTO-LOAD REGISTER
TC0R is an 8-bit register for the TC0 auto-reload function. TC0R’s value applies to TC0OUT and PWM0OUT functions.
Under TC0OUT application, users must enable and set the TC0R register. The main purpose of TC0R is as following.
Store the auto-reload value and set into TC0C when the TC0C overflow. (ALOAD0 = 1).
Store the duty value of PWM0OUT function.
TC0R initial value = xxxx xxxx
0CDH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
TC0R
W W W W W W W W
The equation of TC0R initial value is like TC0C as following.
Which N is determinate by code option: TC0_Counter
TC0_Counter N Max. TC0R value
8-bit 256 255
6-bit 64 63
5-bit 32 31
4-bit 16 15
Note: TheTC0R must small or equal than Max. TC0R value.
Note: The TC0R is write-only register can’t be process by INCMS, DECMS instructions.
TC0R7 TC0R6 TC0R5 TC0R4 TC0R3 TC0R2 TC0R1 TC0R0
TC0R initial value = N - (TC0 interrupt interval time * input clock)
SONiX TECHNOLOGY CO., LTD Page 60 Revision 0.5
Page 61
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
TC0 TIMER COUNTER OPERATION SEQUENCE
The TC0 timer counter’s sequence of operation can be following.
Set the TC0C initial value to setup the interval time.
Set the TC0ENB to be “1” to enable TC0 timer counter.
TC0C is incremented by one with each clock pulse which frequency is corresponding to TC0M selection.
TC0C overflow when TC0C from FFH to 00H.
When TC0C overflow occur, the TC0IRQ flag is set to be “1” by hardware.
Execute the interrupt service routine.
Users reset the TC0C value and resume the TC0 timer operation.
Example: Setup the TC0M and TC0C without auto-reload function. (TC0_Counter=8-bit)
B0BCLR FTC0X8 ;
B0BCLR FTC0IEN ; To disable TC0 interrupt service
B0BCLR FTC0ENB ; To disable TC0 timer
MOV A,#20H ;
B0MOV TC0M,A ; To set TC0 clock = Fcpu / 64
MOV A,#74H ; To set TC0C initial value = 74H
B0MOV TC0C,A ;(To set TC0 interval = 10 ms)
B0BSET FTC0IEN ; To enable TC0 interrupt service
B0BCLR FTC0IRQ ; To clear TC0 interrupt request
B0BSET FTC0ENB ; To enable TC0 timer
Example: Setup the TC0M and TC0C with auto-reload function. (TC0_Counter=8 -bit)
B0BCLR FTC0X8 ; To select TC0=Fcpu/2 as clock source
B0BCLR FTC0IEN ; To disable TC0 interrupt service
B0BCLR FTC0ENB ; To disable TC0 timer
MOV A,#20H ;
B0MOV TC0M,A ; To set TC0 clock = Fcpu / 64
MOV A,#74H ; To set TC0C initial value = 74H
B0MOV TC0C,A ; (To set TC0 interval = 10 ms)
B0MOV TC0R,A ; To set TC0R auto-reload register
B0BSET FTC0IEN ; To enable TC0 interrupt service
B0BCLR FTC0IRQ ; To clear TC0 interrupt request
B0BSET FTC0ENB ; To enable TC0 timer
B0BSET ALOAD0 ; To enable TC0 auto-reload function.
SONiX TECHNOLOGY CO., LTD Page 61 Revision 0.5
Page 62
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
Example: TC0 interrupt service routine without auto-reload function. (TC0_Counter=8-bit)
B0BCLR FTC0IRQ ; Reset TC0IRQ
. . ; TC0 interrupt service routine
. . JMP EXIT_INT ; End of TC0 interrupt service routine and exit interrupt
vector
. .
. .
EXIT_INT:
B0MOV A, PFLAGBUF
B0MOV PFLAG, A
B0XCH A, ACCBUF ; Restore ACC value.
RETI ; Exit interrupt vector
SONiX TECHNOLOGY CO., LTD Page 62 Revision 0.5
Page 63
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
TC0 CLOCK FREQUENCY OUTPUT (BUZZER)
TC0 timer counter provides a frequency output function. By setting the TC0 clock frequency, the clock signal is output
to P5.4 and the P5.4 general purpose I/O function is auto-disable. The TC0 output signal divides by 2. The TC0 clock
has many combinations and easily to make difference frequency. This function applies as buzzer output to output
multi-frequency.
Figure 8-2. The TC0OUT Pulse Frequency
Example: Setup TC0OUT output from TC0 to TC0OUT (P5.4). The external high-speed clock is 4MHz. The
TC0OUT frequency is 1KHz. Because the TC0OUT signal is divided by 2, set the TC0 clock to
2KHz. The TC0 clock source is from external oscillator clock. TC0 rate is Fcpu/4. The
TC0RATE2~TC0RATE1 = 110, TC0C = TC0R = 131, TC0X8 = 0, TC0_Counter=8-bit
B0BCLR FTC0X8 ; Set TC0X8 to 0
MOV A,#01100000B
B0MOV TC0M,A ; Set the TC0 rate to Fcpu/4
MOV A,#131 ; Set the auto-reload reference value
B0MOV TC0C,A
B0MOV TC0R,A
B0BSET FTC0OUT ; Enable TC0 output to P5.4 and disable P5.4 I/O function
B0BSET FALOAD0 ; Enable TC0 auto-reload function
B0BSET FTC0ENB ; Enable TC0 timer
Table 8-4TC0OUT Frequency Table for Fosc = 16MHz, TC0 Rate = Fcpu/8
SONiX TECHNOLOGY CO., LTD Page 65 Revision 0.5
Page 66
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
TIMER COUNTER 1 (TC1)
OVERVIEW
The timer counter 1 (TC1) is us e d to generate an interrupt request when a specified time interval has elapsed. TC1 has
a auto re-loadable counter that consists of two parts: an 8-bit reload register (TC1R) into which you write the counter
TC1out
TC1out
PWM1OUT
PWM1OUT
TC1enb
TC1enb
TC1R reload
TC1R reload
data buffer
da ta b u ffer
load
load
Inte rn a l P 5 .3 I/O c ircu it
Aload1
Aload1
Inte rn a l P 5 .3 I/O c ircu it
Buzzer
Auto. reloadP5.3
Auto. reloadP5.3
Compare
Com pare
Buzzer
÷2
÷2
R
R
S
S
PWM
PWM
fcpu
fcpu
÷2
÷2
(8-TC1Rate)
(8-TC1Rate)
CPUM0
CPUM0
TC1C
TC1C
8-bit binary counter
8-bit binary counter
TC1 Time out
TC1 Time out
reference value, and an 8-bit counter register (TC1C) whose value is automatically incremented by counter logic.
Figure 8-3. Timer Counter TC1 Block Diagram
The main purposes of the TC1 timer is as following.
8-bit programmable timer: Generates interrupts at specific time intervals based on the selected clock frequency.
Arbitrary frequency output (Buzzer output): Outputs selectable clock frequencies to the BZ1 pin (P5.3).
PWM function: PWM output can be generated by the PWM1OUT bit and output to PWM1OUT pin (P5.3).
SONiX TECHNOLOGY CO., LTD Page 66 Revision 0.5
Page 67
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
TC1M MODE REGISTER
The TC1M is the timer mode register, which is an 8-bit read/write register. By loading different value into the TC1M
register, users can modify the timer counter clock frequency dynamically when program executing.
Eight rates for TC1 timer can be selected by TC1RATE0 ~ TC1RATE2 and TC1X8 bits of T0M register. If TC1X8=1 the
TC1 will faster 8 times than TC1X8=0 (Initial value). The bit7 of TC1M named TC1ENB is the control bit to start TC1
timer.
TC1M initial value = 0000 0000
0DCH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
TC1M
R/W R/W R/W R/W - R/W R/W R/W
Bit7 TC1ENB: TC1 counter/BZ1/PWM1OUT enable bit.
Bit[6:4] TC1RATE[2:0]: TC1 clock source selection bits. TC1X8 is bit 3 of T0M register.
Note: Fcpu = Fosc / 4
Bit2 ALOAD1: TC1 auto-reload function control bit.
Bit1 TC01UT: TC1 time-out toggle signal output control bit.
Bit0 PWM1OUT: TC1’s PWM output control bit.
Note: TC1 doesn’t support event counter mode because SN8P1702A and SN8P1703A hasn’t P0.1 for TC1
0 = to disable TC1 signal output and to enable P5.3’s I/O function,
1 = to enable TC1’s signal output and to disable P5.3’s I/O function. (Auto-disable the PWM0OUT function.)
0 = to disable the PWM output,
1 = to enable the PWM output (The TC1OUT control bit must = 0)
TC1 Clock Source
TC1X8 = 0 TC1X8 = 1
SONiX TECHNOLOGY CO., LTD Page 67 Revision 0.5
Page 68
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
TC1C COUNTING REGISTER
TC1C is an 8-bit counter register for the timer counter (TC1). TC1C must be reset whenever the TC1ENB is set “1” to
start the timer. TC0C is incremented by one with a clock pulse which the frequency is determined by TC0RATE0 ~
TC0RATE2. When TC0C has incremented to “0FFH”, it is will be cleared to “00H” in next clock and an overflow is
generated. Under TC1 interrupt service request (TC1IEN) enable condition, the TC1 interrupt request flag will be set
“1” and the system executes the interrupt service routine.
TC1C initial value = xxxx xxxx
0DDH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
TC1C
R/W R/W R/W R/W R/W R/W R/W R/W
TC1C7 TC1C6 TC1C5 TC1C4 TC1C3 TC1C2 TC1C1 TC1C0
TC1 Overflow Time
TC1 rate is determinate by TC1Rate and Code Option TC1_Counter, TC1Rate can set TC1 clock frequency from Fcpu
and TC1_Counter set TC1 became 8-bit, 6-bit, 5-bit or 4-bit counter.
The equation of TC1C initial value is as following.
TC1C initial value = N
Which N is determinate by code option: TC1_Counter
TC1_Counter N Max. TC1C value
8-bit 256 255
6-bit 64 63
5-bit 32 31
4-bit 16 15
Note: TheTC1C must small or equal than Max. TC1 value.
Example: To set 10ms interval time for TC1 interrupt at Fosc = 3.58MHz
000 Fcpu/256 73.2 ms 286us 8000 ms 31.25 ms
001 Fcpu/128 36.6 ms 143us 4000 ms 15.63 ms
010 Fcpu/64 18.3 ms 71.5us 2000 ms 7.8 ms
011 Fcpu/32 9.15 ms 35.8us 1000 ms 3.9 ms
100 Fcpu/16 4.57 ms 17.9us 500 ms 1.95 ms
101 Fcpu/8 2.28 ms 8.94us 250 ms 0.98 ms
110 Fcpu/4 1.14 ms 4.47us 125 ms 0.49 ms
111 Fcpu/2 0.57 ms 2.23us 62.5 ms 0.24 ms
TC1_Counter=6-bit , TC1X8=0
TC1RATE TC1CLOCK
000 Fcpu/256 18.3 ms 286us 2000 ms 31.25 ms
001 Fcpu/128 9.15 ms 143us 1000 ms 15.63 ms
010 Fcpu/64 4.57 ms 71.5us 500 ms 7.8 ms
011 Fcpu/32 2.28 ms 35.8us 250 ms 3.9 ms
100 Fcpu/16 1.14 ms 17.9us 125 ms 1.95 ms
101 Fcpu/8 0.57 ms 8.94us 62.5 ms 0.98 ms
110 Fcpu/4 0.285 ms 4.47us 31.25 ms 0.49 ms
111 Fcpu/2 0.143 ms 2.23us 15.63 ms 0.24 ms
TC1_Counter=5-bit, TC1X8=0
TC1RATE TC1CLOCK
000 Fcpu/256 9.15 ms 286us 1000 ms 31.25 ms
001 Fcpu/128 4.57 ms 143us 500 ms 15.63 ms
010 Fcpu/64 2.28 ms 71.5us 250 ms 7.8 ms
011 Fcpu/32 1.14 ms 35.8us 125 ms 3.9 ms
100 Fcpu/16 0.57 ms 17.9us 62.5 ms 1.95 ms
101 Fcpu/8 0.285 ms 8.94us 31.25 ms 0.98 ms
110 Fcpu/4 0.143 ms 4.47us 15.63 ms 0.49 ms
111 Fcpu/2 71.25 us 2.23us 7.81 ms 0.24 ms
TC1_Counter=4-bit, TC1X8=0
TC1RATE TC1CLOCK
000 Fcpu/256 4.57 ms 286us 500 ms 31.25 ms
001 Fcpu/128 2.28 ms 143us 250 ms 15.63 ms
010 Fcpu/64 1.14 ms 71.5us 125 ms 7.8 ms
011 Fcpu/32 0.57 ms 35.8us 62.5 ms 3.9 ms
100 Fcpu/16 0.285 ms 17.9us 31.25 ms 1.95 ms
101 Fcpu/8 0.143 ms 8.94us 15.63 ms 0.98 ms
110 Fcpu/4 71.25 us 4.47us 7.81 ms 0.49 ms
111 Fcpu/2 35.63 us 2.23us 3.91 ms 0.24 ms
Max overflow intervalOne step = max/16Max overflow interval One step = max/16
SONiX TECHNOLOGY CO., LTD Page 69 Revision 0.5
Page 70
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
TC1_Counter=8-bit, TC1X8=1
TC1RATE TC1CLOCK
000 Fosc/128 9.153 ms 35.754us 1000 ms 3.91 ms
001 Fosc/64 4.58 ms 17.877us 500 ms 1.95 ms
010 Fosc/32 2.29 ms 8.939us 250 ms 0.977 ms
011 Fosc/16 1.14 ms 4.470us 125 ms 0.488 ms
100 Fosc/8 0.57 ms 2.235us 62.5 ms 0.244 ms
101 Fosc/4 0.29 ms 1.117us 31.25 ms 0.122 ms
110 Fosc/2 0.14 ms 0.587us 15.63 ms 0.061 ms
111 Fosc 71.5 us 0.279us 7.81ms 0.03 ms
TC1_Counter=6-bit , TC1X8=1
TC1RATE TC1CLOCK
000 Fosc/128 2.29 ms 35.754us 250 ms 3.91 ms
001 Fosc/64 1.14 ms 17.877us 125 ms 1.95 ms
010 Fosc/32 0.57 ms 8.939us 62.5 ms 0.977 ms
011 Fosc/16 0.29 ms 4.470us 31.25 ms 0.488 ms
100 Fosc/8 0.14 ms 2.235us 15.63 ms 0.244 ms
101 Fosc/4 71.5 us 1.117us 7.81ms 0.122 ms
110 Fosc/2 35.75 us 0.587us 3.905 ms 0.061 ms
111 Fosc 17.875 us 0.279us 1.953 ms 0.03 ms
TC1_Counter=5-bit, TC1X8=1
TC1RATE TC1CLOCK
000 Fosc/128 1.14 ms 35.754us 125 ms 3.91 ms
001 Fosc/64 0.57 ms 17.877us 62.5 ms 1.95 ms
010 Fosc/32 0.29 ms 8.939us 31.25 ms 0.977 ms
011 Fosc/16 0.14 ms 4.470us 15.63 ms 0.488 ms
100 Fosc/8 71.5 us 2.235us 7.81ms 0.244 ms
101 Fosc/4 35.75 us 1.117us 3.905 ms 0.122 ms
110 Fosc/2 17.875 us 0.587us 1.953 ms 0.061 ms
111 Fosc 8.936 us 0.279us 0.976 ms 0.03 ms
TC1_Counter=4-bit, TC1X8=1
TC1RATE TC1CLOCK
000 Fosc/128 0.57 ms 35.754us 62.5 ms 3.91 ms
001 Fosc/64 0.29 ms 17.877us 31.25 ms 1.95 ms
010 Fosc/32 0.14 ms 8.939us 15.63 ms 0.977 ms
011 Fosc/16 71.5 us 4.470us 7.81ms 0.488 ms
100 Fosc/8 35.75 us 2.235us 3.905 ms 0.244 ms
101 Fosc/4 17.875 us 1.117us 1.953 ms 0.122 ms
110 Fosc/2 8.936 us 0.587us 0.976 ms 0.061 ms
111 Fosc 4.468 us 0.279us 0.488 ms 0.03 ms
Max overflow intervalOne step = max/16Max overflow interval One step = max/16
Table 8-5. The Timing Table of Timer Counter TC1
SONiX TECHNOLOGY CO., LTD Page 70 Revision 0.5
Page 71
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
TC1R AUTO-LOAD REGISTER
TC1R is an 8-bit register for the TC1 auto-reload function. TC1R’s value applies to TC1OUT and PWM1OUT functions.
Under TC1OUT application, users must enable and set the TC1R register. The main purpose of TC1R is as following.
Store the auto-reload value and set into TC1C when the TC1C overflow. (ALOAD1 = 1).
Store the duty value of PWM1OUT function.
TC1R initial value = xxxx xxxx
0DEH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
TC1R
W W W W W W W W
The equation of TC1R initial value is like TC1C as following.
Which N is determinate by code option: TC1_Counter
TC1_Counter N Max. TC1R value
8-bit 256 255
6-bit 64 63
5-bit 32 31
4-bit 16 15
Note: TheTC1R must small or equal than Max. TC1R value.
Note: The TC1R is write-only register can’t be process by INCMS, DECMS instructions.
TC1R7 TC1R6 TC1R5 TC1R4 TC1R3 TC1R2 TC1R1 TC1R0
TC1R initial value = N - (TC1 interrupt interval time * input clock)
SONiX TECHNOLOGY CO., LTD Page 71 Revision 0.5
Page 72
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
TC1 TIMER COUNTER OPERATION SEQUENCE
The TC1 timer’s sequence of operation can be following.
Set the TC1C initial value to setup the interval time.
Set the TC1ENB to be “1” to enable TC1 timer counter.
TC1C is incremented by one with each clock pulse which frequency is corresponding to TC1M selection.
TC1C overflow if TC1C from FFH to 00H.
When TC1C overflow occur, the TC1IRQ flag is set to be “1” by hardware.
Execute the interrupt service routine.
Users reset the TC1C value and resume the TC1 timer operation.
Example: Setup the TC1M and TC1C without auto-reload function.(TC1_Counter=8-bit, TC1X8 =0)
B0BCLR FTC1X8 ;
B0BCLR FTC1IEN ; To disable TC1 interrupt service
B0BCLR FTC1ENB ; To disable TC1 timer
MOV A,#20H ;
B0MOV TC1M,A ; To set TC1 clock = Fcpu / 64
MOV A,#74H ; To set TC1C initial value = 74H
B0MOV TC1C,A ;(To set TC1 interval = 10 ms)
B0BSET FTC1IEN ; To enable TC1 interrupt service
B0BCLR FTC1IRQ ; To clear TC1 interrupt request
B0BSET FTC1ENB ; To enable TC1 timer
Example: Setup the TC1M and TC1C with auto-reload function. (TC1_Counter=8-bit, TC1X8=0)
B0BCLR FTC1X8 ; To select TC1=Fcpu/2 as clock source
B0BCLR FTC1IEN ; To disable TC1 interrupt service
B0BCLR FTC1ENB ; To disable TC1 timer
MOV A,#20H ;
B0MOV TC1M,A ; To set TC1 clock = Fcpu / 64
MOV A,#74H ; To set TC1C initial value = 74H
B0MOV TC1C,A ; (To set TC1 interval = 10 ms)
B0MOV TC1R,A ; To set TC1R auto-reload register
B0BSET FTC1IEN ; To enable TC1 interrupt service
B0BCLR FTC1IRQ ; To clear TC1 interrupt request
B0BSET FTC1ENB ; To enable TC1 timer
B0BSET ALOAD1 ; To enable TC1 auto-reload function.
SONiX TECHNOLOGY CO., LTD Page 72 Revision 0.5
Page 73
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
Example: TC1 interrupt service routine without auto-reload function. (TC1_ Counter=8-bit, TC1X8=0)
B0BCLR FTC1IRQ ; Reset TC1IRQ
. . ; TC1 interrupt service routine
. . JMP EXIT_INT ; End of TC1 interrupt service routine and exit interrupt
vector
. .
. .
EXIT_INT:
B0MOV A, PFLAGBUF
B0MOV PFLAG, A
B0XCH A, ACCBUF ; Restore ACC value.
RETI ; Exit interrupt vector
SONiX TECHNOLOGY CO., LTD Page 73 Revision 0.5
Page 74
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
TC1 CLOCK FREQUENCY OUTPUT (BUZZER)
TC1 timer counter provides a frequency output function. By setting the TC1 clock frequency, the clock signal is output
to P5.3 and the P5.3 general purpose I/O function is auto-disable. The TC1 output signal divides by 2. The TC1 clock
has many combinations and easily to make difference frequency. This function applies as buzzer output to output
multi-frequency.
Figure 8-4The TC1OUT Pulse Frequency
Example: Setup TC1OUT output from TC1 to TC1OUT (P5.3). The external high-speed clock is 4MHz. The
TC1OUT frequency is 1KHz. Because the TC1OUT signal is divided by 2, set the TC1 clock to
2KHz. The TC1 clock source is from external oscillator clock. TC1 rate is Fcpu/4. The
TC1RATE2~TC1RATE1 = 110, TC1C = TC1R = 131, TC1_Counter=8-bit, TC1X8=0
B0BCLR FTC1X8 ; Set TC1X8 to 0
MOV A,#01100000B
B0MOV TC1M,A ; Set the TC1 rate to Fcpu/4
MOV A,#131 ; Set the auto-reload reference value
B0MOV TC1C,A
B0MOV TC1R,A
B0BSET FTC1OUT ; Enable TC1 output to P5.3 and disable P5.3 I/O function
B0BSET FALOAD1 ; Enable TC1 auto-reload function
B0BSET FTC1ENB ; Enable TC1 timer
SONiX TECHNOLOGY CO., LTD Page 74 Revision 0.5
Page 75
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
PWM FUNCTION DESCRIPTION
OVERVIEW
PWM function is generated by TC0/TC1 timer counter and output the PWM signal to PWM0OUT pin (P5.4)/
PWM1OUT pin (P5.3). When code option TC0/TC1_Counter= 8-bit, the counter counts modulus 256, from 0-255,
inclusive. The value of the 8-bit counter is compared to the contents of the reference register (TC0R/TC1R). When the
reference register value (TC0R/T C1R) is equal to the counter value (TC0C/T C1C), the PWM output goes low. When
the counter reaches zero, the PWM output is forced high. Following table listed the low-to-high ratio (duty) of the
PWM0/PWM1 output.
For example, TC0_Counter=8-bit, all PWM outputs remain inactive during the first 256 input clock signals. Then, when
the counter value (TC0C/TC1C) changes from FFH back to 00H, the PWM output is forced to high level. The pulse
width ratio (duty cycle) is defined by the contents of the reference register (TC0R/TC1R) and is programmed in
increments of 1:256. The 8-bit PWM data register TC0R/TC1R is write-only register. Different code option of
TC0_Counter/TC1_Counter will cause different PWM Duty, so user can generate different PWM output by selection
different TC0_Counter/TC1_Counter.
PWM output can be held at low level by continuously loading the reference register with 00H. Under PWM operating, to
change the PWM’s duty cycle is to modify the TC0R/TC1R.
TC0X8/TC1X8 PWM0 Frequency PWM1 Frequency
0
1
The value of N depend on code option TC0_Counter/TC1_Counter
Note: Functionality is not guaranteed in shaded area.
SONiX TECHNOLOGY CO., LTD Page 76 Revision 0.5
Page 77
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
01 128..... 254 255.....
01 128..... 254 255.....
TC0/TC1 Clock
TC0/TC1 Clock
TC0R/TC1R = 00H
TC0R/TC1R = 00H
TC0R/TC1R = 01H
TC0R/TC1R = 01H
TC0R/TC1R = 80H
TC0R/TC1R = 80H
TC0R/TC1R = FFH
TC0R/TC1R = FFH
01 128..... 254 255..........
High
High
High
High
High
High
High
Low
Low
Low
Low
Low
Low
Low
Low
Low
01 128 ..... 254 255.....
01 128 ..... 254 255.....
01 128 ..... 254 255..........
Figure 8-5 The Output of PWM with different TC0R/TC1R. (TC0/TC1_Counter=8-bit)
0
12
0
TC0 Clock
TC0 Clock
TC0R = 01H
TC0R = 01H
TC0_count:4-bit
TC0_count:4-bit
TC0R = 01H
TC0R = 01H
TC0_count:5-bit
TC0_count:5-bit
TC0R = 01H
TC0R = 01H
TC0_count:6-bit
TC0_count:6-bit
High
High
High
High
High
High
12
Low
Low
...
...
16
16
17 18
17 18
Low
Low
Low
Low
...
...
32
32
33 34
33 34
...
...
64
64
65 66
65 66
...
...
255
255
01
01
...
...
High
TC0R = 01H
TC0R = 01H
TC0_count:8-bit
TC0_count:8-bit
High
Low
Low
Figure 8-6 The Output of PWM with different TC0_Counter
SONiX TECHNOLOGY CO., LTD Page 77 Revision 0.5
Page 78
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
PWM PROGRAM DESCRIPTION
Example: Setup PWM0 output from TC0 to PWM0OUT (P5.4). The external high-speed oscillator clock is
4MHz. The duty of PWM is 30/256. The PWM frequency is about 1KHz. The PWM clock source is
from external oscillator clock. TC0 rate is Fcpu/4. The TC0RATE2~TC0RATE1 = 110, TC0C = TC0R
= 30, TC0X8 =0, TC0_Counter=8-bit
B0BCLR FTC0X8
MOV A,#01100000B
B0MOV TC0M,A ; Set the TC0 rate to Fcpu/4
MOV A,#0x00 ;First Time Initial TC0
B0MOV TC0C,A
MOV A,#30 ; Set the PWM duty to 30/256
B0BSET FPWM0OUT ; Enable PWM0 output to P5.4 and disable P5.4 I/O function
B0BSET FTC0ENB ; Enable TC0 timer
Note1: The TC0R and TC1R are write-only registers. Don’t process them using INCMS, DECMS
instructions.
Note2: Set TC0C at initial is to make first duty-cycle correct. After TC0 is enabled, don’t modify TC0R
value to avoid duty cycle error of PWM output.
Example: Modify TC0R/TC1R registers’ value.
MOV A, #30H ; Input a number using B0MOV instruction.
B0MOV TC0R, A
INCMS BUF0 ; Get the new TC0R value from the BUF0 buffer defined by
B0MOV A, BUF0 ; programming.
B0MOV TC0R, A
Note2: That is better to set the TC0C and TC0R value together when PWM0 duty modified. It protects the
PWM0 signal no glitch as PWM0 duty changing. That is better to set the TC1C and TC1R value together
when PWM1 duty modified. It protects the PWM1 signal no glitch as PWM1 duty changing.
Note3: The TC0OUT function must be set “0” when PWM0 output enable. The TC1OUT function must be
set “0” when PWM1 output enable.
Note4: The PWM can work with interrupt request.
SONiX TECHNOLOGY CO., LTD Page 78 Revision 0.5
Page 79
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
9
9
9
INTERRUPT
OVERVIEW
The SN8P1702A/SN8P1703A provides 3 interrupt sources, including two internal interrupts (TC0, TC1) and one
external interrupts (INT0 ). The external interrupt can wakeup the chip from power down mode to high-speed normal
mode. The external clock input pins of INT0 are shared with P0.0 pins. Once interrupt service is executed, the GIE bit
in STKP register will clear to “0” for stopping other interrupt request. When interrupt service exits, the GIE bit will set to
“1” to accept the next interrupts’ request. All of the interrupt request signals are stored in INTRQ register. The user can
program the chip to check INTRQ’s content for setting executive priority.
INTENInterrupt enable register
INTEN Interrupt enable reg ister
TC0IRQ
TC0 time out
TC0 time out
TC1 time out
TC1 time out
INT0 trigger
INT0 trigger
INTRQ
INTRQ
3-bit
3-bit
Latchs
Latchs
TC0IRQ
TC1IRQ
TC1IRQ
P00IRQ
P00IRQ
Interrupt
Interrupt
enable
enable
gating
gating
Interrupt vector address (0008H)
Interrupt vector address (0008H)
Global interr upt request signal
Global interr upt request signal
Figure 9-1. The 7 Interrupts
Note: The GIE bit must enable and all interrupt operations work.
SONiX TECHNOLOGY CO., LTD Page 79 Revision 0.5
Page 80
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
INTEN INTERRUPT ENABLE REGISTER
INTEN is the interrupt request control register including two internal interrupts, one external interrupts enable control
bits. One of the register to be set “1” is to enable the interrupt request function. Once of the interrupt occur, the
program jump to ORG 8 to execute interrupt service routines. The program exits the interrupt service routine when the
returning interrupt service routine instruction (RETI) is executed.
INTEN initial value = x000 0000
0C9H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
INTEN
- R/W R/W - - - - R/W
Bit0 P00IEN:External P0.0 interrupt control bit.
0 = disable,
1 = enable.
Bit5 TC0IEN:Timer interrupt control bit.
0 = disable,
1 = enable.
Bit6 TC1IEN:Timer interrupt control bit.
0 = disable,
1 = enable.
0 TC1IEN TC0IEN 0 0 0 0 P00IEN
INTRQ INTERRUPT REQUEST REGISTER
INTRQ is the interrupt request flag register. The register includes all interrupt request indication flags. Each one of
these interrupt request occurs, the bit of the INTRQ register would be set “1”. The INTRQ value needs to be clear by
programming after detecting the flag. In the interrupt vector of program, users know the any interrupt requests
occurring by the register and do the routine corresponding of the interrupt request.
INTRQ initial value = x000 0000
0C8H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
When interrupt occurs, the related request bit of INTRQ register will be set to “1” no matter the related enable bit of
INTEN register is enabled or disabled. If the related bit of INTEN = 1 and the related bit of INTRQ is also set to be “1”.
As the result, the system will execute the interrupt vector (ORG 8). If the related bit of INTEN = 0, moreover, the
system won’t execute interrupt vector even when the related bit of INTRQ is set to be “1”. Users need to be cautious
with the operation under multi-interrupt situation.
0 TC1IRQ TC0IRQ 0 0 0 0 P00IRQ
SONiX TECHNOLOGY CO., LTD Page 80 Revision 0.5
Page 81
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
INTERRUPT OPERATION DESCRIPTION
SN8P1702A/SN8P1703A provides 3 interrupts. The operation of the 3 interrupts is as following.
GIE GLOBAL INTERRUPT OPERATION
GIE is the global interrupt control bit. All interrupts start work after the GIE = 1. It is necessary for interrupt service
request. One of the interrupt requests occurs, and the program counter (PC) points to the interrupt vector (ORG 8) and
the stack add 1 level.
STKP initial value = 0xxx 1111
0DFH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
STKP
R/W - - - R/W R/W R/W R/W
Bit7 GIE:Global interrupt control bit.
0 = disable
1 = enable.
Example: Set global interrupt control bit (GIE).
B0BSET FGIE ; Enable GIE
Note: The GIE bit must enable and all interrupt operations work.
GIE - - - STKPB3 STKPB2 STKPB1 STKPB0
SONiX TECHNOLOGY CO., LTD Page 81 Revision 0.5
Page 82
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
INT0 (P0.0) INTERRUPT OPERATION
The P0.0 interrupt trigger direction is control by PEDGE register.
PEDGE initial value = 0xx0 0xxx
0BFH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
PEDGE
R/W - - R/W R/W - - -
Bit7 PEDGEN: Interrupt and wakeup trigger edge control bit.
Bit[4:3] P00G[1:0]: Port 0.0 edge select bits.
Example: INT0 interrupt request setup.
B0BSET FP00IEN ; Enable INT0 interrupt service
B0BCLR FP00IRQ ; Clear INT0 interrupt request flag
B0BSET FGIE ; Enable GIE
B0BCLR FP00IRQ ; Reset P00IRQ
. . ; INT0 interrupt service routine
. .
EXIT_INT:
B0MOV A, PFLAGBUF
B0MOV PFLAG, A
B0XCH A, ACCBUF ; Restore ACC value.
RETI ; Exit interrupt vector
When the INT0 trigger occurs, the P00IRQ will be set to “1” no matter the P00IEN is enable or disable. If the P00IEN =
1 and the trigger event P00IRQ is also set to be “1”. As the result, the system will execute the interrupt vector (ORG
8). If the P00IEN = 0 and the trigger event P00IRQ is still set to be “1”. Moreover, the system won’t execute interrupt
vector even when the P00IRQ is set to be “1”. Users need to be cautious with the operation under multi-interrupt
situation.
PEDGEN - - P00G1 P00G0 - - -
0 = Disable edge trigger function.
Port 0: Low-level wakeup trigger and falling edge interrupt trigger.
Port 1: Low-level wakeup trigger.
1 = Enable edge trigger function.
P0.0: Wakeup and interrupt trigger is controlled by P00G1 and P00G0 bits.
Port 1: Level change (falling or rising edge) wakeup trigger.
When the TC0C counter occurs overflow, the TC0IRQ will be set to “1” however the TC0IEN is enable or disable. If the
TC0IEN = 1, the trigger event will make the TC0IRQ to be “1” and the system enter interrupt vector. If the TC0IEN = 0,
the trigger event will make the TC0IRQ to be “1” but the system will not enter interrupt vector. Users need to care for
the operation under multi-interrupt situation.
Example: TC0 interrupt request setup.
B0BCLR FTC0IEN ; Disable TC0 interrupt service
B0BCLR FTC0ENB ; Disable TC0 timer
MOV A, #20H ;
B0MOV TC0M, A ; Set TC0 clock = Fcpu / 64
MOV A, #74H ; Set TC0C initial value = 74H
B0MOV TC0C, A ; Set TC0 interval = 10 ms
B0BCLR FTC0IRQ ; Reset TC0IRQ
MOV A, #74H
B0MOV TC0C, A ; Reset TC0C.
. . ; TC0 interrupt service routine
. .
EXIT_INT:
B0MOV A, PFLAGBUF
B0MOV PFLAG, A
B0XCH A, ACCBUF ; Restore ACC value.
RETI ; Exit interrupt vector
SONiX TECHNOLOGY CO., LTD Page 83 Revision 0.5
Page 84
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
TC1 INTERRUPT OPERATION
When the TC1C counter occurs overflow, the TC1IRQ will be set to “1” however the TC1IEN is enable or disable. If the
TC1IEN = 1, the trigger event will make the TC1IRQ to be “1” and the system enter interrupt vector. If the TC1IEN = 0,
the trigger event will make the TC1IRQ to be “1” but the system will not enter interrupt vector. Users need to care for
the operation under multi-interrupt situation.
Example: TC1 interrupt request setup.
B0BCLR FTC1IEN ; Disable TC1 interrupt service
B0BCLR FT C1ENB ; Disable TC1 timer
MOV A, #20H ;
B0MOV TC1M, A ; Set TC1 clock = Fcpu / 64
MOV A, #74H ; Set TC1C initial value = 74H
B0MOV TC1C, A ; Set TC1 interval = 10 ms
MOV A, #74H
B0MOV TC1C, A ; Reset TC1C.
. . ; TC1 interrupt service routine
. .
EXIT_INT:
B0MOV A, PFLAGBUF
B0MOV PFLAG, A
B0XCH A, ACCBUF ; Restore ACC value.
RETI ; Exit interrupt vector
SONiX TECHNOLOGY CO., LTD Page 84 Revision 0.5
Page 85
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
MULTI-INTERRUPT OPERATION
In most conditions, the software designer uses more than one interrupt request. Processing multi-interrupt request
needs to set the priority of these interrupt requests. The IRQ flags of the 7 interrupt are controlled by the interrupt event
occurring. But the IRQ flag set doesn’t mean the system to execute the interrupt vector. The IRQ flags can be triggered
by the events without interrupt enable. Just only any the event occurs and the IRQ will be logic “1”. The IRQ and its
trigger event relationship is as the below table.
There are two things need to do for multi-interrupt. One is to make a good priority for these interrupt requests. Two is
using IEN and IRQ flags to decide executing interrupt service routine or not. Users have to check interrupt control bit
and interrupt request flag in interrupt vector. There is a simple routine as following.
SONiX TECHNOLOGY CO., LTD Page 85 Revision 0.5
Page 86
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
Example: How does users check the interrupt request in multi-interrupt situation?
ORG 8 ; Interrupt vector
B0XCH A, ACCBUF ; Store ACC value.
B0MOV A, PFLAG
B0MOV PFLAGBUF, A
;
INTP00CHK: ; Check INT0 interrupt request
B0BTS1 FP00IEN ; Check P00IEN
JMP INTTC0CHK ; Jump check to next interrupt
B0BTS0 FP00IRQ ; Check P00IRQ
JMP INTP00 ; Jump to INT0 interrupt service routine
INTTC0CHK: ; Check TC0 interrupt request
B0BTS1 FTC0IEN ; Check TC0IEN
JMP INTTC1CHK ; Jump check to next interrupt
B0BTS0 FTC0IRQ ; Check TC0IRQ
JMP INTTC0 ; Jump to TC0 interrupt service routine
INTTC1HK: ; Check TC1 interrupt re quest
B0BTS1 FTC1IEN ; Check TC1IEN
JMP INT_EXIT ; Jump check to next interrupt
B0BTS0 FTC1IRQ ; Check TC1IRQ
JMP INTTC1 ; Jump to TC1 interrupt service routine
INT_EXIT:
B0MOV A, PFLAGBUF
B0MOV PFLAG, A
B0XCH A, ACCBUF ; Restore ACC value.
RETI ; Exit interrupt vector
SONiX TECHNOLOGY CO., LTD Page 86 Revision 0.5
Page 87
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
1
1
1
OVERVIEW
The SN8P1702A/SN8P1703A provides up to 4 ports for users’ application, consisting of one input only port (P0), four
I/O ports (P1, P4, P5). The direction of I/O port is selected by PnM register and PnUR register (N=0,1,4,5) is defined for
user setting pull-up register. After the system resets, all ports work as input function without pull-up resistors.
Note : All of the latch output circuits are push-pull structures.
0
0
0
Port0 structure
Port0 structure
Pin
Pin
I/O PORT
PUR
PUR
Int. bus
Int. bus
Figure 10-1. The I/O Port Block Diagram
Port 1, 4, 5 st ru c t u re
Port 1, 4, 5 st ru c t u re
PUR
PUR
PnM
PnM
PnM
Pin
Pin
PnM
PnM
PnM
Latch
Latch
Int. bus
Int. bus
SONiX TECHNOLOGY CO., LTD Page 87 Revision 0.5
Page 88
Preliminary SN8P1702A/SN8P1703A
I/O PORT FUNCTION TABLE
Port/Pin I/O Function Description Remark
General-purpose input function
P0.0 I
P1.0~P1.1 I/O
P4.0~P4.3 I/O
P5.0~P5.5 I/O General-purpose input/output function
External interrupt (INT0)
Wakeup for power down mode
General-purpose input/output function
Wakeup for power down mode
General-purpose input/output function
ADC analog signal input
Table 10-1. I/O Function Table
8-bit micro-controller build-in 12-bit ADC
SONiX TECHNOLOGY CO., LTD Page 88 Revision 0.5
Page 89
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
PULL-UP RESISTERS
SN8P1702A/SN8P1703A series chips built-in pull-up resisters in port 0, port 1, port4 and port 5. User can set pull-up
register by pin
Register Name P0UR
Address E0H
Bit Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
Bit’s Name - - - - - - - P00R
Read/Write - - - - - - - R/W
After reset 0 0 0 0 0 0 0 0
Register Name P1UR
Address E1H
Bit Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
Bit’s Name - - - - - - P11R P10R
Read/Write - - - - - - R/W R/W
After reset 0 0 0 0 0 0 0 0
Register Name P4UR
Address E4H
Bit Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
Bit’s Name - - - - P43R P42R P41R P40R
Read/Write - - - - R/W R/W R/W R/W
After reset 0 0 0 0 0 0 0 0
Register Name P5UR
Address 0E0H
Bit Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
Bit’s Name - - P55R P54R P53R P52R P51R P50R
Read/Write - - R/W R/W R/W R/W R/W R/W
After reset 0 0 0 0 0 0 0 0
CHIP SN8P1703A
ORG 0x10
Main:
MOV A, #01H
B0MOV P0UR,A ; Enable port 0.0 pull-up resisters
Example 2: Enable all pull-up resisters
CHIP SN8P1703A
ORG 0x10
Main:
MOV A, #01H
B0MOV P0UR,A ; Enable port 0 pull-up resisters
MOV A, #03H
B0MOV P1UR,A ; Enable port 1 pull-up resisters
MOV A, #0FH
B0MOV P4UR,A ; Enable port 4 pull-up resisters
MOV A, #01FH
B0MOV P5UR,A ; Enable port 5 pull-up resisters
Note:
Enable on-chip pull-up resisters of port 0 and p ort 1 to avoid unpredicted wakeup in sleep mode.
SONiX TECHNOLOGY CO., LTD Page 89 Revision 0.5
Page 90
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
I/O PORT MODE
The port direction is programmed by PnM register. Port 0 is always input mode. Port 1,2,4 and 5 can select input or
output direction.
P1M initial value = xxxx xx00
0C1H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
P1M
- - - - - - R/W R/W
Bit[1:0] P1[1:0]M:P1.0~P1.1 I/O direction control bit.
0 = input mode
1 = output mode.
P4M initial value = xxxx 0000
0C4H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
P4M
- - - - R/W R/W R/W R/W
Bit[3:0] P4[3:0]M:P4.0~P4.3 I/O direction control bit.
0 = input mode
1 = output mode.
P5M initial value = xx00 0000
0C5H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
P5M
- - R/W R/W R/W R/W R/W R/W
Bit[5:0] P5[5:0]M: P5.0~P5.5 I/O direction control bit.
0 = input mode
1 = output mode.
The each bit of PnM is set to “0”, the I/O pin is input mode. The each bit of PnM is set to “1”, the I/O pin is output mode.
Input mode is with pull-up resistor controlled by setting @SET_UP macro. The output mode disables the pull-up
resistors no matter pull-up resistor s is set or not.
The PnM registers are read/write bi-direction registers. Users can program them by bit control
instructions (B0BSET, B0BCLR).
0 0 0 0 0 0 P11M P10M
0 0 0 0 P43M P42M P41M P40M
0 0 P55M P54M P53M P52M P51M P50M
SONiX TECHNOLOGY CO., LTD Page 90 Revision 0.5
Page 91
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
Example: I/O mode selecting.
CLR P1M ; Set all ports to be input mode.
CLR P4M
CLR P5M
MOV A, #0FFH ; Set all ports to be output mode.
B0MOV P1M, A
B0MOV P4M, A
B0MOV P5M, A
B0BCLR P1M.0 ; Set P1.0 to be input mode.
B0BSET P1M.0 ; Set P1.0 to be output mode.
SONiX TECHNOLOGY CO., LTD Page 91 Revision 0.5
Page 92
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
I/O PORT DATA REGISTER
P0 initial value = xxxx x000
0D0H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
P0
- - - - - - - R
P1 initial value = xx00 0000
0D1H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
P1
- - - - - - R/W R/W
P4 initial value = 0000 0000
0D4H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
P4
- - - - R/W R/W R/W R/W
P5 initial value = 0000 0000
0D5H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
P5
- - R/W R/W R/W R/W R/W R/W
Example: Read data from input port.
B0MOV A, P0 ; Read data from Port 0
B0MOV A, P1 ; Read data from Port 1
B0MOV A, P4 ; Read data from Port 4
B0MOV A, P5 ; Read data from Port 5
Example: Write data to output port.
MOV A, #55H ; Write data 55H to Port 1, Port 4, Port 5
B0MOV P1, A
B0MOV P4, A
B0MOV P5, A
- - - - - - - P00
- - - - - - P11 P10
- - - - P43 P42 P41 P40
- - P55 P54 P53 P52 P51 P50
SONiX TECHNOLOGY CO., LTD Page 92 Revision 0.5
Page 93
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
Example: Write one bit data to output port.
B0BSET P1.1 ; Set P1.1 and P4.0 to be “1”.
B0BSET P4.0
B0BCLR P1.0 ; Set P1.0 and P5.5 to be “0”.
B0BCLR P5.5
Example: Port bit test.
B0BTS1 P0.0 ; Bit test 1 for P0.0
. B0BTS0 P1.1 ; Bit test 0 for P1.1
SONiX TECHNOLOGY CO., LTD Page 93 Revision 0.5
Page 94
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
1
1
1
1
1
1
4-CHANNEL ANALOG TO DIGITAL
CONVERTER
OVERVIEW
This analog to digital converter of SN8P1702A/SN8P1703A has 4-input sources with up to 4096-step resolution to
transfer analog signal into 12-bits digital data. The sequence of ADC operation is to select input source (AIN0 ~ AIN3)
at first, then set GCHS and ADS bit to “1” to start conversion. When the conversion is complete, the ADC circuit will set
EOC bit to “1” and final value output in ADB register. This ADC circuit can select between 8-bit and 12-bit resolution
operation by programming ADLEN bit in ADR register.
AIN0/P4.0
AIN0/P4.0AIN0/P4.0
DATA BUS
DATA BUS
AIN1/P4.1
AIN1/P4.1AIN1/P4.1
AIN2/P4.2
AIN2/P4.2AIN2/P4.2
AIN3/P4.3
AIN3/P4.3AIN3/P4.3
A/D
A/D
CONVERTER
CONVERTER
(ADC)
(ADC)
8/12
8/12
8/12
DATA BUS
Figure 11-1. AD Converter Function Diagram
Note: For 8-bit resolution, the conversion time is 12 steps.
For 12-bit resolution, the conversion time is 16 steps.
Note: The analog input level must be between the AVREFH and VSS.
Note: The AVREFH level must be between the VDD and VSS+1.2V.
SONiX TECHNOLOGY CO., LTD Page 94 Revision 0.5
Page 95
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
ADM REGISTER
ADM initial value = 0000 x000
0B1H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
ADM
R/W R/W R/W R/W - - R/W R/W
Bit[1:0] CHS[1:0]: ADC input channels select bit.
Bit4 GCHS:Global channel select bit.
Bit5 EOC: ADC status bit.
Bit6 ADS:ADC start bit.
Bit7 ADENB:ADC control bit.
ADENB ADS EOC GCHS - - CHS1 CHS0
00 = AIN0
01 = AIN1
10 = AIN2
11 = AIN3
0 = to disable AIN channel
1 = to enable AIN channel.
0 = Progressing
1 = End of converting and reset ADENB bit.
0 = stop
1 = starting.
0 = disable
1 = enable.
ADR REGISTERS
ADR initial value = x00x 0000
0B3H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
ADR - ADCKS1 ADLEN ADCKS0 ADB3 ADB2 ADB1 ADB0
- R/W R/W R/W R R R R
Bit[3:0] ADBn: ADC data buffer.
ADB11~ADB4 data for 8-bit ADC.
ADB11~ADB0 data for 12-bit ADC.
0 0 Fcpu/4 Both validate in Normal mode and Slow mode
0 1 Fcpu/2 Both validate in Normal mode and Slow mode
1 0 Fhosc Only validate in Normal mode
1 1 Fhosc/2 Only validate in Normal mode
SONiX TECHNOLOGY CO., LTD Page 95 Revision 0.5
Page 96
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
ADB REGISTERS
ADB initial value = xxxx xxxx
0B2H Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
ADB
R R R R R R R R
ADB is ADC data buffer to store AD converter result. The ADB is only 8-bit register including bit4~bit11 ADC data. To
combine ADB register and the low-nibble of ADR will get full 12-bit ADC data buffer. The ADC buffer is a read-only
register. In 8-bit ADC mode, the ADC data is stored in ADB register. In 12-bit ADC mode, the ADC data is stored in
ADB and ADR registers.
Note: ADB[0:11] value is unknown when power on.
ADB11 ADB10 ADB9 ADB8 ADB7 ADB6 ADB5 ADB4
SONiX TECHNOLOGY CO., LTD Page 96 Revision 0.5
Page 97
Preliminary SN8P1702A/SN8P1703A
8-bit micro-controller build-in 12-bit ADC
P4CON REGISTERS
ADB initial value = xxxx 0000
0AEH Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
P4CON
- - - - R/W R/W R/W R/W
P4CON is Port4 Configuration register. This register can avoid current leakage in unselected ADC channel, which
connected to an analog input source. P4CON [3:0] sets to high will isolate related Port4 digital input path outside chip.
For example, both AIN0 (Port4.0) and AIN1 (Port4.1) are connected to analog input signal, and AIN0 be selected as
conversion channel (CHS [1:0] = 00), this mean the unselected channel P4.1 maybe in digital input mode (if P41M = 0)
In this condition will possible leak current from analog input source. Set P4CON1 = “1” can block P4.1 digital input path
to avoid the current leakage from AIN1.
For the same reason, P4CON0 must set to “1” when conversion channel is AIN1. So any Port4 pin be connected
to analog input source should be set related bit of P4CON as high to avoid unpredictable current leakage. Especially
before entering Sleep mode, remember to set related bit of P4CON as “1”.
Bit [3:0] P4CON: Port4 Configuration register.
P4CON3
P4CON2
P4CON1
P4CON0
Note 1: When Port4 is general I/O port, set related P4CON [3:0] = “0”
Note 2: When Port4 is ADC input channel, set related P4CON [3:0] = “1”
The AIN’s input voltage vs. ADB’s output data
AIN n ADB11 ADB10 ADB9 ADB8ADB7ADB6ADB5ADB4ADB3 ADB2 ADB1ADB0
For different applications, users maybe need more than 8-bit resolution but less than 12-bit ADC converter. To process
the ADB and ADR data can make the job well. First, the AD resolution must be set 12-bit mode and then to execute
ADC converter routine. Then delete the LSB of ADC data and get the new resolution result. The table is as following.
ADC
Resolution
8-bit O O O O O O O O x x x x
9-bit O O O O O O O O O x x x
10-bit O O O O O O O O O O x x
11-bit O O O O O O O O O O O x
12-bit O O O O O O O O O O O O
O = Selected, x = Delete
0 0 0 0 P4CON3 P4CON2 P4CON1 P4CON0
0 Pass P4.3 digital path into chip.
1 Isolate P4.3 digital path into chip
0 Pass P4.2 digital path into chip.
1 Isolate P4.2 digital path into chip
0 Pass P4.1 digital path into chip.
1 Isolate P4.1 digital path into chip
0 Pass P4.0 digital path into chip.
1 Isolate P4.0 digital path into chip
12-bit ADC conversion time = 1/(ADC clock /4)*16 sec
8-bit ADC conversion time = 1/(ADC clock /4)*12 sec
High clock (Fosc) is @3.58MHz
ADLEN ADCKS1 ADCKS0 ADC Clock ADC conversion time
0 0 Fcpu/4 1/((3.58MHz/4)/4/4)*12 = 214.5 us
0 (8-bit)
1 (12-bit)
Example: To set AIN0 ~ AIN1 for ADC input and executing 12-bit ADC
ADC0:
MOV A, #60H
B0MOV ADR, A ; To set 12-bit ADC and ADC clock = Fosc.
B0SET FP4CON1 ;Isolate AIN1 signal to avoid current leakage
B0CLR FP4CON0 ;Pass AIN0 signal into ADC
MOV A,#90H
B0MOV ADM,A ; To enable ADC and set AIN0 input
B0SET P4CON1 ; To enable ADC and set AIN0 input
B0BSET FADS ; To start conversion
WADC0: B0BTS1 FEOC ; To skip, if end of converting =1
JMP WADC0 ; else, jump to WADC0
B0MOV A,ADB ; To get AIN0 input data
ADC1: B0SET FP4CON0 ;Isolate AIN0 signal to avoid current leakage
B0CLR FP4CON1 ;Pass AIN1 signal into ADC
MOV A,#91H ;
B0MOV ADM,A ; To enable ADC and set AIN1 input
B0BSET FADS ; To start conversion
. . .
QEXADC: B0BCLR FGCHS ; To release AINx input channel
0 1 Fcpu/2 1/((3.58MHz/4)/2/4)*12 = 107.3 us
1 0 Fhosc 1/(3.58MHz/4)*12 = 13.4 us
1 1 Fhosc/2 1/(3.58MHz/2/4)*12 = 26.8 us
0 0 Fcpu/4 1/((3.58MHz/4)/4/4)*16 = 286 us
0 1 Fcpu/2 1/((3.58MHz/4)/2/4)*16 = 143 us
1 0 Fhosc 1/(3.58MHz/4)*16 = 17.9 us
1 1 Fhosc/2 1/(3.58MHz/2/4)*16 = 35.8 us
SONiX TECHNOLOGY CO., LTD Page 98 Revision 0.5
Page 99
Preliminary SN8P1702A/SN8P1703A
ADC CIRCUIT
Analog Signal Input
Analog Signal Input
VDD
VDD
AVREF
AVREF
AIN0/P40
AIN0/P40
0.1uF
0.1uF
AVREFH is connected to VDD.
8-bit micro-controller build-in 12-bit ADC
MCU
MCU
VDD
VDD
AVREF
Reference Voltage Input
Reference Voltage Input
Analog Signal Input
Analog Signal Input
0.1uF
47uF
47uF
AVREFH is connected to external AD reference voltage.
Figure 11-2. The AINx and AVREFH Circuit of AD Converter
Note: The capacitor between AIN and GND is a bypass capacitor. It is helpful to stable the analog signal.
;------------------------------------------------------------------------------; Include Files
;------------------------------------------------------------------------------.nolist ; do not list the macro file
org 0h ;Bank 0 data section start from RAM address 0x000
Wk00B0 DS 1 ;Temporary buffer for main loop
Iwk00B0 DS 1 ;Temporary buffer for ISR
AccBuf DS 1 ;Accumulator buffer
PflagBuf DS 1 ;PFLAG buffer
org 100h ;Bank 1 data section start from RAM address 0x100
BufB1 DS 20 ;Temporary buffer in bank 1
;------------------------------------------------------------------------------; Bit Flag Definition
;------------------------------------------------------------------------------ Wk00B0_0 EQU Wk00B0.0 ;Bit 0 of Wk00B0
Iwk00B0_1 EQU Iwk00B0.1 ;Bit 1 of Iwk00
SONiX TECHNOLOGY CO., LTD Page 100 Revision 0.5
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.