USB Audio MCU HT82A824R Revision: V1.00 Date: �������������� April 14, 2011 HT82A824R USB Audio MCU Table of Contents Features.............................................................................................................. 7 CPU Features...........................................................................................................................7 General Description........................................................................................... 8 Block Diagram.................................................................................................... 8 Pin Assignment.................................................................................................. 9 Pin Description.................................................................................................. 9 Absolute Maximum Ratings............................................................................ 10 D.C. Characteristics......................................................................................... 11 A.C. Characteristics......................................................................................... 12 System Architecturex...................................................................................... 12 Clocking and Pipelining...........................................................................................................12 Program Counter.....................................................................................................................13 Stack.......................................................................................................................................14 Arithmetic and Logic Unit – ALU.............................................................................................15 Program Memory............................................................................................. 15 Organisation............................................................................................................................15 Special Vectors.......................................................................................................................15 Look-up Table..........................................................................................................................17 Table Program Example..........................................................................................................18 Data Memory.................................................................................................... 19 Organisation............................................................................................................................19 General Purpose Data Memory..............................................................................................20 Special Purpose Data Memory...............................................................................................20 Special Function Registers............................................................................. 21 Indirect addressing register – IAR0, IAR1...............................................................................21 Memory Pointer – MP0, MP1..................................................................................................21 Bank Pointer – BP...................................................................................................................22 Accumulator – ACC................................................................................................................22 Program Counter Low Register – PCL....................................................................................22 Look-up Table Registers – TBLP, TBLH, TBHP......................................................................23 Watchdog Timer Register – WDTS........................................................................................23 Status Register – STATUS......................................................................................................23 Interrupt Control Registers – INTC0, INTC1, MFI1C..............................................................24 Timer/Event Counter Registers – TMRL/TMRH, TMRC.........................................................24 Input/Output Ports and Control Registers...............................................................................24 Port A Wake-up Control Register – PA_WAKE_CTRL............................................................25 Pulse Width Modulator Registers – PWM0, PWM1, PWMC...................................................25 A/D Converter Registers – ADRL, ADRH, ADCR, ACSR........................................................25 USB Registers.........................................................................................................................25 PFD Registers – PFDC, PFDD...............................................................................................25 Rev 1.00 2 April 14, 2011 HT82A824R USB Audio MCU Other Registers ......................................................................................................................25 Input/Output Ports........................................................................................... 26 Pull-high Resistors..................................................................................................................26 Port Wake-up..........................................................................................................................26 I/O Port Control Registers.......................................................................................................27 Pin-shared Functions..............................................................................................................27 I/O Pin Structures....................................................................................................................28 Programming Considerations..................................................................................................29 Timer/Event Counters..................................................................................... 29 Configuring the Timer/Event Counter Input Clock Source......................................................30 Timer Registers – TMR0H/TMR0L, TMR1L/TMR1H...............................................................30 Timer Control Register – TMR0C, TMR1C.............................................................................31 Configuring the Timer Mode....................................................................................................31 Configuring the Event Counter Mode......................................................................................32 Configuring the Pulse Width Measurement Mode...................................................................32 I/O Interfacing..........................................................................................................................33 Programming Considerations..................................................................................................34 Timer Program Example.........................................................................................................35 Programmable Frequency Divider – PFD...............................................................................35 Power Amplifier................................................................................................ 37 Programmable Attenuator.......................................................................................................37 ATTEN_CTRL_L and ATTEN_CTRL_R Registers..................................................................37 Interrupts.......................................................................................................... 38 Interrupt Registers...................................................................................................................38 Interrupt Operation..................................................................................................................38 Interrupt Priority.......................................................................................................................39 USB Interrupt..........................................................................................................................41 Timer/Event Counter Interrupt.................................................................................................41 Play Interrupt...........................................................................................................................41 Multi Function Interrupt...........................................................................................................42 External Interrupt.....................................................................................................................43 A/D Converter Interrupt...........................................................................................................43 Serial Interface Interrupt..........................................................................................................43 Programming Considerations..................................................................................................44 Reset and Initialisation.................................................................................... 44 Reset Functions......................................................................................................................44 Reset Initial Conditions...........................................................................................................47 Oscillator.......................................................................................................... 50 System Crystal/Ceramic Oscillator..........................................................................................50 Watchdog Timer Oscillator......................................................................................................50 Power Down Mode and Wake-up.................................................................... 51 Power Down Mode..................................................................................................................51 Entering the Power Down Mode.............................................................................................51 Rev 1.00 3 April 14, 2011 HT82A824R USB Audio MCU Standby Current Considerations.............................................................................................51 Wake-up..................................................................................................................................52 Watchdog Timer............................................................................................... 53 USB Function................................................................................................... 55 USB Interface..........................................................................................................................55 USB Interface Registers..........................................................................................................55 USC Register..........................................................................................................................55 USR Register..........................................................................................................................57 UCC Register .........................................................................................................................58 AWR Register.........................................................................................................................59 STALL Register ......................................................................................................................59 SIES Register..........................................................................................................................60 MISC Register ........................................................................................................................62 SETIO Register.......................................................................................................................63 USB_STATE Register.............................................................................................................64 Suspend Wake-Up Remote Wake-Up.....................................................................................65 USF Register...........................................................................................................................65 Audio Data Format..................................................................................................................69 USB Speaker Volume Control.................................................................................................70 FIFO Registers........................................................................................................................70 DAC Limit Registers................................................................................................................71 SPI Serial Interface.......................................................................................... 72 SPI Interface Communication.................................................................................................72 SPI Registers..........................................................................................................................72 SPI Bus Enable/Disable..........................................................................................................73 SPI Operation..........................................................................................................................73 Error Detection........................................................................................................................76 Programming Considerations..................................................................................................76 Mode Control Register............................................................................................................76 Play Data.................................................................................................................................78 Analog to Digital Converter............................................................................ 78 A/D Overview..........................................................................................................................78 A/D Converter Data Registers – ADRL, ADRH.......................................................................78 A/D Converter Control Register – ADCR................................................................................79 A/D Converter Clock Source Register – ACSR.......................................................................80 A/D Input Pins.........................................................................................................................80 Initialising the A/D Converter...................................................................................................81 Summary of A/D Conversion Steps.........................................................................................81 Programming Considerations..................................................................................................82 A/D Programming Example.....................................................................................................82 A/D Transfer Function.............................................................................................................85 UART Bus Serial Interface.............................................................................. 85 UART Features.......................................................................................................................85 Rev 1.00 4 April 14, 2011 HT82A824R USB Audio MCU UART External Pin Interfacing................................................................................................86 UART Data Transfer Scheme.................................................................................................86 UART Status and Control Registers.......................................................................................86 USR1 Register........................................................................................................................87 UCR1 Register........................................................................................................................89 UCR2 Register........................................................................................................................90 Baud Rate Generator..............................................................................................................92 Calculating the Register and Error Values..............................................................................92 Setting Up and Controlling the UART............................................................ 93 Introduction.............................................................................................................................93 Enabling/Disabling the UART..................................................................................................93 Data, Parity and Stop Bit Selection.........................................................................................94 UART Transmitter...................................................................................................................94 Transmitting Data....................................................................................................................94 Transmit Break........................................................................................................................95 UART Receiver................................................................................................. 96 Introduction.............................................................................................................................96 Receiving Data........................................................................................................................96 Receive Break.........................................................................................................................97 Idle Status...............................................................................................................................97 Receiver Interrupt....................................................................................................................97 Managing Receiver Errors......................................................................................................97 Overrun Error – OERR Flag....................................................................................................97 Noise Error – NF Flag.............................................................................................................98 Framing Error – FERR Flag....................................................................................................98 Parity Error – PERR Flag........................................................................................................98 Uart Interrupt Scheme.............................................................................................................98 Address Detect Mode..............................................................................................................99 Uart Operation in Power Down Mode...................................................................................100 Pulse Width Modulator.................................................................................. 100 6+2 PWM Mode....................................................................................................................101 7+1 PWM Mode....................................................................................................................102 PWM Output Control.............................................................................................................103 Configuration Options................................................................................... 104 Application Circuits....................................................................................... 105 Instruction Set................................................................................................ 106 Introduction...........................................................................................................................106 Instruction Timing..................................................................................................................106 Moving and Transferring Data...............................................................................................106 Arithmetic Operations............................................................................................................106 Logical and Rotate Operations..............................................................................................106 Branches and Control Transfer.............................................................................................107 Bit Operations.......................................................................................................................107 Rev 1.00 5 April 14, 2011 HT82A824R USB Audio MCU Table Read Operations.........................................................................................................107 Other Operations...................................................................................................................107 Instruction Set Summary.............................................................................. 108 Table Conventions.................................................................................................................108 Instruction Definition..................................................................................... 110 Package Information..................................................................................... 120 48-pin LQFP (7mmx7mm) Outline Dimensions....................................................................120 Rev 1.00 6 April 14, 2011 HT82A824R USB Audio MCU Features CPU Features ●● USB 2.0 Full Speed Compatible ●● USB spec V1.1 full speed operation and USB audio device class spec V1.0 ●● Operating voltage at fSYS = 6M/12MHz: 4.0V~5.5V ●● 48KHz/44.1KHz sampling rate for audio playback selected by software ●● Embedded class AB power amplifier for ear phone speaker driving (32Ω)×2 ●● Embedded High Performance 16-bit stereo audio Sigma-Delta DAC ●● Pass Microsoft® DTM (WHQL) USB audio device ●● Audio playback digital volume control ●● 6 endpoints supported including endpoint 0 ●● Support 1 Control, 2 Interrupts, 1 Isochronous and 2 Bulk transfers ●● One hardware implemented Isochronous transfer ●● Total FIFO size are 528 bytes (8, 8, 384, 32, 32, 64 for EP0~EP2,EP4~EP6) ●● 8192×16 Program Memory ●● 352×8 MCU type data memory RAM (Bank 0, Bank 9) ●● 128×8×4 Speaker Output Data or 12-bit ADC Converted Data RAM (Bank1, Bank2, Bank3, Bank4) ●● USB Audio and 12-bit ADC Stereo Data Capture DMA ●● 128×8×4 MCU Type General Purpose Data RAM (Bank5, Bank6, Bank7, Bank8) ●● 6-channel 12-bit A/D converter ●● 2-channel PWM function shared with PB2~PB3 ●● Dual Programmable Attenuator for 2-channel external stereo audio input ●● Universal Asynchronous Receiver Transmitter (UART) shared with PB0~PB1 ●● SPI interface (master and slave mode) shared with PC4~PC7 ●● Programmable frequency divider (PFD) function shared with PC0 ●● Power-down function and wake-up reduce power consumption ●● Up to 21 bidirectional I/O lines ●● Dual 16-bit programmable Timer/Event Counters with overflow interrupts ●● Watchdog Timer ●● 16-level subroutine nesting ●● Bit manipulation instruction ●● 16-bit table read instruction ●● 63 powerful instructions. ●● All instructions executed within one or two machine cycles ●● Low voltage reset function((3.0V±0.3V) ●● 48-pin LQFP package Rev 1.00 7 April 14, 2011 HT82A824R USB Audio MCU General Description This HT82A824R is an 8-bit high performance RISC microcontroller designed for USB Speaker related product applications. The HT82A824R combines a 16-bit DAC, USB transceiver, SIE (Serial Interface Engine), audio class processing unit, FIFO, 8-bit MCU into a single chip. The Sigma-Delta DAC in the HT82A824R is operating at the 48kHz or 44.1kHz sampling rate. The HT82A824R has a digital programmable gain amplifier. The gain range is from -32dB to +6dB. The external stereo audio input can be the other source of power amplifier by software control. The HT82A824R has a Human Interface Device function that allows a user to control the playback volume at the device side. The HT82A824R also can mute the analog output signal by the operation of HID buttons. Block Diagram Rev 1.00 8 April 14, 2011 HT82A824R USB Audio MCU Pin Assignment Pin Description Pin Name PA0~PA3 PA4/MCLK PA5/SCLK PA6/LRCK PA7/SDATA I/O I/O Configuration Option Pull-high Wake-up Description port. 8-bit input/output Bidirectional Each bit can be configured as a input wake-up by a configuration option. Software instructions determine if the or Schmitt trigger input. Configuration pin is output a CMOS options which pins on this port have pull-high resistors. The determine output can be either NMOS or CMOS types determined via structure configuration option. 2 PA4~PA7 are shared with I S output. port. Software instructions determine if Bidirectional 5-bit input/output the pin output or trigger input. Configuration options Schmitt is a CMOS PB0/UART(TX) PB1/UART(RX) PB2/PWM0 PB3/PWM1 PB4 I/O Pull-high Wake-up determine which pins on this port have pull-high resistors. Pins PB0 and PB1 are pin-shared with the UART pins TX and RX. Note that if the UART function is selected, the internal pull-high function will be disabled to these related two pins by hardware. The UART or I/O option. is selected by software function PB2 Pins and pin-shared with PWM0 and PWM1. If the PWM PB3 are function pull-high function related to these two is selected, the internal pins will be disabled by hardware. PWM or I/O function is selected by software option. PC0/BZ PC1/TMR0 PC2/TMR1 PC3/INT PC4/SDO PC5/SDI PC6/SCS PC7/SCK I/O Pull-high Wake-up VREF_R O – Positive voltage reference for DAC converter right channel. Capacitors should be connected to ground to keep from the disturbing signal. VREF_L O – Positive voltage reference for DAC converter left channel. Capacitors should be connected to ground to keep from the disturbing signal. Rev 1.00 Bidirectional Software instructions determine if port. 8-bit input/output the pin output trigger input. Configuration options or Schmitt is a CMOS determine which pins on this have pull-high resistors. Pin PC0 is port shared with the buzzer pin BZ. Pins PC1 and PC2 are shared with timer input pins TMR0 and TMR1. PC3 is shared with external interrupt input INT. Pins PC4 and PC5 are shared with Serial Interface pins SDO and SDI. Pin PC6 is shared with the Serial Interface Slave Select pin. Pin PC7 is shared with the Serial Interface clock signal. 9 April 14, 2011 HT82A824R USB Audio MCU I/O Configuration Option Description MUSIC_IN_R I – Power amplifier input signal source if register bit SELW =”1”. The analog signal input will go through the programmable attenuator and be amplified by the power amp then output to ROUT. MUSIC_IN_L I – Power amplifier input signal source if register bit SELW =”1”. The analog signal input will go through the programmable attenuator and be amplified by the power amp then output to LOUT. BIAS – – Capacitors should be connected to ground to increase common mode voltage stability LOUT O – Left driver analog output ROUT O – Right driver analog output AN0~AN5 I – 12-bit ADC analog inputs OSCI OSCO I O – OSCI, OSCO are connected to an external 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 AVDD1 – – Audio DAC positive power supply AVSS1 – – Audio DAC negative power supply, ground AVDD2 – – Audio power amplifier positive power supply AVSS2 – – Audio power amplifier negative power supply, ground AVDD3 – – 12-bit ADC positive power supply AVSS3 – – 12-bit ADC negative power supply, ground DVDD1 – – Positive digital power supply DVSS1 – – Negative digital power supply, ground Pin Name Absolute Maximum Ratings Supply Voltage .................................................................................................VSS-0.3V to VSS+6.0V Input Voltage ................................................................................................... VSS-0.3V to VDD+0.3V Storage Temperature ................................................................................................... -50°C to 125°C Operating Temperature ................................................................................................. -40°C to 85°C 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. Rev 1.00 10 April 14, 2011 HT82A824R USB Audio MCU D.C. Characteristics Symbol VDD Ta=25°C Parameter Operating Voltage Test Conditions VDD Conditions 5V No load, fSYS=12MHz DAC/PA Operating No load, fSYS=12MHz DAC/PA Off No load, system HALT, USB transceiver and 3.3V regulator on Min. Typ. Max. Unit 4.0 5.0 5.5 V – 60 80 mA – 6 10 mA – 300 – uA 0.3VDD V IDD1 Operating Current 5V IDD2 Operating Current 5V ISUS Suspend Current 5V VIL1 Input Low Voltage for I/O Ports 5V – 0 – VIH1 Input High Voltage for I/O Ports 5V – 0.7VDD – VDD V VIL2 Input Low Voltage (RESET) 5V – 0 – 0.4VDD V VIH2 Input High Voltage (RESET) 5V – 0.9VDD – VDD V IOL I/O Port Sink Current 5V VOL=0.1VDD – 5 – mA IOH I/O Port Source Current 5V VOH=0.9VDD – -2 – mA RPH Pull-high Resistance 5V – 30 40 80 kΩ VLVR0 Low Voltage Reset 5V – 2.7 3.0 3.3 V VV33O 3.3V Regulator Output 5V 3.0 3.3 3.6 V IV33O=-70mA DAC+Power Amp: Test Condition: Measurement bandwidth 20Hz to 20kHz, fS = 48kHz. Line output series capacitor with 220μF. THD+N THD+NNote1 SNRDA Signal to Noise Ratio Note1 5V 10KΩ Load – -77 – dB 5V 10KΩ Load – 88 – dB DR Dynamic Range 5V 10KΩ Load – 90 – dB POUT Output Power 5V 32Ω Load, THD=0.1% – 40 – mW/ch 12-bit ADC DNL ADC Differential Non-Linearity 5V VREF=AVDD3=VDD, tAD=0.5µs – ±2 – LSB INL ADC Integral Non-Linearity 5V VREF=AVDD3=VDD, tAD=0.5µs – ±4 – LSB Note 1: sine wave input@ 1kHz, –6dB Rev 1.00 11 April 14, 2011 HT82A824R USB Audio MCU A.C. Characteristics Symbol Parameter Ta=25°C Test Conditions VDD Conditions Min. Typ. Max. Unit fSYS1 External Crystal 3.3V – – 12 – MHz fSYS2 System Clock 3.3V – 6 – 16 MHz 5V – – 100 – µs tWDTOSC Watchdog Oscillator Period tRES RESET Input Pulse Width – – 1 – – µs tSST System Start-up timer Period – – – 1024 – tSYS tINT Interrupt Pulse Width – – 1 – – µs Note: tSYS=1/fSYS System Architecturex 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. Clocking and Pipelining The main system clock, derived from a Crystal oscillator 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 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. Rev 1.00 12 April 14, 2011 HT82A824R USB Audio MCU System Clocking and Pipelining Fetching Instruction 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 nonconsecutive Program Memory address. Note that the Program Counter width varies with the Program Memory capacity depending upon which device is selected. However, it must be noted that only the lower 8 bits, known as the Program Counter Low Register, are directly addressable by user. 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. 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. Rev 1.00 13 April 14, 2011 HT82A824R USB Audio MCU Mode Program Counter Bits 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 Timer/Event Counter 0 Overflow Timer/Event Counter 1 Overflow Play Interrupt 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 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 Reserved 0 0 0 0 0 0 0 0 1 1 0 0 0 @4 @3 @2 @1 @0 Skip Program Counter+2 Loading PCL PC12 PC11 PC10 PC9 PC8 @7 @6 @5 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 Note: PC12~PC8: Current Program Counter bits @7~@0: PCL bits #12~#0: Instruction code address bits S12~S0: Stack register bits Stack 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. 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. P ro g ra m T o p o f S ta c k C o u n te r S ta c k L e v e l 1 S ta c k L e v e l 2 S ta c k P o in te r B o tto m Rev 1.00 o f S ta c k S ta c k L e v e l 3 P ro g ra m M e m o ry S ta c k L e v e l 1 6 14 April 14, 2011 HT82A824R USB Audio MCU 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: ●● Arithmetic operations ADD, ADDM, ADC, ADCM,SUB, SUBM, SBC, SBCM, DAA ●● Logic operations AND, OR, XOR, ANDM, ORM,XORM, CPL, CPLA ●● Rotation RRA, RR, RRCA, RRC, RLA, RL, RLCA,RLC ●● Increment and Decrement INCA, INC, DECA, DEC ●● Branch decision JMP, SZ, SZA, SNZ, SIZ, SDZ, SIZA,SDZA, CALL, RET, RETI Program Memory 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. Organisation 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. Special Vectors Within the Program Memory, certain locations are reserved for special usage such as reset and interrupts. ●● Location 000H 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. ●● Location 004H 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. ●● 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. Rev 1.00 15 April 14, 2011 HT82A824R USB Audio MCU ●● 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. ●● Location 014H 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, an external interrupt or an UART Bus interrupt, the program will jump to this location and begin execution if the relevant interrupt is enabled and the stack is not full. Porgram Memory Structure Rev 1.00 16 April 14, 2011 HT82A824R USB Audio MCU 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. 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. The following diagram illustrates the addressing/data flow of the look-up table using the single table address pointer TBLP: 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 T B L H S p e c ifie d b y [m ] T a b le C o n te n ts L o w B y te T a b le C o n te n ts H ig h 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. The following diagram illustrates the addressing/data flow of the look-up table using the dual table address pointers TBLP and TBHP: T B H P P ro g ra m M e m o ry T B L P T B L H H ig h b y te o f ta b le c o n te n ts S p e c ifie d b y [m ] H ig h b y te o f ta b le c o n te n ts Dual Address Pointer Look-up Table Rev 1.00 17 April 14, 2011 HT82A824R USB Audio MCU Table Program Example 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. 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. tempreg1 db ? ; temporary register #1 tempreg2 db ? ; temporary register #2 : : mova,06h ; initialise table pointer - note that this address ; is referenced mov tblp,a ; to the last page or present page : : tabrdl tempreg1 ; transfers value in table referenced by table pointer ; to tempregl ; data at prog. memory address “1F06H” transferred to ; tempreg1 and TBLH dec tblp ; reduce value of table pointer by one tabrdl tempreg2 ; 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 ; sets initial address of last page dc 00Ah, 00Bh, 00Ch, 00Dh, 00Eh, 00Fh, 01Ah, 01Bh Table Location Instruction Table Location b12 b11 b10 b9 TABRDC [m] PC12 PC11 PC10 PC9 TABRDL [m] 1 1 1 1 b8 b7 b6 b5 b4 b3 b2 b1 b0 PC8 @7 @6 @5 @4 @3 @2 @1 @0 1 @7 @6 @5 @4 @3 @2 @1 @0 Note: PC12~PC8: Current program counter bits TBHP register bit4~bit0 when TBHP option is enabled @7~@0: Table Pointer TBLP bits Rev 1.00 18 April 14, 2011 HT82A824R USB Audio MCU Data Memory The data memory is divided into three functional groups: namely; Special Purpose Data Memory, Read Only Data Memory and General Data Memory. Bank0: 160×8 bits, Bank1~Bank4: 128×8×4 bits (Read Only), Bank5~Bank8: 128×8×4 bits, Bank9: 192×8 bits. Most are read/write, but some are read only. The Data Memory is a volatile area of 8-bit wide RAM internal memory and is the location where temporary information is stored. The Special Purpose Data Memory 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 General Purpose Data Memory is reserved for general purpose use. All locations within this area are read and write accessible under program control. The Read Only Data Memory is used for audio output data or DAC converted data memory area, and it’s read only. Organisation The Data RAM Memory is subdivided into several banks, known as Bank 0 to Bank 9, 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~4 Data Memory consist only of Read Only Data Memory which are reserved for USB Speaker output data or ADC (AN0~AN1) converted data. The data memory arrangement for USB Speaker output data or ADC converted data is determined by software option. The Bank 5~9 Data Memory consist only of General Purpose Data Memory. The start address of the Data Memory is the address 40H for Bank 1~9 and the last Data Memory address is BFH for Bank 1~8 and FFH for Bank 9. Selection of which Bank is to be used is implemented using the Bank Pointer. 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. Rev 1.00 19 April 14, 2011 HT82A824R USB Audio MCU 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 several banks, Bank 0 to Bank 9, it is necessary to first ensure that the Bank Pointer is properly set to the correct value before accessing the General Purpose Data Memory. For example, 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 Bank1~9 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”.The following example shows how to clear a section of four Data Memory locations already defined as locations adres1 to adres4. Special Purpose Data Memory Structure Rev 1.00 20 April 14, 2011 HT82A824R USB Audio MCU Special Function Registers 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”. 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 pair, IAR0 and MP0 can together only access data from Bank 0, while the IAR1 and MP1 register pair can access data from Bank 0 to Bank 9. 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. 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 Bank 0 to Bank 9. The following example shows how to clear a section of four Data Memory locations already defined as locations adres1 to adres4. Indirect Addressing Program Example data .section ‘data’ adres1 db ? adres2 db ? adres3 db ? adres4 db ? block db ? code .section at 0 ‘code’ org 00h start: mov a,04h ; setup size of block mov block,a mov a,offset adres1 ; Accumulator loaded with first RAM address mov mp0,a ; setup memory pointer with first RAM address loop: clr IAR0 ; clear the data at address defined by MP0 inc mp0 ; increment memory pointer sdz block ; check if last memory location has been cleared jmp loop 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.00 21 April 14, 2011 HT82A824R USB Audio MCU Bank Pointer – BP The Data Memory is divided into several Banks, known as Bank 0 to Bank 9. 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”. 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. B P 3 B P 2 B P 1 B P 0 B P 3 0 0 0 0 0 0 0 0 1 1 B P 2 0 0 0 0 1 1 1 1 0 0 B P 1 0 0 1 1 0 0 1 1 0 0 B P 0 0 1 0 1 0 1 0 1 0 1 S e B a B a B a B a B a B a B a B a B a B a le c n k n k n k n k n k n k n k n k n k n k t 0 1 2 3 4 5 6 7 8 9 N o t u s e d , m u s t b e re s e t to "0 " 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. 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. Rev 1.00 22 April 14, 2011 HT82A824R USB Audio MCU Look-up Table Registers – TBLP, TBLH, TBHP 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. 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. 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, operations 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. ●● C is set if an operation results in a carry during an addition 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. ●● 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 is zero; otherwise Z is cleared. ●● OV is set if an operation results in a carry into the highest- 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. Rev 1.00 23 April 14, 2011 HT82A824R USB Audio MCU 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. Status Register 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 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. Timer/Event Counter Registers – TMRL/TMRH, TMRC 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. Input/Output Ports and Control Registers 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 and PC. 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 and PCC, 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. Rev 1.00 24 April 14, 2011 HT82A824R USB Audio MCU Port A Wake-up Control Register – PA_WAKE_CTRL 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. 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 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. 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.00 25 April 14, 2011 HT82A824R USB Audio MCU 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 wakeup options on certain pins, the user is provided with an I/O structure to meet the needs of a wide range of application possibilities. The microcontroller provides a maximum of 21 bidirectional input/output lines labeled with port names PA, PB and PC. These I/O ports are mapped to the Data Memory with addresses as shown in the Special Purpose Data Memory table. 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. Pull-high Resistors 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 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 C 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 lowpower state until the logic condition of the selected wake-up pin on Port A~Port C 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 C 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. Port A Wake-up Rev 1.00 26 April 14, 2011 HT82A824R USB Audio MCU I/O Port Control Registers Each I/O port has its own control register PAC, PBC and PCC, 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. 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. 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 software options while for others the function is set by application program control. ●● 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. ●● External Interrupt The external interrupt pin INT is pin-shared with the I/O pin PC3. 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. ●● External Timer/Event Counter Input 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. ●● 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. Rev 1.00 27 April 14, 2011 HT82A824R USB Audio MCU ●● 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. ●● UART The UART pins TX/RX are pin-shared with the I/O pins PB0/PB1. For applications not requiring an UART, the pin-shared UART pins can be used as a normal I/O pins, however, to do this, the UART interrupt enable bits in the MFI1C register must be disabled. ●● PWM The PWM pins PWM0/PWM1 are pin-shared with the I/O pins PB2/PB3. For applications not requiring PWM, the pin-shared PWM pins can be used as a normal I/O pins. 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. Input/Output ports Rev 1.00 28 April 14, 2011 HT82A824R USB Audio MCU Programming Considerations 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 and PCC 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 and PC 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. Read/Write Timing Timer/Event Counters 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. Timer/Event Counter 0 Structure Rev 1.00 29 April 14, 2011 HT82A824R USB Audio MCU Timer/Event Counter 1 Structure Configuring the Timer/Event Counter Input Clock Source 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. Timer Registers – TMR0H/TMR0L, TMR1L/TMR1H 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 reset 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. 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 lowerorder byte buffer. However reading the TMR0L/TMR1L will only read the contents of the low byte buffer. Rev 1.00 30 April 14, 2011 HT82A824R USB Audio MCU Timer Control Register – TMR0C, TMR1C 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. Timer/Event Counter 0/1 Control Register 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. Timer Mode Timing Chart Rev 1.00 31 April 14, 2011 HT82A824R USB Audio MCU 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. 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 wakeup source. Event Counter Mode Timing Chart 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. 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 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. Rev 1.00 32 April 14, 2011 HT82A824R USB Audio MCU 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. 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. Pulse Width Measure Mode Timing Chart 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 pinshared 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 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. Rev 1.00 33 April 14, 2011 HT82A824R USB Audio MCU 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. 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 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. Rev 1.00 34 April 14, 2011 HT82A824R USB Audio MCU 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 jmp usbint reti org 08h jmp tmr0int : org 20h Tmr0int: : : reti : : begin: mov mov mov mov mov mov a,09bh tmr0l,a a,00h tmr0h,a a,080h tmr0c,a ; usb interrupt vector ; Timer/Event Counter 0 interrupt vector ; jump here when Timer0 overflows ; main program ;internal Timer/Event Counter 0 interrupt routine ; Timer/Event Counter 0 main program placed here ;setup Timer0 registers ; setup preload value – timer0 counts from this value to FFFFH ; ; ; ; ; ; setup Timer0 control register timer mode setup interrupt register enable master interrupt and timer interrupt mov a,005h mov intc0,a set tmr0c.4 ; start Timer0 - note mode bits must be previously setup 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. 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 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. The BZ signal comes from an internal PFD generator output. Rev 1.00 35 April 14, 2011 HT82A824R USB Audio MCU PFD Block Diagram PFDC Register The generated frequency of the PFD function is given by the following formula: Rev 1.00 36 April 14, 2011 HT82A824R USB Audio MCU Power Amplifier The SELW bit in the PFDC register is used to control the power amplifier input source. The application program should set SELW =″1″ when the power amplifier signal source is from MUSIC_ IN_L and MUSIC_IN_R, otherwise the speaker will output USB Audio data. 16-bit D/A Output SELW=0 SELW=1 M U X LOUT Power Amp ROUT Programmable Attenuator (L) MUSIC_IN_L Programmable Attenuator (R) MUSIC_IN_R Programmable Attenuator The device includes two fully integrated Programmable Attenuators for two external audio input pins, MUSIC_IN_L and MUSIC_IN_R. The Attenuators are used to reduce the amplitude and power of the external audio input signal before entering the Power Amplifier. The Attenuators are fully under the control of two internal registers, ATTENU_CTRL_L and ATTENU_CTRL_R, one for each attenuator. These registers control the programmable gain function and mute function. The range of programmable gain is from 0 dB to a minimum of -22.5 dB, controlled by ATTENU_CTRL_L[0:6] and ATTENU_CTRL_R[0:6] bits . The resolution of the Attenuator is 0.5 dB per step. The Programmable Attenuator mute function is controlled by the ATTENU_MUTEB_L(R) bit. If this bit is cleared to ″0″, that will enable the mute function and the Power Amp output voltage will be forced to a level of half the power supply. ATTEN_CTRL_L and ATTEN_CTRL_R Registers Attenuator L/R Control Registers Rev 1.00 37 April 14, 2011 HT82A824R USB Audio MCU Interrupts Interrupts are an important part of any microcontroller system. When a USB Interrupt, play data valid interrupt, a Timer/Event Counter overflow, reception of SPI data , External Interrupt, UART Bus interrupt or A/D 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 data valid interrupt and a Multi function interrupt. This latter Multi-function Interrupt represents the Serial Interface Interrupt, an External Interrupt, an UART Bus Interrupt or A/D 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 Operation A USB interrupt, a Play data valid interrupt, a Timer/Event Counter overflow, an SPI interrupt, an A/D conversion complete interrupt, an active edge on the external interrupt pin or an UART Bus interrupt 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 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. Rev 1.00 38 April 14, 2011 HT82A824R USB Audio MCU 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. Priority Vector USB Interrupt Interrupt Source 1 04H Timer/Event Counter 0 overflow 2 08H Timer/Event Counter 1 overflow 3 0CH Play Interrupt 4 10H Multi function 1 interrupt subroutine: Serial Interface Interrupt, A/D Interrupt, External Interrupt, UART Bus Interrupt – – 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. INTC0 Register Rev 1.00 39 April 14, 2011 HT82A824R USB Audio MCU INTC1 Register Interrupt Structure Rev 1.00 40 April 14, 2011 HT82A824R USB Audio MCU USB 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: ●● 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 USB 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 HT82A824R 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 HT82A824R receives a USB Suspend signal from the host PC, the suspend line, bit0 of the USC register, in the HT82A824R 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. Timer/Event Counter Interrupt 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. Play Interrupt For a Play Interrupt to occur, the global interrupt enable bit, EMI, 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 44.1KHz if the PLAY_MODE bit in the MODE_CTRL register is 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. Rev 1.00 41 April 14, 2011 HT82A824R USB Audio MCU 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 four other existing interrupt sources, namely the Serial Interface interrupt, the A/D Converter interrupt, the External interrupt and the UART Bus 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 or an A/D Converter Interrupt, an External Interrupt occurs or an UART Bus interrupt. 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 or the A/D Converter, the External Interrupt or the UART Bus interrupt will not be automatically reset and must be manually reset by the user. MFI1C Register Rev 1.00 42 April 14, 2011 HT82A824R USB Audio MCU External Interrupt 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 PC3 and can only be configured as external interrupt pins if the interrupt is enabled and if the pin is programmed as an input pins. 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 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. 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. Rev 1.00 43 April 14, 2011 HT82A824R USB Audio MCU 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. It is recommended that programs do not use the “CALL subroutine” instruction within the interrupt subroutine. Interrupts often occur in an unpredictable manner or 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. 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. 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. 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. 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. 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 address, 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. Rev 1.00 44 April 14, 2011 HT82A824R USB Audio MCU 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 this time delay, normal operation of the 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. Power-On Reset Timing Chart For most applications a resistor connected between V DD 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. Basic Reset Circuit For applications that operate within an environment where more noise is present the Enhanced Reset Circuit shown is recommended. Enhanced Reset Circuit Rev 1.00 45 April 14, 2011 HT82A824R USB Audio MCU ●● RESET Pin Reset 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 Counter will reset to zero and program execution initiated from this point. 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. Low Voltage Reset Timing Chart ●● Watchdog Time-out Reset during Normal Operation The Watchdog time-out Reset during normal operation is the same as a hardware RESET pin reset except that the Watchdog time-out flag TO will be set to “1” WDT Time-out Reset during Normal Operation Timing Chart ●● Watchdog Time-out Reset during Power Down 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. WDT Time-out Reset during Power Down Timing Chart Rev 1.00 46 April 14, 2011 HT82A824R USB Audio MCU 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 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 Note: “u” stands for unchanged. The following table indicates the way in which the various components of the microcontroller are affected after a power-on reset occurs. Item 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 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 WDT Reset Time-out (Power On) (Normal Operation) RES Reset RES Reset (Normal (HALT) Operation) WDT USB-reset Time-out (Normal) (HALT)* USB-reset (HALT) TMR0H xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu xxxx xxxx xxxx xxxx TMR0L xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu xxxx xxxx xxxx xxxx 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 xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu xxxx xxxx xxxx xxxx TMR1L xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu xxxx xxxx xxxx xxxx TMR1C 00-0 1-- 00-0 1-- 00-0 1-- 00-0 1-- uu-u u-- 00-0 1-- 00-0 1-- Program Counter 000H 000H 000H 000H 000H 000H 000H 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 BP 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu 0000 0000 0000 0000 ACC xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu Rev 1.00 47 April 14, 2011 HT82A824R USB Audio MCU Register WDT Reset Time-out (Power On) (Normal Operation) RES Reset RES Reset (Normal (HALT) Operation) WDT USB-reset Time-out (Normal) (HALT)* USB-reset (HALT) TBLP xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu TBLH -xxx xxxx -uuu uuuu -uuu uuuu -uuu uuuu -uuu uuuu -uuu uuuu -uuu uuuu 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 INTC1 -000 0000 -000 0000 -000 0000 -000 0000 -uuu uuuu -000 0000 -000 0000 WDTS 0000 0111 0000 0111 0000 0111 0000 0111 uuuu uuuu 0000 0111 0000 0111 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 PB 1111 1111 1111 1111 1111 1111 1111 1111 uuuu uuuu 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 INTC1 -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 USVC 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu 0000 0000 0000 0000 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 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 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 xxxx 0xxx xxxx 0xxx xxxx 0xxx xxxx 0xxx xxxx uxxxx xxxx 0xxx xxxx 0xxx 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 SIES 0000 0000 uuuu uuuu 0000 0000 0000 0000 uuuu uuuu 0u00 u000 0u00 u000 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 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 MODE_CTRL 0000 0000 0000 0000 0000 0000 0000 0000 0000 0uuu 0000 0uuu 0000 0uuu PLAY_DATAL_L 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu uuuu uuuu 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 Rev 1.00 48 April 14, 2011 HT82A824R USB Audio MCU Register WDT Reset Time-out (Power On) (Normal Operation) RES Reset RES Reset (Normal (HALT) Operation) WDT USB-reset Time-out (Normal) (HALT)* USB-reset (HALT) PLAY_DATAR_H 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu uuuu uuuu PA_WAKE_CTRL 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 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 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 FIFO5 xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu 0000 0000 0000 0000 FIFO6 xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu uuuu uuuu 0000 0000 0000 0000 ATTENU_CTRL_L 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu ATTENU_CTRL_R 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu USF 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu 0000 0000 0000 0000 USR1 0000 1011 0000 1011 0000 1011 0000 1011 uuuu uuuu uuuu uuuu uuuu uuuu UCR1 0000 00x0 0000 00x0 0000 00x0 0000 00x0 uuuu uuuu uuuu uuuu uuuu uuuu UCR2 0000 0000 0000 0000 0000 0000 0000 0000 uuuu uuuu uuuu uuuu uuuu uuuu TXR/RXR xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu BRG xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx 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 Note: “*” stands for “warm reset” “u” stands for “unchanged” “x” stands for “unknown” “-” stands for “undefined” Rev 1.00 49 April 14, 2011 HT82A824R USB Audio MCU 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. System 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 22 pF 12MHz Crystal NC Watchdog Timer Oscillator The WDT oscillator is a fully self-contained free running on-chip RC oscillator with a typical period of 65μs 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. Rev 1.00 50 April 14, 2011 HT82A824R USB Audio MCU Power Down Mode and Wake-up Power Down Mode All of the Holtek microcontrollers have the ability to enter a Power Down 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 microcontroller 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. 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 application program will stop at the “HALT” instruction. ●● The Data Memory contents and registers will maintain their present condition. ●● 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. ●● The I/O ports will maintain their present condition. ●● In the status register, the Power Down flag, PDF, will 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. Care must also be taken with the loads, which are connected to I/Os, 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 inputs. Also note that additional standby current will also be required if the configuration options have enabled the Watchdog Timer internal oscillator. Rev 1.00 51 April 14, 2011 HT82A824R USB Audio MCU 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 C ●● 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. Each pin on Port A can be setup via an individual configuration option to permit a negative (or positive) transition 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. 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 Wakeup function. Any external pin wake-up will cause the system to resume execution at the instruction following the “HALT” instruction. 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. 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. Rev 1.00 52 April 14, 2011 HT82A824R USB Audio MCU 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. The internal WDT oscillator has an approximate period of 65μs 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 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. 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. 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. Rev 1.00 53 April 14, 2011 HT82A824R USB Audio MCU Watchdog Timer Register Watchdog Timer Rev 1.00 54 April 14, 2011 HT82A824R USB Audio MCU USB Function The device includes a USB 1.1 interface which can be used for data application data transfer. Six endpoints are included in the USB function of this device. USB Interface The USB Interface in the HT82A824R device has 6 Endpoints, known as EP0~EP2, EP4~EP6. Endpoint 0, EP0, is used for Control transfer. Endpoints EP1 and EP4 are for Interrupt transfer, while EP2 supports the Isochronous out transfer. EP5 and EP6 are for Bulk (or Interrupt) 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 six FIFO registers with the names FIFO0~FIFO2, FIFO4~FIFO6. The size of each FIFO is as follows: FIFO0-8 bytes, FIFO1-8 bytes, FIFO2-384 bytes, FIFO4-32 bytes, FIFO5-32 bytes and FIFO6-64 bytes giving a total of 528 bytes. The URD bit, which is bit7 of the USC register is the USB reset signal control function definition bit. 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 USC Register The USC register is the register for the overall control of the USB function. The initial status of this register is 80H. USB Control Register - USC Rev 1.00 55 April 14, 2011 HT82A824R USB Audio MCU Further explanation of each of the bits is given below: ●● 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. ●● RMWK 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. ●● URST 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. ●● 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. ●● V33C The V33C read/write bit is the control bit for the internally generated 3.3V supply for the USB interface. ●● PLLENB The PLLENB read/write bit is the control bit for the internal Phase Locked Loop function. ●● CRCFG 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. ●● URD The URD read/write bit is the USB reset signal control function definition bit. Rev 1.00 56 April 14, 2011 HT82A824R USB Audio MCU USR Register 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, EP4F, EP5F and EP6F 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. b 7 b 0 E P 6 F E P 5 F E P 4 F E P 2 F E P 1 F E P 0 F 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 N o t im p le m e n te d , r e a d a s " 0 " E n d p o in t 4 a c c e s s E n d p o in t 5 a c c e s s E n d p o in t 6 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 Further explanation of each of the bits is given below: ●● EP0F~EP2F, EP4F~EP6F The EP0F~EP2F, EP4F~EP6F read/write bits are set by the SIE to 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. Rev 1.00 57 April 14, 2011 HT82A824R USB Audio MCU UCC Register 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. System Clock Control Register - UCC Further explanation of each of the bits is given below: ●● EPS0~EPS2 These three read/write bits are for the endpoint FIFO selection. It should be noted that Isochronous endpoints 2 is implemented in hardware, therefore FIFO2 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. ●● 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. ●● OSCCLK The OSCCLK read/write bit is used to determine if the oscillator clock is either 6MHz or 12MHz. Rev 1.00 58 April 14, 2011 HT82A824R USB Audio MCU 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. Device Address Register - AWR 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”. Endpoint Stall Register - STALL Rev 1.00 59 April 14, 2011 HT82A824R USB Audio MCU SIES Register The SIES register is the setup register for the Serial Interface Engine. Serial Interface Setup Register - SIES 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 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. ●● 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. ●● OUT 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. ●● IN The read only IN bit is used to indicate that the current USB receiving signal from PC host is an IN token. Rev 1.00 60 April 14, 2011 HT82A824R USB Audio MCU ●● 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. ●● CRCF 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 The EOT read only read only flag is the Token Package active flag. Note that this flag is active low. ●● 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. Rev 1.00 61 April 14, 2011 HT82A824R USB Audio MCU 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. Miscellaneous Register - MISC Further explanation of each of the bits is given below: ●● REQUEST 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 ●● TX The read/write TX bit represents the direction and MCU access transition end. When set high, the MCU 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. ●● CLEAR 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. ●● ISO_OUT_EN The read/write ISO_OUT_EN bit enables the isochronous out pipe interrupt. ●● 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. ●● READY The read only READY bit is used to indicate that the desired FIFO is ready. ●● LEN0 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. Rev 1.00 62 April 14, 2011 HT82A824R USB Audio MCU SETIO Register 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. USB Endpoint Setup IN/OUT Pipe Register - SETIO Rev 1.00 63 April 14, 2011 HT82A824R USB Audio MCU USB_STATE Register This register is used to indicate the error state due to SE0 or SE1 noise, the USBD- and USBD+ input signals and the I2S output control. The SE0 and SE1 bits are set by the SIE and cleared with the program. b7 b0 I2S_OUT_EN I2S_Format USBDP USBDN SE1 SE0 SCLK1 SCLK0 USB-STATE Register SCLK Clock Selection SCLK1 SCLK0 0 0: MCLK/4 0 1: MCLK/2 1 x: MCLK SE0 noise detection 1: Noise detected in USB bus 0: Noise not detected SE1 noise detection 1: Noise detected in USB bus 0: Noise not detected USBD- input USBD+ input 0: Left Justified Mode 1: I2S Mode I2S Output Enable Control bit 1: I2S Output Enable (The PA4~PA7 are as I2S output pins) 0: I2S Output Disable (The PA4~PA7 are as I/O pins) - default "0" USB State Register - USB-STATE The PA4~PA7 are pin-shared with I2S output pins. The following table illustrates the corresponding pin assignment. When the I2S_OUT_EN bit is set to high, that will enable the I2S output function and the PA4~PA7 will force to be the I2S data output pins by hardware. PA4~PA7 I2S pin assignment (I2S_OUT_EN=1) I2S pins Pin name I/O Description 2 PA4 MCLK O I S Master clock PA5 SCLK O I S Serial clock PA6 LRCK O I S Left/Right clock PA7 SDATA O I S Serial data 2 2 2 The HT82A824R provided the I2S output mode which is Left Justified or I2S 16-bit mode and the output pins can be connected to an external I2S D/A converter to generate the audio signal. When the I2S_OUT_EN bit is set to high, the I2S output will be enabled at the same time. The following diagram illustrates the I2S data format. L R C K L e ft C h a n n e l R ig h t C h a n n e l S C L K S D A T A M S B -1 -2 -3 -4 -5 + 5 + 4 + 3 + 2 + 1 M S B L S B -1 -2 -3 -4 + 5 + 4 + 3 + 2 + 1 L S B Left Justified 16-Bit Mode L R C K L e ft C h a n n e l R ig h t C h a n n e l S C L K S D A T A M S B -1 -2 -3 -4 -5 + 5 + 4 + 3 + 2 + 1 M S B L S B -1 -2 -3 -4 + 5 + 4 + 3 + 2 + 1 L S B 2 I S 16-Bit Mode Rev 1.00 64 April 14, 2011 HT82A824R USB Audio MCU Suspend Wake-Up Remote Wake-Up 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 HT82A824R 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. The following shows the related timing of this operation: 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. The following shows the related timing: S U S P E N D M in . 1 U S B C L K R M W K U S B R e s u m e S ig n a l M in .2 .5 m s U S B _ IN T USF Register This register is used to indicate the Data RAM Bank1~4 are assigned for USB Audio data or 12bit A/D converted data, the A/D bias setting, the RAM Bank1~4 data mode selection and the data loaded status. Rev 1.00 65 April 14, 2011 HT82A824R USB Audio MCU USB Speaker Flag register - USF When the Data_Mode bit in USF register is cleared to low, the Data RAM Bank1~4 are assigned to the USB Audio Data. The DMA controller will fetch the USB Audio data to RAM Bank1~4 sequentially via the sampling frequency 48KHz (PLAY_MODE=0) or 44.1KHz (PLAY_MODE=1). If the StartBit bit is set to high will enable the DMA controller and if the loading process is completed, the FullBit bit will be set to high by hardware. Sta�tBit=1 Fu��Bit==1 N Y Sta�tBit=0 Read R�M Bank 1~� END Flow Chart of reading RAM Bank 1~4 (Data_Mode=0) Rev 1.00 66 April 14, 2011 HT82A824R USB Audio MCU When the Data_Mode bit in USF register is set to high, the Data RAM Bank1~4 are assigned to the ADC Converted Data. The DMA controller will fetch the ADC Converted data to RAM Bank1~4 sequentially via the sampling frequency Fsys/256. If the StartBit bit is set to high will enable the DMA controller and if the loading process is completed, the FullBit bit will be set to high by hardware. If the ADC interrupt related control bits are enabled, the ADC interrupt will happen as every one sample conversion process is completed. The following block diagram illustrates the functional blocks for the data fetching process from the ADC to the Data RAM Bank1~4. RAM bank1~bnak4 DMA Controller BIAS_CTRL AN0 12-bit ADC M U X Bias Circuit AN1 Audio Input (L) Audio Input (R) DataMode=1 Rev 1.00 67 April 14, 2011 HT82A824R USB Audio MCU The following flow chart illustrates the procedure for the data fetching process from the ADC to the Data RAM Bank1~4. Power up 12-bit A/D Converter F/W Setting disable ADC interrupt Enable Bias Circuit Data_Mode=1 Note: 1.After setting the StartBit to high by software, the DMA controller will start to fetch the ADC converted data to RAM Bank1~4. 2.If the 512 bytes data are fetched to the RAM Bank1~4, the FullBit bit will be set to high by hardware. 3.The ADC clock source will be forced to be the system clock fSYS. StartBit=1 H/W DMA FullBit=1 N Y StartBit=0 Read RAM Bank 1~4 END Flow Chart of reading RAM Bank 1~4 (Data_Mode=1) Rev 1.00 68 April 14, 2011 HT82A824R USB Audio MCU Audio Data Format If the Data_Mode is cleared to low, the RAM Bank1~4 data is from USB Audio Data. ●● Bank1~Bank4 audio data format (16 bit → 8 bit): Bank1~Bank� USB �udio Data Fo�mat (16 bit → 8 bit) 15 1� 13...� 15 13 1 1�...9 8 O�igina� 16 bit �udio data (�'s com��ement) 0 7 T�uncate 16 bit �udio data to 8-bit If the Data_Mode is set to high, the RAM Bank1~4 data is from ADC converted data via AN0 and AN1 channels. ●● Bank1~Bank4 audio data format (12 bit → 8 bit): Bank1~Bank� Data Fo�mat (1� bit → 8 bit) 11 10 11 9...� 10 1 9...6 5 � 0 O�igina� 1� bit �/D data (�'s com��ement) T�uncate 1� bit �/D data to 8-bit ModeSelect=0 (Spctrum, (R+L)/2) RAM Bank 1 128 Bytes RAM Bank 2 128 Bytes 512 samples RAM Bank 3 128 Bytes RAM Bank 4 128 Bytes ModeSelect=1 (L/R) RAM Bank 1 128 Bytes, Left Channel RAM Bank 2 128 Bytes, Left Channel RAM Bank 3 128 Bytes, Right Channel RAM Bank 4 128 Bytes, Right Channel 256 Left channel samples 256 Right channel samples Data_Mode=0 or Data_Mode=1 Rev 1.00 69 Data_Mode=0 or Data_Mode=1 April 14, 2011 HT82A824R USB Audio MCU 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 MUTEB bit is low and both the DAC and the power amplifier will be muted. 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 Note: Speaker mute control MUTE=0: Mute speaker output. MUTE=1: Normal. FIFO Registers FIFO0~FIFO6 (28H~2CH, 4BH~4CH) USB endpoint accessing registers definitions Rev 1.00 Registers R/W Power-on Function FIFO0~FIFO6 R/W xxH EPi accessing register – EPSX bits in the UCC register. (i = 0~6). When an endpoint is disabled, th corresponding accessing register should be disabled. 70 April 14, 2011 HT82A824R USB Audio MCU 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 0 b 7 D A C _ W R _ T R IG 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 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.00 71 April 14, 2011 HT82A824R USB Audio MCU Example to avoid popping noise: System_Initial: ;----------------------------------------------------------; Avoid Pop Noise ;----------------------------------------------------------mov a,WDTS mov FIFO_TEMP,a ;Save WDTS value mov a,00001111b andm 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 nop ;Write 8000H to DAC set [02FH].3 nop clr [02FH].3 nop ;----------------------------------------------------------mov a,FIFO_TEMP ;Restore WDTS value mov WDTS,a ;Quit DAC Write Data mode ;----------------------------------------------------------- SPI Serial Interface 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. 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 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. 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: CKS M1 M0 SBEN MLS CSEN WCOL TRF 0 1 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. Rev 1.00 72 April 14, 2011 HT82A824R USB Audio MCU 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. 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. SPI Block Diagram Rev 1.00 73 April 14, 2011 HT82A824R USB Audio MCU SPI Interface Control Register 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. 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. 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: Rev 1.00 74 April 14, 2011 HT82A824R USB Audio MCU ●● 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. ♦♦ 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. ♦♦ 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 SPI 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 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 SPI serial bus interrupt. ♦♦ Step 8. Read data from the SBDR register. ♦♦ Step 9. Clear TRF ♦♦ Step10. Goto step 5 SBEN =1 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: 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. Rev 1.00 75 April 14, 2011 HT82A824R USB Audio MCU SCSB SCK SIO_CPOL=0 SIO_CKEG=1 SIO_CPOL=1 SIO_CKEG=1 SIO_CPOL=0 SIO_CKEG=0 SIO_CPOL=1 SIO_CKEG=0 SDI D7/D0 D6/D1 D5/D2 D4/D3 D3/D4 D2/D5 D1/D6 D0/D7 SDO D7/D0 D6/D1 D5/D2 D4/D3 D3/D4 D2/D5 D1/D6 D0/D7 MLS=1 MSB Shift first MLS=0 LSB Shift first 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. 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. Mode Control Register The MODE_CTRL register is used to control DAC and ADC operation mode and SPI function. Rev 1.00 76 April 14, 2011 HT82A824R USB Audio MCU Mode Control Register - MODE_CTRL Note: That the WCOL and CSEN bits are in the SBCR register. SPI usage Example: SPI_Test: clr UCC.@UCC_SYSCLK ;12MHz SYSCLK set SIO_CSEN ;SPI Chip Select Function Enable set SIO_CPOL ;rising edge change data set SIO_CKEG ;data output before serial clock edge ;Master Mode, SCLK=fSIO clr M1 clr M0 ;-------------clrCKS ;fSIO=fsys/2 clr TRF ;clear TRF flag clr TRF_INT ;clear Interrupt SPI flag set MLS ;MSB shift first set CSEN ;Chip Select Enable set SBEN ;SPI Enable, SCS will go low if POLLING_MODE clr ESII ;SPI Interrupt Disable ;WRITE INTO "WRITE ENABLE" INSTRUCTION MOV A,OP_WREN MOV SBDR,A $0: snz TRF jmp$0 clr TRF else set ESII ;SPI Interrupt Enable ;WRITE INTO "WRITE ENABLE" INSTRUCTION MOV A,OP_WREN MOV SBDR,A $0: snz TRF_INT ;set at SPI Interrupt jmp $0 clr TRF_INT endif Rev 1.00 77 April 14, 2011 HT82A824R USB Audio MCU Play Data The Play data for the device is contained in 4 Play registers. The play interrupt will be activated when play data in the PLAY_DATA registers is valid. The PLAY_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 update rate for the PLAY_DATA is 48KHz, if the PLAY_MODE bit in the MODE_CTRL register is equal to 0, or 44.1KHz if the bit is equal to 1. All of the PLAY 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_D1 PR_D0 PLAY_DATAR_H PR_D15 PR_D14 PR_D13 PR_D12 PR_D11 PR_D10 PR_D9 PR_D8 PR_D6 PR_D5 PR_D4 PR_D3 PR_D2 Analog to Digital Converter 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. A/D Overview 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. A/D Converter Data Registers – ADRL, ADRH For the HT82A824R 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. In the following tables, D0~D11 are the A/D conversion data result bits. Register Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 ADRL D3 D2 D1 D0 – – – – ADRH D11 D10 D9 D8 D7 D6 D5 D4 A/D Converter Data Register Rev 1.00 78 April 14, 2011 HT82A824R USB Audio MCU A/D Converter Control Register – ADCR 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. 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 Structure 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. 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 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. Rev 1.00 79 April 14, 2011 HT82A824R USB Audio MCU A/D Converter Clock Source Register – ACSR 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. ADCR Register A/D Converter Clock Source Register 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 AVDD3 power supply pin is used as a separate pin for the A/D converter power supply while the AVSS3 pin is used as the A/D converter ground pin. The A/D converter reference is internally connected to the AVDD3 power supply pin. Rev 1.00 80 April 14, 2011 HT82A824R USB Audio MCU 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. Summary of A/D Conversion Steps The following summarizes the individual steps that should be executed in order to implement an A/D conversion process. ●● Step 1 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. ●● 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 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”. ●● 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. 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. Rev 1.00 81 April 14, 2011 HT82A824R USB Audio MCU The following timing diagram shows graphically the various stages involved in an analog to digital conversion process and its associated timing. A/D Conversion 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. Programming Considerations 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. 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. 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. 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. Rev 1.00 82 April 14, 2011 HT82A824R USB Audio MCU Example: using an EOCB polling method to detect the end of conversion for the HT82A824R. clr EADI ; mov a,00000001 B mov ACSR,a ; ; mov a,00100000B ; ; mov ADCR,a ; ; :; : ; : Start_conversion: clr START Set START ; clr START ; Polling_EOC: sz EOCB ; ; jmp polling_EOC ; mov a,ADRH ; ; Adr_buffer_h,a ; mov a,ADRL ; ; mov adr_buffer_l,a ; : : jmp start_conversion ; Rev 1.00 disable ADC interrupt setup the ACSR register to select fSYS/8 as the A/D clock setup the ADCR register to power up the A/D converter 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 reset A/D start A/D poll the ADCR register EOCB bit to detect end of A/D conversion continue polling read conversion result high byte value from the ADRH register save result to user defined memory read conversion result low byte value from the ADRL register save result to user defined memory start next A/D conversion 83 April 14, 2011 HT82A824R USB Audio MCU Example: using an interrupt method to detect the end of conversion for the HT82A824R. clr EADI ; mov a,00000001B mov ACSR,a ; ; mov a,00100000B ; ; mov ADCR,a ; ; :; : ; : Start_conversion: clr ADF ; set EMF1I ; set EADI ; set EMI ; clr START set START ; clr START ; : : : ; 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, Rev 1.00 disable ADC interrupt setup the ACSR register to select fSYS/8 as the A/D clock setup the ADCR register to power up the A/D converter 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 clear ADC interrupt request flag Multi function 1 interrupt Enable enable ADC interrupt enable global interrupt reset A/D start A/D ADC interrupt service routine 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 84 April 14, 2011 HT82A824R USB Audio MCU A/D Transfer Function As the HT82A824R 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. Ideal A/D Transfer Function UART Bus Serial Interface The HT82A824R device contains an integrated full-duplex asynchronous serial communications UART interface that enables communication with external devices that contain a serial interface. The UART function has many features and can transmit and receive data serially by transferring a frame of data with eight or nine data bits per transmission as well as being able to detect errors when the data is overwritten or incorrectly framed. The UART function possesses its own internal interrupt which can be used to indicate when a reception occurs or when a transmission terminates. UART Features The integrated UART function contains the following features: ●● Full-duplex, asynchronous communication ●● 8 or 9 bits character length ●● Even, odd or no parity options ●● One or two stop bits ●● Baud rate generator with 8-bit prescaler ●● Parity, framing, noise and overrun error detection ●● Support for interrupt on address detect (last character bit=1) ●● Separately enabled transmitter and receiver ●● 2-byte Deep FIFO Receive Data Buffer ●● Transmit and receive interrupts Rev 1.00 85 April 14, 2011 HT82A824R USB Audio MCU Interrupts can be initialized by the following conditions: ●● Transmitter Empty ●● Transmitter Idle ●● Receiver Full ●● Receiver Overrun ●● Address Mode Detect UART External Pin Interfacing To communicate with an external serial interface, the internal UART has two external pins known as TX and RX. The TX pin is the UART transmitter pin, which can be used as a general purpose I/ O pin if the pin is not configured as a UART transmitter, which occurs when the TXEN bit in the UCR2 control register is equal to zero. Similarly, the RX pin is the UART receiver pin, which can also be used as a general purpose I/O pin, if the pin is not configured as a receiver, which occurs if the RXEN bit in the UCR2 register is equal to zero. Along with the UARTEN bit, the TXEN and RXEN bits, if set, will automatically setup these I/O pins to their respective TX output and RX input conditions and disable any pull-high resistor option which may exist on the RX pin. UART Data Transfer Scheme The block diagram shows the overall data transfer structure arrangement for the UART. The actual data to be transmitted from the MCU is first transferred to the TXR register by the application program. The data will then be transferred to the Transmit Shift Register from where it will be shifted out, LSB first, onto the TX pin at a rate controlled by the Baud Rate Generator. Only the TXR register is mapped onto the MCU Data Memory, the Transmit Shift Register is not mapped and is therefore inaccessible to the application program. Data to be received by the UART is accepted on the external RX pin, from where it is shifted in, LSB first, to the Receiver Shift Register at a rate controlled by the Baud Rate Generator. When the shift register is full, the data will then be transferred from the shift register to the internal RXR register, where it is buffered and can be manipulated by the application program. Only the RXR register is mapped onto the MCU Data Memory, the Receiver Shift Register is not mapped and is therefore inaccessible to the application program. It should be noted that the actual register for data transmission and reception, although referred to in the text, and in application programs, as separate TXR and RXR registers, only exists as a single shared register in the Data Memory. This shared register known as the TXR/RXR register is used for both data transmission and data reception. UART Status and Control Registers There are five control registers associated with the UART function. The USR1, UCR1 and UCR2 registers control the overall function of the UART, while the BRG register controls the Baud rate. The actual data to be transmitted and received on the serial interface is managed through the TXR/ RXR data registers. Rev 1.00 86 April 14, 2011 HT82A824R USB Audio MCU T r a n s m itte r S h ift R e g is te r M S B R e c e iv e r S h ift R e g is te r L S B T X P in M S B R X P in C L K L S B C L K T X R R e g is te r B a u d R a te G e n e ra to r M C U R X R R e g is te r B u ffe r D a ta B u s UART Data Transfer Scheme USR1 Register The USR1 register is the status register for the UART, which can be read by the program to determine the present status of the UART. All flags within the USR1 register are read only. Further explanation on each of the flags is given below: ●● TXIF The TXIF flag is the transmit data register empty flag. When this read only flag is “0” it indicates that the character is not transferred to the transmit shift registers. When the flag is “1” it indicates that the transmit shift register has received a character from the TXR data register. The TXIF flag is cleared by reading the UART status register (USR1) with TXIF set and then writing to the TXR data register. Note that when the TXEN bit is set, the TXIF flag bit will also be set since the transmit buffer is not yet full. ●● TIDLE The TIDLE flag is known as the transmission complete flag. When this read only flag is “0” it indicates that a transmission is in progress. This flag will be set to “1” when the TXIF flag is “1” and when there is no transmit data, or break character being transmitted. When TIDLE is “1” the TX pin becomes idle. The TIDLE flag is cleared by reading the USR1 register with TIDLE set and then writing to the TXR register. The flag is not generated when a data character, or a break is queued and ready to be sent. ●● RXIF The RXIF flag is the receive register status flag. When this read only flag is “0” it indicates that the RXR read data register is empty. When the flag is “1” it indicates that the RXR read data register contains new data. When the contents of the shift register are transferred to the RXR register, an interrupt is generated if RIE=1 in the UCR2 register. If one or more errors are detected in the received word, the appropriate receive-related flags NF, FERR, and/or PERR are set within the same clock cycle. The RXIF flag is cleared when the USR1 register is read with RXIF set, followed by a read from the RXR register, and if the RXR register has no data available. ●● RIDLE The RIDLE flag is the receiver status flag. When this read only flag is “0” it indicates that the receiver is between the initial detection of the start bit and the completion of the stop bit. When the flag is “1” it indicates that the receiver is idle. Between the completion of the stop bit and the detection of the next start bit, the RIDLE bit is “1” indicating that the UART is idle. Rev 1.00 87 April 14, 2011 HT82A824R USB Audio MCU ●● OERR The OERR flag is the overrun error flag, which indicates when the receiver buffer has overflowed. When this read only flag is “0” there is no overrun error. When the flag is “1” an overrun error occurs which will inhibit further transfers to the RXR receive data register. The flag is cleared by a software sequence, which is a read to the status register USR1 followed by an access to the RXR data register. ●● FERR The FERR flag is the framing error flag. When this read only flag is “0” it indicates no framing error. When the flag is “1” it indicates that a framing error has been detected for the current character. The flag can also be cleared by a software sequence which will involve a read to the USR1 status register followed by an access to the RXR data register. ●● NF The NF flag is the noise flag. When this read only flag is “0” it indicates a no noise condition. When the flag is “1” it indicates that the UART has detected noise on the receiver input. The NF flag is set during the same cycle as the RXIF flag but will not be set in the case of an overrun. The NF flag can be cleared by a software sequence which will involve a read to the USR1 status register, followed by an access to the RXR data register. ●● PERR The PERR flag is the parity error flag. When this read only flag is “0” it indicates that a parity error has not been detected. When the flag is “1” it indicates that the parity of the received word is incorrect. This error flag is applicable only if Parity mode (odd or even) is selected. The flag can also be cleared by a software sequence which involves a read to the USR1 status register, followed by an access to the RXR data register. Rev 1.00 88 April 14, 2011 HT82A824R USB Audio MCU UCR1 Register The USR1 register is the status register for the UART, which can be read by the program to determine the present status of the UART. All flags within the USR1 register are read only. Further explanation on each of the flags is given below: ●● TX8 This bit is only used if 9-bit data transfers are used, in which case this bit location will store the 9th bit of the transmitted data, known as TX8. The BNO bit is used to determine whether data transfers are in 8-bit or 9-bit format. ●● RX8 This bit is only used if 9-bit data transfers are used, in which case this bit location will store the 9th bit of the received data, known as RX8. The BNO bit is used to determine whether data transfers are in 8-bit or 9-bit format. ●● TXBRK The TXBRK bit is the Transmit Break Character bit. When this bit is “0” there are no break characters and the TX pin operates normally. When the bit is “1” there are transmit break characters and the transmitter will send logic zeros. When equal to “1” after the buffered data has been transmitted, the transmitter output is held low for a minimum of a 13-bit length and until the TXBRK bit is reset. ●● STOPS This bit determines if one or two stop bits are to be used. When this bit is equal to “1” two stop bits are used, if the bit is equal to “0” then only one stop bit is used. ●● PRT This is the parity type selection bit. When this bit is equal to “1” odd parity will be selected, if the bit is equal to “0” then even parity will be selected. ●● PREN This is parity enable bit. When this bit is equal to “1” the parity function will be enabled, if the bit is equal to “0” then the parity function will be disabled. ●● BNO This bit is used to select the data length format, which can have a choice of either 8-bits or 9-bits. If this bit is equal to “1” then a 9-bit data length will be selected, if the bit is equal to “0” then an 8-bit data length will be selected. If 9-bit data length is selected then bits RX8 and TX8 will be used to store the 9th bit of the received and transmitted data respectively. ●● UARTEN The UARTEN bit is the UART enable bit. When the bit is “0” the UART will be disabled and the RX and TX pins will function as General Purpose I/O pins. When the bit is “1” the UART will be enabled and the TX and RX pins will function as defined by the TXEN and RXEN control bits. When the UART is disabled it will empty the buffer so any character remaining in the buffer will be discarded. In addition, the baud rate counter value will be reset. When the UART is disabled, all error and status flags will be reset. The TXEN, RXEN, TXBRK, RXIF, OERR, FERR, PERR, and NF bits will be cleared, while the TIDLE, TXIF and RIDLE bits will be set. Other control bits in UCR1, UCR2, and BRG registers will remain unaffected. If the UART is active and the UARTEN bit is cleared, all pending transmissions and receptions will be terminated and the module will be reset as defined above. When the UART is re-enabled it will restart in the same configuration. Rev 1.00 89 April 14, 2011 HT82A824R USB Audio MCU UCR2 Register The UCR2 register is the second of the two UART control registers and serves several purposes. One of its main functions is to control the basic enable/disable operation of the UART Transmitter and Receiver as well as enabling the various UART interrupt sources. The register also serves to control the baud rate speed, receiver wake-up enable and the address detect enable. Further explanation on each of the bits is given below: ●● TEIE This bit enables or disables the transmitter empty interrupt. If this bit is equal to “1” when the transmitter empty TXIF flag is set, due to a transmitter empty condition, the UART interrupt request flag will be set. If this bit is equal to “0” the UART interrupt request flag will not be influenced by the condition of the TXIF flag. ●● TIIE This bit enables or disables the transmitter idle interrupt. If this bit is equal to “1” when the transmitter idle TIDLE flag is set, the UART interrupt request flag will be set. If this bit is equal to “0” the UART interrupt request flag will not be influenced by the condition of the TIDLE flag. ●● RIE This bit enables or disables the receiver interrupt. If this bit is equal to “1” when the receiver overrun OERR flag or receive data available RXIF flag is set, the UART interrupt request flag will be set. If this bit is equal to “0” the UART interrupt will not be influenced by the condition of the OERR or RXIF flags. ●● WAKE This bit enables or disables the receiver wake-up function. If this bit is equal to “1” and if the MCU is in the Power Down Mode, a low going edge on the RX input pin will wake-up the device. If this bit is equal to “0” and if the MCU is in the Power Down Mode, any edge transitions on the RX pin will not wake-up the device. Rev 1.00 90 April 14, 2011 HT82A824R USB Audio MCU ●● ADDEN The ADDEN bit is the address detect mode bit. When this bit is “1” the address detect mode is enabled. When this occurs, if the 8th bit, which corresponds to RX7 if BNO=0, or the 9th bit, which corresponds to RX8 if BNO=1, has a value of “1” then the received word will be identified as an address, rather than data. If the corresponding interrupt is enabled, an interrupt request will be generated each time the received word has the address bit set, which is the 8 or 9 bit depending on the value of BNO. If the address bit is “0” an interrupt will not be generated, and the received data will be discarded. ●● BRGH The BRGH bit selects the high or low speed mode of the Baud Rate Generator. This bit, together with the value placed in the BRG register, controls the Baud Rate of the UART. If this bit is equal to “1” the high speed mode is selected. If the bit is equal to “0” the low speed mode is selected. ●● RXEN The RXEN bit is the Receiver Enable Bit. When this bit is equal to “0” the receiver will be disabled with any pending data receptions being aborted. In addition the buffer will be reset. In this situation the RX pin can be used as a general purpose I/O pin. If the RXEN bit is equal to “1” the receiver will be enabled and if the UARTEN bit is equal to “1” the RX pin will be controlled by the UART. Clearing the RXEN bit during a transmission will cause the data reception to be aborted and will reset the receiver. If this occurs, the RX pin can be used as a general purpose I/O pin. ●● TXEN The TXEN bit is the Transmitter Enable Bit. When this bit is equal to “0” the transmitter will be disabled with any pending transmissions being aborted. In addition the buffer will be reset. In this situation the TX pin can be used as a general purpose I/O pin. If the TXEN bit is equal to “1” the transmitter will be enabled and if the UARTEN bit is equal to “1” the TX pin will be controlled by the UART. Clearing the TXEN bit during a transmission will cause the transmission to be aborted and will reset the transmitter. If this occurs, the TX pin can be used as a general purpose I/O pin. Rev 1.00 91 April 14, 2011 HT82A824R USB Audio MCU Baud Rate Generator To setup the speed of the serial data communication, the UART function contains its own dedicated baud rate generator. The baud rate is controlled by its own internal free running 8-bit timer, the period of which is determined by two factors. The first of these is the value placed in the BRG register and the second is the value of the BRGH bit within the UCR2 control register. The BRGH bit decides, if the baud rate generator is to be used in a high speed mode or low speed mode, which in turn determines the formula that is used to calculate the baud rate. The value in the BRG register determines the division factor, N, which is used in the following baud rate calculation formula. Note that N is the decimal value placed in the BRG register and has a range of between 0 and 255. UCR2 BRGH Bit Baud Rate 0 fSYS/【(64(N+1)】 1 fSYS /【(16(N+1)】 By programming the BRGH bit which allows selection of the related formula and programming the required value in the BRG register, the required baud rate can be setup. Note that because the actual baud rate is determined using a discrete value, N, placed in the BRG register, there will be an error associated between the actual and requested value. The following example shows how the BRG register value N and the error value can be calculated. Calculating the Register and Error Values For a system frequency of 12MHz, and with BRGH set to “0” determine the BRG register value N, the actual baud rate and the error value for a desired baud rate of 4800. From the above table the desired baud rate BR= fSYS/【(64(N+1)】 Re-arranging this equation gives N = fSYS/(BR×64)-1 Giving a value for N= 12000000/(4800×64)-1=38.0625 To obtain the closest value, a decimal value of 38 should be placed into the BRG register. This gives an actual or calculated baud rate value of BR= 12000000/【(64(38+1)】=4808 Therefore the error is equal to (4808-4800)/4800= 0.16% The following tables show actual values of baud rate and error values for the two values of BRGH. Baud Rates for BRGH=0 Baud Rate K/BPS fSYS=12MHz fSYS=6MHz BRG Kbaud Error (%) BRG Kbaud Error (%) 0.3 ─ ─ ─ ─ ─ ─ 1.2 155 1.202 0.16 77 1.202 0.16 2.4 77 2.404 0.16 38 2.404 0.16 4.8 38 4.808 0.16 19 4.6875 -2.34 9.6 19 9.375 -2.34 9 9.375 -2.34 19.2 9 18.75 -2.34 4 18.75 -2.34 38.4 4 37.5 -2.34 2 31.25 -18.62 57.6 2 62.5 8.51 ─ ─ ─ 115.2 ─ ─ ─ ─ ─ ─ Baud Rates and Error Values for BRGH=0 Rev 1.00 92 April 14, 2011 HT82A824R USB Audio MCU Baud Rates for BRGH=1 Baud Rate K/BPS fSYS=12MHz fSYS=6MHz BRG Kbaud Error (%) BRG Kbaud Error (%) 0.3 ─ ─ ─ ─ ─ ─ 1.2 ─ ─ ─ ─ ─ ─ 2.4 ─ ─ ─ 155 2.404 0.16 4.8 155 4.808 0.16 77 4.808 0.16 9.6 77 9.615 0.16 38 9.615 0.16 19.2 38 19.230 0.16 19 19.230 0.16 38.4 19 37.500 -2.34 9 37.500 -2.34 57.6 12 57.692 0.16 6 53.57 -6.99 115.2 6 107.143 -6.99 2 125.0 8.51 Baud Rates and Error Values for BRGH=1 Setting Up and Controlling the UART Introduction For data transfer, the UART function utilizes a non-return-to-zero, more commonly known as NRZ, format. This is composed of one start bit, eight or nine data bits, and one or two stop bits. Parity is supported by the UART hardware, and can be setup to be even, odd or no parity. For the most common data format, 8 data bits along with no parity and one stop bit, denoted as 8, N, 1, is used as the default setting, which is the setting at power-on. The number of data bits and stop bits, along with the parity, are setup by programming the corresponding BNO, PRT, PREN, and STOPS bits in the UCR1 register. The baud rate used to transmit and receive data is setup using the internal 8-bit baud rate generator, while the data is transmitted and received LSB first. Although the UART’s transmitter and receiver are functionally independent, they both use the same data format and baud rate. In all cases stop bits will be used for data transmission. Enabling/Disabling the UART The basic on/off function of the internal UART function is controlled using the UARTEN bit in the UCR1 register. As the UART transmit and receive pins, TX and RX respectively, are pin-shared with normal I/O pins, one of the basic functions of the UARTEN control bit is to control the UART function of these two pins. If the UARTEN, TXEN and RXEN bits are set, then these two I/O pins will be setup as a TX output pin and an RX input pin respectively, in effect disabling the normal I/O pin function. If no data is being transmitted on the TX pin then it will default to a logic high value. Clearing the UARTEN bit will disable the TX and RX pins and allow these two pins to be used as normal I/O pins. When the UART function is disabled the buffer will be reset to an empty condition, at the same time discarding any remaining residual data. Disabling the UART will also reset the error and status flags with bits TXEN, RXEN, TXBRK, RXIF, OERR, FERR, PERR and NF being cleared while bits TIDLE, TXIF and RIDLE will be set. The remaining control bits in the UCR1, UCR2 and BRG registers will remain unaffected. If the UARTEN bit in the UCR1 register is cleared while the UART is active, then all pending transmissions and receptions will be immediately suspended and the UART will be reset to a condition as defined above. If the UART is then subsequently re-enabled, it will restart again in the same configuration. Rev 1.00 93 April 14, 2011 HT82A824R USB Audio MCU Data, Parity and Stop Bit Selection The format of the data to be transferred, is composed of various factors such as data bit length, parity on/off, parity type, address bits and the number of stop bits. These factors are determined by the setup of various bits within the UCR1 register. The BNO bit controls the number of data bits which can be set to either 8 or 9, the PRT bit controls the choice of odd or even parity, the PREN bit controls the parity on/off function and the STOPS bit decides whether one or two stop bits are to be used. The following table shows various formats for data transmission. The address bit identifies the frame as an address character. The number of stop bits, which can be either one or two, is independent of the data length. Start Bit Data Bits Example of 8-bit Data Formats 1 8 1 7 1 7 Example of 8-bit Data Formats 1 9 1 8 1 8 Address Bits Parity Bits Stop Bit 0 0 11 0 1 0 1 1 1 0 0 11 0 1 0 1 1 1 The following diagram shows the transmit and receive waveforms for both 8-bit and 9-bit data formats. UART Transmitter Data word lengths of either 8 or 9 bits, can be selected by programming the BNO bit in the UCR1 register. When BNO bit is set, the word length will be set to 9 bits. In this case the 9th bit, which is the MSB, needs to be stored in the TX8 bit in the UCR1 register. At the transmitter core lies the Transmitter Shift Register, more commonly known as the TSR, whose data is obtained from the transmit data register, which is known as the TXR register. The data to be transmitted is loaded into this TXR register by the application program. The TSR register is not written to with new data until the stop bit from the previous transmission has been sent out. As soon as this stop bit has been transmitted, the TSR can then be loaded with new data from the TXR register, if it is available. It should be noted that the TSR register, unlike many other registers, is not directly mapped into the Data Memory area and as such is not available to the application program for direct read/write operations. An actual transmission of data will normally be enabled when the TXEN bit is set, but the data will not be transmitted until the TXR register has been loaded with data and the baud rate generator has defined a shift clock source. However, the transmission can also be initiated by first loading data into the TXR register, after which the TXEN bit can be set. When a transmission of data begins, the TSR is normally empty, in which case a transfer to the TXR register will result in an immediate transfer to the TSR. If during a transmission the TXEN bit is cleared, the transmission will immediately cease and the transmitter will be reset. The TX output pin will then return to having a normal general purpose I/O pin function. Transmitting Data When the UART is transmitting data, the data is shifted on the TX pin from the shift register, with the least significant bit first. In the transmit mode, the TXR register forms a buffer between the internal bus and the transmitter shift register. It should be noted that if 9-bit data format has been selected, then the MSB will be taken from the TX8 bit in the UCR1 register. The steps to initiate a data transfer can be summarized as follows: Rev 1.00 94 April 14, 2011 HT82A824R USB Audio MCU ●● Make the correct selection of the BNO, PRT, PREN and STOPS bits to define the required word length, parity type and number of stop bits. ●● Setup the BRG register to select the desired baud rate. ●● Set the TXEN bit to ensure that the TX pin is used as a UART transmitter pin and not as an I/O pin. ●● Access the USR1 register and write the data that is to be transmitted into the TXR register. Note that this step will clear the TXIF bit. ●● This sequence of events can now be repeated to send additional data. It should be noted that when TXIF=0, data will be inhibited from being written to the TXR register. Clearing the TXIF flag is always achieved using the following software sequence: 1. A USR1 register access 2. A TXR register write execution The read-only TXIF flag is set by the UART hardware and if set indicates that the TXR register is empty and that other data can now be written into the TXR register without overwriting the previous data. If the TEIE bit is set then the TXIF flag will generate an interrupt. During a data transmission, a write instruction to the TXR register will place the data into the TXR register, which will be copied to the shift register at the end of the present transmission. When there is no data transmission in progress, a write instruction to the TXR register will place the data directly into the shift register, resulting in the commencement of data transmission, and the TXIF bit being immediately set. When a frame transmission is complete, which happens after stop bits are sent or after the break frame, the TIDLE bit will be set. To clear the TIDLE bit the following software sequence is used: 1. A USR1 register access 2. A TXR register write execution Note: That both the TXIF and TIDLE bits are cleared by the same software sequence. Transmit Break If the TXBRK bit is set then break characters will be sent on the next transmission. Break character transmission consists of a start bit, followed by 13×N ‘0’ bits and stop bits, where N=1, 2, etc. If a break character is to be transmitted then the TXBRK bit must be first set by the application program, then cleared to generate the stop bits. Transmitting a break character will not generate a transmit interrupt. Note that a break condition length is at least 13 bits long. If the TXBRK bit is continually kept at a logic high level then the transmitter circuitry will transmit continuous break characters. After the application program has cleared the TXBRK bit, the transmitter will finish transmitting the last break character and subsequently send out one or two stop bits. The automatic logic highs at the end of the last break character will ensure that the start bit of the next frame is recognized. Rev 1.00 95 April 14, 2011 HT82A824R USB Audio MCU UART Receiver Introduction The UART is capable of receiving word lengths of either 8 or 9 bits. If the BNO bit is set, the word length will be set to 9 bits with the MSB being stored in the RX8 bit of the UCR1 register. At the receiver core lies the Receive Serial Shift Register, commonly known as the RSR. The data which is received on the RX external input pin is sent to the data recovery block. The data recovery block operating speed is 16 times that of the baud rate, while the main receive serial shifter operates at the baud rate. After the RX pin is sampled for the stop bit, the received data in RSR is transferred to the receive data register, if the register is empty. The data which is received on the external RX input pin is sampled three times by a majority detect circuit to determine the logic level that has been placed onto the RX pin. It should be noted that the RSR register, unlike many other registers, is not directly mapped into the Data Memory area and as such is not available to the application program for direct read/write operations. Receiving Data When the UART receiver is receiving data, the data is serially shifted in on the external RX input pin, LSB first. In the read mode, the RXR register forms a buffer between the internal bus and the receiver shift register. The RXR register is a two byte deep FIFO data buffer, where two bytes can be held in the FIFO while a third byte can continue to be received. Note that the application program must ensure that the data is read from RXR before the third byte has been completely shifted in, otherwise this third byte will be discarded and an overrun error OERR will be subsequently indicated. The steps to initiate a data transfer can be summarized as follows: ●● Make the correct selection of BNO, PRT, PREN and STOPS bits to define the word length, parity type and number of stop bits. ●● Setup the BRG register to select the desired baud rate. ●● Set the RXEN bit to ensure that the RX pin is used as a UART receiver pin and not as an I/O pin. At this point the receiver will be enabled which will begin to look for a start bit. When a character is received the following sequence of events will occur: ●● The RXIF bit in the USR1 register will be set when RXR register has data available, at least one more character can be read. ●● When the contents of the shift register have been transferred to the RXR register, then if the RIE bit is set, an interrupt will be generated. ●● If during reception, a frame error, noise error, parity error, or an overrun error has been detected, then the error flags can be set. The RXIF bit can be cleared using the following software sequence: 1. A USR1 register access 2. An RXR register read execution Rev 1.00 96 April 14, 2011 HT82A824R USB Audio MCU Receive Break Any break character received by the UART will be managed as a framing error. The receiver will count and expect a certain number of bit times as specified by the values programmed into the BNO and STOPS bits. If the break is much longer than 13 bit times, the reception will be considered as complete after the number of bit times specified by BNO and STOPS. The RXIF bit is set, FERR is set, zeros are loaded into the receive data register, interrupts are generated if appropriate and the RIDLE bit is set. If a long break signal has been detected and the receiver has received a start bit, the data bits and the invalid stop bit, which sets the FERR flag, the receiver must wait for a valid stop bit before looking for the next start bit. The receiver will not make the assumption that the break condition on the line is the next start bit. A break is regarded as a character that contains only zeros with the FERR flag set. The break character will be loaded into the buffer and no further data will be received until stop bits are received. It should be noted that the RIDLE read only flag will go high when the stop bits have not yet been received. The reception of a break character on the UART registers will result in the following: ●● The framing error flag, FERR, will be set. ●● The receive data register, RXR, will be cleared. ●● The OERR, NF, PERR, RIDLE or RXIF flags will possibly be set. Idle Status When the receiver is reading data, which means it will be in between the detection of a start bit and the reading of a stop bit, the receiver status flag in the USR1 register, otherwise known as the RIDLE flag, will have a zero value. In between the reception of a stop bit and the detection of the next start bit, the RIDLE flag will have a high value, which indicates the receiver is in an idle condition. Receiver Interrupt The read only receive interrupt flag RXIF in the USR1 register is set by an edge generated by the receiver. An interrupt is generated if RIE=1, when a word is transferred from the Receive Shift Register, RSR, to the Receive Data Register, RXR. An overrun error can also generate an interrupt if RIE=1. Managing Receiver Errors Several types of reception errors can occur within the UART module, the following section describes the various types and how they are managed by the UART. . Overrun Error – OERR Flag The RXR register is composed of a two byte deep FIFO data buffer, where two bytes can be held in the FIFO register, while a third byte can continue to be received. Before this third byte has been entirely shifted in, the data should be read from the RXR register. If this is not done, the overrun error flag OERR will be consequently indicated. In the event of an overrun error occurring, the following will happen: ●● The OERR flag in the USR1 register will be set. ●● The RXR contents will not be lost. ●● The shift register will be overwritten. ●● An interrupt will be generated if the RIE bit is set. The OERR flag can be cleared by an access to the USR1 register followed by a read to the RXR register. Rev 1.00 97 April 14, 2011 HT82A824R USB Audio MCU Noise Error – NF Flag Over-sampling is used for data recovery to identify valid incoming data and noise. If noise is detected within a frame the following will occur: ●● The read only noise flag, NF, in the USR1 register will be set on the rising edge of the RXIF bit. ●● Data will be transferred from the Shift register to the RXR register. ●● No interrupt will be generated. However this bit rises at the same time as the RXIF bit which itself generates an interrupt. Note that the NF flag is reset by a USR1 register read operation followed by an RXR register read operation. Framing Error – FERR Flag The read only framing error flag, FERR, in the USR1 register, is set if a zero is detected instead of stop bits. If two stop bits are selected, both stop bits must be high, otherwise the FERR flag will be set. The FERR flag is buffered along with the received data and is cleared on any reset. Parity Error – PERR Flag The read only parity error flag, PERR, in the USR1 register, is set if the parity of the received word is incorrect. This error flag is only applicable if the parity is enabled, PREN = 1, and if the parity type, odd or even is selected. The read only PERR flag is buffered along with the received data bytes. It is cleared on any reset. It should be noted that the FERR and PERR flags are buffered along with the corresponding word and should be read before reading the data word. Uart Interrupt Scheme The UART internal function possesses its own internal interrupt and independent interrupt vector. Several individual UART conditions can generate an internal UART interrupt. These conditions are, a transmitter data register empty, transmitter idle, receiver data available, receiver overrun, address detect and an RX pin wake-up. When any of these conditions are created, if the UART interrupt is enabled and the stack is not full, the program will jump to the UART interrupt vector where it can be serviced before returning to the main program. Four of these conditions, have a corresponding USR1 register flag, which will generate a UART interrupt if its associated interrupt enable flag in the UCR2 register is set. The two transmitter interrupt conditions have their own corresponding enable bits, while the two receiver interrupt conditions have a shared enable bit. These enable bits can be used to mask out individual UART interrupt sources. The address detect condition, which is also a UART interrupt source, does not have an associated flag, but will generate a UART interrupt when an address detect condition occurs if its function is enabled by setting the ADDEN bit in the UCR2 register. An RX pin wake-up, which is also a UART interrupt source, does not have an associated flag, but will generate a UART interrupt if the microcontroller is woken up by a low going edge on the RX pin, if the WAKE and RIE bits in the UCR2 register are set. Note that in the event of an RX wake-up interrupt occurring, there will be a delay of 1024 system clock cycles before the system resumes normal operation. Note that the USR1 register flags are read only and cannot be cleared or set by the application program, neither will they be cleared when the program jumps to the corresponding interrupt servicing routine, as is the case for some of the other interrupts. The flags will be cleared automatically when certain actions are taken by the UART, the details of which are given in the UART register section. The overall UART interrupt can be disabled or enabled by the EURI bit in the MFI1C interrupt control register to prevent a UART interrupt from occurring. Rev 1.00 98 April 14, 2011 HT82A824R USB Audio MCU UART interrupt scheme Address Detect Mode Setting the Address Detect Mode bit, ADDEN, in the UCR2 register, enables this special mode. If this bit is enabled then an additional qualifier will be placed on the generation of a Receiver Data Available interrupt, which is requested by the RXIF flag. If the ADDEN bit is enabled, then when data is available, an interrupt will only be generated, if the highest received bit has a high value. Note that the EURI and EMI interrupt enable bits must also be enabled for correct interrupt generation. This highest address bit is the 9th bit if BNO=1 or the 8th bit if BNO=0. If this bit is high, then the received word will be defined as an address rather than data. A Data Available interrupt will be generated every time the last bit of the received word is set. If the ADDEN bit is not enabled, then a Receiver Data Available interrupt will be generated each time the RXIF flag is set, irrespective of the data last bit status. The address detect mode and parity enable are mutually exclusive functions. Therefore if the address detect mode is enabled, then to ensure correct operation, the parity function should be disabled by resetting the parity enable bit to zero. ADDEN Bit 9 if BNO =1, Bit 8 if BNO =0 UART Interrupt Generated 0 √ 0 1 Rev 1.00 99 1 √ 0 × 1 √ April 14, 2011 HT82A824R USB Audio MCU Uart Operation in Power Down Mode When the MCU is in the Power Down Mode the UART will cease to function. When the device enters the Power Down Mode, all clock sources to the module are shutdown. If the MCU enters the Power Down Mode while a transmission is still in progress, then the transmission will be terminated and the external TX transmit pin will be forced to a logic high level. In a similar way, if the MCU enters the Power Down Mode while receiving data, then the reception of data will likewise be terminated. When the MCU enters the Power Down Mode, note that the USR1, UCR1, UCR2, transmit and receive registers, as well as the BRG register will not be affected. The UART function contains a receiver RX pin wake-up function, which is enabled or disabled by the WAKE bit in the UCR2 register. If this bit, along with the UART enable bit, UARTEN, the receiver enable bit, RXEN and the receiver interrupt bit, RIE, are all set before the MCU enters the Power Down Mode, then a falling edge on the RX pin will wake-up the MCU from the Power Down Mode. Note that as it takes 1024 system clock cycles after a wake-up, before normal microcontroller operation resumes, any data received during this time on the RX pin will be ignored. For a UART wake-up interrupt to occur, in addition to the bits for the wake-up being set, the global interrupt enable bit, EMI, and the UART interrupt enable bit, EURI must also be set. If these two bits are not set then only a wake up event will occur and no interrupt will be generated. Note also that as it takes 1024 system clock cycles after a wake-up before normal microcontroller resumes, the UART interrupt will not be generated until after this time has elapsed. Pulse Width Modulator 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. 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. 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. The overall PWM output enable/disable is controlled using the PWMC register which acts like an on/off switch for each PWM output. Rev 1.00 100 April 14, 2011 HT82A824R USB Audio MCU PWM Modulation Frequency fSYS/64 for (6+2) bits mode fSYS/128 for (7+1) bits mode PWM Cycle Frequency PWM Cycle Duty fSYS/256 [PWM]/256 6+2 PWM Mode Each full PWM cycle, as it is controlled by an 8-bit PWM0 or PWM1 register, has 256 clock periods. However, in the 6+2 PWM Mode, each PWM cycle is subdivided into four individual subcycles 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 by a factor of four is achieved. The 8-bit PWM0 or PWM1 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 subcycles is shown in the following table. Parameter AC (0~3) DC (Duty Cycle) DC+1 64 DC 64 i < AC Modulation cycle i (i=0~3) i ≥ AC 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. (6+2) PWM Mode Output Waveform Pulse Width Modulation Registers for (6+2) PWM Mode Rev 1.00 101 April 14, 2011 HT82A824R USB Audio MCU 7+1 PWM Mode Each full PWM cycle, as it is controlled by an 8-bit PWM0 or PWM1 register, has 256 clock periods. However, in the 7+1 PWM Mode, each PWM cycle is subdivided into two individual subcycles 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 by a factor of two is achieved. The 8-bit PWM0 or PWM1 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. Parameter AC (0~3) DC (Duty Cycle) DC+1 128 DC 128 i < AC Modulation cycle i (i=0~1) i ≥ AC 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. (7+1) PWM Mode Output Waveform Pulse Width Modulation Registers for (7+1) PWM Mode Rev 1.00 102 April 14, 2011 HT82A824R USB Audio MCU 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. 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 Rev 1.00 a,64h ; setup PWM0 value of 100 decimal which is 64H PWM0,a PWMC.PWM_MOD0 ; setup pin PWM0 to the 6+2 PWM Mode PWMC.PWM_EN0 ; enable PWM0 output PWMC.PWM_EN0 ; disable PWM0 output 103 April 14, 2011 HT82A824R USB Audio MCU 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~PB4: pull-high enable or disable (bit option) 3 PC0~PC7: pull-high enable or disable (nibble option) 4 PA0~PA7: wake up enable or disable (bit option) 5 PB0~PB4: wake up enable or disable (bit option) 6 PC0~PC7: wake up enable or disable (nibble option) 7 PA0~PA7: CMOS or NMOS Output type (bit option) Watchdog Options 8 WDT: enable or disable 9 CLRWDT instructions: one or two instructions 10 WDT Clock Source: fSYS/4 or WDT oscillator LVR Option 11 LVR function: enable or disable TBHP Option 12 TBHP enable or disable IO VDD Option Rev 1.00 13 VDD or V33O for PA4~PA7 (nibble option) 14 VDD or V33O for PB0~PB4 (bit option) 15 VDD or V33O for PC4~PC7 (nibble option) 104 April 14, 2011 HT82A824R USB Audio MCU Application Circuits J1 VDD USBUSB+ VSS USB CON 1 VDD 2 D3 D+ 4 VSS L6 BEAD C36 0.1uF R4 33 R5 33 C7 47p C8 47p USBDN L10 R6 1.5K 2 USBDP V33O C35 C9 1uF 0.1uF + J5 + AVSS1 MUSIC_IN_R C53 0.1uF MUSIC_R 0.1uF MUSIC_L C54 BIAS VSS VDD AVSS1 C11 100uF LOUT C12 100uF ROUT VREF_L AVSS1 AVDD1 MUSIC_R MUSIC_L BIAS AVSS1 LOUT ROUT AVDD2 AVDD3 AN5 MUSIC_IN_L 3 2 1 AUDIO OUT STEREO C56 C52 0.1uF 10uF + SPK Volume Dec AVSS1 Ground Plane Connection 1 SW3 SPK Volume Inc AVSS1 SW4 R14 SPK Mute 330 2 USB ACTIVE D2 SW5 GLED PA3 1 PA2 PA1 BEAD FERRITE PA1 PA2 PA3 PA0 1 2 3 4 5 6 7 8 9 10 11 12 1 1 VREF_L AVSS1 AVDD1 MUSIC_IN_R MUSIC_IN_L BIAS AVSS2 LOUT ROUT AVDD2 AVDD3 AN5 L2 2 2 BEAD FERRITE L5 BEAD FERRITE C19 0.1uF AVSS1 U1 36 35 34 33 32 31 30 29 28 27 26 25 USBDN DVDD RESETB OSCO OSCI PC0 PC1 PC2 PC3 PC4 PC5 PC6 AVSS1 + VREF_L HT82A824R LQFP-48 USBDN DVDD1 RESETB OSCO OSCI PC0/BZ PC1/TMR0 PC2/TMR1 PC3/INTB PC4/SDO PC5/SDI PC6/SCSB C50 C48 1uF AVSS1 C20 1uF AVDD2 AVSS1 0.1uF AVSS1 AN0 AN1 Y1 C49 1uF 12MHz C51 AVSS1 0.1uF VDD C46 0.1uF C47 0.1uF + VREF_R AVSS1 1 L9 2 BEAD FERRITE MUSIC_IN_L MUSIC_IN_R DVDD + Reset SW1 C4 C6 1uF 0.1uF C3 0.1uF R2 100K DVDD April 14, 2011 105 Rev 1.00 VREF_R PA0 PA1 PA2 PA3 PA4 PA5 PA6 PA7 DVSS1 V33O USBDP 48 47 46 45 44 43 42 41 40 39 38 37 VREF_R PA0 PA1 PA2 PA3 MCLK/PA4 SCLK/PA5 LRCK/PA6 SDATA/PA7 DVSS1 V33O USBDP AN4 AN3 AN2 AN1 AN0 AVSS3 PB4 PB3/PWM1 PB2/PWM0 PB1/RX PB0/TX PC7/SCK 13 14 15 16 17 18 19 20 21 22 23 24 AN4 AN3 AN2 AN1 AN0 AVSS3 PB4 PB3 PB2 PB1 PB0 PC7 1 2 + HT82A824R USB Audio MCU Instruction Set Introduction Central to the successful operation of any 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. For easier understanding of the various instruction codes, they have been subdivided into several functional groupings. 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.5μs and branch or call instructions would be implemented within 1μs. 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. 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 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. Logical and Rotate Operations 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 Rev 1.00 106 April 14, 2011 HT82A824R USB Audio MCU 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. 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. Bit 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. Table Read Operations 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. Other Operations 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. Rev 1.00 107 April 14, 2011 HT82A824R USB Audio MCU 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 Conventions x: Bits immediate data m: Data Memory address A: Accumulator i: 0~7 number of bits addr: Program memory address Mnemonic Description Cycles Flag Affected 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] Logic Operation 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 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 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 1 1 1 1Note 1Note 1Note 1 1 1 1Note 1 Z Z Z Z Z Z Z Z Z Z Z Arithmetic Increment & Decrement INCA [m] INC [m] DECA [m] DEC [m] Increment Data Memory with result in ACC Increment Data Memory Decrement Data Memory with result in ACC Decrement Data Memory 1 1Note 1 1Note Z Z Z Z Rotate RRA [m] RR [m] RRCA [m] RRC [m] RLA [m] RL [m] RLCA [m] RLC [m] 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 Rev 1.00 108 April 14, 2011 HT82A824R USB Audio MCU Mnemonic Description Cycles Flag Affected 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 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.00 109 April 14, 2011 HT82A824R USB Audio MCU 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 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 Operation AC ← 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 Accumulator. result is stored in the Accumulator. 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 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 logical AND operation. The result is stored in the Accumulator. AND operation. The result is stored in the Data Memory. Operation [m] ← ACC "AND" [m] Affected flag(s) Z Rev 1.00 110 April 14, 2011 HT82A824R USB Audio MCU 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 WDTare 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 WDTare 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 Operation WDT cleared TO ← 0 PDF ← 0 Affected flag(s) Rev 1.00 TO, PDF 111 April 14, 2011 HT82A824R USB Audio MCU 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 Rev 1.00 112 April 14, 2011 HT82A824R USB Audio MCU 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 ← 0 Affected flag(s) TO, PDF 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 Rev 1.00 113 April 14, 2011 HT82A824R USB Audio MCU 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 OR A,x Logical OR immediate data to ACC Description Data in the Accumulator and the specified immediate data perform a bitwise 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 logical OR operation. The result is stored in the Accumulator. 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) Rev 1.00 None 114 April 14, 2011 HT82A824R USB Audio MCU RLA [m] Description Rotate Data Memory left with result in ACC 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 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) Rev 1.00 C 115 April 14, 2011 HT82A824R USB Audio MCU 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 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 ACC ← 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 Operation instruction. ACC ← [m] – 1 Affected flag(s) Skip if ACC = 0 None Rev 1.00 116 April 14, 2011 HT82A824R USB Audio MCU 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].1 ← 1 Affected flag(s) None 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 Rev 1.00 117 April 14, 2011 HT82A824R USB Audio MCU 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 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. ACC.3 ~ ACC.0 ← [m].7 ~ [m].4 Operation 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) Rev 1.00 None 118 April 14, 2011 HT82A824R USB Audio MCU 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 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 Operation ACC ← ACC "XOR"x Affected flag(s) Z logical XOR operation. The result is stored in the Accumulator. Rev 1.00 119 April 14, 2011 HT82A824R USB Audio MCU Package Information Package Information 48-pin LQFP (7mm7mm) Outline Outline Dimensions 48-pin LQFP (7mmx7mm) Dimensions Dimensions in inch Symbol Symbol B B C C D D E Nom. Dimensions in inch Min. Max. Min. 0.350 0.350 0.272 Nom. ― 0.280 0.358 0.272 0.350 0.272 ― 0.358 0.280 ― 0.280 0.350 0.358 Max. 0.358 0.272 0.020 ― E F ― 0.008 0.020 F G ― 0.053 0.008 0.057 0.053 ― 0.063 ― H G I H J I K J K α Symbol Symbol ― ― 0.018 0.004 0.018 0.030 0.008 7 ― 0° ― 0.057 ― 0 0.063 — 0.030 0.008 Dimensions in mm ― Min. ― 0.004 0.004 0.004 0.280 Nom. in mm Dimensions 7° Max. A 8.90 B Min. 6.90 Nom. 9.10 7.10 Max. 8.90 8.90 6.90 6.90 ― 9.10 9.10 ― 7.10 7.10 0.50 ― 9.10 0.20 ― A C B D C E 8.90 D F 6.90 E G ― 1.35 0.50 1.45 F H ― 0.20 1.60 G I 1.35 ― 0.10 0.75 0.20 7 H I J Rev 1.00 A A J K ― — 0.45 K 0.10 α 0° 0.45 ― 0.10 0.10 0 ― ― 1 120 ― 7.10 ― ― 1.45 1.60 — 0.75 0.20 7° May 12, 2010 April 14, 2011 HT82A824R USB Audio MCU 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, USA 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.00 121 April 14, 2011