Section 33. Audio Digital-to-Analog Converter (DAC)

Similar documents
Section 29. Real-Time Clock and Calendar (RTCC)

DAC Digital To Analog Converter

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science Electronic Circuits Spring 2007

Section 15. Quadrature Encoder Interface (QEI)

Section 7. Oscillator

Section 19. Voltage Reference

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

Section bit A/D Converter

Hello, and welcome to this presentation of the STM32L4 reset and clock controller.

PCM Encoding and Decoding:

Section 17. UART HIGHLIGHTS UART. This section of the manual contains the following major topics:

AVR126: ADC of megaavr in Single Ended Mode. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Digital to Analog Converter. Raghu Tumati

AVR125: ADC of tinyavr in Single Ended Mode. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Section bit A/D Converter

Timer A (0 and 1) and PWM EE3376

DATA SHEET. TDA1543 Dual 16-bit DAC (economy version) (I 2 S input format) INTEGRATED CIRCUITS

Chapter 6 PLL and Clock Generator

Section 14. Compare/Capture/PWM (CCP)

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

AVR127: Understanding ADC Parameters. Introduction. Features. Atmel 8-bit and 32-bit Microcontrollers APPLICATION NOTE

Digital to Analog and Analog to Digital Conversion

Analog Signal Conditioning

24-Bit, 96kHz BiCMOS Sign-Magnitude DIGITAL-TO-ANALOG CONVERTER

Lesson 16 Analog-to-Digital Converter (ADC)

DSPDemo. By Moe Wheatley MoeTronix.

AC/DC Power Supply Reference Design. Advanced SMPS Applications using the dspic DSC SMPS Family

LM 358 Op Amp. If you have small signals and need a more useful reading we could amplify it using the op amp, this is commonly used in sensors.

W a d i a D i g i t a l

MCP3426/7/8. 16-Bit, Multi-Channel ΔΣ Analog-to-Digital Converter with I 2 C Interface and On-Board Reference. Features.

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

8-Bit Flash Microcontroller for Smart Cards. AT89SCXXXXA Summary. Features. Description. Complete datasheet available under NDA

AND9035/D. BELASIGNA 250 and 300 for Low-Bandwidth Applications APPLICATION NOTE

TMU3114MS. USB Full Speed Controller. Data Sheet. Tenx reserves the right to change or discontinue this product without notice. tenx technology inc.

Simplifying System Design Using the CS4350 PLL DAC

Tire pressure monitoring

Glitch Free Frequency Shifting Simplifies Timing Design in Consumer Applications

25. AM radio receiver

Welcome to the tutorial for the MPLAB Starter Kit for dspic DSCs

Lesson 10: Video-Out Interface

6 Output With 1 kω in Series Between the Output and Analyzer Output With RC Low-Pass Filter (1 kω and 4.7 nf) in Series Between the Output

Analog to Digital Conversion of Sound with the MSP430F2013

Serial Communications

Introduction to SMPS Control Techniques

DS1104 R&D Controller Board

US-SPI New generation of High performances Ultrasonic device

Real-Time Clock. * Real-Time Computing, edited by Duncan A. Mellichamp, Van Nostrand Reinhold

Lab Experiment 1: The LPC 2148 Education Board

Agilent AN 1316 Optimizing Spectrum Analyzer Amplitude Accuracy

LC 2 MOS Signal Conditioning ADC with RTD Excitation Currents AD7711

What Does Rail-to-Rail Operation Really Mean?

HOW TO GET 23 BITS OF EFFECTIVE RESOLUTION FROM YOUR 24-BIT CONVERTER

HANDLING SUSPEND MODE ON A USB MOUSE

Atmel Norway XMEGA Introduction

POCKET SCOPE 2. The idea 2. Design criteria 3

ADS9850 Signal Generator Module

FREQUENCY RESPONSE ANALYZERS

Getting Started with PIC24F/PIC24H Programming and Interfacing in C

An Introduction to MPLAB Integrated Development Environment

Interfacing Analog to Digital Data Converters

AN3998 Application note

Optimizing VCO PLL Evaluations & PLL Synthesizer Designs

Hello and welcome to this training module for the STM32L4 Liquid Crystal Display (LCD) controller. This controller can be used in a wide range of

Analog-to-Digital Converters

Microprocessor & Assembly Language

Comparison of TI Voice-Band CODECs for Telephony Applications

AN3252 Application note

QUICK START GUIDE FOR DEMONSTRATION CIRCUIT BIT DIFFERENTIAL ADC WITH I2C LTC2485 DESCRIPTION

MAS.836 HOW TO BIAS AN OP-AMP

PART B QUESTIONS AND ANSWERS UNIT I

LEVERAGING FPGA AND CPLD DIGITAL LOGIC TO IMPLEMENT ANALOG TO DIGITAL CONVERTERS

Measuring Temperature withthermistors a Tutorial David Potter

Low-Power Pin Sampling Techniques Using Kinetis L Series

BIODEX ADDENDUM BIODEX EMG/ANALOG SIGNAL ACCESS CONFIGURATION UTILITY SOFTWARE FOR SYSTEM 3 REVISION 2 AND SYSTEM 4 DYNAMOMETERS

