HT82A836R USB Audio MCU Technical Document · Application Note - HA0075E MCU Reset and Oscillator Circuits Application Note Features · USB 2.0 full speed compatible · 352´8 Data Memory in two banks · USB spec V1.1 full speed operation and USB audio · Programmable frequency divider function device class spec V1.0 · Integrated SPI hardware interface · Operating voltage at fSYS= 6M/12MHz: 3.3V~5.5V · Low voltage reset function · Port A wake-up on rising or falling transitions · 6-channel 12-bit A/D converter · Embedded high-performance 16-bit PCM ADC · 2-channel PWM function · Integrated Digital PGA - Programmable Gain Ampli- · m Law Compander fier · Power-down function and wake-up reduce power · 48kHz/8kHz sampling rate for audio playback se- consumption lected by software · Up to of 44 bidirectional I/O lines · 8kHz/16kHz audio recording sampling rate selected · Dual 16-bit programmable Timer/Event Counters by software with overflow interrupts · Embedded class AB power amplifier for speaker driv- · Watchdog Timer ing · 16-level subroutine nesting · Embedded High Performance 16-bit audio DAC · Bit manipulation instruction · Audio playback digital volume control · 15-bit table read instruction · 5 endpoints supported including endpoint 0 · 63 powerful instructions · Supports 1 Control, 2 Interrupts and 2 Isochronous · All instructions executed within one or two machine transfers cycles · Two hardware implemented Isochronous transfers · Low voltage reset function (3.0V±0.3V) · Total FIFO size: 496 bytes - 8, 8, 384, 64, 32 for · 80-pin LQFP (10mm´10mm) package type EP0~EP4 · 8192´16 Program Memory General Description The DAC in the HT82A836R operates at a sampling rate of 48kHz/8kHz and the 16-bit PCM ADC operates at frequency of 8kHz/16kHz for the Microphone input, with the options selected using software. The integrated DAC also includes a digitally programmable gain amplifier with a range of -32dB to +6dB. The digital gain range of the ADC input is from 0dB to 19.5dB. The HT82A836R is an 8-bit high-performance RISC microcontroller designed for USB phone product applications. To ensure a high level of functional integration for USB phone applications, this 8-bit microcontroller includes important features such as 16-bit PCM A/D Converter, USB transceiver, Serial Interface Engine, audio class processing unit, m law Compander, 6-channel 12-bit ADC, 2-channel PWM and FIFO. Rev. 1.10 1 August 5, 2011 HT82A836R Block Diagram L V R W a tc h d o g T im e r O s c illa to r O T P P ro g ra m M e m o ry W a tc h d o g T im e r R A M D a ta M e m ro y S P I In te rfa c e U S B In te rfa c e R e s e t C ir c u it 8 - b it R IS C M C U C o re In te rru p t C o n tr o lle r S y s te m O s c illa to r I/O P o rts 1 6 - b it T im e r A /D C o n v e rte r P r o g r a m m a b le F re q u e n c y G e n e ra to r 1 6 - b it T im e r S ta c k P W M G e n e ra to r P o w e r A m p . D A C A /D P C M C o n v e rte r Pin Assignment R E S E D V D D U S B D U S B D V 3 3 D V S S P F P F P F P F P A P A P A P A P A P A P A P A A V D D R O U O N P T T 7 6 5 4 3 2 1 0 3 2 1 0 1 2 1 L O U T A V S S 2 A V S S 1 B IA S M U S IC _ IN A V D D 1 A V D D 4 A N 5 A N 4 A N 3 A N 2 A N 1 A N 0 A V S S 4 A V D D 3 V A G R e f V A G T I+ T IT G 8 0 7 9 7 8 7 7 7 6 7 5 7 4 7 3 7 2 7 1 7 0 6 9 6 8 6 7 6 6 6 5 6 4 6 3 6 2 6 1 1 6 0 2 5 9 3 5 8 4 5 7 5 5 6 6 5 5 7 5 4 8 5 3 9 5 2 H T 8 2 A 8 3 6 R 8 0 L Q F P -A 1 0 1 1 5 1 5 0 1 2 4 9 1 3 4 8 4 7 1 4 4 6 1 5 4 5 1 6 4 4 1 7 4 3 1 8 4 2 1 9 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 0 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 4 0 4 1 O S C O S C P E 0 P E 1 P E 2 P E 3 P E 4 P E 5 P E 6 P E 7 D V S P D 0 P D 1 P D 2 P D 3 P D 4 P D 5 P D 6 P D 7 D V D O I /IN T S 2 D 2 P C 0 P C 1 P C 2 P C 3 P C 4 P C 5 P C 6 P C 7 D V S P B 0 P B 1 P B 2 P B 3 P B 4 P B 5 P B 6 P B 7 P W M P W M A V S O I S K 2 /B Z /T M R 0 /T M R 1 /S D /S D /S C /S C S 3 0 1 S 3 Rev. 1.10 August 5, 2011 HT82A836R Pin Description I/O Configuration Option ROUT O ¾ Right driver analog output LOUT O ¾ Left driver analog output AVSS4 ¾ ¾ 12-bit ADC negative power supply, ground AVSS3 ¾ AVSS2 ¾ ¾ Audio power amplifier negative power supply, ground AVSS1 ¾ ¾ Audio DAC negative power supply, ground BIAS ¾ ¾ A capacitor should be connected to ground to increase half-supply stability I ¾ Power amplifier input signal source if register bit SELW= ²1². The analog signal input will amplify by the power amp then output to ROUT and LOUT at the same time. AVDD4 ¾ ¾ 12-bit ADC positive power supply AVDD3 ¾ ¾ PCM ADC positive power supply AVDD2 ¾ ¾ Audio power amplifier positive power supply AVDD1 ¾ ¾ Audio DAC positive power supply AN0~AN5 I ¾ 12-bit ADC analog inputs VAGRef I ¾ PCM ADC analog ground reference voltage (should left open or connected by a bypass capacitor (Ex:100pF) to ground) VAG O ¾ PCM ADC analog ground voltage (should connected by a bypass capacitor (Ex:10mF) to ground) TI+ I ¾ OP AMP non-inverting input TI- I ¾ OP AMP inverting input TG O ¾ OP AMP gain setting output PWM0~PWM1 O ¾ PWM outputs Pin Name MUSIC_IN Description PCM ADC negative power supply, ground PA0~PA7 Bidirectional 8-bit input/output port. Each bit can be configured as a wake-up Pull-high input by a configuration option. Software instructions determine if the pin is a Wake-up I/O CMOS output or Schmitt trigger input. Configuration options determine which NMOS/CMOS pins on this port have pull-high resistors. The output structure can be either Output NMOS or CMOS types determined via configuration option. PB0~PB7 I/O Pull-high Wake-up Bidirectional 8-bit input/output port. Software instructions determine if the pin is a CMOS output or Schmitt trigger input. Configuration options determine which pins on this port have pull-high resistors. PC0/BZ PC1/TMR0 PC2/TMR1 PC3 PC4/SDO PC5/SDI PC6/SCS PC7/SCK I/O Pull-high Wake-up Bidirectional 8-bit input/output port. Software instructions determine if the pin is a CMOS output or Schmitt trigger input. Configuration options determine which pins on this port have pull-high resistors. Pin PC0 is shared with the buzzer pin BZ. Pins PC1/PC2 are shared with timer input pins TMR0/TMR1. Pins PC4/ PC5 are shared with Serial Interface pins SDO/SDI. Pin PC6 is shared with the Serial Interface Slave Select pin. Pin PC7 is shared with the Serial Interface clock signal. PD0~PD7 I/O Pull-high Wake-up Bidirectional 8-bit input/output port. Software instructions determine if the pin is a CMOS output or Schmitt trigger input. Configuration options determine which pins on this port have pull-high resistors. Rev. 1.10 3 August 5, 2011 HT82A836R I/O Configuration Option Description PE0~PE6 PE7/INT I/O Pull-high Wake-up Bidirectional 8-bit input/output port. Software instructions determine if the pin is a CMOS output or Schmitt trigger input. Configuration options determine which pins on this port have pull-high resistors. PE7 is shared with external interrupt input INT. PF0~PF3 I/O Pull-high Wake-up Bidirectional 4-bit input/output port. Software instructions determine if the pin is a CMOS output or Schmitt trigger input. Configuration options determine which pins on this port have pull-high resistors. DVDD2 ¾ ¾ Positive digital power supply DVSS2 ¾ ¾ Negative digital & I/O power supply, ground DVDD1 ¾ ¾ Positive digital power supply DVSS1 ¾ ¾ Negative digital power supply, ground OSCI OSCO I O ¾ OSCI, OSCO are connected to an 6MHz or 12MHz crystal/resonator, determined by software instructions, for the internal system clock. RESET I ¾ Schmitt trigger reset input, active low USBDN I/O ¾ USBD- line USBDP I/O ¾ USBD+ line V33O O ¾ 3.3V regulator output Pin Name Absolute Maximum Ratings Supply Voltage ...........................VSS-0.3V to VSS+6.0V Storage Temperature ............................-50°C to 125°C Input Voltage..............................VSS-0.3V to VDD+0.3V IOL Total ..............................................................150mA Total Power Dissipation .....................................500mW Operating Temperature...........................-40°C to 85°C IOH Total............................................................-100mA Note: These are stress ratings only. Stresses exceeding the range specified under ²Absolute Maximum Ratings² may cause substantial damage to the device. Functional operation of this device at other conditions beyond those listed in the specification is not implied and prolonged exposure to extreme conditions may affect device reliability. D.C. Characteristics Ta=25°C Test Conditions Symbol Parameter VDD Conditions ¾ Min. Typ. Max. Unit 3.3 5.0 5.5 V VDD Operating Voltage ¾ IDD1 Operating Current 5V No load, fSYS=12MHz ADC on, DAC on ¾ 12 ¾ mA IDD2 Operating Current 5V No load, fSYS=12MHz ADC off, DAC off ¾ 8 ¾ mA ISUS Suspend Current 5V No load, system HALT, USB transceiver and 3.3V regulator on ¾ 330 ¾ mA VIL1 Input Low Voltage for I/O Ports ¾ ¾ 0 ¾ 0.3VDD V VIH1 Input High Voltage for I/O Ports ¾ ¾ 0.7VDD ¾ VDD V VIL2 Input Low Voltage (RESET) ¾ ¾ 0 ¾ 0.4VDD V VIH2 Input High Voltage (RESET) ¾ ¾ 0.8VDD ¾ VDD V IOL I/O Port Sink Current 5V VOL=0.1VDD ¾ 5 ¾ mA Rev. 1.10 4 August 5, 2011 HT82A836R Test Conditions Symbol Parameter VDD Min. Typ. Max. Unit Conditions IOH I/O Port Source Current 5V VOH=0.9VDD ¾ -5 ¾ mA RPH Pull-high Resistance 5V ¾ 30 40 80 kW VLVR0 Low Voltage Reset 5V ¾ 2.7 3.0 3.3 V VV33O 3.3V Regulator Output 5V IV33O= -5mA 3.0 3.3 3.6 V DAC+Power Amp: Test Condition: Measurement bandwidth 20Hz to 20kHz, fS= 48kHz. Line output series capacitor with 220mF. THD+N SNRDA DR POUT THD+N(Note) Signal to Noise Ratio Note1 Dynamic Range Output Power 4W load ¾ -30 ¾ dB 8W load ¾ -35 ¾ dB 4W load ¾ 81 ¾ dB 8W load ¾ 82 ¾ dB 4W load ¾ 87 ¾ dB 8W load ¾ 88 ¾ dB 4W load, THD=10% ¾ 400 ¾ mW/ch 8W load, THD=10% ¾ 200 ¾ mW/ch 5V 5V 5V 5V PCM ADC: SNRAD Signal to Noise Ratio 5V ¾ ¾ 77 ¾ dB VAG Reference Voltage 5V ¾ ¾ 2.0 ¾ V VPEAK Peak Single Frequency Tone 5V Amplitude without Clipping ¾ ¾ 1.575 ¾ VPK Note: Sine wave input at 1kHz, -6dB A.C. Characteristics Ta=25°C Test Conditions Symbol Parameter Min. Typ. Max. Unit ¾ 0.4 ¾ 12 MHz 5V ¾ ¾ 100 ¾ ms Reset Low Pulse Width ¾ ¾ 1 ¾ ¾ ms tSST System Start-up Timer Period ¾ ¾ ¾ 1024 ¾ *tSYS tINT Interrupt Pulse Width ¾ ¾ 1 ¾ ¾ ms tADC A/D Conversion Time ¾ ¾ ¾ 80 ¾ tAD tADCS A/D Sampling Time ¾ ¾ ¾ 32 ¾ tAD VDD Conditions 5V tWDTOSC Watchdog Oscillator Period tRES fSYS System Clock (Crystal OSC) Note: *tSYS=1/fSYS Rev. 1.10 5 August 5, 2011 HT82A836R System Architecture A key factor in the high-performance features of the Holtek range of microcontrollers is attributed to the internal system architecture. The range of devices take advantage of the usual features found within RISC microcontrollers providing increased speed of operation and enhanced performance. The pipelining scheme is implemented in such a way that instruction fetching and instruction execution are overlapped, hence instructions are effectively executed in one cycle, with the exception of branch or call instructions. An 8-bit wide ALU is used in practically all operations of the instruction set. It carries out arithmetic operations, logic operations, rotation, increment, decrement, branch decisions, etc. The internal data path is simplified by moving data through the Accumulator and the ALU. Certain internal registers are implemented in the Data Memory and can be directly or indirectly addressed. The simple addressing methods of these registers along with additional architectural features ensure that a minimum of external components is required to provide a functional I/O control system with maximum reliability and flexibility. functions. In this way, one T1~T4 clock cycle forms one instruction cycle. Although the fetching and execution of instructions takes place in consecutive instruction cycles, the pipelining structure of the microcontroller ensures that instructions are effectively executed in one instruction cycle. The exception to this are instructions where the contents of the Program Counter are changed, such as subroutine calls or jumps, in which case the instruction will take one more instruction cycle to execute. For instructions involving branches, such as jump or call instructions, two machine cycles are required to complete instruction execution. An extra cycle is required as the program takes one cycle to first obtain the actual jump or call address and then another cycle to actually execute the branch. The requirement for this extra cycle should be taken into account by programmers in timing sensitive applications. Program Counter During program execution, the Program Counter is used to keep track of the address of the next instruction to be executed. It is automatically incremented by one each time an instruction is executed except for instructions, such as ²JMP² or ²CALL², that demand a jump to a non-consecutive Program Memory address. Note that the Program Counter width varies with the Program Memory capacity depending upon which device is selected. Clocking and Pipelining The main system clock, derived from a Crystal/Resonator is subdivided into four internally generated non-overlapping clocks, T1~T4. The Program Counter is incremented at the beginning of the T1 clock during which time a new instruction is fetched. The remaining T2~T4 clocks carry out the decoding and execution O s c illa to r C lo c k ( S y s te m C lo c k ) P h a s e C lo c k T 1 P h a s e C lo c k T 2 P h a s e C lo c k T 3 P h a s e C lo c k T 4 P ro g ra m C o u n te r P ip e lin in g P C P C + 1 F e tc h In s t. (P C ) E x e c u te In s t. (P C -1 ) P C + 2 F e tc h In s t. (P C + 1 ) E x e c u te In s t. (P C ) F e tc h In s t. (P C + 2 ) E x e c u te In s t. (P C + 1 ) System Clocking and Pipelining M O V A ,[1 2 H ] 2 C A L L D E L A Y 3 C P L [1 2 H ] 4 : 5 : 6 1 D E L A Y : F e tc h In s t. 1 E x e c u te In s t. 1 F e tc h In s t. 2 E x e c u te In s t. 2 F e tc h In s t. 3 F lu s h P ip e lin e F e tc h In s t. 6 E x e c u te In s t. 6 F e tc h In s t. 7 N O P Instruction Fetching Rev. 1.10 6 August 5, 2011 HT82A836R Stack However, it must be noted that only the lower 8 bits, known as the Program Counter Low Register, are directly addressable by user. This is a special part of the memory which is used to save the contents of the Program Counter only. The stack has 16 levels and is neither part of the data nor part of the program space, and can neither be read from nor written to. The activated level is indexed by the Stack Pointer, SP, which can also neither be read from nor written to. At a subroutine call or interrupt acknowledge signal, the contents of the Program Counter are pushed onto the stack. At the end of a subroutine or an interrupt routine, signaled by a return instruction, RET or RETI, the Program Counter is restored to its previous value from the stack. After a device reset, the Stack Pointer will point to the top of the stack. When executing instructions requiring jumps to non-consecutive addresses such as a jump instruction, a subroutine call, interrupt or reset, etc., the microcontroller manages program control by loading the required address into the Program Counter. For conditional skip instructions, once the condition has been met, the next instruction, which has already been fetched during the present instruction execution, is discarded and a dummy cycle takes its place while the correct instruction is obtained. The lower byte of the Program Counter, known as the Program Counter Low register or PCL, is available for program control and is a readable and writable register. By transferring data directly into this register, a short program jump can be executed directly, however, as only this low byte is available for manipulation, the jumps are limited to the present page of memory, that is 256 locations. When such program jumps are executed it should also be noted that a dummy cycle will be inserted. If the stack is full and an enabled interrupt takes place, the interrupt request flag will be recorded but the acknowledge signal will be inhibited. When the Stack Pointer is decremented, by RET or RETI, the interrupt will be serviced. This feature prevents stack overflow allowing the programmer to use the structure more easily. However, when the stack is full, a CALL subroutine instruction can still be executed which will result in a stack overflow. Precautions should be taken to avoid such cases, which might cause unpredictable program branching. The lower byte of the Program Counter is fully accessible under program control. Manipulating the PCL might cause program branching, so an extra cycle is needed to pre-fetch. Further information on the PCL register can be found in the Special Function Register section. Program Counter Bits Mode b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 Initial Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 USB Interrupt 0 0 0 0 0 0 0 0 0 0 1 0 0 Timer/Event Counter 0 Overflow 0 0 0 0 0 0 0 0 0 1 0 0 0 Timer/Event Counter 1 Overflow 0 0 0 0 0 0 0 0 0 1 1 0 0 Play Interrupt 0 0 0 0 0 0 0 0 1 0 0 0 0 Multi Function Interrupt 0 0 0 0 0 0 0 0 1 0 1 0 0 Record Interrupt 0 0 0 0 0 0 0 0 1 1 0 0 0 Skip Program Counter + 2 Loading PCL PC12 PC11 PC10 PC9 PC8 @7 @6 @5 @4 @3 @2 @1 @0 Jump, Call Branch #12 #11 #10 #9 #8 #7 #6 #5 #4 #3 #2 #1 #0 Return from Subroutine S12 S11 S10 S9 S8 S7 S6 S5 S4 S3 S2 S1 S0 Program Counter Note: PC12~PC8: Current Program Counter bits @7~@0: PCL bits #12~#0: Instruction code address bits S12~S0: Stack register bits Rev. 1.10 7 August 5, 2011 HT82A836R P ro g ra m T o p o f S ta c k C o u n te r Special Vectors Within the Program Memory, certain locations are reserved for special usage such as reset and interrupts. S ta c k L e v e l 1 · Location 000H S ta c k L e v e l 2 S ta c k P o in te r B o tto m o f S ta c k S ta c k L e v e l 3 This vector is reserved for use by the device reset for program initialisation. After a device reset is initiated, the program will jump to this location and begin execution. P ro g ra m M e m o ry · Location 004H S ta c k L e v e l 1 6 This vector is used by the USB interrupt. If a USB interrupt occurs, the program will jump to this location and begin execution if the USB interrupt is enabled and the stack is not full. Arithmetic and Logic Unit - ALU The arithmetic-logic unit or ALU is a critical area of the microcontroller that carries out arithmetic and logic operations of the instruction set. Connected to the main microcontroller data bus, the ALU receives related instruction codes and performs the required arithmetic or logical operations after which the result will be placed in the specified register. As these ALU calculation or operations may result in carry, borrow or other status changes, the status register will be correspondingly updated to reflect these changes. The ALU supports the following functions: · Location 008H This vector is used by the Timer/Event Counter 0. If a counter overflow occurs, the program will jump to this location and begin execution if the timer interrupt is enabled and the stack is not full. · Location 00CH This vector is used by the Timer/Event counter 1. If a counter overflow occurs, the program will jump to this location and begin execution if the timer interrupt is enabled and the stack is not full. · Location 010H This vector is used by the play interrupt service program. If play data occurs, the program will jump to this location and begin execution if the play interrupt is enabled and the stack is not full. · Arithmetic operations: ADD, ADDM, ADC, ADCM, SUB, SUBM, SBC, SBCM, DAA · Logic operations: AND, OR, XOR, ANDM, ORM, XORM, CPL, CPLA · Location 014H · Rotation RRA, RR, RRCA, RRC, RLA, RL, RLCA, This vector is used by the Multi-function interrupt. If an interrupt results from a serial interface interrupt, an end of 12-bit A/D conversion cycle or an external interrupt, the program will jump to this location and begin execution if the relevant interrupt is enabled and the stack is not full. RLC · Increment and Decrement INCA, INC, DECA, DEC · Branch decision, JMP, SZ, SZA, SNZ, SIZ, SDZ, SIZA, SDZA, CALL, RET, RETI · Location 018H Program Memory This area is used by the Record interrupt. If record data occurs, the program will jump to this location and begin execution if the timer interrupt is enabled and the stack is not full. The Program Memory is the location where the user code or program is stored. The device contains One-Time Programmable, OTP, memory where users can program their application code into the device. By using the appropriate programming tools, OTP devices offer users the flexibility to freely develop their applications, which may be useful during debug or for products requiring frequent upgrades or program changes. OTP devices are also applicable for use in applications that require low or medium volume production runs. 0 0 0 0 H 0 0 0 4 H 0 0 0 8 H 0 0 0 C H 0 0 1 0 H Organisation 0 0 1 4 H The Program Memory has a capacity of 8K by 16 bits. The Program Memory is addressed by the Program Counter and also contains data, table information and interrupt entries. Table data, which can be setup in any location within the Program Memory, is addressed by separate table pointer registers. 0 0 1 8 H 0 0 1 B H D e v ic e In itia liz a tio n P r o g r a m U S B In te r r u p t S u b r o u tin e T im e r /E v e n t C o u n te r 0 In te r r u p t S u b r o u tin e T im e r /E v e n t C o u n te r 1 In te r r u p t S u b r o u tin e P ro g ra m M e m o ry P la y In te r r u p t S u b r o u tin e M u lti- fu n c tio n 1 In te r r u p t S u b r o u tin e R e c o r d In te r r u p t S u b r o u tin e 0 0 2 0 H 1 F F F H L o o k - u p T a b le ( 2 5 6 w o r d s ) 1 6 b its Program Memory Structure Rev. 1.10 8 August 5, 2011 HT82A836R The following diagram illustrates the addressing/data flow of the look-up table using the dual table address pointers TBLP and TBHP: Look-up Table Any location within the Program Memory can be defined as a look-up table where programmers can store fixed data. To use the look-up table, the table pointers must first be setup which point to the data in the Program Memory which is to be read. In this device there are two table pointers, the low byte pointer, TBLP and the high byte pointer, TBHP. However, the high byte pointer, TBHP, can only be used if it is enabled using configuration options. Using both table pointers enables any area in the Program Memory to be addressed while if only the low byte pointer, TBLP, is used then only the present page or last page can be addressed. T B H P T B L H H ig h b y te o f ta b le c o n te n ts The following example shows how the table pointer and table data is defined and retrieved from the micro controller using the single table data pointer, TBLP. This example uses raw table data located in the last page which is stored there using the ORG statement. The value at this ORG statement is ²1F00H² which refers to the start address of the last page within the 8K Program Memory of device. The table pointer is setup here to have an initial value of ²06H². This will ensure that the first data read from the data table will be at the Program Memory address ²1F06H² or 6locations after the start of the last page. Note that the value for the table pointer is referenced to the first address of the present page if the ²TABRDC [m]² instruction is being used. The high byte of the table data which in this case is equal to zero will be transferred to the TBLH register automatically when the ²TABRDL [m]² instruction is executed. P ro g ra m M e m o ry T B L H T a b le C o n te n ts H ig h B y te S p e c ifie d b y [m ] T a b le C o n te n ts L o w Because the TBLH register is a read-only register and cannot be restored, care should be taken to ensure its protection if both the main routine and Interrupt Service Routine use the table read instructions. If using the table read instructions, the Interrupt Service Routines may change the value of TBLH and subsequently cause errors if used again by the main routine. As a rule it is recommended that simultaneous use of the table read instructions should be avoided. However, in situations where simultaneous use cannot be avoided, the interrupts should be disabled prior to the execution of any main routine table-read instructions. Note that all table related instructions require two instruction cycles to complete their operation. B y te Single Address Pointer Look-up Table If the configuration options enable the high table pointer, TBHP, then this register together with the low table pointer, TBLP, can be used together as a pair to point to any located in the Program Memory. After setting up both the low and high byte table pointers, the table data can then be retrieved from any area of Program Memory using the ²TABRDC [m]² instruction or from the last page of the Program Memory using the ²TABRDL [m]² instruction. When either of these instructions are executed, the lower order table byte from the Program Memory will be transferred to the user defined Data Memory register [m] as specified in the instruction. The higher order table data byte from the Program Memory will be transferred to the TBLH special register. Rev. 1.10 H ig h b y te o f ta b le c o n te n ts Table Program Example The following diagram illustrates the addressing/data flow of the look-up table using the single table address pointer TBLP: T B L P S p e c ifie d b y [m ] Dual Address Pointer Look-up Table If the configuration options do not enable the high byte pointer, then after setting up the low table pointer, TBLP, the table data can be retrieved from the current Program Memory page or last Program Memory page using the ²TABRDC[m]² or ²TABRDL [m]² instructions, respectively. When these instructions are executed, the lower order table byte from the Program Memory will be transferred to the user defined Data Memory register [m] as specified in the instruction. The higher order table data byte from the Program Memory will be transferred to the TBLH special register. P ro g ra m C o u n te r H ig h B y te P ro g ra m M e m o ry T B L P 9 August 5, 2011 HT82A836R tempreg1 tempreg2 db db : : ? ? ; temporary register #1 ; temporary register #2 mov a,06h ; initialise table pointer - note that this address ; is referenced mov tblp,a : : ; to the last page or present page tabrdl tempreg1 ; ; ; ; dec tblp ; reduce value of table pointer by one tabrdl tempreg2 ; ; ; ; ; ; ; ; transfers value in table referenced by table pointer to tempregl data at prog. memory address ²1F06H² transferred to tempreg1 and TBLH transfers value in table referenced by table pointer to tempreg2 data at prog.memory address ²1F05H² transferred to tempreg2 and TBLH in this example the data ²1AH² is transferred to tempreg1 and data ²0FH² to register tempreg2 the value ²00H² will be transferred to the high byte register TBLH : : org 1F00h dc 00Ah, 00Bh, 00Ch, 00Dh, 00Eh, 00Fh, 01Ah, 01Bh : : Table Location Bits Instruction TABRDC [m] ; sets initial address of last page b12 b11 b10 PC12 PC11 PC10 TABRDL [m] 1 1 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 PC9 PC8 @7 @6 @5 @4 @3 @2 @1 @0 1 1 @7 @6 @5 @4 @3 @2 @1 @0 1 Table Location Note: PC12~PC8: Current Program Counter bits TBHP register bit4~bit0 when TBHP option is enabled @7~@0: Table Pointer TBLP bits Data Memory Organisation The Data Memory is a volatile area of 8-bit wide RAM internal memory and is the location where temporary information is stored. Divided into two sections, the first of these is an area of RAM where special function registers are located. These registers have fixed locations and are necessary for correct operation of the device. Many of these registers can be read from and written to directly under program control, however, some remain protected from user manipulation. The second area of Data Memory is reserved for general purpose use. All locations within this area are read and write accessible under program control. Rev. 1.10 The RAM Data Memory is subdivided into two banks, known as Bank 0 and Bank 1, all of which are implemented in 8-bit wide RAM. The Bank 0 Data Memory is subdivided into two sections, the Special Purpose Data Memory and the General Purpose Data Memory. The start address of the Bank 0 Data Memory is the address 00H and the last Data Memory address is FFH. The Bank 1 Data Memory consists only of General Purpose Data Memory. The start address of the Bank 1 Data Memory is the address 40H and the last Data Memory address is FFH. Selection of which Bank is to be used is implemented using the Bank Pointer. 10 August 5, 2011 HT82A836R 0 0 H 0 1 H 0 2 H 0 3 H 0 4 H 0 5 H 0 6 H 0 7 H 0 8 H 0 9 H 0 A H 0 B H 0 C H 0 D H 0 E H 0 F H 1 0 H 1 1 H 1 2 H 1 3 H 1 4 H 1 5 H 1 6 H 1 7 H 1 8 H 1 9 H 1 A H 1 B H 1 C H 1 D H 1 E H 1 F H 2 0 H 2 1 H 2 2 H 2 3 H 2 4 H 2 5 H 2 6 H 2 7 H 2 8 H 2 9 H 2 A H 2 B H 2 C H 2 D H 2 E H 2 F H 3 0 H 3 1 H 3 2 H 3 3 H 3 4 H 3 5 H 3 6 H 3 7 H 3 8 H 3 9 H 3 A H 3 B H 3 C H 3 D H 3 E H 3 F H 4 0 H 4 1 H 4 2 H 4 3 H 4 4 H 4 5 H 4 6 H 4 7 H 4 8 H 4 9 H 4 A H 4 B H ~ 5 F H 4 0 H 6 0 H F F H B a n k 0 B a n k 1 Data Memory Structure Note: Most of the RAM Data Memory bits can be directly manipulated using the ²SET [m].i² and ²CLR [m].i² instructions with the exception of a few dedicated bits. The RAM Data Memory can also be accessed through the Memory Pointer registers MP0 and MP1. General Purpose Data Memory All microcontroller programs require an area of read/write memory where temporary data can be stored and retrieved for use later. It is this area of RAM memory that is known as General Purpose Data Memory. This area of Data Memory is fully accessible by the user program for both read and write operations. By using the ²SET [m].i² and ²CLR [m].i² instructions individual bits can be set or reset under program control giving the user a large range of flexibility for bit manipulation in the Data Memory. As the General Purpose Data Memory exists in two banks, Bank 0 and Bank1, it is necessary to first ensure that the Bank Pointer is properly set to the correct value before accessing the General Purpose Data Memory. When the Bank Pointer is set to the value 00H, data from Bank 0 will be accessed and when set to the value 01H data from Bank 1 will be accessed. Note that Bank 1 must be accessed indirectly using the Memory Pointer MP1 and the Indirect Addressing Register IAR1. Special Purpose Data Memory This area of Data Memory, is located in Bank 0, where registers, necessary for the correct operation of the microcontroller, are stored. Most of the registers can be read from and written to but some are protected and are read only, the details of which are located under the relevant Special Function Register section. Note that for locations that are unused, any read instruction to these addresses will return the value ²00H². B a n k 0 S p e IA M IA M c ia l R e g is te r R 0 P 0 R 1 P 1 B P A C C P C L T B L P T B L H W D T S S T A T U S IN T C 0 T M R 0 H T M R 0 L T M R 0 C T M R 1 H T M R 1 L T M R 1 C P A P A C P B P B C P C P C C P D P D C P E P E C P F P F C IN T C 1 T B H P U S C U S R U C C A W R S T A L L S IE S M IS C S E T IO F IF O 0 F IF O 1 F IF O 2 F IF O 3 F IF O 4 D A C _ L IM IT _ L D A C _ L IM IT _ H D A C _ W R P G A _ C T R L P F D C P F D D O P E R _ M O D E M O D E _ C T R L S B C R S B D R R E C O R D _ IN _ L R E C O R D _ IN _ H P L A Y P L A Y P L A Y P L A Y R E C O R E C O _ D A T A L _ _ D A T A L _ _ D A T A R _ _ D A T A R _ R D _ D A T A R D _ D A T A A D R L A D R H A D C R A C S R P A _ W A K E _ C T R P W M C P W M 0 P W M 1 M F I1 C U S B _ S T A T E U S V C L H L H _ L _ H L : U n u s e d , re a d a s "0 0 " Special Purpose Data Memory Structure Rev. 1.10 11 August 5, 2011 HT82A836R Special Function Registers pair, IAR0 and MP0 can together only access data from Bank 0, while the IAR1 and MP1 register pair can access data from both Bank 0 and Bank 1. As the Indirect Addressing Registers are not physically implemented, reading the Indirect Addressing Registers indirectly will return a result of ²00H² and writing to the registers indirectly will result in no operation. To ensure successful operation of the microcontroller, certain internal registers are implemented in the Data Memory area. These registers ensure correct operation of internal functions such as timers, interrupts, USB port, etc., as well as external functions such as I/O data control. The location of these registers within the Data Memory begins at the address ²00H². Any unused Data Memory locations between these special function registers and the point where the General Purpose Memory begins is reserved and attempting to read data from these locations will return a value of ²00H². Memory Pointer - MP0, MP1 For all devices, two Memory Pointers, known as MP0 and MP1 are provided. These Memory Pointers are physically implemented in the Data Memory and can be manipulated in the same way as normal registers providing a convenient way with which to address and track data. When any operation to the relevant Indirect Addressing Registers is carried out, the actual address that the microcontroller is directed to, is the address specified by the related Memory Pointer. MP0, together with Indirect Addressing Register, IAR0, are used to access data from Bank 0 only, while MP1 and IAR1 are used to access data from both Bank 0 and Bank 1. Indirect Addressing Register - IAR0, IAR1 The Indirect Addressing Registers, IAR0 and IAR1, although having their locations in normal RAM register space, do not actually physically exist as normal registers. The method of indirect addressing for RAM data manipulation uses these Indirect Addressing Registers and Memory Pointers, in contrast to direct memory addressing, where the actual memory address is specified. Actions on the IAR0 and IAR1 registers will result in no actual read or write operation to these registers but rather to the memory location specified by their corresponding Memory Pointer, MP0 or MP1. Acting as a The following example shows how to clear a section of four RAM locations already defined as locations adres1 to adres4. data .section ¢data¢ adres1 db ? adres2 db ? adres3 db ? adres4 db ? block db ? code .section at 0 ¢code¢ org 00h start: mov mov mov mov a,04h ; setup size of block block,a a,offset adres1 ; Accumulator loaded with first RAM address mp0,a ; setup memory pointer with first RAM address clr inc sdz jmp IAR0 mp0 block loop loop: ; clear the data at address defined by MP0 ; increment memory pointer ; check if last memory location has been cleared continue: The important point to note here is that in the example shown above, no reference is made to specific Data Memory addresses. Rev. 1.10 12 August 5, 2011 HT82A836R Bank Pointer - BP Look-up Table Registers - TBLP, TBLH, TBHP The Data Memory is divided into two Banks, known as Bank 0 and Bank 1. Selecting the required Data Memory area is achieved using the Bank Pointer. If data in Bank 0 is to be accessed, then the BP register must be loaded with the value ²00², while if data in Bank 1 is to be accessed, then the BP register must be loaded with the value ²01². These three special function registers are used to control operation of the look-up table, which is stored in the Program Memory. TBLP is the table low byte pointer and indicates the lowest 8-bit address location where the table data is located. TBHP is the table high byte pointer and indicates the highest bit address location where the table data is located. The TBHP high byte table pointer can only be used if its configuration option is selected. The table pointers must be setup before any table read commands are executed. Their value can be changed, for example using the ²INC² or ²DEC² instructions, allowing for easy table data pointing and reading. If the TBHP configuration is enabled, then the TBLP and TBHP register pair can be used together with the ²TABRDC² instruction to point directly to any location in the program memory. TBLH is the location where the higher order byte of the table data is stored after a table read data instruction has been executed. The lower order table data byte is transferred to a user defined location. Using Memory Pointer MP0 and Indirect Addressing Register IAR0 will always access data from Bank 0, irrespective of the value of the Bank Pointer. The Data Memory is initialised to Bank 0 after a reset, except for the WDT time-out reset in the Power Down Mode, in which case, the Data Memory bank remains unaffected. Directly addressing the Data Memory will always result in Bank 0 being accessed irrespective of the value of the Bank Pointer. Accumulator - ACC The Accumulator is central to the operation of any microcontroller and is closely related with operations carried out by the ALU. The Accumulator is the place where all intermediate results from the ALU are stored. Without the Accumulator it would be necessary to write the result of each calculation or logical operation such as addition, subtraction, shift, etc., to the Data Memory resulting in higher programming and timing overheads. Data transfer operations usually involve the temporary storage function of the Accumulator; for example, when transferring data between one user defined register and another, it is necessary to do this by passing the data through the Accumulator as no direct transfer between two registers is permitted. Watchdog Timer Register - WDTS The Watchdog feature of the microcontroller provides an automatic reset function giving the microcontroller a means of protection against spurious jumps to incorrect Program Memory addresses. To implement this, a timer is provided within the microcontroller which will issue a reset command when its value overflows. To provide variable Watchdog Timer reset times, the Watchdog Timer clock source can be divided by various division ratios, the value of which is set using the WDTS register. By writing directly to this register, the appropriate division ratio for the Watchdog Timer clock source can be setup. Note that only the lower 3 bits are used to set division ratios between 1 and 128. Program Counter Low Register - PCL To provide additional program control functions, the low byte of the Program Counter is made accessible to programmers by locating it within the Special Purpose area of the Data Memory. By manipulating this register, direct jumps to other program locations are easily implemented. Loading a value directly into this PCL register will cause a jump to the specified Program Memory location, however, as the register is only 8-bit wide, only jumps within the current Program Memory page are permitted. When such operations are used, note that a dummy cycle will be inserted. Status Register - STATUS This 8-bit register contains the zero flag (Z), carry flag (C), auxiliary carry flag (AC), overflow flag (OV), power down flag (PDF), and watchdog time-out flag (TO). These arithmetic/logical operation and system management flags are used to record the status and operation of the microcontroller. With the exception of the TO and PDF flags, bits in the status register can be altered by instructions like most other registers. Any data written into the status register will not change the TO or PDF flag. In addition, opera- b 7 b 0 B P 0 B a n k P o in te r B P 0 0 1 D a ta M e m o ry B a n k 0 B a n k 1 N o t u s e d , m u s t b e re s e t to "0 " Bank Pointer Rev. 1.10 13 August 5, 2011 HT82A836R b 7 b 0 T O P D F O V Z A C C S T A T U S R e g is te r A r C a A u Z e ith m e r r y fla x ilia r y r o fla g O v e r flo w g tic /L o g ic O p e r a tio n F la g s c a r r y fla g fla g S y s te m M P o w e r d o w W a tc h d o g N o t im p le m a n n tim e a g e m e n t F la g s fla g e - o u t fla g n te d , re a d a s "0 " Status Register like a global enable/disable and is used to set all of the interrupt enable bits on or off. This bit is cleared when an interrupt routine is entered to disable further interrupt and is set by executing the ²RETI² instruction. Note in situations where other interrupts may require servicing within present interrupt service routines, the EMI bit can be manually set by the program after the present interrupt service routine has been entered. tions related to the status register may give different results due to the different instruction operations. The TO flag can be affected only by a system power-up, a WDT time-out or by executing the ²CLR WDT² or ²HALT² instruction. The PDF flag is affected only by executing the ²HALT² or ²CLR WDT² instruction or during a system power-up. The Z, OV, AC and C flags generally reflect the status of the latest operations. Timer/Event Counter Registers - TMRL/TMRH, TMRC · C is set if an operation results in a carry during an ad- dition operation or if a borrow does not take place during a subtraction operation; otherwise C is cleared. C is also affected by a rotate through carry instruction. The device contains two 16-bit Timer/Event Counters. Each Timer/Event Counter has an associated register pair, known as TMR0L/TMR0H and TMR1L/TMR1H which are the locations where the timer¢s 16-bit value is located. Each timer also has an associated control register, known as TMR0C and TMR1C which contains the setup information for the associated timer. · AC is set if an operation results in a carry out of the low nibbles in addition, or no borrow from the high nibble into the low nibble in subtraction; otherwise AC is cleared. · Z is set if the result of an arithmetic or logical operation Input/Output Ports and Control Registers is zero; otherwise Z is cleared. Within the area of Special Function Registers, the I/O registers and their associated control registers play a prominent role. All I/O ports have a designated register correspondingly labeled as PA, PB, PC, PD, PE and PF. These labeled I/O registers are mapped to specific addresses within the Data Memory as shown in the Data Memory table, which are used to transfer the appropriate output or input data on that port. With each I/O port there is an associated control register labeled PAC, PBC, PCC, PDC, PEC and PFC, also mapped to specific addresses with the Data Memory. The control register specifies which pins of that port are set as inputs and which are set as outputs. To setup a pin as an input, the corresponding bit of the control register must be set high, for an output it must be set low. During program initialization, it is important to first setup the control registers to specify which pins are outputs and which are inputs before reading data from or writing data to the I/O ports. One flexible feature of these registers is the ability to directly program single bits using the ²SET [m].i² and ²CLR [m].i² instructions. The ability to change I/O pins from output to input and vice versa by manipulating specific bits of the I/O control registers during normal program operation is a useful feature of these devices. · OV is set if an operation results in a carry into the high- est-order bit but not a carry out of the highest-order bit, or vice versa; otherwise OV is cleared. · PDF is cleared by a system power-up or executing the ²CLR WDT² instruction. PDF is set by executing the ²HALT² instruction. · TO is cleared by a system power-up or executing the ²CLR WDT² or ²HALT² instruction. TO is set by a WDT time-out. In addition, on entering an interrupt sequence or executing a subroutine call, the status register will not be pushed onto the stack automatically. If the contents of the status registers are important and if the subroutine can corrupt the status register, precautions must be taken to correctly save it. Interrupt Control Registers - INTC0, INTC1, MFI1C These three 8-bit registers, known as the INTC0, INTC1 and MFI1C control the operation of the interrupts. By setting various bits within this register using standard bit manipulation instructions, the enable/disable function of the all interrupts can be independently controlled. A master interrupt bit within this register, the EMI bit, acts Rev. 1.10 14 August 5, 2011 HT82A836R Port A Wake-up Control Register PA_WAKE_CTRL Input/Output Ports Holtek microcontrollers offer considerable flexibility on their I/O ports. With the input or output designation of every pin fully under user program control, pull-high options for all ports and wake-up options on certain pins, the user is provided with an I/O structure to meet the needs of a wide range of application possibilities. This register is used to select the edge type that triggers the wake-up function on the Port A pins. If the configuration options select some or all of the Port A pins to have a wake-up function then this register can be used to select either whether the active edge is a negative or positive transition. Only Port A is allowed this selection. The microcontroller provides a maximum of 44 bidirectional input/output lines labeled with port names PA, PB, PC, PD, PE and PF. These I/O ports are mapped to the Data Memory with addresses as shown in the Special Purpose Data Memory table. Seven of these I/O lines can be used for input and output operations and one line as an input only. For input operation, these ports are non-latching, which means the inputs must be ready at the T2 rising edge of instruction ²MOV A,[m]², where m denotes the port address. For output operation, all the data is latched and remains unchanged until the output latch is rewritten. Pulse Width Modulator Registers - PWM0, PWM1, PWMC The device 2 integrated Pulse Width Modulators. Each one has its own independent register, known as PWM0 and PWM1. The 8-bit contents of each of these registers define the duty cycle value for the modulation cycle of the corresponding pulse width modulator. The PWMC is the control register for the PWM functions and controls the mode selection and on/off function. A/D Converter Registers - ADRL, ADRH, ADCR, ACSR Pull-high Resistors The device contains a single 6-channel 12-bit A/D converter. The correct operation of the A/D requires the use of two data registers, a control register and a clock source register. There are two data registers, a high byte data register known as ADRH, and a low byte data register known as ADRL. These are the register locations where the digital value is placed after the completion of an analog to digital conversion cycle. The channel selection and configuration of the A/D converter is setup via the control register ADCR while the A/D clock frequency is defined by the clock source register, ACSR. Many product applications require pull-high resistors for their switch inputs usually requiring the use of an external resistor. To eliminate the need for these external resistors, all I/O pins, when configured as an input have the capability of being connected to an internal pull-high resistor. These pull-high resistors are selectable via configuration options and are implemented using a weak PMOS transistor. Port A Wake-up If the HALT instruction is executed, the device will enter the Power Down Mode, where the system clock will stop resulting in power being conserved, a feature that is important for battery and other low-power applications. Various methods exist to wake-up the microcontroller, one of which is a logical transition on one of the Port A~Port F pins from high to low. After a HALT instruction forces the microcontroller into entering the Power Down Mode, the device will remain idle or in a low-power state until the logic condition of the selected wake-up pin on Port A~Port F changes from high to low. This function is especially suitable for applications that can be woken up via external switches. Note that each pin on Port A~Port F can be selected individually using configuration options to have this wake-up feature. Additionally Port A pins have an additional selection allowing their wake-up function to be either negative or positive edge triggered. This option is provided using the PA_WAKE_CTRL register. Only Port A pins have this feature, the wake-up pins on the other ports are only negative edge triggered. USB Registers The device contains an internal USB port which is controlled via several registers. These are used to setup the USB operation, the external pins, error handling etc. As this register list is too numerous to list here details can be found in the relevant USB description. PFD Registers - PFDC, PFDD The device contains a fully integrated Programmable Frequency Driver otherwise known as the PFD. Two registers control the overall operation of the PFD to determine the output frequency and the function enable/disable. Other Registers The device contains several other special function registers for control of various internal functions. As their functional description is too detailed to be described here their details will be provided in the relevant functional description section. Rev. 1.10 15 August 5, 2011 HT82A836R b 7 P A .7 P A .6 P A .5 P A .4 P A .3 P A .2 P A .1 b 0 P A .0 P o rt A P A .0 P A .1 P A .2 P A .3 P A .4 P A .5 P A .6 P A .7 P A .x 1 0 W a k e -u p w a k w a k w a k w a k w a k w a k w a k w a k e -u e -u e -u e -u e -u e -u e -u e -u p e d p e d p e d p e d p e d p e d p e d p e d g e g e g e g e g e g e g e g e A c tiv e e d g e lo w to h ig h h ig h to lo w Port A Wake-up I/O Port Control Registers · External Timer/Event Counter Input Each I/O port has its own control register PAC, PBC, PCC, PDC, PEC and PFC, to control the input/output configuration. With this control register, each CMOS output or input with or without pull-high resistor structures can be reconfigured dynamically under software control. Each of the I/O ports is directly mapped to a bit in its associated port control register. The external timer pins TMR0/TMR1 are pin-shared with the I/O pins PC1/PC2. If these shared pins are to be used as a Timer/Event Counter inputs, then the Timer/Event Counter must be configured to be in the Event Counter or Pulse Width Measurement Mode. This is achieved by setting the appropriate bits in the relevant timer/Event Counter Control Register. The pin must also be setup as an input by setting the appropriate bit in the Port Control Register Pull-high resistor options can also be selected via the appropriate port pull-high configuration option. If the shared pin is to be used as a normal I/O pin, then the external timer input function must be disabled, by ensuring that the corresponding Timer/Event Counter is configured to be in the Off Mode or Timer Mode. For the I/O pin to function as an input, the corresponding bit of the control register must be written as a ²1². This will then allow the logic state of the input pin to be directly read by instructions. When the corresponding bit of the control register is written as a ²0², the I/O pin will be setup as a CMOS output. If the pin is currently setup as an output, instructions can still be used to read the output register. However, it should be noted that the program will in fact only read the status of the output data latch and not the actual logic status of the output pin. · PFD Output The device contains a PFD function whose single output is pin-shared with PC0. The output function of this pin is chosen via software. Note that the corresponding bit of the port control register, PCC.0, must setup the pin as an output to enable the PFD output. If the PCC port control register has setup the pin as an input, then the pin will function as a normal logic input with the usual pull-high option, even if the PFD configuration option has been selected. Pin-shared Functions The flexibility of the microcontroller range is greatly enhanced by the use of pins that have more than one function. Limited numbers of pins can force serious design constraints on designers but by supplying pins with multi-functions, many of these difficulties can be overcome. For some pins, the chosen function of the multi-function I/O pins is set by configuration options while for others the function is set by application program control. · SPI Interface The device contains an internal SPI interface whose pins are shared with I/O pins PC4~PC7. The SPI Interface control register, SBCR, is used to determine if these pins are to be used as normal I/O pins or as SPI Interface pins. · Serial Interface The serial interface pins SDO, SDI, SCS and SCK are pin-shared with the I/O pins PC4, PC5, PC6 and PC7. For applications not requiring serial interface, the pin-shared pins can be used as a normal I/O pin. I/O Pin Structures The following diagrams illustrate the I/O pin internal structures. As the exact logical construction of the I/O pin may differ from these drawings, they are supplied as a guide only to assist with the functional understanding of the I/O pins. · External Interrupt The external interrupt pin INT is pin-shared with the I/O pin PE7. For applications not requiring an external interrupt input, the pin-shared external interrupt pin can be used as a normal I/O pin, however to do this, the external interrupt enable bits in the MFI1C register must be disabled. Rev. 1.10 16 August 5, 2011 HT82A836R P u ll- H ig h O p tio n C o n tr o l B it Q D D a ta B u s W r ite C o n tr o l R e g is te r V P A 0 P B 0 P C 0 P C 1 P C 2 P C 3 P C 4 P C 5 P C 6 P C 7 P D 0 P E 0 P E 7 P F 0 Q C K S C h ip R e s e t R e a d C o n tr o l R e g is te r D a ta B it Q D W r ite D a ta R e g is te r C K S Q M R e a d D a ta R e g is te r S y s te m D D U ~ P A ~ P B /B Z /T M /T M /S D /S D /S C /S C ~ P D ~ P E /IN T ~ P F 7 7 R 0 R 1 O I S K 6 7 3 X W a k e - u p ( P A o n ly ) C o n fig u r a tio n O p tio n B Z fo r P C 0 T M R 0 fo r P C 1 T M R 1 fo r P C 2 P C 3 S D O fo r P C 4 S D I fo r P C 5 S C S fo r P C 6 S C K fo r P C 7 Input/Output Ports Programming Considerations Timer/Event Counters Within the user program, one of the first things to consider is port initialisation. After a reset, all of the data and port control register will be set high. This means that all I/O pins will default to an input state, the level of which depends on the other connected circuitry and whether pull-high options have been selected. If the PAC, PBC, PCC, PDC, PEC and PFC port control registers, are then programmed to setup some pins as outputs, these output pins will have an initial high output value unless the associated PA, PB, PC, PD, PE and PF port data registers are first programmed. Selecting which pins are inputs and which are outputs can be achieved byte-wide by loading the correct value into the port control register or by programming individual bits in the port control register using the ²SET [m].i² and ²CLR [m].i² instructions. Note that when using these bit control instructions, a read-modify-write operation takes place. The microcontroller must first read in the data on the entire port, modify it to the required new bit values and then rewrite this data back to the output ports. T 1 S y s te m T 2 T 3 T 4 T 1 T 2 T 3 The provision of timers form an important part of any microcontroller giving the designer a means of carrying out time related functions. The device contains two internal 16-bit count-up timers each of which has three operating modes. The timer can be configured to operate as a general timer, external event counter or as a pulse width measurement device. There are three registers related to each of the Timer/Event Counters, these are a pair or timer registers and a control register. The register pairs TMR0L/ TMR0H and TMR1L/TMR1H contain the 16-bit timing value. Writing to these register pairs places an initial starting value in the Timer/Event Counter preload registers while reading them retrieves the contents of the Timer/Event Counter. The TMR0C and TMR1C registers are the Timer/Event Counter control registers, which define the timer options, and determines how the timers are to be used. The timer clock source can be configured to come from the internal system clock source or from an external clock on shared pin PC1/TMR0 and PC2/TMR1. T 4 C lo c k P o rt D a ta W r ite to P o r t R e a d fro m P o rt Read/Write Timing Rev. 1.10 17 August 5, 2011 HT82A836R D a ta B u s L o w B y te B u ffe r T 0 M 1 fS Y S /4 1 6 - B it P r e lo a d R e g is te r T 0 M 0 T im e r /E v e n t C o u n te r M o d e C o n tro l T M R 0 H ig h B y te T 0 O N R e lo a d O v e r flo w to In te rru p t L o w B y te 1 6 - B it T im e r /E v e n t C o u n te r T 0 E Timer/Event Counter 0 Structure D a ta B u s L o w B y te B u ffe r T 1 M 1 fS Y S /4 1 6 - B it P r e lo a d R e g is te r T 1 M 0 T im e r /E v e n t C o u n te r M o d e C o n tro l T M R 1 H ig h B y te T 1 O N L o w B y te 1 6 - B it T im e r /E v e n t C o u n te r R e lo a d O v e r flo w to In te rru p t T 1 E Timer/Event Counter 1 Structure Timer Registers - TMR0H/TMR0L, TMR1L/TMR1H Configuring the Timer/Event Counter Input Clock Source The timer register are special function registers located in the Special Purpose Data Memory and is the place where the actual timer values are stored. These registers exist in pairs and are known as TMR0L/TMR0H and TMR1L/TMR1H. The value in these timer registers increases by one each time an internal clock pulse is received or an external transition occurs on the external timer pin. The timer will count from the initial value loaded by the preload register to the full count of FFFFH at which point the timer overflows and an internal interrupt signal is generated. The timer value will then be re- The Timer/Event Counter¢s clock can originate from various sources. The system clock source is used when the Timer/Event Counter is in the timer mode or in the pulse width measurement mode. An external clock source is used when the Timer/Event Counter is in the event counting mode, the clock source being provided on the external timer pin, TMR0 or TMR1. Depending upon the condition of the T0E or T1E bit, each high to low, or low to high transition on the external timer pin will increment the counter by one. Rev. 1.10 18 August 5, 2011 HT82A836R Timer Control Register - TMR0C, TMR1C set with the initial preload register value and continue counting. To achieve a maximum full range count of FFFFH the preload register must first be cleared to all zeros. It should be noted that after power-on, the preload register will be in an unknown condition. Note that if the Timer/Event Counter is switched off and data is written to its preload register, this data will be immediately written into the actual timer register. However, if the Timer/Event Counter is enabled and counting, any new data written into the preload data register during this period will remain in the preload register and will only be written into the timer register the next time an overflow occurs. The flexible features of the Holtek microcontroller Timer/Event Counters enable them to operate in three different modes, the options of which are determined by the contents of their control register, which has the name TMR0C and TMR1C. It is the Timer Control Register together with their corresponding timer register pair that control the full operation of the Timer/Event Counter. Before the Timer/Event Counter can be used, it is essential that the Timer Control Register pair is fully programmed with the right data to ensure its correct operation, a process that is normally carried out during program initialisation. To choose which of the three modes the Timer/Event Counter is to operate in, either in the timer mode, the event counting mode or the pulse width measurement mode, bits 7 and 6 of the Timer Control Register, which are known as the bit pair TM1/TM0, must be set to the required logic levels. The Timer/Event Counter on/off bit, which is bit 4 of the Timer Control Register and known as TON, provides the basic on/off control of the Timer/Event Counter. Setting the bit high allows the Timer/Event Counter to run, clearing the bit stops it running. If the Timer/Event Counter is in the event count or pulse width measurement mode, the active transition edge level type is selected by the logic level of bit 3 of the Timer control Register which is known as TE. Note that writing data to the lower byte 8-bit registers, TMR0L/TMR1L, will only put the written data into an internal lower-order byte 8-bit buffer, while writing to the high byte 8-bit registers, TMR0H/TMR1H will transfer the specified data and the contents of the lower-order byte buffer into both the TMR0/1H and TMR0/1L registers. The Timer/Event Counter preload register is modified by writing to the TMR0/1H registers. Reading the TMR0H/TMR1H registers will latch the contents of both the TMR0H/TMR1H and the TMR0L/TMR1L counters to the destination and the lower-order byte buffer. However reading the TMR0L/TMR1L will only read the contents of the low byte buffer. b 7 T M 1 b 0 T M 0 T O N T E T M R 0 C /T M R 1 C R e g is te r N o t im p le m e n te d , r e a d a s " 0 " E v e n t C 1 : c o u n 0 : c o u n P u ls e W 1 : s ta rt 0 : s ta rt o u n te r A c tiv e E d g t o n fa llin g e d g e t o n r is in g e d g e id th M e a s u r e m e n c o u n tin g o n r is in g c o u n tin g o n fa llin g e S e le c t t A c tiv e E d g e S e le c t e d g e , s to p o n fa llin g e d g e e d g e , s to p o n r is in g e d g e T im e r /E v e n t C o u n te r C o u n tin g E n a b le 1 : e n a b le 0 : d is a b le N o t im p le m e n te d , r e a d a s " 0 " O p e r a tin g M o d e S e T M 1 T M 0 0 n o 0 0 e v 1 1 tim 0 1 p u 1 le c t m o d e n t c e r m ls e w e a v a ila b le o u n te r m o d e o d e id th m e a s u r e m e n t m o d e Timer/Event Counter 0/1 Control Register Rev. 1.10 19 August 5, 2011 HT82A836R As the external timer pin is shared with an I/O pin, to ensure that the pin is configured to operate as an event counter input pin, two things have to happen. The first is to ensure that the Operating Mode Select bits in the Timer Control Register place the Timer/Event Counter in the Event Counting Mode, the second is to ensure that the port control register configures the pin as an input. It should be noted that in the event counting mode, even if the microcontroller is in the Power Down Mode, the Timer/Event Counter will continue to record externally changing logic events on the timer input pin. As a result when the timer overflows it will generate a timer interrupt and corresponding wake-up source. Configuring the Timer Mode In this mode, the timer can be utilised to measure fixed time intervals, providing an internal interrupt signal each time the counter overflows. To operate in this mode, bits TM1 and TM0 of the TMRC register must be set to 1 and 0 respectively. In this mode, the internal clock is used as the timer clock. The input clock frequency to the timer is fSYS/4. The timer-on bit, TON, must be set high to enable the timer to run. Each time an internal clock high to low transition occurs, the timer increments by one. When the timer is full and overflows, the timer will be reset to the value already loaded into the preload register and continue counting. If the timer interrupt is enabled, an interrupt signal will also be generated. The interrupt can be disabled by ensuring that the Timer/Event Counter Interrupt Enable bit in the Interrupt Control Register, INTC0, is reset to zero. Configuring the Pulse Width Measurement Mode In this mode, the Timer/Event Counter can be utilised to measure the width of external pulses applied to the external timer pin. To operate in this mode, the Operating Mode Select bit pair in the Timer Control Register must be set to the correct value. In this mode the internal clock, fSYS/4, is used as the Timer/Event Counter clock. After the other bits in the Timer Control Register have been setup, the enable bit, which is bit 4 of the Timer Control Register, can be set high to enable the Timer/Event Counter, however it will not actually start counting until an active edge is received on the external timer pin. Configuring the Event Counter Mode In this mode, a number of externally changing logic events, occurring on the external timer pin, can be recorded by the Timer/Event Counter. To operate in this mode, the Operating Mode Select bit pair in the Timer Control Register must be set to the correct value. In this mode the external timer pin is used as the Timer/Event Counter clock source. After the other bits in the Timer Control Register have been setup, the enable bit, which is bit 4 of the Timer Control Register, can be set high to enable the Timer/Event Counter to run. If the Active Edge Select bit, which is bit 3 of the Timer Control Register, is low, the Timer/Event Counter will increment each time the external timer pin receives a low to high transition. If the Active Edge Select bit is high, the counter will increment each time the external timer pin receives a high to low transition. When it is full and overflows, an interrupt signal is generated and the Timer/Event Counter will reload the value already loaded into the preload register and continue counting. The interrupt can be disabled by ensuring that the Timer/Event Counter Interrupt Enable bit in the Interrupt Control Register, INTC0, is reset to zero. If the Active Edge Select bit, which is bit 3 of the Timer Control Register, is low, once a high to low transition has been received on the external timer pin, the Timer/Event Counter will start counting until the external timer pin returns to its original high level. At this point the enable bit will be automatically reset to zero and the Timer/Event Counter will stop counting. If the Active Edge Select bit is high, the Timer/Event Counter will begin counting once a low to high transition has been received on the external timer pin and stop counting when the external timer pin returns to its original low level. As before, the enable bit will be automatically reset to zero and the Timer/Event Counter will stop counting. It is important to note that in the Pulse Width Measurement Mode, the P r e s c a le r O u tp u t In c re m e n t T im e r C o n tr o lle r T im e r + 1 T im e r + 2 T im e r + N T im e r + N + 1 Timer Mode Timing Chart E x te r n a l T im e r P in In p u t T E = 1 In c re m e n t T im e r C o u n te r T im e r + 1 T im e r + 2 T im e r + 3 Event Counter Mode Timing Chart Rev. 1.10 20 August 5, 2011 HT82A836R pin is setup as an input. Any pull-high configuration for this pins will remain valid even if the pin is used as a Timer/Event Counter input. enable bit is automatically reset to zero when the external control signal on the external timer pin returns to its original level, whereas in the other two modes the enable bit can only be reset to zero under program control. The residual value in the Timer/Event Counter, which can now be read by the program, therefore represents the length of the pulse received on the external timer pin. As the enable bit has now been reset, any further transitions on the external timer pin will be ignored. Not until the enable bit is again set high by the program can the timer begin further pulse width measurements. In this way, single shot pulse measurements can be easily made. Programming Considerations When configured to run in the timer mode, the fSYS/4 is used as the timer clock source and is therefore synchronised with the overall operation of the microcontroller. In this mode, when the appropriate timer register is full, the microcontroller will generate an internal interrupt signal directing the program flow to the respective internal interrupt vector. For the pulse width measurement mode, the fSYS/4 clock is also used as the timer clock source but the timer will only run when the correct logic condition appears on the external timer input pin. As this is an external event and not synchronized with the internal timer clock, the microcontroller will only see this external event when the next timer clock pulse arrives. As a result there may be small differences in measured values requiring programmers to take this into account during programming. The same applies if the timer is configured to be in the event counting mode which again is an external event and not synchronised with the fSYS/4 clock. It should be noted that in this mode the Timer/Event Counter is controlled by logical transitions on the external timer pin and not by the logic level. When the Timer/Event Counter is full and overflows, an interrupt signal is generated and the Timer/Event Counter will reload the value already loaded into the preload register and continue counting. The interrupt can be disabled by ensuring that the Timer/Event Counter Interrupt Enable bit in the Interrupt Control Register, INTC0, is reset to zero. As the external timer pin is shared with an I/O pin, to ensure that the pin is configured to operate as a pulse width measurement pin, two things have to happen. The first is to ensure that the Operating Mode Select bits in the Timer Control Register place the Timer/Event Counter in the Pulse Width Measurement Mode, the second is to ensure that the port control register configures the pin as an input. When the Timer/Event Counter is read or if data is written to the preload registers, the clock is inhibited to avoid errors, however as this may result in a counting error, this should be taken into account by the programmer. Care must be taken to ensure that the timers are properly initialised before using them for the first time. The associated timer enable bits in the interrupt control register must be properly set otherwise the internal interrupt associated with the timer will remain inactive. The edge select, timer mode and clock source control bits in timer control register must also be correctly set to ensure the timer is properly configured for the required application. It is also important to ensure that an initial value is first loaded into the timer register before the timer is switched on; this is because after power-on the initial value of the timer register is unknown. After the timer has been initialised the timer can be turned on and off by controlling the enable bit in the timer control register. Note that setting the timer enable bit high to turn the timer on, should only be executed after the timer mode I/O Interfacing The Timer/Event Counter, when configured to run in the event counter or pulse width measurement mode, requires the use of an external pin for correct operation. As the external timer pin is pin-shared with an I/O pin, it must be configured correctly to ensure it is setup for use as a Timer/Event Counter input and not as a normal I/O pin. This is implemented by ensuring that the mode select bits in the Timer/Event Counter control register, select either the event counter or pulse width measurement mode. Additionally the Port Control Register bit for this pin must be set high to ensure that the E x te r n a l T im e r P in In p u t T O N ( w ith T E = 0 ) T im e r C lo c k In c re m e n t T im e r C o u n te r T im e r + 1 + 2 + 3 + 4 T im e r C lo c k is s a m p le d a t e v e r y fa llin g e d g e o f T 1 . Pulse Width Measure Mode Timing Chart Rev. 1.10 21 August 5, 2011 HT82A836R bits have been properly setup. Setting the timer enable bit high together with a mode bit modification, may lead to improper timer operation if executed as a single timer control register byte write instruction. When the Timer/Event counter overflows, its corresponding interrupt request flag in the interrupt control register will be set. If the timer interrupt is enabled this will in turn generate an interrupt signal. However irrespective of whether the timer interrupt is enabled or not, a Timer/Event counter overflow will also generate a wake-up signal if the device is in a Power-down condition. This situation may occur if the Timer/Event Counter is in the Event Counting Mode and if the external signal continues to change state. In such a case, the Timer/Event Counter will continue to count these external events and if an overflow occurs the device will be woken up from its Power-down condition. To prevent such a wake-up from occurring, the timer interrupt request flag should first be set high before issuing the HALT instruction to enter the Power Down Mode. Timer Program Example This program example shows how the Timer/Event Counter registers are setup, along with how the interrupts are enabled and managed. Note how the Timer/Event Counter is turned on, by setting bit 4 of the Timer Control Register. The Timer/Event Counter can be turned off in a similar way by clearing the same bit. This example program sets the Timer/Event Counter to be in the timer mode, which uses the internal system clock as the clock source. org 04h ; usb interrupt vector jmp usbint reti org 08h ; Timer/Event Counter 0 interrupt vector jmp tmr0int ; jump here when Timer 0 overflows : org 20h ; main program ;internal Timer/Event Counter interrupt routine tmr0int: : ; Timer/Event Counter 0 main program placed here : reti : : begin: ;setup Timer 0 registers mov a,09bh ; setup preload value - timer0 counts from this value to FFFFH mov tmr0l,a; mov a,00h mov tmr0h,a; mov a,080h ; setup Timer 0 control register mov tmr0c,a ; timer mode ; setup interrupt register mov a,005h ; enable master interrupt and timer interrupt mov intc0,a set tmr0c.4 ; start Timer 0 - note mode bits must be previously setup Rev. 1.10 22 August 5, 2011 HT82A836R Programmable Frequency Divider - PFD The Programmable Frequency Divider function, PFD, allows the generation of a user defined frequency. The clock source for the PFD is the system clock divided by 4, which after being divided by 16 is then passed through a programmable prescaler and the PFDD register allows a range of user defined frequencies to be generated. to be used as a PFD output. The PFDEN bit is used to control the overall on/off function of the PFD, while bits PRES0 and PRES1 are used to select the frequency division ratio of the prescaler. The PFDD register provided further division of the clock source, however this register can only be written to when the PFD function is enabled. If the PFD function is disabled, then all write operations to the PFDD register will be inhibited. When the PFD is disabled note that the PFDD register will be automatically cleared. The PFDD contents, the PFD must be enabled. When the generator is disabled, the PFDD is cleared by hardware. Overall operation of the PFD is controlled using two registers, the PFDC register and the PFDD register. As the PFD output pin is pin-shared with I/O pin PC0, the PFD_IO bit in the PFDC register is used to select whether the pin is to be used an a normal I/O function or fS Y S /4 4 - S ta g e P r e s c a le r (1 /1 6 ) P F D F re q u e n c y P r e s c a le r O u tp u t P r e s c a le r P F D O u tp u t P F D D P F D E N P R E S 1 , P R E S 0 PFD Block Diagram b 7 b 0 P R E S 1 P R E S 0 P F D E N P F D _ IO S E L W P F D C R e g is te r P o w e r A m p lifie r in p u t s o u r c e 1 : M U S C I_ IN s o u rc e 0 : U S B A u d io d a ta s o u r c e P C 0 /P F D p in fu n c tio n c o n tr o l 1 : P F D o u tp u t 0 : P C 0 I/O p in N o t im p le m e n te d , r e a d a s " 0 " P F D e n a b le c o n tr o l 1 : e n a b le 0 : d is a b le P r e s c a le r c o n tr o l P R E S 1 P R E S 0 0 0 0 1 1 0 1 1 D iv is io ¸ ¸ ¸ ¸ n R a tio 1 2 4 8 N o t im p le m e n te d , r e a d a s " 0 " PFDC Register The generated frequency of the PFD function is given by the following formula: P F D o u tp u t fre q u e n c y = P r e s c a le r O u tp u t , w h e r e N = th e v a lu e o f th e P F D d a ta 2 x (N + 1 ) Power Amplifier The SELW bit in the PFDC register is used to control the power amplifier input source. The software should set SELW = ²1² when the power amplifier signal come from MUSIC_IN, otherwise the speaker output USB Audio data. 1 6 - b it D /A O u tp u t S E L W = 0 S E L W = 1 M U X P o w e r A m p L O U T R O U T M U S IC _ IN Rev. 1.10 23 August 5, 2011 HT82A836R Interrupts continue with normal execution at the point where the interrupt occurred. The various interrupt enable bits, together with their associated request flags, are shown in the following diagram with their order of priority. Once an interrupt subroutine is serviced, all the other interrupts will be blocked, as the EMI bit will be cleared automatically. This will prevent any further interrupt nesting from occurring. However, if other interrupt requests occur during this interval, although the interrupt will not be immediately serviced, the request flag will still be recorded. If an interrupt requires immediate servicing while the program is already in another interrupt service routine, the EMI bit should be set after entering the routine, to allow interrupt nesting. If the stack is full, the interrupt request will not be acknowledged, even if the related interrupt is enabled, until the Stack Pointer is decremented. If immediate service is desired, the stack must be prevented from becoming full. Interrupts are an important part of any microcontroller system. When a USB Interrupt, play/record data valid interrupt, a Timer/Event Counter overflow, reception of SPI data, A/D Interrupt or External Interrupt is occurs, their corresponding interrupt will enforce a temporary suspension of the main program allowing the microcontroller to direct attention to their respective needs. The device provides a USB interrupt, two internal timer/event counter interrupts, a play/record data valid interrupt and a Multi function interrupt. This latter Multi-function Interrupt represents the Serial Interface Interrupt, A/D Interrupt or the External Interrupt. Interrupt Registers Overall interrupt control, which means interrupt enabling and request flag setting, is controlled by three interrupt control registers INTC0, INTC1 and MFI1C which are located in the Data Memory. By controlling the appropriate enable bits in this register each individual interrupt can be enabled or disabled. Also when an interrupt occurs, the corresponding request flag will be set by the microcontroller. The global enable flag if cleared to zero will disable all interrupts. Interrupt Priority Interrupts, occurring in the interval between the rising edges of two consecutive T2 pulses, will be serviced on the latter of the two T2 pulses, if the corresponding interrupts are enabled. In case of simultaneous requests, the following table shows the priority that is applied. These can be masked by resetting the EMI bit. Interrupt Operation A USB interrupt, a Play or Record data valid interrupt, a Timer/Event Counter overflow, an SPI interrupt, an A/D conversion complete interrupt or an active edge on the external interrupt pin will all generate an interrupt request by setting their corresponding request flag, if their appropriate interrupt enable bit is set. When this happens, the Program Counter, which stores the address of the next instruction to be executed, will be transferred onto the stack. The Program Counter will then be loaded with a new address which will be the value of the corresponding interrupt vector. The microcontroller will then fetch its next instruction from this interrupt vector. The instruction at this vector will usually be a JMP statement which will jump to another section of program which is known as the interrupt service routine. Here is located the code to control the appropriate interrupt. The interrupt service routine must be terminated with a RETI statement, which retrieves the original Program Counter address from the stack and allows the microcontroller to Rev. 1.10 No. Interrupt Source Priority Vector a USB Interrupt 1 04H b Timer/Event Counter 0 overflow 2 08H c Timer/Event Counter 1 overflow 3 0CH d Play Interrupt 4 10H e Multi function 1 interrupt subroutine:Serial Interface Interrupt, A/D Interrupt, External Interrupt 5 14H f Record Interrupt 6 18H In cases where both USB and Play interrupts are enabled and where an USB and Play interrupt occurs simultaneously, the USB interrupt will always have priority and will therefore be serviced first. Suitable masking of the individual interrupts using the interrupt registers can prevent simultaneous occurrences. 24 August 5, 2011 HT82A836R b 7 b 0 T 1 F T 0 F E IF E T 1 I E T 0 I E E I E M I IN T C 0 R e g is te r C o n tr o ls th e m a s te r ( g lo b a l) in te r r u p t 1 : e n a b le 0 : d is a b le C o n tr o l th e U S B in te r r u p t 1 : e n a b le 0 : d is a b le C o n tr o ls th e T im e r /E v e n t C o u n te r 0 in te r r u p t 1 : e n a b le 0 : d is a b le C o n tr o ls th e T im e r /E v e n t C o u n te r 1 in te r r u p t 1 : e n a b le 0 : d is a b le U S B in te r r u p t r e q u e s t fla g 1 : a c tiv e 0 : in a c tiv e In te r n a l T im e r /E v e n t C o u n te r 0 r e q u e s t fla g 1 : a c tiv e 0 : in a c tiv e In te r n a l T im e r /E v e n t C o u n te r 1 r e q u e s t fla g 1 : a c tiv e 0 : in a c tiv e N o t im p le m e n te d , r e a d a s " 0 " INTC0 Register b 7 b 0 R E C F M F F 1 P L A Y F P L A Y F E M F 1 I E P L A Y I IN T C 1 R e g is te r P la y in te r r u p t 1 : e n a b le 0 : d is a b le C o n tr o l th e M u lti- fu n c tio n 1 in te r r u p t 1 : e n a b le 0 : d is a b le R e c o r d in te r r u p t 1 : e n a b le 0 : d is a b le N o t im p le m e n te d , r e a d a s " 0 " P la y in te r r u p t r e q u e s t fla g 1 : a c tiv e 0 : in a c tiv e M u lti- fu n c tio n in te r r u p t r e q u e s t fla g 1 : a c tiv e 0 : in a c tiv e R e c o r d in te r r u p t r e q u e s t fla g 1 : a c tiv e 0 : in a c tiv e N o t im p le m e n te d , r e a d a s " 0 " INTC1 Register Rev. 1.10 25 August 5, 2011 HT82A836R A u to m a tic a lly C le a r e d b y IS R e x c e p t fo r S IF , A D F a n d E IF M a n u a lly S e t o r C le a r e d b y S o ftw a r e A u to m a tic a lly D is a b le d b y IS R C a n b e E n a b le d M a n u a lly P r io r ity U S B In te rru p t R e q u e s t F la g U S B F E U I T im e r /E v e n t C o u n te r In te r r u p t R e q u e s t F la g T 0 F E T 0 I T im e r /E v e n t C o u n te r In te r r u p t R e q u e s t F la g T 1 F E T 1 I E M I P la y In te r r u p t R e q u e s t F la g P L A Y F E P L A Y I M u lti F u n c tio n In te r r u p t R e q u e s t F la g M F F 1 E M F 1 I R e c o rd In te rru p t R e q u e s t F la g R E C F R E C I S e r ia l In te r fa c e In te r r u p t R e q u e s t F la g S IF E S II A /D C o n v e rte r In te rru p t R e q u e s t F la g A D F E A D I E x te rn a l In te rru p t R e q u e s t F la g E IF E E I H ig h In te rru p t P o llin g L o w Interrupt Structure USB Interrupt Timer/Event Counter Interrupt The USB interrupt will be triggered by any of the following USB events resulting in the related interrupt request flag, USBF; bit 4 of INTC0, being set: For a Timer/Event Counter interrupt to occur, the global interrupt enable bit, EMI, and the corresponding timer interrupt enable bit, ET0I or ET1I, must first be set. An actual Timer/Event Counter interrupt will take place when the Timer/Event Counter request flag, T0F or T1F, is set, a situation that will occur when the relevant Timer/Event Counter overflows. When the interrupt is enabled, the stack is not full and a Timer/Event Counter 0 overflow occurs, a subroutine call to the timer 0 interrupt vector at location 08H, will take place. If a Timer/Event Counter 1 overflow occurs, a subroutine call to the timer 1 interrupt vector at location 0CH will take place. When the interrupt is serviced, the timer interrupt request flag, T0F or T1F, will be automatically reset and the EMI bit will be automatically cleared to disable other interrupts. · A PC access of the corresponding USB FIFO · A USB suspend signal from the PC · A USB resume signal from the PC · A USB Reset signal When the interrupt is enabled, the stack is not full and the interrupt is active, a subroutine call to location 04H will occur. The interrupt request flag, USBF, and EMI bits will be cleared to disable other interrupts. When the PC Host accesses the HT82A836R FIFO, the corresponding USR request bit is set, and a USB interrupt is triggered. In this way the user can determine which FIFO has been accessed. When the interrupt has been serviced, the corresponding bit will be automatically cleared. When the HT82A836R receives a USB Suspend signal from the host PC, the suspend line, bit0 of the USC register, in the HT82A836R is set and a USB interrupt is also triggered. Also when the device receives a Resume signal from the host PC, the resume line, bit3 of the USC register, is set and a USB interrupt generated. Rev. 1.10 Play Interrupt For a Play Interrupt to occur, the global interrupt enable bit, , and the corresponding Play Interrupt bit, EPLAI, must first be set. An actual Play Interrupt will take place when the Play Interrupt request flag, PLAYF, is set, a situation that will occur at a regular play frequency of 8kHz if the PLAY_MODE bit in the MODE_CTRL register is 26 August 5, 2011 HT82A836R External Interrupt set high. If this bit is not high, then the play interrupt frequency will be 48kHz. When the interrupt is enabled, the stack is not full and a Play Interrupt occurs, a subroutine call to the Play Interrupt vector at location 10H, will take place. When the interrupt is serviced, the Play Interrupt request flag, PLAYF, will be automatically reset and the EMI bit will be automatically cleared to disable other interrupts. The device contains an external interrupt function controlled by the external pin INT. For an external interrupt to occur, the pin must be setup as an interrupt input pin by ensuring that the corresponding external interrupt enable bit is first set. This is bit 2 in the MFI1C register and known as EEI. An external interrupt is triggered by a negative edge transition on the external interrupt pin INT, after which the related interrupt request flag, EIF, which is bit 6 in the MFI1C register, will be set. The interrupt vector for the External Interrupt is the Multi-function interrupt located at 014H. Therefore if the Multi-function and External Interrupts are enabled, the stack is not full and a negative logical transition occurs on pin INT, a subroutine call to location 014H will take place. The Multi-function Interrupt request flag MFF1 will be reset automatically and the EMI bit will be cleared to disable other interrupts. The External Interrupt flag will not be reset automatically and needs to be reset manually by the application program. The external interrupt pin INT is pin-shared with I/O pin PE7 and can only be configured as external interrupt pins if the interrupt is enabled and if the pin is programmed as an input pins. Multi Function Interrupt An additional interrupt known as the Multi-function interrupt is provided. Unlike the other interrupts, this interrupt has no independent source, but rather is formed from three other existing interrupt sources, namely the Serial Interface interrupt, the A/D Converter interrupt and the External interrupt. The Multi-function interrupt is enabled by setting the EMF1I bit, which is bit 1 of the INTC1 register. An actual Multi-function interrupt will be initialised when the Multi-function interrupt request flag MFF1 is set, this is bit 5 of the INTC1 register. When the master interrupt global bit is set, the stack is not full and the corresponding EMF1I interrupt enable bit is set, a Multi-Function internal interrupt will be generated when either a Serial Interface Interrupt, an A/D Converter Interrupt or an External Interrupt occurs. This will create a subroutine call to its corresponding vector location 014H. When a Multi-function internal interrupt occurs, the Multi-Function request flag MFF1 will be reset and the EMI bit will be cleared to disable other interrupts. However, it must be noted that the request flags from the original source of the Multi-function interrupt, namely the Serial Interface Interrupt, the A/D Converter or the External Interrupt will not be automatically reset and must be manually reset by the user. b 7 A/D Converter Interrupt The device contains an internal A/D converter with its own interrupt function. For an A/D Interrupt to occur, the corresponding A/D Interrupt enable bit must be first set. This is bit 1 in the MFI1C register and known as EADI. An A/D Interrupt is generated when the A/D conversion process is complete, after which the related interrupt request flag, ADF, which is bit 5 in the MFI1C register, will be set. The interrupt vector for the A/D Interrupt is the Multi-function interrupt located at 014H. Therefore if the Multi-function and A/D Interrupt are enabled, the stack is b 0 E IF A D F S IF E E I E A D I E S II M F I1 C R e g is te r C o n tr o l S e r ia l in te r fa c e in te r r u p t 1 : e n a b le 0 : d is a b le C o n tr o l th e A /D C o n v e r te r in te r r u p t 1 : e n a b le 0 : d is a b le C o n tr o l th e e x te r n a l in te r r u p t 1 : e n a b le 0 : d is a b le N o t im p le m e n te d , r e a d a s " 0 " S e r ia l in te r fa c e in te r r u p t r e q u e s t fla g 1 : a c tiv e 0 : in a c tiv e A /D c o n v e r te r r e q u e s t fla g 1 : a c tiv e 0 : in a c tiv e E x te r n a l in te r r u p t r e q u e s t fla g 1 : a c tiv e 0 : in a c tiv e N o t im p le m e n te d , r e a d a s " 0 " MFI1C Register Rev. 1.10 27 August 5, 2011 HT82A836R need to be serviced immediately in some applications. If only one stack is left and the interrupt is not well controlled, the original control sequence will be damaged once a ²CALL subroutine² is executed in the interrupt subroutine. not full and the A/D conversion completes, a subroutine call to location 014H will take place. The Multi-function Interrupt request flag MFF1 will be reset automatically and the EMI bit will be cleared to disable other interrupts. The A/D Interrupt flag will not be reset automatically and needs to be reset manually by the application program. All of these interrupts have the capability of waking up the processor when in the Power Down Mode. Only the Program Counter is pushed onto the stack. If the contents of the accumulator or status register are altered by the interrupt service program, which may corrupt the desired control sequence, then the contents should be saved in advance. Serial Interface Interrupt The device contains an internal Serial Interface with its own interrupt function. For a Serial Interface Interrupt to occur, the corresponding Serial Interface Interrupt enable bit must be first set. This is bit 0 in the MFI1C register and known as ESII. A Serial Interface Interrupt is generated when a data reception or transmission is complete, after which the related interrupt request flag, SIF, which is bit 4 in the MFI1C register, will be set. The interrupt vector for the Serial Interface Interrupt is the Multi-function Interrupt, located at 014H. Therefore if the Multi-function and Serial Interface Interrupt are enabled, the stack is not full and a serial interface data reception or transmission is complete, a subroutine call to location 014H will take place. The Multi-function Interrupt request flag MFF1 will be reset automatically and the EMI bit will be cleared to disable other interrupts. The Serial Interface Interrupt flag will not be reset automatically and needs to be reset manually by the application program. Reset and Initialisation A reset function is a fundamental part of any microcontroller ensuring that the device can be set to some predetermined condition irrespective of outside parameters. The most important reset condition is after power is first applied to the microcontroller. In this case, internal circuitry will ensure that the microcontroller, after a short delay, will be in a well defined state and ready to execute the first program instruction. After this power-on reset, certain important internal registers will be set to defined states before the program commences. One of these registers is the Program Counter, which will be reset to zero forcing the microcontroller to begin program execution from the lowest Program Memory address. Record Interrupt In addition to the power-on reset, situations may arise where it is necessary to forcefully apply a reset condition when the microcontroller is running. One example of this is where after power has been applied and the microcontroller is already running, the RESET line is forcefully pulled low. In such a case, known as a normal operation reset, some of the microcontroller registers remain unchanged allowing the microcontroller to proceed with normal operation after the reset line is allowed to return high. Another type of reset is when the Watchdog Timer overflows and resets the microcontroller. All types of reset operations result in different register conditions being setup. For a Record Interrupt to occur, the global interrupt enable bit, EMI, and the corresponding Record Interrupt bit, RECI, must first be set. An actual Record Interrupt will take place when the Record Interrupt request flag, RECF, is set, a situation that will occur when the record data is valid. When the interrupt is enabled, the stack is not full and a Record Interrupt occurs, a subroutine call to the Record Interrupt vector at location 18H, will take place. When the interrupt is serviced, the Record Interrupt request flag, RECF, will be automatically reset and the EMI bit will be automatically cleared to disable other interrupts. If the A/D Converter is powered down (AD_ENB =1), PLL clock disabled (PLLEN=1) or USB clock disabled (USBCKEN=0), the record interrupt also be disabled. Another reset exists in the form of a Low Voltage Reset, LVR, where a full reset, similar to the RESET reset is implemented in situations where the power supply voltage falls below a certain threshold. Programming Considerations By disabling the interrupt enable bits, a requested interrupt can be prevented from being serviced, however, once an interrupt request flag is set, it will remain in this condition in the interrupt control register until the corresponding interrupt is serviced or until the request flag is cleared by a software instruction. Reset Functions There are five ways in which a microcontroller reset can occur, through events occurring both internally and externally: · Power-on Reset The most fundamental and unavoidable reset is the one that occurs after power is first applied to the microcontroller. As well as ensuring that the Program Memory begins execution from the first memory ad- It is recommended that programs do not use the ²CALL subroutine² instruction within the interrupt subroutine. Interrupts often occur in an unpredictable manner or Rev. 1.10 28 August 5, 2011 HT82A836R Counter will reset to zero and program execution initiated from this point. dress, a power-on reset also ensures that certain other registers are preset to known conditions. All the I/O port and port control registers will power up in a high condition ensuring that all pins will be first set to inputs. Although the microcontroller has an internal RC reset function, if the VDD power supply rise time is not fast enough or does not stabilise quickly at power-on, the internal reset function may be incapable of providing proper reset operation. For this reason it is recommended that an external RC network is connected to the RESET pin, whose additional time delay will ensure that the RESET pin remains low for an extended period to allow the power supply to stabilise. During t h is t im e d e l ay, nor m a l o p e r at i o n o f t h e microcontroller will be inhibited. After the RESET line reaches a certain voltage value, the reset delay time tRSTD is invoked to provide an extra delay time after which the microcontroller will begin normal operation. The abbreviation SST in the figures stands for System Start-up Timer. V D D 0 .9 V R E S tR R E S 0 .9 V D D D D tR S T D S S T T im e - o u t In te rn a l R e s e t RES Reset Timing Chart · Low Voltage Reset - LVR The microcontroller contains a low voltage reset circuit in order to monitor the supply voltage of the device, which is selected via a configuration option. If the supply voltage of the device drops to within a range of 0.9V~VLVR such as might occur when changing the battery, the LVR will automatically reset the device internally. The LVR includes the following specifications: For a valid LVR signal, a low voltage, i.e., a voltage in the range between 0.9V~VLVR must exist for greater than the value tLVR specified in the A.C. characteristics. If the low voltage state does not exceed 1ms, the LVR will ignore it and will not perform a reset function. D D S T D S S T T im e - o u t L V R In te rn a l R e s e t tR In te rn a l R e s e t For most applications a resistor connected between VDD and the RESET pin and a capacitor connected between VSS and the RESET pin will provide a suitable external reset circuit. Any wiring connected to the RESET pin should be kept as short as possible to minimize any stray noise interference. Low Voltage Reset Timing Chart · Watchdog Time-out Reset during Normal Operation V D D The Watchdog time-out Reset during normal operation is the same as a hardware RES pin reset except that the Watchdog time-out flag TO will be set to ²1². R E S E T W D T T im e - o u t 1 0 0 k W 0 .1 m F tR V S S S T D S S T T im e - o u t In te rn a l R e s e t Basic Reset Circuit For applications that operate within an environment where more noise is present the Enhanced Reset Circuit shown is recommended. 0 .0 1 m F S T D S S T T im e - o u t Power-On Reset Timing Chart WDT Time-out Reset during Normal Operation Timing Chart · Watchdog Time-out Reset during Power Down V D D The Watchdog time-out Reset during Power Down is a little different from other kinds of reset. Most of the conditions remain unchanged except that the Program Counter and the Stack Pointer will be cleared to ²0² and the TO flag will be set to ²1². Refer to the A.C. Characteristics for tSST details. 1 0 0 k W R E S E T 1 0 k W 0 .1 m F V S S W D T T im e - o u t Enhanced Reset Circuit tS · RES Pin Reset S T S S T T im e - o u t This type of reset occurs when the microcontroller is already running and the RESET pin is forcefully pulled low by external hardware such as an external switch. In this case as in the case of other reset, the Program Rev. 1.10 0 .4 V WDT Time-out Reset during Power Down Timing Chart 29 August 5, 2011 HT82A836R The following table indicates the way in which the various components of the microcontroller are affected after a power-on reset occurs. Reset Initial Conditions The different types of reset described affect the reset flags in different ways. These flags, known as PDF and TO are located in the status register and are controlled by various microcontroller operations, such as the Power Down function or Watchdog Timer. The reset flags are shown in the table: TO PDF Item RESET Conditions 0 0 RES reset during power-on u u RES or LVR reset during normal operation 1 u WDT time-out reset during normal operation 1 1 WDT time-out reset during Power Down Condition After RESET Program Counter Reset to zero Interrupts All interrupts will be disabled WDT Clear after reset, WDT begins counting Timer/Event Counter Timer Counter will be turned off Note: ²u² stands for unchanged Input/Output Ports I/O ports will be setup as inputs Stack Pointer Stack Pointer will point to the top of the stack The different kinds of resets all affect the internal registers of the microcontroller in different ways. To ensure reliable continuation of normal program execution after a reset occurs, it is important to know what condition the microcontroller is in after a particular reset occurs. The following table describes how each type of reset affects each of the microcontroller internal registers. Note that where more than one package type exists the table will reflect the situation for the larger package type. The states of the registers are summarized in the table. Register Reset (Power-on) WDT RES Reset RES Reset Time-out (Normal (HALT) (Normal Operation) Operation) WDT Time-Out (HALT)* USB Reset USB Reset (Normal) (HALT) MP0 xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu MP1 xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu ACC xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu 000H 000H 000H 000H 000H 000H 000H xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu Program Counter TBLP TBLH -xxx xxxx -uuu uuuu -uuu uuuu -uuu uuuu -uuu uuuu -uuu uuuu -uuu uuuu WDTS 0000 0111 0000 0111 0000 0111 0000 0111 uuuu uuuu 0000 0111 0000 0111 STATUS --00 xxxx --1u uuuu --uu uuuu --01 uuuu --11 uuuu --uu uuuu --01 uuuu INTC0 -000 0000 -000 0000 -000 0000 -000 0000 -uuu uuuu -000 0000 -000 0000 TMR0H xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu TMR0L xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu TMR0C 00-0 1000 00-0 1000 00-0 1000 00-0 1000 uu-u uuuu 00-0 1000 00-0 1000 TMR1H xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu TMR1L xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu TMR1C 00-0 1--- 00-0 1--- 00-0 1--- 00-0 1--- uu-u u--- 00-0 1--- 00-0 1--- PA 1111 1111 1111 1111 1111 1111 1111 1111 uuuu uuuu 1111 1111 1111 1111 PAC 1111 1111 1111 1111 1111 1111 1111 1111 uuuu uuuu 1111 1111 1111 1111 Rev. 1.10 30 August 5, 2011 HT82A836R Register PB Reset (Power-on) WDT RES Reset RES Reset Time-out (Normal (HALT) (Normal Operation) Operation) WDT Time-Out (HALT)* USB Reset USB Reset (Normal) (HALT) 1111 1111 1111 1111 uuuu uuuu 1111 1111 1111 1111 1111 1111 1111 1111 PBC 1111 1111 1111 1111 1111 1111 1111 1111 uuuu uuuu 1111 1111 1111 1111 PC 1111 1111 1111 1111 1111 1111 1111 1111 uuuu uuuu 1111 1111 1111 1111 PCC 1111 1111 1111 1111 1111 1111 1111 1111 uuuu uuuu 1111 1111 1111 1111 PD 1111 1111 1111 1111 1111 1111 1111 1111 uuuu uuuu 1111 1111 1111 1111 PDC 1111 1111 1111 1111 1111 1111 1111 1111 uuuu uuuu 1111 1111 1111 1111 PE 1111 1111 1111 1111 1111 1111 1111 1111 uuuu uuuu 1111 1111 1111 1111 PEC 1111 1111 1111 1111 1111 1111 1111 1111 uuuu uuuu 1111 1111 1111 1111 PF ---- 1111 ---- 1111 ---- 1111 ---- 1111 ---- uuuu ---- 1111 ---- 1111 PFC ---- 1111 ---- 1111 ---- 1111 ---- 1111 ---- uuuu ---- 1111 ---- 1111 -000 0000 -000 0000 -000 0000 -000 0000 -uuu uuuu -000 0000 -000 0000 TBHP xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu USC 1000 0000 uuxx uuuu 10xx 0000 10xx 0000 10xx uuuu 1000 0u00 1000 0u00 USR 0000 0000 uuuu uuuu 0000 0000 0000 0000 uuuu uuuu 00uu 0000 00uu 0000 UCC 0000 0000 uuuu uuuu 0000 0000 0000 0000 uuuu uuuu 0u00 u000 0u00 u000 AWR 0000 0000 uuuu uuuu 0000 0000 0000 0000 uuuu uuuu 0000 0000 0000 0000 STALL 0000 0000 uuuu uuuu 0000 0000 0000 0000 uuuu uuuu 0000 0000 0000 0000 SIES 0000 0000 uuuu uuuu 0000 0000 0000 0000 uuuu uuuu 0u00 u000 0u00 u000 MISC 0000 0000 uuuu uuuu 0000 0000 0000 0000 uuuu uuuu 0000 0000 0000 0000 SETIO xxxx x010 xxxx x010 xxxx x010 xxxx x010 xxxx x010 xxxx x010 xxxx x010 FIFO0 xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu 0000 0000 0000 0000 FIFO1 xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu 0000 0000 0000 0000 FIFO2 xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu 0000 0000 0000 0000 FIFO3 xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu 0000 0000 0000 0000 FIFO4 xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu 0000 0000 0000 0000 DAC_LIMIT_L 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu 0000 0000 0000 0000 DAC_LIMIT_H 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu 0000 0000 0000 0000 DAC_WR 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu 0000 0000 0000 0000 PGA_CTRL 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 00uu uuuu 00uu uuuu PFDC 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0uuu 0000 0uuu 0000 PFDD 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0uuu 0000 0uuu 0000 OPER_MODE 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu uuuu uuuu MODE_CTRL 0000 0000 0000 0000 0000 0000 0000 0000 0000 0uuu 0000 0uuu 0000 0uuu SBCR 0110 0000 0110 0000 0110 0000 0110 0000 uuuu uuuu uuuu uuuu uuuu uuuu SBDR uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu RECORD_IN_L 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu uuuu uuuu RECORD_IN_H 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu uuuu uuuu PLAY_DATAL_L 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu uuuu uuuu INTC1 Rev. 1.10 31 August 5, 2011 HT82A836R Reset (Power-on) WDT RES Reset RES Reset Time-out (Normal (HALT) (Normal Operation) Operation) WDT Time-Out (HALT)* USB Reset USB Reset (Normal) (HALT) PLAY_DATAL_H 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu uuuu uuuu PLAY_DATAR_L 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu uuuu uuuu PLAY_DATAR_H 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu uuuu uuuu RECORD_DATA_L 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu uuuu uuuu RECORD_DATA_H 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu uuuu uuuu ADRL xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu Register ADRH xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu ADCR 0100 0000 0100 0000 0100 0000 0100 0000 uuuu uuuu uuuu uuuu uuuu uuuu ACSR 1--- --00 1--- --00 1--- --00 1--- --00 u--- --uu u--- --uu u--- --uu PA_WAKE_CTRL 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu uuuu uuuu PWMC 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu uuuu uuuu PWM0 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu PWM1 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu MFI1C 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu 0000 0000 0000 0000 USB_STATE 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu uuuu uuuu USVC 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu 0000 0000 0000 0000 ²*² stands for warm reset ²u² stands for unchanged ²x² stands for unknown ²-² stands for unimplemented Oscillator The device use crystal oscillator as the system clock source. Two types of crystal system clock frequencies can be selected while various clock source options for the Watchdog Timer are provided for maximum flexibility. C 1 O S C I O S C O C 2 System Crystal/Ceramic Oscillator Crystal/Ceramic Oscillator For the 12MHz crystal oscillator configurations, the simple connection of a crystal across OSC1 and OSC2 will create the necessary phase shift and feedback for oscillation. For the 6MHz crystal oscillator configuration the addition of two small value capacitors are required. The SYSCLK bit in the UCC register determines the system frequency selection. Crystal C1, C2 6MHz Crystal 22pF 12MHz Crystal NC Rev. 1.10 Watchdog Timer Oscillator The WDT oscillator is a fully self-contained free running on-chip RC oscillator with a typical period of 65 us at 5V requiring no external components. When the device enters the Power Down Mode, the system clock will stop running but the WDT oscillator continues to free-run and to keep the watchdog active. However, to preserve power in certain applications the WDT oscillator can be disabled via a configuration option. 32 August 5, 2011 HT82A836R Power Down Mode and Wake-up inputs. Also note that additional standby current will also be required if the configuration options have enabled the Watchdog Timer internal oscillator. Power Down Mode All of the Holtek microcontrollers have the ability to enter a Power Down Mode, also known as the HALT Mode or Sleep Mode. When the device enters this mode, the normal operating current, will be reduced to an extremely low standby current level. This occurs because when the device enters the Power Down Mode, the system oscillator is stopped which reduces the power consumption to extremely low levels, however, as the device maintains its present internal condition, it can be woken up at a later stage and continue running, without requiring a full reset. This feature is extremely important in application areas where the MCU must have its power supply constantly maintained to keep the device in a known condition but where the power supply capacity is limited such as in battery applications. Wake-up After the system enters the Power Down Mode, it can be woken up from one of various sources listed as follows: · An external reset · An external falling or rising edge on Port A · An external falling edge on Port B~Port F · A system interrupt · A WDT overflow If the system is woken up by an external reset, the device will experience a full system reset, however, if the device is woken up by a WDT overflow, a Watchdog Timer reset will be initiated. Although both of these wake-up methods will initiate a reset operation, the actual source of the wake-up can be determined by examining the TO and PDF flags. The PDF flag is cleared by a system power-up or executing the clear Watchdog Timer instructions and is set when executing the ²HALT² instruction. The TO flag is set if a WDT time-out occurs, and causes a wake-up that only resets the Program Counter and Stack Pointer, the other flags remain in their original status. Entering the Power Down Mode There is only one way for the device to enter the Power Down Mode and that is to execute the ²HALT² instruction in the application program. When this instruction is executed, the following will occur: · The system oscillator will stop running and the appli- cation program will stop at the ²HALT² instruction. · The Data Memory contents and registers will maintain their present condition. Each pin on Port A can be setup via an individual configuration option to permit a negative (or positive) transition · The WDT will be cleared and resume counting if the WDT clock source is selected to come from the WDT oscillator. The WDT will stop if its clock source originates from the system clock. on the pin to wake-up the system. When a Port A pin wake-up occurs, the program will resume execution at the instruction following the ²HALT² instruction. · The I/O ports will maintain their present condition. · In the status register, the Power Down flag, PDF, will Each pin on can be setup via an individual configuration option to permit a negative transition on the pin to wake-up the system. Port A has an addition function, controlled via the PA_WAKE_CTRL register in the Data Memory, allowing either a negative or positive edge to initiate a Wake-up function. Any external pin wake-up will cause the system to resume execution at the instruction following the ²HALT² instruction. be set and the Watchdog time-out flag, TO, will be cleared. Standby Current Considerations As the main reason for entering the Power Down Mode is to keep the current consumption of the MCU to as low a value as possible, perhaps only in the order of several micro-amps, there are other considerations which must also be taken into account by the circuit designer if the power consumption is to be minimized. Special attention must be made to the I/O pins on the device. All high-impedance input pins must be connected to either a fixed high or low level as any floating input pins could create internal oscillations and result in increased current consumption. This also applies to devices which have different package types, as there may be undonbed pins, which must either be setup as outputs or if setup as inputs must have pull-high resistors connected. Care must also be taken with the loads, which are connected to I/O pins, which are setup as outputs. These should be placed in a condition in which minimum current is drawn or connected only to external circuits that do not draw current, such as other CMOS Rev. 1.10 If the system is woken up by an interrupt, then two possible situations may occur. The first is where the related interrupt is disabled or the interrupt is enabled but the stack is full, in which case the program will resume execution at the instruction following the ²HALT² instruction. In this situation, the interrupt which woke-up the device will not be immediately serviced, but will rather be serviced later when the related interrupt is finally enabled or when a stack level becomes free. The other situation is where the related interrupt is enabled and the stack is not full, in which case the regular interrupt response takes place. If an interrupt request flag is set to ²1² before entering the Power Down Mode, the wake-up function of the related interrupt will be disabled. 33 August 5, 2011 HT82A836R source instead of the internal WDT oscillator. If the instruction clock is used as the clock source, it must be noted that when the system enters the Power Down Mode, as the system clock is stopped, then the WDT clock source will also be stopped. Therefore the WDT will lose its protecting purposes. In such cases the system cannot be restarted by the WDT and can only be restarted using external signals. For systems that operate in noisy environments, using the internal WDT oscillator is therefore the recommended choice. No matter what the source of the wake-up event is, once a wake-up situation occurs, a time period equal to 1024 system clock periods will be required before normal system operation resumes. However, if the wake-up has originated due to an interrupt, the actual interrupt subroutine execution will be delayed by an additional one or more cycles. If the wake-up results in the execution of the next instruction following the ²HALT² instruction, this will be executed immediately after the 1024 system clock period delay has ended. Under normal program operation, a WDT time-out will initialise a device reset and set the status bit TO. However, if the system is in the Power Down Mode, when a WDT time-out occurs, only the Program Counter and Stack Pointer will be reset. Three methods can be adopted to clear the contents of the WDT and the WDT prescaler. The first is an external hardware reset, which means a low level on the RESET pin, the second is using the watchdog software instructions and the third is via a ²HALT² instruction. Watchdog Timer The Watchdog Timer is provided to prevent program malfunctions or sequences from jumping to unknown locations, due to certain uncontrollable external events such as electrical noise. It operates by providing a device reset when the WDT counter overflows. The WDT clock is supplied by two sources selected by configuration option: its own self contained dedicated internal WDT oscillator or fSYS/4. Note that if the WDT configuration option has been disabled, then any instruction relating to its operation will result in no operation. There are two methods of using software instructions to clear the Watchdog Timer, one of which must be chosen by configuration option. The first option is to use the single ²CLR WDT² instruction while the second is to use the two commands ²CLR WDT1² and ²CLR WDT2². For the first option, a simple execution of ²CLR WDT² will clear the WDT while for the second option, both ²CLR WDT1² and ²CLR WDT2² must both be executed to successfully clear the WDT. Note that for this second option, if ²CLR WDT1² is used to clear the WDT, successive executions of this instruction will have no effect, only the execution of a ²CLR WDT2² instruction will clear the WDT. Similarly, after the ²CLR WDT2² instruction has been executed, only a successive ²CLR WDT1² instruction can clear the Watchdog Timer. The internal WDT oscillator has an approximate period of 65ms at a supply voltage of 5V. If selected, it is first divided by 256 via an 8-stage counter. Note that this period can vary with VDD, temperature and process variations. For longer WDT time-out periods the WDT prescaler can be utilized. By writing the required value to bits 0, 1 and 2 of the WDTS register, known as WS0, WS1 and WS2, longer time-out periods can be achieved. With WS0, WS1 and WS2 all equal to 1, the division ratio is 1:128 which gives a maximum time-out period. A configuration option can select the instruction clock, which is the system clock divided by 4, as the WDT clock b 7 T 3 b 0 T 2 T 1 T 0 W S 2 W S 1 W S 0 W D T S R e g is te r W D T p r e s c a le r r a te s e le c t W D T R W S 0 W S 1 W S 2 1 :1 0 0 0 1 :2 1 0 0 1 :4 0 1 0 1 :8 1 1 0 1 :1 0 0 1 1 :3 1 0 1 1 :6 0 1 1 1 :1 1 1 1 a te 6 2 4 2 8 N o t u s e d T e s t m o d e s e ttin g b its T 3 T 2 T 1 T 0 1 0 1 0 O th e rs O p e r a tio n m o d e E n te r D A C w r ite m o d e N o r m a l o p e r a tio n Watchdog Timer Register Rev. 1.10 34 August 5, 2011 HT82A836R C L R W D T 1 F la g C L R W D T 2 F la g C le a r W D T T y p e C o n fig u r a tio n O p tio n 1 o r 2 In s tr u c tio n s fS Y S /4 W D T O s c illa to r C L R W D T C lo c k S o u r c e C o n fig u r a tio n O p tio n 8 - b it C o u n te r (¸ 2 5 6 ) W D T C lo c k S o u r c e C L R 7 - b it P r e s c a le r 8 -to -1 M U X W S 0 ~ W S 2 W D T T im e - o u t Watchdog Timer USB Function The device includes a USB 1.1 interface which can be used for data application data transfer. Five endpoints are included in the USB function of this device. · RMWK USB Interface · URST The RMWK read/write bit is the USB remote wake-up command. It is set by the MCU to allow the USB host to leave the suspend mode after an external wake-up. The URST read/write bit is the USB reset indication bit. This bit is set and cleared by the USB SIE and indicates a USB reset event on the USB bus. When this bit is set to ²1², this indicates that a USB reset has occurred and that a USB interrupt will be generated. The Interface in the HT82A836R device has 5 Endpoints, known as EP0~EP4. Endpoint 0, EP0, is used for Control transfer. Endpoints EP1 and EP4 are for Interrupt transfer, while EP2 supports the Isochronous out transfer. EP3 supports Isochronous in transfer. A set of registers stored in the Data Memory is used for overall control of the USB function. These control registers include, USC, USR, UCC, AWR, STALL, SIES and MISC. There are also five FIFO registers with the names FIFO0~FIFO4. The size of each FIFO is as follows:, FIFO0-8 bytes, FIFO1-8 bytes, FIFO2-384 bytes, FIFO3-32 bytes and FIFO4-64 bytes, giving a total of 496 bytes. The URD bit, which is bit7 of the USC register is the USB reset signal control function definition bit. · RESUME The RESUME read only bit is used to indicate that the USB has left the Suspend Mode. When the USB has left the Suspend Mode, this read-only bit is set to ²1² by the SIE. When the RESUME bit is set by SIE, an interrupt will be generated to wake-up the MCU. In order to detect the suspend state, the MCU should set the USBCKEN bit and clear SUSP2 in the UCC register, to enable the SIE detect function. The RESUME bit will be cleared when SUSP goes to ²0². When the MCU is detecting the SUSP, the condition of the RESUME bit, which will wake-up the MCU, should be noted and taken into consideration. USB Interface Registers The USB setup, data management and endpoint control in the device is controlled via a series of registers in the Data Memory. · V33C The V33C read/write bit is the control bit for the internally generated 3.3V supply for the USB interface. USC Register · PLLEN The USC register is the register for the overall control of the USB function. The initial status of this register is 80H. The PLLEN read/write bit is the control bit for the internal Phase Locked Loop function. · CRCFG Further explanation of each of the bits is given below: The CRCFG read/write bit is the CRC error condition failure flag. The CRCFG bit will be set by the hardware however the CRCFG bit needs to be cleared using firmware. · SUSP The SUSP bit is the USB Suspend Indicator bit. When this read-only bit is set to ²1² by the SIE, it indicates that the USB bus has entered the suspend mode. The USB interrupt is also triggered when this bit changes from low to high. Rev. 1.10 · URD The URD read/write bit is the USB reset signal control function definition bit. 35 August 5, 2011 HT82A836R b 7 U R D b 0 C R C F G P L L E N V 3 3 C R E S U M E U R S T R M W K S U S P U S C R e g is te r U S B S u s p e n d In d ic a tio n ( r e a d o n ly ) 1 : S u s p e n d m o d e 0 : N o t in s u s p e n d m o d e U S B R e m o te W a k e -u p 1 : L e a v e s u s p e n d m o d e 0 : N o c h a n g e U S B R e s e t In d ic a tio n 1 : U S B re s e t o c c u rre d 0 : N o re s e t U S B R e s u m e In d ic a tio n ( r e a d o n ly ) 1 : U S B le ft s u s p e n d m o d e 0 : N o c h a n g e V 3 3 O O u tp u t C o n tro l 1 : V 3 3 O o u tp u t o n 0 : V 3 3 O o u tp u t o ff P L L E n a b le 1 : P L L o ff 0 : P L L o n C R C E r r o r C o n d itio n 1 : E rro r 0 : N o E rro r U S B R e s e t C o n tr o l D e fin itio n 1 : U S B r e s e t s ig n a l w ill r e s e t M C U 0 : U S B re s e t c a n n o t re s e t M C U USB Control Register - USC Further explanation of each of the bits is given below: USR Register · EPS0~EPS2 The USR register is the USB endpoint interrupt status register and is used to indicate which endpoint is accessed and to select the USB bus. The endpoint request flags, EP0F, EP1F, EP2F, EP3F and EP4F are used to indicate which endpoints are accessed. If an endpoint is accessed, the related endpoint request flag will be set to ²1² and the USB interrupt will be generated if the USB interrupt is enabled and the stack is not full. When the active endpoint request flag is serviced, the endpoint request flag has to be cleared to ²0² by software. These three read/write bits are for the endpoint FIFO selection. It should be noted that Isochronous endpoints 2 and 3 are implemented in hardware, therefore FIFO2 and FIFO3 cannot be read from or written to using firmware. · USBCKEN The USBCKEN read/write bit enables the USB clock. · SUSP2 The SUSP2 read/write bit is the second suspend bit and is used to select a power reducing function when the device is in the Suspend Mode. In the Normal Mode this bit should be cleared to zero. Further explanation of each of the bits is given below: · ESP0F~ESP4F The ESP0F~ESP4F read/write bits are set by the SIE an indicate whether the associated endpoint has been accessed and a USB interrupt generated. After the interrupt has been serviced the bits should be cleared by the application program. · FSYS16MHz This read/write bit is used to determine if the system clock is derived from an external oscillator or from the internal PLL 16MHz clock. · SYSCLK UCC Register The SYSCLK read/write bit is used to determine if the system clock is either 6MHz or 12MHz. The UCC register is the system clock control register and is used to select the clock that is used in the MCU. This register consists of a USB clock control bit, USBCKEN, a second suspend mode control bit, SUSP2, and a system clock selection bit, SYSCLK. The register also controls the endpoint selection, which is determined by bits EPS0, EPS1 and EPS2. Rev. 1.10 AWR Register The AWR register is used to store the current USB device address and also for control of the Remote Wake-up function. The initial value of the AWR register is ²00H². The address value extracted from the USB command must not be loaded into this register until the SETUP stage has finished. 36 August 5, 2011 HT82A836R b 7 b 0 E P 4 F E P 3 F E P 2 F E P 1 F E P 0 F U S R R e g is te r E n d p o in t 0 a c c e s s E n d p o in t 1 a c c e s s E n d p o in t 2 a c c e s s E n d p o in t 3 a c c e s s E n d p o in t 4 a c c e s s 1 : A c c e s s A ll E n d p o in ts 0 : N o a c c e s s N o t im p le m e n te d , r e a d a s " 0 " USB Endpoint Status Register - USR b 7 b 0 S Y S C L K F S Y S 1 6 M H z S U S P 2 U S B C K E N E P S 2 E P S 1 E P S 0 U C C R e g is te r A c c e s s E n d p o in t F IF O E P S 0 E P S 2 E P S 1 0 0 0 1 0 0 0 0 1 1 0 1 0 1 0 1 1 0 0 1 1 1 1 1 S e le c tio n E n d E n d E n d E n d E n d p o in p o in p o in p o in p o in S e t 0 t 1 t 2 t 3 t 4 le c tio n F IF O F IF O F IF O F IF O F IF O - C o n In te Is o c Is o c In te tro l rru p t h ro n o u s O u t h ro n o u s In rru p t U n d e fin e d , c a n n o t b e u s e d U S B C lo c k C o n tr o l 1 : C lo c k e n a b le d 0 : C lo c k d is a b le d R e d u c e P o w e r in S u s p e n d 1 : R e d u c e p o w e r in P o w e r - d o w n m o d e 0 : C le a r to z e r o in N o r m a l m o d e S y s te m C lo c k S o u r c e 1 : 1 6 M H z P L L s o u rc e 0 : O S C s o u rc e S y s te m C lo c k F r e q u e n c y 1 : 6 M H z 0 : 1 2 M H z N o t im p le m e n te d , r e a d a s " 0 " System Clock Control Register - UCC b 7 A D 6 b 0 A D 5 A D 4 A D 3 A D 2 A D 1 A D 0 W K E N A W R R e g is te r U S B R e m o te W a k e - u p E n a b le /D is a b le 1 : e n a b le 0 : d is a b le U S B d e v ic e a d d r e s s Device Address Register - AWR Rev. 1.10 37 August 5, 2011 HT82A836R immediately after an address is written to the AWR register. Therefore in order to work properly, the program has to clear this bit after a next valid SETUP token is received. STALL Register The STALL register shows whether the corresponding endpoint has operated correctly or not. As soon as the endpoint has operated incorrectly, the related read/write bit in the STALL has to be set to ²1². The STALL register will be cleared by a USB reset signal and a setup token event. The initial value of the STALL register is ²00H². · ERR The read/write ERR bit is used to indicate that errors have occurred when the FIFO is accessed. This bit is set by SIE and should be cleared by the program. This bit is used for all endpoints. SIES Register · OUT The SIES register is the setup register for the Serial Interface Engine. The read/write OUT bit is used to indicate the reception of an OUT token, except for the OUT zero length token. The device will clear this bit after the OUT data has been read. Also, this bit will be cleared by the SIE after the next valid SETUP token is received. Further explanation of each of the bits is given below: · ASET The read/write ASET bit is used to configure the SIE to automatically change the device address to the value presently stored in the AWR register. When this bit is set to ²1² by, the SIE will update the device address with the value stored in the AWR register after the PC host has successfully read the data from the device with an IN operation. Otherwise, when this bit is cleared to ²0², the SIE will update the device address · IN The read only IN bit is used to indicate that the current USB receiving signal from PC host is an IN token. · NAK This read only bit is used to indicate that the SIE has transmitted a NAK signal to the host in response to the PC host IN or OUT token. b 7 S T L 7 b 0 S T L 6 S T L 5 S T L 4 S T L 3 S T L 2 S T L 1 S T L 0 S T A L L R e g is te r E n d p o in t 0 ~ 4 S ta ll In d ic a to r 1 : E n d p o in t s ta lle d 0 : N o r m a l o p e r a tio n U n d e fin e d , r e a d a s " 0 " Endpoint Stall Register - STALL b 7 M N I b 0 E O T C R C F N A K IN O U T E R R A S E T S IE S R e g is te r D e v ic e A d d r e s s S e t 1 : U p d a te a d d re s s fro m H o s t re a d 0 : U p d a te s a fte r A W R r e g is te r w r ite F IF O a c c e s s e rro r 1 : E r r o r c o n d itio n 0 : N o e rro r O U T to k e n r e c e iv e d 1 : T o k e n r e c e iv e d 0 : N o to k e n r e c e iv e d IN to k e n in d ic a to r 1 : U S B r e c e iv e s ig n a l is In to k e n 0 : N o t In to k e n S IE tr a n s m itte d N A K to k e n in d ic a to r 1 : N A K to k e n tr a n s m itte d 0 : N o N A K to k e n tr a n s m itte d E r r o r F a ilu r e F la g 1 : E rro r 0 : N o e rro r T o k e n p a c k a g e a c tiv e in d ic a to r 1 : In a c tiv e 0 : A c tiv e N A K to k e n in te r r u p t m a s k 1 : N A K to k e n in te r r u p t m a s k 0 : N o in te r r u p t m a s k Serial Interface Setup Register - SIES Rev. 1.10 38 August 5, 2011 HT82A836R · CRCF desires to write data to the FIFO. After finishing, this bit must be set low before terminating the request to represent a transition end. For an MCU read operation, this bit must be set low and then high after finishing. The CRCF read/write is an error condition failure flag that includes CRC, PID and no integrate token error. CRCF will be set by the hardware but needs to be cleared by the firmware. · EOT · CLEAR The EOT read only read only flag is the Token Package active flag. Note that this flag is active low. The read/write CLEAR bit MCU is used to request a FIFO clear, even if the FIFO is not ready. After clearing the FIFO, the USB interface will send a force_tx_err to tell the Host that data under-run if the Host wants to read data. · NMI The read/write NMI bit is the NAK token interrupt mask flag. If this bit set, when the device sends a NAK token to the host, the interrupt will be disabled. Otherwise if this bit is cleared, when the device sends a NAK token to the host, it will enter the interrupt subroutine. · ISO_IN_EN The read/write ISO_IN_EN bit enables the isochronous in pipe interrupt. · ISO_OUT_EN The read/write ISO_OUT_EN bit enables the isochronous out pipe interrupt. MISC Register The MISC register combines command and status to control the desired endpoint FIFO action and to show the status of the desired endpoint FIFO. The MISC register will be cleared by a USB reset signal. · SETCMD The read/write SETCMD bit is used to show that the data in the FIFO is a setup command. The bit will remain in the same state until the following data enters the FIFO. Further explanation of each of the bits is given below: · REQUEST · READY The read/write REQUEST, if set high, can request the FIFO after the corresponding status has been set. When finished this bit must be set low. The read only READY bit is used to indicate that the desired FIFO is ready. · LEN0 · TX The read only LEN0 bit is used to indicate that the host has sent a 0-sized packet to the MCU. This bit must be cleared by a read action to the corresponding FIFO. The read/write TX bit represents the direction and MCU access transition end. When set high, the MCU b 7 L E N 0 b 0 R E A D Y S E T C M D IS O _ O U T _ E N IS O _ IN _ E N C L E A R T X R E Q U E S T M IS C R e g is te r F IF O R e q u e s t 1 : R e q u e s t 0 : N o re q u e s t M C U tr a n s m it r e q u e s t 1 : T r a n s m it r e q u e s t 0 : T r a n s m it e n d C le a r F IF O r e q u e s t 1 : R e q u e s t 0 : N o re q u e s t Is o c h r o n o u s P ip e - in in te r r u p t 1 : E n a b le 0 : D is a b le Is o c h r o n o u s P ip e - o u t in te r r u p t 1 : E n a b le 0 : D is a b le F IF O s e tu p c o m m a n d in d ic a to r 1 : S e tu p c o m m a n d 0 : N o n -s e tu p c o m m a n d F IF O r e a d y in d ic a to r 1 : R e a d y 0 : N o t re a d y 0 s iz e p a c k e t in d ic a to r 1 : 0 p a c k e t 0 : N o n 0 p a c k e t Miscellaneous Register - MISC Rev. 1.10 39 August 5, 2011 HT82A836R SETIO Register Suspend Wake-Up Remote Wake-Up The SETIO register is used to setup the endpoints to either input or output pipe type. The DATA token toggle bit is also contained within this register. Note that for USB definition, when the host sends a ²set Configuration², the Data pipe should send DATA0, about the Data toggle, first. Therefore, when the device receives a ²set configuration² setup command, the user needs to toggle this bit as the following data will send DATA0 first. It is only required to set the data pipe as an input pile or output pile. The purpose of this function is to avoid the host sending an abnormal IN or OUT token and disabling the endpoint. All bits are read/write. The device includes a Suspend mode. If there is no signal on the USB bus for over 3ms, the device will enter a suspend mode. When this happens, the SUSPEND bit, which is bit 0 of the USC register, will be set to ²1² and a USB interrupt will be generated to indicate that the device should jump to the suspend state to meet the requirements of the USB suspend current spec. In order to meet the requirements of the suspend current, the program should disable the USB clock by clearing the USBCKEN bit, which is bit3 of the UCC register, to ²0². The suspend current can be further decreased by setting the SUSP2 bit, which is bit4 of the UCC register. When the resume signal is sent out by the host, the HT82A836R will be woken up the by the USB interrupt and the RESUME bit, which is bit 3 of the USC register, will be set. In order to make the device operate correctly, the program must set the USBCKEN bit and clear the SUSP2 bit. Since the Resume signal will be cleared before the Idle signal is sent out by the host and the SUSPEND bit, will change to ²0². Therefore when the MCU is detecting the Suspend line, the condition of the Resume line should be noted and taken into consideration. SETIO (27H) register, USB Endpoint 1~Endpoint 4 set IN/OUT pipe register. USB_STATE Register This register is used to indicate the error state due to SE0 or SE1 noise as well as the USBD- and USBD+ input signals. The SE0 and SE1 bits are set by the SIE and cleared with the program. b 7 b 0 S E T IO 4 S E T IO 3 S E T IO 2 S E T IO 1 D A T A T G S E T IO R e g is te r D A T A to k e n to g g le S e t E n d p o in t 1 I/O 1 : In p u t 0 : O u tp u t - d e fa u lt " 1 " S e t E n d p o in t 2 I/O 1 : In p u t 0 : O u tp u t - d e fa u lt " 1 " S e t E n d p o in t 3 I/O 1 : In p u t 0 : O u tp u t - d e fa u lt " 1 " S e t E n d p o in t 4 I/O 1 : In p u t 0 : O u tp u t - d e fa u lt " 1 " U n d e fin e d USB Endpoint Setup IN/OUT Pipe Register - SETIO b 7 b 0 U S B D P U S B D N S E 1 S E 0 U S B -S T A T E R e g is te r U n d e fin e d , r e a d a s " 0 " S E 0 n o is e d e te c tio n 1 : N o is e d e te c te d in U S B b u s 0 : N o is e n o t d e te c te d S E 1 n o is e d e te c tio n 1 : N o is e d e te c te d in U S B b u s 0 : N o is e n o t d e te c te d U S B D - in p u t U S B D + in p u t U n d e fin e d , r e a d a s " 0 " USB State Register - USB-STATE Rev. 1.10 40 August 5, 2011 HT82A836R The following shows the related timing of this operation: The following shows the related timing: S U S P E N D S U S P E N D M in . 1 U S B C L K U S B R e s u m e S ig n a l R M W K U S B _ IN T U S B R e s u m e S ig n a l The device contains a remote wake-up function which can wake-up the USB Host by sending a wake-up pulse through the RMWK bit, which is bit 1 of the USC register. Once the USB Host receives a wake-up signal from the device, it will send a Resume signal to the device. M in .2 .5 m s U S B _ IN T USB Speaker Volume Control The speaker output volume as well as the speaker mute/un-mute function are controlled by the USB Speaker Volume Control USVC register. The volume range can be set between a range of 6dB to -32dB by software. The relationship between the USVC volume control bits and the amplification or attenuation values are shown in the Volume Control Table. The mute control will be enabled when the MUTE bit is low and both the DAC and the power amplifier will be muted. b 7 M U T E b 0 U S V C 6 U S V C 5 U S V C 4 U S V C 3 U S V C 2 U S V C 1 U S V C 0 U S V C R e g is te r V o lu m e C o n tr o l B its 0 ~ 6 M u te C o n tro l 1 : D is a b le d 0 : E n a b le d USB Speaker Volume Control Register - USVC Result (dB) USVC Result (dB) USVC Result (dB) USVC Result (dB) USVC 6 000_1100 -2 111_1100 -10 110_1100 -24 101_1100 5.5 000_1011 -2.5 111_1011 -10.5 110_1011 -25 101_1011 5 000_1010 -3 111_1010 -11 110_1010 -26 101_1010 4.5 000_1001 -3.5 111_1001 -11.5 110_1001 -27 101_1001 4 000_1000 -4 111_1000 -12 110_1000 -28 101_1000 3.5 000_0111 -4.5 111_0111 -13 110_0111 -29 101_0111 3 000_0110 -5 111_0110 -14 110_0110 -30 101_0110 2.5 000_0101 -5.5 111_0101 -15 110_0101 -31 101_0101 2 000_0100 -6 111_0100 -16 110_0100 -32 101_0100 1.5 000_0011 -6.5 111_0011 -17 110_0011 ¾ ¾ 1 000_0010 -7 111_0010 -18 110_0010 ¾ ¾ 0.5 000_0001 -7.5 111_0001 -19 110_0001 ¾ ¾ 0 000_0000 -8 111_0000 -20 110_0000 ¾ ¾ -0.5 111_1111 -8.5 110_1111 -21 101_1111 ¾ ¾ -1 111_1110 -9 110_1110 -22 101_1110 ¾ ¾ -1.5 111_1101 -9.5 110_1101 -23 101_1101 ¾ ¾ Speaker Volume Control Table Rev. 1.10 41 August 5, 2011 HT82A836R FIFO Registers Registers R/W Power-on Function FIFO0~ FIFO4 R/W xxH EPi accessing register - EPSX bits in the UCC register. (i = 0~4). When an endpoint is disabled, the corresponding accessing register should be disabled. FIFO0~FIFO4 (28H~2CH) USB Endpoint Accessing Registers Definitions DAC Limit Registers The DAC_Limit_L and DAC_Limit_H registers are used to define the 16-bit DAC output limits. The values in the DAC_Limit_L and DAC_Limit_H registers are unsigned values. If the 16-bit data from the Host exceeds that of the range defined by the two DAC_Limit_L and DAC_Limit_H registers then the output digital code to DAC will be clamped within these register values. DAC_Limit_L DAC output limit low byte DAC_Limit_H DAC output limit high byte Example to set the DAC output limit values: ;----------------------------------------------------------; Set DAC Limit Value=FF00H ;----------------------------------------------------------clr [02DH] ; Set DAC Limit low byte=00H set [02EH] ; Set DAC Limit high byte=FFH ;----------------------------------------------------------In order to prevent a popping noise from the speaker output, the power amplifier should output a value of VDD/2, which means a value of 8000H should be sent to the DAC during the initial power on state. Generating a pulse on the DAC_WR_TRIG bit will write the values into the DAC. If the DAC_WR_TRIG, bit 3 of the DAC_WR register, is already high then clearing the DAC_WR_TRIG bit, will write the values into the DAC_Limit_L and DAC_Limit_H registers for the DAC. b 7 b 0 D A C _ W R _ T R IG R E C _ M O D E D A C _ W R R e c o 1 : R E re g 0 : P C rd C is M R e g is te r D a ta S o O R D _ IN te r d a ta A /D c o n u r _ H s o v e c e a n d R E C O R D _ IN _ L u rc e r te r d a ta s o u r c e - d e fa u lt U n d e fin e d , r e a d a s " 0 " D A C W r ite T r ig g e r 0 ® 1 ® 0 : L a tc h D A C d a ta U n d e fin e d , r e a d a s " 0 " DAC Write and Record Source Register - DAC_WR D A C _ W R _ T R IG T h e e d g e w ill la tc h D A C lim it r e g is te r v a lu e . Note: In the DAC write data mode (high nibble of WDTS register is 0101b), the DAC_Limit_L and DAC_Limit_H registers will be the 16-bit DAC input data register at the falling edge of DAC_WR_TRIG. Otherwise, these two registers are used to define the 16-bit DAC output limit (repeated below). Rev. 1.10 42 August 5, 2011 HT82A836R REC_MODE=1:Writing to RECORD_IN_L register will only put the written data to an internal lower-order byte buffer (8-bit) and writing RECORD_IN_H will transfer the RECORD_IN_L and RECORD_IN_H registers content to isochronous in buffer. When record interrupt happened, firmware should write 16-bit 2¢s complement value to RECORD_IN_L and RECORD_IN_H (RECORD_U_EN=0) registers or write 8-bit m law value to RECORD_IN_H register (RECORD_U_EN=1). REC_MODE= ²1² Record data comes from the RECORD_IN_H and RECORD_IN_L registers REC_MODE= ²0² Record data comes from the PCM ADC (Default =0) The record write data format will be controlled by bit RECORD_U_EN of OPER_MODE register when REC_MODE= ²1². The record data write format as follow: RECORD_IN_L RECORD_IN_H RECORD_U_EN= 0 PCM (Low byte) PCM (High byte) RECORD_U_EN= 1 N/A m Law Example Program to Eliminate Pop Noise: System_Initial: ;----------------------------------------------------------; Avoid Pop Noise ;----------------------------------------------------------mov a,WDTS mov FIFO_TEMP,a ;Save WDTS value mov a,00001111b mov a,WDTS mov a,01010000b orm a,WDTS ;Enter DAC Write Data mode, high nibble of WDTS=0101b clr [02DH] ;Set DAC data low byte=00H mov a,80H mov [02EH],a ;Set DAC data high byte=80H ;Write 8000H to DAC set [02FH].3 clr [02FH].3 ;----------------------------------------------------------mov a,FIFO_TEMP ;Restore WDTS value mov WDTS,a ;Quit DAC Write Data mode ;----------------------------------------------------------- Rev. 1.10 43 August 5, 2011 HT82A836R Digital Programmable Gain Amplifier - PGA The device includes a fully integrated Programmable Gain Amplifier, otherwise known as the PGA. The PGA is a digital amplifier used to amplify the 16-bit data that comes from the PCM A/D Converter (REC_MODE (2FH.0)=0) or from the RECORD_IN_H and RECORD_IN_L (REC_MODE (2FH.0)=1). The PGA function is controlled using the PGA_CTRL register within which there is six bits to control the gain value. This gain value ranges from 0dB up to a maximum of 19.5dB, in steps of 0.5dB, and is selected using the PGA0~PGA5 bits. P G A 5 ~ P G A 0 P C M A /D 0 C o n v e rte r P G A 1 R E C O R D _ IN _ L R E C O R D _ IN _ H U S B R E C _ M O D PGA Block Diagram b 7 b 0 M U T E _ M K B A D C _ R E S E T P G A 5 P G A 4 P G A 3 P G A 2 P G A 1 P G A 0 P G A _ C T R L R e g is te r G a P G 0 0 in A 0 0 S 5 ~ 0 0 e le P G 0 0 0 0 : 1 0 0 1 1 0 0 1 1 0 1 0 : 1 1 1 1 1 0 1 1 c tio n C o n tr o l A 0 G a in - d B 0 0 0 .5 1 : 0 1 9 .0 1 9 .5 1 0 1 9 .5 : 1 9 .5 1 P C M A /D C o n v e rte r R e s e t C o n tro l 1 : R e s e t P C M A /D c o n v e rte r 0 : N o r m a l o p e r a tio n M ic r o p h o n e M u te C o n tr o l 1 : N o r m a l o p e r a tio n 0 : M ic r o p h o n e m u te d Programmable Gain Amplifier Control Register - PGA_CTRL Rev. 1.10 44 August 5, 2011 HT82A836R SPI Serial Interface After Power on, the contents of the SBDR register will be in an unknown condition while the SBCR register will default to the condition below: The device includes a single SPI Serial Interface. The SPI interface is a full duplex serial data link, originally designed by Motorola, which allows multiple devices connected to the same SPI bus to communicate with each other. The devices communicate using a master/slave technique where only the single master device can initiate a data transfer. A simple four line signal bus is used for all communication. CKS M1 0 1 M0 SBEN MLS CSEN WCOL TRF 1 0 0 0 0 0 Note that data written to the SBDR register will only be written to the TXRX buffer, whereas data read from the SBDR register will actually be read from the register. SPI Interface Communication Four lines are used for SPI communication known as SDI - Serial Data Input, SDO - Serial Data Output, SCK - Serial Clock and SCS - Slave Select. Note that the condition of the Slave Select line is conditioned by the CSEN bit in the SBCR control register. If the CSEN bit is high then the SCS line is active while if the bit is low then the SCS line will be in a floating condition. The following timing diagram depicts the basic timing protocol of the SPI bus. SPI Bus Enable/Disable To enable the SPI bus then CSEN=1 and SBEN=1, the SCK, SDI, SDO and SCS lines should all be zero, then wait for data to be written to the SBDR (TXRX buffer) register. For the Master Mode, after data has been written to the SBDR (TXRX buffer) register then transmission or reception will start automatically. When all the data has been transferred the TRF bit should be set. For the Slave Mode, when clock pulses are received on SCK, data in the TXRX buffer will be shifted out or data on SDI will be shifted in. SPI Registers There are two registers associated with the SPI Interface. These are the SBCR register which is the control register and the SBDR which is the data register. The SBCR register is used to setup the required setup parameters for the SPI bus and also used to store associated operating flags, while the SBDR register is used for data storage. To Disable the SPI bus SCK, SDI, SDO, SCS floating. SPI Operation All communication is carried out using the 4-line interface for both Master or Slave Mode. The timing diagram shows the basic operation of the bus. D a ta B u s S B D R ( R e c e iv e d D a ta R e g is te r ) D 7 D 6 D 5 D 4 D 3 D 2 D 1 D 0 M S D O U X B u ffe r S B E N M L S M In te r n a l B a u d R a te C lo c k S C K a n d , s ta rt E N a n d , s ta rt C lo c k P o la r ity U X M S D O S D I U X T R F C 0 C 1 C 2 M a s te r o r S la v e A N D In te r n a l B u s y F la g S B E N a n d , s ta rt E N W r ite S B D R W r ite S B D R S B E N W C O L F la g E n a b le /D is a b le W r ite S B D R S C S M a s te r o r S la v e S B E N C S E N SPI Block Diagram Rev. 1.10 45 August 5, 2011 HT82A836R b 7 C K S b 0 M 1 M 0 S B E N M L S C S E N W C O L T R F S B C R R e g is te r T r a n s m itt/R e c e iv e F la g 0 : N o t c o m p le te 1 : T r a n s m is s io n /r e c e p tio n c o m p le te W r ite C o llis io n B it 0 : C o llis io n fr e e 1 : C o llis io n d e te c te d S e le c tio n S ig n a l E n a b le /D is a b le B it 0 : S C S flo a tin g 1 : E n a b le M S B /L S B F ir s t B it 0 : L S B s h ift fir s t 1 : M S B s h ift fir s t S e r ia l B 0 : D is a b 1 : E n a b D e p e u s E n a b le /D is a b le B it le le n d e n t u p o n C S E N b it M a s te r /S la M 1 M 0 0 0 0 1 1 0 1 1 v e /B a u d R a te B its M a s M a s M a s S la v te r, te r, te r, e m b a u d ra te : fS b a u d ra te : fS b a u d ra te : fS o d e IO IO IO /4 /1 6 C lo c k S o u r c e S e le c t B it 0 : f S IO = f S Y S / 2 1 : f S IO = f S Y S SPI Interface Control Register S B E N = 1 , C S E N = 0 a n d w r ite d a ta to S B D R ( If p u lle d - h ig h ) S C S S B E N = C S E N = 1 a n d w r ite d a ta to S B D R S C K S D I S D O D 7 /D 0 D 6 /D 1 D 5 /D 2 D 4 /D 3 D 3 /D 4 D 2 /D 5 D 1 /D 6 D 0 /D 7 D 7 /D 0 D 6 /D 1 D 5 /D 2 D 4 /D 3 D 3 /D 4 D 2 /D 5 D 1 /D 6 D 0 /D 7 S C K SPI Bus Timing The CSEN bit in the SBCR register controls the overall function of the SPI interface. Setting this bit high, will enable the SPI interface by allowing the SCS line to be active, which can then be used to control the SPI interface. If the CSEN bit is low, the SPI interface will be disabled and the SCS line will be in a floating condition and can therefore not be used for control of the SPI interface. The SBEN bit in the SBCR register must also be high which will change the pin function from a standard I/O to an SPI function pin. If in the Master Mode the SCK line will be either high or low depending upon the clock polarity configuration option. If in the Slave Mode the SCK line will be in a floating condition. If SBEN is low then the bus will be disabled. The SBEN bit determines if pins PC4~PC7 are used as normal I/O pins or as SPI function pins. If this bit is high then the pins will be SPI function pins and here pin SCS will go low if CSEN=1. If the bit is low then the pins will function as normal I/O pins. Note that when SBEN=1, then any pull-high resistors connected to pins PC4~PC7 will be disconnected therefore the user hardware should ensure that external pull-high resistors are added to the SPI pins if necessary. If CSEN = 0 then the SCS pin will be in a floating state. The SPI clock polarity is controlled using the SIO_CPOL bit in the MODE_CTRL register. If SIO_CPOL = 1, then the rising edge will be selected. Otherwise if SIO_CPOL = 0, the falling edge will be selected. Rev. 1.10 46 August 5, 2011 HT82A836R the TXRX register, then wait for the master clock and SCS signal. After this goto step 6. For read operations: the data transferred in on the SDI line will be stored in the TXRX buffer until all the data has been received at which point it will be latched into the SBDR register. Step 6. Check the WCOL bit, if set high then a collision error has occurred so return to step5. If equal to zero then go to the following step. Step 7. Check the TRF bit or wait for an SBI serial bus interrupt. Step 8. Read data from the SBDR register. Step 9. Clear TRF Step10. Goto step 5 In the Master Mode the Master will always generate the clock signal. The clock and data transmission will be initiated after data has been written to the SBDR register. In the Slave Mode, the clock signal will be received from an external master device for both data transmission or reception. The following sequences show the order to be followed for data transfer in both Master and Slave Mode: · Master Mode: Step 1. Select the clock source using the CKS bit in the SBCR control register. Step 2. Setup the M0 and M1 bits in the SBCR control register to select the Master Mode and the required Baud rate. Values of 00, 01 or 10 can be selected. Step 3. Setup the CSEN bit and setup the MLS bit to choose if the data is MSB or LSB first, this must be same as the Slave device. Step 4. Setup the SBEN bit in the SBCR control register to enable the SPI interface. PC4~PC7 are SPI function pins (pin SCS will go low if CSEN=1). SBEN= ²0² PC4~PC7 are general purpose I/O Port pins (Default) Note: · Step 5. For write operations: write the data to the SBDR register, which will actually place the data into the TXRX buffer. Then use the SCK and SCS lines to output the data. After this goto to step 6. For read operations: the data transferred in on the SDI line will be stored in the TXRX buffer until all the data has been received at which point it will be latched into the SBDR register. (1) If SBEN=²1², the pull-high resistor of PC4~PC7 will be disable. When this happens, the user should add external pull-high resistors to the SPI related pins if necessary (EX: pin SCS). (2) If CSEN=²0², the SCS pin will enter a floating state. The SPI cock polarity controlled by SIO_CPOL bit of MODE_CTRL register. If SIO_CPOL =²1², rising edge (CLK) will be selected. Otherwise SIO_CPOL=²0², falling edge (CLK) will be selected. Step 6. Check the WCOL bit, if set high then a collision error has occurred so return to step5. If equal to zero then go to the following step. Error Detection The WCOL bit in the SBCR register is provided to indicate errors during data transfer. The bit is set by the Serial Interface but must be cleared by the application program. This bit indicates a data collision has occurred which happens if a write to the SBDR register takes place during a data transfer operation and will prevent the write operation from continuing. The bit will be set high by the Serial Interface but has to be cleared by the user application program. The overall function of the WCOL bit can be disabled or enabled by a SIO_WCOL bit of MODE_CTRL register. Step 7. Check the TRF bit or wait for an SBI serial bus interrupt. Step 8. Read data from the SBDR register. Step 9. Clear TRF. Step10. Goto step 5. · Slave Mode: Step 1. The CKS bit has a don¢t care value in the slave mode. Step 2. Setup the M0 and M1 bits to 00 to select the Slave Mode. The CKS bit is don¢t care. Step 3. Setup the CSEN bit and setup the MLS bit to choose if the data is MSB or LSB first, this must be same as the Master device. Step 4. Setup the SBEN bit in the SBCR control register to enable the SPI interface. Step 5. For write operations: write data to the SBCR register, which will actually place the data into Rev. 1.10 SBEN= ²1² Programming Considerations When the device is placed into the Power Down Mode note that data reception and transmission will continue. The TRF bit is used to generate an interrupt when the data has been transferred or received. 47 August 5, 2011 HT82A836R Mode Control Register The MODE_CTRL register is used to control DAC and ADC operation mode and SPI function. Note that the WCOL and CSEN bits are in the SBCR register. SPI usage example: SPI_Test: clr UCC.@UCC_SYSCLK set SIO_CSEN clr SIO_CPOL ;Master Mode, SCLK=fSIO clr M1 clr M0 ;-------------clr CKS clr TRF clr TRF_INT set MLS set CSEN set SBEN if POLLING_MODE clr ESII ;WRITE INTO ²WRITE ENABLE² INSTRUCTION MOV A,OP_WREN MOV SBDR,A $0: snz TRF jmp $0 clr TRF else set ESII ;WRITE INTO ²WRITE ENABLE² INSTRUCTION MOV A,OP_WREN MOV SBDR,A $0: snz TRF_INT jmp $0 clr TRF_INT endif ;12MHz SYSCLK ;SPI Chip Select Function Enable ;falling edge change data ;fSIO=fSYS/2 ;clear TRF flag ;clear Interrupt SPI flag ;MSB shift first ;Chip Select Enable ;SPI Enable, SCS will go low ;SPI Interrupt Disable ;SPI Interrupt Enable ;set at SPI Interrupt b 7 R e c o rd _ F re q b 0 S IO _ C S E N S IO _ W C O L S IO _ C P O L A D _ E N B P L A Y _ M O D E D A _ R _ E N B D A _ L _ E N B M O D E _ C T R L R e g is te r D A C L e ft C h a n n e l C o n tro l 1 : D is a b le 0 : E n a b le - d e fa u lt D A C R ig h t C h a n n e l C o n tr o l 1 : D is a b le 0 : E n a b le - d e fa u lt A /D C o n v e rte r C o n tro l 1 : P o w e r-d o w n 0 : P o w e r - o n - d e fa u lt D A C P la y M o d e C o n tr o l 1 : 8 k H z /1 6 - b it 0 : 4 8 k H z /1 6 - b it - d e fa u lt S P I C lo c k P o la r ity C o n tr o l 1 : R is in g e d g e 0 : F a llin g e d g e - d e fa u lt S P I W C O L B it C o n tr o l 1 : W C O L b it e n a b le d 0 : W C O L b it d is a b le d - d e fa u lt S P I C S E N B it C o n tr o l 1 : C S E N b it e n a b le d 0 : C S E N b it d is a b le d - d e fa u lt R e c o rd F re q u e n c y C o n tro l 1 : 1 6 k H z 2 : 8 k H z - d e fa u lt Mode Control Register - MODE_CTRL Rev. 1.10 48 August 5, 2011 HT82A836R Operation Mode Control Register The OPER_MODE register is used to control certain operational operational modes. The operation mode is used to control the m law compander enable/disable for the speaker and microphone data. b 7 b 0 P L A Y _ U _ E N R E C O R D _ U _ E N O P E R _ M O D E R e g is te r P la y m L a w C o m p r e s s io n C o n tr o l 1 : C o m p r e s s io n e n a b le d 0 : C o m p r e s s io n d is a b le d - d e fa u lt R e c o rd m L a w E x p a n d e r C o n tro l 1 : E x p a n d e r e n a b le d 0 : E x p a n d e r d is a b le d - d e fa u lt U n a v a ila b le Operation Mode Control Register - OPER_MODE Play/Record Data The Play and Record data for the device is contained in 4 Play registers and 2 Record registers. The play/record interrupt will be activated when play/record data in the PLAY_DATA or RECORD_DATA registers is valid. The PLAY_DATA/RECORD_DATA registers will latch data until the next interrupt is generated. The DAC PLAY_DATA register contains an unsigned value with a range of 0~FFFFH. The RECORD_DATA is stored in 2¢s complement format with a range of 8000H~7FFFH. The update rate of the PCM ADC RECORD_DATA is 8kHz with the Record_Freq bit in the MODE_CTRL register is equal to 0, or 16kHz if the bit is set to 1. The update rate for the PLAY_DATA is 48kHz, if the PLAY_MODE bit in the MODE_CTRL register is equal to 0, or 8kHz if the bit is equal to 1. All of the PLAY and RECORD registers are read only. Name b7 b6 b5 b4 b3 b2 b1 b0 PLAY_DATAL_L PL_D7 PL_D6 PL_D5 PL_D4 PL_D3 PL_D2 PL_D1 PL_D0 PLAY_DATAL_H PL_D15 PL_D14 PL_D13 PL_D12 PL_D11 PL_D10 PL_D9 PL_D8 PLAY_DATAR_L PR_D7 PR_D6 PR_D5 PR_D4 PR_D3 PR_D2 PR_D1 PR_D0 PLAY_DATAR_H PR_D15 PR_D14 PR_D13 PR_D12 PR_D11 PR_D10 PR_D9 PR_D8 RECORD_DATA_L R_D7 R_D6 R_D5 R_D4 R_D3 R_D2 R_D1 R_D0 RECORD_DATA_H R_D15 R_D14 R_D13 R_D12 R_D11 R_D10 R_D9 R_D8 The play data format is controlled by bit PLAY_U_EN in the OPER_MODE register. PLAY_DATAL_L PLAY_DATAL_H PLAY_DATAR_L PLAY_DATAR_H PLAY_U_EN=0 PCM (Left Channel Low Byte) PCM (Left Channel High Byte) PCM (Right Channel Low Byte) PCM (Right Channel High Byte) PLAY_U_EN=1 N/A m Law (Left Channel) N/A m Law (Right Channel) The record data registers RECORD_DATA_L/RECORD_DATA_H will not be affected by bit RECORD_U_EN in the OPER_MODE register. The record data registers RECORD_DATA_L/RECORD_DATA_H are in PCM format. Rev. 1.10 49 August 5, 2011 HT82A836R Pulse Width Modulator The overall PWM output enable/disable is controlled using the PWMC register which acts like an on/off switch for each PWM output. The device contains a 2 channel Pulse Width Modulator function, more commonly known as PWM. Useful for such applications such as motor speed control, the PWM function provides outputs with a fixed frequency but with a duty cycle that can be varied by setting particular values into the corresponding PWM registers. PWM Modulation fSYS/64 for (6+2) bits mode fSYS/128 for (7+1) bits mode The device has two PWM outputs for which two 8-bit PWM registers are provided and are known as PWM0 and PWM1. It is in these registers, that the 8-bit value, which represents the overall duty cycle of one modulation cycle of the output waveform, should be placed. To increase the PWM modulation frequency, each modulation cycle is modulated into two or four individual modulation sub-sections, known as the 7+1 mode or 6+2 respectively. The mode selection is made using the PWMC register. Note that it is only necessary to write the required modulation value into the corresponding PWM0 or PWM1 register, as the subdivision of the waveform into its sub-modulation cycles is implemented automatically within the microcontroller hardware. For all devices, the PWM clock source is the system clock fSYS. Y S fSYS/256 [PWM]/256 6+2 PWM Mode Each full PWM cycle, as it is controlled by an 8-bit PWM register, has 256 clock periods. However, in the 6+2 PWM mode, each PWM cycle is subdivided into four individual sub-cycles known as modulation cycle 0 ~ modulation cycle 3, denoted as i in the table. Each one of these four sub-cycles contains 64 clock cycles. In this mode, a modulation frequency increase of four is achieved. The 8-bit PWM register value, which represents the overall duty cycle of the PWM waveform, is divided into two groups. The first group which consists of bit2~bit7 is denoted here as the DC value. The second group which consists of bit0~bit1 is known as the AC value. In the 6+2 PWM mode, the duty cycle value of each of the four modulation sub-cycles is shown in the following table. This method of dividing the original modulation cycle into a further 2 or 4 sub-cycles enables the generation of higher PWM frequencies, which allow a wider range of applications to be served. As long as the periods of the generated PWM pulses are less than the time constants of the load, the PWM output will be suitable for driving, as such long time constant loads will average out the pulses of the PWM output. The difference between what is known as the PWM cycle frequency and the PWM modulation frequency should be understood. As the PWM clock is the system clock, fSYS, and as the PWM value is 8-bits wide, the overall PWM cycle frequency is fSYS/256. However when in the 7+1 mode of operation, the PWM modulation frequency will be fSYS/128, while the PWM modulation frequency for the 6+2 mode of operation will be fSYS/64. fS PWM Cycle PWM Cycle Frequency Duty Parameter AC (0~3) Modulation cycle i (i=0~3) i<AC i³AC DC (Duty Cycle) DC+1 64 DC 64 6+2 Mode Modulation Cycle Values The following diagram illustrates the waveforms associated with the 6+2 mode of PWM operation. It is important to note how the single PWM cycle is subdivided into 4 individual modulation cycles, numbered from 0~3 and how the AC value is related to the PWM value. /2 [P W M ] = 1 0 0 P W M 2 5 /6 4 2 5 /6 4 2 5 /6 4 2 5 /6 4 2 5 /6 4 2 6 /6 4 2 5 /6 4 2 5 /6 4 2 5 /6 4 2 6 /6 4 2 6 /6 4 2 6 /6 4 2 5 /6 4 2 5 /6 4 2 6 /6 4 2 6 /6 4 2 6 /6 4 2 6 /6 4 2 5 /6 4 2 6 /6 4 [P W M ] = 1 0 1 P W M [P W M ] = 1 0 2 P W M [P W M ] = 1 0 3 P W M P W M m o d u la tio n p e r io d : 6 4 /f S Y S P W M c y c le : 2 5 6 /fS Y S (6+2) PWM Mode Output Waveform Rev. 1.10 50 August 5, 2011 HT82A836R b 7 b 0 P W M R e g is te r A C v a lu e D C v a lu e (6 + 2 ) M o d e Pulse Width Modulation Registers for (6+2) PWM Mode 7+1 PWM Mode Parameter Each full PWM cycle, as it is controlled by an 8-bit PWM register, has 256 clock periods. However, in the 7+1 PWM mode, each PWM cycle is subdivided into two individual sub-cycles known as modulation cycle 0 ~ modulation cycle 1, denoted as i in the table. Each one of these two sub-cycles contains 128 clock cycles. In this mode, a modulation frequency increase of two is achieved. The 8-bit PWM register value, which represents the overall duty cycle of the PWM waveform, is divided into two groups. The first group which consists of bit1~bit7 is denoted here as the DC value. The second group which consists of bit0 is known as the AC value. In the 7+1 PWM mode, the duty cycle value of each of the two modulation sub-cycles is shown in the following table. fS Y S AC (0~1) DC (Duty Cycle) i<AC DC+1 128 i³AC DC 128 Modulation cycle i (i=0~1) 7+1 Mode Modulation Cycle Values The following diagram illustrates the waveforms associated with the 7+1 mode of PWM operation. It is important to note how the single PWM cycle is subdivided into 2 individual modulation cycles, numbered from 0~1 and how the AC value is related to the PWM value in the 7+1 PWM Mode. /2 [P W M ] = 1 0 0 P W M 5 0 /1 2 8 5 0 /1 2 8 5 0 /1 2 8 5 1 /1 2 8 5 0 /1 2 8 5 1 /1 2 8 5 1 /1 2 8 5 1 /1 2 8 5 1 /1 2 8 5 1 /1 2 8 5 2 /1 2 8 [P W M ] = 1 0 1 P W M [P W M ] = 1 0 2 P W M [P W M ] = 1 0 3 P W M 5 2 /1 2 8 P W M m o d u la tio n p e r io d : 1 2 8 /fS Y S P W M c y c le : 2 5 6 /fS Y S (7+1) PWM Mode Output Waveform b 7 b 0 P W M R e g is te r A C v a lu e D C v a lu e (7 + 1 ) M o d e Pulse Width Modulation Registers for (7+1) PWM Mode Rev. 1.10 51 August 5, 2011 HT82A836R PWM Output Control Control of the two PWM outputs is achieved using the PWMC register. Bits within this register control the on/off function of the individual PWM outputs as well as their chosen mode type. Note than when the PWM outputs are disabled they will remain in a low state. b 7 b 0 P W M _ M O D 1 P W M _ M O D 0 P W M _ E N 1 P W M _ E N 0 P W M C R e g is te r P W M 0 O u tp u t E n a b le 1 : P W M 0 o u tp u t e n a b le d 0 : P W M 0 d is a b le d P W M 1 O u tp u t E n a b le 1 : P W M 1 o u tp u t e n a b le d 0 : P W M 1 d is a b le d U n d e fin e d , r e a d a s " 0 " P W M 0 M o d e C o n tro l 1 : P W M 0 in 7 + 1 m o d e 0 : P W M 0 in 6 + 2 m o d e P W M 1 M o d e C o n tro l 1 : P W M 1 in 7 + 1 m o d e 0 : P W M 1 in 6 + 2 m o d e U n d e fin e d , r e a d a s " 0 " PWM Control Register - PWMC PWM Programming Example The following sample program shows how the PWM outputs are setup and controlled. Before use the corresponding PWM output configuration options must first be selected. mov mov clr set : : clr a,64h PWM0,a PWMC.PWM_MOD0 PWMC.PWM_EN0 ; setup PWM0 value of 100 decimal which is 64H PWMC.PWM_EN0 ; disable PWM0 output Rev. 1.10 ; setup pin PWM0 to the 6+2 PWM Mode ; enable PWM0 output 52 August 5, 2011 HT82A836R Analog to Digital Converter In the following tables, D0~D11 are the A/D conversion data result bits. The need to interface to real world analog signals is a common requirement for many electronic systems. However, to properly process these signals by a microcontroller, they must first be converted into digital signals by A/D converters. By integrating the A/D conversion electronic circuitry into the microcontroller, the need for external components is reduced significantly with the corresponding follow-on benefits of lower costs and reduced component space requirements. Register Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 ADRL D3 D1 D0 ¾ ¾ ¾ ¾ ADRH D11 D10 D9 D8 D7 D6 D5 D4 D2 A/D Converter Data Register A/D Converter Control Register - ADCR A/D Overview To control the function and operation of the A/D converter, a control register known as ADCR is provided. This 8-bit register defines functions such as the selection of which analog channel is connected to the internal A/D converter, power on/off the A/D converter, control the start function and monitoring the A/D converter end of conversion status. The device contains a 6-channel analog to digital converter which can directly interface to external analog signals, such as that from sensors or other control signals and convert these signals directly into a 12-bit digital value. The following diagram shows the overall internal structure of the A/D converter, together with its associated registers. One section of this register contains the bits ACS2~ACS0 which define the channel number. As each of the devices contains only one actual analog to digital converter circuit, each of the individual 6 analog inputs must be routed to the converter. It is the function of the ACS2~ACS0 bits in the ADCR register to determine which analog channel is actually connected to the internal A/D converter. A/D Converter Data Registers - ADRL, ADRH For the HT82A836R device, which has a 12-bit A/D converter, two registers are required, a high byte register, known as ADRH, and a low byte register, known as ADRL, to store the 12-bit analog to digital conversion value. After the conversion process takes place, these registers can be directly read by the microcontroller to obtain the digitised conversion value. Note that only the high byte register ADRH utilises its full 8-bit contents. The low byte register utilises only 4 bits of its 8-bit contents as it contains only the lowest bit of the 12-bit converted value. The ADCR control register also contains the PCR2~PCR0 bits which determine power on/off the A/D converter and. If the PCR2~PCR0 bits are all set to zero, then the internal A/D converter circuitry will be powered off to reduce the power consumption. Any other non-zero combination on the PCR2~PCR0 bits will power-on the the A/D converter will be power on which will consume a certain amount of power. C lo c k D iv id e R a tio A D C S o u rc e fS Y S /2 A C S R ¸ N A V A N 0 A N 1 A N 2 A N 3 A N 4 A N 5 R e g is te r D D 4 A /D r e fe r e n c e v o lta g e A D R L A D C A D R H A /D D a ta R e g is te r s A V S S 4 G ro u n d A D C S 0 ~ A D C S 2 C h a n n e l S e le c t B its S T A R T E O C B P C R 0 ~ P C R 2 S ta r t B it E n d o f C o n v e r s io n B its A /D P o w e r O n /O ff C o n tro l A D C R R e g is te r A/D Converter Structure Rev. 1.10 53 August 5, 2011 HT82A836R A/D Converter Clock Source Register - ACSR The START bit in the ADCR register is used to start and reset the A/D converter. When the microcontroller sets this bit from low to high and then low again, an analog to digital conversion cycle will be initiated. When the START bit is brought from low to high but not low again, the EOCB bit in the ADCR register will be set to a ²1² and the analog to digital converter will be reset. It is the START bit that is used to control the overall on/off operation of the internal analog to digital converter. The clock source for the A/D converter, which originates from the system clock fSYS, is first divided by a division ratio, the value of which is determined by the ADCS1 and ADCS0 bits in the ACSR register. Although the A/D clock source is determined by the system clock fSYS, and by bits ADCS1 and ADCS0, there are some limitations on the maximum A/D clock source speed that can be selected. The EOCB bit in the ADCR register is used to indicate when the analog to digital conversion process is complete. This bit will be automatically set to ²0² by the microcontroller after a conversion cycle has ended. In addition, the corresponding A/D interrupt request flag will be set in the interrupt control register, and if the interrupts are enabled, an appropriate internal interrupt signal will be generated. This A/D internal interrupt signal will direct the program flow to the associated A/D internal interrupt address for processing. If the A/D internal interrupt is disabled, the microcontroller can be used to poll the EOCB bit in the ADCR register to check whether it has been cleared as an alternative method of detecting the end of an A/D conversion cycle. b 7 S T A R T E O C B P C R 2 P C R 1 P C R 0 A C S 2 A C S 1 b 0 A C S 0 A/D Input Pins All of the A/D analog input pins are independent analog inputs and not shared with other I/O pins. Bits PCR2~PCR0 in the ADCR register, not configuration options, determine whether the A/D converter is powered on or powered down. The AVDD4 power supply pin is used as the A/D converter reference voltage, and as such analog inputs must not be allowed to exceed this value. Appropriate measures should also be taken to ensure that the AVDD4 pin remains as stable and noise free as possible. A D C R R e g is te r S e le c t A /D c h a n n e l A A C S 2 A C S 1 0 0 0 0 0 1 0 1 1 0 1 0 O th e rs C S 0 0 1 0 1 0 1 : A N : A N : A N : A N : A N : A N : U n A /D p o w e r O n /O ff C o n tro l P C R 2 P C R 1 P C R 0 : A /D 0 0 0 0 (P O R ) 1 2 3 4 5 d e fin e d , m u s t n o t b e u s e d c o n v e rte r p o w e re d d o w n O th e r s v a lu e s : A /D c o n v e r te r p o w e r e d o n E n d o f A /D c o n v e r s io n fla g 1 : n o t e n d o f A /D c o n v e r s io n - A /D c o n v e r s io n w a itin g o r in p r o g r e s s 0 : e n d o f A /D c o n v e r s io n - A /D c o n v e r s io n e n d e d S ta r t th e A /D c o n v e r s io n 0 ® 1 ® 0 : S ta rt 0 ® 1 : R e s e t A /D c o n v e rte r a n d s e t E O C B to "1 " ADCR Register b 7 T E S T b 0 A D C S 1 A D C S 0 A C S R R e g is te r S e le c t A /D c o n v e r te A D C S 0 A D C S 1 0 0 1 0 0 1 1 1 r c lo c k s o u r c e : s y : s y : s y : u n s te s te s te d e m c lo c k /2 c lo c k /8 m c lo c k /3 2 fin e d m N o t im p le m e n te d , r e a d a s " 0 " F o r te s t m o d e u s e o n ly A/D Converter Clock Source Register Rev. 1.10 54 August 5, 2011 HT82A836R A/D converter interrupt function is active. The master interrupt control bit, EMI, in the INTC0 interrupt control register must be set to ²1², the multi-function 1 interrupt control bit, EMF1I, in the INTC1 register and the A/D converter interrupt bit, EADI, in the MFI1C register must also be set to ²1². Initialising the A/D Converter The internal A/D converter must be initialised in a special way. Each time the A/D channel selection bits are modified by the program, the A/D converter must be re-initialised. If the A/D converter is not initialised after the channel selection bits are changed, the EOCB flag may have an undefined value, which may produce a false end of conversion signal. To initialise the A/D converter after the channel selection bits have changed, then, within a time frame of one to ten instruction cycles, the START bit in the ADCR register must first be set high and then immediately cleared to zero. This will ensure that the EOCB flag is correctly set to a high condition. · Step 5 The analog to digital conversion process can now be initialised by setting the START bit in the ADCR register from ²0² to ²1² and then to ²0² again. Note that this bit should have been originally set to ²0². · Step 6 To check when the analog to digital conversion process is complete, the EOCB bit in the ADCR register can be polled. The conversion process is complete when this bit goes low. When this occurs the A/D data registers ADRL and ADRH can be read to obtain the conversion value. As an alternative method if the interrupts are enabled and the stack is not full, the program can wait for an A/D interrupt to occur. Summary of A/D Conversion Steps The following summarises the individual steps that should be executed in order to implement an A/D conversion process. · Step 1 Note: When checking for the end of the conversion process, if the method of polling the EOCB bit in the ADCR register is used, the interrupt enable step above can be omitted. Select the required A/D conversion clock by correctly programming bits ADCS1 and ADCS0 in the ACSR register. · Step 2 Select which channel is to be connected to the internal A/D converter by correctly programming the ACS2~ACS0 bits which are also contained in the ADCR register. The following timing diagram shows graphically the various stages involved in an analog to digital conversion process and its associated timing. The setting up and operation of the A/D converter function is fully under the control of the application program as there are no configuration options associated with the A/D converter. After an A/D conversion process has been initiated by the application program, the microcontroller internal hardware will begin to carry out the conversion, during which time the program can continue with other functions. · Step 3 Select A/D converter power on or power down by programming the PCR2~PCR0 bits in the ADCR register. Note that this step can be combined with Step 2 into a single ADCR register programming operation. · Step 4 If the interrupts are to be used, the interrupt control registers must be correctly configured to ensure the S T A R T b it s e t h ig h w ith in o n e to te n in s tr u c tio n c y c le s a fte r th e P C R 0 ~ P C R 2 b its c h a n g e s ta te S T A R T A /D E O C B s a m p lin g t im e 3 2 tA P C R 2 ~ P C R 0 A /D s a m p lin g tim e 3 2 tA D 0 0 0 B A /D s a m p lin g tim e 3 2 tA D 0 1 1 B D 1 0 0 B 0 0 0 B A /D c o n v e r te r is p o w e r e d o ff to r e d u c e p o w e r c o n s u m p tio n A C S 2 ~ A C S 0 0 1 0 B 0 0 0 B 0 0 1 B S ta rt o f A /D c o n v e r s io n S ta rt o f A /D c o n v e r s io n S ta rt o f A /D c o n v e r s io n 0 0 0 B P o w e r-o n R e s e t R e s e t A /D c o n v e rte r R e s e t A /D c o n v e rte r E n d o f A /D c o n v e r s io n S e le c t a n a lo g c h a n n e l tA A /D N o te : A /D c lo c k m u s t b e fS Y S /2 , fS Y S R e s e t A /D c o n v e rte r E n d o f A /D c o n v e r s io n tA D C c o n v e r s io n tim e /8 o r fS Y S D o n 't c a r e A /D E n d o f A /D c o n v e r s io n tA D C c o n v e r s io n tim e A /D D C c o n v e r s io n tim e /3 2 A/D Conversion Timing Rev. 1.10 55 August 5, 2011 HT82A836R Programming Considerations The exception to this is where the channel selection bits are all cleared, in which case the A/D converter is not required to be re-initialised. When programming, special attention must be given to the A/D channel selection bits in the ADCR register. This ability to reduce power by turning off the internal A/D function by clearing the A/D channel selection bits may be an important consideration in battery powered applications. A/D Programming Example The following two programming examples illustrate how to setup and implement an A/D conversion. In the first example, the method of polling the EOCB bit in the ADCR register is used to detect when the conversion cycle is complete, whereas in the second example, the A/D interrupt is used to determine when the conversion is complete. Another important programming consideration is that when the A/D channel selection bits change value the A/D converter must be re-initialised. This is achieved by pulsing the START bit in the ADCR register immediately after the channel selection bits have changed state. Example: using an EOCB polling method to detect the end of conversion for the HT82A836R. clr EADI ; disable ADC interrupt mov a,00000001 B mov ACSR,a ; setup the ACSR register to select fSYS/8 as the A/D ; clock mov a,00100000B ; setup the ADCR register to power up the A/D ; converter mov ADCR,a ; and select AN0 to be connected to the A/D ; converter : ; the following START signal (0-1-0) must be issued : ; within 10 instruction cycles : Start_conversion: clr START Set START ; reset A/D clr START ; start A/D Polling_EOC: sz EOCB ; poll the ADCR register EOCB bit to detect end ; of A/D conversion jmp polling_EOC ; continue polling mov a,ADRH ; read conversion result high byte value from the ; ADRH register Adr_buffer_h,a ; save result to user defined memory mov a,ADRL ; read conversion result low byte value from the ; ADRL register mov adr_buffer_l,a ; save result to user defined memory : : jmp start_conversion ; start next A/D conversion Rev. 1.10 56 August 5, 2011 HT82A836R Example: using an interrupt method to detect the end of conversion for the HT82A836R. clr EADI ; disable ADC interrupt mov a,00000001B mov ACSR,a ; setup the ACSR register to select fSYS/8 as the A/D ; clock mov a,00100000B ; setup the ADCR register to power up the A/D ; converter mov ADCR,a ; and select AN0 to be connected to the A/D ; converter : ; the following START signal (0-1-0) must be issued : : Start_conversion: clr ADF set EMF1I set EADI set EMI clr START set START clr START : : : ; ADC interrupt service routine ADC_ISR: clr ADF mov acc_stack,a mov a,STATUS mov status_stack,a : : mov a,ADRH mov adr_buffer_h,a mov a,ADRL mov adr_buffer_l,a : : EXIT_INT_ISR: mov a,status_stack mov STATUS,a mov a,acc_stack reti Rev. 1.10 ; within 10 instruction cycles ; ; ; ; clear ADC interrupt request flag Multi function 1 interrupt Enable enable ADC interrupt enable global interrupt ; reset A/D ; start A/D ; clear ADC interrupt request flag ; save ACC to user defined memory ; save STATUS to user defined memory ; ; ; ; ; ; read ADRH save read ADRL save conversion result high byte value from the register result to user defined register conversion result low byte value from the register result to user defined register ; restore STATUS from user defined memory ; restore ACC from user defined memory 57 August 5, 2011 HT82A836R A/D Transfer Function As the HT82A836R device contains a 12-bit A/D converter, their full-scale converted digitised value is equal to FFFH. Since the full-scale analog input value is equal to the voltage, this gives a single bit analog input value of VDD/4096. The following graphs show the ideal transfer function between the analog input value and the digitised output value for the A/D converters. Note that to reduce the quantisation error, a 0.5 LSB offset is added to the A/D Converter input. Except for the digitised zero value, the subsequent digitised values will change at a point 0.5 LSB below where they would change without the offset, and the last full scale digitised value will change at a point 1.5 LSB below the VDD level. 1 .5 L S B F F F H F F E H F F D H A /D C o n v e r s io n R e s u lt 0 .5 L S B 0 3 H 0 2 H 0 1 H 0 1 2 4 0 9 3 3 4 0 9 4 4 0 9 5 4 0 9 6 ( V D D ) 4 0 9 6 A n a lo g In p u t V o lta g e Ideal A/D Transfer Function Rev. 1.10 58 August 5, 2011 HT82A836R Configuration Options Configuration options refer to certain options within the MCU that are programmed into the OTP Program Memory device during the programming process. During the development process, these options are selected using the HT-IDE software development tools. As these options are programmed into the device using the hardware programming tools, once they are selected they cannot be changed later by the application software. All options must be defined for proper system function, the details of which are shown in the table. No. Options I/O Options 1 PA0~PA7: pull-high enable or disable (bit option) 2 PB0~PB7: pull-high enable or disable (bit option) 3 PC0~PC7: pull-high enable or disable (nibble option) 4 PD0~PD7: pull-high enable or disable (bit option) 5 PE0~PE7: pull-high enable or disable (bit option) 6 PF0~PF3: pull-high enable or disable (bit option) 7 PA0~PA7: wake-up enable or disable (bit option) 8 PB0~PB7: wake-up enable or disable (bit option) 9 PC0~PC7: wake-up enable or disable (nibble option) 10 PD0~PD7: wake-up enable or disable (bit option) 11 PE0~PE7: wake-up enable or disable (bit option) 12 PF0~PF3: wake-up enable or disable (bit option) 13 PA0~PA7: CMOS or NMOS output type (bit option) Watchdog Options 14 WDT: enable or disable 15 CLRWDT instructions: one or two instructions 16 WDT Clock Source: fSYS/4 or WDT oscillator LVR Options 17 LVR function: enable or disable TBHP Options 18 TBHP enable or disable Rev. 1.10 59 August 5, 2011 HT82A836R Application Circuits L 2 1 V D D U S B 2 A V D D 2 B e a d F e r r ite C O N 1 V D D V D D 2 0 .1 m F U S B + 3 U S B - 1 V S S 3 3 W B e a d 0 .1 m F 4 7 p F 1 k W L 1 1 V D D 2 D D 1 0 m F R E S E T 1 0 m F 0 .1 m F D V D D 0 .1 m F A V D D 1 B e a d F e r r ite 1 W A V D D 1 B u z z e r 0 .1 m F A V S S 2 1 0 m F V P N P 2 B e a d F e r r ite U S B D P U S B D N 4 7 p F 2 V 3 3 O 4 7 W 1 0 m F P C 0 L 5 1 1 .5 k W 3 3 W 4 V S S 0 .1 m F 1 0 0 k W S W 1 R e s e t 0 .1 m F 3 2 1 0 7 6 5 4 3 2 1 0 T 1 D D 2 U T R E S E D V D D U S B D U S B D V 3 3 O D V S S P F P F P F P F P A P A P A P A P A P A P A P A A V R O N P 1 L 3 1 V D D 2 A V D D 3 T 1 N P 1 P h o n e ja c k S te r e o 6 1 6 2 6 3 6 4 6 5 6 6 R E S E D V D D U S B D U S B D V 3 3 O D V S S 3 2 1 0 V A G A V S S 3 S P K M u te 4 5 6 7 8 9 1 0 1 1 1 2 S 4 D 3 R e f 1 3 1 4 1 5 1 6 1 7 1 8 IC _ IN D 1 D 4 H T 8 2 A 8 3 6 R S 4 D 3 R e f P C 2 0 S 1 P 1 9 O S C O O S C I P E 0 P E 1 P E 2 P E 3 P E 4 P E 5 P E 6 P E 7 /IN T D V S S 2 P D 0 P D 1 P D 2 P D 3 P D 4 P D 5 P D 6 P D 7 D V D D 2 T S 2 4 0 3 9 3 8 3 7 3 6 3 5 3 4 3 3 3 2 3 1 3 0 2 9 2 8 2 7 2 6 2 5 2 4 2 3 1 0 0 p F 2 2 3 .3 k W 1 0 m F A V S S 3 3 2 1 3 3 0 W IC _ IN D 1 D 4 L O U A V S A V S B IA S M U S A V D A V D A N 5 A N 4 A N 3 A N 2 A N 1 A N 0 A V S A V D V A G V A G T I+ T IT G 2 P + 1 S 1 P 1 0 0 k W T S 2 P C 1 k W U S B A c tiv e G L E D 7 S P K V o lu m e In c L O U A V S A V S B IA S M U S A V D A V D A N 5 A N 4 A N 3 A N 2 A N 1 A N 0 A V S A V D V A G V A G T I+ T IT G P C 0 /B Z 1 /T M R 0 2 /T M R 1 P C 3 C 4 /S D O P C 5 /S D I C 6 /S C S C 7 /S C K D V S S 3 P B 0 P B 1 P B 2 P B 3 P B 4 P B 5 P B 6 P B 7 P W M 0 P W M 1 A V S S 3 P A 0 6 1 0 m F A V D D 3 P A 3 5 L O U T R O U T A V S S 2 S P K V o lu m e D e c S W 5 4 S W 4 3 S W 3 1 0 0 m F 2 1 1 0 2 1 0 m F P A 2 1 0 0 m F 3 D D 2 U T P A 1 J 5 6 7 6 8 6 9 7 0 7 1 7 2 7 3 7 4 7 5 7 6 7 7 1 0 m F P F P F P F P F P A P A P A P A P A P A P A P A A V R O 0 .1 m F 7 8 7 9 8 0 B e a d F e r r ite P C P C P 1 0 0 p F 1 0 k W A V S S 3 P C 0 /B Z 1 /T M R 0 2 /T M R 1 P C 3 C 4 /S D O P C 5 /S D I C 6 /S C S C 7 /S C K D V S S 3 P B 0 P B 1 P B 2 P B 3 P B 4 P B 5 P B 6 P B 7 P W M 0 P W M 1 A V S S 3 M ic r o p h o n e P 0 .1 m F 2 1 P 1 0 0 k W 3 O S C O O S C I P E 0 P E 1 P E 2 P E 3 P E 4 P E 5 P E 6 P E 7 /IN T D V S S 2 P D 0 P D 1 P D 2 P D 3 P D 4 P D 5 P D 6 P D 7 D V D D 2 5 9 5 8 5 7 5 6 5 5 5 4 5 3 5 2 5 1 5 0 4 9 4 8 4 7 4 6 4 5 4 4 4 3 4 2 4 1 P A 7 P A 6 P A 4 P E 0 0 .1 m F 1 L 4 2 1 B e a d F e r r ite L 8 V D D P E 1 2 P E 2 B e a d F e r r ite A V S S 3 1 L 7 B e a d F e r r ite A V S S 4 2 A V D D 4 0 .1 m F P E 3 P E 4 1 0 m F P E 5 Rev. 1.10 1 2 M H z P A 5 1 0 k W M K 1 6 0 60 S 1 1 S 1 2 S 1 3 1 2 3 S 2 1 S 2 2 S 2 3 4 5 6 S 3 1 S 3 2 S 3 3 7 8 9 S 4 1 S 4 2 S 4 3 * 0 # S 5 1 S 5 2 S 5 3 U P D O W N C A N C E L S 6 1 S 6 2 S 6 3 O K M U T E _ S P S E L S 1 4 M U S IC S 2 4 S 3 4 S 4 4 S 5 4 S 6 4 August 5, 2011 HT82A836R Instruction Set subtract instruction mnemonics to enable the necessary arithmetic to be carried out. Care must be taken to ensure correct handling of carry and borrow data when results exceed 255 for addition and less than 0 for subtraction. The increment and decrement instructions INC, INCA, DEC and DECA provide a simple means of increasing or decreasing by a value of one of the values in the destination specified. Introduction C e n t ra l t o t he s uc c es s f ul oper a t i on o f a n y microcontroller is its instruction set, which is a set of program instruction codes that directs the microcontroller to perform certain operations. In the case of Holtek microcontrollers, a comprehensive and flexible set of over 60 instructions is provided to enable programmers to implement their application with the minimum of programming overheads. Logical and Rotate Operations For easier understanding of the various instruction codes, they have been subdivided into several functional groupings. The standard logical operations such as AND, OR, XOR and CPL all have their own instruction within the Holtek microcontroller instruction set. As with the case of most instructions involving data manipulation, data must pass through the Accumulator which may involve additional programming steps. In all logical data operations, the zero flag may be set if the result of the operation is zero. Another form of logical data manipulation comes from the rotate instructions such as RR, RL, RRC and RLC which provide a simple means of rotating one bit right or left. Different rotate instructions exist depending on program requirements. Rotate instructions are useful for serial port programming applications where data can be rotated from an internal register into the Carry bit from where it can be examined and the necessary serial bit set high or low. Another application where rotate data operations are used is to implement multiplication and division calculations. Instruction Timing Most instructions are implemented within one instruction cycle. The exceptions to this are branch, call, or table read instructions where two instruction cycles are required. One instruction cycle is equal to 4 system clock cycles, therefore in the case of an 8MHz system oscillator, most instructions would be implemented within 0.5ms and branch or call instructions would be implemented within 1ms. Although instructions which require one more cycle to implement are generally limited to the JMP, CALL, RET, RETI and table read instructions, it is important to realize that any other instructions which involve manipulation of the Program Counter Low register or PCL will also take one more cycle to implement. As instructions which change the contents of the PCL will imply a direct jump to that new address, one more cycle will be required. Examples of such instructions would be ²CLR PCL² or ²MOV PCL, A². For the case of skip instructions, it must be noted that if the result of the comparison involves a skip operation then this will also take one more cycle, if no skip is involved then only one cycle is required. Branches and Control Transfer Program branching takes the form of either jumps to specified locations using the JMP instruction or to a subroutine using the CALL instruction. They differ in the sense that in the case of a subroutine call, the program must return to the instruction immediately when the subroutine has been carried out. This is done by placing a return instruction RET in the subroutine which will cause the program to jump back to the address right after the CALL instruction. In the case of a JMP instruction, the program simply jumps to the desired location. There is no requirement to jump back to the original jumping off point as in the case of the CALL instruction. One special and extremely useful set of branch instructions are the conditional branches. Here a decision is first made regarding the condition of a certain data memory or individual bits. Depending upon the conditions, the program will continue with the next instruction or skip over it and jump to the following instruction. These instructions are the key to decision making and branching within the program perhaps determined by the condition of certain input switches or by the condition of internal data bits. Moving and Transferring Data The transfer of data within the microcontroller program is one of the most frequently used operations. Making use of three kinds of MOV instructions, data can be transferred from registers to the Accumulator and vice-versa as well as being able to move specific immediate data directly into the Accumulator. One of the most important data transfer applications is to receive data from the input ports and transfer data to the output ports. Arithmetic Operations The ability to perform certain arithmetic operations and data manipulation is a necessary feature of most microcontroller applications. Within the Holtek microcontroller instruction set are a range of add and Rev. 1.10 61 August 5, 2011 HT82A836R Bit Operations Other Operations The ability to provide single bit operations on Data Memory is an extremely flexible feature of all Holtek microcontrollers. This feature is especially useful for output port bit programming where individual bits or port pins can be directly set high or low using either the ²SET [m].i² or ²CLR [m].i² instructions respectively. The feature removes the need for programmers to first read the 8-bit output port, manipulate the input data to ensure that other bits are not changed and then output the port with the correct new data. This read-modify-write process is taken care of automatically when these bit operation instructions are used. In addition to the above functional instructions, a range of other instructions also exist such as the ²HALT² instruction for Power-down operations and instructions to control the operation of the Watchdog Timer for reliable program operations under extreme electric or electromagnetic environments. For their relevant operations, refer to the functional related sections. Instruction Set Summary The following table depicts a summary of the instruction set categorised according to function and can be consulted as a basic instruction reference using the following listed conventions. Table Read Operations Table conventions: Data storage is normally implemented by using registers. However, when working with large amounts of fixed data, the volume involved often makes it inconvenient to store the fixed data in the Data Memory. To overcome this problem, Holtek microcontrollers allow an area of Program Memory to be setup as a table where data can be directly stored. A set of easy to use instructions provides the means by which this fixed data can be referenced and retrieved from the Program Memory. Mnemonic x: Bits immediate data m: Data Memory address A: Accumulator i: 0~7 number of bits addr: Program memory address Description Cycles Flag Affected 1 1Note 1 1 1Note 1 1 1Note 1 1Note 1Note Z, C, AC, OV Z, C, AC, OV Z, C, AC, OV Z, C, AC, OV Z, C, AC, OV Z, C, AC, OV Z, C, AC, OV Z, C, AC, OV Z, C, AC, OV Z, C, AC, OV C 1 1 1 1Note 1Note 1Note 1 1 1 1Note 1 Z Z Z Z Z Z Z Z Z Z Z 1 1Note 1 1Note Z Z Z Z Arithmetic ADD A,[m] ADDM A,[m] ADD A,x ADC A,[m] ADCM A,[m] SUB A,x SUB A,[m] SUBM A,[m] SBC A,[m] SBCM A,[m] DAA [m] Add Data Memory to ACC Add ACC to Data Memory Add immediate data to ACC Add Data Memory to ACC with Carry Add ACC to Data memory with Carry Subtract immediate data from the ACC Subtract Data Memory from ACC Subtract Data Memory from ACC with result in Data Memory Subtract Data Memory from ACC with Carry Subtract Data Memory from ACC with Carry, result in Data Memory Decimal adjust ACC for Addition with result in Data Memory Logic Operation AND A,[m] OR A,[m] XOR A,[m] ANDM A,[m] ORM A,[m] XORM A,[m] AND A,x OR A,x XOR A,x CPL [m] CPLA [m] Logical AND Data Memory to ACC Logical OR Data Memory to ACC Logical XOR Data Memory to ACC Logical AND ACC to Data Memory Logical OR ACC to Data Memory Logical XOR ACC to Data Memory Logical AND immediate Data to ACC Logical OR immediate Data to ACC Logical XOR immediate Data to ACC Complement Data Memory Complement Data Memory with result in ACC Increment & Decrement INCA [m] INC [m] DECA [m] DEC [m] Rev. 1.10 Increment Data Memory with result in ACC Increment Data Memory Decrement Data Memory with result in ACC Decrement Data Memory 62 August 5, 2011 HT82A836R Mnemonic Description Cycles Flag Affected Rotate Data Memory right with result in ACC Rotate Data Memory right Rotate Data Memory right through Carry with result in ACC Rotate Data Memory right through Carry Rotate Data Memory left with result in ACC Rotate Data Memory left Rotate Data Memory left through Carry with result in ACC Rotate Data Memory left through Carry 1 1Note 1 1Note 1 1Note 1 1Note None None C C None None C C Move Data Memory to ACC Move ACC to Data Memory Move immediate data to ACC 1 1Note 1 None None None Clear bit of Data Memory Set bit of Data Memory 1Note 1Note None None Jump unconditionally Skip if Data Memory is zero Skip if Data Memory is zero with data movement to ACC Skip if bit i of Data Memory is zero Skip if bit i of Data Memory is not zero Skip if increment Data Memory is zero Skip if decrement Data Memory is zero Skip if increment Data Memory is zero with result in ACC Skip if decrement Data Memory is zero with result in ACC Subroutine call Return from subroutine Return from subroutine and load immediate data to ACC Return from interrupt 2 1Note 1note 1Note 1Note 1Note 1Note 1Note 1Note 2 2 2 2 None None None None None None None None None None None None None Read table (current page) to TBLH and Data Memory Read table (last page) to TBLH and Data Memory 2Note 2Note None None No operation Clear Data Memory Set Data Memory Clear Watchdog Timer Pre-clear Watchdog Timer Pre-clear Watchdog Timer Swap nibbles of Data Memory Swap nibbles of Data Memory with result in ACC Enter power down mode 1 1Note 1Note 1 1 1 1Note 1 1 None None None TO, PDF TO, PDF TO, PDF None None TO, PDF Rotate RRA [m] RR [m] RRCA [m] RRC [m] RLA [m] RL [m] RLCA [m] RLC [m] Data Move MOV A,[m] MOV [m],A MOV A,x Bit Operation CLR [m].i SET [m].i Branch JMP addr SZ [m] SZA [m] SZ [m].i SNZ [m].i SIZ [m] SDZ [m] SIZA [m] SDZA [m] CALL addr RET RET A,x RETI Table Read TABRDC [m] TABRDL [m] Miscellaneous NOP CLR [m] SET [m] CLR WDT CLR WDT1 CLR WDT2 SWAP [m] SWAPA [m] HALT Note: 1. For skip instructions, if the result of the comparison involves a skip then two cycles are required, if no skip takes place only one cycle is required. 2. Any instruction which changes the contents of the PCL will also require 2 cycles for execution. 3. For the ²CLR WDT1² and ²CLR WDT2² instructions the TO and PDF flags may be affected by the execution status. The TO and PDF flags are cleared after both ²CLR WDT1² and ²CLR WDT2² instructions are consecutively executed. Otherwise the TO and PDF flags remain unchanged. Rev. 1.10 63 August 5, 2011 HT82A836R Instruction Definition ADC A,[m] Add Data Memory to ACC with Carry Description The contents of the specified Data Memory, Accumulator and the carry flag are added. The result is stored in the Accumulator. Operation ACC ¬ ACC + [m] + C Affected flag(s) OV, Z, AC, C ADCM A,[m] Add ACC to Data Memory with Carry Description The contents of the specified Data Memory, Accumulator and the carry flag are added. The result is stored in the specified Data Memory. Operation [m] ¬ ACC + [m] + C Affected flag(s) OV, Z, AC, C ADD A,[m] Add Data Memory to ACC Description The contents of the specified Data Memory and the Accumulator are added. The result is stored in the Accumulator. Operation ACC ¬ ACC + [m] Affected flag(s) OV, Z, AC, C ADD A,x Add immediate data to ACC Description The contents of the Accumulator and the specified immediate data are added. The result is stored in the Accumulator. Operation ACC ¬ ACC + x Affected flag(s) OV, Z, AC, C ADDM A,[m] Add ACC to Data Memory Description The contents of the specified Data Memory and the Accumulator are added. The result is stored in the specified Data Memory. Operation [m] ¬ ACC + [m] Affected flag(s) OV, Z, AC, C AND A,[m] Logical AND Data Memory to ACC Description Data in the Accumulator and the specified Data Memory perform a bitwise logical AND operation. The result is stored in the Accumulator. Operation ACC ¬ ACC ²AND² [m] Affected flag(s) Z AND A,x Logical AND immediate data to ACC Description Data in the Accumulator and the specified immediate data perform a bitwise logical AND operation. The result is stored in the Accumulator. Operation ACC ¬ ACC ²AND² x Affected flag(s) Z ANDM A,[m] Logical AND ACC to Data Memory Description Data in the specified Data Memory and the Accumulator perform a bitwise logical AND operation. The result is stored in the Data Memory. Operation [m] ¬ ACC ²AND² [m] Affected flag(s) Z Rev. 1.10 64 August 5, 2011 HT82A836R CALL addr Subroutine call Description Unconditionally calls a subroutine at the specified address. The Program Counter then increments by 1 to obtain the address of the next instruction which is then pushed onto the stack. The specified address is then loaded and the program continues execution from this new address. As this instruction requires an additional operation, it is a two cycle instruction. Operation Stack ¬ Program Counter + 1 Program Counter ¬ addr Affected flag(s) None CLR [m] Clear Data Memory Description Each bit of the specified Data Memory is cleared to 0. Operation [m] ¬ 00H Affected flag(s) None CLR [m].i Clear bit of Data Memory Description Bit i of the specified Data Memory is cleared to 0. Operation [m].i ¬ 0 Affected flag(s) None CLR WDT Clear Watchdog Timer Description The TO, PDF flags and the WDT are all cleared. Operation WDT cleared TO ¬ 0 PDF ¬ 0 Affected flag(s) TO, PDF CLR WDT1 Pre-clear Watchdog Timer Description The TO, PDF flags and the WDT are all cleared. Note that this instruction works in conjunction with CLR WDT2 and must be executed alternately with CLR WDT2 to have effect. Repetitively executing this instruction without alternately executing CLR WDT2 will have no effect. Operation WDT cleared TO ¬ 0 PDF ¬ 0 Affected flag(s) TO, PDF CLR WDT2 Pre-clear Watchdog Timer Description The TO, PDF flags and the WDT are all cleared. Note that this instruction works in conjunction with CLR WDT1 and must be executed alternately with CLR WDT1 to have effect. Repetitively executing this instruction without alternately executing CLR WDT1 will have no effect. Operation WDT cleared TO ¬ 0 PDF ¬ 0 Affected flag(s) TO, PDF Rev. 1.10 65 August 5, 2011 HT82A836R CPL [m] Complement Data Memory Description Each bit of the specified Data Memory is logically complemented (1¢s complement). Bits which previously contained a 1 are changed to 0 and vice versa. Operation [m] ¬ [m] Affected flag(s) Z CPLA [m] Complement Data Memory with result in ACC Description Each bit of the specified Data Memory is logically complemented (1¢s complement). Bits which previously contained a 1 are changed to 0 and vice versa. The complemented result is stored in the Accumulator and the contents of the Data Memory remain unchanged. Operation ACC ¬ [m] Affected flag(s) Z DAA [m] Decimal-Adjust ACC for addition with result in Data Memory Description Convert the contents of the Accumulator value to a BCD ( Binary Coded Decimal) value resulting from the previous addition of two BCD variables. If the low nibble is greater than 9 or if AC flag is set, then a value of 6 will be added to the low nibble. Otherwise the low nibble remains unchanged. If the high nibble is greater than 9 or if the C flag is set, then a value of 6 will be added to the high nibble. Essentially, the decimal conversion is performed by adding 00H, 06H, 60H or 66H depending on the Accumulator and flag conditions. Only the C flag may be affected by this instruction which indicates that if the original BCD sum is greater than 100, it allows multiple precision decimal addition. Operation [m] ¬ ACC + 00H or [m] ¬ ACC + 06H or [m] ¬ ACC + 60H or [m] ¬ ACC + 66H Affected flag(s) C DEC [m] Decrement Data Memory Description Data in the specified Data Memory is decremented by 1. Operation [m] ¬ [m] - 1 Affected flag(s) Z DECA [m] Decrement Data Memory with result in ACC Description Data in the specified Data Memory is decremented by 1. The result is stored in the Accumulator. The contents of the Data Memory remain unchanged. Operation ACC ¬ [m] - 1 Affected flag(s) Z HALT Enter power down mode Description This instruction stops the program execution and turns off the system clock. The contents of the Data Memory and registers are retained. The WDT and prescaler are cleared. The power down flag PDF is set and the WDT time-out flag TO is cleared. Operation TO ¬ 0 PDF ¬ 1 Affected flag(s) TO, PDF Rev. 1.10 66 August 5, 2011 HT82A836R INC [m] Increment Data Memory Description Data in the specified Data Memory is incremented by 1. Operation [m] ¬ [m] + 1 Affected flag(s) Z INCA [m] Increment Data Memory with result in ACC Description Data in the specified Data Memory is incremented by 1. The result is stored in the Accumulator. The contents of the Data Memory remain unchanged. Operation ACC ¬ [m] + 1 Affected flag(s) Z JMP addr Jump unconditionally Description The contents of the Program Counter are replaced with the specified address. Program execution then continues from this new address. As this requires the insertion of a dummy instruction while the new address is loaded, it is a two cycle instruction. Operation Program Counter ¬ addr Affected flag(s) None MOV A,[m] Move Data Memory to ACC Description The contents of the specified Data Memory are copied to the Accumulator. Operation ACC ¬ [m] Affected flag(s) None MOV A,x Move immediate data to ACC Description The immediate data specified is loaded into the Accumulator. Operation ACC ¬ x Affected flag(s) None MOV [m],A Move ACC to Data Memory Description The contents of the Accumulator are copied to the specified Data Memory. Operation [m] ¬ ACC Affected flag(s) None NOP No operation Description No operation is performed. Execution continues with the next instruction. Operation No operation Affected flag(s) None OR A,[m] Logical OR Data Memory to ACC Description Data in the Accumulator and the specified Data Memory perform a bitwise logical OR operation. The result is stored in the Accumulator. Operation ACC ¬ ACC ²OR² [m] Affected flag(s) Z Rev. 1.10 67 August 5, 2011 HT82A836R OR A,x Logical OR immediate data to ACC Description Data in the Accumulator and the specified immediate data perform a bitwise logical OR operation. The result is stored in the Accumulator. Operation ACC ¬ ACC ²OR² x Affected flag(s) Z ORM A,[m] Logical OR ACC to Data Memory Description Data in the specified Data Memory and the Accumulator perform a bitwise logical OR operation. The result is stored in the Data Memory. Operation [m] ¬ ACC ²OR² [m] Affected flag(s) Z RET Return from subroutine Description The Program Counter is restored from the stack. Program execution continues at the restored address. Operation Program Counter ¬ Stack Affected flag(s) None RET A,x Return from subroutine and load immediate data to ACC Description The Program Counter is restored from the stack and the Accumulator loaded with the specified immediate data. Program execution continues at the restored address. Operation Program Counter ¬ Stack ACC ¬ x Affected flag(s) None RETI Return from interrupt Description The Program Counter is restored from the stack and the interrupts are re-enabled by setting the EMI bit. EMI is the master interrupt global enable bit. If an interrupt was pending when the RETI instruction is executed, the pending Interrupt routine will be processed before returning to the main program. Operation Program Counter ¬ Stack EMI ¬ 1 Affected flag(s) None RL [m] Rotate Data Memory left Description The contents of the specified Data Memory are rotated left by 1 bit with bit 7 rotated into bit 0. Operation [m].(i+1) ¬ [m].i; (i = 0~6) [m].0 ¬ [m].7 Affected flag(s) None RLA [m] Rotate Data Memory left with result in ACC Description The contents of the specified Data Memory are rotated left by 1 bit with bit 7 rotated into bit 0. The rotated result is stored in the Accumulator and the contents of the Data Memory remain unchanged. Operation ACC.(i+1) ¬ [m].i; (i = 0~6) ACC.0 ¬ [m].7 Affected flag(s) None Rev. 1.10 68 August 5, 2011 HT82A836R RLC [m] Rotate Data Memory left through Carry Description The contents of the specified Data Memory and the carry flag are rotated left by 1 bit. Bit 7 replaces the Carry bit and the original carry flag is rotated into bit 0. Operation [m].(i+1) ¬ [m].i; (i = 0~6) [m].0 ¬ C C ¬ [m].7 Affected flag(s) C RLCA [m] Rotate Data Memory left through Carry with result in ACC Description Data in the specified Data Memory and the carry flag are rotated left by 1 bit. Bit 7 replaces the Carry bit and the original carry flag is rotated into the bit 0. The rotated result is stored in the Accumulator and the contents of the Data Memory remain unchanged. Operation ACC.(i+1) ¬ [m].i; (i = 0~6) ACC.0 ¬ C C ¬ [m].7 Affected flag(s) C RR [m] Rotate Data Memory right Description The contents of the specified Data Memory are rotated right by 1 bit with bit 0 rotated into bit 7. Operation [m].i ¬ [m].(i+1); (i = 0~6) [m].7 ¬ [m].0 Affected flag(s) None RRA [m] Rotate Data Memory right with result in ACC Description Data in the specified Data Memory and the carry flag are rotated right by 1 bit with bit 0 rotated into bit 7. The rotated result is stored in the Accumulator and the contents of the Data Memory remain unchanged. Operation ACC.i ¬ [m].(i+1); (i = 0~6) ACC.7 ¬ [m].0 Affected flag(s) None RRC [m] Rotate Data Memory right through Carry Description The contents of the specified Data Memory and the carry flag are rotated right by 1 bit. Bit 0 replaces the Carry bit and the original carry flag is rotated into bit 7. Operation [m].i ¬ [m].(i+1); (i = 0~6) [m].7 ¬ C C ¬ [m].0 Affected flag(s) C RRCA [m] Rotate Data Memory right through Carry with result in ACC Description Data in the specified Data Memory and the carry flag are rotated right by 1 bit. Bit 0 replaces the Carry bit and the original carry flag is rotated into bit 7. The rotated result is stored in the Accumulator and the contents of the Data Memory remain unchanged. Operation ACC.i ¬ [m].(i+1); (i = 0~6) ACC.7 ¬ C C ¬ [m].0 Affected flag(s) C Rev. 1.10 69 August 5, 2011 HT82A836R SBC A,[m] Subtract Data Memory from ACC with Carry Description The contents of the specified Data Memory and the complement of the carry flag are subtracted from the Accumulator. The result is stored in the Accumulator. Note that if the result of subtraction is negative, the C flag will be cleared to 0, otherwise if the result is positive or zero, the C flag will be set to 1. Operation ACC ¬ ACC - [m] - C Affected flag(s) OV, Z, AC, C SBCM A,[m] Subtract Data Memory from ACC with Carry and result in Data Memory Description The contents of the specified Data Memory and the complement of the carry flag are subtracted from the Accumulator. The result is stored in the Data Memory. Note that if the result of subtraction is negative, the C flag will be cleared to 0, otherwise if the result is positive or zero, the C flag will be set to 1. Operation [m] ¬ ACC - [m] - C Affected flag(s) OV, Z, AC, C SDZ [m] Skip if decrement Data Memory is 0 Description The contents of the specified Data Memory are first decremented by 1. If the result is 0 the following instruction is skipped. As this requires the insertion of a dummy instruction while the next instruction is fetched, it is a two cycle instruction. If the result is not 0 the program proceeds with the following instruction. Operation [m] ¬ [m] - 1 Skip if [m] = 0 Affected flag(s) None SDZA [m] Skip if decrement Data Memory is zero with result in ACC Description The contents of the specified Data Memory are first decremented by 1. If the result is 0, the following instruction is skipped. The result is stored in the Accumulator but the specified Data Memory contents remain unchanged. As this requires the insertion of a dummy instruction while the next instruction is fetched, it is a two cycle instruction. If the result is not 0, the program proceeds with the following instruction. Operation ACC ¬ [m] - 1 Skip if ACC = 0 Affected flag(s) None SET [m] Set Data Memory Description Each bit of the specified Data Memory is set to 1. Operation [m] ¬ FFH Affected flag(s) None SET [m].i Set bit of Data Memory Description Bit i of the specified Data Memory is set to 1. Operation [m].i ¬ 1 Affected flag(s) None Rev. 1.10 70 August 5, 2011 HT82A836R SIZ [m] Skip if increment Data Memory is 0 Description The contents of the specified Data Memory are first incremented by 1. If the result is 0, the following instruction is skipped. As this requires the insertion of a dummy instruction while the next instruction is fetched, it is a two cycle instruction. If the result is not 0 the program proceeds with the following instruction. Operation [m] ¬ [m] + 1 Skip if [m] = 0 Affected flag(s) None SIZA [m] Skip if increment Data Memory is zero with result in ACC Description The contents of the specified Data Memory are first incremented by 1. If the result is 0, the following instruction is skipped. The result is stored in the Accumulator but the specified Data Memory contents remain unchanged. As this requires the insertion of a dummy instruction while the next instruction is fetched, it is a two cycle instruction. If the result is not 0 the program proceeds with the following instruction. Operation ACC ¬ [m] + 1 Skip if ACC = 0 Affected flag(s) None SNZ [m].i Skip if bit i of Data Memory is not 0 Description If bit i of the specified Data Memory is not 0, the following instruction is skipped. As this requires the insertion of a dummy instruction while the next instruction is fetched, it is a two cycle instruction. If the result is 0 the program proceeds with the following instruction. Operation Skip if [m].i ¹ 0 Affected flag(s) None SUB A,[m] Subtract Data Memory from ACC Description The specified Data Memory is subtracted from the contents of the Accumulator. The result is stored in the Accumulator. Note that if the result of subtraction is negative, the C flag will be cleared to 0, otherwise if the result is positive or zero, the C flag will be set to 1. Operation ACC ¬ ACC - [m] Affected flag(s) OV, Z, AC, C SUBM A,[m] Subtract Data Memory from ACC with result in Data Memory Description The specified Data Memory is subtracted from the contents of the Accumulator. The result is stored in the Data Memory. Note that if the result of subtraction is negative, the C flag will be cleared to 0, otherwise if the result is positive or zero, the C flag will be set to 1. Operation [m] ¬ ACC - [m] Affected flag(s) OV, Z, AC, C SUB A,x Subtract immediate data from ACC Description The immediate data specified by the code is subtracted from the contents of the Accumulator. The result is stored in the Accumulator. Note that if the result of subtraction is negative, the C flag will be cleared to 0, otherwise if the result is positive or zero, the C flag will be set to 1. Operation ACC ¬ ACC - x Affected flag(s) OV, Z, AC, C Rev. 1.10 71 August 5, 2011 HT82A836R SWAP [m] Swap nibbles of Data Memory Description The low-order and high-order nibbles of the specified Data Memory are interchanged. Operation [m].3~[m].0 « [m].7 ~ [m].4 Affected flag(s) None SWAPA [m] Swap nibbles of Data Memory with result in ACC Description The low-order and high-order nibbles of the specified Data Memory are interchanged. The result is stored in the Accumulator. The contents of the Data Memory remain unchanged. Operation ACC.3 ~ ACC.0 ¬ [m].7 ~ [m].4 ACC.7 ~ ACC.4 ¬ [m].3 ~ [m].0 Affected flag(s) None SZ [m] Skip if Data Memory is 0 Description If the contents of the specified Data Memory is 0, the following instruction is skipped. As this requires the insertion of a dummy instruction while the next instruction is fetched, it is a two cycle instruction. If the result is not 0 the program proceeds with the following instruction. Operation Skip if [m] = 0 Affected flag(s) None SZA [m] Skip if Data Memory is 0 with data movement to ACC Description The contents of the specified Data Memory are copied to the Accumulator. If the value is zero, the following instruction is skipped. As this requires the insertion of a dummy instruction while the next instruction is fetched, it is a two cycle instruction. If the result is not 0 the program proceeds with the following instruction. Operation ACC ¬ [m] Skip if [m] = 0 Affected flag(s) None SZ [m].i Skip if bit i of Data Memory is 0 Description If bit i of the specified Data Memory is 0, the following instruction is skipped. As this requires the insertion of a dummy instruction while the next instruction is fetched, it is a two cycle instruction. If the result is not 0, the program proceeds with the following instruction. Operation Skip if [m].i = 0 Affected flag(s) None TABRDC [m] Read table (current page) to TBLH and Data Memory Description The low byte of the program code (current page) addressed by the table pointer (TBLP) is moved to the specified Data Memory and the high byte moved to TBLH. Operation [m] ¬ program code (low byte) TBLH ¬ program code (high byte) Affected flag(s) None TABRDL [m] Read table (last page) to TBLH and Data Memory Description The low byte of the program code (last page) addressed by the table pointer (TBLP) is moved to the specified Data Memory and the high byte moved to TBLH. Operation [m] ¬ program code (low byte) TBLH ¬ program code (high byte) Affected flag(s) None Rev. 1.10 72 August 5, 2011 HT82A836R XOR A,[m] Logical XOR Data Memory to ACC Description Data in the Accumulator and the specified Data Memory perform a bitwise logical XOR operation. The result is stored in the Accumulator. Operation ACC ¬ ACC ²XOR² [m] Affected flag(s) Z XORM A,[m] Logical XOR ACC to Data Memory Description Data in the specified Data Memory and the Accumulator perform a bitwise logical XOR operation. The result is stored in the Data Memory. Operation [m] ¬ ACC ²XOR² [m] Affected flag(s) Z XOR A,x Logical XOR immediate data to ACC Description Data in the Accumulator and the specified immediate data perform a bitwise logical XOR operation. The result is stored in the Accumulator. Operation ACC ¬ ACC ²XOR² x Affected flag(s) Z Rev. 1.10 73 August 5, 2011 HT82A836R Package Information Note that the package information provided here is for consultation purposes only. As this information may be updated at regular intervals users are reminded to consult the Holtek website (http://www.holtek.com.tw/english/literature/package.pdf) for the latest version of the package information. 80-pin LQFP (10mm´10mm) Outline Dimensions C D G 4 1 6 0 H I 6 1 4 0 F A B E 2 1 8 0 K a J 2 0 1 Symbol Nom. Max. A 0.469 ¾ 0.476 B 0.390 ¾ 0.398 C 0.469 ¾ 0.476 D 0.390 ¾ 0.398 E ¾ 0.016 ¾ F ¾ 0.006 ¾ G 0.053 ¾ 0.057 H ¾ ¾ 0.063 I ¾ 0.004 ¾ J 0.018 ¾ 0.030 K 0.004 ¾ 0.008 a 0° ¾ 7° Symbol Rev. 1.10 Dimensions in inch Min. Dimensions in mm Min. Nom. Max. A 11.90 ¾ 12.10 B 9.90 ¾ 10.10 C 11.90 ¾ 12.10 D 9.90 ¾ 10.10 E ¾ 0.40 ¾ F ¾ 0.16 ¾ G 1.35 ¾ 1.45 H ¾ ¾ 1.60 I ¾ 0.10 ¾ J 0.45 ¾ 0.75 K 0.10 ¾ 0.20 a 0° ¾ 7° 74 August 5, 2011 HT82A836R Holtek Semiconductor Inc. (Headquarters) No.3, Creation Rd. II, Science Park, Hsinchu, Taiwan Tel: 886-3-563-1999 Fax: 886-3-563-1189 http://www.holtek.com.tw Holtek Semiconductor Inc. (Taipei Sales Office) 4F-2, No. 3-2, YuanQu St., Nankang Software Park, Taipei 115, Taiwan Tel: 886-2-2655-7070 Fax: 886-2-2655-7373 Fax: 886-2-2655-7383 (International sales hotline) Holtek Semiconductor Inc. (Shenzhen Sales Office) 5F, Unit A, Productivity Building, No.5 Gaoxin M 2nd Road, Nanshan District, Shenzhen, China 518057 Tel: 86-755-8616-9908, 86-755-8616-9308 Fax: 86-755-8616-9722 Holtek Semiconductor (USA), Inc. (North America Sales Office) 46729 Fremont Blvd., Fremont, CA 94538 Tel: 1-510-252-9880 Fax: 1-510-252-9885 http://www.holtek.com Copyright Ó 2011 by HOLTEK SEMICONDUCTOR INC. The information appearing in this Data Sheet is believed to be accurate at the time of publication. However, Holtek assumes no responsibility arising from the use of the specifications described. The applications mentioned herein are used solely for the purpose of illustration and Holtek makes no warranty or representation that such applications will be suitable without further modification, nor recommends the use of its products for application that may present a risk to human life due to malfunction or otherwise. Holtek¢s products are not authorized for use as critical components in life support devices or systems. Holtek reserves the right to alter its products without prior notification. For the most up-to-date information, please visit our web site at http://www.holtek.com.tw. Rev. 1.10 75 August 5, 2011