Page 2
PowerTool, rfLAB, rfPICDEM, Select Mode, Smart Serial, SmartTel and Total Endurance are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. SQTP is a service mark of Microchip Technology Incorporated in the U.S.A. All other trademarks mentioned herein are property of their respective companies.
Introduction ..............................5-2 Table Instruction Operation ..........................5-2 Control Registers ............................. 5-5 Run-Time Self-Programming (RTSP) ....................... 5-9 Data EEPROM Programming ........................5-14 Design Tips ..............................5-20 Related Application Notes ..........................5-21 Revision History ............................. 5-22 2004 Microchip Technology Inc. DS70046C-page iii...
Page 4
Using the RCON Status Bits .......................... 8-10 Device Reset Times ............................8-11 Device Start-up Time Lines ..........................8-13 Special Function Register Reset States ......................8-16 Design Tips ..............................8-17 Related Application Notes ..........................8-18 Revision History ............................. 8-19 2004 Microchip Technology Inc. DS70046C-page iv...
Page 5
Reading and Writing into 32-bit Timers ......................12-21 Timer Operation in Power Saving States ..................... 12-21 Peripherals Using Timer Modules ........................ 12-22 Design Tips ..............................12-24 Related Application Notes ..........................12-25 Revision History ............................12-26 2004 Microchip Technology Inc. DS70046C-page v...
Page 6
PWM Update Lockout ..........................15-35 PWM Special Event Trigger ......................... 15-35 Operation in Device Power Saving Modes ....................15-36 Special Features for Device Emulation ......................15-37 Related Application Notes ..........................15-40 Revision History ............................15-41 2004 Microchip Technology Inc. DS70046C-page vi...
Page 7
Operation During Sleep and Idle Modes ...................... 17-49 Effects of a Reset ............................17-49 Special Function Registers Associated with the 10-bit A/D Converter ............17-50 Design Tips ..............................17-51 Related Application Notes ..........................17-52 Revision History ............................17-53 2004 Microchip Technology Inc. DS70046C-page vii...
Page 8
Other Features of the UART ........................19-21 UART Operation During CPU Sleep and Idle Modes ................... 19-21 Registers Associated with UART Module ..................... 19-22 Design Tips ..............................19-23 Related Application Notes ..........................19-24 Revision History ............................19-25 2004 Microchip Technology Inc. DS70046C-page viii...
Page 9
DCI Operation .............................. 22-10 Using the DCI Module ..........................22-17 Operation in Power Saving Modes ....................... 22-28 Registers Associated with DCI ........................22-28 Design Tips ..............................22-30 Related Application Notes ..........................22-31 Revision History ............................22-32 2004 Microchip Technology Inc. DS70046C-page ix...
Page 10
25-1 Introduction ..............................25-2 Microchip Hardware and Language Tools ...................... 25-2 Third Party Hardware/Software Tools and Application Libraries ..............25-6 dsPIC30F Hardware Development Boards ....................25-11 Related Application Notes ..........................25-15 Revision History ............................25-16 SECTION 26. APPENDIX Appendix A: I2C™ Overview........................... 26-2 Appendix B: CAN Overview ..........................
This literature can be obtained from your local sales office, or downloaded from the Microchip web site (www.microchip.com). Manual Objective PICmicro and dsPIC30F devices are grouped by the size of their Instruction Word and Data Path. The current device families are: Base-Line:...
Watchdog Timer and Power Saving Modes Flash and EEPROM Programming Device Configuration 1.3.3 Peripherals The dsPIC30F has many peripherals that allow the device to be interfaced to the external world. The peripherals discussed in this manual include: I/O Ports Timers Input Capture Module...
Family Reference Manual Development Support Microchip offers a wide range of development tools that allow users to efficiently develop and debug application code. Microchip’s development tools can be broken down into four categories: Code generation Hardware/Software debug Device programmer Product evaluation boards A full description of each of Microchip’s development tools is discussed in Section...
(www.microchip.com) for the latest published technical documentation. 1.6.1 Microchip Documentation The following dsPIC30F documentation is available from Microchip at the time of this writing. Many of these documents provide application specific information that gives actual examples of using, programming and designing with dsPIC30F MCUs.
(W15) operates as a software stack pointer for interrupts and calls. The dsPIC30F instruction set has two classes of instructions: the MCU class of instructions and the DSP class of instructions. These two instruction classes are seamlessly integrated into the architecture and execute from a single execution unit.
Section 2. CPU Figure 2-1: dsPIC30F CPU Core Block Diagram X Address Bus Y Data Bus X Data Bus Data Latch Data Latch Interrupt PSV & Table Controller Y Data X Data Data Access Control Block (4 Kbytes) (4 Kbytes)
Family Reference Manual Programmer’s Model The programmer’s model for the dsPIC30F is shown in Figure 2-2. All registers in the program- mer’s model are memory mapped and can be manipulated directly by instructions. A description of each register is provided in Table 2-1.
Page 24
0x0004 in memory. W2 is also mapped to this address in memory. Even though this is an unlikely event, it is impossible to detect until run-time. The dsPIC30F ensures that the data write will dominate, resulting in W2 = 0x1234 in the example above.
W15 is initialized to 0x0800 during all Resets. This address ensures that the stack pointer (SP) will point to valid RAM in all dsPIC30F devices and permits stack availability for non-maskable trap exceptions, which may occur before the SP is initialized by the user software. The user may reprogram the SP during initialization to any location within data space.
Page 28
ULNK (unlink) instructions. W14 can be used in a normal working register by instructions when it is not used as a frame pointer. Refer to the “dsPIC30F Programmer’s Reference Manual” (DS70030) for software examples that use W14 as a stack frame pointer.
2.4.1 SR: CPU Status Register The dsPIC30F CPU has a 16-bit status register (SR), the LSByte of which is referred to as the lower status register (SRL). The upper byte of SR is referred to as SRH. A detailed description of SR is shown in Register 2-1.
Page 30
Family Reference Manual Register 2-1: SR: CPU Status Register Upper Byte: R/C-0 R/C-0 R/C-0 R -0 R/W-0 bit 15 bit 8 Lower Byte: (SRL) R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 IPL<2:0> bit 7 bit 0 bit 15 OA: Accumulator A Overflow Status bit...
Page 34
Family Reference Manual 2.4.3 Other dsPIC30F CPU Control Registers The registers listed below are associated with the dsPIC30F CPU core, but are described in further detail in other sections of this manual. 2.4.3.1 TBLPAG: Table Page Register The TBLPAG register is used to hold the upper 8 bits of a program memory address during table read and write operations.
Section 2. CPU Arithmetic Logic Unit (ALU) The dsPIC30F ALU is 16-bits wide and is capable of addition, subtraction, single bit shifts and logic operations. Unless otherwise mentioned, arithmetic operations are 2’s complement in nature. Depending on the operation, the ALU may affect the values of the Carry (C), Zero (Z), Negative (N), Overflow (OV) and Digit Carry (DC) status bits in the SR register.
Page 38
2.6.2 Multiplier The dsPIC30F features a 17-bit x 17-bit multiplier which is shared by both the MCU ALU and the DSP engine. The multiplier is capable of signed or unsigned operation and can support either 1.31 fractional (Q.31) or 32-bit integer results.
Page 40
Family Reference Manual Table 2-2: dsPIC30F Data Ranges Register Fraction Integer Range Fraction Range Size Resolution 16-bit -32768 to -1.0 to (1.0 – 2 3.052 x 10 32767 (Q.15 Format) 32-bit -2,147,483,648 to -1.0 to (1.0 – 2 4.657 x 10 2,147,483,647 (Q.31 Format)
Page 42
Family Reference Manual 2.6.3.2 Saturation and Overflow Modes The device supports three Saturation and Overflow modes. Accumulator 39-bit Saturation: In this mode, the saturation logic loads the maximally positive 9.31 value (0x7FFFFFFFFF), or maximally negative 9.31 value (0x8000000000), into the target accumulator.
Page 44
Family Reference Manual 2.6.5 Barrel Shifter The barrel shifter is capable of performing up to a 16-bit arithmetic right shift, or up to a 16-bit left shift, in a single cycle. The barrel shifter can be used by DSP instructions or MCU instructions for multi-bit shifts.
Instruction Flow Types Most instructions in the dsPIC30F architecture occupy a single word of program memory and execute in a single cycle. An instruction pre-fetch mechanism facilitates single cycle (1 T execution. However, some instructions take 2 or 3 instruction cycles to execute. Consequently, ®...
Page 46
Family Reference Manual 1 Instruction Word, 2 or 3 Instruction Cycle Program Flow Changes: These instructions include relative call and branch instructions, and skip instructions. When an instruction changes the PC (other than to increment it), the program memory pre-fetch data must be discarded.
Family Reference Manual Loop Constructs The dsPIC30F supports both REPEAT and DO instruction constructs to provide unconditional automatic program loop control. The REPEAT instruction is used to implement a single instruction program loop. The DO instruction is used to implement a multiple instruction program loop. Both instructions use control bits within the CPU Status register, SR, to temporarily modify CPU operation.
Page 50
‘do-while’ construct in the C programming language because the instructions in the loop will always be executed at least once. The dsPIC30F has three registers associated with DO loops: DOSTART, DOEND and DCOUNT. These registers are memory mapped and automatically loaded by the hardware when the DO instruction is executed.
Page 52
Family Reference Manual 2.9.2.5 DO Loop Restrictions DO loops have the following restrictions imposed: • choice of last instruction in the loop • the loop length (offset from the first instruction) • reading of the DOEND register All DO loops must contain at least 2 instructions because the loop termination tests are performed in the penultimate instruction.
2.10 Address Register Dependencies The dsPIC30F architecture supports a data space read (source) and a data space write (destination) for most MCU class instructions. The effective address (EA) calculation by the AGU and subsequent data space read or write, each take a period of 1 instruction cycle to complete.
Page 54
If the source read (pre-fetched instruction) does not calculate an EA using Wn, no stalls will occur. During each instruction cycle, the dsPIC30F hardware automatically checks to see if a RAW data dependency is about to occur. If the conditions specified above are not satisfied, the CPU will automatically add a one instruction cycle delay before executing the pre-fetched instruction.
Page 55
Section 2. CPU If a RAW data dependency is detected, the dsPIC30F will begin an instruction stall. During an instruction stall, the following events occur: The write operation underway (for the previous instruction) is allowed to complete as normal. Data space is not addressed until after the instruction stall.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Family Reference Manual Introduction The dsPIC30F data width is 16-bits. All internal registers and data space memory are organized as 16-bits wide. The dsPIC30F features two data spaces. The data spaces can be accessed separately (for some DSP instructions) or together as one 64-Kbyte linear address range (for MCU instructions).
Page 64
The memory regions included in the near data region will depend on the amount of data memory implemented for each dsPIC30F device variant. At a minimum, the near data region will include all of the SFRs and some of the X data memory. For devices that have smaller amounts of data memory, the near data region may include all of X memory space and possibly some or all of Y memory space.
Section 3. Data Memory Data Space Address Generator Units (AGUs) The dsPIC30F contains an X AGU and a Y AGU for generating data memory addresses. Both X and Y AGUs can generate any effective address (EA) within a 64-Kbyte range. However, EAs that are outside the physical memory provided will return all zeros for data reads and data writes to those locations will have no effect.
Page 66
The Y AGU only supports Post-modification Addressing modes associated with the DSP class of instructions. For more information on Addressing modes, please refer to the dsPIC30F Program- mer’s Reference Manual. The Y AGU also supports modulo addressing for automated circular buffers.
(since the data pointer mechanism is essentially the same for both). One circular buffer can be supported in each of the X (which also provides the pointers into Program space) and Y data spaces.
Page 68
Family Reference Manual 3.3.1 Modulo Start and End Address Selection Four address registers are available for specifying the modulo buffer start and end addresses: • XMODSRT: X AGU Modulo Start Address Register • XMODEND: X AGU Modulo End Address Register •...
Page 70
Family Reference Manual An additional condition exists for indirect read operations performed immediately after writing to the modulo address SFRs: • XMODSRT • XMODEND • YMODSRT • YMODEND If modulo addressing has already been enabled in MODCON, then a write to the X (or Y) modulo address SFRs should not be immediately followed by an indirect read, using the W register designated for modulo buffer access from X-data space (or Y-data space).
Page 72
Family Reference Manual 3.3.4 Modulo Addressing Initialization for Incrementing Modulo Buffer The following steps describe the setup procedure for an incrementing circular buffer. The steps are similar whether the X AGU or Y AGU is used. Determine the buffer length in 16-bit data words. Multiply this value by 2 to get the length of the buffer in bytes.
Family Reference Manual Bit-Reversed Addressing 3.4.1 Introduction to Bit-Reversed Addressing Bit-reversed addressing simplifies data re-ordering for radix-2 FFT algorithms. It is supported through the X WAGU only. Bit-reversed addressing is accomplished by effectively creating a ‘mirror image’ of an address pointer by swapping the bit locations around the center point of the binary value, as shown in Figure 3-7.
Page 76
Family Reference Manual 3.4.3 Bit-Reverse Modifier Value The value loaded into the XBREV register is a constant that indirectly defines the size of the bit-reversed data buffer. The XB modifier values used with common bit-reversed buffers are summarized in Table 3-2.
Family Reference Manual 3.4.4 Bit-Reversed Addressing Code Example The following code example reads a series of 16 data words and writes the data to a new location in bit-reversed order. W0 is the read address pointer and W1 is the write address pointer subject to bit-reverse modification.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Revision A This is the initial released revision of this document. Revision B This revision incorporates additional technical content for the dsPIC30F Data Memory module. Revision C This revision incorporates all known errata at the time of this document update.
Family Reference Manual Program Memory Address Map The dsPIC30F devices have a 4M x 24-bit program memory address space, shown in Figure 4-1. There are three available methods for accessing program space. Via the 23-bit PC. Via table read (TBLRD) and table write (TBLWT) instructions.
Family Reference Manual Program Counter The PC increments by 2 with the LSb set to ‘0’ to provide compatibility with data space addressing. Sequential instruction words are addressed in the 4M program memory space by PC<22:1>. Each instruction word is 24-bits wide.
Page 90
Family Reference Manual 4.3.2 Table Address Generation For all table instructions, a W register address value is concatenated with the 8-bit Data Table Page register, TBLPAG, to form a 23-bit effective program space address plus a byte select bit, as shown in Figure 4-4.
PSV Mapping with X and Y Data Spaces The Y data space is located outside of the upper half of data space for most dsPIC30F variants, such that the PSV area will map into X data space. The X and Y mapping will have an effect on how PSV is used in algorithms.
Refer to Section 2. “CPU” for more information about instruction stalls using PSV. Program Memory Writes The dsPIC30F family of devices contains internal program Flash memory for executing user code. There are two methods by which the user can program this memory: Run-Time Self Programming (RTSP) In-Circuit Serial Programming™...
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Family Reference Manual Revision History Revision A This is the initial released revision of this document. Revision B There were no technical content or editorial revisions to this section of the manual, however, this section was updated to reflect Revision B throughout the manual.
The table instructions provide one method of transferring data between the program memory space and the data memory space of dsPIC30F devices. A summary of the table instructions is provided here since they are used during programming of the Flash program memory and data EEPROM.
Note: The tblpage() and tbloffset() directives are provided by the Microchip assembler for the dsPIC30F. These directives select the appropriate TBLPAG and W register values for the table instruction from a program memory address value. Refer to the Microchip software tools documentation for further details.
Page 100
Family Reference Manual 5.2.2 Using Table Write Instructions The effect of a table write instruction will depend on the type of memory technology that is present in the device program memory address space. The program memory address space could contain volatile or non-volatile program memory, non-volatile data memory, and an External Bus Interface (EBI).
Page 102
Family Reference Manual 5.3.2 NVM Address Register There are two NVM Address Registers - NVMADRU and NVMADR. These two registers when concatenated form the 24-bit effective address (EA) of the selected row or word for programming operations. The NVMADRU register is used to hold the upper 8 bits of the EA, while the NVMADR register is used to hold the lower 16 bits of the EA.
The dsPIC30F Flash program memory is organized into rows and panels. Each row consists of 32 instructions or 96 bytes. The panel size may vary depending on the dsPIC30F device variant. Refer to the device data sheet for further information. Typically, each panel consists of 128 rows, or 4K x 24 instructions.
Page 106
Family Reference Manual 5.4.2.1 Flash Program Memory Programming Algorithm The user can erase and program Flash Program Memory by rows (32 instruction words). The general process is as follows: Read one row of program Flash (32 instruction words) and store into data RAM as a data “image”.
Page 108
Family Reference Manual 5.4.2.3 Loading Write Latches The following is a sequence of instructions that can be used to load the 768-bits of write latches (32 instruction words). 32 TBLWTL and 32 TBLWTH instructions are needed to load the write latches selected by the table pointer.
Family Reference Manual 5.4.3.2 Configuration Register Write Code Example The following code sequence can be used to modify a Device Configuration register: ; Set up a pointer to the location to be written. #tblpage(CONFIG_ADDR),W0 TBLPAG #tbloffset(CONFIG_ADDR),W0 ; Get the new data to write to the configuration register #ConfigValue,W1 ;...
Page 112
Family Reference Manual 5.5.3 Erasing One Word of Data EEPROM Memory The TBLPAG and NVMADR registers must be loaded with the data EEPROM address to be erased. Since one word of the EEPROM is accessed, the LSB of the NVMADR has no effect on the erase operation.
Page 114
Family Reference Manual 5.5.5 Erasing One Row of Data EEPROM The NVMCON register is configured to erase one row of EEPROM memory. The TABPAG and NVMADR registers must point to the row to be erased. The data EEPROM must be erased at even address boundaries.
Family Reference Manual 5.5.7 Reading the Data EEPROM Memory A TBLRD instruction reads a word at the current program word address. This example uses W0 as a pointer to data Flash. The result is placed into register W4. ; Setup pointer to EEPROM memory...
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Revision A This is the initial released revision of this document. Revision B This revision incorporates technical content changes for the dsPIC30F Flash and EEPROM Programming module. Revision C This revision incorporates all known errata at the time of this document update.
A device Reset is not a true exception because the interrupt controller is not involved in the Reset process. The dsPIC30F device clears its registers in response to a Reset which forces the PC to zero. The processor then begins program execution at location 0x000000. The user programs a GOTO instruction at the Reset address which redirects program execution to the appropriate start-up routine.
Page 123
Note: The peripherals and sources of interrupt available in the IVT will vary depending on the specific dsPIC30F device. The sources of interrupt shown in this document represent a comprehensive listing of all interrupt sources found on dsPIC30F devices. Refer to the specific device data sheet for further details.
Otherwise, the trap vector is programmed with the address of a service routine that will correct the trap condition. The dsPIC30F has four implemented sources of non-maskable traps: • Oscillator Failure Trap • Stack Error Trap •...
Page 126
A misaligned data word fetch is attempted. This condition occurs when an instruction performs a word access with the LSb of the effective address set to ‘1’. The dsPIC30F CPU requires all word accesses to be aligned to an even address boundary.
Page 128
IEC Control registers, a wake-up signal is sent to the dsPIC30F CPU. When the device wakes from Sleep or Idle mode, one of two actions may occur: If the interrupt priority level for that source is greater than the current CPU priority level, then the processor will process the interrupt and branch to the ISR for the interrupt source.
Page 130
Family Reference Manual 6.3.2 Interrupt Latency for Two-Cycle Instructions The interrupt latency during a two-cycle instruction is the same as during a one-cycle instruction. The first and second cycle of the interrupt process allow the two-cycle instruction to complete execution.
Page 131
6.3.4 Special Conditions for Interrupt Latency The dsPIC30F allows the current instruction to complete when a peripheral interrupt source becomes pending. The interrupt latency is the same for both one and two-cycle instructions. However, there are certain conditions that can increase interrupt latency by one cycle, depending on when the interrupt occurs.
Family Reference Manual Interrupt Control and Status Registers The following registers are associated with the interrupt controller: • INTCON1, INTCON2 Registers Global interrupt control functions are derived from these two registers. INTCON1 contains the Interrupt Nesting Disable (NSTDIS) bit, as well as the control and status flags for the processor trap sources.
Family Reference Manual Interrupt Setup Procedures 6.5.1 Initialization The following steps describe how to configure a source of interrupt: Set the NSTDIS Control bit (INTCON1<15>) if nested interrupts are not desired. Select the user assigned priority level for the interrupt source by writing the control bits in the appropriate IPCx Control register.
Family Reference Manual Design Tips Question 1: What happens when two sources of interrupt become pending at the same time and have the same user assigned priority level? Answer: The interrupt source with the highest natural order priority will take precedence. The natural order priority is determined by the Interrupt Vector Table (IVT) address for that source.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Revision A This is the initial released revision of this document. Revision B This revision incorporates additional technical content for the dsPIC30F Interrupts module. Revision C This revision incorporates all known errata at the time of this document update. DS70053C-page 6-46...
Family Reference Manual Introduction This section describes the dsPIC30F oscillator system and its operation. The dsPIC30F oscillator system has the following modules and features: • Various external and internal oscillator options as clock sources • An on-chip PLL to boost internal operating frequency •...
Family Reference Manual CPU Clocking Scheme Referring to Figure 7-1, the system clock source can be provided by one of four sources. These sources are the Primary oscillator, Secondary oscillator, Internal Fast RC (FRC) oscillator or the Low Power RC (LPRC) oscillator. The Primary oscillator source has the option of using the internal PLL.
Family Reference Manual 7.3.1 Clock Switching Mode Configuration Bits The FCKSM<1:0> configuration bits (F <15:14>) are used to enable/disable device clock switching and the Fail-Safe Clock Monitor (FSCM). When these bits are unprogrammed (default), clock switching and the FSCM are disabled.
Section 7. Oscillator Primary Oscillator The Primary oscillator is available on the OSC1 and OSC2 pins of the dsPIC30F device family. The Primary oscillator has 13 Operation modes summarized in Table 7-2. In general, the Primary oscil- lator can be configured for an external clock input, external RC network, or an external crystal.
In XT, XTL and HS modes, a crystal or ceramic resonator is connected to the OSC1 and OSC2 pins to establish oscillation (Figure 7-3). The dsPIC30F oscillator design requires the use of a parallel cut crystal. Using a series cut crystal may give a frequency out of the crystal manufacturer’s specifications.
The dsPIC30F internal oscillator circuit is a parallel oscillator circuit, which requires that a parallel resonant crystal be selected. The load capacitance is usually specified in the 22 pF to 33 pF range.
Family Reference Manual External RC Oscillator For timing insensitive applications, the ERC and ERCIO modes of the Primary oscillator offer additional cost savings. The RC oscillator frequency is a function of the: • Supply voltage • External resistor (R ) values •...
Page 180
Family Reference Manual Figure 7-9: Typical External RC Oscillator Frequency vs = 20 pF Operation above 4 MHz is not recommended. = 10k = 100k Figure 7-10: Typical External RC Oscillator Frequency vs. V = 100 pF Operation above 4 MHz is not recommended.
Table 7-3. Note: Some PLL output frequency ranges can be achieved that exceed the maximum operating frequency of the dsPIC30F device. Refer to the “Electrical Specifications” in the specific device data sheet for further details. Table 7-3: PLL Frequency Range...
Family Reference Manual 7.14 Internal Low Power RC (LPRC) Oscillator The LPRC oscillator is a component of the Watchdog Timer (WDT) and oscillates at a nominal frequency of 512 kHz. The LPRC oscillator is the clock source for the Power-up Timer (PWRT) circuit, WDT and clock monitor circuits.
Family Reference Manual Figure 7-13: Postscaler Update Timing System Clock Divide by 4 Divide by 16 Divide by 64 POST<1:0> Postscaled System Clock 1:16 1:64 Note: This diagram demonstrates the clock postscaler function only. The divide ratios shown in the timing diagram are not correct.
Page 188
Family Reference Manual 7.17.3 Clock Switching Tips • If the destination clock source is a crystal oscillator, the clock switch time will be dominated by the oscillator start-up time. • If the new clock source does not start, or is not present, then the clock switching hardware will simply wait for the 10 synchronization cycles to occur.
Family Reference Manual 7.18 Design Tips Question 1: When looking at the OSC2 pin after power-up with an oscilloscope, there is no clock. What can cause this? Answer: Entering Sleep mode with no source for wake-up (such as, WDT, MCLR, or an interrupt).
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Revision A This is the initial released revision of this document. Revision B This revision incorporates technical content changes for the dsPIC30F Oscillator module. Revision C This revision incorporates all known errata at the time of this document update. DS70054C-page 7-28...
Family Reference Manual Introduction The Reset module combines all Reset sources and controls the device Master Reset Signal, SYSRST. The following is a list of device Reset sources: • POR: Power-on Reset • EXTR: Pin Reset (MCLR) • SWR: RESET Instruction •...
Page 196
Family Reference Manual Register 8-1: RCON: Reset Control Register (Continued) bit 1 BOR: Brown-out Reset Flag bit 1 = A Brown-out Reset has occurred. Note that BOR is also set after Power-on Reset. 0 = A Brown-out Reset has not occurred...
Page 198
Family Reference Manual Figure 8-2: POR Module Timing Diagram for Rising V POR Circuit Threshold Voltage Time Internal Power-on Reset pulse occurs at V and begins POR delay time, T POR circuit is initialized at V Time System Reset is released after Power-up Timer expires.
Family Reference Manual Brown-out Reset (BOR) The BOR (Brown-out Reset) module is based on an internal voltage reference circuit. The main purpose of the BOR module is to generate a device Reset when a brown-out condition occurs. Brown-out conditions are generally caused by glitches on the AC mains (i.e., missing waveform portions of the AC cycles due to bad power transmission lines), or voltage sags due to excessive current draw when a large load is energized.
Family Reference Manual Using the RCON Status Bits The user can read the RCON register after any device Reset to determine the cause of the Reset. Note: The status bits in the RCON register should be cleared after they are read so that the next RCON register value after a device Reset will be meaningful.
Page 204
Family Reference Manual 8.9.1 POR and Long Oscillator Start-up Times The oscillator start-up circuitry and its associated delay timers is not linked to the device Reset delays that occur at power-up. Some crystal circuits (especially low frequency crystals) will have a relatively long start-up time.
Page 206
Family Reference Manual The Reset time line shown in Figure 8-6 is similar to that shown in Figure 8-5, except that the PWRT has been enabled to increase the amount of delay time before SYSRST is released. FSCM The FSCM, if enabled, will begin to monitor the system clock after T expires.
8.11 Special Function Register Reset States Most of the special function registers (SFRs) associated with the dsPIC30F CPU and peripherals are reset to a particular value at a device Reset. The SFRs are grouped by their peripheral or CPU function and their Reset values are specified in each section of this manual.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Family Reference Manual Introduction The LVD module is applicable to battery operated applications. As the battery drains its energy, the battery voltage slowly drops. The battery source impedance also increases as it loses energy. The LVD module is used to detect when the battery voltage (and therefore, the V of the device) drops below a threshold, which is considered near the end of battery life for the application.
Family Reference Manual Design Tips Question 1: The LVD circuitry seems to be generating random interrupts? Answer: Ensure that the internal voltage reference is stable before enabling the LVD interrupt. This is done by polling the BGST status bit (RCON<13>) after the LVD module is enabled. After this time delay, the LVDIF bit should be cleared and then, the LVDIE bit may be set.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Family Reference Manual Revision History Revision A This is the initial released revision of this document. Revision B There were no technical content or editorial revisions to this section of the manual, however, this section was updated to reflect Revision B throughout the manual.
10.2 Power Saving Modes The dsPIC30F device family has two special Power Saving modes, Sleep mode and Idle mode, that can be entered through the execution of a special PWRSAV instruction. The assembly syntax of the PWRSAV instruction is as follows: PWRSAV #SLEEP_MODE ;...
Page 223
= PLL lock time (20 µs nominal). LOCK 3: T = Fail-Safe Clock Monitor delay (100 µs nominal). FSCM 4: T Note: Please refer to the “Electrical Specifications” section of the dsPIC30F device data FSCM LOCK sheet for T and T specification values. 10.3.3...
Family Reference Manual 10.3.6 Wake-up from Sleep on Interrupt User interrupt sources that are assigned to CPU priority level 0 cannot wake the CPU from Sleep mode, because the interrupt source is effectively disabled. To use an interrupt as a wake-up source, the CPU priority level for the interrupt must be assigned to CPU priority level 1 or greater.
Family Reference Manual 10.6 Watchdog Timer The primary function of the Watchdog Timer (WDT) is to reset the processor in the event of a software malfunction. The WDT is a free running timer, which runs on the internal LPRC oscillator requiring no external components.
Page 227
The WDT time-out period is directly related to the frequency of the LPRC oscillator. The frequency of the LPRC oscillator will vary as a function of device operating voltage and temperature. Please refer to the specific dsPIC30F device data sheet for LPRC clock frequency specifications.
Page 228
Family Reference Manual Table 10-2 shows time-out periods for various prescaler selections: Table 10-2: WDT Time-out Period vs. Prescale A and Prescale B Settings Prescaler A Value Prescaler B Value 1024 2048 3072 4096 5120 6144 7168 1024 8192...
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Family Reference Manual 11.1 Introduction This section provides information on the I/O ports for the dsPIC30F family of devices. All of the device pins (except V , MCLR, and OSC1/CLKI) are shared between the peripherals and the general purpose I/O ports.
11.3.1 I/O Multiplexing with Multiple Peripherals For some dsPIC30F devices, especially those with a small number of I/O pins, multiple peripheral functions may be multiplexed on each I/O pin. Figure 11-2 shows an example of two peripherals multiplexed to the same I/O pin.
(enabled) for generating CN interrupts. The total number of available CN inputs is dependent on the selected dsPIC30F device. Refer to the device data sheet for further details. Figure 11-3 shows the basic function of the CN hardware.
Family Reference Manual 11.5.1 CN Control Registers There are four control registers associated with the CN module. The CNEN1 and CNEN2 registers contain the CNxIE control bits, where ‘x’ denotes the number of the CN input pin. The CNxIE bit must be set for a CN input pin to interrupt the CPU.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
This is the initial released revision of this document. Revision B This revision incorporates additional technical content for the dsPIC30F I/O Ports module. Revision C There were no technical content revisions to this section of the manual, however, this section was updated to reflect Revision C throughout the manual.
Family Reference Manual 12.1 Introduction Depending on the specific variant, the dsPIC30F device family offers several 16-bit timers. These timers are designated as Timer1, Timer2, Timer3, ..., etc. Each timer module is a 16-bit timer/counter consisting of the following readable/writable registers: •...
12.2.1 Type A Timer At least one Type A timer is available on most dsPIC30F devices. For most dsPIC30F devices, Timer1 is a Type A timer. A Type A timer has the following unique features over other types: • can be operated from the device Low Power 32 kHz Oscillator •...
Page 246
12.2.2 Type B Timer Timer2 and Timer4, if present, are Type B timers on most dsPIC30F devices. A Type B timer has the following unique features over other types of timers: • A Type B timer can be concatenated with a Type C timer to form a 32-bit timer. The TxCON register for a Type B timer has the T32 control bits to enable the 32-bit timer function.
Page 247
1, 8, 64, 256 Note: In certain variants of the dsPIC30F family, the TxCK pin may not be available. Refer to the device data sheet for the I/O pin details. In such cases, the timer must use the system clock (F /4) as its input clock, unless it is configured for 32-bit operation.
Family Reference Manual 12.3 Control Registers Register 12-1: TxCON: Type A Time Base Register Upper Byte: R/W-0 R/W-0 — TSIDL — — — — — bit 15 bit 8 Lower Byte: R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 — TGATE TCKPS<1:0>...
Page 252
Family Reference Manual 12.4.2 Synchronous Counter Mode Using External Clock Input When the TCS control bit (TxCON<1>) is set, the clock source for the timer is provided externally and the selected timer increments on every rising edge of clock input on the TxCK pin.
Page 254
Family Reference Manual 12.4.4 Timer Operation with Fast External Clock Source In some applications, it may be desirable to use one of the timers to count clock edges from a relatively high frequency external clock source. In these situations, Type A and Type B time...
Family Reference Manual 12.5 Timer Prescalers The input clock (F /4 or external clock) to all 16-bit timers has prescale options of 1:1, 1:8, 1:64 and 1:256. The clock prescaler is selected using the TCKPS<1:0> control bits (TxCON<5:4>). The prescaler counter is cleared when any of the following occurs: •...
Family Reference Manual 12.9 32-bit Timer Configuration A 32-bit timer module can be formed by combining a Type B and a Type C 16-bit timer module. The Type C time base becomes the MSWord of the combined timer and the Type B time base is the LSWord.
Family Reference Manual 12.10 32-bit Timer Modes of Operation 12.10.1 Timer Mode Example 12-5 shows how to configure a 32-bit timer in Timer mode. This example assumes Timer2 is a Type B time base and Timer3 is a Type C time base. For 32-bit timer operation, the T32 control bit must be set in the T2CON register (Type B time base).
Page 262
Family Reference Manual 12.10.3 Asynchronous Counter Mode Type B and Type C time bases do not support the Asynchronous External Clock mode. Therefore, no 32-bit Asynchronous Counter mode is supported. 12.10.4 Gated Time Accumulation Mode The 32-bit timer operates similarly to a 16-bit timer in Gated Time Accumulation mode.
Family Reference Manual 12.13 Peripherals Using Timer Modules 12.13.1 Time Base for Input Capture/Output Compare The Input Capture and Output Compare peripherals can select one of two timer modules as their time base. Refer to Section 13. “Input Capture”, Section 14. “Output Compare”, and the device data sheet for further details.
Family Reference Manual 12.14 Design Tips Question 1: Can a timer module be used to wake the device from Sleep mode? Answer: Yes, but only Timer1 has the ability to wake the device from Sleep mode. This is because Timer1 allows the TMR1 register to increment from an external, unsynchronized clock source.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
This is the initial released revision of this document. Revision B This revision incorporates technical content changes for the dsPIC30F Timers module. Revision C There were no technical content revisions to this section of the manual, however, this section was updated to reflect Revision C throughout the manual.
Family Reference Manual 13.1 Introduction This section describes the Input Capture module and its associated Operational modes. The Input Capture module is used to capture a timer value from one of two selectable time bases, upon an event on an input pin. The Input Capture features are quite useful in applications requiring frequency (Time Period) and pulse measurement.
Section 13. Input Capture 13.2 Input Capture Registers Each capture channel available on the dsPIC30F devices has the following registers, where ‘x’ denotes the number of the capture channel: • ICxCON: Input Capture Control Register • ICxBUF: Input Capture Buffer Register...
13.3 Timer Selection Each dsPIC30F device may have one or more input capture channels. Each channel can select between one of two 16-bit timers for the time base. Refer to the device data sheet for the specific timers that can be selected.
Page 274
Family Reference Manual 13.4.2 Prescaler Capture Events The capture module has two Prescaled Capture modes. The Prescale modes are selected by setting the ICM<2:0> (ICxCON<2:0>) bits to ‘100’ or ‘101’, respectively. In these modes, the capture module counts four or sixteen rising edge pin events before a capture event occurs.
Family Reference Manual 13.4.3 Edge Detection Mode The capture module can capture a time base count value on every rising and falling edge of the input signal applied to the ICx pin. The Edge Detection mode is selected by setting the ICM<2:0>...
The input capture module assignment for each UART will depend on the dsPIC30F device variant that is selected. Refer to the device data sheet for further details on the autobaud support.
In the event the capture module has been configured for a mode other than ICM<2:0> = ‘111’ and the dsPIC30F does enter the Sleep mode, no external pin stimulus, rising or falling, will generate a wake-up condition from Sleep.
Family Reference Manual 13.11 Design Tips Question 1: Can the Input Capture module be used to wake the device from Sleep mode? Answer: Yes. When the Input Capture module is configured to ICM<2:0> = ‘111’ and the respective channel interrupt enable bit is asserted, ICxIE = 1, a rising edge on the capture pin will wake-up the device from Sleep (see Section 13.8 “Input Capture Operation in Power...
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Family Reference Manual 13.13 Revision History Revision A This is the initial released revision of this document. Revision B There were no technical content or editorial revisions to this section of the manual, however, this section was updated to reflect Revision B throughout the manual.
Like most dsPIC peripherals, it also has the ability to generate interrupts-on- compare match events. The dsPIC30F device may have up to eight output compare channels, designated OC1, OC2, OC3, etc. Refer to the specific device data sheet for the number of channels available in a particular device.
Family Reference Manual 14.3 Modes of Operation Each output compare module has the following modes of operation: • Single Compare Match mode • Dual Compare Match mode generating - Single Output Pulse - Continuous Output Pulses • Simple Pulse Width Modulation mode...
Page 288
Family Reference Manual 14.3.1.2 Compare Mode Output Driven Low To configure the output compare module for this mode, set control bits OCM<2:0> = ‘010’. The compare time base must also be enabled. Once this Compare mode has been enabled, the output pin, OCx, will be initially driven high and remain high until a match occurs between the Timer and OCxR registers.
Page 290
Family Reference Manual Example 14-1: Compare Mode Toggle Mode Pin State Setup The following code example illustrates how to define the initial OC1 pin state for the output compare toggle mode of operation. Toggle mode with initial OC1 pin state set low 0x0001, w0 ;...
Page 292
Family Reference Manual Figure 14-6: Dual Compare Mode 1 Instruction Clock Period 4000 0000 3000 3001 3002 3003 3004 3005 3006 TMRy TMRy Resets Here 4000 OCxR 3000 OCxRS 3003 OCx pin OCxIF Cleared by User Note 1: An ‘x’ represents the output compare channel number. A ‘y’ represents the time base number.
Page 294
Family Reference Manual Example 14-3 shows example code for configuration of the single output pulse event. Example 14-3: Single Output Pulse Setup and Interrupt Servicing The following code example will set the Output Compare 1 module for interrupts on the single pulse event and select Timer 2 as the clock source for the compare time base.
Page 296
Family Reference Manual 14.3.2.4 Dual Compare Mode: Continuous Output Pulses To configure the output compare module for this mode, set control bits OCM<2:0> = ‘101’. In addition, the compare time base must be selected and enabled. Once this mode has been enabled, the output pin, OCx, will be driven low and remain low until a match occurs between the compare time base and OCxR register.
Page 298
Family Reference Manual Example 14-4 shows example code for configuration of the continuous output pulse event. Example 14-4: Continuous Output Pulse Setup and Interrupt Servicing The following code example will set the Output Compare 1 module for interrupts on the continuous pulse event and select Timer 2 as the clock source for the compare time-base.
Page 300
Family Reference Manual 14.3.3 Pulse Width Modulation Mode When control bits OCM<2:0> (OCxCON<2:0>) are set to ‘110’ or ‘111’, the selected output compare channel is configured for the PWM (Pulse Width Modulation) mode of operation. The following two PWM modes are available: •...
Page 302
Family Reference Manual 14.3.3.3 PWM Duty Cycle The PWM duty cycle is specified by writing to the OCxRS register. The OCxRS register can be written to at any time, but the duty cycle value is not latched into OCxR until a match between PRy and TMRy occurs (i.e., the period is complete).
Page 304
Family Reference Manual Example 14-6 shows configuration and interrupt service code for the PWM mode of operation. Example 14-6: PWM Mode Pulse Setup and Interrupt Servicing The following code example will set the Output Compare 1 module for PWM mode w/o FAULT pin enabled, a 50% duty cycle and a PWM frequency of 52.08 kHz at Fosc = 40 MHz.
Family Reference Manual 14.6 Design Tips Question 1: The Output Compare pin stops functioning even when the OCSIDL bit is not set. Why? Answer: This is most likely to occur when the TSIDL bit (TxCON<13>) of the associated timer source is set.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Family Reference Manual 14.8 Revision History Revision A This is the initial released revision of this document. Revision B There were no technical content or editorial revisions to this section of the manual, however, this section was updated to reflect Revision B throughout the manual.
A 6-output MCPWM module is also available and is typically found on smaller devices that have less than 64 pins. A given dsPIC30F device may have more than one MCPWM module. Please refer to the specific device data sheet for further details.
Family Reference Manual 15.2 Control Registers The following registers control the operation of the MCPWM module: • PTCON: PWM Time Base Control register • PTMR: PWM Time Base register • PTPER: PWM Time Base Period register • SEVTCMP: PWM Special Event Compare register •...
Family Reference Manual 15.3 PWM Time Base The PWM time base is provided by a 15-bit timer with a prescaler and postscaler (see Figure 15-2). The 15 bits of the time base are accessible via the PTMR register. PTMR<15> is a read-only status bit, PTDIR, that indicates the present count direction of the PWM time base.
Page 328
Family Reference Manual 15.3.6 PWM Time Base Interrupts The interrupt signals generated by the PWM time base depend on the mode selection bits, PTMOD<1:0> (PTCON<1:0>), and the time base postscaler bits, PTOPS<3:0> (PTCON<7:4>). • Free Running Mode When the PWM time base is in the Free Running mode (PTMOD<1:0> = 00), an interrupt is generated when the PTMR register is reset to ‘0’, due to a match with the PTPER register.
Family Reference Manual 15.4 PWM Duty Cycle Comparison Units The MCPWM module has four PWM generators. There are four 16-bit special function registers used to specify duty cycle values for the PWM generators: • PDC1 • PDC2 • PDC3 •...
Page 332
Family Reference Manual 15.4.3 Single Event PWM Operation The PWM module will produce single pulse outputs when the PWM time base is configured for the single event mode (PTMOD<1:0> = 01). This mode of operation is useful for driving certain types of electronically commutated motors.
Family Reference Manual Figure 15-9: Duty Cycle Update Times in Up/Down Count Mode Duty cycle value loaded from PDCx register, CPU interrupted PWM output PTMR Value PTIF New value written to PDCx register Figure 15-10: Duty Cycle Update Times in Up/Down Count Mode with Double Updates...
Page 336
Family Reference Manual Figure 15-13: Dead Time Unit Block Diagram for One Output Pin Pair Zero Compare Prescaler Clock Control 6-Bit Down Counter High-side PWM signal to output pin Low-Side PWM signal to output pin Dead Time Select Logic...
Family Reference Manual Table 15-4 shows example dead time ranges as a function of the input clock prescaler selected and the device operating frequency. Table 15-4: Example Dead Time Ranges Prescaler Selection Resolution Dead Time Range 33 ns (30 MHz)
Page 340
Family Reference Manual Table 15-5: PWM Output Override Example #1 State OVDCON<15:8> OVDCON<7:0> 00000000b 00100100b 00000000b 00100001b 00000000b 00001001b 00000000b 00011000b 00000000b 00010010b 00000000b 00000110b Figure 15-17: PWM Output Override Example #1 STATE PWM3H PWM3L PWM2H PWM2L PWM1H PWM1L Note: Switching times between states 1-6 are controlled by user software.
Family Reference Manual 15.9 PWM Output and Polarity Control The PENxx control bits in PWMCON1 enable each PWM output pin for use by the module. When a pin is enabled for PWM output, the PORT and TRIS registers controlling the pin are disabled.
Page 344
Family Reference Manual 15.10.5 Fault Pin Software Control Each of the fault pins can be controlled manually in software. Since each fault input is shared with a PORT I/O pin, the PORT pin can be configured as an output by clearing the corresponding TRIS bit.
Family Reference Manual 15.12.1 Special Event Trigger Enable The PWM module will always produce the special event trigger signal. This signal may optionally be used by the A/D module. Refer to Section Section 17. “10-bit A/D Converter” for more information on using the special event trigger.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent, and could be used with modification and possible limitations. The current...
Family Reference Manual 16.1 Module Introduction 16.1.1 Features Overview Quadrature encoders (a.k.a. Incremental encoders or Optical encoders) are used in position and speed detection of rotating motion systems. Quadrature encoders enable closed loop control of many motor control applications, such as Switched Reluctance (SR) motor and AC Induction Motor (ACIM).
Family Reference Manual 16.2 Control and Status Registers The QEI module has four user-accessible registers. The registers are accessible in either byte or word mode. The registers are shown in Figure 16-3 and listed below: • Control/Status Register (QEICON) – This register allows control of the QEI operation and status flags indicating the module state.
Page 358
Family Reference Manual Register 16-1: QEICON: QEI Control Register (Continued) bit 2 POSRES: Position Counter Reset Enable bit 1 = Index Pulse resets Position Counter 0 = Index Pulse does not reset Position Counter (Bit only applies when QEIM<2:0> = 100 or 110)
Page 359
001 = 1:2 Clock Divide 000 = 1:1 Clock Divide Note: The available control bits in the DFLTCON Register may vary depending on the dsPIC30F device that is used. Refer to Register 16-2 and Register 16-3 for details. Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’...
Page 360
000 = 1:1 Clock Divide bit 3-0 Unimplemented: Read as ‘0’ Note: The available control bits in the DFLTCON Register may vary depending on the dsPIC30F device that is used. Refer to Register 16-2 and Register 16-3 for details. Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’...
Family Reference Manual 16.4 Quadrature Decoder Position measurement modes are selected when QEIM2 = 1 (QEICON<10>). When QEIM1 = 1 (QEICON<9>), the ‘x4’ measurement mode is selected and the QEI logic clocks the position counter on both edges of the Phase A and Phase B input signals.
Page 363
Phase B signal to be fed to the A input of the quadrature counter. Therefore, if the Phase A signal leads the Phase B signal at the dsPIC30F device pins, the Phase A input to the quadrature counter will now lag the Phase B input. This is recognized as rotation in the reverse direction and the counter will be decremented on each quadrature pulse.
Family Reference Manual 16.4.4 Quadrature Rate The RPM of the position control system will vary. The RPMs along with the quadrature encoder line count determine the frequency of the QEA and QEB input signals. The quadrature encoder signals can be decoded such that a count pulse is generated for every quadrature signal edge.
Page 366
Family Reference Manual 16.5.3 Using Index to Reset Position Counter When QEIM<0> = 0, the index pulse is utilized for resetting the position counter. For this mode the position counter reset mechanism operates as follows: (See Figure 16-9 for related timing details).
16-bit timer/counter. The setup and control for the auxiliary timer is accomplished through the QEICON register. The QEI timer functions similar to the other dsPIC30F timers. Refer to Section 12. “Timers” for a general discussion of timers.
Family Reference Manual 16.8 I/O Pin Control Enabling the QEI module causes the associated I/O pins to come under the control of the QEI and prevents lower priority I/O functions such as Ports from affecting the I/O pin. Depending on the mode specified by QEIM<2:0> and other control bits, the I/O pins may assume differing functions, as shown in Table 16-2 and Table 16-3.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Revision A This is the initial released revision of this document. Revision B This revision provides expanded information for the dsPIC30F Quadrature Encoder Interface (QEI) module. Revision C This revision incorporates all known errata at the time of this document update.
These voltage reference inputs may be shared with other analog input pins. The actual number of analog input pins and external voltage reference input configuration will depend on the specific dsPIC30F device. Refer to the device data sheet for further details.
Family Reference Manual 17.2 Control Registers The A/D module has six Control and Status registers. These registers are: • ADCON1: A/D Control Register 1 • ADCON2: A/D Control Register 2 • ADCON3: A/D Control Register 3 • ADCHS: A/D Input Channel Select Register •...
Page 382
Family Reference Manual Register 17-1: ADCON1: A/D Control Register 1 (Continued) bit 1 SAMP: A/D Sample Enable bit 1 = At least one A/D sample/hold amplifier is sampling 0 = A/D sample/hold amplifiers are holding When ASAM = 0, writing ‘1’ to this bit will start sampling.
Page 388
Family Reference Manual A sample/convert sequence that uses multiple S/H channels can be simultaneously sampled or sequentially sampled, as controlled by the SIMSAM bit (ADCON1<3>). Simultaneously sampling multiple signals ensures that the snapshot of the analog inputs occurs at precisely the same time for all inputs.
The internal RC clock source should be used when A/D conversions are performed while the dsPIC30F is in Sleep mode. The internal RC oscillator is selected by setting the ADRC bit (ADCON3<7>). When the ADRC bit is set, the ADCS<5:0> bits have no effect on the A/D operation.
Family Reference Manual 17.8 Selecting Analog Inputs for Sampling All Sample-and-Hold Amplifiers have analog multiplexers (see Figure 17-1) on both their non-inverting and inverting inputs to select which analog input(s) are sampled. Once the sample/convert sequence is specified, the ADCHS bits determine which analog inputs are selected for each sample.
Family Reference Manual 17.8.3 Channel 1, 2 and 3 Input Selection Channel 1, 2 and 3 can sample a subset of the analog input pins. Channel 1, 2 and 3 may select one of two groups of 3 inputs.
The SSRC<2:0> bits (ADCON1<7:5>) select the source of the conversion trigger. Note: The available conversion trigger sources may vary depending on the dsPIC30F device variant. Please refer to the specific device data sheet for the available conversion trigger sources.
Page 396
Family Reference Manual 17.12.2 Clocked Conversion Trigger When SSRC<2:0> = 111, the conversion trigger is under A/D clock control. The SAMC bits (ADCON3<12:8>) select the number of T clock cycles between the start of sampling and the start of conversion. This trigger option provides the fastest conversion rates on multiple channels.
Page 398
Family Reference Manual 17.12.2.2 Multiple Channels with Simultaneous Sampling As shown in Figure 17-8 when using simultaneous sampling, the SAMC value specifies the sampling time. In the example, SAMC specifies a sample time of 3 T . Because automatic sample start is active, sampling will start on all channels after the last conversion ends and will continue for 3 A/D clocks.
Page 400
Family Reference Manual 17.12.3 Event Trigger Conversion Start It is often desirable to synchronize the end of sampling and the start of conversion with some other time event. The A/D module may use one of three sources as a conversion trigger.
Page 402
Family Reference Manual 17.12.3.5 Multiple Channels with Simultaneous Sampling As shown in Figure 17-12 when using simultaneous sampling, the sampling will start on all channels after setting the ASAM bit or when the last conversion ends. Sampling will stop and conversions will start when the conversion trigger occurs.
Page 404
Family Reference Manual 17.12.3.7 Sample Time Considerations for Automatic Sampling/Conversion Sequences Different sample/conversion sequences provide different available sampling times for the S/H channel to acquire the analog signal. The user must ensure the sampling time exceeds the sampling requirements, as outlined in Section 17.16 “A/D Sampling Requirements”.
Family Reference Manual 17.14 Specifying How Conversion Results are Written Into the Buffer As conversions are completed, the module writes the results of the conversions into the A/D result buffer. This buffer is a RAM array of sixteen 10-bit words. The buffer is accessed through 16 address locations within the SFR space named ADCBUF0...ADCBUFF.
Page 412
Family Reference Manual Table 17-4: Converting Three Inputs, Four Times and Four Inputs, One Time/Interrupt CONTROL BITS OPERATION SEQUENCE Sequence Select Sample MUX A Inputs: SMPI<3:0> = 0011 AN4 -> CH0, AN0 -> CH1, AN1 -> CH2, AN2 -> CH3...
Family Reference Manual 17.17 Reading the A/D Result Buffer The RAM is 10-bits wide, but the data is automatically formatted to one of four selectable formats when a read from the buffer is performed. The FORM<1:0> bits (ADCON1<9:8>) select the format.
Family Reference Manual 17.21 Initialization Example 17-7 shows a simple initialization code example for the A/D module. In this particular configuration, all 16 analog input pins, AN0-AN15, are set up as analog inputs. Operation in Idle mode is disabled output data is in unsigned fractional format, and AV...
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
This is the initial released revision of this document. Revision B To reflect editorial and technical content revisions for the dsPIC30F 10-bit A/D Converter module. Revision C This revision incorporates all known errata at the time of this document update.
These voltage reference inputs may be shared with other analog input pins. The actual number of analog input pins and external voltage reference input configuration will depend on the specific dsPIC30F device. Refer to the dsPIC30F device data sheets (DS70082 and DS70083) for further details.
Family Reference Manual 18.2 Control Registers The A/D module has six Control and Status registers. These registers are: • ADCON1: A/D Control Register 1 • ADCON2: A/D Control Register 2 • ADCON3: A/D Control Register 3 • ADCHS: A/D Input Channel Select Register •...
Family Reference Manual 18.4 A/D Terminology and Conversion Sequence Figure 18-2 shows a basic conversion sequence and the terms that are used. A sampling of the analog input pin voltage is performed by sample and hold S/H amplifiers. The S/H amplifiers are also called S/H channels.
The internal RC clock source should be used when A/D conversions are performed while the dsPIC30F is in Sleep mode. The internal RC oscillator is selected by setting the ADRC bit (ADCON3<7>). When the ADRC bit is set, the ADCS<5:0> bits have no effect on the A/D operation.
The SSRC<2:0> bits (ADCON1<7:5>) select the source of the conversion trigger. Note: The available conversion trigger sources may vary depending on the dsPIC30F device variant. Please refer to the specific device data sheet for the available conversion trigger sources.
Page 446
Family Reference Manual 18.11.2 Clocked Conversion Trigger When SSRC<2:0> = 111, the conversion trigger is under A/D clock control. The SAMC bits (ADCON3<12:8>) select the number of T clock cycles between the start of sampling and the start of conversion. After the start of sampling, the module will count a number of T clocks specified by the SAMC bits.
Page 448
Family Reference Manual 18.11.3.4 Synchronizing A/D Operations to Internal or External Events The modes where an external event trigger pulse ends sampling and starts conversion (SSRC = 001, 010, 011) may be used in combination with auto sampling (ASAM = 1) to cause the A/D to synchronize the sample conversion events to the trigger pulse source.
Page 450
Family Reference Manual 18.13.1 Number of Conversions per Interrupt The SMPI<3:0> bits (ADCON2<5:2>) will select how many A/D conversions will take place before the CPU is interrupted. This can vary from 1 sample per interrupt to 16 samples per interrupt.
Page 452
Family Reference Manual Example 18-3: Sampling and Converting a Single Channel Multiple Times Code Example ADPCFG = 0xFFFB; // all PORTB = Digital; RB2 = analog ADCON1 = 0x00E0; // SSRC bit = 111 implies internal // counter ends sampling and starts // converting.
Page 454
Family Reference Manual 18.14.2 Example: A/D Conversions While Scanning Through All Analog Inputs Figure 18-10 and Table 18-2 illustrate a typical setup, where all available analog input channels are sampled and converted. The set CSCNA bit specifies scanning of the A/D inputs to the CH0 positive input.
Family Reference Manual 18.14.3 Example: Using Dual 8-Word Buffers Refer to Subsection 17.15.4 in Section 17. “10-bit A/D Converter” for an example that uses dual buffers. 18.14.4 Example: Using Alternating MUX A, MUX B Input Selections See Subsection 17.15.5 in Section 17. “10-bit A/D Converter” for an example that uses the MUX A and MUX B input selections.
Family Reference Manual 18.17 Transfer Function The ideal transfer function of the A/D converter is shown in Figure 18-13. The difference of the input voltages (V – V ), is compared to the reference (V REFH – V REFL...
Family Reference Manual 18.21 Operation During Sleep and Idle Modes Sleep and Idle modes are useful for minimizing conversion noise because the digital activity of the CPU, buses and other peripherals is minimized. 18.21.1 CPU Sleep Mode Without RC A/D Clock When the device enters Sleep mode, all clock sources to the module are shutdown and stay at logic ‘0’.
Family Reference Manual 18.24 Design Tips Question 1: How can I optimize the system performance of the A/D converter? Answer: Make sure you are meeting all of the timing specifications. If you are turning the module off and on, there is a minimum delay you must wait before taking a sample. If you are...
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
This is the initial released revision of this document. Revision B To reflect editorial and technical content revisions for the dsPIC30F 12-bit A/D Converter module. Revision C This revision incorporates all known errata at the time of this document update.
The Universal Asynchronous Receiver Transmitter (UART) module is one of the serial I/O modules available in the dsPIC30F device family. The UART is a full-duplex asynchronous sys- tem that can communicate with peripheral devices, such as personal computers, RS-232 and RS-485 interfaces.
Page 470
Family Reference Manual Register 19-3: RXREG: UART Receive Register Upper Byte: — — — — — — — URX8 bit 15 bit 8 Lower Byte: URX<7:0> bit 7 bit 0 bit 15-9 Unimplemented: Read as ‘0’ bit 8 URX8: Data bit 8 of the Received Character (in 9-bit mode) bit 7-0 URX<7:0>: Data bits 7-0 of the Received Character...
Family Reference Manual 19.3 UART Baud Rate Generator (BRG) The UART module includes a dedicated 16-bit baud rate generator. The UxBRG register controls the period of a free running 16-bit timer. Equation 19-1 shows the formula for computation of the baud rate.
19.4.3 Alternate UART I/O Pins Some dsPIC30F devices have an alternate set of UART transmit and receive pins that can be used for communications. The alternate UART pins are useful when the primary UART pins are shared by other peripherals. The alternate I/O pins are enabled by setting the ALTIO bit (UxMODE<10>).
Page 476
Family Reference Manual 19.5.1 Transmit Buffer (UxTXB) Each UART has a 4-deep, 9-bit wide FIFO transmit data buffer. The UxTXREG register provides user access to the next available buffer location. The user may write up to 4 words in the buffer.
Family Reference Manual 19.5.4 Transmission of Break Characters Setting the UTXBRK bit (UxSTA<11>) will force the UxTX line to ‘0’. UTXBRK overrides any other transmitter activity. The user should wait for the transmitter to be Idle (TRMT = 1) before setting UTXBRK.
Page 480
Family Reference Manual Figure 19-5: UART Receiver Block Diagram Internal Data Bus Word or Word Read Only Byte Read UxMODE UxSTA URX8 UxRXREG Low Byte Receive Buffer Control – Generate Flags – Generate Interrupt – Shift Data Characters UxRXIF...
Family Reference Manual 19.7 Using the UART for 9-bit Communication A typical multi-processor communication protocol will differentiate between data bytes and address/control bytes. A common scheme is to use a 9th data bit to identify whether a data byte is address or data information.
Family Reference Manual 19.9 Initialization Example 19-2 is an initialization routine for the Transmitter/Receiver in 8-bit mode. Example 19-3 shows an initialization of the Addressable UART in 9-bit Address Detect mode. In both examples, the value to load into the UxBRG register is dependent on the desired baud rate and the device frequency.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
This is the initial released revision of this document. Revision B Revision B has been expanded to include a full description of the dsPIC30F UART module. Revision C This revision incorporates all known errata at the time of this document update.
Motorola's SPI and SIOP interfaces. Depending on the variant, the dsPIC30F family offers one or two SPI modules on a single device. SPI1 and SPI2 are functionally identical. The SPI2 module is available in many of the higher pin count packages (64-pin and higher), while the SPI1 module is available on all devices.
Family Reference Manual 20.2 Status and Control Registers Register 20-2: SPIxSTAT: SPI Status and Control Register Upper Byte: R/W-0 R/W-0 SPIEN — SPISIDL — — — — — bit 15 bit 8 Lower Byte: R/W-0 — SPIROV — —...
Page 498
Family Reference Manual 20.3.2.1 Master Mode The following steps should be taken to set up the SPI module for the Master mode of operation: If using interrupts: • Clear the SPIxIF bit in the respective IFSn register. • Set the SPIxIE bit in the respective IECn register.
Page 500
Family Reference Manual 20.3.2.2 Slave Mode The following steps should be taken to set up the SPI module for the Slave mode of operation: Clear the SPIxBUF register. If using interrupts: • Clear the SPIxIF bit in the respective IFSn register.
Page 504
Family Reference Manual 20.3.3 SPI Error Handling When a new data word has been shifted into SPIxSR and the previous contents of SPIxRXB have not been read by the user software, the SPIROV bit (SPIxSTAT<6>) will be set. The module will not transfer the received data from SPIxSR to SPIxRXB.
Page 506
Family Reference Manual 20.3.5.2 SPIx Buffers in Framed SPI Modes When SPIFSD (SPIxCON<13>) = 0, the SPIx module is in the Frame Master mode of operation. In this mode, the frame sync pulse is initiated by the module when the user software writes the transmit data to SPIxBUF location (thus writing the SPIxTXB register with transmit data).
Page 508
Family Reference Manual 20.3.5.5 SPI Slave Mode and Frame Master Mode This framed SPI mode is enabled by setting the MSTEN (SPIxCON<5>) bit to ‘0’, the FRMEN (SPIxCON<14>) bit to ‘1’ and the SPIFSD (SPIxCON<13>) bit to ‘0’. The input SPI clock will be continuous in Slave mode.
• Power Save modes: These are invoked by the execution of the PWRSAV instruction. There are two Power Save modes supported in the dsPIC30F family of devices. These are specified in the PWRSAV instruction via a parameter. The two modes are: - Sleep mode: Device clock source and entire device is shut down.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Revision A This is the initial released revision of this document. Revision B This revision reflects editorial and technical content changes for the dsPIC30F Serial Peripheral Interface (SPI) module. Revision C There were no technical content revisions to this section of the manual, however, this section was updated to reflect Revision C throughout the manual.
• Where the dsPIC30F acts as a Slave Device • Where the dsPIC30F acts as a Master Device in a Single Master System (Slave may also be active) • Where the dsPIC30F acts as a Master/Slave Device in a Multi-Master System...
The I C bus is a two-wire serial interface. Figure 21-2 is a schematic of a typical I C connection between the dsPIC30F device and a 24LC256 I C serial EEPROM. The I C interface employs a comprehensive protocol to ensure reliable transmission and reception of data.
Page 520
C message is shown in Figure 21-4. In this example, the message will read a specified byte from a 24LC256 I C serial EEPROM. The dsPIC30F device will act as the master and the 24LC256 device will act as the slave.
Page 522
Family Reference Manual Register 21-2 and Register 21-2 define the I C module Control and Status registers, I2CCON and I2CSTAT. The I2CTRN is the register to which transmit data is written. This register is used when the module operates as a master transmitting data to the slave or as a slave sending reply data to the master.
Page 524
Family Reference Manual Register 21-1: I2CCON: I C Control Register (Continued) bit 4 ACKEN: Acknowledge Sequence Enable bit (When operating as I C master. Applicable during master receive.) 1 = Initiate Acknowledge sequence on SDA and SCL pins, and transmit ACKDT data bit Hardware clear at end of master Acknowledge sequence.
Page 526
Family Reference Manual Register 21-2: I2CSTAT: I C Status Register (Continued) bit 4 P: Stop bit 1 = Indicates that a Stop bit has been detected last 0 = Stop bit was not detected last Hardware set or clear when Start, Repeated Start or Stop detected.
Page 528
Family Reference Manual 21.4.3 Setting Baud Rate when Operating as a Bus Master When operating as an I C master, the module must generate the system SCL clock. Generally, C system clocks are specified to be either 100 kHz, 400 kHz or 1 MHz. The system clock rate is specified as the minimum SCL low time plus the minimum SCL high time.
C serial memory. In an I C system, the master controls the sequence of all data communication on the bus. In this example, the dsPIC30F and its I C module have the role of the single master in the system. As the single master, it is responsible for generating the SCL clock and controlling the message protocol.
Page 530
Family Reference Manual 21.5.1 Generating Start Bus Event To initiate a Start event, the software sets the Start enable bit, SEN (I2CCON<0>). Prior to setting the Start bit, the software can check the P (I2CSTAT<4>) status bit to ensure that the bus is in an Idle state.
Page 532
Family Reference Manual 21.5.2.5 TBF Status Flag When transmitting, the TBF bit (I2CSTAT<0>) is set when the CPU writes to I2CTRN and is cleared when all 8 bits are shifted out. 21.5.2.6 IWCOL Status Flag If the software writes the I2CTRN when a transmit is already in progress (i.e., the module is still shifting out a data byte), then IWCOL is set and the contents of the buffer are unchanged (the write doesn’t occur).
Page 536
Family Reference Manual 21.5.5 Generating Stop Bus Event Setting the Stop sequence enable bit, PEN (I2CCON<2>), enables generation of a master Stop sequence. Note: The lower 5 bits of I2CCON must be ‘0’ (master logic inactive) before attempting to set the PEN bit.
Page 538
Family Reference Manual 21.5.7 Building Complete Master Messages As described at the beginning of Section 21.5, the software is responsible for constructing messages with the correct message protocol. The module controls individual portions of the I message protocol, however, sequencing of the components of the protocol to construct a complete message is a software task.
Page 544
Family Reference Manual 21.6.3 Bus Arbitration and Bus Collision Bus arbitration supports multi-master system operation. The wired-and nature of the SDA line permits arbitration. Arbitration takes place when the first master outputs a ‘1’ on SDA by letting SDA float high and, simultaneously, the second master outputs a ‘0’...
In some systems, particularly where multiple processors communicate with each other, the dsPIC30F device may communicate as a slave (see Figure 21-21). When the module is enabled, the slave module is active. The slave may not initiate a message, it can only respond to a message sequence initiated by a master.
Page 548
Family Reference Manual 21.7.3.2 7-bit Address and Slave Read When a slave read is specified by having R/W = 1 in a 7-bit address byte, the process of detecting the device address is similar to that for a slave write (see Figure 21-23). If the addresses match, the following events occur: An ACK is generated.
Page 550
Family Reference Manual 21.7.3.4 General Call Operation The addressing procedure for the I C bus is such that the first byte after a Start condition usually determines which slave device the master is addressing. The exception is the general call address, which can address all devices.
Page 552
Family Reference Manual 21.7.4.1 Acknowledge Generation Normally, the slave module will Acknowledge all received bytes by sending an ACK on the ninth SCL clock. If the receive buffer is overrun, the slave module does not generate this ACK. Overrun is indicated if either (or both): The buffer full bit, RBF (I2CSTAT<1>), was set before the transfer was received.
Page 558
Family Reference Manual 21.7.5 Sending Data to a Master Device When the R/W bit of the incoming device address byte is one and an address match occurs, the R_W bit (I2CSTAT<2>) is set. At this point, the master device is expecting the slave to respond by sending a byte of data.
Page 562
Family Reference Manual 21.8.1 Integrated Signal Conditioning The SCL and SDA pins have an input glitch filter. The I C bus requires this filter in both the 100 kHz and 400 kHz systems. When operating on a 400 kHz bus, the I C specification requires a slew rate control of the device pin output.
Family Reference Manual 21.11 Design Tips Question 1: I’m operating as a bus master and transmitting data, however, slave and receive interrupts are also occurring. Answer: The master and slave circuits are independent. The slave module will receive events from the bus sent by the master.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Revision History Revision A This is the initial released revision of this document. Revision B This revision has been expanded to contain a full description of the dsPIC30F Inter-Integrated Circuit (I C) module. Revision C This revision incorporates all known errata at the time of this document update.
The data word length for the DCI is programmable up to 16 bits to match the data size of the dsPIC30F CPU. However, many codecs have data word sizes greater than 16 bits. Long data word lengths can be supported by the DCI. The DCI is configured to transmit/receive the long word in multiple 16-bit time slots.
Page 572
Family Reference Manual Register 22-4: DCISTAT Upper Byte: — — — — SLOT<3:0> bit 15 bit 8 Lower Byte: — — — — RFUL TUNF TMPTY bit 7 bit 0 bit 15-12 Reserved: Read as ‘0’ bit 11-8 SLOT<3:0>: DCI Slot Status bits...
Family Reference Manual 22.3 Codec Interface Basics and Terminology The interface protocols supported by the DCI require the use of a Frame Synchronization (FS) signal to initiate a data transfer between two devices. In most cases, the rising edge of FS starts a new data transfer.
Family Reference Manual The FS pulse has a minimum active time of one SCK period so the slave device can detect the start of the data frame. The duty cycle of the FS pulse may vary depending on the specific pro- tocol that is used to mark certain boundaries in the data frame.
Page 577
CSCKD control bit, DCICON1<10>. When the CSCK pin is configured as an output (CSCKD = 0), the serial clock is derived from the dsPIC30F system clock source and supplied to external devices by the DCI. When the CSCK pin is configured as an input (CSCKD = 1), the serial clock must be provided by an external device.
Page 578
Family Reference Manual 22.4.3 Bit Clock Generator The DCI module has a dedicated 12-bit time base that produces the bit clock. The bit clock rate (period) is set by writing a non-zero 12-bit value to the BCG<11:0> control bits (DCICON3<11:0>).
Page 580
If the CSDOM bit is set, the CSDO pin will be tri-stated during unused time slot periods. This mode allows multiple dsPIC30F devices to share the same CSDO line in a multiplexed application. Each device on the CSDO line is configured so that it will only transmit data during specific time slots.
Page 582
Family Reference Manual 22.4.14 Transmit Status Bits There are two transmit status bits, TMPTY and TUNF. The transmit status bits only indicate status for register locations that are used by the module. If the buffer length is set to less than four words, for example, the unused register locations will not affect the transmit status bits.
Page 584
Family Reference Manual 22.5.1.1 DCI Start-up and Data Buffering Data transfers are begun by setting the DCIEN control bit (DCICON1<15>). Prior to this, the DCI Control registers should have been initialized for the desired operating mode. (See Section 22.5.4 “Multi-Channel Operation”, Section 22.5.5 “I...
Page 586
Family Reference Manual 22.5.2 Master vs. Slave Operation The DCI can be configured for master or slave operation. The master device generates the frame sync signal to initiate a data transfer. The Operating mode (master or slave) is selected by the COFSD control bit (DCICON1<8>).
Page 588
Family Reference Manual Write the COFSG<3:0> control bits (DCICON2<8:5>) for the desired number of data words per frame. The WS and COFSG control bits will determine the length of the data frame in CSCK cycles (see Section 22.4.7 “Frame Synchronization Generator”) COFSG<3:0>...
Page 590
Family Reference Manual 22.5.5.2 How to Determine the I S Channel Alignment Most I S codecs support two channels of data and the level of the frame sync signal indicates the channel that is transferred during that half of the data frame. The COFS pin can be polled in software using its associated Port register to determine the present level on the pin in the DCI Interrupt Service Routine.
Family Reference Manual Clear the CSDOM control bit (DCICON1<6>). Write the TSCON and RSCON registers to determine which data time slots in the frame are to be transmitted and received, respectively. This will depend on which data time slots in the AC-Link protocol will be used.
Family Reference Manual 22.8 Design Tips Question 1: Can the DCI support data word lengths greater than 16-bits? Answer: Yes. A long data word can be transmitted and received using multiple Transmit and Receive registers. See Section 22.5.3 “Data Packing for Long Data Word Support” for details.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Revision A This is the initial released revision of this document. Revision B This revision incorporates additional technical content and changes for the dsPIC30F Data Converter Interface (DCI) module. Revision C This revision incorporates all known errata at the time of this document update.
Family Reference Manual 23.1 Introduction The Controller Area Network (CAN) module is a serial interface useful for communicating with other peripherals or microcontroller devices. This interface/protocol was designed to allow communications within noisy environments. Figure 23-1 shows an example CAN bus network.
Page 606
Family Reference Manual 23.2.3 CAN Receive Buffer Registers This subsection shows the Receive buffer registers with their associated control registers. Register 23-7: CiRX0CON: Receive Buffer 0 Status and Control Register Upper Byte: — — — — — — —...
Page 616
Family Reference Manual 23.2.7 CAN Module Error Count Register This subsection describes the CAN Module Transmission/Reception Error Count register. The various error status flags are present in the CAN Interrupt Flag Register. Register 23-21: CiEC: Transmit/Receive Error Count Upper Byte: TERRCNT<7:0>...
Family Reference Manual 23.3 CAN Module Features The CAN module is a communication controller implementing the CAN 2.0A/B protocol as defined in the BOSCH specification. The module will support CAN 1.2, CAN 2.0A, CAN 2.0B Passive and CAN 2.0B Active versions of the protocol. The module implementation is a Full CAN system.
Page 628
Family Reference Manual 23.4.1 CAN Message Formats The CAN protocol engine handles all functions for receiving and transmitting messages on the CAN bus. Messages are transmitted by first loading the appropriate data registers. Status and errors can be checked by reading the appropriate registers. Any message detected on the CAN bus is checked for errors and then matched against filters to see if it should be received and stored in one of the two receive registers.
Family Reference Manual 23.5 CAN Module Operation Modes The CAN Module can operate in one of several Operation modes selected by the user. These modes include: • Normal Operation mode • Disable mode • Loopback mode • Listen Only mode •...
Page 636
Family Reference Manual 23.5.5 Configuration Mode In the Configuration mode, the module will not transmit or receive. The error counters are cleared and the interrupt flags remain unchanged. The programmer will have access to configuration registers that are access restricted in other modes.
Page 638
Family Reference Manual 23.6.1.1 Receive Buffer Priority To provide flexibility, there are several acceptance filters corresponding to each receive buffer. There is also an implied priority to the receive buffers. RXB0 is the higher priority buffer and has 2 message acceptance filters associated with it. RXB1 is the lower priority buffer and has 4 acceptance filters associated with it.
Page 640
Family Reference Manual 23.6.2 Message Acceptance Filters The message acceptance filters and masks are used to determine if a message in the message assembly buffer should be loaded into either of the receive buffers. Once a valid message has been received into the Message Assembly Buffer (MAB), the identifier fields of the message are compared to the filter values.
Page 642
Family Reference Manual 23.6.3 Receiver Overrun An overrun condition occurs when the Message Assembly Buffer (MAB) has assembled a valid received message, the message is accepted through the acceptance filters, and when the receive buffer associated with the filter has not been designated as clear of the previous message.
Page 644
Family Reference Manual 23.6.6 Receive Interrupts Several Interrupts are linked to the message reception. The receive interrupts can be broken up into two separate groups: • Receive Error Interrupts • Receive interrupts 23.6.6.1 Receive Interrupt A message has been successfully received and loaded into one of the receive buffers. This inter- rupt is activated immediately after receiving the End-Of-Frame (EOF) field.
Page 646
Family Reference Manual 23.6.6.3 Receive Error Interrupts A receive error interrupt will be indicated by the ERRIF bit (CiINTF<5>). This bit shows that an error condition occurred. The source of the error can be determined by checking the bits in the CAN Interrupt Status Register CiINTF.
Page 648
Family Reference Manual Figure 23-12: Transmit Buffers TXB0 TXB1 TXB2 Message Queue Control Transmit Byte Sequencer 23.7.3 Transmit Message Priority Transmit priority is a prioritization within each node of the pending transmittable messages. Prior to sending the SOF (Start-Of-Frame), the priorities of all buffers ready for transmission are compared.
Page 650
Family Reference Manual Figure 23-14: Abort All Messages CAN bus CiTX ABAT TXREQ TXnIF TXABT - Processor sets TXREQ while module receiving/transmitting message. Module continues with CAN message. - Processor sets ABAT while module looking for 11 recessive bits. Module clears TXREQ bits.
Page 652
Family Reference Manual Figure 23-17: Transmit Flowchart START The message transmission sequence begins when the device determines that the TXREQ for any of the Transmit registers has been set. Are any TXREQ bits = 1 Clearing the TXREQ bit while it is set, or setting...
Page 654
Family Reference Manual 23.7.8 Transmission Errors The CAN module will detect the following transmission errors: • Acknowledge Error • Form Error • Bit Error These transmission errors will not necessarily generate an interrupt but are indicated by the transmission error counter. However, each of these errors will cause the transmission error counter to be incremented by one.
Family Reference Manual 23.7.9.2 Transmission Error Interrupts A transmission error interrupt will be indicated by the ERRIF flag. This flag shows that an error condition occurred. The source of the error can be determined by checking the error flags in the CAN Interrupt Status register CiINTF.
Family Reference Manual 23.9 CAN Baud Rate All nodes on any particular CAN bus must have the same nominal bit rate. The CAN bus uses NRZ coding which does not encode a clock. Therefore the receivers independent clock must be recovered by the receiving nodes and synchronized to the transmitters clock.
Page 660
Family Reference Manual 23.9.3 Propagation Segment This part of the bit time is used to compensate physical delay times within the network. These delay times consist of the signal propagation time on the bus line and the internal delay time of the nodes.
Family Reference Manual 23.9.7 Programming Time Segments Some requirements for programming of the time segments are as follows: • Propagation Segment + Phase1 Segment > = Phase2 Segment • Phase2 Segment > Synchronous Jump Width Typically, the sampling of the bit should take place at about 60-70% through the bit time, depending on the system parameters.
Family Reference Manual 23.13 Operation in CPU Power Saving Modes 23.13.1 Operation in Sleep Mode Sleep mode is entered by executing a PWRSAV #0 instruction. This will stop the crystal oscillator and shut down all system clocks. The user should ensure that the module is not active when the CPU goes into Sleep mode.
Family Reference Manual 23.14 CAN Protocol Overview The Controller Area Network (CAN) is a serial communications protocol which efficiently supports distributed real-time control with a very high level of robustness. The CAN Protocol is fully defined by Robert Bosch GmbH, in the CAN Specification V2.0B from 1991.
Page 668
Family Reference Manual The LLC sub layer is concerned with Message Filtering, Overload Notification and Error Recovery Management. The scope of the LLC sub layer is: • To provide services for data transfer and for remote data request. • To decide which messages received by the LLC sub layer are actually to be accepted.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Family Reference Manual 24.1 Introduction The device configuration registers allow each user to customize certain aspects of the device to fit the needs of the application. Device configuration registers are non-volatile memory locations in the program memory map that hold settings for the dsPIC device during power-down. The configuration registers hold global setup information for the device, such as the oscillator source, Watchdog Timer mode and code protection settings.
Family Reference Manual 24.4 Device Identification Registers The dsPIC30F devices have two sets of registers located in configuration space that provide identification information. 24.4.1 Device ID (DEVID) Registers The configuration memory space locations 0xFF0000 and 0xFF0002 are used to store a read only Device ID number that is set when the device is manufactured.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
Revision A This is the initial released revision of this document. Revision B This revision incorporates technical content changes for the dsPIC30F Device Configuration module. Revision C This revision incorporates all known errata at the time of this document update.
Family Reference Manual Note: Some development tools described in this section are not available at the time of this writing, however they are currently under development. Some of the product details may change. Please check the Microchip web site or your local Microchip sales office for the most current information and the availability of each product.
Page 685
Microchip sales office for availability of the MPLAB C30 C compiler. The Microchip Technology MPLAB C30 C compiler is a complete, easy-to-use language product. It allows dsPIC applications codes to be written in high level C language and then be fully converted into machine-object code for programming of the microcontroller.
Page 686
Family Reference Manual 25.2.4 MPLAB ICE 4000 In-Circuit Emulator Note: This product is currently under development at the time of this writing. Some of the product details may change. Please refer to the Microchip web site or your local Microchip sales office for the most current information and the availability of this product.
Page 687
In Stand-alone mode, the PRO MATE II device programmer will be able to read, verify or program PICmicro and dsPIC30F devices. It will also be able to set code protection in this mode. PRO MATE II features will include: •...
Microchip sales office for the most current information and the availability of these products. In addition to the Microchip MPLAB C30 C Compiler, the dsPIC30F will be supported by ANSI C compilers developed by IAR, HI-TECH and Custom Computer Services (CCS).
Page 689
• ceil(), floor() • fmod(), frexp() The math function routines will be developed and optimized in dsPIC30F assembly language and will be callable from both assembly and C language. Floating point and double precision versions of each function shall be provided. The Microchip MPLAB C30 and IAR C compilers will be supported.
Page 690
Microchip sales office for the most current information and the availability of this product. Microchip will offer a peripheral driver library that will support the setup and control of dsPIC30F hardware peripherals, including, but not limited to: • Analog-to-Digital Converter •...
Page 691
Microchip sales office for the most current information and the availability of this product. Microchip will offer a CAN driver library, which will support the dsPIC30F CAN peripheral. Some of the CAN functions which will be supported are: • Initialize CAN Module •...
Page 692
Operating Systems for the vehicle software standard OSEK/VDX will be developed for support of the dsPIC30F product family. The functionality of OSEK, “Offene Systeme und deren Schnittstellen für die Elektronik im Kraftfahrzeug” (Open systems and the corresponding interfaces for automotive electronics), is harmonized with VDX “Vehicle Distributed eXecutive”...
Each board will feature key dsPIC30F peripherals and support Microchip’s MPLAB In-Circuit Debugger (ICD 2) tool for cost effective debugging and programming of the dsPIC30F device. The three initial boards to be provided are: •...
Page 694
The dsPIC30F general purpose development board will provide the application designer with a low cost development tool in which to become familiar with the dsPIC30F 16-bit architecture, high performance peripherals and powerful instruction set. The development board will serve as an ideal prototyping tool in which to quickly develop and validate key design requirements.
Page 695
400 volts and up to 1 kW power output. The high voltage module will have an active power factor correction circuit that will be controlled by the dsPIC30F device. This power module is intended for AC induction motor and power inverter applications.
Page 696
Microchip sales office for the most current information and the availability of this product. The dsPIC30F connectivity development board will provide the application developer a basic platform for developing and evaluating various connectivity solutions, implementing TCP/IP protocol layers combined with V.22/V.22bis and V.32 (non-trellis coding) ITU specifications, across PSTN or Ethernet communication channels.
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the dsPIC30F Product Family, but the concepts are pertinent and could be used with modification and possible limitations. The current...
25.6 Revision History Revision A This is the initial released revision of the dsPIC30F Development Tool Support description. Revision B There were no technical content or editorial revisions to this section of the manual, however, this section was updated to reflect Revision B throughout the manual.
Family Reference Manual APPENDIX A: I C OVERVIEW This appendix provides an overview of the Inter-Integrated Circuit (I C™) bus, with Subsection A.2 “Addressing I C Devices” discussing the operation of the SSP modules in I C mode. The I C bus is a two-wire serial interface.
Page 702
Family Reference Manual Addressing I C Devices There are two address formats. The simplest is the 7-bit address format with a R/W bit (Figure A-2). The more complex is the 10-bit address with a R/W bit (Figure A-3). For 10-bit address format, two bytes must be transmitted.
Page 704
Family Reference Manual Figure A-6 and Figure A-7 illustrate master-transmitter and master-receiver data transfer sequences. Figure A-6: Master-Transmitter Sequence For 7-bit address: Slave Address R/W A Data A Data A/A P '0' (write) data transferred (n bytes - acknowledge) A master transmitter addresses a slave receiver with a 7-bit address.
Page 706
Family Reference Manual Multi-master The I C protocol allows a system to have more than one master. This is called a multi-master system. When two or more masters try to transfer data at the same time, arbitration and synchronization occur.
Page 708
Family Reference Manual Table A-2 and Table A-3 show the specifications of a compliant I C bus. The column titled, Parameter No., is provided to ease the user’s correlation to the corresponding parameter in the device data sheet. Figure A-11 and Figure A-12 show these times on the appropriate waveforms.
Family Reference Manual APPENDIX B: CAN OVERVIEW This appendix provides an overview of the Controller Area Network (CAN) bus. The CAN Section of this reference manual discusses the implementation of the CAN protocol for that hardware module. CAN Bus Background The Controller Area Network (CAN) is a serial communications protocol which efficiently supports distributed real-time control with a very high level of security.
Page 712
Family Reference Manual Full CAN devices do the whole bus protocol in hardware, including the acceptance filtering and the message management. They contain several so called message objects which handle the identifier, the data, the direction (receive or transmit) and the information Standard CAN/Extended CAN.
Page 714
Family Reference Manual CAN Bus Features CAN has the following properties: • Prioritization of messages • Latency times ensured • Configuration flexibility • Multi-cast reception with time synchronization • System wide data consistency • Multi-master • Error detection and signaling •...
Page 716
Family Reference Manual Frame Types B.6.1 Standard Data Frame A data frame is generated by a node when the node wishes to transmit data. The Standard CAN Data Frame is shown in Figure B-2. In common with all other frames, the frame begins with a Start-Of-Frame bit (SOF –...
Page 724
Family Reference Manual Figure C-1: S Bus Connections Transmitter master S Transmitter S Receiver S Transmitter S Receiver Receiver master S Controller S Transmitter S Receiver Separate controller as master Figure C-2: S Interface Timing Diagram Note: A 5 bit transfer is shown here for illustration purposes. The I S protocol does not specify word length –...
Page 726
Family Reference Manual C.4.2 Slot #0, TAG Frame Slot #0 is commonly called the ‘tag frame’. The tag frame has a bit location for each data time slot in the AC-Link protocol. These bits are used to specify which time slots in a frame are valid for use by the controller.
Page 728
Family Reference Manual Figure C-4: AC-Link Data Frame SYNC Slot3 Slot 4 Slot 10 Slot 11 Slot 12 Command Command SDATA_OUT Left PCM Right PCM Line 2 Handset Codec I/O Frame Address Data Data Data Control Slot3 Slot 4...
Page 731
Family Reference Manual Numerics Low Voltage Detect (LVD) ......... 9-3 Oscillator System............7-3 10-bit Address Mode ............21-35 Output Compare Module ......... 14-2 12-Bit A/D Reset System ............8-2 ADCHS ............17-4, 18-4 Shared Port Structure..........11-4 ADPCFG ............17-4, 18-4 Type A Timer ............
Page 732
BOR and POR ............24-7 DSP Filter Design Software Utility ........25-8 General Code Segment ...........24-7 dsPIC Language Suite............. 25-3 Motor Control PWM Module........24-7 dsPIC30F Hardware Development Boards....25-11 Oscillator ..............24-7 Connection Considerations ..........17-47 Connectivity Development Board........25-14 Equations Control Register Descriptions ..........3-18 Calculating the PWM Period........
Page 733
Family Reference Manual Bus Arbitration and Bus Collision......21-30 Interrupt Latency Bus Collision During a Repeated One-Cycle Instructions ..........6-11 Start Condition ..........21-31 Two-Cycle Instructions ..........6-12 Bus Collision During a Start Condition....21-31 Interrupt Operation ............6-9 Bus Collision During a Stop Condition ....
Page 734
With Fault Protection Input Pin ......14-19 Oscillator Switching Sequence.........7-23 PWM Duty Cycle Comparison Units ......15-20 OSEK Operating Systems..........25-10 PWM Fault Pins ............. 15-32 Other dsPIC30F CPU Control Registers......2-16 PWM Output and Polarity Control........15-32 DISICNT..............2-16 PWM Output Override ........... 15-29 MODCON..............2-16 PWM Special Event Trigger...........
Page 735
Family Reference Manual ADCON1 (A/D Control) Register1..17-5, 18-5, 21-11 FBORPOR (BOR and POR ADCON1 A/D Control 1 ........17-5, 17-6 Configuration Register)........24-5 ADCON1 A/D Control 1 (12-bit) ....... 18-5 FBORPOR BOR and POR Device Configuration.. 15-15 ADCON2 (A/D Control) Register2....17-7, 18-6 FGS (General Code Segment ADCON2 A/D Control 2 ...........
Page 737
Family Reference Manual Using QEI as Alternate 16-bit Timer/Counter ....16-16 Type A Timer ..............12-3 Type B Timer ..............12-4 Using Table Read Instructions........... 5-3 Type C Timer ..............12-5 Byte Mode ..............5-3 Word Mode ..............5-3 Using Table Write Instructions...........
Page 738
Fax: 86-532-502-7205 Tel: 765-864-8360 Fax: 765-864-8387 Los Angeles Mission Viejo, CA Tel: 949-462-9523 Fax: 949-462-9608 San Jose Mountain View, CA Tel: 650-215-1444 Fax: 650-961-0286 Toronto Mississauga, Ontario, Canada Tel: 905-673-0699 Fax: 905-673-6509 10/20/04 2004 Microchip Technology Inc. DS70046C-page 8...
Need help?
Do you have a question about the dsPIC30F and is the answer not in the manual?
Questions and answers