US-Key New generation of High performances Ultrasonic device

Chapter 6: From Digital-to-Analog and Back Again

Conversion Between Analog and Digital Signals

LM118/LM218/LM318 Operational Amplifiers

A Differential Op-Amp Circuit Collection

µpd6379, 6379A, 6379L, 6379AL

AVR1301: Using the XMEGA DAC. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AN LPC1700 timer triggered memory to GPIO data transfer. Document information. LPC1700, GPIO, DMA, Timer0, Sleep Mode

Decimal Number (base 10) Binary Number (base 2)

Baseband delay line QUICK REFERENCE DATA

Single Phase Two-Channel Interleaved PFC Operating in CrM

AN4646 Application note

Analog Representations of Sound

AN1229. Class B Safety Software Library for PIC MCUs and dspic DSCs OVERVIEW OF THE IEC STANDARD INTRODUCTION

Section 14. Motor Control PWM

AN974 APPLICATION NOTE

DIGITAL-TO-ANALOGUE AND ANALOGUE-TO-DIGITAL CONVERSION

ARM Thumb Microcontrollers. Application Note. Software ISO 7816 I/O Line Implementation. Features. Introduction

24-Bit Analog-to-Digital Converter (ADC) for Weigh Scales FEATURES S8550 VFB. Analog Supply Regulator. Input MUX. 24-bit Σ ADC. PGA Gain = 32, 64, 128

PAC52XX Clock Control Firmware Design

Combining the ADS1202 with an FPGA Digital Filter for Current Measurement in Motor Control Applications

Small Hardware Development and Prototyping Board for the SX28

PCXpocket 440. Professional Digital Audio Card. User s manual. DU IS=A

It should be corrected as indicated by the shading below.

M68EVB908QL4 Development Board for Motorola MC68HC908QL4

Impedance 50 (75 connectors via adapters)

Transcription:

Section 33. Audio Digital-to-Analog Converter (DAC) HIGHLIGHTS This section of the manual contains the following major topics: 33.1 Introduction... 33-2 33.2 Key Features...33-3 33.3 DAC Registers... 33-3 33.4 Module Operation... 33-7 33.5 Interrupts and Status... 33-10 33.6 Audio DAC Operation without... 33-11 33.7 Audio DAC Operation with... 33-13 33.8 External Circuit Example... 33-16 33.9 Operations in Power-Saving Modes... 33-17 33.10 Register Map...33-18 33.11 Related Application Notes... 33-19 33.12 Revision History... 33-20 33 Audio Digital-to-Analog Converter (DAC) 2009 Microchip Technology Inc. DS70211B-page 33-1

dspic33f Family Reference Manual 33.1 INTRODUCTION The Audio Digital-to-Analog Converter (DAC) module is a 16-bit Delta-Sigma signal converter designed for audio applications. Two output channels support stereo operations. Data input is in the form of a 16-bit digital value from the application program via the module or the DAC data and control registers. Data output is an analog voltage, which is proportional to the digital input value. Each output channel provides three voltage outputs: Positive DAC output Negative DAC output Midpoint voltage output (not present on all devices) The midpoint output is an offset voltage level that represents the midpoint of the output voltage range. Figure 33-1 is a simplified block diagram of the Audio DAC. A four-word deep buffers the data input for each channel. If at any time the becomes empty (for example, if the module or processor cannot provide data in a timely manner), the DAC accepts alternate data from the DAC Default Data Register (DACxDFLT). This register provides a default input value that represents a safe output voltage, which is often the midpoint value or a zero value. The sample rate of the DAC is established by an integer division of the rate of an auxiliary oscillator or system clock by a divider circuit. The divisor ratio is specified by the DAC Clock Divider (DACFDIV<6:0>) Configuration bits in the DAC Control Register (DACxCON). Figure 33-1: Audio DAC Module Block Diagram Right Channel DACxRDAT Amp DAC1RM DAC1RP DAC1RN Note 1 16-bit Data Bus ACLK CONTROL DACFDIV CLK DIV DACxDFLT DAC1LM Amp DAC1LP DAC1LN DACxLDAT Note 1 Left Channel Note 1: If is empty, data will be taken from the DACxDFLT register. DS70211B-page 33-2 2009 Microchip Technology Inc.

Section 33. Audio Digital-to-Analog Converter (DAC) 33.2 KEY FEATURES The Audio DAC provides these key features: 16-bit resolution (14-bit accuracy) Second-order digital Delta-Sigma modulator 256x oversampling ratio 100 ksps maximum sampling rate User controllable sample clock Maximum input signal frequency of 45 khz Differential analog outputs Four word deep input buffer 16-bit processor I/O and interfaces Note: The Audio DAC module is designed specifically for the Audio applications. Using this module for control loop type of applications is not recommended. 33.3 DAC REGISTERS The Audio DAC module is controlled by five DAC registers. DACxCON: DAC Control Register This register configures the corresponding DAC module by enabling/disabling the module and by specifying data format, DAC filter clock divider and operations in Idle/Sleep mode. DACxSTAT: DAC Status and Control Register This register specifies which channels are enabled and the status of the data buffer of that channel. DACxDFLT: DAC Default Data Register This register specifies a DAC default value to be used as the input when the is empty. DACxLDAT: DAC Left Channel Data Register This register specifies data for the left channel. DACxRDAT: DAC Right Channel Data Register This register specifies data for the right channel. 33 Audio Digital-to-Analog Converter (DAC) 2009 Microchip Technology Inc. DS70211B-page 33-3

dspic33f Family Reference Manual Register 33-1: DACxCON: DAC Control Register R/W-0 U-0 R/W-0 R/W-0 U-0 U-0 U-0 R/W-0 DACEN DACSIDL AMPON FORM bit 15 bit 8 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-1 R/W-0 R/W-1 DACFDIV<6:0> bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as 0 -n = Value at POR 1 = Bit is set 0 = Bit is cleared x = Bit is unknown bit 15 DACEN: DAC Enable bit 1 = Enables module 0 = Disables module bit 14 Unimplemented: Read as 0 bit 13 DACSIDL: Stop in Idle Mode bit 1 = Discontinue module operation when device enters Idle mode 0 = Continue module operation in Idle mode bit 12 AMPON: Enable Analog Amplifier in Sleep Mode/Stop-in Idle Mode bit 1 = Analog Amplifier is enabled during Sleep Mode/Stop-in Idle mode 0 = Analog Amplifier is disabled during Sleep Mode/Stop-in Idle mode. All channels are reset bit 11-9 Unimplemented: Read as 0 bit 8 FORM: Data Format Select bit 1 = Signed integer 0 = Unsigned integer bit 7 Unimplemented: Read as 0 bit 6-0 DACFDIV<6:0>: DAC Clock Divider bits 1111111 = Divide input clock by 128 0000101 = Divide input clock by 6 (default) 0000010 = Divide input clock by 3 0000001 = Divide input clock by 2 0000000 = Divide input clock by 1 (no divide) DS70211B-page 33-4 2009 Microchip Technology Inc.

Section 33. Audio Digital-to-Analog Converter (DAC) Register 33-2: DACxSTAT: DAC Status and Control Register R/W-0 U-0 R/W-0 U-0 U-0 R/W-0 R-0 R-0 LOEN LMVOEN LITYPE LFULL LEMPTY bit 15 bit 8 R/W-0 U-0 R/W-0 U-0 U-0 R/W-0 R-0 R-0 ROEN RMVOEN RITYPE RFULL REMPTY bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as 0 -n = Value at POR 1 = Bit is set 0 = Bit is cleared x = Bit is unknown bit 15 LOEN: Left Channel DAC Enable bit 1 = Positive and negative DAC outputs are enabled 0 = DAC outputs are disabled bit 14 Unimplemented: Read as 0 bit 13 LMVOEN: Left Channel Midpoint DAC Voltage Enable bit 1 = Midpoint DAC output is enabled 0 = Midpoint output is disabled bit 12-11 Unimplemented: Read as 0 bit 10 bit 9 bit 8 LITYPE: Left Channel Type of Interrupt bit 1 = Interrupt if is empty 0 = Interrupt if is not full LFULL: Status, Left Channel Data Input is Full bit 1 = is full 0 = is not full LEMPTY: Status, Left Channel Data Input is Empty bit 1 = is empty 0 = is not empty bit 7 ROEN: Right Channel DAC Enable bit 1 = Positive and negative DAC outputs are enabled 0 = DAC outputs are disabled bit 6 Unimplemented: Read as 0 bit 5 RMVOEN: Right Channel Midpoint DAC Voltage Enable bit 1 = Midpoint DAC output is enabled 0 = Midpoint output is disabled bit 4-3 Unimplemented: Read as 0 bit 2 bit 1 bit 0 RITYPE: Right Channel Type of Interrupt bit 1 = Interrupt if is empty 0 = Interrupt if is not full RFULL: Status, Right Channel Data Input is Full bit 1 = is full 0 = is not full REMPTY: Status, Right Channel Data Input is Empty bit 1 = is empty 0 = is not empty 33 Audio Digital-to-Analog Converter (DAC) 2009 Microchip Technology Inc. DS70211B-page 33-5

dspic33f Family Reference Manual Register 33-3: DACxDFLT: DAC Default Data Register R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 DACDFLT<15:8> bit 15 bit 8 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 DACDFLT<7:0> bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as 0 -n = Value at POR 1 = Bit is set 0 = Bit is cleared x = Bit is unknown bit 15-0 DACDFLT: DAC Default Value bits Register 33-4: DACxLDAT: DAC Left Channel Data Register R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 DACLDAT<15:8> bit 15 bit 8 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 DACLDAT<7:0> bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as 0 -n = Value at POR 1 = Bit is set 0 = Bit is cleared x = Bit is unknown bit 15-0 DACLDAT: Left Channel Data bits Register 33-5: DACxRDAT: DAC Right Channel Data Register R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 DACRDAT<15:8> bit 15 bit 8 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 DACRDAT<7:0> bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as 0 -n = Value at POR 1 = Bit is set 0 = Bit is cleared x = Bit is unknown bit 15-0 DACRDAT: Right Channel Data bits DS70211B-page 33-6 2009 Microchip Technology Inc.

Section 33. Audio Digital-to-Analog Converter (DAC) 33.4 MODULE OPERATION Figure 33-2 illustrates the digital-to-analog conversion process. The digital interpolation filter up-samples the input signal to create additional interpolated data points. The over-sampling ratio is 256:1, or 256x the incoming sampling rate. For example, a 100 ksps input signal (the maximum sampling rate) produces 25.6M data points per second. The interpolation filter also eliminates unwanted noise produced by the up-sampling process. The output of the interpolation filter drives the Sigma-Delta modulator, which converts the word output from the interpolation filter into a serial bit stream. The bit stream from the modulator is processed by the reconstruction filter to convert the bit stream to an analog signal. It then performs a low-pass filter to yield the desired voltage levels. The reconstruction filter produces two differential voltage outputs and a midpoint reference: Positive (voltage level representing the output signal) Negative (complement of the positive output signal voltage level) Midpoint (offset voltage level representing the midpoint of the output voltage range) Figure 33-2: CPU Block Diagram of Digital-to-Analog Process DACR Interrupt DACxRDAT DAC1RM 33 DACxDFLT Fs ACLK CLK DIV Interpolation Filter (256) DACFDIV<6:0> 256*Fs DACCLK = Fs x 256 Sigma-Delta Modulator Reconstruction Filter Right Channel Digital-to-Analog Converter Analog Amplifier DAC1RP DA1CRN DAC1LM Audio Digital-to-Analog Converter (DAC) DACxLDAT Fs Interpolation Filter (256) 256*Fs Sigma-Delta Modulator Reconstruction Filter Left Channel Digital-to-Analog Converter (DAC) Analog Amplifier DAC1LP DAC1LN DACL Interrupt CPU 2009 Microchip Technology Inc. DS70211B-page 33-7

dspic33f Family Reference Manual 33.4.1 Data Format The DAC module accepts 16-bit input data in two formats. Data formatting is controlled by the Data Format Select (FORM) bit in the DAC Control (DACxCON<8>) register. The supported formats are: 1 = Signed (2 s complement) 0 = Unsigned If the FORM bit is configured for unsigned data (FORM = 0), the user input data yields the following behavior: 0xFFFF = Most positive output voltage 0x8000 = Midpoint output voltage 0x7FFF = Value just below midpoint 0x0000 = Minimum output voltage If the FORM bit is configured for signed data (FORM = 1), the user input data yields the following behavior: 0x7FFF = Most positive output voltage 0x0000 = Midpoint output voltage 0xFFFF = Value just below midpoint 0x8000 = Minimum output voltage 33.4.2 Clock The DAC clock (DACCLK) must be equal to the sampling rate times 256. Assuming a 100 ksps input, the DAC clock rate must be 25.6 MHz (100,000 x 256 = 25,600,000). DACCLK is generated by dividing the high-speed oscillator (auxiliary or system clock) by a specified value. The divisor ratio is specified by clock divider bits (DACFDIV<6:0>) in the DAC Control (DACxCON register<6:0>). The resulting DACCLK must not exceed 25.6 MHz. Consider an application example where the dspic DSC device uses the device FRC as the clock source. The device oscillator pre-pll divider (N1) and post-pll divider (N2) are set to divide by 2. For more details on oscillator selection, refer to Section 39. Oscillator (Part III) (DS70216). It is desired that the DAC module be configured to output a 8 khz sampled signal. Therefore, the DAC clock rate must be 256 x 8 khz = 2.048 MHz. For this example, the dspic DSC PLL can be configured to provide a system clock, which is an integral multiple of the DAC clock rate (i.e., 2.048 MHz). The system clock source to the DAC module is designated FVCO and is the output of the PLL before the post-pll divider (N2). For more details, refer to Figure 39-8: PLL Block Diagram in Section 39. Oscillator (Part III) (DS70216). By selecting the value of M to be 40, FVCO is given as shown in Equation 33-1: Equation 33-1: FVCO Equation FVCO = (7.3728 * 10 6 * 40)/2 = 147.456 * 10 6 MHz This FVCO value is an integral multiple (2.048 MHz x 72 = 147.456 x 10 6 MHz) of the required DAC clock value. Setting the SELACLK (ACLKCON<13>) bit to 0 and setting the DACFDIV register value to divide the FVCO clock by 72 will produce the desired DAC clock. DS70211B-page 33-8 2009 Microchip Technology Inc.

Section 33. Audio Digital-to-Analog Converter (DAC) Table 33-1 lists the DACCLK rates required to achieve common audio sample rates. Table 33-1: CLOCK RATE RATIO DACCLK Rate (MHz) (FS x 256) Sample Data Rate (khz) (FS) 1.8432 7.2 2.048 8.0 2.4576 9.6 2.8224 11.025 4.096 16 5.6448 22.05 6.144 24 8.192 32 11.2896 44.1 12.288 48 22.5792 88.2 24.576 96.0 25.6 100 The DACCLK rate is achieved by selecting an Auxiliary Oscillator with the appropriate DACFDIV<6:0> Configuration bits. For example, a DACCLK rate of 25.6 MHz (for 100 ksps input rate) might be obtained as shown in Table 33-2: Table 33-2: Auxiliary Oscillator Frequency Auxiliary Oscillator Frequency DACFDIV Configuration Bits 25.6 MHz DACFDIV = 0b0000000 51.2 MHz DACFDIV = 0b0000001 76.8 MHz DACFDIV = 0b0000010 33 Audio Digital-to-Analog Converter (DAC) For more details on oscillator selection, refer to Section 39. Oscillator (Part III) (DS70216). 2009 Microchip Technology Inc. DS70211B-page 33-9

dspic33f Family Reference Manual 33.5 INTERRUPTS AND STATUS The Audio DAC provides two interrupts, one for each channel. Depending on the setting of the interrupt Configuration bits (LITYPE for the left channel and RITYPE for the right channel) in the DAC Status Register (DACxSTAT), the DAC interrupt is triggered by either a Empty or Not Full condition. The Empty interrupt can be used with the Audio DAC to maximize throughput while minimizing the impact of interrupts on the CPU. The Empty interrupt is the simplest and preferred interrupt method for use with. The Not Full interrupt is used in applications without to minimize the occurrence of DAC under run. This interrupt can also be used with, but additional software support is required. The DAC Interrupt Service Routine (ISR) must clear its corresponding interrupt flags (DAC1LIF and DAC1RIF in the IFS4 register). Note: Each channel includes two status bits to indicate the status of its, as shown in Table 33-3: Table 33-3: The Audio DAC reads data from every 256 DAC clock cycles. DAC interrupts occur once the data is read, depending on the status of the. Interrupt Status Bits Channel Name (1) Description Left LFULL (DAC1STAT<9>) Left channel is full LEMPTY (DAC1STAT<8>) Left channel is empty Right RFULL (DAC1STAT<1>) Right channel is full REMPTY (DAC1STAT<0>) Right channel is empty Note 1: These bits can be read in software to confirm the status. DS70211B-page 33-10 2009 Microchip Technology Inc.

Section 33. Audio Digital-to-Analog Converter (DAC) 33.6 AUDIO DAC OPERATION WITHOUT Example 33-1 demonstrates a typical configuration for the Audio DAC module. In this example, the interrupts for both channels are set to occur every time the corresponding is not full. When the DAC Enable (DACEN) bit in the DAC Control (DACxCON<15>) register gets set, DAC interrupts are generated for both channels. Since the is initially empty, the first data value is read from the DAC Default (DACxDFLT) register. For this example, the default is set to a midpoint value of 0x8000. Example 33-1: DAC Operation without DAC1STATbits.ROEN = 1; /* Right Channel DAC Enabled */ DAC1STATbits.LOEN = 1; /* Left Channel DAC Enabled */ DAC1STATbits.RITYPE = 0; /* Right Channel Interrupt if is not Full */ DAC1STATbits.LITYPE = 0; /* Left Channel Interrupt if is not Full */ DAC1CONbits.AMPON = 0; /* Amplifier Disabled During Sleep and Idle Modes */ DAC1CONbits.DACFDIV = 0; /* Divide Clock by 1 (Assumes Clock is 25.6MHz) */ DAC1CONbits.FORM = 0; /* Data Format is Unsigned */ DAC1DFLT = 0x8000; /* Default value set to Midpoint when FORM = 0 */ IFS4bits.DAC1RIF = 0; /* Clear Right Channel Interrupt Flag */ IFS4bits.DAC1LIF = 0; /* Clear Left Channel Interrupt Flag */ IEC4bits.DAC1RIE = 1; /* Right Channel Interrupt Enabled */ IEC4bits.DAC1LIE = 1; /* Left Channel Interrupt Enabled */ 33 DAC1CONbits.DACEN = 1; /* DAC1 Module Enabled */ void attribute ((interrupt, no_auto_psv))_dac1rinterrupt(void) { IFS4bits.DAC1RIF = 0; /* Clear Right Channel Interrupt Flag */ DAC1RDAT = MyDataR[0]; /* User Code to Write to Goes Here */ } Audio Digital-to-Analog Converter (DAC) void attribute ((interrupt, no_auto_psv))_dac1linterrupt(void) { IFS4bits.DAC1LIF = 0; /* Clear Left Channel Interrupt Flag */ DAC1LDAT = MyDataL[0]; /* User Code to Write to Goes Here */ } Figure 33-3 illustrates how the Audio DAC interacts with the application program to respond to DAC interrupts and transfer data in a timely manner. This example shows a single-word transfer per interrupt. Depending on your particular application, you could choose to write up to four words per interrupt. Note: A write to the is ignored, if the is full or if a write occurs before the DAC is enabled. 2009 Microchip Technology Inc. DS70211B-page 33-11

dspic33f Family Reference Manual Figure 33-3: A. When DAC is initialized, DAC Enable (DACEN) bit is set. is not full, so DAC interrupts are generated for both channels. Because s have no data, contents of DACDFLT register is processed by both DAC channels. Application program recognizes interrupt request and begins processing ISR. Audio DAC Interaction without Default Value Default Value AUDIO DAC MODULE Right Channel DACRDAT DACDFLT Left Channel DACLDAT dspic33f CPU USER APPLICATION Interrupt Service Routine (ISR) ISR B. Interrupt Service Routine (ISR) writes to DACRDAT and DACLDAT. Default Value AUDIO DAC MODULE Right Channel DACRDAT dspic33f CPU USER APPLICATION ISR Transfer Data DACDFLT Left Channel Default Value DACLDAT ISR Transfer Data C. After 256 DAC clock cycles, the reads data from. As the processing occurs the DAC data register status becomes not full, causing another DAC interrupt to be generated. First Sample First Sample AUDIO DAC MODULE Right Channel DACRDAT DACDFLT Left Channel DACLDAT dspic33f CPU USER APPLICATION ISR ISR D. The application program transfers the next word to the left and right data registers. This transfer is completed before the requests the next input word (i.e., before it completes 256 DAC clock cycles). This process repeats until the application program turns off the DAC module (disables DACEN). First Sample First Sample AUDIO DAC MODULE Right Channel DACRDAT DACDFLT Left Channel DACLDAT dspic33f CPU USER APPLICATION ISR Transfer Data ISR Transfer Data DS70211B-page 33-12 2009 Microchip Technology Inc.

Section 33. Audio Digital-to-Analog Converter (DAC) 33.7 AUDIO DAC OPERATION WITH On some of the dspic33f devices, the module can transfer data from the CPU to the Audio DAC without CPU assistance. Refer to the specific dspic33f device data sheet to determine if is present on your particular device. For more details on the module, refer to Section 22. Direct Memory Access () (DS70182). When the Audio DAC module uses, it requires one channel for each DAC channel. The DAC channel can be mapped to any available channel. Interaction begins when the receives an interrupt from the Audio DAC. Depending on the setting of the interrupt Configuration bits (LITYPE for the left channel and RITYPE for the right channel) in the DAC Status Register (DACxSTAT), the interrupt is triggered by either a Empty or Not Full condition (see 33.5 Interrupts and Status ). 33.7.1 Channel to Peripheral Association Setup The channel needs to know which interrupt request to respond to and which peripheral target address to write to for the Audio DAC. The interrupt is identified by the Interrupt Select (IRQSEL<6:0>) bits in the Channel x IRQ Request (xreq) register (in the module). The write address is identified by Channel X Peripheral Address (xpad) register (also in the module). Table 33-4 shows the values that should be written to associate a particular peripheral with a given channel. Table 33-4: Peripheral to Association Channel to Peripheral Association 33.7.2 Code Setup xreq Register IRQSEL<6:0> Bits xpad Register Values to Write to Peripheral DAC1 Right Data 1001110 0x03F6 DAC1RDAT DAC1 Left Data 1001111 0x03F8 DAC1LDAT Example 33-2 illustrates code for a typical DAC configuration for operation. In this example, the interrupts are set to occur every time the is empty. When the DAC Enable (DACEN) bit gets set, an interrupt is generated because the is initially empty. Since the is empty, the first data value is read from the default register. In this case, the default value is zero. Figure 33-4 illustrates how the Audio DAC interacts with the module to respond to DAC interrupts and transfer data in a timely manner. This example shows a single-word transfer per interrupt. 33 Audio Digital-to-Analog Converter (DAC) 2009 Microchip Technology Inc. DS70211B-page 33-13

dspic33f Family Reference Manual Example 33-2: DAC Operation with /* Code */ unsigned int RightBufferA[32] attribute ((space(dma))); unsigned int RightBufferB[32] attribute ((space(dma))); unsigned int LeftBufferA[32] attribute ((space(dma))); unsigned int LeftBufferB[32] attribute ((space(dma))); /* Channel 0 set to DAC1RDAT */ 0CONbits.AMODE = 0; /* Register Indirect with Post Increment */ 0CONbits.MODE = 2; /* Continuous Mode with Ping-Pong Enabled */ 0CONbits.DIR = 1; /* Ram-to-Peripheral Data Transfer */ 0PAD = (volatile unsigned int)&dac1rdat; /* Point to DAC1RDAT */ 0CNT = 31; /* 32 Request */ 0REQ = 78; /* Select DAC1RDAT as Request Source */ 0STA = builtin_dmaoffset(rightbuffera); 0STB = builtin_dmaoffset(rightbufferb); IFS0bits.0IF = 0; /* Clear Interrupt Flag */ IEC0bits.0IE = 1; /* Set Interrupt Enable Bit */ 0CONbits.CHEN = 1; /* Enable Channel 0 */ /* Channel 1 set to DAC1LDAT */ 1CONbits.AMODE = 0; /* Register Indirect with Post Increment */ 1CONbits.MODE = 2; /* Continuous Mode with Ping-Pong Enabled */ 1CONbits.DIR = 1; /* Ram-to-Peripheral Data Transfer */ 1PAD = (volatile unsigned int)&dac1ldat; /* Point to DAC1LDAT */ 1CNT = 31; /* 32 Request */ 1REQ = 79; /* Select DAC1LDAT as Request Source */ 1STA = builtin_dmaoffset(leftbuffera); 1STB = builtin_dmaoffset(leftbufferb); IFS0bits.1IF = 0; /* Clear Interrupt Flag */ IEC0bits.1IE = 1; /* Set Interrupt Enable Bit */ 1CONbits.CHEN = 1; /* Enable Channel 1 */ /* DAC1 Code */ DAC1STATbits.ROEN = 1; /* Right Channel DAC Enabled */ DAC1STATbits.LOEN = 1; /* Left Channel DAC Enabled */ DAC1STATbits.RITYPE = 1; /* Right Channel Interrupt if is Empty */ DAC1STATbits.LITYPE = 1; /* Left Channel Interrupt if is Empty */ DAC1CONbits.AMPON = 0; /* Amplifier is Disabled During Sleep/Idle Modes */ DAC1CONbits.DACFDIV = 0; /* Divide Clock by 1 (Assumes Clock is 25.6MHz) */ DAC1CONbits.FORM = 0; /* Data Format is Unsigned */ DAC1CONbits.DACEN = 1; /* DAC1 Module Enabled */ /* Rest of User Code Goes Here */ void attribute ((interrupt, no_auto_psv))_0interrupt(void) { IFS0bits.0IF = 0; /* Clear Channel 0 Interrupt Flag */ /* User Code to update Right Buffer in */ } void attribute ((interrupt, no_auto_psv))_1interrupt(void) { IFS0bits.1IF = 0; /* Clear Channel 1 Interrupt Flag */ /* User Code to update Left Buffer in */ } DS70211B-page 33-14 2009 Microchip Technology Inc.

Section 33. Audio Digital-to-Analog Converter (DAC) Figure 33-4: A. When DAC is initialized, DAC Enable (DACEN) bit is set. is empty, so DAC generates Requests for both channels. Because s have no data, contents of DACDFLT register is processed by both DAC channels. Audio DAC Interaction with Default Value Default Value AUDIO DAC MODULE Right Channel DACRDAT DACDFLT Left Channel DACLDAT CONTROLLER CHANNEL 0 CHANNEL 1 MODULE Right DATA 1 Right DATA n Right DATA 1 Right DATA n Left DATA 1 Left DATA n Left DATA 1 Left DATA n Buffer A Buffer B Buffer A Buffer B B. fetches data word from the Right Data Buffer A and writes it to the right DAC Data (DACRDAT) register. It then fetches a data word from the Left Data Buffer A and writes it to the left DAC Data (DACLDAT) register. Simultaneously, the DAC continues processing DACDFLT. C. After 256 DAC clock cycles, the default word has been processed by both channels. The converters read the next word from their respective and generate Request to fetch next samples. Default Value Default Value First Sample First Sample AUDIO DAC MODULE Right Channel DACRDAT DACDFLT Left Channel DACLDAT AUDIO DAC MODULE Right Channel DACRDAT DACDFLT Left Channel DACLDAT CONTROLLER CHANNEL 0 CHANNEL 1 CONTROLLER CHANNEL 0 CHANNEL 1 MODULE Right DATA 1 Right DATA n Right DATA 1 Right DATA n Left DATA 1 Left DATA n Left DATA 1 Left DATA n MODULE Right DATA 1 Right DATA n Right DATA 1 Right DATA n Left DATA 1 Left DATA n Left DATA 1 Buffer A Buffer B Buffer A Buffer B Buffer A Buffer B Buffer A Buffer B 33 Audio Digital-to-Analog Converter (DAC) Left DATA n AUDIO DAC MODULE MODULE D. The next words are fetched from memory. This process continues, fetching and processing one word at a time in each channel until the application program terminates data transfer. First Sample First Sample Right Channel DACRDAT DACDFLT Left Channel DACLDAT CONTROLLER CHANNEL 0 CHANNEL 1 Right DATA 1 Right DATA n Right DATA 1 Right DATA n Left DATA 1 Left DATA n Left DATA 1 Buffer A Buffer B Buffer A Buffer B Left DATA n 2009 Microchip Technology Inc. DS70211B-page 33-15

dspic33f Family Reference Manual 33.8 EXTERNAL CIRCUIT EXAMPLE Figure 33-5 shows a typical configuration for connecting a speaker with a single channel of the Audio DAC module. This example uses the differential outputs of the Audio DAC and produces a single-ended output using op amp differential amplifiers. The corresponding output is two times the positive input. Figure 33-5: External Circuit Example RIGHT CHANNEL 100 µf DAC1RP 10K 10K 10K - 0.1µF 1 2 Headphone Amplifier VOUT1 VDD VIN1 VOUT2 10 9 3.3V 1µF 100 µf DAC1RN 10K + MCP6022 1µF 3 BYP VIN2 8 0.1µF VCC/2 LEFT CHANNEL 3.3V 1 2 S1 CLK 4 3 100K 4 CLK 5 GND 3.3V LM4811 4 3 S1 SHUTDN UP/DN 1 2 VOL UP/DN 100K 7 6 100K 10K 10K DAC1LP - 10K DAC1LN + 10K MCP6022 VCC/2 DS70211B-page 33-16 2009 Microchip Technology Inc.

Section 33. Audio Digital-to-Analog Converter (DAC) 33.9 OPERATIONS IN POWER-SAVING MODES The dspic33f family of devices has four power modes comprised of one normal (full-power) mode and three power-saving modes invoked by the PWRSAV instruction. Depending on the mode selected, entry into a power-saving mode may also affect the operation of the module. When the Enable Analog Amplifier (AMPON) bit in the DAC Control (DACxCON<12>) register is set, the analog circuitry and the analog output amplifier are powered on during Sleep and Stop-in-Idle mode. This configuration keeps the analog output voltage at a known state during Sleep and Stop-in-Idle modes. If the AMPON bit is cleared and the processor enters Sleep mode or Stop-in-Idle mode, the analog circuitry is powered off and held in reset to reduce current consumption. When the output amplifier is powered off, the analog output is in a high-impedance state. In Sleep mode, if the AMPON bit is cleared, the DAC internal state, including the s (except the SFRs), is reset, the clocks are stopped and the output analog amplifier and associated circuitry are powered down. If the AMPON bit is set, the DAC internal state and the SFRs are maintained, the clocks are stopped and the output analog amplifier and associated circuitry remain powered up. If the Stop-in-Idle Mode (DACSIDL) bit in the DAC Control (DACxCON<13>) register is set when Idle mode is entered, and if the AMPON bit is not set, the DAC internal state (except the SFRs) is reset, the clocks are stopped and the output analog amplifier and associated circuitry is powered down. If the AMPON bit is set, the DAC internal state and the SFRs are maintained, the clocks are stopped and the output analog amplifier and associated circuitry remains powered up. If DACSIDL is not set when Idle mode is entered, the DAC ignores Idle mode and continues running. The DACEN bit (DACxCON<15>) is cleared when the device enters Sleep mode or Stop-in-Idle mode, regardless of the status of AMPON bit. If the AMPON bit is set before the device enters Sleep mode or Stop-in-Idle mode, the new data can be placed in the s upon exiting Sleep or Stop-in-Idle. When the DAC is re-enabled, it continues the operation where it left off. Note: If AMPON = 1 and DACEN = 0, reading the will empty the. 33 Audio Digital-to-Analog Converter (DAC) 2009 Microchip Technology Inc. DS70211B-page 33-17

DS70211B-page 33-18 2009 Microchip Technology Inc. 33.10 REGISTER MAP A summary of the Audio DAC registers is provided in Table 33-5. Table 33-5: Audio DAC Register Map File Name Bit 15 Bit 14 Bit 13 Bit 12 Bit 11 Bit 10 Bit 9 Bit 8 Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit1 Bit 0 All Resets DACxCON DACEN DACSIDL AMPON FORM DACFDIV<6:0> 0000 DACxSTAT LOEN LMVOEN LITYPE LFULL LEMPTY ROEN RMVOEN RITYPE RFULL REMPTY 0000 DACxDFLT DACDFLT<15:0> 0000 DACxRDAT DACRDAT<15:0> 0000 DACxLDAT DACLDAT<15:0> 0000 Legend: x = unknown value on Reset, = unimplemented, read as 0. Reset values are shown in hexadecimal. dspic33f Family Reference Manual

Section 33. Audio Digital-to-Analog Converter (DAC) 33.11 RELATED APPLICATION NOTES This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dspic33f product family, but the concepts are pertinent and could be used with modification and possible limitations. The current application notes related to the Audio Digital-to-Analog Converter (DAC) module are: Title Application Note # No related application notes are available at this time. N/A Note: Please visit the Microchip web site (www.microchip.com) for additional Application Notes and code examples for the dspic33f family of devices. 33 Audio Digital-to-Analog Converter (DAC) 2009 Microchip Technology Inc. DS70211B-page 33-19

dspic33f Family Reference Manual 33.12 REVISION HISTORY Revision A (October 2007) This is the initial released version of this document. Revision B (September 2009) This revision includes the following updates: Equations: - Added the FVCO equation (see Equation 33-1) in 33.4.2 Clock. Figures: - Updated the + and - signs and input signal names on both differential amps in Figure 33-5. Notes: - Added a note on the Audio DAC module usage in 33.2 Key Features. Sections: - Added the DAC code example in 33.4.2 Clock. - Added 33.11 Related Application Notes. - Deleted the following description in 33.1 Introduction : The positive and negative outputs are differential about a midpoint voltage of approximately 1.65 volts with a voltage swing of approximately ±1 volt. The signals are capable of driving a 1 kω load. - Deleted the Signal-to-noise ratio: 90 db in 33.2 Key Features. - Deleted the following description in 33.4 Module Operation : The differential outputs from the reconstruction filter are amplified by analog amplifiers to provide the required 2V peak-to-peak voltage swing into a 1 kω load. Additional minor corrections such as language and formatting updates have been incorporated throughout the document. DS70211B-page 33-20 2009 Microchip Technology Inc.