Part Number Hot Search : 
2SK23 MD90FF25 6AGPA P1214 1N5732D XC61C LM290 RS4937
Product Description
Full Text Search
 

To Download PIC18LF26J50T-ISO Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2009 microchip technology inc. preliminary ds39931b pic18f46j50 family data sheet 28/44-pin, low-power, high-performance usb microcontrollers with nanowatt xlp? technology
ds39931b-page ii preliminary ? 2009 microchip technology inc. information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates. it is your responsibility to ensure that your application meets with your specifications. microchip makes no representations or warranties of any kind whether express or implied, written or oral, statutory or otherwise, related to the information, including but not limited to its condition, quality, performance, merchantability or fitness for purpose . microchip disclaims all liability arising from this information and its use. use of microchip devices in life support and/or safety applications is entirely at the buyer?s risk, and the buyer agrees to defend, indemnify and hold harmless microchip from any and all damages, claims, suits, or expenses resulting from such use. no licenses are conveyed, implicitly or otherwise, under any microchip intellectual property rights. trademarks the microchip name and logo, the microchip logo, accuron, dspic, k ee l oq , k ee l oq logo, mplab, pic, picmicro, picstart, rfpic, smartshunt and uni/o are registered trademarks of microchip tec hnology incorporated in the u.s.a. and other countries. filterlab, linear active thermistor, mxdev, mxlab, seeval, smartsensor and the embedded control solutions company are registered trademarks of microchip technology incorporated in the u.s.a. analog-for-the-digital age, appl ication maestro, codeguard, dspicdem, dspicdem.net, dspicworks, dsspeak, ecan, economonitor, fansense, in-circuit serial programming, icsp, icepic, mindi, miwi, mpasm, mplab certified logo, mplib, mplink, mtouch, nanowatt xlp, pickit, picdem, picdem.net, pictail, pic 32 logo, powercal, powerinfo, powermate, powertool, real ice, rflab, select mode, total endurance, tsha rc, wiperlock and zena are trademarks of microchip tec hnology 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. ? 2009, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. note the following details of the code protection feature on microchip devices: ? microchip products meet the specification cont ained in their particular microchip data sheet. ? microchip believes that its family of products is one of the mo st secure families of its kind on the market today, when used i n the intended manner and under normal conditions. ? there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip produc ts in a manner outside the operating specifications contained in microchip?s data sheets. most likely, the person doing so is engaged in theft of intellectual property. ? microchip is willing to work with the customer who is concerned about the integrity of their code. ? neither microchip nor any other semiconductor manufacturer c an guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are co mmitted to continuously improvi ng the code protection features of our products. attempts to break microchip?s c ode protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received iso/ts-16949:2002 certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona; gresham, oregon and design centers in california and india. the company?s quality system processes and procedures are for its pic ? mcus and dspic ? dscs, k ee l oq ? code hopping devices, serial eeproms, microperipherals, nonvolatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001:2000 certified.
? 2009 microchip technology inc. preliminary ds39931b-page 1 pic18f46j50 family power management features with nanowatt xlp? for extreme low-power: ? deep sleep mode: cpu off, peripherals off, currents down to 13 na and 850 na with rtcc - able to wake-up on external triggers, programmable wdt or rtcc alarm - ultra low-power wake-up (ulpwu) ? sleep mode: cpu off, peripherals off, sram on, fast wake-up, currents down to 105 na typical ? idle: cpu off, peripherals on, currents down to 2.3 a typical ? run: cpu on, peripherals on, currents down to 6.2 a typical ? timer1 oscillator w/rtcc: 1 a, 32 khz typical ? watchdog timer: 1.3 a typical special microcontroller features: ? 5.5v tolerant inputs (digital only pins) ? low-power, high-speed cmos flash technology ? c compiler optimized architecture for re-entrant code ? priority levels for interrupts ? self-programmable under software control ? 8 x 8 single-cycle hardware multiplier ? extended watchdog timer (wdt): - programmable period from 4 ms to 131s ? single-supply in-circuit serial programming? (icsp?) via two pins ? in-circuit debug (icd) with three breakpoints via two pins ? operating voltage range of 2.0v to 3.6v ? on-chip 2.5v regulator ? flash program memory of 10,000 erase/write cycles minimum and 20-year data retention universal serial bus (usb) features ? usb v2.0 compliant ? full speed (12 mbps) and low speed (1.5 mbps) ? supports control, interrupt, isochronous and bulk transfers ? supports up to 32 endpoints (16 bidirectional) ? usb module can use any ram location on the device as usb endpoint buffers ? on-chip usb transceiver with crystal-less operation flexible oscillator structure: ? high-precision internal oscillator (0.15% typ.) for usb ? two external clock modes, up to 48 mhz (12 mips) ? internal 31 khz oscillator, internal oscillators tunable at 31 khz and 8 mhz or 48 mhz with pll ? secondary oscillator using timer1 @ 32 khz ? fail-safe clock monitor: - allows for safe shutdown if any clock stops ? two-speed oscillator start-up ? programmable reference clock output generator peripheral highlights: ? peripheral pin select: - allows independent i/o mapping of many peripherals - continuous hardware integrity checking and safety interlocks prevent unintentional configuration changes ? hardware real-time clock and calendar (rtcc): - provides clock, calendar and alarm functions ? high-current sink/source 25 ma/25 ma (portb and portc) ? four programmable external interrupts ? four input change interrupts ? two enhanced capture/compare/pwm (eccp) modules: - one, two or four pwm outputs - selectable polarity - programmable dead time - auto-shutdown and auto-restart - pulse steering control ? two master synchronous serial port (mssp) modules supporting three-wire spi (all four modes) and i 2 c? master and slave modes ? full-duplex master/slave spi dma engine ? 8-bit parallel master port/enhanced parallel slave port ? two-rail ? rail analog comparators with input multiplexing ? 10-bit, up to 13-channel analog-to-digital (a/d) converter module: - auto-acquisition capability - conversion available during sleep - self-calibration ? high/low-voltage detect module ? charge time measurement unit (ctmu): - supports capacitive touch sensing for touch screens and capacitive switches - provides a precise resolution time measure- ment for both flow measurement and simple temperature sensing ? two enhanced usart modules: - supports rs-485, rs-232 and lin/j2602 - auto-wake-up on start bit ? auto-baud detect 28/44-pin, low-power, high-performance usb microcontrollers
pic18f46j50 family ds39931b-page 2 preliminary ? 2009 microchip technology inc. pic18f/lf (1) device pins program memory (bytes) sram (bytes) remappable pins timers 8/16-bit eccp/(pwm) eusart mssp 10-bit a/d (ch) comparators deep sleep pmp/psp ctmu rtcc usb spi w/dma i 2 c? pic18f24j50 28 16k 3776 16 2/3 2 2 2 y y 10 2 y n y y y pic18f25j50 28 32k 3776 16 2/3 2 2 2 y y 10 2 y n y y y pic18f26j50 28 64k 3776 16 2/3 2 2 2 y y 10 2 y n y y y pic18f44j50 44 16k 3776 22 2/3 2 2 2 y y 13 2 y y y y y pic18f45j50 44 32k 3776 22 2/3 2 2 2 y y 13 2 y y y y y pic18f46j50 44 64k 3776 22 2/3 2 2 2 y y 13 2 y y y y y pic18lf24j50 28 16k 3776 16 2/3 2 2 2 y y 10 2 n n y y y pic18lf25j50 28 32k 3776 16 2/3 2 2 2 y y 10 2 n nyyy pic18lf26j50 28 64k 3776 16 2/3 2 2 2 y y 10 2 n nyyy pic18lf44j50 44 16k 3776 22 2/3 2 2 2 y y 13 2 n yyyy pic18lf45j50 44 32k 3776 22 2/3 2 2 2 y y 13 2 n yyyy pic18lf46j50 44 64k 3776 22 2/3 2 2 2 y y 13 2 n yyyy note 1: see section 1.3 ?details on individual family devices? , section 3.6 ?deep sleep mode? and section 26.3 ?on-chip voltage regulator? for details describing the functional differences between pic18f and pic18lf variants in this device family.
? 2009 microchip technology inc. preliminary ds39931b-page 3 pic18f46j50 family pin diagrams pic18f2xj50 10 11 2 3 4 5 6 1 8 7 9 12 13 14 15 16 17 18 19 20 23 24 25 26 27 28 22 21 mclr ra0/an0/c1ina/ulpwu/ rp0 ra1/an1/c2ina/ rp1 ra2/an2/v ref -/cv ref /c2inb ra3/an3/v ref +/c1inb v ddcore /v cap (2) ra5/an4/ss1 /hlvdin/rcv/ rp2 v ss osc1/clki/ra7 osc2/clko/ra6 rc0/t1oso/t1cki/ rp11 rc1/t1osi/uoe / rp12 rc2/an11/ctpls/ rp13 v usb rb7/kbi3/pgd/ rp10 rb6/kbi2/pgc/ rp9 rb5/kbi1/sdi1/sda1/ rp8 rb4/kbi0/sck1/scl1/ rp7 rb3/an9/ctedg2/vpo/ rp6 rb2/an8/ctedg1/vmo/refo/ rp5 rb1/an10/rtcc/ rp4 rb0/an12/int0/ rp3 v dd v ss rc7/rx1/dt1/sdo1/ rp18 rc6/tx1/ck1/ rp17 rc5/d+/vp rc4/d-/vm 28-pin spdip/soic/ssop (1) legend: rpn represents remappable pins. note 1: some input and output functions are routed through the peripheral pin select (pps) module and can be dynamically assigned to any of the rpn pins. for a list of the input and output functions, see table 9-13 and table 9-14, respectively. for details on configuring the pps module, see section 9.7 ?peripheral pin select (pps)? . 2: see section 26.3 ?on-chip voltage regulator? for details on how to connect the v ddcore /v cap pin. 3: for the qfn package, it is recommended that the bottom pad be connected to v ss . 28-pin qfn (1,3) rc0/t1oso/t1cki/ rp11 rb7/kbi3/pgd/ rp10 rb6/kbi2/pgc/ rp9 rb5/kbi1/sdi1/sda1/ rp8 rb4/kbi0/sck1/scl1/ rp7 rb3/an9/ctedg2/vpo/ rp6 rb2/an8/ctedg1/vmo/refo/ rp5 rb1/an10/rtcc/ rp4 rb0/an12/int0/ rp3 v dd v ss rc7/rx1/dt1/sdo1/ rp18 rc6/tx1/ck1/ rp17 rc5/d+/vp rc4/d-/vm mclr ra0/an0/c1ina/ulpwu/ rp0 ra1/an1/c2ina/ rp1 ra2/an2/v ref -/cv ref /c2inb ra3/an3/v ref +/c1inb v ddcore /v cap (2) ra5/an4/ss1 /hlvdin/rcv/ rp2 v ss osc1/clki/ra7 osc2/clko/ra6 rc1/t1osi/uoe / rp12 rc2/an11/ctpls/ rp13 v usb = pins are up to 5.5v tolerant 10 11 2 3 6 1 18 19 20 21 22 12 13 14 15 8 7 16 17 23 24 25 26 27 28 9 pic18f2xj50 5 4
pic18f46j50 family ds39931b-page 4 preliminary ? 2009 microchip technology inc. pin diagrams (continued) 44-pin qfn (1,3) ra3/an3/v ref +/c1inb ra2/an2/v ref -/cv ref -/c2inb ra1/an1/c2ina/pma7/ rp1 ra0/an0/c1ina/ulpwu/pma6/ rp0 mclr rb7/kbi3/pgd/ rp10 rb6/kbi2/pgc/ rp9 rb5/pma0/kbi1/sdi1/sda1/ rp8 rb4/pma1/kbi0/sck1/scl1/ rp7 nc rc6/pma5/tx1/ck1/ rp17 rc5/d+/vp rc4/d-/vm rd3/pmd3/ rp20 rd2/pmd2/ rp19 rd1/pmd1/sda2 rd0/pmd0/scl2 v usb rc2/an11/ctpls/ rp13 rc1/t1osi/u oe / rp12 rc0/t1oso/t1cki/ rp11 osc2/clko/ra6 osc1/clki/ra7 v ss av dd re2/an7/pmcs re1/an6/pmwr re0/an5/pmrd ra5/an4/ss1 /hlvdin/rcv/ rp2 v ddcore /v cap (2) rc7/pma4/rx1/dt1/sdo1/ rp18 rd4/pmd4/ rp21 rd5/pmd5/ rp22 rd6/pmd6/ rp23 v ss v dd rb0/an12/int0/ rp3 rb1/an10/pmbe/rtcc/ rp4 rb2/an8/ctedg1/pma3/vmo/refo/ rp5 rb3/an9/ctedg2/pma2/vpo/ rp6 rd7/pmd7/ rp24 av ss v dd av dd legend: rpn represents remappable pins. note 1: some input and output functions are routed through the peripheral pin select (pps) module and can be dynamically assigned to any of the rpn pins. for a list of the input and output functions, see table 9-13 and table 9-14, respectively. for details on configuring the pps module, see section 9.7 ?peripheral pin select (pps)? . 2: see section 26.3 ?on-chip voltage regulator? for details on how to connect the v ddcore /v cap pin. 3: for the qfn package, it is recommended that the bottom pad be connected to v ss . = pins are up to 5.5v tolerant 10 11 2 3 6 1 18 19 20 21 22 12 13 14 15 38 8 7 44 43 42 41 40 39 16 17 29 30 31 32 33 23 24 25 26 27 28 36 34 35 9 37 5 4 pic18f4xj50
? 2009 microchip technology inc. preliminary ds39931b-page 5 pic18f46j50 family pin diagrams (continued) 10 11 2 3 6 1 18 19 20 21 22 12 13 14 15 38 8 7 44 43 42 41 40 39 16 17 29 30 31 32 33 23 24 25 26 27 28 36 34 35 9 pic18f4xj50 37 ra3/an3/v ref +/c1inb ra2/an2/v ref -/cv ref -/c2inb ra1/an1/c2ina/pma7/ rp1 ra0/an0/c1ina/ulpwu/pma6/ rp0 mclr nc rb7/kbi3/pgd/ rp10 rb6/kbi2/pgc/ rp9 rb5/pma0/kbi1/sdi1/sda1/ rp8 rb4/pma1/kbi0/sck1/scl1/ rp7 nc rc6/pma5/tx1/ck1/ rp17 rc5/d+/vp rc4/d-/vm rd3/pmd3/ rp20 rd2/pmd2/ rp19 rd1/pmd1/sda2 rd0/pmd0/scl2 v usb rc2/an11/ctpls/ rp13 rc1/t1osi/uoe / rp12 nc nc rc0/t1oso/t1cki/ rp11 osc2/clko/ra6 osc1/clki/ra7 v ss v dd re2/an7/pmcs re1/an6/pmwr re0/an5/pmrd ra5/an4/ss1 /hlvdin/rcv/ rp2 v ddcore /v cap (2) rc7/pma4/rx1/dt1/sdo1/ rp18 rd4/pmd4/ rp21 rd5/pmd5/ rp22 rd6/pmd6/ rp23 v ss v dd rb0/an12/int0/ rp3 rb1/an10/pmbe/rtcc/ rp4 rb2/an8/ctedg1/pma3/vmo/refo/ rp5 rb3/an9/ctedg2/pma2/vpo/ rp6 44-pin tqfp (1) rd7/pmd7/ rp24 5 4 legend: rpn represents remappable pins. note 1: some input and output functions are routed through the peripheral pin select (pps) module and can be dynamically assigned to any of the rpn pins. for a list of the input and output functions, see table 9-13 and table 9-14, respectively. for details on configuring the pps module, see section 9.7 ?peripheral pin select (pps)? . 2: see section 26.3 ?on-chip voltage regulator? for details on how to connect the v ddcore /v cap pin. = pins are up to 5.5v tolerant
pic18f46j50 family ds39931b-page 6 preliminary ? 2009 microchip technology inc. table of contents 1.0 device overview ............................................................................................................. ............................................................. 9 2.0 oscillator configurations .................................... ............................................................... ......................................................... 27 3.0 low-power modes............................................................................................................. ......................................................... 39 4.0 reset ....................................................................................................................... ................................................................... 55 5.0 memory organization ......................................................................................................... ........................................................ 69 6.0 flash program memory........................................................................................................ ...................................................... 95 7.0 8 x 8 hardware multiplier................................................................................................... ....................................................... 105 8.0 interrupts .................................................................................................................. ................................................................ 107 9.0 i/o ports ................................................................................................................... ................................................................ 123 10.0 parallel master port (pmp)................................................................................................. ...................................................... 161 11.0 timer0 module .............................................................................................................. ........................................................... 187 12.0 timer1 module .............................................................................................................. ........................................................... 191 13.0 timer2 module .............................................................................................................. ........................................................... 203 14.0 timer3 module .............................................................................................................. ........................................................... 205 15.0 timer4 module .............................................................................................................. ........................................................... 215 16.0 real-time clock and calendar (rtcc) ........................................................................................ ........................................... 217 17.0 enhanced capture/compare/pwm (eccp) module................................................................................. ............................... 237 18.0 master synchronous serial port (mssp) module ............................................................................... ..................................... 261 19.0 enhanced universal synchronous asynchronous receiver transmitter (eusart) .................................................. ............. 315 20.0 10-bit analog-to-digital converter (a/d) module ............................................................................ .......................................... 339 21.0 universal serial bus (usb) ................................................................................................. ..................................................... 349 22.0 comparator module.......................................................................................................... ........................................................ 377 23.0 comparator voltage reference module ........................................................................................ ........................................... 385 24.0 high/low voltage detect (hlvd) ............................................................................................. ................................................ 389 25.0 charge time measurement unit (ctmu) ........................................................................................ ........................................ 395 26.0 special features of the cpu ................................................................................................ .................................................... 411 27.0 instruction set summary .................................................................................................... ...................................................... 429 28.0 development support........................................................................................................ ....................................................... 479 29.0 electrical characteristics ................................................................................................. ......................................................... 483 30.0 packaging information...................................................................................................... ........................................................ 523 appendix a: revision history................................................................................................... .......................................................... 535 appendix b: device differences................................................................................................. ........................................................ 535 the microchip web site ......................................................................................................... ............................................................ 549 customer change notification service ........................................................................................... ................................................... 549 customer support ............................................................................................................... ............................................................... 549 reader response ................................................................................................................ .............................................................. 550 product identification system.................................................................................................. ........................................................... 551
? 2009 microchip technology inc. preliminary ds39931b-page 7 pic18f46j50 family to our valued customers it is our intention to provide our valued customers with the best documentation possible to ensure successful use of your micro chip products. to this end, we will continue to improve our publications to better suit your needs. our publications will be refined and enhanced as new volumes and updates are introduced. if you have any questions or comments regar ding this publication, please contact the marketing communications department via e-mail at docerrors@microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we welcome your feedback. most current data sheet to obtain the most up-to-date version of this data s heet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the vers ion number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences fr om the data sheet and recommended workarounds, may exist for curren t devices. as device/documentation issues become known to us, we will publish an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particular device, please check with one of the following: ? microchip?s worldwide web site; http://www.microchip.com ? your local microchip sales office (see last page) when contacting a sales office, please specify which device, re vision of silicon and data sheet (include literature number) you are using. customer notification system register on our web site at www.microchip.com to receive the most current information on all of our products.
pic18f46j50 family ds39931b-page 8 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. ds39931b-page 9 pic18f46j50 family 1.0 device overview this document contains device-specific information for the following devices: this family introduces a new line of low-voltage universal serial bus (usb) microcontrollers with the main traditional advantage of all pic18 microcontrollers, namely, high computational performance and a rich feature set at an extremely competitive price point. these features make the pic18f46j50 family a logical choice for many high-performance applications, where cost is a primary consideration. 1.1 core features 1.1.1 nanowatt technology all of the devices in the pic18f46j50 family incorpo- rate a range of features that can significantly reduce power consumption during operation. key features are: ? alternate run modes: by clocking the controller from the timer1 source or the internal rc oscillator, power consumption during code execution can be reduced by as much as 90%. ? multiple idle modes: the controller can also run with its cpu core disabled but the peripherals still active. in these states, power consumption can be reduced even further, to as little as 4% of normal operational requirements. ? on-the-fly mode switching: the power-managed modes are invoked by user code during operation, allowing the users to incorporate power-saving ideas into their application?s software design. 1.1.2 universal serial bus (usb) devices in the pic18f46j50 family incorporate a fully-featured usb communications module with a built-in transceiver that is compliant with the usb specification revision 2.0. the module supports both low-speed and full-speed communication for all supported data transfer types. 1.1.3 oscillator options and features all of the devices in the pic18f46j50 family offer five different oscillator options, allowing users a range of choices in developing application hardware. these include: ? two crystal modes, using crystals or ceramic resonators. ? two external clock modes, offering the option of a divide-by-4 clock output. ? an internal oscillator block, which provides an 8 mhz clock and an intrc source (approxi- mately 31 khz, stable over temperature and v dd ), as well as a range of six user-selectable clock frequencies, between 125 khz to 4 mhz, for a total of eight clock frequencies. this option frees an oscillator pin for use as an additional general purpose i/o. ? a phase lock loop (pll) frequency multiplier, available to the high-speed crystal, and external and internal oscillators, providing a clock speed up to 48 mhz. ? dual clock operation, allowing the usb module to run from a high-frequency oscillator while the rest of the microcontroller is clocked at a different frequency. the internal oscillator block provides a stable reference source that gives the pic18f46j50 family additional features for robust operation: ? fail-safe clock monitor: this option constantly monitors the main clock source against a reference signal provided by the internal oscillator. if a clock failure occurs, the controller is switched to the internal oscillator, allowing for continued low-speed operation or a safe application shutdown. ? two-speed start-up: this option allows the internal oscillator to serve as the clock source from power-on reset (por), or wake-up from sleep mode, until the primary clock source is available. 1.1.4 expanded memory the pic18f46j50 family provides ample room for application code, from 16 kbytes to 64 kbytes of code space. the flash cells for program memory are rated to last in excess of 10000 erase/write cycles. data retention without refresh is conservatively estimated to be greater than 20 years. the flash program memory is readable and writable during normal operation. the pic18f46j50 family also provides plenty of room for dynamic application data with up to 3.8 kbytes of data ram. ? pic18f24j50 ? pic18lf24j50 ? pic18f25j50 ? pic18lf25j50 ? pic18f26j50 ? pic18lf26j50 ? pic18f44j50 ? pic18lf44j50 ? pic18f45j50 ? pic18lf45j50 ? pic18f46j50 ? pic18lf46j50
pic18f46j50 family ds39931b-page 10 ? 2009 microchip technology inc. 1.1.5 extended instruction set the pic18f46j50 family implements the optional extension to the pic18 instruction set, adding eight new instructions and an indexed addressing mode. enabled as a device configuration option, the extension has been specifically designed to optimize re-entrant application code originally developed in high-level languages, such as c. 1.1.6 easy migration regardless of the memory size, all devices share the same rich set of peripherals, allowing for a smooth migration path as applications grow and evolve. the consistent pinout scheme used throughout the entire family also aids in migrating to the next larger device. the pic18f46j50 family is also pin compatible with other pic18 families, such as the pic18f4550, pic18f2450 and pic18f45j10. this allows a new dimension to the evolution of applications, allowing developers to select different price points within microchip?s pic18 portfolio, while maintaining the same feature set. 1.2 other special features ? communications: the pic18f46j50 family incorporates a range of serial and parallel com- munication peripherals, including a fully featured usb communications module that is compliant with the usb specification revision 2.0. this device also includes two independent enhanced usarts and two master synchronous serial port (mssp) modules, capable of both serial peripheral interface (spi) and i 2 c? (master and slave) modes of operation. the device also has a parallel port and can be configured to serve as either a parallel master port (pmp) or as a parallel slave port (psp). ? eccp modules: all devices in the family incorpo- rate three enhanced capture/compare/pwm (eccp) modules to maximize flexibility in control applications. up to four different time bases may be used to perform several different operations at once. each of the eccps offers up to four pwm outputs, allowing for a total of eight pwms. the eccps also offer many beneficial features, including polarity selection, programmable dead time, auto-shutdown and restart and half-bridge and full-bridge output modes. ? 10-bit a/d converter: this module incorporates programmable acquisition time, allowing for a channel to be selected and a conversion to be initiated without waiting for a sampling period, and thus, reducing code overhead. ? extended watchdog timer (wdt): this enhanced version incorporates a 16-bit prescaler, allowing an extended time-out range that is stable across operating voltage and temperature. see section 29.0 ?electrical characteristics? for time-out periods. 1.3 details on individual family devices devices in the pic18f46j50 family are available in 28-pin and 44-pin packages. block diagrams for the two groups are shown in figure 1-1 and figure 1-2. the devices are differentiated from each other in two ways: ? flash program memory (three sizes: 16 kbytes for the pic18fx4j50, 32 kbytes for pic18fx5j50 devices and 64 kbytes for pic18fx6j50) ? i/o ports (three bidirectional ports on 28-pin devices, five bidirectional ports on 44-pin devices) all other features for devices in this family are identical. these are summarized in table 1-1 and table 1-2. the pinouts for the pic18f2xj50 devices are listed in table 1-3. the pinouts for the pic18f4xj50 devices are shown in table 1-4. the pic18f46j50 family of devices provides an on-chip voltage regulator to supply the correct voltage levels to the core. parts designated with an ?f? part number (such as pic18 f 46j50) have the voltage regulator enabled. these parts can run from 2.15v-3.6v on v dd, but should have the v ddcore pin connected to v ss through a low-esr capacitor. parts designated with an ?lf? part number (such as pic18 lf 46j50) do not enable the volt- age regulator. for ?lf? parts, an external supply of 2.0v-2.7v has to be supplied to the v ddcore pin while 2.0v-3.6v can be supplied to v dd (v ddcore should never exceed v dd ). for more details about the internal voltage regulator, see section 26.3 ?on-chip voltage regulator? .
? 2009 microchip technology inc. ds39931b-page 11 pic18f46j50 family table 1-1: device features for the pic18f2xj50 (28-pin devices) table 1-2: device features for the pic18f4xj50 (44-pin devices) features pic18f24j50 pic18f25j50 pic18f26j50 operating frequency dc ? 48 mhz dc ? 48 mhz dc ? 48 mhz program memory (bytes) 16k 32k 64k program memory (instructions) 8,192 16,384 32,768 data memory (bytes) 3.8k 3.8k 3.8k interrupt sources 30 i/o ports ports a, b, c timers 5 enhanced capture/compare/pwm modules 2 serial communications mssp (2), enhanced usart (2), usb parallel communications (pmp/psp) no 10-bit analog-to-digital module 10 input channels resets (and delays) por, bor, reset instruction, stack full, stack underflow, mclr , wdt (pwrt, ost) instruction set 75 instructions, 83 with extended instruction set enabled packages 28-pin qfn, soic, ssop and spdip (300 mil) features pic18f44j50 pic18f45j50 pic18f46j50 operating frequency dc ? 48 mhz dc ? 48 mhz dc ? 48 mhz program memory (bytes) 16k 32k 64k program memory (instructions) 8,192 16,384 32,768 data memory (bytes) 3.8k 3.8k 3.8k interrupt sources 30 i/o ports ports a, b, c, d, e timers 5 enhanced capture/compare/pwm modules 2 serial communications mssp (2), enhanced usart (2), usb parallel communications (pmp/psp) yes 10-bit analog-to-digital module 13 input channels resets (and delays) por, bor, reset instruction, stack full, stack underflow, mclr , wdt (pwrt, ost) instruction set 75 instructions, 83 with extended instruction set enabled packages 44-pin qfn and tqfp
pic18f46j50 family ds39931b-page 12 ? 2009 microchip technology inc. figure 1-1: pic18f2xj50 (28-pin) block diagram instruction decode and control porta data latch data memory (3.8 kbytes) address latch data address<12> 12 access bsr fsr0 fsr1 fsr2 inc/dec logic address 4 12 4 pch pcl pclath 8 31-level stack program counter prodl prodh 8 x 8 multiply 8 bitop 8 8 alu<8> address latch program memory (16 kbytes-64 kbytes) data latch 20 8 8 table pointer<21> inc/dec logic 21 8 data bus<8> table latch 8 ir 12 3 pclatu pcu note 1: see table 1-3 for i/o port pin descriptions. 2: bor functionality is provided when t he on-board voltage regulator is enabled. eusart1 comparators mssp1 timer2 timer1 timer3 timer0 eccp1 adc 10-bit w instruction bus <16> stkptr bank 8 state machine control signals decode 8 8 eusart2 eccp2 rom latch mssp2 portc ra0:ra7 (1) rc0:rc7 (1) portb rb0:rb7 (1) timer4 osc1/clki osc2/clko v dd , 8 mhz intosc v ss mclr power-up timer oscillator start-up timer power-on reset watchdog timer brown-out reset (2) precision reference band gap intrc oscillator regulator voltage v ddcore /v cap usb ctmu timing generation usb module v usb hlvd rtcc
? 2009 microchip technology inc. ds39931b-page 13 pic18f46j50 family figure 1-2: pic18f4xj50 (44-pin) block diagram prodl prodh 8 x 8 multiply 8 bitop 8 8 alu<8> 8 8 3 w 8 8 8 instruction decode and control data latch address latch data address<12> 12 access bsr fsr0 fsr1 fsr2 inc/dec logic address 4 12 4 pch pcl pclath 8 31-level stack program counter address latch program memory (16 kbytes-64 kbytes) data latch 20 table pointer<21> inc/dec logic 21 8 data bus<8> table latch 8 ir 12 rom latch pclatu pcu instruction bus <16> stkptr bank state machine control signals decode system bus interface ad<15:0>, a<19:16> (multiplexed with portd and porte) porta portc portd porte ra0:ra7 (1) rc0:rc7 (1) rd0:rd7 (1) re0:re2 (1) portb rb0:rb7 (1) eusart1 comparators mssp1 timer2 timer1 timer3 timer0 eccp1 adc 10-bit eusart2 eccp2 mssp2 timer4 note 1: see table 1-3 for i/o port pin descriptions. 2: the on-chip voltage regulator is always enabled by default. data memory (3.8 kbytes) usb pmp osc1/clki osc2/clko v dd , 8 mhz intosc v ss mclr power-up timer oscillator start-up timer power-on reset watchdog timer brown-out reset (2) precision reference band gap intrc oscillator regulator voltage v ddcore /v cap timing generation usb module v usb ctmu hlvd rtcc
pic18f46j50 family ds39931b-page 14 ? 2009 microchip technology inc. table 1-3: pic18f2xj50 pi nout i/o de scriptions pin name pin number pin type buffer type description 28-spdip/ ssop/ soic 28-qfn mclr 1 26 i st master clear (reset) input. this pin is an active-low reset to the device. osc1/clki/ra7 osc1 clki ra7 (1) 96 i i i/o st cmos ttl oscillator crystal or external clock input. oscillator crystal input or external clock source input. st buffer when configured in rc mode; cmos otherwise. main oscillator input connection. external clock source input; always associated with pin function osc1 (see related osc1/clki pins). digital i/o. osc2/clko/ra6 osc2 clko ra6 (1) 10 7 o o i/o ? ? ttl oscillator crystal or clock output. oscillator crystal output. connects to crystal or resonator in crystal oscillator mode. main oscillator feedback output connection. in rc mode, osc2 pin outputs clko, which has 1/4 the frequency of osc1 and denotes the instruction cycle rate. digital i/o. legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) dig = digital output i 2 c? = open-drain, i 2 c specific note 1: ra7 and ra6 will be disabled if osc1 and osc2 are used for the clock function.
? 2009 microchip technology inc. ds39931b-page 15 pic18f46j50 family porta is a bidirectional i/o port. ra0/an0/c1ina/ulpwu/rp0 ra0 an0 c1ina ulpwu rp0 227 i/o i i i i/o dig analog analog analog dig digital i/o. analog input 0. comparator 1 input a. ultra low-power wake-up input. remappable peripheral pin 0 input/output. ra1/an1/c2ina/rp1 ra1 an1 c2ina rp1 328 i o i i/o dig analog analog dig digital i/o. analog input 1. comparator 2 input a. remappable peripheral pin 1 input/output. ra2/an2/v ref -/cv ref /c2inb ra2 an2 v ref - cv ref c2inb 41 i/o i o i i dig analog analog analog analog digital i/o. analog input 2. a/d reference voltage (low) input. comparator reference voltage output. comparator 2 input b. ra3/an3/v ref +/c1inb ra3 an3 v ref + c1inb 52 i/o i i i dig analog analog analog digital i/o. analog input 3. a/d reference voltage (high) input. comparator 1 input b. ra5/an4/ss1 /hlvdin/ rcv/rp2 ra5 an4 ss1 hlvdin rcv rp2 74 i/o i i i i i/o dig analog ttl analog analog dig digital i/o. analog input 4. spi slave select input. low-voltage detect input. external usb transceiver rcv input. remappable peripheral pin 2 input/output. ra6 (1) ra7 (1) see the osc2/clko/ra6 pin. see the osc1/clki/ra7 pin. table 1-3: pic18f2xj50 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 28-spdip/ ssop/ soic 28-qfn legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) dig = digital output i 2 c? = open-drain, i 2 c specific note 1: ra7 and ra6 will be disabled if osc1 and osc2 are used for the clock function.
pic18f46j50 family ds39931b-page 16 ? 2009 microchip technology inc. portb is a bidirectional i/o port. portb can be software programmed for internal weak pull-ups on all inputs. rb0/an12/int0/rp3 rb0 an12 int0 rp3 21 18 i/o i i i/o dig analog st dig digital i/o. analog input 12. external interrupt 0. remappable peripheral pin 3 input/output. rb1/an10/rtcc/rp4 rb1 an10 rtcc rp4 22 19 i/o i o i/o dig analog dig dig digital i/o. analog input 10. asynchronous serial transmit data output. remappable peripheral pin 4 input/output. rb2/an8/ctedg1/vmo/ refo/rp5 rb2 an8 ctedg1 vmo refo rp5 23 20 i/o i i o o i/o dig analog st dig dig dig digital i/o. analog input 8. ctmu edge 1 input. external usb transceiver d- data output. reference output clock. remappable peripheral pin 5 input/output. rb3/an9/ctedg2/vpo/rp6 rb3 an9 ctedg2 vpo rp6 24 21 i/o i i/o o i dig analog st dig dig digital i/o. analog input 9. ctmu edge 2 input. external usb transceiver d+ data output. remappable peripheral pin 6 input/output. table 1-3: pic18f2xj50 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 28-spdip/ ssop/ soic 28-qfn legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) dig = digital output i 2 c? = open-drain, i 2 c specific note 1: ra7 and ra6 will be disabled if osc1 and osc2 are used for the clock function.
? 2009 microchip technology inc. ds39931b-page 17 pic18f46j50 family portb (continued) rb4/kbi0/sck1/scl1/rp7 rb4 kbi0 sck1 scl1 rp7 25 22 i/o i i/o i/o i/o dig ttl dig i 2 c dig digital i/o. interrupt-on-change pin. synchronous serial clock input/output. i 2 c clock input/output. remappable peripheral pin 7 input/output. rb5/kbi1/sdi1/sda1/rp8 rb5 kbi1 sdi1 sda1 rp8 26 23 i/o i/o i i/o i/o dig dig st i 2 c dig digital i/o. parallel master port address. spi data input. i 2 c? data input/output. remappable peripheral pin 8 input/output. rb6/kbi2/pgc/rp9 rb6 kbi2 pgc rp9 27 24 i/o i i i/o dig ttl st dig digital i/o. interrupt-on-change pin. icsp? clock input. remappable peripheral pin 9 input/output. rb7/kbi3/pgd/rp10 rb7 kbi3 pgd rp10 28 25 i/o i i/o i/o dig ttl st dig digital i/o. interrupt-on-change pin. in-circuit debugger and icsp programming data pin. remappable peripheral pin 10 input/output. table 1-3: pic18f2xj50 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 28-spdip/ ssop/ soic 28-qfn legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) dig = digital output i 2 c? = open-drain, i 2 c specific note 1: ra7 and ra6 will be disabled if osc1 and osc2 are used for the clock function.
pic18f46j50 family ds39931b-page 18 ? 2009 microchip technology inc. portc is a bidirectional i/o port. rc0/t1oso/t1cki/rp11 rc0 t1oso t1cki rp11 11 8 i/o o i i/o st analog st dig digital i/o. timer1 oscillator output. timer1 external digital clock input. remappable peripheral pin 11 input/output. rc1/t1osi/uoe /rp12 rc1 t1osi uoe rp12 12 9 i/o i o i/o st analog dig dig digital i/o. timer1 oscillator input. external usb transceiver noe output. remappable peripheral pin 12 input/output. rc2/an11/ctpls/rp13 rc2 an11 ctpls rp13 13 10 i/o i o i/o st analog dig dig digital i/o. analog input 11. ctmu pulse generator output. remappable peripheral pin 13 input/output. rc4/d-/vm rc4 d- vm 15 12 i i/o i ttl ? ttl digital i. usb bus minus line input/output. external usb transceiver fm input. rc5/d+/vp rc5 d+ vp 16 13 i i/o i ttl dig ttl digital i. usb bus plus line input/output. external usb transceiver vp input. rc6/tx1/ck1/rp17 rc6 tx1 ck1 rp17 17 14 i/o o i/o i/o st dig st dig digital i/o. eusart1 asynchronous transmit. eusart1 synchronous clock (see related rx1/dt1). remappable peripheral pin 17 input/output. rc7/rx1/dt1/sdo1/rp18 rc7 rx1 dt1 sdo1 rp18 18 15 i/o i i/o o i/o st st st dig dig digital i/o. asynchronous serial receive data input. synchronous serial data output/input. spi data output. remappable peripheral pin 18 input/output. table 1-3: pic18f2xj50 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 28-spdip/ ssop/ soic 28-qfn legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) dig = digital output i 2 c? = open-drain, i 2 c specific note 1: ra7 and ra6 will be disabled if osc1 and osc2 are used for the clock function.
? 2009 microchip technology inc. ds39931b-page 19 pic18f46j50 family v ss 1 8 5 p ? ground reference for logic and i/o pins. v ss 21916?? v dd 20 17 p ? positive supply for peripheral digital logic and i/o pins. v ddcore /v cap v ddcore v cap 63? p p ? ? ? core logic power or external filter capacitor connection. positive supply for microcontroller core logic (regulator disabled). external filter capacitor connection (regulator enabled). v usb 14 11 p ? usb voltage input pin. table 1-3: pic18f2xj50 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 28-spdip/ ssop/ soic 28-qfn legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) dig = digital output i 2 c? = open-drain, i 2 c specific note 1: ra7 and ra6 will be disabled if osc1 and osc2 are used for the clock function.
pic18f46j50 family ds39931b-page 20 ? 2009 microchip technology inc. table 1-4: pic18f4xj50 pi nout i/o de scriptions pin name pin number pin type buffer type description 44- qfn 44- tqfp mclr 18 18 i st master clear (reset) input; this is an active-low reset to the device. osc1/clki/ra7 osc1 clki ra7 (1) 32 30 i i i/o st cmos ttl oscillator crystal or external clock input. oscillator crystal input or external clock source input. st buffer when configured in rc mode; otherwise cmos. main oscillator input connection. external clock source input; always associated with pin function osc1 (see related osc1/clki pins). digital i/o. osc2/clko/ra6 osc2 clko ra6 (1) 33 31 o o i/o ? ? ttl oscillator crystal or clock output. oscillator crystal output. connects to crystal or resonator in crystal oscillator mode. main oscillator feedback output connection in rc mode, osc2 pin outputs clko, which has 1/4 the frequency of osc1 and denotes the instruction cycle rate. digital i/o. legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) dig = digital output i 2 c? = open-drain, i 2 c specific note 1: ra7 and ra6 will be disabled if osc1 and osc2 are used for the clock function.
? 2009 microchip technology inc. ds39931b-page 21 pic18f46j50 family porta is a bidirectional i/o port. ra0/an0/c1ina/ulpwu/pma6/ rp0 ra0 an0 c1ina ulpwu pma6 rp0 19 19 i/o i i i i/o i/o dig analog analog analog dig dig digital i/o. analog input 0. comparator 1 input a. ultra low-power wake-up input. parallel master port digital i/o. remappable peripheral pin 0 input/output. ra1/an1/c2ina/pma7/rp1 ra1 an1 c2ina pma7 rp1 20 20 i o i i/o i/o dig analog analog dig dig digital i/o. analog input 1. comparator 2 input a. parallel master port digital i/o. remappable peripheral pin 1 input/output. ra2/an2/v ref -/cv ref /c2inb ra2 an2 v ref - cv ref c2inb 21 21 i/o i o i i dig analog analog analog analog digital i/o. analog input 2. a/d reference voltage (low) input. comparator reference voltage output. comparator 2 input b. ra3/an3/v ref +/c1inb ra3 an3 v ref + c1inb 22 22 i/o i i i dig analog analog analog digital i/o. analog input 3. a/d reference voltage (high) input. comparator 1 input b. ra5/an4/ss1 /hlvdin/rcv/rp2 ra5 an4 ss1 hlvdin rcv rp2 24 24 i/o i i i i i/o dig analog ttl analog analog dig digital i/o. analog input 4. spi slave select input. low-voltage detect input. external usb transceiver rcv input. remappable peripheral pin 2 input/output. ra6 (1) ra7 (1) see the osc2/clko/ra6 pin. see the osc1/clki/ra7 pin. table 1-4: pic18f4xj50 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 44- qfn 44- tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) dig = digital output i 2 c? = open-drain, i 2 c specific note 1: ra7 and ra6 will be disabled if osc1 and osc2 are used for the clock function.
pic18f46j50 family ds39931b-page 22 ? 2009 microchip technology inc. portb is a bidirectional i/o port. portb can be software programmed for internal weak pull-ups on all inputs. rb0/an12/int0/rp3 rb0 an12 int0 rp3 98 i/o i i i/o dig analog st dig digital i/o. analog input 12. external interrupt 0. remappable peripheral pin 3 input/output. rb1/an10/pmbe/rtcc/rp4 rb1 an10 pmbe rtcc rp4 10 9 i/o i o o i/o dig analog dig dig dig digital i/o. analog input 10. parallel master port byte enable. asynchronous serial transmit data output. remappable peripheral pin 4 input/output. rb2/an8/ctedg1/pma3/vmo/ refo/rp5 rb2 an8 ctedg1 pma3 vmo refo rp5 11 10 i/o i i o o o i/o dig analog st dig dig dig dig digital i/o. analog input 8. ctmu edge 1 input. parallel master port address. external usb transceiver d- data output. reference output clock. remappable peripheral pin 5 input/output. rb3/an9/ctedg2/pma2/vpo/ rp6 rb3 an9 ctedg2 pma2 vpo rp6 12 11 i/o i i o o i/o dig analog st dig dig dig digital i/o. analog input 9. ctmu edge 2 input. parallel master port address. external usb transceiver d+ data output. remappable peripheral pin 6 input/output. table 1-4: pic18f4xj50 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 44- qfn 44- tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) dig = digital output i 2 c? = open-drain, i 2 c specific note 1: ra7 and ra6 will be disabled if osc1 and osc2 are used for the clock function.
? 2009 microchip technology inc. ds39931b-page 23 pic18f46j50 family portb (continued) rb4/pma1/kbi0/sck1/scl1/rp7 rb4 pma1 kbi0 sck1 scl1 rp7 14 14 i/o i/o i i/o i/o i/o dig dig ttl dig i 2 c dig digital i/o. parallel master port address. interrupt-on-change pin. synchronous serial clock input/output. i 2 c clock input/output. remappable peripheral pin 7 input/output. rb5/pma0/kbi1/sdi1/sda1/rp8 rb5 pma0 kbi1 sdi1 sda1 rp8 15 15 i/o i/o i i i/o i/o dig dig ttl st i 2 c dig digital i/o. parallel master port address. interrupt-on-change pin. spi data input. i 2 c? data input/output. remappable peripheral pin 8 input/output. rb6/kbi2/pgc/rp9 rb6 kbi2 pgc rp9 16 16 i/o i i i/o dig ttl st dig digital i/o. interrupt-on-change pin. icsp? clock input. remappable peripheral pin 9 input/output. rb7/kbi3/pgd/rp10 rb7 kbi3 pgd rp10 17 17 i/o i i/o i/o dig ttl st dig digital i/o. interrupt-on-change pin. in-circuit debugger and icsp programming data pin. remappable peripheral pin 10 input/output. table 1-4: pic18f4xj50 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 44- qfn 44- tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) dig = digital output i 2 c? = open-drain, i 2 c specific note 1: ra7 and ra6 will be disabled if osc1 and osc2 are used for the clock function.
pic18f46j50 family ds39931b-page 24 ? 2009 microchip technology inc. portc is a bidirectional i/o port. rc0/t1oso/t1cki/rp11 rc0 t1oso t1cki rp11 34 32 i/o o i i/o st analog st dig digital i/o. timer1 oscillator output. timer1/timer3 external clock input. remappable peripheral pin 11 input/output. rc1/t1osi/uoe /rp12 rc1 t1osi uoe rp12 35 35 i/o i o i/o st analog dig dig digital i/o. timer1 oscillator input. external usb transceiver noe output. remappable peripheral pin 12 input/output. rc2/an11/ctpls/rp13 rc2 an11 ctpls rp13 36 36 i/o i o i/o st analog dig dig digital i/o. analog input 11. ctmu pulse generator output. remappable peripheral pin 13 input/output. rc4/d-/vm rc4 d- vm 42 42 i o i ttl ? ttl digital i. usb bus minus line input/output. external usb transceiver fm input. rc5/d+/vp rc5 d+ vp 43 43 i i/o i ttl dig ttl digital i. usb bus plus line input/output. external usb transceiver vp input. rc6/pma5/tx1/ck1/rp17 rc6 pma5 tx1 ck1 rp17 44 44 i/o i/o o i/o i/o st dig dig st dig digital i/o. parallel master port address. eusart1 asynchronous transmit. eusart1 synchronous clock (see related rx1/dt1). remappable peripheral pin 17 input/output. rc7/pma4/rx1/dt1/sdo1/rp18 rc7 pma4 rx1 dt1 sdo1 rp18 11 i/o i/o i i/o o i/o st dig st st dig dig eusart1 asynchronous receive. parallel master port address. eusart1 synchronous data (see related tx1/ck1). synchronous serial data output/input. spi data output. remappable peripheral pin 18 input/output. table 1-4: pic18f4xj50 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 44- qfn 44- tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) dig = digital output i 2 c? = open-drain, i 2 c specific note 1: ra7 and ra6 will be disabled if osc1 and osc2 are used for the clock function.
? 2009 microchip technology inc. ds39931b-page 25 pic18f46j50 family portd is a bidirectional i/o port. rd0/pmd0/scl2 rd0 pmd0 scl2 38 38 i/o i/o i/o st dig dig digital i/o. parallel master port data. i 2 c? data input/output. rd1/pmd1/sda2 rd1 pmd1 sda2 39 39 i/o i/o i/o st dig dig digital i/o. parallel master port data. i 2 c data input/output. rd2/pmd2/rp19 rd2 pmd2 rp19 40 40 i/o i/o i/o st dig dig digital i/o. parallel master port data. remappable peripheral pin 19 input/output. rd3/pmd3/rp20 rd3 pmd3 rp20 41 41 i/o i/o i/o st dig dig digital i/o. parallel master port data. remappable peripheral pin 20 input/output. rd4/pmd4/rp21 rd4 pmd4 rp21 22 i/o i/o i/o st dig dig digital i/o. parallel master port data. remappable peripheral pin 21 input/output. rd5/pmd5/rp22 rd5 pmd5 rp22 33 i/o i/o i/o st dig dig digital i/o. parallel master port data. remappable peripheral pin 22 input/output. rd6/pmd6/rp23 rd6 pmd6 rp23 44 i/o i/o i/o st dig dig digital i/o. parallel master port data. remappable peripheral pin 23 input/output. rd7/pmd7/rp24 rd7 pmd7 rp24 55 i/o i/o i/o st dig dig digital i/o. parallel master port data. remappable peripheral pin 24 input/output. table 1-4: pic18f4xj50 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 44- qfn 44- tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) dig = digital output i 2 c? = open-drain, i 2 c specific note 1: ra7 and ra6 will be disabled if osc1 and osc2 are used for the clock function.
pic18f46j50 family ds39931b-page 26 ? 2009 microchip technology inc. porte is a bidirectional i/o port. re0/an5/pmrd re0 an5 pmrd 25 25 i/o i i/o st analog dig digital i/o. analog input 5. parallel master port input/output. re1/an6/pmwr re1 an6 pmwr 26 26 i/o i i/o st analog dig digital i/o. analog input 6. parallel master port write strobe. re2/an7/pmcs re2 an7 pmcs 27 27 i/o i o st analog ? digital i/o. analog input 7. parallel master port byte enable. v ss 1 6 6 p ? ground reference for logic and i/o pins. v ss 23129?? av ss 1 30 ? p ? ground reference for analog modules. v dd 1 8 7 p ? positive supply for peripheral digital logic and i/o pins. v dd 22928p? v ddcore /v cap v ddcore v cap 23 23 p p ? ? core logic power or external filter capacitor connection. positive supply for microcontroller core logic (regulator disabled). external filter capacitor connection (regulator enabled). av dd 1 7 ? p ? positive supply for analog modules. av dd 2 28 ? ? ? positive supply for analog modules. v usb 37 37 p ? usb voltage input pin. table 1-4: pic18f4xj50 pinout i/o descriptions (continued) pin name pin number pin type buffer type description 44- qfn 44- tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) dig = digital output i 2 c? = open-drain, i 2 c specific note 1: ra7 and ra6 will be disabled if osc1 and osc2 are used for the clock function.
? 2009 microchip technology inc. preliminary ds39931b-page 27 pic18f46j50 family 2.0 oscillator configurations 2.1 overview devices in the pic18f46j50 family incorporate a different oscillator and microcontroller clock system than general purpose pic18f devices. besides the usb module, with its unique requirements for a stable clock source, make it necessary to provide a separate clock source that is compliant with both usb low-speed and full-speed specifications. the pic18f46j50 family has additional prescalers and postscalers, which have been added to accommodate a wide range of oscillator frequencies. figure 2-1 provides an overview of the oscillator structure. other oscillator features used in pic18 enhanced microcontrollers, such as the internal oscillator block and clock switching, remain the same. they are discussed later in this chapter. 2.1.1 oscillator control the operation of the oscillator in pic18f46j50 family devices is controlled through three configuration regis- ters and two control registers. configuration registers, config1l, config1h and config2l, select the oscillator mode, pll prescaler and cpu divider options. as configuration bits, these are set when the device is programmed and left in that configuration until the device is reprogrammed. the osccon register (register 2-2) selects the active clock mode; it is primarily used in controlling clock switching in power-managed modes. its use is discussed in section 2.5.1 ?oscillator control register? . the osctune register (register 2-1) is used to trim the intosc frequency source, and select the low-frequency clock source that drives several special features. the osctune register is also used to activate or disable the phase locked loop (pll). its use is described in section 2.2.5.1 ?osctune register? . 2.2 oscillator types pic18f46j50 family devices can be operated in eight distinct oscillator modes. users can program the fosc<2:0> configuration bits to select one of the modes listed in table 2-1. for oscillator modes which produce a clock output (clko) on pin ra6, the output frequency will be one fourth of the peripheral clock frequency. the clock output stops when in sleep mode, but will continue during idle mode (see figure 2-1). table 2-1: oscillator modes mode description ecpll external clock input mode, the pll can be enabled or disabled in software, clko on ra6, apply external clock signal to ra7. ec external clock input mode, the pll is always disabled, clko on ra6, apply external clock signal to ra7. hspll high-speed crystal/resonator mode, pll can be enabled or disabled in software, crystal/resonator connected between ra6 and ra7. hs high-speed crystal/resonator mode, pll always disabled, crystal/resonator connected between ra6 and ra7. intoscpllo internal oscillator mode, pll can be enabled or disabled in software, clko on ra6, port function on ra7, the internal oscillator block is used to derive both the primary clock source and the postscaled internal clock. intoscpll internal oscillator mode, pll can be enabled or disabled in software, port function on ra6 and ra7, the internal oscillator block is used to derive both the primary clock source and the postscaled internal clock. intosco internal oscillator mode, pll is always disabled, clko on ra6, port function on ra7, the output of the intosc postscaler serves as both the postscaled internal clock and the primary clock source. intosc internal oscillator mode, pll is always disabled, port function on ra6 and ra7, the output of the intosc postscaler serves as both the postscaled internal clock and the primary clock source.
pic18f46j50 family ds39931b-page 28 preliminary ? 2009 microchip technology inc. 2.2.1 oscillator modes and usb operation because of the unique requirements of the usb module, a different approach to clock operation is necessary. in order to use the usb module, a fixed 6 mhz or 48 mhz clock must be internally provided to the usb module for operation in either low-speed or full-speed mode, respectively. the microcontroller core need not be clocked at the same frequency as the usb module. a network of muxes, clock dividers and a fixed 96 mhz output pll have been provided, which can be used to derive various microcontroller core and usb module frequencies. figure 2-1 helps in understanding the oscillator structure of the pic18f46j50 family of devices. figure 2-1: pic18f46j50 family clock diagram osc1 osc2 primary oscillator cpu peripherals idle intosc postscaler 8 mhz 4 mhz 2 mhz 1 mhz 500 khz 125 khz 250 khz 111 110 101 100 011 010 001 000 31 khz intrc 31 khz internal oscillator block 8 mhz 8 mhz 0 1 osctune<7> plldiv<2:0> cpu divider 1 2 3 6 usb module 4 mhz wdt, pwrt, fscm and two-speed start-up osccon<6:4> pllen 1 0 f osc 2 1 0 pll prescaler 96 mhz pll (1) 2 1 0 fsen 8 10 11 4 cpdiv<1:0> 00 01 10 11 cpdiv<1:0> (note 2) 00 fosc<2:1> other 00 01 osccon<1:0> 11 4 ra6 clko enabled modes timer1 clock (3) postscaled internal clock t1osi t1oso secondary oscillator t1oscen clock needs 48 mhz for fs needs 6 mhz for ls note 1: the pll requires a 4 mhz input and it produces a 96 mhz output. the pll will not be available until the pllen bit in the osctune register is set. once the pllen bit is set, the pll requires up to t rc to lock. during this time, the device continues to be clock ed at the pll bypassed frequency. 2: in order to use the usb module in full-speed mode, this node must be run at 48 mhz. for low-speed mode, this node may be run at either 48 mhz or 24 mhz, but the cpdiv bi ts must be set such that the usb module is clocked at 6 mhz. 3: selecting the timer1 clock or postscaled internal clock wi ll turn off the primary oscillator (unless required by the reference clock of section 2.6 ?reference clock output? ) and pll. 4: the usb module cannot be used to communicate unless the primary clock source is selected. 12 10 6 5 4 3 2 1 000 001 010 011 100 101 110 111 48 mhz primary clock source (4)
? 2009 microchip technology inc. preliminary ds39931b-page 29 pic18f46j50 family 2.2.2 crystal oscillator/ceramic resonators in hs and hspll oscillator modes, a crystal or ceramic resonator is connected to the osc1 and osc2 pins to establish oscillation. figure 2-2 displays the pin connections. the oscillator design requires the use of a parallel cut crystal. figure 2-2: crystal/ceramic resonator operation (hs or hspll configuration) table 2-2: capacitor selection for ceramic resonators table 2-3: capacitor selection for crystal oscillator an internal postscaler allows users to select a clock frequency other than that of the crystal or resonator. frequency division is determined by the cpdiv configuration bits. users may select a clock frequency of the oscillator frequency, or 1/2, 1/3 or 1/6 of the frequency. note: use of a series cut crystal may give a fre- quency out of the crystal manufacturer?s specifications. typical capacitor values used: mode freq osc1 osc2 hs 8.0 mhz 16.0 mhz 27 pf 22 pf 27 pf 22 pf capacitor values are for design guidance only. these capacitors were tested with the resonators listed below for basic start-up and operation. these values are not optimized . different capacitor values may be required to produce acceptable oscillator operation. the user should test the performance of the oscillator over the expected v dd and temperature range for the application. see the notes following table 2-3 for additional information. resonators used: 4.0 mhz 8.0 mhz 16.0 mhz note 1: see table 2-2 and table 2-3 for initial values of c1 and c2. 2: a series resistor (r s ) may be required for at strip cut crystals. 3: r f varies with the selected oscillator mode. c1 (1) c2 (1) xtal osc2 osc1 r f (3) sleep to logic r s (2) internal pic18f46j50 osc type crystal freq typical capacitor values tested: c1 c2 hs 4 mhz 27 pf 27 pf 8 mhz 22 pf 22 pf 16 mhz 18 pf 18 pf capacitor values are for design guidance only. these capacitors were tested with the crystals listed below for basic start-up and operation. these values are not optimized. different capacitor values may be required to produce acceptable oscillator operation. the user should test the performance of the oscillator over the expected v dd and temperature range for the application. see the notes following this table for additional information. crystals used: 4 mhz 8 mhz 16 mhz note 1: higher capacitance not only increases the stability of oscillator, but also increases the start-up time. 2: since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appropriate values of external components. 3: rs may be required to avoid overdriving crystals with low drive level specification. 4: always verify oscillator performance over the v dd and temperature range that is expected for the application.
pic18f46j50 family ds39931b-page 30 preliminary ? 2009 microchip technology inc. 2.2.3 external clock input the ec and ecpll oscillator modes require an external clock source to be connected to the osc1 pin. there is no oscillator start-up time required after a power-on reset (por) or after an exit from sleep mode. in the ec oscillator mode, the oscillator frequency divided by 4 is available on the osc2 pin. in the ecpll oscillator mode, the pll output divided by 4 is available on the osc2 pin this signal may be used for test purposes or to synchronize other logic. figure 2-3 displays the pin connections for the ec oscillator mode. figure 2-3: external clock input operation (ec and ecpll configuration) 2.2.4 pll frequency multiplier pic18f46j50 family devices include a pll circuit. this is provided specifically for usb applications with lower speed oscillators and can also be used as a microcontroller clock source. the pll can be enabled in hspll, ecpll, intoscpll and intoscpllo oscillator modes by setting the pllen bit (osctune<6>). it is designed to produce a fixed 96 mhz reference clock from a fixed 4 mhz input. the output can then be divided and used for both the usb and the microcontroller core clock. because the pll has a fixed frequency input and output, there are eight prescaling options to match the oscillator input frequency to the pll. this prescaler allows the pll to be used with crystals, res- onators and external clocks, which are integer multiple frequencies of 4 mhz. for example, a 12 mhz crystal could be used in a prescaler divide by three mode to drive the pll. there is also a cpu divider, which can be used to derive the microcontroller clock from the pll. this allows the usb peripheral and microcontroller to use the same oscillator input and still operate at different clock speeds. the cpu divider can reduce the incoming frequency by a factor of 1, 2, 3 or 6. 2.2.5 internal oscillator block the pic18f46j50 family devices include an internal oscillator block which generates two different clock signals; either can be used as the microcontroller?s clock source. the internal oscillator may eliminate the need for external oscillator circuits on the osc1 and/or osc2 pins. the main output (intosc) is an 8 mhz clock source which can be used to directly drive the device clock. it also drives the intosc postscaler which can provide a range of clock frequencies from 31 khz to 8 mhz. additionally, the intosc may be used in conjunction with the pll to generate clock frequencies up to 48 mhz. the other clock source is the internal rc oscillator (intrc) which provides a nominal 31 khz output. intrc is enabled if it is selected as the device clock source. it is also enabled automatically when any of the following are enabled: ? power-up timer ? fail-safe clock monitor ? watchdog timer ? two-speed start-up these features are discussed in larger detail in section 26.0 ?special features of the cpu? . the clock source frequency (intosc direct, intrc direct or intosc postscaler) is selected by configuring the ircf bits of the osccon register (page 35). osc1/clki osc2/clko f osc /4 clock from ext. system pic18f46j50
? 2009 microchip technology inc. preliminary ds39931b-page 31 pic18f46j50 family 2.2.5.1 osctune register the internal oscillator?s output has been calibrated at the factory but can be adjusted in the user?s applica- tion. this is done by writing to the osctune register (register 2-1). the tuning sensitivity is constant throughout the tuning range. when the osctune register is modified, the intosc frequency will begin shifting to the new frequency. the intosc clock will stabilize typically within 1 s. code execution continues during this shift. there is no indication that the shift has occurred. the osctune register also contains the intsrc bit. the intsrc bit allows users to select which internal oscillator provides the clock source when the 31 khz frequency option is selected. this is covered in larger detail in section 2.5.1 ?oscillator control register? . the pllen bit, contained in the osctune register, can be used to enable or disable the internal 96 mhz pll when running in one of the pll type oscillator modes (e.g., intoscpll). oscillator modes that do not contain ?pll? in their name cannot be used with the pll. in these modes, the pll is always disabled regardless of the setting of the pllen bit. when configured for one of the pll enabled modes, set- ting the pllen bit does not immediately switch the device clock to the pll output. the pll requires up to electrical parameter, t rc, to start-up and lock, during which time, the device continues to be clocked. once the pll output is ready, the microcontroller core will automatically switch to the pll derived frequency. 2.2.5.2 internal oscillator output frequency and drift the internal oscillator block is calibrated at the factory to produce an intosc output frequency of 8.0 mhz. however, this frequency may drift as v dd or tempera- ture changes, which can affect the controller operation in a variety of ways. the low-frequency intrc oscillator operates indepen- dently of the intosc source. any changes in intosc across voltage and temperature are not necessarily reflected by changes in intrc and vice versa. 2.2.5.3 compensating for intosc drift it is possible to adjust the intosc frequency by modifying the value in the osctune register. this has no effect on the intrc clock source frequency. tuning the intosc source requires knowing when to make the adjustment, in which direction it should be made and in some cases, how large a change is needed. when using the eusart, for example, an adjustment may be required when it begins to generate framing errors or receives data with errors while in asynchronous mode. framing errors indicate that the device clock frequency is too high; to adjust for this, decrement the value in osctune to reduce the clock frequency. on the other hand, errors in data may sug- gest that the clock speed is too low; to compensate, increment osctune to increase the clock frequency. it is also possible to verify device clock speed against a reference clock. two timers may be used: one timer is clocked by the peripheral clock, while the other is clocked by a fixed reference source, such as the timer1 oscillator. both timers are cleared, but the timer clocked by the reference generates interrupts. when an interrupt occurs, the internally clocked timer is read and both timers are cleared. if the internally clocked timer value is greater than expected, then the internal oscillator block is running too fast. to adjust for this, decrement the osctune register. finally, an eccp module can use free-running timer1 (or timer3), clocked by the internal oscillator block and an external event with a known period (i.e., ac power frequency). the time of the first event is captured in the ccprxh:ccprxl registers and is recorded for use later. when the second event causes a capture, the time of the first event is subtracted from the time of the second event. since the period of the external event is known, the time difference between events can be calculated. if the measured time is greater than the calculated time, the internal oscillator block is running too fast; to compensate, decrement the osctune register. if the measured time is less than the calculated time, the inter- nal oscillator block is running too slow; to compensate, increment the osctune register.
pic18f46j50 family ds39931b-page 32 preliminary ? 2009 microchip technology inc. 2.3 oscillator settings for usb when the pic18f46j50 family devices are used for usb connectivity, a 6 mhz or 48 mhz clock must be provided to the usb module for operation in either low-speed or full-speed modes, respectively. this may require some forethought in selecting an oscillator frequency and programming the device. the full range of possible oscillator configurations compatible with usb operation is shown in table 2-5. 2.3.1 low-speed operation the usb clock for low-speed mode is derived from the primary oscillator or from the 96 mhz pll. in order to operate the usb module in low-speed mode, a 6 mhz clock must be provided to the usb module. due to the way the clock dividers have been implemented in the pic18f46j50 family, the microcontroller core must run at 24 mhz in order for the usb module to get the 6 mhz clock needed for low-speed usb operation. several clocking schemes could be used to meet these two required conditions. see table 2-4 and table 2-5 for possible combinations which can be used for low-speed usb operation. table 2-4: clock for low-speed usb register 2-1: osctune: oscillator tuning register (access f9bh) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 intsrc pllen tun5 tun4 tun3 tun2 tun1 tun0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 intsrc: internal oscillator low-frequency source select bit 1 = 31.25 khz device clock derived from 8 mhz intosc source (divide-by-256 enabled) 0 = 31 khz device clock derived directly from intrc internal oscillator bit 6 pllen: frequency multiplier enable bit 1 = 96 mhz pll is enabled 0 = 96 mhz pll is disabled bit 5-0 tun<5:0>: frequency tuning bits 011111 = maximum frequency 011110 ? ? ? 000001 000000 = center frequency; oscillator module is running at the calibrated frequency 111111 ? ? ? 100000 = minimum frequency clock input cpu clock cpdiv<1:0> usb clock 48 24 ? 10 ? 48/8 = 6 mhz 24 24 ? 11 ? 24/4 = 6 mhz
? 2009 microchip technology inc. preliminary ds39931b-page 33 pic18f46j50 family table 2-5: oscillator configurat ion options for usb operation input oscillator frequency pll division (plldiv<2:0>) clock mode (fosc<2:0>) mcu clock division (cpdiv<1:0>) microcontroller clock frequency 48 mhz n/a ec none ( 11 )48mhz 2 ( 10 ) 24 mhz 3 ( 01 )16mhz 6 ( 00 )8mhz 48 mhz 12 ( 000 )ecpll none ( 11 )48mhz 2 ( 10 ) 24 mhz 3 ( 01 )16mhz 6 ( 00 )8mhz 40 mhz 10 ( 001 )ecpll none ( 11 )48mhz 2 ( 10 ) 24 mhz 3 ( 01 )16mhz 6 ( 00 )8mhz 24 mhz 6 ( 010 ) hspll, ecpll none ( 11 )48mhz 2 ( 10 ) 24 mhz 3 ( 01 )16mhz 6 ( 00 )8mhz 24 mhz n/a ec, hs none ( 11 ) 24 mhz 2 ( 10 )12mhz 3 ( 01 )8mhz 6 ( 00 )4mhz 20 mhz 5 ( 011 ) hspll, ecpll none ( 11 )48mhz 2 ( 10 ) 24 mhz 3 ( 01 )16mhz 6 ( 00 )8mhz 16 mhz 4 ( 100 ) hspll, ecpll none ( 11 )48mhz 2 ( 10 ) 24 mhz 3 ( 01 )16mhz 6 ( 00 )8mhz 12 mhz 3 ( 101) hspll, ecpll none ( 11 )48mhz 2 ( 10 ) 24 mhz 3 ( 01 )16mhz 6 ( 00 )8mhz 8mhz 2 ( 110 ) hspll, ecpll, intoscpll/ intoscpllo none ( 11 )48mhz 2 ( 10 ) 24 mhz 3 ( 01 )16mhz 6 ( 00 )8mhz 4mhz 1 ( 111 ) hspll, ecpll none ( 11 )48mhz 2 ( 10 ) 24 mhz 3 ( 01 )16mhz 6 ( 00 )8mhz legend: all clock frequencies, except 24 mhz, are exclusively asso ciated with full-speed usb operation (usb clock of 48 mhz). bold text highlights the clock selections that are compat ible with low-speed usb operation (system clock of 24 mhz, usb clock of 6 mhz).
pic18f46j50 family ds39931b-page 34 preliminary ? 2009 microchip technology inc. 2.4 usb from intosc the 8 mhz intosc included in all pic18f46j50 family devices is extremely accurate. when the 8 mhz intosc is used with the 96 mhz pll, it may be used to derive the usb module clock. the high accuracy of the intosc will allow the application to meet low-speed usb signal rate specifications. 2.5 clock sources and oscillator switching like previous pic18 enhanced devices, the pic18f46j50 family includes a feature that allows the device clock source to be switched from the main oscillator to an alternate, low-frequency clock source. pic18f46j50 family devices offer two alternate clock sources. when an alternate clock source is enabled, the various power-managed operating modes are available. essentially, there are three clock sources for these devices: ? primary oscillators ? secondary oscillators ? internal oscillator block the primary oscillators include the external crystal and resonator modes, the external clock modes and the internal oscillator block. the particular mode is defined by the fosc<2:0> configuration bits. the details of these modes are covered earlier in this chapter. the secondary oscillators are external sources that are not connected to the osc1 or osc2 pins. these sources may continue to operate even after the controller is placed in a power-managed mode. pic18f46j50 family devices offer the timer1 oscillator as a secondary oscillator. this oscillator, in all power-managed modes, is often the time base for functions such as a real-time clock (rtc). most often, a 32.768 khz watch crystal is connected between the rc0/t1oso/t1cki/rp11 and rc1/t1osi/uoe /rp12 pins. like the hs oscillator mode circuits, loading capacitors are also connected from each pin to ground. the timer1 oscillator is discussed in larger detail in section 12.5 ?timer1 oscillator? . in addition to being a primary clock source, the postscaled internal clock is available as a power-managed mode clock source. the intrc source is also used as the clock source for several special features, such as the wdt and fail-safe clock monitor (fscm). 2.5.1 oscillator control register the osccon register (register 2-2) controls several aspects of the device clock?s operation, both in full-power operation and in power-managed modes. the system clock select bits, scs<1:0>, select the clock source. the available clock sources are the primary clock (defined by the fosc<2:0> configura- tion bits), the secondary clock (timer1 oscillator) and the postscaled internal clock.the clock source changes immediately, after one or more of the bits is written to, following a brief clock transition interval. the scs bits are cleared on all forms of reset. the internal oscillator frequency select bits, ircf<2:0>, select the frequency output provided on the postscaled internal clock line. the choices are the intrc source, the intosc source (8 mhz) or one of the frequencies derived from the intosc postscaler (31 khz to 4 mhz). if the postscaled internal clock is supplying the device clock, changing the states of these bits will have an immediate change on the inter- nal oscillator?s output. on device resets, the default output frequency of the intosc postscaler is set at 4mhz. when an output frequency of 31 khz is selected (ircf<2:0> = 000 ), users may choose the internal oscillator, which acts as the source. this is done with the intsrc bit in the osctune register (osctune<7>). setting this bit selects intosc as a 31.25 khz clock source by enabling the divide-by-256 output of the intosc postscaler. clearing intsrc selects intrc (nominally 31 khz) as the clock source. this option allows users to select the tunable and more precise intosc as a clock source, while maintaining power savings with a very low clock speed. regardless of the setting of intsrc, intrc always remains the clock source for features such as the wdt and the fscm. the osts and t1run bits indicate which clock source is currently providing the device clock. the osts bit indicates that the oscillator start-up timer (ost) has timed out and the primary clock is providing the device clock in primary clock modes. the t1run bit (t1con<6>) indicates when the timer1 oscillator is providing the device clock in secondary clock modes. in power-managed modes, only one of these bits will be set at any time. if none of these bits are set, the intrc is providing the clock or the internal oscillator block has just started and is not yet stable. the idlen bit determines if the device goes into sleep mode, or one of the idle modes, when the sleep instruction is executed.
? 2009 microchip technology inc. preliminary ds39931b-page 35 pic18f46j50 family the use of the flag and control bits in the osccon register is discussed in more detail in section 3.0 ?low-power modes? . 2.5.2 oscillator transitions pic18f46j50 family devices contain circuitry to prevent clock ?glitches? when switching between clock sources. a short pause in the device clock occurs dur- ing the clock switch. the length of this pause is the sum of two cycles of the old clock source and three to four cycles of the new clock source. this formula assumes that the new clock source is stable. clock transitions are discussed in more detail in section 3.1.2 ?entering power-managed modes? . note 1: the timer1 crystal driver is enabled by setting the t1oscen bit in the timer1 control register (t1con<3>). if the timer1 oscillator is not enabled, then any attempt to select the timer1 clock source will be ignored, unless the config2l register?s t1dig bit is set. 2: if timer1 is driving a crystal, it is recom- mended that the timer1 oscillator be operating and stable prior to switching to it as the clock source; otherwise, a very long delay may occur while the timer1 oscillator starts. register 2-2: osccon: oscillator control register (access fd3h) r/w-0 r/w-1 r/w-1 r/w-0 r-1 (1) u-1 r/w-0 r/w-0 idlen ircf2 ircf1 ircf0 osts ?scs1scs0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 idlen: idle enable bit 1 = device enters idle mode on sleep instruction 0 = device enters sleep mode on sleep instruction bit 6-4 ircf<2:0>: internal oscillator frequency select bits 111 = 8 mhz (intosc drives clock directly) 110 = 4 mhz (2) 101 = 2 mhz 100 = 1 mhz 011 = 500 khz 010 = 250 khz 001 = 125 khz 000 = 31 khz (from either intosc/256 or intrc directly) (3) bit 3 osts: oscillator start-up time-out status bit (1) 1 = oscillator start-up timer time-out has expired; primary oscillator is running 0 = oscillator start-up timer time-out is running; primary oscillator is not ready bit 2 unimplemented: read as ? 1 ? bit 1-0 scs<1:0>: system clock select bits 11 = postscaled internal clock (intrc/intosc derived) 10 = reserved 01 = timer1 oscillator 00 = primary clock source (intosc postscaler output when fosc<2:0> = 001 or 000 ) 00 = primary clock source (cpu divider output for other values of fosc<2:0>) note 1: reset value is ? 0 ? when two-speed start-up is enabled and ? 1 ? if disabled. 2: default output frequency of intosc on reset (4 mhz). 3: source selected by the intsrc bit (osctune<7>).
pic18f46j50 family ds39931b-page 36 preliminary ? 2009 microchip technology inc. 2.6 reference clock output in addition to the peripheral clock/4 output in certain oscillator modes, the device clock in the pic18f46j50 family can also be configured to provide a reference clock output signal to a port pin. this feature is avail- able in all oscillator configurations and allows the user to select a greater range of clock submultiples to drive external devices in the application. this reference clock output is controlled by the refocon register (register 2-3). setting the roon bit (refocon<7>) makes the clock signal available on the refo (rb2) pin. the rodiv<3:0> bits enable the selection of 16 different clock divider options. the rosslp and rosel bits (refocon<5:4>) control the availability of the reference output during sleep mode. the rosel bit determines if the oscillator is on osc1 and osc2, or the current system clock source is used for the reference clock output. the rosslp bit determines if the reference source is available on rb2 when the device is in sleep mode. to use the reference clock output in sleep mode, both the rosslp and rosel bits must be set. the device clock must also be configured for an ec or hs mode; otherwise, the oscillator on osc1 and osc2 will be powered down when the device enters sleep mode. clearing the rosel bit allows the reference output frequency to change as the system clock changes during any clock switches. register 2-3: refocon: reference osci llator control register (banked f3dh) r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 roon ? rosslp rosel rodiv3 rodiv2 rodiv1 rodiv0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 roon: reference oscillator output enable bit 1 = reference oscillator enabled on refo pin 0 = reference oscillator disabled bit 6 unimplemented: read as ? 0 ? bit 5 rosslp: reference oscillator output stop in sleep bit 1 = reference oscillator continues to run in sleep 0 = reference oscillator is disabled in sleep bit 4 rosel: reference oscillator source select bit 1 = primary oscillator crystal/resonator used as the base clock (1) 0 = system clock (f osc ) used as the base clock; base clock reflects any clock switching of the device bit 3-0 rodiv<3:0>: reference oscillator divisor select bits 1111 = base clock value divided by 32,768 1110 = base clock value divided by 16,384 1101 = base clock value divided by 8,192 1100 = base clock value divided by 4,096 1011 = base clock value divided by 2,048 1010 = base clock value divided by 1,024 1001 = base clock value divided by 512 1000 = base clock value divided by 256 0111 = base clock value divided by 128 0110 = base clock value divided by 64 0101 = base clock value divided by 32 0100 = base clock value divided by 16 0011 = base clock value divided by 8 0010 = base clock value divided by 4 0001 = base clock value divided by 2 0000 = base clock value note 1: the crystal oscillator must be enabled using the fosc<2:0> bits; the crystal maintains the operation in sleep mode.
? 2009 microchip technology inc. preliminary ds39931b-page 37 pic18f46j50 family 2.7 effects of power-managed modes on various clock sources when the pri_idle mode is selected, the designated primary oscillator continues to run without interruption. for all other power-managed modes, the oscillator using the osc1 pin is disabled. unless the usb module is enabled, the osc1 pin (and osc2 pin if used by the oscillator) will stop oscillating. in secondary clock modes (sec_run and sec_idle), the timer1 oscillator is operating and providing the device clock. the timer1 oscillator may also run in all power-managed modes if required to clock timer1 or timer3. in internal oscillator modes (rc_run and rc_idle), the internal oscillator block provides the device clock source. the 31 khz intrc output can be used directly to provide the clock and may be enabled to support various special features regardless of the power-managed mode (see section 26.2 ?watchdog timer (wdt)? , section 26.4 ?two-speed start-up? and section 26.5 ?fail-safe clock monitor? for more information on wdt, fscm and two-speed start-up). the intosc output at 8 mhz may be used directly to clock the device or may be divided down by the post- scaler. the intosc output is disabled if the clock is provided directly from the intrc output. if sleep mode is selected, all clock sources which are no longer required are stopped. since all the transistor switching currents have been stopped, sleep mode achieves the lowest current consumption of the device (only leakage currents) outside of deep sleep. sleep mode should not be invoked while the usb module is enabled and operating in full-power mode. before sleep mode is selected, the usb module should be put in the suspend state. this is accomplished by setting the suspnd bit in the ucon register. enabling any on-chip feature that will operate during sleep mode increases the current consumed during sleep mode. the intrc is required to support wdt operation. the timer1 oscillator may be operating to support a rtc. other features may be operating that do not require a device clock source (i.e., mssp slave, pmp, intx pins, etc.). peripherals that may add significant current consumption are listed in section 29.2 ?dc characteristics: power-down and supply current pic18f46j50 family (industrial)? . 2.8 power-up delays power-up delays are controlled by two timers so that no external reset circuitry is required for most applica- tions. the delays ensure that the device is kept in reset until the device power supply is stable under normal circumstances and the primary clock is operat- ing and stable. for additional information on power-up delays, see section 4.6 ?power-up timer (pwrt)? . the first timer is the power-up timer (pwrt), which provides a fixed delay on power-up (parameter 33, table 29-14). the second timer is the oscillator start-up timer (ost), intended to keep the chip in reset until the crystal oscillator is stable (hs mode). the ost does this by counting 1024 oscillator cycles before allowing the oscillator to clock the device. there is a delay of interval, t csd (parameter 38, table 29-14), following por, while the controller becomes ready to execute instructions. this delay runs concurrently with any other delays. this may be the only delay that occurs when any of the internal oscillator or ec modes are used as the primary clock source.
pic18f46j50 family ds39931b-page 38 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39931b-page 39 pic18f46j50 family 3.0 low-power modes the pic18f46j50 family devices can manage power consumption through clocking to the cpu and the peripherals. in general, reducing the clock frequency and number of circuits being clocked reduce power consumption. for managing power in an application, the primary modes of operation are: ? run mode ? idle mode ? sleep mode ? deep sleep mode additionally, there is an ultra low-power wake-up (ulpwu) mode for generating an interrupt-on-change on ra0. these modes define which portions of the device are clocked and at what speed. ? the run and idle modes can use any of the three available clock sources (primary, secondary or internal oscillator blocks). ? the sleep mode does not use a clock source. the ulpwu mode on ra0 allows a slow falling voltage to generate an interrupt-on-change on ra0 without excess current consumption. see section 3.7 ?ultra low-power wake-up? . the power-managed modes include several power-saving features offered on previous pic ? devices, such as clock switching, ulpwu and sleep mode. in addition, the pic18f46j50 family devices add a new power-managed deep sleep mode. 3.1 selecting power-managed modes selecting a power-managed mode requires these decisions: ? will the cpu be clocked? ? if so, which clock source will be used? the idlen bit (osccon<7>) controls cpu clocking and the scs<1:0> bits (osccon<1:0>) select the clock source. the individual modes, bit settings, clock sources and affected modules are summarized in table 3-1. 3.1.1 clock sources the scs<1:0> bits allow the selection of one of three clock sources for power-managed modes. they are: ? primary clock source ? defined by the fosc<2:0> configuration bits ? timer1 clock ? provided by the secondary oscillator ? postscaled internal clock ? derived from the internal oscillator block 3.1.2 entering power-managed modes switching from one clock source to another begins by loading the osccon register. the scs<1:0> bits select the clock source. changing these bits causes an immediate switch to the new clock source, assuming that it is running. the switch also may be subject to clock transition delays. these delays are discussed in section 3.1.3 ?clock transitions and status indicators? and subsequent sections. entry to the power-managed idle or sleep modes is triggered by the execution of a sleep instruction. the actual mode that results depends on the status of the idlen bit. depending on the current mode and the mode being switched to, a change to a power-managed mode does not always require setting all of these bits. many transi- tions may be done by changing the oscillator select bits, the idlen bit, or the dsen bit prior to issuing a sleep instruction. if the idlen and dsen bits are already configured correctly, it only may be necessary to perform a sleep instruction to switch to the desired mode.
pic18f46j50 family ds39931b-page 40 preliminary ? 2009 microchip technology inc. table 3-1: low-power modes 3.1.3 clock transitions and status indicators the length of the transition between clock sources is the sum of two cycles of the old clock source and three to four cycles of the new clock source. this formula assumes that the new clock source is stable. two bits indicate the current clock source and its status: osts (osccon<3>) and t1run (t1con<6>). in general, only one of these bits will be set in a given power-managed mode. when the osts bit is set, the primary clock would be providing the device clock. when the t1run bit is set, the timer1 oscillator would be providing the clock. if neither of these bits is set, intrc would be clocking the device. 3.1.4 multiple sleep commands the power-managed mode that is invoked with the sleep instruction is determined by the setting of the idlen and dsen bits at the time the instruction is exe- cuted. if another sleep instruction is executed, the device will enter the power-managed mode specified by idlen and dsen at that time. if idlen or dsen have changed, the device will enter the new power-managed mode specified by the new setting. 3.2 run modes in the run modes, clocks to both the core and peripherals are active. the difference between these modes is the clock source. 3.2.1 pri_run mode the pri_run mode is the normal, full-power execu- tion mode of the microcontroller. this is also the default mode upon a device reset unless two-speed start-up is enabled (see section 26.4 ?two-speed start-up? for details). in this mode, the osts bit is set (see section 2.5.1 ?oscillator control register? ). 3.2.2 sec_run mode the sec_run mode is the compatible mode to the ?clock switching? feature offered in other pic18 devices. in this mode, the cpu and peripherals are clocked from the timer1 oscillator. this gives users the option of low-power consumption while still using a high-accuracy clock source. sec_run mode is entered by setting the scs<1:0> bits to ? 01 ?. the device clock source is switched to the timer1 oscillator (see figure 3-1), the primary oscillator is shut down, the t1run bit (t1con<6>) is set and the osts bit is cleared. mode dsconh<7> osccon<7,1:0> module clocking available clock and oscillator source dsen (1) idlen (1) scs<1:0> cpu peripherals sleep 00 n/a off off timer1 oscillator and/or rtcc may optionally be enabled deep sleep 10 n/a off (2) off rtcc can run uninterrupted using the timer1 or internal low-power rc oscillator pri_run 0 n/a 00 clocked clocked the normal, full-power execution mode; primary clock source (defined by fosc<2:0>) sec_run 0 n/a 01 clocked clocked secondary ? timer1 oscillator rc_run 0 n/a 11 clocked clocked postscaled internal clock pri_idle 0100 off clocked primary clock source (defined by fosc<2:0>) sec_idle 0101 off clocked secondary ? timer1 oscillator rc_idle 0111 off clocked postscaled internal clock note 1: idlen and dsen reflect their values when the sleep instruction is executed. 2: deep sleep turns off the voltage regulator for ultra low-power consumption. see section 3.6 ?deep sleep mode? for more information. note: executing a sleep instruction does not necessarily place the device into sleep mode. it acts as the trigger to place the controller into either the sleep or deep sleep mode, or one of the idle modes, depending on the setting of the idlen bit. note: the timer1 oscillator should already be running prior to entering sec_run mode. if the t1oscen bit is not set when the scs<1:0> bits are set to ? 01 ?, entry to sec_run mode will not occur. if the timer1 oscillator is enabled, but not yet running, device clocks will be delayed until the oscillator has started. in such situa- tions, initial oscillator operation is far from stable and unpredictable operation may result.
? 2009 microchip technology inc. preliminary ds39931b-page 41 pic18f46j50 family on transitions from sec_run mode to pri_run mode, the peripherals and cpu continue to be clocked from the timer1 oscillator while the primary clock is started. when the primary clock becomes ready, a clock switch back to the primary clock occurs (see figure 3-2). when the clock switch is complete, the t1run bit is cleared, the osts bit is set and the primary clock would be providing the clock. the idlen and scs bits are not affected by the wake-up; the timer1 oscillator continues to run. figure 3-1: transition timing for entry to sec_run mode figure 3-2: transition timing from sec_run mode to pri_run mode (hspll) q4 q3 q2 osc1 peripheral program q1 t1osi q1 counter clock cpu clock pc + 2 pc 123 n-1n clock transition q4 q3 q2 q1 q3 q2 pc + 4 q1 q3 q4 osc1 peripheral program pc t1osi pll clock q1 pc + 4 q2 output q3 q4 q1 cpu clock pc + 2 clock counter q2 q2 q3 note 1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. scs<1:0> bits changed t pll (1) 12 n-1n clock osts bit set transition t ost (1)
pic18f46j50 family ds39931b-page 42 preliminary ? 2009 microchip technology inc. 3.2.3 rc_run mode in rc_run mode, the cpu and peripherals are clocked from the internal oscillator; the primary clock is shutdown. this mode provides the best power conser- vation of all the run modes while still executing code. it works well for user applications, which are not highly timing sensitive or do not require high-speed clocks at all times. this mode is entered by setting the scs<1:0> bits (osccon<1:0>) to ? 11 ?. when the clock source is switched to the internal oscillator block (see figure 3-3), the primary oscillator is shutdown and the osts bit is cleared. on transitions from rc_run mode to pri_run mode, the device continues to be clocked from the intosc block while the primary clock is started. when the primary clock becomes ready, a clock switch to the primary clock occurs (see figure 3-4). when the clock switch is complete, the osts bit is set and the primary clock is providing the device clock. the idlen and scs bits are not affected by the switch. the intrc clock source will continue to run if either the wdt or the fscm is enabled. figure 3-3: transition timing to rc_run mode figure 3-4: transition timing from rc_run mode to pri_run mode q4 q3 q2 osc1 peripheral program q1 intrc q1 counter clock cpu clock pc + 2 pc 123 n-1n clock transition q4 q3 q2 q1 q3 q2 pc + 4 q1 q3 q4 osc1 peripheral program pc intrc pll clock q1 pc + 4 q2 output q3 q4 q1 cpu clock pc + 2 clock counter q2 q2 q3 note 1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. scs<1:0> bits changed t pll (1) 12 n-1n clock osts bit set transition t ost (1)
? 2009 microchip technology inc. preliminary ds39931b-page 43 pic18f46j50 family 3.3 sleep mode the power-managed sleep mode is identical to the legacy sleep mode offered in all other pic devices. it is entered by clearing the idlen bit (the default state on device reset) and executing the sleep instruction. this shuts down the selected oscillator (figure 3-5). all clock source status bits are cleared. entering the sleep mode from any other mode does not require a clock switch. this is because no clocks are needed once the controller has entered sleep mode. if the wdt is selected, the intrc source will continue to operate. if the timer1 oscillator is enabled, it will also continue to run. when a wake event occurs in sleep mode (by interrupt, reset or wdt time-out), the device will not be clocked until the clock source selected by the scs<1:0> bits becomes ready (see figure 3-6), or it will be clocked from the internal oscillator if either the two-speed start-up or the fscm are enabled (see section 26.0 ?special features of the cpu? ). in either case, the osts bit is set when the primary clock is providing the device clocks. the idlen and scs bits are not affected by the wake-up. figure 3-5: transition timing for entry to sleep mode figure 3-6: transition timing for wake from sleep (hspll) q4 q3 q2 osc1 peripheral sleep program q1 q1 counter clock cpu clock pc + 2 pc q3 q4 q1 q2 osc1 peripheral program pc pll clock q3 q4 output cpu clock q1 q2 q3 q4 q1 q2 clock counter pc + 6 pc + 4 q1 q2 q3 q4 wake event note 1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. t ost (1) t pll (1) osts bit set pc + 2
pic18f46j50 family ds39931b-page 44 preliminary ? 2009 microchip technology inc. 3.4 idle modes the idle modes allow the controller?s cpu to be selectively shut down while the peripherals continue to operate. selecting a particular idle mode allows users to further manage power consumption. if the idlen bit is set to ? 1 ? when a sleep instruction is executed, the peripherals will be clocked from the clock source selected using the scs<1:0> bits; however, the cpu will not be clocked. the clock source status bits are not affected. setting idlen and executing a sleep instruction provides a quick method of switching from a given run mode to its corresponding idle mode. if the wdt is selected, the intrc source will continue to operate. if the timer1 oscillator is enabled, it will also continue to run. since the cpu is not executing instructions, the only exits from any of the idle modes are by interrupt, wdt time-out or a reset. when a wake event occurs, cpu execution is delayed by an interval of t csd (parameter 38, table 29-14) while it becomes ready to execute code. when the cpu begins executing code, it resumes with the same clock source for the current idle mode. for example, when waking from rc_idle mode, the internal oscillator block will clock the cpu and peripherals (in other words, rc_run mode). the idlen and scs bits are not affected by the wake-up. while in any idle or sleep mode, a wdt time-out will result in a wdt wake-up to the run mode currently specified by the scs<1:0> bits. 3.4.1 pri_idle mode this mode is unique among the three low-power idle modes, in that it does not disable the primary device clock. for timing-sensitive applications, this allows for the fastest resumption of device operation with its more accurate primary clock source, since the clock source does not have to ?warm up? or transition from another oscillator. pri_idle mode is entered from pri_run mode by setting the idlen bit and executing a sleep instruc- tion. if the device is in another run mode, set idlen first, then set the scs bits to ? 00 ? and execute sleep . although the cpu is disabled, the peripherals continue to be clocked from the primary clock source specified by the fosc<1:0> configuration bits. the osts bit remains set (see figure 3-7). when a wake event occurs, the cpu is clocked from the primary clock source. a delay of interval, t csd , is required between the wake event and when code execution starts. this is required to allow the cpu to become ready to execute instructions. after the wake-up, the osts bit remains set. the idlen and scs bits are not affected by the wake-up (see figure 3-8). 3.4.2 sec_idle mode in sec_idle mode, the cpu is disabled but the peripherals continue to be clocked from the timer1 oscillator. this mode is entered from sec_run by set- ting the idlen bit and executing a sleep instruction. if the device is in another run mode, set idlen first, then set scs<1:0> to ? 01 ? and execute sleep . when the clock source is switched to the timer1 oscillator, the primary oscillator is shutdown, the osts bit is cleared and the t1run bit is set. when a wake event occurs, the peripherals continue to be clocked from the timer1 oscillator. after an interval of t csd following the wake event, the cpu begins exe- cuting code being clocked by the timer1 oscillator. the idlen and scs bits are not affected by the wake-up; the timer1 oscillator continues to run (see figure 3-8). figure 3-7: transition timing for entry to idle mode note: the timer1 oscillator should already be running prior to entering sec_idle mode. if the t1oscen bit is not set when the sleep instruction is executed, the sleep instruction will be ignored and entry to sec_idle mode will not occur. if the timer1 oscillator is enabled, but not yet running, peripheral clocks will be delayed until the oscillator has started. in such situations, initial oscillator operation is far from stable and unpredictable operation may result. q1 peripheral program pc pc + 2 osc1 q3 q4 q1 cpu clock clock counter q2
? 2009 microchip technology inc. preliminary ds39931b-page 45 pic18f46j50 family figure 3-8: transition timing for wake from idle to run mode 3.4.3 rc_idle mode in rc_idle mode, the cpu is disabled but the peripherals continue to be clocked from the internal oscillator block. this mode allows for controllable power conservation during idle periods. from rc_run, this mode is entered by setting the idlen bit and executing a sleep instruction. if the device is in another run mode, first set idlen, then clear the scs bits and execute sleep . when the clock source is switched to the intosc block, the primary oscillator is shutdown and the osts bit is cleared. when a wake event occurs, the peripherals continue to be clocked from the internal oscillator block. after a delay of t csd following the wake event, the cpu begins executing code being clocked by the intrc. the idlen and scs bits are not affected by the wake-up. the intrc source will continue to run if either the wdt or the fscm is enabled. 3.5 exiting idle and sleep modes an exit from sleep mode, or any of the idle modes, is triggered by an interrupt, a reset or a wdt time-out. this section discusses the triggers that cause exits from power-managed modes. the clocking subsystem actions are discussed in each of the power-managed modes sections (see section 3.2 ?run modes?, section 3.3 ?sleep mode? and section 3.4 ?idle modes? ). 3.5.1 exit by interrupt any of the available interrupt sources can cause the device to exit from an idle mode, or the sleep mode, to a run mode. to enable this functionality, an interrupt source must be enabled by setting its enable bit in one of the intcon or pie registers. the exit sequence is initiated when the corresponding interrupt flag bit is set. on all exits from idle or sleep modes by interrupt, code execution branches to the interrupt vector if the gie/gieh bit (intcon<7>) is set. otherwise, code execution continues or resumes without branching (see section 8.0 ?interrupts? ). a fixed delay of interval, t csd , following the wake event, is required when leaving sleep and idle modes. this delay is required for the cpu to prepare for execu- tion. instruction execution resumes on the first clock cycle following this delay. 3.5.2 exit by wdt time-out a wdt time-out will cause different actions depending on which power-managed mode the device is, when the time-out occurs. if the device is not executing code (all idle modes and sleep mode), the time-out will result in an exit from the power-managed mode (see section 3.2 ?run modes? and section 3.3 ?sleep mode? ). if the device is executing code (all run modes), the time-out will result in a wdt reset (see section 26.2 ?watchdog timer (wdt)? ). the wdt and postscaler are cleared by one of the following events: ? executing a sleep or clrwdt instruction ? the loss of a currently selected clock source (if the fscm is enabled) 3.5.3 exit by reset exiting an idle or sleep mode by reset automatically forces the device to run from the intrc. osc1 peripheral program pc cpu clock q1 q3 q4 clock counter q2 wake event t csd
pic18f46j50 family ds39931b-page 46 preliminary ? 2009 microchip technology inc. 3.5.4 exit without an oscillator start-up delay certain exits from power-managed modes do not invoke the ost at all. there are two cases: ? pri_idle mode (where the primary clock source is not stopped) and the primary clock source is the ec mode ? pri_idle mode and the primary clock source is the ecpll mode in these instances, the primary clock source either does not require an oscillator start-up delay, since it is already running (pri_idle), or normally does not require an oscillator start-up delay (ec). however, a fixed delay of interval, t csd , following the wake event, is still required when leaving sleep and idle modes to allow the cpu to prepare for execution. instruction execution resumes on the first clock cycle following this delay. 3.6 deep sleep mode deep sleep mode brings the device into its lowest power consumption state without requiring the use of external switches to remove power from the device. during deep sleep, the on-chip v ddcore voltage regu- lator is powered down, effectively disconnecting power to the core logic of the microcontroller. on devices that support it, the deep sleep mode is entered by: ? setting the regslp (wdtcon<7>) bit ? clearing the idlen bit ? clearing the gie bit ? setting the dsen bit (dsconh<7>) ? executing the sleep instruction immediately after setting dsen (no delay or interrupts in between) in order to minimize the possibility of inadvertently enter- ing deep sleep, the dsen bit is cleared in hardware two instruction cycles after having been set. therefore, in order to enter deep sleep, the sleep instruction must be executed in the immediate instruction cycle after set- ting dsen. if dsen is not set when sleep is executed, the device will enter conventional sleep mode instead. during deep sleep, the core logic circuitry of the microcontroller is powered down to reduce leakage current. therefore, most peripherals and functions of the microcontroller become unavailable during deep sleep. however, a few specific peripherals and func- tions are powered directly from the v dd supply rail of the microcontroller, and therefore, can continue to function in deep sleep. entering deep sleep mode clears the dswakel register. however, if the real-time clock and calendar (rtcc) is enabled prior to entering deep sleep, it will continue to operate uninterrupted. the device has a dedicated brown-out reset (dsbor) and watchdog timer reset (dswdt) for monitoring voltage and time-out events in deep sleep. the dsbor and dswdt are independent of the standard bor and wdt used with other power-managed modes (run, idle and sleep). when a wake event occurs in deep sleep mode (by mclr reset, rtcc alarm, int0 interrupt, ulpwu or dswdt), the device will exit deep sleep mode and perform a power-on reset (por). when the device is released from reset, code execution will resume at the device?s reset vector. 3.6.1 preparing for deep sleep because v ddcore could fall below the sram retention voltage while in deep sleep mode, sram data could be lost in deep sleep. exiting deep sleep mode causes a por; as a result, most special function registers will reset to their default por values. applications needing to save a small amount of data throughout a deep sleep cycle can save the data to the general purpose dsgpr0 and dsgpr1 registers. the contents of these registers are preserved while the device is in deep sleep, and will remain valid throughout an entire deep sleep entry and wake-up sequence. note: since deep sleep mode powers down the microcontroller by turning off the on-chip v ddcore voltage regulator, deep sleep capability is available only on pic18fxxj members in the device family. the on-chip voltage regulator is not available in pic18lfxxj members of the device family, and therefore they do not support deep sleep.
? 2009 microchip technology inc. preliminary ds39931b-page 47 pic18f46j50 family 3.6.2 i/o pins during deep sleep during deep sleep, the general purpose i/o pins will retain their previous states. pins that are configured as inputs (tris bit set) prior to entry into deep sleep will remain high impedance during deep sleep. pins that are configured as outputs (tris bit clear) prior to entry into deep sleep will remain as output pins during deep sleep. while in this mode, they will drive the output level determined by their corresponding lat bit at the time of entry into deep sleep. when the device wakes back up, the i/o pin behavior depends on the type of wake up source. if the device wakes back up by an rtcc alarm, int0 interrupt, dswdt or ulpwu event, all i/o pins will continue to maintain their previous states, even after the device has finished the por sequence and is executing application code again. pins configured as inputs during deep sleep will remain high impedance, and pins configured as outputs will continue to drive their previous value. after waking up, the tris and lat registers will be reset, but the i/o pins will still maintain their previous states. if firmware modifies the tris and lat values for the i/o pins, they will not immediately go to the newly configured states. once the firmware clears the release bit (dsconl<0>), the i/o pins will be ?released?. this causes the i/o pins to take the states configured by their respective tris and lat bit values. if the deep sleep bor (dsbor) circuit is enabled, and v dd drops below the dsbor and v dd rail por thresh- olds, the i/o pins will be immediately released similar to clearing the release bit. all previous state informa- tion will be lost, including the general purpose dsgpr0 and dsgpr1 contents. see section 3.6.5 ?deep sleep brown-out reset (dsbor)? for additional details regarding this scenario if a mclr reset event occurs during deep sleep, the i/o pins will also be released automatically, but in this case, the dsgpr0 and dsgpr1 contents will remain valid. in all other deep sleep wake-up cases, application firmware needs to clear the release bit in order to reconfigure the i/o pins. 3.6.3 deep sleep wake-up sources the device can be awakened from deep sleep mode by a mclr , por, rtcc, int0 i/o pin interrupt, dswdt or ulpwu event. after waking, the device performs a por. when the device is released from reset, code execution will begin at the device?s reset vector. the software can determine if the wake-up was caused from an exit from deep sleep mode by reading the ds bit (wdtcon<3>). if this bit is set, the por was caused by a deep sleep exit. the ds bit must be manually cleared by the software. the software can determine the wake event source by reading the dswakeh and dswakel registers. when the application firmware is done using the dswakeh and dswakel status registers, individual bits do not need to be manually cleared before entering deep sleep again. when entering deep sleep mode, these registers are automatically cleared. 3.6.3.1 wake-up event considerations deep sleep wake-up events are only monitored while the processor is fully in deep sleep mode. if a wake-up event occurs before deep sleep mode is entered, the event status will not be reflected in the dswake registers. if the wake-up sour ce asserts prior to entering deep sleep, the cpu will either go to the interrupt vector (if the wake source has an interrupt bit and the interrupt is fully enabled) or will abort the deep sleep entry sequence by executing past the sleep instruction if the interrupt was not enabled. in this case, a wake-up event handler should be placed after the sleep instruction to process the event and re-attempt entry into deep sleep, if desired. when the device is in deep sleep with more than one wake-up source simultaneously enabled, only the first wake-up source to assert will be detected and logged in the dswakeh/dswakel status registers. 3.6.4 deep sleep watchdog timer (dswdt) deep sleep has its own dedicated wdt (dswdt) with a postscaler for time-outs of 2.1 ms to 25.7 days, configurable through the bits, dswdtps<3:0>. the dswdt can be clocked from either the intrc or the t1osc/t1cki input. if the t1osc/t1cki source will be used with a crystal, the t1oscen bit in the t1con register needs to be set prior to entering deep sleep. the reference clock source is configured through the dswdtosc bit. dswdt is enabled through the dswdten bit. entering deep sleep mode automatically clears the dswdt. see section 26.0 ?special features of the cpu? for more information.
pic18f46j50 family ds39931b-page 48 preliminary ? 2009 microchip technology inc. 3.6.5 deep sleep brown-out reset (dsbor) the deep sleep module contains a dedicated deep sleep bor (dsbor) circuit. this circuit may be optionally enabled through the dsboren configuration bit. the dsbor circuit monitors the v dd supply rail voltage. the behavior of the dsbor circuit is described in section 4.4 ?brown-out reset (bor)? . 3.6.6 rtcc peripheral and deep sleep the rtcc can operate uninterrupted during deep sleep mode. it can wake the device from deep sleep by configuring an alarm. the rtcc clock source is configured with the rtcosc bit (config3l<1>). the available reference clock sources are the intrc and t1osc/t1cki. if the intrc is used, the rtcc accuracy will directly depend on the intrc tolerance.for more information on configuring the rtcc peripheral, see section 16.0 ?real-time clock and calendar (rtcc)? . 3.6.7 typical deep sleep sequence this section gives the typical sequence for using the deep sleep mode. optional steps are indicated, and additional information is given in notes at the end of the procedure. 1. enable dswdt (optional). (1) 2. configure dswdt clock source (optional). (2) 3. enable dsbor (optional). (1) 4. enable rtcc (optional). (3) 5. configure the rtcc peripheral (optional). (3) 6. configure the ulpwu peripheral (optional). (4) 7. enable the int0 interrupt (optional). 8. context save sram data by writing to the dsgpr0 and dsgpr1 registers (optional). 9. set the regslp bit (wdtcon<7>) and clear the idlen bit (osccon<7>). 10. if using an rtcc alarm for wake-up, wait until the rtcsync bit (rtccfg<4>) is clear. 11. enter deep sleep mode by setting the dsen bit (dsconh<7>) and issuing a sleep instruction. these two instructions must be executed back to back. 12. once a wake-up event occurs, the device will perform a por reset sequence. code execution resumes at the device?s reset vector. 13. determine if the device exited deep sleep by reading the deep sleep bit, ds (wdtcon<3>). this bit will be set if there was an exit from deep sleep mode. 14. clear the deep sleep bit, ds (wdtcon<3>). 15. determine the wake-up source by reading the dswakeh and dswakel registers. 16. determine if a dsbor event occurred during deep sleep mode by reading the dsbor bit (dsconl<1>). 17. read the dsgpr0 and dsgpr1 context save registers (optional). 18. clear the release bit (dsconl<0>). 3.6.8 deep sleep fault detection if during deep sleep, the device is subjected to unusual operating conditions, such as an electrostatic discharge (esd) event, it is possible that internal cir- cuit states used by the deep sleep module could become corrupted. if this were to happen, the device may exhibit unexpected behavior, such as a failure to wake back up. in order to prevent this type of scenario from occurring, the deep sleep module includes automatic self-monitoring capability. during deep sleep, critical internal nodes are continuously monitored in order to detect possible fault conditions (which would not ordinarily occur). if a fault condition is detected, the circuitry will set the dsflt status bit (dswakel<7>) and automatically wake the microcontroller from deep sleep, causing a por reset. during deep sleep, the fault detection circuitry is always enabled and does not require any specific configuration prior to entering deep sleep. note 1: dswdt and dsbor are enabled through the devices? configuration bits. for more information, see section 26.1 ?configuration bits? . 2: the dswdt and rtcc clock sources are selected through the devices? con- figuration bits. for more information, see section 26.1 ?configuration bits? . 3: for more information, see section 16.0 ?real-time clock and calendar (rtcc)? . 4: for more information on configuring this peripheral, see section 3.7 ?ultra low-power wake-up? .
? 2009 microchip technology inc. preliminary ds39931b-page 49 pic18f46j50 family 3.6.9 deep sleep mode registers deep sleep mode registers are provided in register 3-1 through register 3-6. register 3-1: dsconh: deep sleep contro l high byte register (banked f4dh) r/w-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 dsen (1) ? ? ? ? (reserved) dsulpen rtcwdis bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 dsen: deep sleep enable bit (1) 1 = deep sleep mode is entered on a sleep command 0 = sleep mode is entered on a sleep command bit 6-3 unimplemented: read as ? 0 ? bit 2 (reserved): always write ? 0 ? to this bit bit 1 dsulpen: ultra low-power wake-up module enable bit 1 = ulpwu module is enabled in deep sleep 0 = ulpwu module is disabled in deep sleep bit 0 rtcwdis: rtcc wake-up disable bit 1 = wake-up from rtcc is disabled 0 = wake-up from rtcc is enabled note 1: in order to enter deep sleep, sleep must be executed immediately after setting dsen. register 3-2: dsconl: deep sleep low byte control register (banked f4ch) u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 (1) r/w-0 (1) ? ? ? ? ? ulpwdis dsbor release bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-3 unimplemented: read as ? 0 ? bit 2 ulpwdis: ultra low-power wake-up disable bit 1 = ulpwu wake-up source is disabled 0 = ulpwu wake-up source is enabled (must also set dsulpen = 1 ) bit 1 dsbor: deep sleep bor event status bit 1 = dsboren was enabled and v dd dropped below the dsbor arming voltage during deep sleep, but did not fall below v dsbor 0 = dsboren was disabled, or v dd did not drop below the dsbor arming voltage during deep sleep bit 0 release: i/o pin state release bit upon waking from deep sleep, the i/o pins maintain their previous states. clearing this bit will release the i/o pins and allow their respective tris and lat bits to control their states. note 1: this is the value when v dd is initially applied.
pic18f46j50 family ds39931b-page 50 preliminary ? 2009 microchip technology inc. register 3-3: dsgpr0: deep sleep persistent general purpose register 0 (banked f4eh) r/w-xxxx (1) deep sleep persistent general purpose bits bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 deep sleep persistent general purpose bits contents are retained even in deep sleep mode. note 1: all register bits are maintained unless: v ddcore drops below the normal bor threshold outside of deep sleep or the device is in deep sleep and the dedicated dsbor is enabled and v dd drops below the dsbor threshold, or dsbor is enabled or disabled, but v dd is hard cycled to near v ss . register 3-4: dsgpr1: deep sleep persistent general purpose register 1 (banked f4fh) r/w-xxxx (1) deep sleep persistent general purpose bits bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 deep sleep persistent general purpose bits contents are retained even in deep sleep mode. note 1: all register bits are maintained unless: v ddcore drops below the normal bor threshold outside of deep sleep or the device is in deep sleep and the dedicated dsbor is enabled and v dd drops below the dsbor threshold, or dsbor is enabled or disabled, but v dd is hard cycled to near v ss .
? 2009 microchip technology inc. preliminary ds39931b-page 51 pic18f46j50 family register 3-5: dswakeh: deep sleep wake high byte register (banked f4bh) u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 ? ? ? ? ? ? ?dsint0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-1 unimplemented: read as ? 0 ? bit 0 dsint0: interrupt-on-change bit 1 = interrupt-on-change was asserted during deep sleep 0 = interrupt-on-change was not asserted during deep sleep register 3-6: dswakel: deep sleep wake low byte register (banked f4ah) r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-1 dsflt ? dsulp dswdt dsrtc dsmclr ? dspor bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 dsflt: deep sleep fault detected bit 1 = a deep sleep fault was detected during deep sleep 0 = a deep sleep fault was not detected during deep sleep bit 6 unimplemented: read as ? 0 ? bit 5 dsulp: ultra low-power wake-up status bit 1 = an ultra low-power wake-up event occurred during deep sleep 0 = an ultra low-power wake-up event did not occur during deep sleep bit 4 dswdt: deep sleep watchdog timer time-out bit 1 = the deep sleep watchdog timer timed out during deep sleep 0 = the deep sleep watchdog timer did not time out during deep sleep bit 3 dsrtc: real-time clock and calendar alarm bit 1 = the real-time clock/calendar triggered an alarm during deep sleep 0 = the real-time clock /calendar did not trigger an alarm during deep sleep bit 2 dsmclr: mclr event bit 1 = the mclr pin was asserted during deep sleep 0 = the mclr pin was not asserted during deep sleep bit 1 unimplemented: read as ? 0 ? bit 0 dspor: power-on reset event bit 1 = the v dd supply por circuit was active and a por event was detected (1) 0 = the v dd supply por circuit was not active, or was active, but did not detect a por event note 1: unlike the other bits in this register, this bit can be set outside of deep sleep.
pic18f46j50 family ds39931b-page 52 preliminary ? 2009 microchip technology inc. 3.7 ultra low-power wake-up the ultra low-power wake-up (ulpwu) on ra0 allows a slow falling voltage to generate an interrupt-on-change without excess current consumption. follow these steps to use this feature: 1. configure a remappable output pin to output the ulpout signal. 2. map an intx interrupt-on-change input function to the same pin as used for the ulpout output func- tion. alternatively, in step 1, configure ulpout to output onto a portb interrupt-on-change pin. 3. charge the capacitor on ra0 by configuring the ra0 pin to an output and setting it to ? 1 ?. 4. enable interrupt-on-change (pie bit) for the corresponding pin selected in step 2. 5. stop charging the capacitor by configuring ra0 as an input. 6. discharge the capacitor by setting the ulpen and ulpsink bits in the wdtcon register. 7. configure sleep mode. 8. enter sleep mode. when the voltage on ra0 drops below v il , an interrupt will be generated, which will cause the device to wake-up and execute the next instruction. this feature provides a low-power technique for periodically waking up the device from sleep mode. the time-out is dependent on the discharge time of the rc circuit on ra0. when the ulpwu module causes the device to wake-up from sleep mode, the wdtcon bit is set. when the ulpwu module causes the device to wake-up from deep sleep, the dsulp (dswakel<5>) bit is set. software can check these bits upon wake-up to determine the wake-up source. also in sleep mode, only the remappable output func- tion, ulpwu, will output this bit value to an rpn pin for externally detecting wake-up events. see example 3-1 for initializing the ulpwu module. a series resistor between ra0 and the external capacitor provides overcurrent protection for the ra0/an0/c1ina/ulpwu/rp0 pin and can allow for software calibration of the time-out (see figure 3-9). figure 3-9: serial resistor a timer can be used to measure the charge time and discharge time of the capacitor. the charge time can then be adjusted to provide the desired interrupt delay. this technique will compensate for the affects of temperature, voltage and component accuracy. the ulpwu peripheral can also be configured as a simple programmable low-voltage detect (lvd) or temperature sensor. note: for module-related bit definitions, see the wdtcon register in section 26.2 ?watchdog timer (wdt)? and the dswakel register (register 3-6). note: for more information, refer to an879, ? using the microchip ultra low-power wake-up module ? application note (ds00879). r 1 c 1 ra0
? 2009 microchip technology inc. preliminary ds39931b-page 53 pic18f46j50 family example 3-1: ultra low-power wake-up initialization //********************************************************************************* //configure a remappable output pin with interrupt capability //for ulpwu function (rp21 => rd4/int1 in this example) //********************************************************************************* rpor21 = 13;// ulpwu function mapped to rp21/rd4 rpinr1 = 21;// int1 mapped to rp21 (rd4) //*************************** //charge the capacitor on ra0 //*************************** trisabits.trisa0 = 0; portabits.ra0 = 1; for(i = 0; i < 10000; i++) nop(); //********************************** //stop charging the capacitor on ra0 //********************************** trisabits.trisa0 = 1; //***************************************** //enable the ultra low power wakeup module //and allow capacitor discharge //***************************************** wdtconbits.ulpen = 1; wdtconbits.ulpsink = 1; //****************************************** //enable interrupt for ulpw //****************************************** //for sleep //(assign the ulpout signal in the pps module to a pin //which has also been assigned an interrupt capability, //such as int1) intcon3bits.int1if = 0; intcon3bits.int1ie = 1; //******************** //configure sleep mode //******************** //for sleep oscconbits.idlen = 0; //for deep sleep oscconbits.idlen = 0; // enable deep sleep dsconhbits.dsen = 1; // note: must be set just before executing sleep(); //**************** //enter sleep mode //**************** sleep(); // for sleep, execution will resume here // for deep sleep, execution will restart at reset vector (use wdtconbits.ds to detect)
pic18f46j50 family ds39931b-page 54 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39931b-page 55 pic18f46j50 family 4.0 reset the pic18f46j50 family of devices differentiate among various kinds of reset: a) power-on reset (por) b) mclr reset during normal operation c) mclr reset during power-managed modes d) watchdog timer (wdt) reset (during execution) e) configuration mismatch (cm) f) brown-out reset (bor) g) reset instruction h) stack full reset i) stack underflow reset j) deep sleep reset this section discusses resets generated by mclr , por and bor, and covers the operation of the various start-up timers. for information on wdt resets, see section 26.2 ?watchdog timer (wdt)? . for stack reset events, see section 5.1.4.4 ?stack full and underflow resets? and for deep sleep mode, see section 3.6 ?deep sleep mode? . figure 4-1 provides a simplified block diagram of the on-chip reset circuit. 4.1 rcon register device reset events are tracked through the rcon register (register 4-1). the lower five bits of the register indicate that a specific reset event has occurred. in most cases, these bits can only be set by the event and must be cleared by the application after the event. the state of these flag bits, taken together, can be read to indicate the type of reset that just occurred. this is described in more detail in section 4.7 ?reset state of registers? . figure 4-1: simplified block diagram of on-chip reset circuit external reset mclr v dd wdt time-out v dd rise detect pwrt intrc por pulse chip_reset brown-out reset (1) reset instruction stack pointer stack full/underflow reset sleep ( )_idle 32 ms pwrt 11-bit ripple counter 66 ms s r q configuration word mismatch deep sleep reset note 1: the brown-out reset is not available in pic18f2xj50 and pic18f4xj50 devices.
pic18f46j50 family ds39931b-page 56 preliminary ? 2009 microchip technology inc. register 4-1: rcon: reset cont rol register (access fd0h) r/w-0 u-0 r/w-1 r/w-1 r-1 r-1 r/w-0 r/w-0 ipen ?cm ri to pd por bor bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ipen: interrupt priority enable bit 1 = enable priority levels on interrupts 0 = disable priority levels on interrupts (pic16cxxx compatibility mode) bit 6 unimplemented: read as ? 0 ? bit 5 cm: configuration mismatch flag bit 1 = a configuration mismatch reset has not occurred 0 = a configuration mismatch reset has occurred (must be set in software after a configuration mismatch reset occurs) bit 4 ri : reset instruction flag bit 1 = the reset instruction was not executed (set by firmware only) 0 = the reset instruction was executed causing a device reset (must be set in software after a brown-out reset occurs) bit 3 to : watchdog time-out flag bit 1 = set by power-up, clrwdt instruction or sleep instruction 0 = a wdt time-out occurred bit 2 pd : power-down detection flag bit 1 = set by power-up or by the clrwdt instruction 0 = set by execution of the sleep instruction bit 1 por : power-on reset status bit 1 = a power-on reset has not occurred (set by firmware only) 0 = a power-on reset occurred (must be set in software after a power-on reset occurs) bit 0 bor : brown-out reset status bit 1 = a brown-out reset has not occurred (set by firmware only) 0 = a brown-out reset occurred (must be set in software after a brown-out reset occurs) note 1: it is recommended that the por bit be set after a power-on reset has been detected, so that subsequent power-on resets may be detected. 2: if the on-chip voltage regulator is disabled, bor remains ? 0 ? at all times. see section 4.4.1 ?detecting bor? for more information. 3: brown-out reset is said to have occurred when bor is ? 0 ? and por is ? 1 ? (assuming that por was set to ? 1 ? by software immediately after a power-on reset).
? 2009 microchip technology inc. preliminary ds39931b-page 57 pic18f46j50 family 4.2 master clear (mclr ) the master clear reset (mclr) pin provides a method for triggering a hard external reset of the device. a reset is generated by holding the pin low. pic18 extended microcontroller devices have a noise filter in the mclr reset path, which detects and ignores small pulses. the mclr pin is not driven low by any internal resets, including the wdt. 4.3 power-on reset (por) a por condition is generated on-chip whenever v dd rises above a certain threshold. this allows the device to start in the initialized state when v dd is adequate for operation. to take advantage of the por circuitry, tie the mclr pin through a resistor (1 k to 10 k ) to v dd . this will eliminate external rc components usually needed to create a por delay. when the device starts normal operation (i.e., exits the reset condition), device operating parameters (voltage, frequency, temperature, etc.) must be met to ensure operation. if these conditions are not met, the device must be held in reset until the operating conditions are met. por events are captured by the por bit (rcon<1>). the state of the bit is set to ? 0 ? whenever a power-on reset occurs; it does not change for any other reset event. por is not reset to ? 1 ? by any hardware event. to capture multiple events, the user manually resets the bit to ? 1 ? in software following any por. 4.4 brown-out reset (bor) the ?f? devices in the pic18f46j50 family incorporate two types of bor circuits: one which monitors v ddcore and one which monitors v dd . only one bor circuit can be active at a time. when in normal run mode, idle or normal sleep modes, the bor circuit that monitors v ddcore is active and will cause the device to be held in bor if v ddcore drops below v bor (parameter d005). once v ddcore rises back above v bor , the device will be held in reset until the expiration of the power-up timer, with period, t pwrt (parameter 33). during deep sleep operation, the on-chip core voltage regulator is disabled and v ddcore is allowed to drop to v ss . if the deep sleep bor circuit is enabled by the dsboren bit (config3l<2> = 1 ), it will monitor v dd . if v dd drops below the v dsbor threshold, the device will be held in a reset state similar to por. all registers will be set back to their por reset values and the con- tents of the dsgpr0 and dsgpr1 holding registers will be lost. additionally, if any i/o pins had been configured as outputs during deep sleep, these pins will be tri-stated and the device will no longer be held in deep sleep. once the v dd voltage recovers back above the v dsbor threshold, and once the core voltage regulator achieves a v ddcore voltage above v bor , the device will begin executing code again normally, but the ds bit in the wdtcon register will not be set. the device behavior will be similar to hard cycling all power to the device. on ?lf? devices (ex: pic18lf46j50), the v ddcore bor circuit is always disabled because the internal core voltage regulator is disabled. instead of monitor- ing v ddcore , pic18lf devices in this family can still use the v dd bor circuit to monitor v dd excursions below the v dsbor threshold. the v dd bor circuit can be disabled by setting the dsboren bit = 0 . the v dd bor circuit is enabled when dsboren = 1 on ?lf? devices, or on ?f? devices while in deep sleep with dsboren = 1 . when enabled, the v dd bor cir- cuit is extremely low power (typ. 200na) during normal operation above ~2.3v on v dd . if v dd drops below this dsbor arming level when the v dd bor circuit is enabled, the device may begin to consume additional current (typ. 50 a) as internal features of the circuit power-up. the higher current is necessary to achieve more accurate sensing of the v dd level. however, the device will not enter reset until v dd falls below the v dsbor threshold. 4.4.1 detecting bor the bor bit always resets to ? 0 ? on any v ddcore bor or por event. this makes it difficult to determine if a brown-out reset event has occurred just by reading the state of bor alone. a more reliable method is to simultaneously check the state of both por and bor . this assumes that the por bit is reset to ? 1 ? in software immediately after any power-on reset event. if bor is ? 0 ? while por is ? 1 ?, it can be reliably assumed that a brown-out reset event has occurred. if the voltage regulator is disabled (lf device), the v ddcore bor functionality is disabled. in this case, the bor bit cannot be used to determine a brown-out reset event. the bor bit is still cleared by a power-on reset event.
pic18f46j50 family ds39931b-page 58 preliminary ? 2009 microchip technology inc. 4.5 configuration mismatch (cm) the configuration mismatch (cm) reset is designed to detect, and attempt to recover from, random memory corrupting events. these include electrostatic discharge (esd) events, which can cause widespread single-bit changes throughout the device, and result in catastrophic failure. in pic18fxxj flash devices, the device configuration registers (located in the configuration memory space) are continuously monitored during operation by com- paring their values to complimentary shadow registers. if a mismatch is detected between the two sets of registers, a cm reset automatically occurs. these events are captured by the cm bit (rcon<5>). the state of the bit is set to ? 0 ? whenever a cm event occurs; it does not change for any other reset event. a cm reset behaves similarly to a mclr , reset instruction, wdt time-out or stack event resets. as with all hard and power reset events, the device configuration words are reloaded from the flash configuration words in program memory as the device restarts. 4.6 power-up timer (pwrt) pic18f46j50 family devices incorporate an on-chip pwrt to help regulate the por process. the pwrt is always enabled. the main function is to ensure that the device voltage is stable before code is executed. the power-up timer (pwrt) of the pic18f46j50 family devices is a 5-bit counter which uses the intrc source as the clock input. this yields an approximate time interval of 32 x 32 s = 1 ms. while the pwrt is counting, the device is held in reset. the power-up time delay depends on the intrc clock and will vary from chip-to-chip due to temperature and process variation. see dc parameter 33 (t pwrt ) for details. 4.6.1 time-out sequence the pwrt time-out is invoked after the por pulse has cleared. the total time-out will vary based on the status of the pwrt. figure 4-2, figure 4-3, figure 4-4 and figure 4-5 all depict time-out sequences on power-up with the pwrt. since the time-outs occur from the por pulse, if mclr is kept low long enough, the pwrt will expire. bringing mclr high will begin execution immediately if a clock source is available (figure 4-4). this is useful for testing purposes, or to synchronize more than one pic18f device operating in parallel. figure 4-2: time-out sequence on power-up (mclr tied to v dd , v dd rise < t pwrt ) t pwrt v dd mclr internal por pwrt time-out internal reset
? 2009 microchip technology inc. preliminary ds39931b-page 59 pic18f46j50 family figure 4-3: time-out sequence on power-up (mclr not tied to v dd ): case 1 figure 4-4: time-out sequence on power-up (mclr not tied to v dd ): case 2 figure 4-5: slow rise time (mclr tied to v dd , v dd rise > t pwrt ) t pwrt v dd mclr internal por pwrt time-out internal reset v dd mclr internal por pwrt time-out internal reset t pwrt v dd mclr internal por pwrt time-out internal reset 0v 1v 3.3v t pwrt
pic18f46j50 family ds39931b-page 60 preliminary ? 2009 microchip technology inc. 4.7 reset state of registers most registers are unaffected by a reset. their status is unknown on por and unchanged by all other resets. the other registers are forced to a ?reset state? depending on the type of reset that occurred. most registers are not affected by a wdt wake-up, since this is viewed as the resumption of normal operation. status bits from the rcon register (cm , ri , to , pd , por and bor ) are set or cleared differently in different reset situations, as indicated in table 4-1. these bits are used in software to determine the nature of the reset. table 4-2 describes the reset states for all of the special function registers. these are categorized by por and bor, mclr and wdt resets and wdt wake-ups. table 4-1: status bits, their significance and the initialization condition for rcon register condition program counter (1) rcon register stkptr register cm ri to pd por bor stkful stkunf power-on reset 0000h 111100 0 0 reset instruction 0000h u0uuuu u u brown-out reset 0000h 1111u0 u u configuration mismatch reset 0000h 0uuuuu u u mclr reset during power-managed run modes 0000h uu1uuu u u mclr reset during power-managed idle modes and sleep mode 0000h uu10uu u u mclr reset during full-power execution 0000h uuuuuu u u stack full reset (stvren = 1 ) 0000h uuuuuu 1 u stack underflow reset (stvren = 1 ) 0000h uuuuuu u 1 stack underflow error (not an actual reset, stvren = 0 ) 0000h uuuuuu u 1 wdt time-out during full-power or power-managed run modes 0000h uu0uuu u u wdt time-out during power-managed idle or sleep modes pc + 2 uu00uu u u interrupt exit from power-managed modes pc + 2 uuu0uu u u legend: u = unchanged note 1: when the wake-up is due to an interrupt and the gieh or giel bit is set, the pc is loaded with the interrupt vector (0008h or 0018h).
? 2009 microchip technology inc. preliminary ds39931b-page 61 pic18f46j50 family table 4-2: initialization conditions for all registers register applicable devices power-on reset, brown-out reset, wake from deep sleep mclr resets wdt reset reset instruction stack resets cm resets wake-up via wdt or interrupt tosu pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---0 0000 (1) tosh pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu (1) tosl pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu (1) stkptr pic18f2xj50 pic18f4xj50 00-0 0000 uu-0 0000 uu-u uuuu (1) pclatu pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu pclath pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu pcl pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 pc + 2 (2) tblptru pic18f2xj50 pic18f4xj50 --00 0000 --00 0000 --uu uuuu tblptrh pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu tblptrl pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu tablat pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu prodh pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu prodl pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu intcon pic18f2xj50 pic18f4xj50 0000 000x 0000 000u uuuu uuuu (3) intcon2 pic18f2xj50 pic18f4xj50 1111 1111 1111 1111 uuuu uuuu (3) intcon3 pic18f2xj50 pic18f4xj50 1100 0000 1100 0000 uuuu uuuu (3) indf0 pic18f2xj50 pic18f4xj50 n/a n/a n/a postinc0 pic18f2xj50 pic18f4xj50 n/a n/a n/a postdec0 pic18f2xj50 pic18f4xj50 n/a n/a n/a preinc0 pic18f2xj50 pic18f4xj50 n/a n/a n/a plusw0 pic18f2xj50 pic18f4xj50 n/a n/a n/a fsr0h pic18f2xj50 pic18f4xj50 ---- xxxx ---- uuuu ---- uuuu fsr0l pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu wreg pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu indf1 pic18f2xj50 pic18f4xj50 n/a n/a n/a postinc1 pic18f2xj50 pic18f4xj50 n/a n/a n/a postdec1 pic18f2xj50 pic18f4xj50 n/a n/a n/a preinc1 pic18f2xj50 pic18f4xj50 n/a n/a n/a plusw1 pic18f2xj50 pic18f4xj50 n/a n/a n/a fsr1h pic18f2xj50 pic18f4xj50 ---- xxxx ---- uuuu ---- uuuu fsr1l pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu bsr pic18f2xj50 pic18f4xj50 ---- 0000 ---- 0000 ---- uuuu indf2 pic18f2xj50 pic18f4xj50 n/a n/a n/a legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 4-1 for reset value for specific condition. 5: not implemented for pic18f2xj50 devices.
pic18f46j50 family ds39931b-page 62 preliminary ? 2009 microchip technology inc. postinc2 pic18f2xj50 pic18f4xj50 n/a n/a n/a postdec2 pic18f2xj50 pic18f4xj50 n/a n/a n/a preinc2 pic18f2xj50 pic18f4xj50 n/a n/a n/a plusw2 pic18f2xj50 pic18f4xj50 n/a n/a n/a fsr2h pic18f2xj50 pic18f4xj50 ---- xxxx ---- uuuu ---- uuuu fsr2l pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu status pic18f2xj50 pic18f4xj50 ---x xxxx ---u uuuu ---u uuuu tmr0h pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu tmr0l pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu t0con pic18f2xj50 pic18f4xj50 1111 1111 1111 1111 uuuu uuuu osccon pic18f2xj50 pic18f4xj50 0110 q000 0110 q000 0110 q00u cm1con pic18f2xj50 pic18f4xj50 0001 1111 uuuu uuuu uuuu uuuu cm2con pic18f2xj50 pic18f4xj50 0001 1111 uuuu uuuu uuuu uuuu rcon (4) pic18f2xj50 pic18f4xj50 0-11 1100 0-qq qquu u-qq qquu tmr1h pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu tmr1l pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu t1con pic18f2xj50 pic18f4xj50 0000 0000 u0uu uuuu uuuu uuuu tmr2 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu pr2 pic18f2xj50 pic18f4xj50 1111 1111 1111 1111 uuuu uuuu t2con pic18f2xj50 pic18f4xj50 -000 0000 -000 0000 -uuu uuuu ssp1buf pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu ssp1add pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu ssp1msk pic18f2xj50 pic18f4xj50 1111 1111 uuuu uuuu uuuu uuuu ssp1stat pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu ssp1con1 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu ssp1con2 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu adresh pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu adresl pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu adcon0 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu adcon1 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu wdtcon pic18f2xj50 pic18f4xj50 1qq- 0000 0qq- 0000 uqq- uuuu pstr1con pic18f2xj50 pic18f4xj50 00-0 0001 00-0 0001 uu-u uuuu eccp1as pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu table 4-2: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset, wake from deep sleep mclr resets wdt reset reset instruction stack resets cm resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 4-1 for reset value for specific condition. 5: not implemented for pic18f2xj50 devices.
? 2009 microchip technology inc. preliminary ds39931b-page 63 pic18f46j50 family eccp1del pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu ccpr1h pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu ccpr1l pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu ccp1con pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu pstr2con pic18f2xj50 pic18f4xj50 00-0 0001 00-0 0001 uu-u uuuu eccp2as pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu eccp2del pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu ccpr2h pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu ccpr2l pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu ccp2con pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu ctmuconh pic18f2xj50 pic18f4xj50 0-00 000- 0-00 000- u-uu uuu- ctmuconl pic18f2xj50 pic18f4xj50 0000 00xx 0000 00xx uuuu uuuu ctmuicon pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu spbrg1 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu rcreg1 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu txreg1 pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu txsta1 pic18f2xj50 pic18f4xj50 0000 0010 0000 0010 uuuu uuuu rcsta1 pic18f2xj50 pic18f4xj50 0000 000x 0000 000x uuuu uuuu spbrg2 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu rcreg2 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu txreg2 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu txsta2 pic18f2xj50 pic18f4xj50 0000 0010 0000 0010 uuuu uuuu eecon2 pic18f2xj50 pic18f4xj50 ---- ---- ---- ---- ---- ---- eecon1 pic18f2xj50 pic18f4xj50 --00 x00- --00 u00- --00 u00- ipr3 pic18f2xj50 pic18f4xj50 1111 1111 1111 1111 uuuu uuuu pir3 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu (3) pie3 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu ipr2 pic18f2xj50 pic18f4xj50 1111 1111 1111 1111 uuuu uuuu pir2 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu (3) pie2 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu ipr1 pic18f2xj50 pic18f4xj50 1111 1111 1111 1111 uuuu uuuu pir1 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu (3) pie1 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu table 4-2: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset, wake from deep sleep mclr resets wdt reset reset instruction stack resets cm resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 4-1 for reset value for specific condition. 5: not implemented for pic18f2xj50 devices.
pic18f46j50 family ds39931b-page 64 preliminary ? 2009 microchip technology inc. rcsta2 pic18f2xj50 pic18f4xj50 0000 000x 0000 000x uuuu uuuu osctune pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu t1gcon pic18f2xj50 pic18f4xj50 0000 0x00 0000 0x00 uuuu uuuu rtcvalh pic18f2xj50 pic18f4xj50 0xxx xxxx 0uuu uuuu 0uuu uuuu rtcvall pic18f2xj50 pic18f4xj50 0xxx xxxx 0uuu uuuu 0uuu uuuu t3gcon pic18f2xj50 pic18f4xj50 0000 0x00 uuuu uxuu uuuu uxuu trise (5) pic18f2xj50 pic18f4xj50 ---- -111 ---- -111 ---- -uuu trisd (5) pic18f2xj50 pic18f4xj50 1111 1111 1111 1111 uuuu uuuu trisc pic18f2xj50 pic18f4xj50 11-- -111 11-- -111 uu-- -uuu trisb pic18f2xj50 pic18f4xj50 1111 1111 1111 1111 uuuu uuuu trisa pic18f2xj50 pic18f4xj50 111- 1111 111- 1111 uuu- uuuu alrmcfg pic18f2xj50 pic18f4xj50 0000 0000 uuuu uuuu uuuu uuuu alrmrpt pic18f2xj50 pic18f4xj50 0000 0000 uuuu uuuu uuuu uuuu alrmvalh pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu alrmvall pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu late (5) pic18f2xj50 pic18f4xj50 ---- -xxx ---- -uuu ---- -uuu latd (5) pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu latc pic18f2xj50 pic18f4xj50 xx-- -xxx uu-- -uuu uu-- -uuu latb pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu lata pic18f2xj50 pic18f4xj50 xxx- xxxx uuu- uuuu uuu- uuuu dmacon1 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu dmacon2 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu hlvdcon pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu porte (5) pic18f2xj50 pic18f4xj50 00-- -xxx uu-- -uuu uu-- -uuu portd (5) pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu portc pic18f2xj50 pic18f4xj50 xxxx -xxx uuuu -uuu uuuu -uuu portb pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu porta pic18f2xj50 pic18f4xj50 xxx- xxxx uuu- uuuu uuu- uuuu spbrgh1 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu baudcon1 pic18f2xj50 pic18f4xj50 0100 0-00 0100 0-00 uuuu u-uu spbrgh2 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu baudcon2 pic18f2xj50 pic18f4xj50 0100 0-00 0100 0-00 uuuu u-uu table 4-2: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset, wake from deep sleep mclr resets wdt reset reset instruction stack resets cm resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 4-1 for reset value for specific condition. 5: not implemented for pic18f2xj50 devices.
? 2009 microchip technology inc. preliminary ds39931b-page 65 pic18f46j50 family tmr3h pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu tmr3l pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu t3con pic18f2xj50 pic18f4xj50 0000 0000 uuuu uuuu uuuu uuuu tmr4 pic18f2xj50 pic18f4xj50 0000 0000 uuuu uuuu uuuu uuuu pr4 pic18f2xj50 pic18f4xj50 1111 1111 1111 1111 uuuu uuuu t4con pic18f2xj50 pic18f4xj50 -000 0000 -000 0000 -uuu uuuu ssp2buf pic18f2xj50 pic18f4xj50 xxxx xxxx uuuu uuuu uuuu uuuu ssp2add pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu ssp2mask pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu ssp2stat pic18f2xj50 pic18f4xj50 1111 1111 1111 1111 uuuu uuuu ssp2con1 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu ssp2con2 pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu cmstat pic18f2xj50 pic18f4xj50 ---- --11 ---- --11 ---- --uu pmaddrh (5) pic18f2xj50 pic18f4xj50 -000 0000 -000 0000 -uuu uuuu pmdout1h (5) pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu pmaddrl pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu pmdout1l pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu pmdin1h pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu pmdin1l pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu txaddrl pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu txaddrh pic18f2xj50 pic18f4xj50 ---- 0000 ---- 0000 ---- uuuu rxaddrl pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu rxaddrh pic18f2xj50 pic18f4xj50 ---- 0000 ---- 0000 ---- uuuu dmabcl pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu dmabch pic18f2xj50 pic18f4xj50 ---- --00 ---- --00 ---- --uu ucon pic18f2xj50 pic18f4xj50 -0x0 000- -0x0 000- -uuu uuu- ustat pic18f2xj50 pic18f4xj50 -xxx xxx- -xxx xxx- -uuu uuu- ueir pic18f2xj50 pic18f4xj50 0--0 0000 0--0 0000 u--u uuuu uir pic18f2xj50 pic18f4xj50 -000 0000 -000 0000 -uuu uuuu ufrmh pic18f2xj50 pic18f4xj50 ---- -xxx ---- -xxx ---- -uuu ufrml pic18f2xj50 pic18f4xj50 xxxx xxxx xxxxx xxxx uuuu uuuu pmconh pic18f2xj50 pic18f4xj50 0-00 0000 0-00 0000 u-uu uuuu pmconl pic18f2xj50 pic18f4xj50 000- 0000 000- 0000 uuu- uuuu table 4-2: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset, wake from deep sleep mclr resets wdt reset reset instruction stack resets cm resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 4-1 for reset value for specific condition. 5: not implemented for pic18f2xj50 devices.
pic18f46j50 family ds39931b-page 66 preliminary ? 2009 microchip technology inc. pmmodeh pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu pmmodel pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu pmdout2h pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu pmdout2l pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu pmdin2h pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu pmdin2l pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu pmeh pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu pmel pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu pmstath pic18f2xj50 pic18f4xj50 00-- 0000 00-- 0000 uu-- uuuu pmstatl pic18f2xj50 pic18f4xj50 10-- 1111 10-- 1111 uu-- uuuu cvrcon (5) pic18f2xj50 pic18f4xj50 0000 0000 0000 0000 uuuu uuuu ancon1 pic18f2xj50 pic18f4xj50 00-0 0000 uu-u uuuu uu-u uuuu ancon0 pic18f2xj50 pic18f4xj50 0000 0000 uuuu uuuu uuuu uuuu odcon1 pic18f2xj50 pic18f4xj50 ---- --00 ---- --uu ---- --uu odcon2 pic18f2xj50 pic18f4xj50 ---- --00 ---- --uu ---- --uu odcon3 pic18f2xj50 pic18f4xj50 ---- --00 ---- --uu ---- --uu rtccfg pic18f2xj50 pic18f4xj50 0-00 0000 u-uu uuuu u-uu uuuu rtccal pic18f2xj50 pic18f4xj50 0000 0000 uuuu uuuu uuuu uuuu refocon pic18f2xj50 pic18f4xj50 0-00 0000 u-uu uuuu u-uu uuuu padcfg1 pic18f2xj50 pic18f4xj50 ---- -000 ---- -uuu ---- -uuu ucfg pic18f2xj50 pic18f4xj50 00-0 0000 00-0 0000 uu-u uuuu uaddr pic18f2xj50 pic18f4xj50 -000 0000 -uuu uuuu -uuu uuuu ueie pic18f2xj50 pic18f4xj50 0--0 0000 0--0 0000 u--u uuuu uie pic18f2xj50 pic18f4xj50 -000 0000 -000 0000 -uuu uuuu uep15 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu uep14 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu uep13 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu uep12 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu uep11 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu uep10 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu uep9 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu uep8 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu uep7 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu table 4-2: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset, wake from deep sleep mclr resets wdt reset reset instruction stack resets cm resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 4-1 for reset value for specific condition. 5: not implemented for pic18f2xj50 devices.
? 2009 microchip technology inc. preliminary ds39931b-page 67 pic18f46j50 family uep6 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu uep5 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu uep4 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu uep3 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu uep2 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu uep1 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu uep0 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpinr24 pic18f2xj50 pic18f4xj50 ---1 1111 ---1 1111 ---u uuuu rpinr23 pic18f2xj50 pic18f4xj50 ---1 1111 ---1 1111 ---u uuuu rpinr22 pic18f2xj50 pic18f4xj50 ---1 1111 ---1 1111 ---u uuuu rpinr21 pic18f2xj50 pic18f4xj50 ---1 1111 ---1 1111 ---u uuuu rpinr17 pic18f2xj50 pic18f4xj50 ---1 1111 ---1 1111 ---u uuuu rpinr16 pic18f2xj50 pic18f4xj50 ---1 1111 ---1 1111 ---u uuuu rpinr13 pic18f2xj50 pic18f4xj50 ---1 1111 ---1 1111 ---u uuuu rpinr12 pic18f2xj50 pic18f4xj50 ---1 1111 ---1 1111 ---u uuuu rpinr8 pic18f2xj50 pic18f4xj50 ---1 1111 ---1 1111 ---u uuuu rpinr7 pic18f2xj50 pic18f4xj50 ---1 1111 ---1 1111 ---u uuuu rpinr6 pic18f2xj50 pic18f4xj50 ---1 1111 ---1 1111 ---u uuuu rpinr4 pic18f2xj50 pic18f4xj50 ---1 1111 ---1 1111 ---u uuuu rpinr3 pic18f2xj50 pic18f4xj50 ---1 1111 ---1 1111 ---u uuuu rpinr2 pic18f2xj50 pic18f4xj50 ---1 1111 ---1 1111 ---u uuuu rpinr1 pic18f2xj50 pic18f4xj50 ---1 1111 ---1 1111 ---u uuuu rpor24 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor23 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor22 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor21 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor20 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor19 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor18 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor17 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor13 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor12 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor11 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu table 4-2: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset, wake from deep sleep mclr resets wdt reset reset instruction stack resets cm resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 4-1 for reset value for specific condition. 5: not implemented for pic18f2xj50 devices.
pic18f46j50 family ds39931b-page 68 preliminary ? 2009 microchip technology inc. rpor10 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor9 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor8 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor7 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor6 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor5 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor4 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor3 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor2 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor1 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu rpor0 pic18f2xj50 pic18f4xj50 ---0 0000 ---0 0000 ---u uuuu table 4-2: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset, wake from deep sleep mclr resets wdt reset reset instruction stack resets cm resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. note 1: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 4: see table 4-1 for reset value for specific condition. 5: not implemented for pic18f2xj50 devices.
? 2009 microchip technology inc. preliminary ds39931b-page 69 pic18f46j50 family 5.0 memory organization there are two types of memory in pic18 flash microcontrollers: ? program memory ? data ram as harvard architecture devices, the data and program memories use separate busses; this allows for concurrent access of the two memory spaces. section 6.0 ?flash program memory? provides additional information on the operation of the flash program memory. 5.1 program memory organization pic18 microcontrollers implement a 21-bit program counter, which is capable of addressing a 2-mbyte program memory space. accessing a location between the upper boundary of the physically implemented memory and the 2-mbyte address returns all ? 0 ?s (a nop instruction). the pic18f46j50 family offers a range of on-chip flash program memory sizes, from 16 kbytes (up to 8,192 single-word instructions) to 64 kbytes (32,768 single-word instructions). figure 5-1 provides the program memory maps for individual family devices. figure 5-1: memory maps for pic18f46j50 family devices note: sizes of memory areas are not to scale. sizes of program memory areas ar e enhanced to show detail. unimplemented read as ? 0 ? unimplemented read as ? 0 ? unimplemented read as ? 0 ? 000000h 1ffffff 003fffh 007fffh 00ffffh pc<20:0> stack level 1 ? stack level 31 ? ? call, callw, rcall, return, retfie, retlw, 21 user memory space on-chip memory on-chip memory on-chip memory addulnk, subulnk config. words config. words config. words pic18fx4j50 pic18fx5j50 pic18fx6j50
pic18f46j50 family ds39931b-page 70 preliminary ? 2009 microchip technology inc. 5.1.1 hard memory vectors all pic18 devices have a total of three hard-coded return vectors in their program memory space. the reset vector address is the default value to which the program counter returns on all device resets; it is located at 0000h. pic18 devices also have two interrupt vector addresses for handling high-priority and low-priority interrupts. the high-priority interrupt vector is located at 0008h and the low-priority interrupt vector at 0018h. figure 5-2 provides their locations in relation to the program memory map. figure 5-2: hard vector and configuration word locations for pic18f46j50 family devices 5.1.2 flash configuration words because pic18f46j50 family devices do not have persistent configuration memory, the top four words of on-chip program memory are reserved for configuration information. on reset, the configuration information is copied into the configuration registers. the configuration words are stored in their program memory location in numerical order, starting with the lower byte of config1 at the lowest address and ending with the upper byte of config4. table 5-1 provides the actual addresses of the flash configuration word for devices in the pic18f46j50 family. figure 5-2 displays their location in the memory map with other memory vectors. additional details on the device configuration words are provided in section 26.1 ?configuration bits? . table 5-1: flash configuration word for pic18f46j50 family devices reset vector low-priority interrupt vector 0000h 0018h on-chip program memory high-priority interrupt vector 0008h 1fffffh (top of memory) (top of memory-7) flash configuration words read as ? 0 ? legend: (top of memory) represents upper boundary of on-chip program memory space (see figure 5-1 for device-specific values). shaded area represents unimplemented memory. areas are not shown to scale. device program memory (kbytes) configuration word addresses pic18f24j50 16 3ff8h to 3fffh pic18f44j50 pic18f25j50 32 7ff8h to 7fffh pic18f45j50 pic18f26j50 64 fff8h to ffffh pic18f46j50
? 2009 microchip technology inc. preliminary ds39931b-page 71 pic18f46j50 family 5.1.3 program counter the program counter (pc) specifies the address of the instruction to fetch for execution. the pc is 21 bits wide and is contained in three separate 8-bit registers. the low byte, known as the pcl register, is both readable and writable. the high byte, or pch register, contains the pc<15:8> bits; it is not directly readable or writable. updates to the pch register are performed through the pclath register. the upper byte is called pcu. this register contains the pc<20:16> bits; it is also not directly readable or writable. updates to the pcu register are performed through the pclatu register. the contents of pclath and pclatu are transferred to the program counter by any operation that writes to pcl. similarly, the upper 2 bytes of the program counter are transferred to pclath and pclatu by an operation that reads pcl. this is useful for computed offsets to the pc (see section 5.1.6.1 ?computed goto? ). the pc addresses bytes in the program memory. to prevent the pc from becoming misaligned with word instructions, the least significant bit (lsb) of pcl is fixed to a value of ? 0 ?. the pc increments by two to address sequential instructions in the program memory. the call , rcall , goto and program branch instructions write to the program counter directly. for these instructions, the contents of pclath and pclatu are not transferred to the program counter. 5.1.4 return address stack the return address stack allows any combination of up to 31 program calls and interrupts to occur. the pc is pushed onto the stack when a call or rcall instruc- tion is executed, or an interrupt is acknowledged. the pc value is pulled off the stack on a return, retlw or a retfie instruction (and on addulnk and subulnk instructions if the extended instruction set is enabled). pclatu and pclath are not affected by any of the return or call instructions. the stack operates as a 31-word by 21-bit ram and a 5-bit stack pointer (sp), stkptr. the stack space is not part of either program or data space. the stack pointer is readable and writable and the address on the top of the stack is readable and writable through the top-of-stack special function registers (sfrs). data can also be pushed to, or popped from the stack, using these registers. a call type instruction causes a push onto the stack. the stack pointer is first incremented and the location pointed to by the stack pointer is written with the contents of the pc (already pointing to the instruction following the call ). a return type instruction causes a pop from the stack. the contents of the location pointed to by the stkptr are transferred to the pc and then the stack pointer is decremented. the stack pointer is initialized to ? 00000 ? after all resets. there is no ram associated with the location corresponding to a stack pointer value of ? 00000 ?; this is only a reset value. status bits indicate if the stack is full, has overflowed or has underflowed. 5.1.4.1 top-of-stack access only the top of the return address stack (tos) is read- able and writable. a set of three registers, tosu:tosh:tosl, holds the contents of the stack location pointed to by the stkptr register (figure 5-3). this allows users to implement a software stack if necessary. after a call, rcall or interrupt (and addulnk and subulnk instructions if the extended instruction set is enabled), the software can read the pushed value by reading the tosu:tosh:tosl registers. these values can be placed on a user-defined software stack. at return time, the software can return these values to tosu:tosh:tosl and do a return. the user must disable the global interrupt enable bits while accessing the stack to prevent inadvertent stack corruption. figure 5-3: return address stack and associated registers 00011 001a34h 11111 11110 11101 00010 00001 00000 00010 return address stack <20:0> to p - o f - st a c k 000d58h tosl tosh tosu 34h 1ah 00h stkptr<4:0> top-of-stack registers stack pointer
pic18f46j50 family ds39931b-page 72 preliminary ? 2009 microchip technology inc. 5.1.4.2 return stack pointer (stkptr) the stkptr register (register 5-1) contains the stack pointer value, the stkful (stack full) and the stkunf (stack underflow) status bits. the value of the stack pointer can be 0 through 31. the stack pointer increments before values are pushed onto the stack and decrements after values are popped off the stack. on reset, the stack pointer value will be zero. the user may read and write the stack pointer value. this feature can be used by a real-time operating system (rtos) for return stack maintenance. after the pc is pushed onto the stack 31 times (without popping any values off the stack), the stkful bit is set. the stkful bit is cleared by software or by a power-on reset (por). the action that takes place when the stack becomes full depends on the state of the stack overflow reset enable (stvren) configuration bit. refer to section 26.1 ?configuration bits? for device configuration bits? description. if stvren is set (default), the 31 st push will push the (pc + 2) value onto the stack, set the stkful bit and reset the device. the stkful bit will remain set and the stack pointer will be set to zero. if stvren is cleared, the stkful bit will be set on the 31 st push and the stack pointer will increment to 31. any additional pushes will not overwrite the 31 st push and the stkptr will remain at 31. when the stack has been popped enough times to unload the stack, the next pop will return zero to the pc and set the stkunf bit, while the stack pointer remains at zero. the stkunf bit will remain set until cleared by software or until a por occurs. 5.1.4.3 push and pop instructions since the top-of-stack is readable and writable, the ability to push values onto the stack and pull values off the stack, without disturbing normal program execution is necessary. the pic18 instruction set includes two instructions, push and pop , that permit the tos to be manipulated under software control. tosu, tosh and tosl can be modified to place data or a return address on the stack. the push instruction places the current pc value onto the stack. this increments the stack pointer and loads the current pc value onto the stack. the pop instruction discards the current tos by decrementing the stack pointer. the previous value pushed onto the stack then becomes the tos value. note: returning a value of zero to the pc on an underflow has the effect of vectoring the program to the reset vector, where the stack conditions can be verified and appropriate actions can be taken. this is not the same as a reset, as the contents of the sfrs are not affected. register 5-1: stkptr: stack pointer register (access ffch) r/c-0 r/c-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 stkful (1) stkunf (1) ? sp4 sp3 sp2 sp1 sp0 bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 stkful: stack full flag bit (1) 1 = stack became full or overflowed 0 = stack has not become full or overflowed bit 6 stkunf: stack underflow flag bit (1) 1 = stack underflow occurred 0 = stack underflow did not occur bit 5 unimplemented: read as ? 0 ? bit 4-0 sp<4:0>: stack pointer location bits note 1: bits 7 and 6 are cleared by user software or by a por.
? 2009 microchip technology inc. preliminary ds39931b-page 73 pic18f46j50 family 5.1.4.4 stack full and underflow resets device resets on stack overflow and stack underflow conditions are enabled by setting the stvren bit in configuration register 1l. when stvren is set, a full or underflow condition sets the appropriate stkful or stkunf bit and then causes a device reset. when stvren is cleared, a full or underflow condition sets the appropriate stkful or stkunf bit, but does not cause a device reset. the stkful or stkunf bits are cleared by the user software or a por. 5.1.5 fast register stack (frs) a fast register stack (frs) is provided for the status, wreg and bsr registers to provide a ?fast return? option for interrupts. this stack is only one level deep and is neither readable nor writable. it is loaded with the current value of the corresponding register when the processor vectors for an interrupt. all inter- rupt sources push values into the stack registers. the values in the registers are then loaded back into the working registers if the retfie , fast instruction is used to return from the interrupt. if both low-priority and high-priority interrupts are enabled, the stack registers cannot be used reliably to return from low-priority interrupts. if a high-priority interrupt occurs while servicing a low-priority interrupt, the stack register values stored by the low-priority interrupt will be overwritten. in these cases, users must save the key registers in software during a low-priority interrupt. if interrupt priority is not used, all interrupts may use the frs for returns from interrupt. if no interrupts are used, the frs can be used to restore the status, wreg and bsr registers at the end of a subroutine call. to use the fast register stack for a subroutine call, a call label, fast instruction must be executed to save the status, wreg and bsr registers to the fast register stack. a return , fast instruction is then executed to restore these registers from the frs. example 5-1 provides a source code example that uses the frs during a subroutine call and return. example 5-1: fast register stack code example 5.1.6 look-up tables in program memory there may be programming situations that require the creation of data structures or look-up tables in program memory. for pic18 devices, look-up tables can be implemented in two ways: ? computed goto ? table reads 5.1.6.1 computed goto a computed goto is accomplished by adding an offset to the pc. an example is shown in example 5-2. a look-up table can be formed with an addwf pcl instruction and a group of retlw nn instructions. the w register is loaded with an offset into the table before executing a call to that table. the first instruction of the called routine is the addwf pcl instruction. the next executed instruction will be one of the retlw nn instructions that returns the value ? nn ? to the calling function. the offset value (in wreg) specifies the number of bytes that the pc should advance and should be multiples of 2 (lsb = 0 ). in this method, only one byte may be stored in each instruction location, room on the return address stack is required. example 5-2: computed goto using an offset value 5.1.6.2 table reads a better method of storing data in program memory allows two bytes to be stored in each instruction location. look-up table data may be stored two bytes per program word while programming. the table pointer (tblptr) specifies the byte address, and the table latch (tablat) contains the data that is read from the program memory. data is transferred from program memory one byte at a time. table read operation is discussed further in section 6.1 ?table reads and table writes? . call sub1, fast ;status, wreg, bsr ;saved in fast register ;stack ? ? sub1 ? ? return fast ;restore values saved ;in fast register stack movf offset, w call table org nn00h table addwf pcl retlw nnh retlw nnh retlw nnh . . .
pic18f46j50 family ds39931b-page 74 preliminary ? 2009 microchip technology inc. 5.2 pic18 instruction cycle 5.2.1 clocking scheme the microcontroller clock input, whether from an internal or external source, is internally divided by ?4? to generate four non-overlapping quadrature clocks (q1, q2, q3 and q4). internally, the pc is incremented on every q1; the instruction is fetched from the program memory and latched into the instruction register (ir) during q4. the instruction is decoded and executed during the following q1 through q4. figure 5-4 illustrates the clocks and instruction execution flow. 5.2.2 instruction flow/pipelining an ?instruction cycle? consists of four q cycles, q1 through q4. the instruction fetch and execute are pipe- lined in such a manner that a fetch takes one instruction cycle, while the decode and execute takes another instruction cycle. however, due to the pipelining, each instruction effectively executes in one cycle. if an instruction causes the pc to change (e.g., goto ), then two cycles are required to complete the instruction (example 5-3). a fetch cycle begins with the pc incrementing in q1. in the execution cycle, the fetched instruction is latched into the ir in cycle q1. this instruction is then decoded and executed during the q2, q3 and q4 cycles. data memory is read during q2 (operand read) and written during q4 (destination write). figure 5-4: clock/instruction cycle example 5-3: instruction pipeline flow q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 q1 q2 q3 q4 pc osc2/clko (rc mode) pc pc + 2 pc + 4 fetch inst (pc) execute inst (pc ? 2) fetch inst (pc + 2) execute inst (pc) fetch inst (pc + 4) execute inst (pc + 2) internal phase clock note: all instructions are single-cycle, except for any program branches. these take two cycles since the fetch instruction is ?flushed? from the pipeline while the new instruction is being fetched and then executed. t cy 0t cy 1t cy 2t cy 3t cy 4t cy 5 1. movlw 55h fetch 1 execute 1 2. movwf portb fetch 2 execute 2 3. bra sub_1 fetch 3 execute 3 4. bsf porta, bit3 (forced nop) fetch 4 flush ( nop ) 5. instruction @ address sub_1 fetch sub_1 execute sub_1
? 2009 microchip technology inc. preliminary ds39931b-page 75 pic18f46j50 family 5.2.3 instructions in program memory the program memory is addressed in bytes. instruc- tions are stored as 2 bytes or 4 bytes in program memory. the least significant byte (lsb) of an instruction word is always stored in a program memory location with an even address (lsb = 0 ). to maintain alignment with instruction boundaries, the pc increments in steps of 2 and the lsb will always read ? 0 ? (see section 5.1.3 ?program counter? ). figure 5-5 provides an example of how instruction words are stored in the program memory. the call and goto instructions have the absolute program memory address embedded into the instruc- tion. since instructions are always stored on word boundaries, the data contained in the instruction is a word address. the word address is written to pc<20:1>, which accesses the desired byte address in program memory. instruction #2 in figure 5-5 displays how the instruction, goto 0006h , is encoded in the program memory. program branch instructions, which encode a relative address offset, operate in the same manner. the offset value stored in a branch instruction represents the number of single-word instructions that the pc will be offset by. section 27.0 ?instruction set summary? provides further details of the instruction set. figure 5-5: instructions in program memory 5.2.4 two-word instructions the standard pic18 instruction set has four two-word instructions: call , movff , goto and lsfr . in all cases, the second word of the instructions always has ? 1111 ? as its four most significant bits (msbs); the other 12 bits are literal data, usually a data memory address. the use of ? 1111 ? in the 4 msbs of an instruction specifies a special form of nop . if the instruction is executed in proper sequence immediately after the first word, the data in the second word is accessed and used by the instruction sequence. if the first word is skipped for some reason and the second word is executed by itself, a nop is executed instead. this is necessary for cases when the two-word instruction is preceded by a conditional instruction that changes the pc. example 5-4 illustrates how this works. example 5-4: two-word instructions word address lsb = 1 lsb = 0 program memory byte locations 000000h 000002h 000004h 000006h instruction 1: movlw 055h 0fh 55h 000008h instruction 2: goto 0006h efh 03h 00000ah f0h 00h 00000ch instruction 3: movff 123h, 456h c1h 23h 00000eh f4h 56h 000010h 000012h 000014h note: see section 5.5 ?program memory and the extended instruction set? for infor- mation on two-word instructions in the extended instruction set. case 1: object code source code 0110 0110 0000 0000 tstfsz reg1 ; is ram location 0? 1100 0001 0010 0011 movff reg1, reg2 ; no, skip this word 1111 0100 0101 0110 ; execute this word as a nop 0010 0100 0000 0000 addwf reg3 ; continue code case 2: object code source code 0110 0110 0000 0000 tstfsz reg1 ; is ram location 0? 1100 0001 0010 0011 movff reg1, reg2 ; yes, execute this word 1111 0100 0101 0110 ; 2nd word of instruction 0010 0100 0000 0000 addwf reg3 ; continue code
pic18f46j50 family ds39931b-page 76 preliminary ? 2009 microchip technology inc. 5.3 data memory organization the data memory in pic18 devices is implemented as static ram. each register in the data memory has a 12-bit address, allowing up to 4096 bytes of data memory. the memory space is divided into as many as 16 banks that contain 256 bytes each. the pic18f46j50 family implements all available banks and provides 3.8 kbytes of data memory available to the user. figure 5-6 provides the data memory organization for the devices. the data memory contains special function registers (sfrs) and general purpose registers (gprs). the sfrs are used for control and status of the controller and peripheral functions, while gprs are used for data storage and scratchpad operations in the user?s application. any read of an unimplemented location will read as ? 0 ?s. the instruction set and architecture allow operations across all banks. the entire data memory may be accessed by direct, indirect or indexed addressing modes. addressing modes are discussed later in this section. to ensure that commonly used registers (select sfrs and select gprs) can be accessed in a single cycle, pic18 devices implement an access bank. this is a 256-byte memory space that provides fast access to select sfrs and the lower portion of gpr bank 0 with- out using the bsr. section 5.3.3 ?access bank? provides a detailed description of the access ram. 5.3.1 usb ram all 3.8 kbytes of the gprs implemented on the pic18f46j50 family devices can be accessed simulta- neously by both the microcontroller core and the serial interface engine (sie) of the usb module. the sie uses a dedicated usb dma engine to store any incoming data packets (out/setup) directly into main system data memory. for in data packets, the sie can directly read the contents of general purpose sram and use it to create usb data packets that are sent to the host. sram bank 4 (400h-4ffh) is unique. in addition to being accessible by both the microcontroller core and the usb module, the sie uses a portion of bank 4 as special function registers (sfrs). these sfrs compose the buffer descriptor table (bdt). when the usb module is enabled, the bdt registers are used to control the behavior of the usb dma oper- ation for each of the enabled endpoints. the exact number of sram locations that are used for the bdt depends on how many endpoints are enabled and what usb ping-pong mode is used. for more details, see section 21.3 ?usb ram? . when the usb module is disabled, these sram loca- tions behave like any other gpr location. when the usb module is disabled, these locations may be used for any general purpose. 5.3.2 bank select register large areas of data memory require an efficient addressing scheme to make rapid access to any address possible. ideally, this means that an entire address does not need to be provided for each read or write operation. for pic18 devices, this is accom- plished with a ram banking scheme. this divides the memory space into 16 contiguous banks of 256 bytes. depending on the instruction, each location can be addressed directly by its full 12-bit address, or an 8-bit low-order address and a 4-bit bank pointer. most instructions in the pic18 instruction set make use of the bank pointer, known as the bank select register (bsr). this sfr holds the 4 msbs of a location?s address; the instruction itself includes the 8 lsbs. only the four lower bits of the bsr are implemented (bsr<3:0>). the upper four bits are unused; they will always read ? 0 ? and cannot be written to. the bsr can be loaded directly by using the movlb instruction. the value of the bsr indicates the bank in data memory. the 8 bits in the instruction show the location in the bank and can be thought of as an offset from the bank?s lower boundary. the relationship between the bsr?s value and the bank division in data memory is illustrated in figure 5-7. since, up to 16 registers may share the same low-order address, the user must always be careful to ensure that the proper bank is selected before performing a data read or write. for example, writing what should be program data to an 8-bit address of f9h while the bsr is 0fh, will end up resetting the pc. while any bank can be selected, only those banks that are actually implemented can be read or written to. writes to unimplemented banks are ignored, while reads from unimplemented banks will return ? 0 ?s. even so, the status register will still be affected as if the operation was successful. the data memory map in figure 5-6 indicates which banks are implemented. in the core pic18 instruction set, only the movff instruction fully specifies the 12-bit address of the source and target registers. this instruction ignores the bsr completely when it executes. all other instructions include only the low-order address as an operand and must use either the bsr or the access bank to locate their target registers. note: the operation of some aspects of data memory are changed when the pic18 extended instruction set is enabled. see section 5.6 ?data memory and the extended instruction set? for more information. note: in and out are always from the usb host's perspective.
? 2009 microchip technology inc. preliminary ds39931b-page 77 pic18f46j50 family figure 5-6: data memory map for pic18f46j50 family devices bank 0 bank 1 bank 14 bank 15 data memory map bsr3:bsr0 = 0000 = 0001 = 1111 060h 05fh f5fh fffh 00h 5fh 60h ffh access bank when a = 0 : the bsr is ignored and the access bank is used. the first 96 bytes are general purpose ram (from bank 0). the remaining 160 bytes are special function registers (from bank 15). when a = 1 : the bsr specifies the bank used by the instruction. ebfh f00h effh 1ffh 100h 0ffh 000h access ram (1) ffh 00h ffh 00h ffh 00h gpr (1) gpr (1) access ram high access ram low bank 2 = 0010 (sfrs) 2ffh 200h bank 3 ffh 00h gpr (1) ffh = 0011 = 1101 gpr, bdt (1) gpr (1) gpr (1) gpr (1) gpr (1) gpr (1) gpr (1) gpr (1) gpr (1) gpr (1) 4ffh 400h 5ffh 500h 3ffh 300h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h 00h gpr (1) gpr (1) = 0110 = 0111 = 1010 = 1100 = 1000 = 0101 = 1001 = 1011 = 0100 bank 4 bank 5 bank 6 bank 7 bank 8 bank 9 bank 10 bank 11 bank 12 bank 13 = 1110 6ffh 600h 7ffh 700h 8ffh 800h 9ffh 900h affh a00h bffh b00h cffh c00h dffh d00h e00h note 1: these banks also serve as ram buffers for usb operation. see section 5.3.1 ?usb ram? for more information. 2: addresses ec0h through f5fh are not par t of the access bank. either the banked or the movff instruction should be used to access these sfrs. c0h 60h access sfrs non-access sfr (2) non-access sfr (2) ec0h
pic18f46j50 family ds39931b-page 78 preliminary ? 2009 microchip technology inc. figure 5-7: use of the bank select register (direct addressing) 5.3.3 access bank while the use of the bsr with an embedded 8-bit address allows users to address the entire range of data memory, it also means that the user must always ensure that the correct bank is selected. otherwise, data may be read from or written to the wrong location. this can be disastrous if a gpr is the intended target of an operation, but an sfr is written to instead. verifying and/or changing the bsr for each read or write to data memory can become very inefficient. to streamline access for the most commonly used data memory locations, the data memory is configured with an access bank, which allows users to access a mapped block of memory without specifying a bsr. the access bank consists of the first 96 bytes of memory (00h-5fh) in bank 0 and the last 160 bytes of memory (60h-ffh) in bank 15. the lower half is known as the access ram and is composed of gprs. the upper half is where the device?s sfrs are mapped. these two areas are mapped contiguously in the access bank and can be addressed in a linear fashion by an 8-bit address (figure 5-6). the access bank is used by core pic18 instructions that include the access ram bit (the ?a? parameter in the instruction). when ?a? is equal to ? 1 ?, the instruction uses the bsr and the 8-bit address included in the opcode for the data memory address. when ?a? is ? 0 ?, however, the instruction is forced to use the access bank address map; the current value of the bsr is ignored entirely. using this ?forced? addressing allows the instruction to operate on a data address in a single cycle without updating the bsr first. for 8-bit addresses of 60h and above, this means that users can evaluate and operate on sfrs more efficiently. the access ram below 60h is a good place for data values that the user might need to access rapidly, such as immediate computational results or common program variables. access ram also allows for faster and more code efficient context saving and switching of variables. the mapping of the access bank is slightly different when the extended instruction set is enabled (xinst configuration bit = 1 ). this is discussed in more detail in section 5.6.3 ?mapping the access bank in indexed literal offset mode? . 5.3.4 general purpose register file pic18 devices may have banked memory in the gpr area. this is data ram, which is available for use by all instructions. gprs start at the bottom of bank 0 (address 000h) and grow upward toward the bottom of the sfr area. gprs are not initialized by a por and are unchanged on all other resets. note 1: the access ram bit of the instruction can be used to force an override of the selected bank (bsr<3:0>) to the registers of the access bank. 2: the movff instruction embeds the entire 12-bit address in the instruction. data memory bank select (2) 7 0 from opcode (2) 0000 000h 100h 200h 300h f00h e00h fffh bank 0 bank 1 bank 2 bank 14 bank 15 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh bank 3 through bank 13 0010 11111111 7 0 bsr (1) 11111111
? 2009 microchip technology inc. preliminary ds39931b-page 79 pic18f46j50 family 5.3.5 special function registers the sfrs are registers used by the cpu and periph- eral modules for controlling the desired operation of the device. these registers are implemented as static ram. sfrs start at the top of data memory (fffh) and extend downward to occupy more than the top half of bank 15 (f40h to fffh). table 5-2, table 5-3 and table 5-4 provide a list of these registers. the sfrs can be classified into two sets: those associated with the ?core? device functionality (alu, resets and interrupts) and those related to the peripheral functions. the reset and interrupt registers are described in their corresponding chapters, while the alu?s status register is described later in this section. registers related to the operation of the peripheral features are described in t he chapter for that peripheral. the sfrs are typically distributed among the peripherals whose functions they control. unused sfr locations are unimplemented and read as ? 0 ?s note: the sfrs located between ec0h and f5fh are not part of the access bank. either banked instructions (using bsr) or the movff instruction should be used to access these locations. when program- ming in mplab c18, the compiler will automatically use the appropriate addressing mode. table 5-2: access bank special function register map address name address name address name address name address name fffh tosu fdfh indf2 (1) fbfh pstr1con f9fh ipr1 f7fh spbrgh1 ffeh tosh fdeh postinc2 (1) fbeh eccp1as f9eh pir1 f7eh baudcon1 ffdh tosl fddh postdec2 (1) fbdh eccp1del f9dh pie1 f7dh spbrgh2 ffch stkptr fdch preinc2 (1) fbch ccpr1h f9ch rcsta2 f7ch baudcon2 ffbh pclatu fdbh plusw2 (1) fbbh ccpr1l f9bh osctune f7bh tmr3h ffah pclath fdah fsr2h fbah ccp1con f9ah t1gcon f7ah tmr3l ff9h pcl fd9h fsr2l fb9h pstr2con f99h rtcvalh f79h t3con ff8h tblptru fd8h status fb8h eccp2as f98h rtcvall f78h tmr4 ff7h tblptrh fd7h tmr0h fb7h eccp2del f97h t3gcon f77h pr4 ff6h tblptrl fd6h tmr0l fb6h ccpr2h f96h trise f76h t4con ff5h tablat fd5h t0con fb5h ccpr2l f95h trisd f75h ssp2buf ff4h prodh fd4h ? (5) fb4h ccp2con f94h trisc f74h ssp2add (3) ff3h prodl fd3h osccon fb3h ctmuconh f93h trisb f73h ssp2stat ff2h intcon fd2h cm1con fb2h ctmuconl f92h trisa f72h ssp2con1 ff1h intcon2 fd1h cm2con fb1h ctmuicon f91h alrmcfg f71h ssp2con2 ff0h intcon3 fd0h rcon fb0h spbrg1 f90h alrmrpt f70h cmstat fefh indf0 (1) fcfh tmr1h fafh rcreg1 f8fh alrmvalh f6fh pmaddrh (2,4) feeh postinc0 (1) fceh tmr1l faeh txreg1 f8eh alrmvall f6eh pmaddrl (2,4) fedh postdec0 (1) fcdh t1con fadh txsta1 f8dh late (2) f6dh pmdin1h (2) fech preinc0 (1) fcch tmr2 fach rcsta1 f8ch latd (2) f6ch pmdin1l (2) febh plusw0 (1) fcbh pr2 fabh spbrg2 f8bh latc f6bh txaddrl feah fsr0h fcah t2con faah rcreg2 f8ah latb f6ah txaddrh fe9h fsr0l fc9h ssp1buf fa9h txreg2 f89h lata f69h rxaddrl fe8h wreg fc8h ssp1add (3) fa8h txsta2 f88h dmacon1 f68h rxaddrh fe7h indf1 (1) fc7h ssp1stat fa7h eecon2 f87h ? (5) f67h dmabcl fe6h postinc1 (1) fc6h ssp1con1 fa6h eecon1 f86h dmacon2 f66h dmabch fe5h postdec1 (1) fc5h ssp1con2 fa5h ipr3 f85h hlvdcon f65h ucon fe4h preinc1 (1) fc4h adresh fa4h pir3 f84h porte (2) f64h ustat fe3h plusw1 (1) fc3h adresl fa3h pie3 f83h portd (2) f63h ueir fe2h fsr1h fc2h adcon0 fa2h ipr2 f82h portc f62h uir fe1h fsr1l fc1h adcon1 fa1h pir2 f81h portb f61h ufrmh fe0h bsr fc0h wdtcon fa0h pie2 f80h porta f60h ufrml note 1: this is not a physical register. 2: this register is not available on 28-pin devices. 3: sspxadd and sspxmsk share the same address. 4: pmaddrh and pmdouth share the same address and pm addrl and pmdoutl share the same address. pmaddrx is used in master modes an d pmdoutx is used in slave modes. 5: reserved: do not write to this location.
pic18f46j50 family ds39931b-page 80 preliminary ? 2009 microchip technology inc. table 5-3: non-access bank special function register map address name address name address name address name address name f5fh pmconh f3fh rtccfg f1fh ? effh ppscon edfh ? f5eh pmconl f3eh rtccal f1eh ? efeh rpinr24 edeh rpor24 (1) f5dh pmmodeh f3dh refocon f1dh ? efdh rpinr23 eddh rpor23 (1) f5ch pmmodel f3ch padcfg1 f1ch ? efch rpinr22 edch rpor22 (1) f5bh pmdout2h f3bh ?f1bh ? efbh rpinr21 edbh rpor21 (1) f5ah pmdout2l f3ah ?f1ah ?efah ? edah rpor20 (1) f59h pmdin2h f39h ucfg f19h ?ef9h ? ed9h rpor19 (1) f58h pmdin2l f38h uaddr f18h ?ef8h ? ed8h rpor18 f57h pmeh f37h ueie f17h ? ef7h rpinr17 ed7h rpor17 f56h pmel f36h uie f16h ? ef6h rpinr16 ed6h ? f55h pmstath f35h uep15 f15h ?ef5h ?ed5h ? f54h pmstatl f34h uep14 f14h ?ef4h ?ed4h ? f53h cvrcon f33h uep13 f13h ? ef3h rpinr13 ed3h rpor13 f52h tclkcon f32h uep12 f12h ? ef2h rpinr12 ed2h rpor12 f51h ?f31huep11f11h ?ef1h ? ed1h rpor11 f50h ? f30h uep10 f10h ?ef0h ? ed0h rpor10 f4fh dsgpr1 f2fh uep9 f0fh ? eefh ? ecfh rpor9 f4eh dsgpr0 f2eh uep8 f0eh ? eeeh rpinr8 eceh rpor8 f4dh dsconh f2dh uep7 f0dh ? eedh rpinr7 ecdh rpor7 f4ch dsconl f2ch uep6 f0ch ? eech rpinr6 ecch rpor6 f4bh dswakeh f2bh uep5 f0bh ? eebh ? ecbh rpor5 f4ah dswakel f2ah uep4 f0ah ? eeah rpinr4 ecah rpor4 f49h ancon1 f29h uep3 f09h ? ee9h rpinr3 ec9h rpor3 f48h ancon0 f28h uep2 f08h ? ee8h rpinr2 ec8h rpor2 f47h ? f27h uep1 f07h ? ee7h rpinr1 ec7h rpor1 f46h ? f26h uep0 f06h ? ee6h ? ec6h rpor0 f45h ?f25h ? f05h ? ee5h ?ec5h ? f44h ?f24h ? f04h ? ee4h ?ec4h ? f43h ?f23h ? f03h ? ee3h ?ec3h ? f42h odcon1 f22h ? f02h ? ee2h ?ec2h ? f41h odcon2 f21h ? f01h ? ee1h ?ec1h ? f40h odcon3 f20h ? f00h ? ee0h ? ec0h ? note 1: this register is not av ailable on 28-pin devices.
? 2009 microchip technology inc. preliminary ds39931b-page 81 pic18f46j50 family 5.3.5.1 context defined sfrs there are several registers that share the same address in the sfr space. the register's definition and usage depends on the operating mode of its associated peripheral. these registers are: ? sspxadd and sspxmsk: these are two separate hardware registers, accessed through a single sfr address. the operating mode of the mssp modules determines which register is being accessed. see section 18.5.3.4 ?7-bit address masking mode? for additional details. ? pmaddrh/l and pmdout2h/l: in this case, these named buffer pairs are actually the same physical registers. the parallel master port (pmp) module?s operating mode determines what func- tion the registers take on. see section 10.1.2 ?data registers? for additional details. table 5-4: register file summary (pic18f46j50 family) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: tosu ? ? ? top-of-stack upper byte (tos<20:16>) ---0 0000 61, 73 tosh top-of-stack high byte (tos<15:8>) 0000 0000 61, 71 tosl top-of-stack low byte (tos<7:0>) 0000 0000 61, 71 stkptr stkful stkunf ? sp4 sp3 sp2 sp1 sp0 00-0 0000 61, 72 pclatu ? ?bit 21 (1) holding register for pc<20:16> ---0 0000 61, 71 pclath holding register for pc<15:8> 0000 0000 61, 71 pcl pc low byte (pc<7:0>) 0000 0000 61, 71 tblptru ? ? bit 21 program memory table pointer upper byte (tblptr<20:16>) --00 0000 61, 104 tblptrh program memory table pointer high byte (tblptr<15:8>) 0000 0000 61, 104 tblptrl program memory table pointer low byte (tblptr<7:0>) 0000 0000 61, 104 tablat program memory table latch 0000 0000 61, 104 prodh product register high byte xxxx xxxx 61, 105 prodl product register low byte xxxx xxxx 61, 105 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 61, 109 intcon2 rbpu intedg0 intedg1 intedg2 intedg3 tmr0ip int3ip rbip 1111 1111 61, 109 intcon3 int2ip int1ip int3ie int2ie int1ie int3if int2if int1if 1100 0000 61, 109 indf0 uses contents of fsr0 to address data memory ? value of fsr0 not changed (not a physical register) n/a 61, 90 postinc0 uses contents of fsr0 to address data memory ? value of fsr0 post-incremented (not a physical register) n/a 61, 91 postdec0 uses contents of fsr0 to address data memory ? value of fsr0 post-decremented (not a physical register) n/a 61, 91 preinc0 uses contents of fsr0 to address data memory ? value of fsr0 pre-incremented (not a physical register) n/a 61, 91 plusw0 uses contents of fsr0 to address data memory ? value of fsr0 pre-incremented (not a physical register) ? value of fsr0 offset by w n/a 61, 91 fsr0h ? ? ? ? indirect data memory address pointer 0 high byte ---- xxxx 61, 90 fsr0l indirect data memory address pointer 0 low byte xxxx xxxx 61, 90 wreg working register xxxx xxxx 61, 73 indf1 uses contents of fsr1 to address data memory ? value of fsr1 not changed (not a physical register) n/a 61, 90 postinc1 uses contents of fsr1 to address data memory ? value of fsr1 post-incremented (not a physical register) n/a 61, 91 postdec1 uses contents of fsr1 to address data memory ? value of fsr1 post-decremented (not a physical register) n/a 61, 91 preinc1 uses contents of fsr1 to address data memory ? value of fsr1 pre-incremented (not a physical register) n/a 62, 91 plusw1 uses contents of fsr1 to address data memory ? value of fsr1 pre-incremented (not a physical register) ? value of fsr1 offset by w n/a 61, 91 legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition, r = reserved. bold indicates shared access sfrs. note 1: bit 21 of the pc is only available in serial programming (sp) modes. 2: reset value is ? 0 ? when two-speed start-up is enabled and ? 1 ? if disabled. 3: the sspxmsk registers are only accessible when sspxcon2<3:0> = 1001 . 4: alternate names and definitions for these bits when the mssp module is operating in i 2 c? slave mode. see section 18.5.3.2 ?address masking modes? for details. 5: these bits and/or registers are only available in 44-pin devices; otherwise, they are unimplemented and read as ? 0 ?. reset values are shown for 44-pin devices. 6: the pmaddrh/pmdout1h and pmaddrl/pmdout1l register pairs share the same physical registers and addresses, but have different functions determined by the module?s operating mode. see section 10.1.2 ?data registers? for more information.
pic18f46j50 family ds39931b-page 82 preliminary ? 2009 microchip technology inc. fsr1h ? ? ? ? indirect data memory address pointer 1 high byte ---- xxxx 61, 90 fsr1l indirect data memory address pointer 1 low byte xxxx xxxx 61, 90 bsr ? ? ? ? bank select register ---- 0000 61, 76 indf2 uses contents of fsr2 to address data memory ? value of fsr2 not changed (not a physical register) n/a 61, 90 postinc2 uses contents of fsr2 to address data memory ? value of fsr2 post-incremented (not a physical register) n/a 62, 91 postdec2 uses contents of fsr2 to address data memory ? value of fsr2 post-decremented (not a physical register) n/a 62, 91 preinc2 uses contents of fsr2 to address data memory ? value of fsr2 pre-incremented (not a physical register) n/a 62, 91 plusw2 uses contents of fsr2 to address data memory ? value of fsr2 pre-incremented (not a physical register) ? value of fsr2 offset by w n/a 62, 91 fsr2h ? ? ? ? indirect data memory address pointer 2 high byte ---- xxxx 62, 90 fsr2l indirect data memory address pointer 2 low byte xxxx xxxx 62, 90 status ? ? ?n ov z dcc ---x xxxx 62, 88 tmr0h timer0 register high byte 0000 0000 62, 194 tmr0l timer0 register low byte xxxx xxxx 62, 194 t0con tmr0on t08bit t0cs t0se psa t0ps2 t0ps1 t0ps0 1111 1111 62, 188 osccon idlen ircf2 ircf1 ircf0 osts (2) ? scs1 scs0 0110 q-00 62, 35 cm1con con coe cpol evpol1 evpol0 cref cch1 cch0 0001 1111 62, 385 cm2con con coe cpol evpol1 evpol0 cref cch1 cch0 0001 1111 62, 385 rcon ipen ?cm ri to pd por bor 0-11 1100 60, 62, 121 tmr1h timer1 register high byte xxxx xxxx 62, 194 tmr1l timer1 register low byte xxxx xxxx 62, 194 t1con tmr1cs1 tmr1cs0 t1ckps1 t1ckps0 t1oscen t1sync rd16 tmr1on 0000 0000 62, 194 tmr2 timer2 register 0000 0000 62, 203 pr2 timer2 period register 1111 1111 62, 203 t2con ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 -000 0000 62, 203 ssp1buf mssp1 receive buffer/transmit register xxxx xxxx 62, 280, 314 ssp1add mssp1 address register (i 2 c? slave mode), mssp1 baud rate reload register (i 2 c master mode) 0000 0000 62, 285 ssp1msk (4) msk7 msk6 msk5 msk4 msk3 msk2 msk1 msk0 1111 1111 62, 287 ssp1stat smp cke d/a psr/w ua bf 0000 0000 62, 262, 281 ssp1con1 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 62, 262, 282 ssp1con2 gcen ackstat ackdt acken rcen pen rsen sen 0000 0000 62, 262, 283 gcen ackstat admsk5 (4) admsk4 (4) admsk3 (4) admsk2 (4) admsk1 (4) sen adresh a/d result register high byte xxxx xxxx 62, 348 adresl a/d result register low byte xxxx xxxx 62, 348 adcon0 vcfg1 vcfg0 chs3 chs2 chs1 chs0 go/done adon 0000 0000 61, 339 adcon1 adfm adcal acqt2 acqt1 acqt0 adcs2 adcs1 adcs0 0000 0000 62, 339 wdtcon regslp lvdstat ulplvl ? ds ulpen ulpsink swdten 1xx- 0000 62, 421 pstr1con cmpl1 cmpl0 ? strsync strd strc strb stra 00-0 0001 62, 257 eccp1as eccp1ase eccp1as2 eccp1as1 eccp1as0 pss1ac1 pss1ac0 pss1bd1 pss1bd0 0000 0000 62 table 5-4: register file summary (pic18f46j50 family) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition, r = reserved. bold indicates shared access sfrs. note 1: bit 21 of the pc is only available in serial programming (sp) modes. 2: reset value is ? 0 ? when two-speed start-up is enabled and ? 1 ? if disabled. 3: the sspxmsk registers are only accessible when sspxcon2<3:0> = 1001 . 4: alternate names and definitions for these bits when the mssp module is operating in i 2 c? slave mode. see section 18.5.3.2 ?address masking modes? for details. 5: these bits and/or registers are only available in 44-pin devices; otherwise, they are unimplemented and read as ? 0 ?. reset values are shown for 44-pin devices. 6: the pmaddrh/pmdout1h and pmaddrl/pmdout1l register pairs share the same physical registers and addresses, but have different functions determined by the module?s operating mode. see section 10.1.2 ?data registers? for more information.
? 2009 microchip technology inc. preliminary ds39931b-page 83 pic18f46j50 family eccp1del p1rsen p1dc6 p1dc5 p1dc4 p1dc3 p1dc2 p1dc1 p1dc0 0000 0000 63 ccpr1h capture/compare/pwm register 1 high byte xxxx xxxx 63 ccpr1l capture/compare/pwm register 1 low byte xxxx xxxx 63 ccp1con p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 0000 0000 63 pstr2con cmpl1 cmpl0 ? strsync strd strc strb stra 00-0 0001 63, 257 eccp2as eccp2ase eccp2as2 eccp2as1 eccp2as0 pss2ac1 pss2ac0 pss2bd1 pss2bd0 0000 0000 63 eccp2del p2rsen p2dc6 p2dc5 p2dc4 p2dc3 p2dc2 p2dc1 p2dc0 0000 0000 63 ccpr2h capture/compare/pwm register 2 high byte xxxx xxxx 63 ccpr2l capture/compare/pwm register 2 low byte xxxx xxxx 63 ccp2con p2m1 p2m0 dc2b1 dc2b0 ccp2m3 ccp2m2 ccp2m1 ccp2m0 0000 0000 63 ctmuconh ctmuen ? ctmusidl tgen edgen edgseqen idissen ? 0-00 000- 63 ctmuconl edg2pol edg2sel1 edg2sel0 edg1p ol edg1sel1 edg1sel0 edg2stat edg1stat 0000 00xx 63 ctmuicon itrim5 itrim4 itrim3 itrim2 itrim1 itrim0 irng1 irng0 0000 0000 63 spbrg1 eusart1 baud rate generator register low byte 0000 0000 63, 319 rcreg1 eusart1 receive register 0000 0000 63, 327, 320 txreg1 eusart1 transmit register xxxx xxxx 63, 327, 326 txsta1 csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 63, 325 rcsta1 spen rx9 sren cren adden ferr oerr rx9d 0000 000x 63, 327 spbrg2 eusart2 baud rate generator register low byte 0000 0000 63, 319 rcreg2 eusart2 receive register 0000 0000 63, 327, 328 txreg2 eusart2 transmit register 0000 0000 63, 325, 326 txsta2 csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 63, 325 eecon2 program memory control register 2 (not a physical register) ---- ---- 63, 96 eecon1 ? ? wprog free wrerr wren wr ? --00 x00- 63, 96 ipr3 ssp2ip bcl2ip rc2ip tx2ip tmr4ip ctmuip tmr3gip rtccip 1111 1111 63, 118 pir3 ssp2if bcl2if rc2if tx2if tmr4if ctmuif tmr3gif rtccif 0000 0000 63, 112 pie3 ssp2ie bcl2ie rc2ie tx2ie tmr4ie ctmuie tmr3gie rtccie 0000 0000 63, 115 ipr2 oscfip cm2ip cm1ip usbip bcl1ip hlvdip tmr3ip ccp2ip 1111 1111 63, 118 pir2 oscfif cm2if cm1if usbif bcl1if hlvdif tmr3if ccp2if 0000 0000 63, 112 pie2 oscfie cm2ie cm1ie usbie bcl1ie hlvdie tmr3ie ccp2ie 0000 0000 63, 115 ipr1 pmpip (5) adip rc1ip tx1ip ssp1ip ccp1ip tmr2ip tmr1ip 1111 1111 63, 118 pir1 pmpif (5) adif rc1if tx1if ssp1if ccp1if tmr2if tmr1if 0000 0000 63, 112 pie1 pmpie (5) adie rc1ie tx1ie ssp1ie ccp1ie tmr2ie tmr1ie 0000 0000 63, 115 rcsta2 spen rx9 sren cren adden ferr oerr rx9d 0000 000x 64, 327 osctune intsrc pllen tun5 tun4 tun3 tun2 tun1 tun0 0000 0000 64, 31 t1gcon tmr1ge t1gpol t1gtm t1gspm t1ggo/ t1done t1gval t1gss1 t1gss0 0000 0x00 192 rtcvalh rtcc value register window high byte, based on rtcptr<1:0> 0xxx xxxx 64, 223 rtcvall rtcc value register window low byte, based on rtcptr<1:0> 0xxx xxxx 64, 223 table 5-4: register file summary (pic18f46j50 family) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition, r = reserved. bold indicates shared access sfrs. note 1: bit 21 of the pc is only available in serial programming (sp) modes. 2: reset value is ? 0 ? when two-speed start-up is enabled and ? 1 ? if disabled. 3: the sspxmsk registers are only accessible when sspxcon2<3:0> = 1001 . 4: alternate names and definitions for these bits when the mssp module is operating in i 2 c? slave mode. see section 18.5.3.2 ?address masking modes? for details. 5: these bits and/or registers are only available in 44-pin devices; otherwise, they are unimplemented and read as ? 0 ?. reset values are shown for 44-pin devices. 6: the pmaddrh/pmdout1h and pmaddrl/pmdout1l register pairs share the same physical registers and addresses, but have different functions determined by the module?s operating mode. see section 10.1.2 ?data registers? for more information.
pic18f46j50 family ds39931b-page 84 preliminary ? 2009 microchip technology inc. t3gcon tmr3ge t3gpol t3gtm t3gspm t3ggo/ t 3don e t3gval t3gss1 t3gss0 0000 0x00 64, 206 trise ? ? ? ? ? trise2 trise1 trise0 ---- -111 64 trisd trisd7 trisd6 trisd5 trisd4 trisd3 trisd2 trisd1 trisd0 1111 1111 64, 271 trisc trisc7 trisc6 trisc5 trisc4 ? trisc2 trisc1 trisc0 1111 -111 64, 134 trisb trisb7 trisb6 trisb5 tri sb4 trisb3 trisb2 trisb1 trisb0 1111 1111 64, 130 trisa trisa7 trisa6 trisa5 ? trisa3 trisa2 trisa1 trisa0 111- 1111 64, 127 alrmcfg alrmen chime amask3 amask2 amask1 amask0 alrmptr1 alrmptr0 0000 0000 64, 221 alrmrpt arpt7 arpt6 arpt5 arpt4 arpt3 arpt2 arpt1 arpt0 0000 0000 64, 222 alrmvalh alarm value register window high byte, based on alrmptr<1:0> xxxx xxxx 64, 226 alrmvall alarm value register window low byte, based on alrmptr<1:0> xxxx xxxx 64, 226 late ? ? ? ? ?late2late1late0 ---- -xxx 64, 140 latd latd7 latd6 latd5 latd4 latd3 latd2 latd1 latd0 xxxx xxxx 64, 138 latc latc7 latc6 latc5 latc4 ? latc2 latc1 latc0 xxxx -xxx 64, 133 latb latb7 latb6 latb5 latb4 latb3 latb2 latb1 latb0 xxxx xxxx 64, 133 lata lata7 lata6 lata5 ? lata3 lata2 lata1 lata0 xxx- xxxx 64, 133 dmacon1 sscon1 sscon0 txinc rxinc duplex1 duplex0 dlyinten dmaen 0000 0000 64, 274 dmatxbuf spi dma transmit buffer xxxx xxxx 64 dmacon2 dlycyc3 dlycyc2 dlycyc1 dlycyc0 intlvl3 intlvl2 intlvl1 intlvl0 0000 0000 64, 275 hlvdcon vdirmag bgvst irvst hlvden hlvdl3 hlvdl2 hlvdl1 hlvdl0 0000 0000 64 porte rdpu repu ? ? ? re2 re1 re0 00-- -xxx 64, 123 portd rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0 xxxx xxxx 64, 123 portc rc7 rc6 rc5 rc4 ? rc2 rc1 rc0 xxxx -xxx 64, 123 portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx 64, 123 porta ra7 ra6 ra5 ? ra3 ra2 ra1 ra0 xxx- xxxx 64, 348 spbrgh1 eusart1 baud rate generator register high byte 0000 0000 64, 319 baudcon1 abdovf rcidl rxdtp txckp brg16 ? wue abden 0100 0-00 64, 319 spbrgh2 eusart2 baud rate generator register high byte 0000 0000 64, 319 baudcon2 abdovf rcidl rxdtp txckp brg16 ? wue abden 0100 0-00 64, 319 tmr3h timer3 register high byte xxxx xxxx 65, 189 tmr3l timer3 register low byte xxxx xxxx 65, 189 t3con tmr3cs1 tmr3cs0 t3ckps1 t3ckps0 t3oscen t3sync rd16 tmr3on 0000 0000 65, 189 tmr4 timer4 register 0000 0000 65, 215 pr4 timer4 period register 1111 1111 65, 189 t4con ? t4outps3 t4outps2 t4outps1 t4outps0 tmr4on t4ckps1 t4ckps0 -000 0000 65, 215 ssp2buf mssp2 receive buffer/transmit register xxxx xxxx 65, 280, 314 ssp2add/ mssp2 address register (i 2 c? slave mode), mssp2 baud rate reload register (i 2 c master mode) 0000 0000 65, 280 ssp2msk ( 4 ) msk7 msk6 msk5 msk4 msk3 msk2 msk1 msk0 0000 0000 65, 287 ssp2stat smp cke d/a psr/w ua bf 1111 1111 65, 262, 302 ssp2con1 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 65, 262, 314 table 5-4: register file summary (pic18f46j50 family) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition, r = reserved. bold indicates shared access sfrs. note 1: bit 21 of the pc is only available in serial programming (sp) modes. 2: reset value is ? 0 ? when two-speed start-up is enabled and ? 1 ? if disabled. 3: the sspxmsk registers are only accessible when sspxcon2<3:0> = 1001 . 4: alternate names and definitions for these bits when the mssp module is operating in i 2 c? slave mode. see section 18.5.3.2 ?address masking modes? for details. 5: these bits and/or registers are only available in 44-pin devices; otherwise, they are unimplemented and read as ? 0 ?. reset values are shown for 44-pin devices. 6: the pmaddrh/pmdout1h and pmaddrl/pmdout1l register pairs share the same physical registers and addresses, but have different functions determined by the module?s operating mode. see section 10.1.2 ?data registers? for more information.
? 2009 microchip technology inc. preliminary ds39931b-page 85 pic18f46j50 family ssp2con2 gcen ackstat ackdt acken rcen pen rsen sen 0000 0000 65, 262, 314 gcen ackstat admsk5 (4) admsk4 (4) admsk3 (4) admsk2 (4) admsk1 (4) sen cmstat ? ? ? ? ? ? cout2 cout1 ---- --11 65, 382 pmaddrh/ ? cs1 parallel master port address high byte -000 0000 65, 169 pmdout1h (5) parallel port out data high byte (buffer 1) 0000 0000 65, 172 pmaddrl/ parallel master port address low byte 0000 0000 65, 168 pmdout1l (5) parallel port out data low byte (buffer 0) 0000 0000 65, 169 pmdin1h (5) parallel port in data high byte (buffer 1) 0000 0000 65, 169 pmdin1l (5) parallel port in data low byte (buffer 0) 0000 0000 65, 169 txaddrl spi dma transit data pointer low byte xxxx xxxx 65, 276 txaddrh ? ? ? ? spi dma transit data pointer high byte ---- xxxx 65, 276 rxaddrl spi dma receive data pointer low byte xxxx xxxx 65, 276 rxaddrh ? ? ? ? spi dma receive data pointer high byte ---- xxxx 65, 276 dmabcl spi dma byte count low byte xxxx xxxx 65, 276 dmabch ? ? ? ? ? ? spi dma receive data pointer high byte ---- --xx 65, 276 ucon ? ppbrst se0 pktdis usben resume suspnd ? -0x0 000- 65, 351 ustat ? endp3 endp2 endp1 endp0 dir ppbi ? -xxx xxx- 65, 355 ueir btsef ? ? btoef dfn8ef crc16ef crc5ef pidef 0--0 0000 65, 368 uir ? sofif stallif idleif trnif actvif uerrif urstif -000 0000 65, 365 ufrmh ? ? ? ? ?frm10frm9frm8 ---- -xxx 65, 357 ufrml frm7 frm6 frm5 frm4 frm3 frm2 frm1 frm0 xxxx xxxx 65, 357 pmconh (5) pmpen ? psidl adrmux1 adrmux0 ptbeen ptwren ptrden 0-00 0000 65, 162 pmconl (5) csf1 csf0 alp ? cs1p bep wrsp rdsp 000- 0000 65, 163 pmmodeh (5) busy irqm1 irqm0 incm1 incm0 mode16 mode1 mode0 0000 0000 66, 164 pmmodel (5) waitb1 waitb0 waitm3 waitm2 waitm1 waitm0 waite1 waite0 0000 0000 66, 165 pmdout2h (5) parallel port out data high byte (buffer 3) 0000 0000 66, 168 pmdout2l (5) parallel port out data low byte (buffer 2) 0000 0000 66, 168 pmdin2h (5) parallel port in data high byte (buffer 3) 0000 0000 66, 168 pmdin2l (5) parallel port in data low byte (buffer 2) 0000 0000 66, 168 pmeh (5) pten15 pten14 pten13 pten12 pten11 pten10 pten9 pten8 0000 0000 66, 166 pmel (5) pten7 pten6 pten5 pten4 pten3 pten2 pten1 pten0 0000 0000 66, 166 pmstath (5) ibf ibov ? ? ib3f ib2f ib1f ib0f 00-- 0000 66, 167 pmstatl (5) obe obuf ? ? ob3e ob2e ob1e ob0e 10-- 1111 66, 167 cvrcon (5) cvren cvroe cvrr r cvr3 cvr2 cvr1 cvr0 0000 0000 66, 386 tclkcon ? ? ? t1run ? ? t3ccp2 t3ccp1 ---0 --00 193 dsgpr1 deep sleep persistent general purpose register (contents retained even in deep sleep) xxxx xxxx 50 dsgpr0 deep sleep persistent general purpose register (contents retained even in deep sleep) xxxx xxxx 50 dsconh dsen ? ? ? ? (reserved) dsulpen rtcwdis 0--- -000 49 dsconl ? ? ? ? ? ulpwdis dsbor release ---- -000 49 dswakeh ? ? ? ? ? ? ?dsint0 ---- ---0 51 dswakel dsflt ? dsulp dswdt dsrtc dsmclr ?dspor 0-00 00-1 51 table 5-4: register file summary (pic18f46j50 family) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition, r = reserved. bold indicates shared access sfrs. note 1: bit 21 of the pc is only available in serial programming (sp) modes. 2: reset value is ? 0 ? when two-speed start-up is enabled and ? 1 ? if disabled. 3: the sspxmsk registers are only accessible when sspxcon2<3:0> = 1001 . 4: alternate names and definitions for these bits when the mssp module is operating in i 2 c? slave mode. see section 18.5.3.2 ?address masking modes? for details. 5: these bits and/or registers are only available in 44-pin devices; otherwise, they are unimplemented and read as ? 0 ?. reset values are shown for 44-pin devices. 6: the pmaddrh/pmdout1h and pmaddrl/pmdout1l register pairs share the same physical registers and addresses, but have different functions determined by the module?s operating mode. see section 10.1.2 ?data registers? for more information.
pic18f46j50 family ds39931b-page 86 preliminary ? 2009 microchip technology inc. ancon1 vbgen r ? pcfg12 pcfg11 pcfg10 pcfg9 pcfg8 00-0 0000 66, 340 ancon0 pcfg7 (5) pcfg6 (5) pcfg5 (5) pcfg4 pcfg3 pcfg2 pcfg1 pcfg0 0000 0000 66, 339 odcon1 ? ? ? ? ? ? eccp20d eccp10d ---- --00 66, 125 odcon2 ? ? ? ? ? ?u2odu1od ---- --00 66, 125 odcon3 ? ? ? ? ? ? spi2od spi1od ---- --00 66, 126 rtccfg rtcen ? rtcwren rtcsync halfsec rtcoe rtcptr1 rtcptr0 0-00 0000 66, 219 rtccal cal7 cal6 cal5 cal4 cal3 cal2 cal1 cal0 0000 0000 66, 220 refocon roon ? rosslp rosel rodiv3 rodiv2 rodi v1 rodiv0 0-00 0000 66, 36 padcfg1 ? ? ? ? ? rtsecsel1 rtsecsel0 pmpttl ---- -000 66, 126 ucfg uteye uoemon ? upuen utrdis fsen ppb1 ppb0 00-0 0000 66, 352 uaddr ? addr6 addr5 addr4 addr3 addr2 addr1 addr0 -000 0000 66, 357 ueie btsee ? ? btoee dfn8ee crc16ee crc5ee pidee 0--0 0000 66, 369 uie ? sofie stallie idleie trnie actvie uerrie urstie -000 0000 66, 367 uep15 ? ? ? ephshk epcondis epouten epinen epstall ---0 0000 66, 356 uep14 ? ? ? ephshk epcondis epouten epinen epstall ---0 0000 66, 356 uep13 ? ? ? ephshk epcondis epouten epinen epstall ---0 0000 66, 356 uep12 ? ? ? ephshk epcondis epouten epinen epstall ---0 0000 66, 356 uep11 ? ? ? ephshk epcondis epouten epinen epstall ---0 0000 66, 356 uep10 ? ? ? ephshk epcondis epouten epinen epstall ---0 0000 66, 356 uep9 ? ? ? ephshk epcondis epouten epinen epstall ---0 0000 66, 356 uep8 ? ? ? ephshk epcondis epouten epinen epstall ---0 0000 66, 356 uep7 ? ? ? ephshk epcondis epouten epinen epstall ---0 0000 66, 356 uep6 ? ? ? ephshk epcondis epouten epinen epstall ---0 0000 67, 356 uep5 ? ? ? ephshk epcondis epouten epinen epstall ---0 0000 67, 356 uep4 ? ? ? ephshk epcondis epouten epinen epstall ---0 0000 67, 356 uep3 ? ? ? ephshk epcondis epouten epinen epstall ---0 0000 67, 356 uep2 ? ? ? ephshk epcondis epouten epinen epstall ---0 0000 67, 356 uep1 ? ? ? ephshk epcondis epouten epinen epstall ---0 0000 67, 356 uep0 ? ? ? ephshk epcondis epouten epinen epstall ---0 0000 67, 356 ppscon ? ? ? ? ? ? ? iolock ---- ---0 146 rpinr24 ? ? ? input function flt0 to input pin mapping bits ---1 1111 67, 151 rpinr23 ? ? ? input function ss2 to input pin mapping bits ---1 1111 67, 151 rpinr22 ? ? ? input function sck2 to input pin mapping bits ---1 1111 67, 151 rpinr21 ? ? ? input function sdi2 to input pin mapping bits ---1 1111 67, 150 rpinr17 ? ? ? input function ck2 to input pin mapping bits ---1 1111 67, 150 rpinr16 ? ? ? input function rx2dt2 to input pin mapping bits ---1 1111 67 rpinr13 ? ? ? input function t3g to input pin mapping bits ---1 1111 67 rpinr12 ? ? ? input function t1g to input pin mapping bits ---1 1111 67, 149 rpinr8 ? ? ? input function ic2 to input pin mapping bits ---1 1111 67, 149 rpinr7 ? ? ? input function ic1 to input pin mapping bits ---1 1111 67, 148 rpinr6 ? ? ? input function t3cki to input pin mapping bits ---1 1111 67, 148 rpinr4 ? ? ? input function t0cki to input pin mapping bits ---1 1111 67, 148 table 5-4: register file summary (pic18f46j50 family) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition, r = reserved. bold indicates shared access sfrs. note 1: bit 21 of the pc is only available in serial programming (sp) modes. 2: reset value is ? 0 ? when two-speed start-up is enabled and ? 1 ? if disabled. 3: the sspxmsk registers are only accessible when sspxcon2<3:0> = 1001 . 4: alternate names and definitions for these bits when the mssp module is operating in i 2 c? slave mode. see section 18.5.3.2 ?address masking modes? for details. 5: these bits and/or registers are only available in 44-pin devices; otherwise, they are unimplemented and read as ? 0 ?. reset values are shown for 44-pin devices. 6: the pmaddrh/pmdout1h and pmaddrl/pmdout1l register pairs share the same physical registers and addresses, but have different functions determined by the module?s operating mode. see section 10.1.2 ?data registers? for more information.
? 2009 microchip technology inc. preliminary ds39931b-page 87 pic18f46j50 family rpinr3 ? ? ? input function int3 to input pin mapping bits ---1 1111 67, 147 rpinr2 ? ? ? input function int2 to input pin mapping bits ---1 1111 67 rpinr1 ? ? ? input function int1 to input pin mapping bits ---1 1111 67, 147 rpor24 (5) ? ? ? remappable pin rp24 output signal select bits ---0 0000 67, 159 rpor23 (5) ? ? ? remappable pin rp23 output signal select bits ---0 0000 67, 158 rpor22 (5) ? ? ? remappable pin rp22 output signal select bits ---0 0000 67, 158 rpor21 (5) ? ? ? remappable pin rp21 output signal select bits ---0 0000 67, 158 rpor20 (5) ? ? ? remappable pin rp20 output signal select bits ---0 0000 67, 157 rpor19 (5) ? ? ? remappable pin rp19 output signal select bits ---0 0000 67, 157 rpor18 ? ? ? remappable pin rp18 output signal select bits ---0 0000 67, 157 rpor17 ? ? ? remappable pin rp17 output signal select bits ---0 0000 67, 156 rpor13 ? ? ? remappable pin rp13 output signal select bits ---0 0000 67, 156 rpor12 ? ? ? remappable pin rp12 output signal select bits ---0 0000 67, 156 rpor11 ? ? ? remappable pin rp11 output signal select bits ---0 0000 67, 155 rpor10 ? ? ? remappable pin rp10 output signal select bits ---0 0000 68, 155 rpor9 ? ? ? remappable pin rp9 output signal select bits ---0 0000 68, 155 rpor8 ? ? ? remappable pin rp8 output signal select bits ---0 0000 68, 154 rpor7 ? ? ? remappable pin rp7 output signal select bits ---0 0000 68, 154 rpor6 ? ? ? remappable pin rp6 output signal select bits ---0 0000 68, 154 rpor5 ? ? ? remappable pin rp5 output signal select bits ---0 0000 68, 153 rpor4 ? ? ? remappable pin rp4 output signal select bits ---0 0000 68, 153 rpor3 ? ? ? remappable pin rp3 output signal select bits ---0 0000 68, 153 rpor2 ? ? ? remappable pin rp2 output signal select bits ---0 0000 68, 152 rpor1 ? ? ? remappable pin rp1 output signal select bits ---0 0000 68, 152 rpor0 ? ? ? remappable pin rp0 output signal select bits ---0 0000 68, 152 table 5-4: register file summary (pic18f46j50 family) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition, r = reserved. bold indicates shared access sfrs. note 1: bit 21 of the pc is only available in serial programming (sp) modes. 2: reset value is ? 0 ? when two-speed start-up is enabled and ? 1 ? if disabled. 3: the sspxmsk registers are only accessible when sspxcon2<3:0> = 1001 . 4: alternate names and definitions for these bits when the mssp module is operating in i 2 c? slave mode. see section 18.5.3.2 ?address masking modes? for details. 5: these bits and/or registers are only available in 44-pin devices; otherwise, they are unimplemented and read as ? 0 ?. reset values are shown for 44-pin devices. 6: the pmaddrh/pmdout1h and pmaddrl/pmdout1l register pairs share the same physical registers and addresses, but have different functions determined by the module?s operating mode. see section 10.1.2 ?data registers? for more information.
pic18f46j50 family ds39931b-page 88 preliminary ? 2009 microchip technology inc. 5.3.6 status register the status register in register 5-2, contains the arithmetic status of the alu. the status register can be the operand for any instruction, as with any other register. if the status register is the destination for an instruction that affects the z, dc, c, ov or n bits, then the write to these five bits is disabled. these bits are set or cleared according to the device logic. therefore, the result of an instruction with the status register as destination may be different than intended. for example, clrf status will set the z bit but leave the other bits unchanged. the status register then reads back as ? 000u u1uu ?. it is recom- mended, therefore, that only bcf , bsf , swapf , movff and movwf instructions are used to alter the status register because these instructions do not affect the z, c, dc, ov or n bits in the status register. for other instructions not affecting any status bits, see the instruction set summary in table 27-2 and table 27-3. note: the c and dc bits operate as a borrow and digit borrow bits respectively, in subtraction. register 5-2: status register (access fd8h) u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x ? ? ?novzdc (1) c (2) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 n: negative bit this bit is used for signed arithmetic (2?s complement). it indicates whether the result was negative (alu msb = 1 ). 1 = result was negative 0 = result was positive bit 3 ov: overflow bit this bit is used for signed arithmetic (2?s complement). it indicates an overflow of the 7-bit magnitude, which causes the sign bit (bit 7) to change state. 1 = overflow occurred for signed arithmetic (in this arithmetic operation) 0 = no overflow occurred bit 2 z: zero bit 1 = the result of an arithmetic or logic operation is zero 0 = the result of an arithmetic or logic operation is not zero bit 1 dc: digit carry/borrow bit (1) for addwf , addlw , sublw and subwf instructions: 1 = a carry-out from the 4 th low-order bit of the result occurred 0 = no carry-out from the 4 th low-order bit of the result bit 0 c: carry/borrow bit (2) for addwf , addlw , sublw and subwf instructions: 1 = a carry-out from the msb of the result occurred 0 = no carry-out from the msb of the result occurred note 1: for borrow, the polarity is reversed. a subtraction is executed by adding the 2?s complement of the second operand. for rotate ( rrf , rlf ) instructions, this bit is loaded with either bit 4 or bit 3 of the source register. 2: for borrow, the polarity is reversed. a subtraction is executed by adding the 2?s complement of the second operand. for rotate ( rrf , rlf ) instructions, this bit is loaded with either the high or low-order bit of the source register.
? 2009 microchip technology inc. preliminary ds39931b-page 89 pic18f46j50 family 5.4 data addressing modes while the program memory can be addressed in only one way, through the pc, information in the data mem- ory space can be addressed in several ways. for most instructions, the addressing mode is fixed. other instructions may use up to three modes, depending on which operands are used and whether or not the extended instruction set is enabled. the addressing modes are: ? inherent ? literal ?direct ?indirect an additional addressing mode, indexed literal offset, is available when the extended instruction set is enabled (xinst configuration bit = 1 ). its operation is discussed in more detail in section 5.6.1 ?indexed addressing with literal offset? . 5.4.1 inherent and literal addressing many pic18 control instructions do not need any argument at all; they either perform an operation that globally affects the device, or they operate implicitly on one register. this addressing mode is known as inherent addressing. examples include sleep , reset and daw . other instructions work in a similar way, but require an additional explicit argument in the opcode. this is known as literal addressing mode, because they require some literal value as an argument. examples include addlw and movlw , which respectively, add or move a literal value to the w register. other examples include call and goto , which include a 20-bit program memory address. 5.4.2 direct addressing direct addressing specifies all or part of the source and/or destination address of the operation within the opcode itself. the options are specified by the arguments accompanying the instruction. in the core pic18 instruction set, bit-oriented and byte-oriented instructions use some version of direct addressing by default. all of these instructions include some 8-bit literal address as their lsb. this address specifies either a register address in one of the banks of data ram ( section 5.3.4 ?general purpose register file? ), or a location in the access bank ( section 5.3.3 ?access bank? ) as the data source for the instruction. the access ram bit, ?a?, determines how the address is interpreted. when ?a? is ? 1 ?, the contents of the bsr ( section 5.3.2 ?bank select register? ) are used with the address to determine the complete 12-bit address of the register. when ?a? is ? 0 ?, the address is interpreted as being a register in the access bank. addressing that uses the access ram is sometimes also known as direct forced addressing mode. a few instructions, such as movff , include the entire 12-bit address (either source or destination) in their opcodes. in these cases, the bsr is ignored entirely. the destination of the operation?s results is determined by the destination bit, ?d?. when ?d? is ? 1 ?, the results are stored back in the source register, overwriting its original contents. when ?d? is ? 0 ?, the results are stored in the w register. instructions without the ?d? argument have a destination that is implicit in the instruction; their destination is either the target register being operated on or the w register. 5.4.3 indirect addressing indirect addressing allows the user to access a location in data memory without giving a fixed address in the instruction. this is done by using file select registers (fsrs) as pointers to the locations to be read or written to. since the fsrs are themselves located in ram as sfrs, they can also be directly manipulated under program control. this makes fsrs very useful in implementing data structures such as tables and arrays in data memory. the registers for indirect addressing are also implemented with indirect file operands (indfs) that permit automatic manipulation of the pointer value with auto-incrementing, auto-decrementing or offsetting with another value. this allows for efficient code using loops, such as the example of clearing an entire ram bank in example 5-5. it also enables users to perform indexed addressing and other stack pointer operations for program memory in data memory. example 5-5: how to clear ram (bank 1) using indirect addressing note: the execution of some instructions in the core pic18 instruction set are changed when the pic18 extended instruction set is enabled. see section 5.6 ?data memory and the extended instruction set? for more information. lfsr fsr0, 100h ; next clrf postinc0 ; clear indf ; register then ; inc pointer btfss fsr0h, 1 ; all done with ; bank1? bra next ; no, clear next continue ; yes, continue
pic18f46j50 family ds39931b-page 90 preliminary ? 2009 microchip technology inc. 5.4.3.1 fsr registers and the indf operand (indf) at the core of indirect addressing are three sets of registers: fsr0, fsr1 and fsr2. each represents a pair of 8-bit registers, fsrnh and fsrnl. the four upper bits of the fsrnh register are not used, so each fsr pair holds a 12-bit value. this represents a value that can address the entire range of the data memory in a linear fashion. the fsr register pairs, then, serve as pointers to data memory locations. indirect addressing is accomplished with a set of indf operands, indf0 through indf2. these can be pre- sumed as ?virtual? registers: they are mapped in the sfr space but are not physically implemented. read- ing or writing to a particular indf register actually accesses its corresponding fsr register pair. a read from indf1, for example, reads the data at the address indicated by fsr1h:fsr1l. instructions that use the indf registers as operands actually use the contents of their corresponding fsr as a pointer to the instruc- tion?s target. the indf operand is just a convenient way of using the pointer. because indirect addressing uses a full 12-bit address, data ram banking is not necessary. thus, the current contents of the bsr and the access ram bit have no effect on determining the target address. figure 5-8: indirect addressing fsr1h:fsr1l 0 7 data memory 000h 100h 200h 300h f00h e00h fffh bank 0 bank 1 bank 2 bank 14 bank 15 bank 3 through bank 13 addwf , indf1 , 1 0 7 using an instruction with one of the indirect addressing registers as the operand.... ...uses the 12-bit address stored in the fsr pair associated with that register.... ...to determine the data memory location to be used in that operation. in this case, the fsr1 pair contains fcch. this means the contents of location fcch will be added to that of the w register and stored back in fcch. xxxx 1111 11001100
? 2009 microchip technology inc. preliminary ds39931b-page 91 pic18f46j50 family 5.4.3.2 fsr registers and postinc, postdec, preinc and plusw in addition to the indf operand, each fsr register pair also has four additional indirect operands. like indf, these are ?virtual? registers that cannot be indirectly read or written to. accessing these registers actually accesses the associated fsr register pair, but also performs a specific action on its stored value. they are: ? postdec: accesses the fsr value, then automatically decrements it by ? 1 ? thereafter ? postinc: accesses the fsr value, then automatically increments it by ? 1 ? thereafter ? preinc: increments the fsr value by ? 1 ?, then uses it in the operation ? plusw: adds the signed value of the w register (range of 127 to 128) to that of the fsr and uses the new value in the operation in this context, accessing an indf register uses the value in the fsr registers without changing them. similarly, accessing a plusw register gives the fsr value offset by the value in the w register; neither value is actually changed in the operation. accessing the other virtual registers changes the value of the fsr registers. operations on the fsrs with postdec, postinc and preinc affect the entire register pair; that is, roll- overs of the fsrnl register from ffh to 00h carry over to the fsrnh register. on the other hand, results of these operations do not change the value of any flags in the status register (e.g., z, n, ov, etc.). the plusw register can be used to implement a form of indexed addressing in the data memory space. by manipulating the value in the w register, users can reach addresses that are fixed offsets from pointer addresses. in some applications, this can be used to implement some powerful program control structure, such as software stacks, inside of data memory. 5.4.3.3 operations by fsrs on fsrs indirect addressing operations that target other fsrs or virtual registers represent special cases. for example, using an fsr to point to one of the virtual registers will not result in successful operations. as a specific case, assume that fsr0h:fsr0l contains fe7h, the address of indf1. attempts to read the value of the indf1, using indf0 as an operand, will return 00h. attempts to write to indf1, using indf0 as the operand, will result in a nop . on the other hand, using the virtual registers to write to an fsr pair may not occur as planned. in these cases, the value will be written to the fsr pair but without any incrementing or decrementing. thus, writing to indf2 or postdec2 will write the same value to the fsr2h:fsr2l. since the fsrs are physical registers mapped in the sfr space, they can be manipulated through all direct operations. users should proceed cautiously when working on these registers, particularly if their code uses indirect addressing. similarly, operations by indirect addressing are gener- ally permitted on all other sfrs. users should exercise appropriate caution that they do not inadvertently change settings that might affect the operation of the device. 5.5 program memory and the extended instruction set the operation of program memory is unaffected by the use of the extended instruction set. enabling the extended instruction set adds five additional two-word commands to the existing pic18 instruction set: addfsr , callw , movsf , movss and subfsr . these instructions are executed as described in section 5.2.4 ?two-word instructions? . 5.6 data memory and the extended instruction set enabling the pic18 extended instruction set (xinst configuration bit = 1 ) significantly changes certain aspects of data memory and its addressing. specifically, the use of the access bank for many of the core pic18 instructions is different. this is due to the introduction of a new addressing mode for the data memory space. this mode also alters the behavior of indirect addressing using fsr2 and its associated operands. what does not change is just as important. the size of the data memory space is unchanged, as well as its linear addressing. the sfr map remains the same. core pic18 instructions can still operate in both direct and indirect addressing mode; inherent and literal instructions do not change at all. indirect addressing with fsr0 and fsr1 also remains unchanged.
pic18f46j50 family ds39931b-page 92 preliminary ? 2009 microchip technology inc. 5.6.1 indexed addressing with literal offset enabling the pic18 extended instruction set changes the behavior of indirect addressing using the fsr2 register pair and its associated file operands. under proper conditions, instructions that use the access bank, that is, most bit and byte-oriented instructions, can invoke a form of indexed addressing using an offset specified in the instruction. this special address- ing mode is known as indexed addressing with literal offset, or indexed literal offset mode. when using the extended instruction set, this addressing mode requires the following: ? the use of the access bank is forced (?a? = 0 ); and ? the file address argument is less than or equal to 5fh. under these conditions, the file address of the instruction is not interpreted as the lower byte of an address (used with the bsr in direct addressing) or as an 8-bit address in the access bank. instead, the value is interpreted as an offset value to an address pointer specified by fsr2. the offset and the contents of fsr2 are added to obtain the target address of the operation. 5.6.2 instructions affected by indexed literal offset mode any of the core pic18 instructions that can use direct addressing are potentially affected by the indexed literal offset addressing mode. this includes all byte and bit-oriented instructions, or almost one-half of the standard pic18 instruction set. instructions that only use inherent or literal addressing modes are unaffected. additionally, byte and bit-oriented instructions are not affected if they use the access bank (access ram bit is ? 1 ?) or include a file address of 60h or above. instructions meeting these criteria will continue to execute as before. a comparison of the different possible addressing modes when the extended instruction set is enabled is provided in figure 5-9. those who desire to use byte or bit-oriented instruc- tions in the indexed literal offset mode should note the changes to assembler syntax for this mode. this is described in more detail in section 27.2.1 ?extended instruction syntax? .
? 2009 microchip technology inc. preliminary ds39931b-page 93 pic18f46j50 family figure 5-9: comparing addressing options for bit-oriented and byte-oriented instructions (extended instruction set enabled) example instruction: addwf, f, d, a (opcode: 0010 01da ffff ffff ) when a = 0 and f 60h: the instruction executes in direct forced mode. ?f? is interpreted as a location in the access ram between 060h and fffh. this is the same as locations f60h to fffh (bank 15) of data memory. locations below 060h are not available in this addressing mode. when a = 0 and f 5fh: the instruction executes in indexed literal offset mode. ?f? is interpreted as an offset to the address value in fsr2. the two are added together to obtain the address of the target register for the instruction. the address can be anywhere in the data memory space. note that in this mode, the correct syntax is: addwf [k], d where ?k? is same as ?f?. when a = 1 (all values of f): the instruction executes in direct mode (also known as direct long mode). ?f? is interpreted as a location in one of the 16 banks of the data memory space. the bank is designated by the bank select register (bsr). the address can be in any implemented bank in the data memory space. 000h 060h 100h f00h f60h fffh valid range 00h 60h ffh data memory access ram bank 0 bank 1 through bank 14 bank 15 sfrs 000h 060h 100h f00h f60h fffh data memory bank 0 bank 1 through bank 14 bank 15 sfrs fsr2h fsr2l ffffffff 001001da ffffffff 001001da 000h 060h 100h f00h f60h fffh data memory bank 0 bank 1 through bank 14 bank 15 sfrs for ?f? bsr 00000000
pic18f46j50 family ds39931b-page 94 preliminary ? 2009 microchip technology inc. 5.6.3 mapping the access bank in indexed literal offset mode the use of indexed literal offset addressing mode effectively changes how the lower part of access ram (00h to 5fh) is mapped. rather than containing just the contents of the bottom part of bank 0, this mode maps the contents from bank 0 and a user-defined ?window? that can be located anywhere in the data memory space. the value of fsr2 establishes the lower boundary of the addresses mapped to the window, while the upper boundary is defined by fsr2 plus 95 (5fh). addresses in the access ram above 5fh are mapped as previously described (see section 5.3.3 ?access bank? ). figure 5-10 provides an example of access bank remapping in this addressing mode. remapping of the access bank applies only to opera- tions using the indexed literal offset mode. operations that use the bsr (access ram bit is ? 1 ?) will continue to use direct addressing as before. any indirect or indexed addressing operation that explicitly uses any of the indirect file operands (including fsr2) will con- tinue to operate as standard indirect addressing. any instruction that uses the access bank, but includes a register address of greater than 05fh, will use direct addressing and the normal access bank map. 5.6.4 bsr in indexed literal offset mode although the access bank is remapped when the extended instruction set is enabled, the operation of the bsr remains unchanged. direct addressing, using the bsr to select the data memory bank, operates in the same manner as previously described. figure 5-10: remapping the access bank with indexed literal offset addressing data memory 000h 100h 200h f60h f00h fffh bank 1 bank 15 bank 2 through bank 14 sfrs 05fh addwf f, d, a fsr2h:fsr2l = 120h locations in the region from the fsr2 pointer (120h) to the pointer plus 05fh (17fh) are mapped to the bottom of the access ram (000h-05fh). special function registers at f60h through fffh are mapped to 60h through ffh, as usual. bank 0 addresses below 5fh are not available in this mode. they can still be addressed by using the bsr. access bank 00h ffh bank 0 sfrs bank 1 ?window? not accessible window example situation: 120h 17fh 5fh 60h
? 2009 microchip technology inc. preliminary ds39931b-page 95 pic18f46j50 family 6.0 flash program memory the flash program memory is readable, writable and erasable during normal operation over the entire v dd range. a read from program memory is executed on 1 byte at a time. a write to program memory is executed on blocks of 64 bytes at a time or 2 bytes at a time. program memory is erased in blocks of 1024 bytes at a time. a bulk erase operation may not be issued from user code. writing or erasing program memory will cease instruction fetches until the operation is complete. the program memory cannot be accessed during the write or erase, therefore, code cannot execute. an internal programming timer terminates program memory writes and erases. a value written to program memory does not need to be a valid instruction. executing a program memory location that forms an invalid instruction results in a nop . 6.1 table reads and table writes in order to read and write program memory, there are two operations that allow the processor to move bytes between the program memory space and the data ram: ? table read ( tblrd ) ? table write ( tblwt ) the program memory space is 16 bits wide, while the data ram space is 8 bits wide. table reads and table writes move data between these two memory spaces through an 8-bit register (tablat). table read operations retrieve data from program memory and place it into the data ram space. figure 6-1 illustrates the operation of a table read with program memory and data ram. table write operations store data from the data memory space into holding registers in program memory. the procedure to write the contents of the holding registers into program memory is detailed in section 6.5 ?writing to flash program memory? . figure 6-2 illustrates the operation of a table write with program memory and data ram. table operations work with byte entities. a table block containing data, rather than program instructions, is not required to be word-aligned. therefore, a table block can start and end at any byte address. if a table write is being used to write executable code into program memory, program instructions will need to be word-aligned. figure 6-1: table read operation table pointer (1) table latch (8-bit) program memory tblptrh tblptrl tablat tblptru instruction: tblrd * note 1: table pointer register points to a byte in program memory. program memory (tblptr)
pic18f46j50 family ds39931b-page 96 preliminary ? 2009 microchip technology inc. figure 6-2: table write operation 6.2 control registers several control registers are used in conjunction with the tblrd and tblwt instructions. those are: ? eecon1 register ? eecon2 register ? tablat register ? tblptr registers 6.2.1 eecon1 and eecon2 registers the eecon1 register (register 6-1) is the control register for memory accesses. the eecon2 register is not a physical register; it is used exclusively in the memory write and erase sequences. reading eecon2 will read all ? 0 ?s. the wprog bit, when set, will allow programming two bytes per word on the execution of the wr command. if this bit is cleared, the wr command will result in programming on a block of 64 bytes. the free bit, when set, will allow a program memory erase operation. when free is set, the erase operation is initiated on the next wr command. when free is clear, only writes are enabled. the wren bit, when set, will allow a write operation. on power-up, the wren bit is clear. the wrerr bit is set in hardware when the wr bit is set and cleared when the internal programming timer expires and the write operation is complete. the wr control bit initiates write operations. the bit cannot be cleared, only set, in software. it is cleared in hardware at the completion of the write operation. ta b l e p o i n t e r (1) table latch (8-bit) tblptrh tblptrl tablat program memory (tblptr) tblptru instruction: tblwt* note 1: table pointer actually points to one of 64 holding registers, the address of which is determined by tblptrl<5:0>. the process for physically writing data to the program memory array is discussed in section 6.5 ?writing to flash program memory? . holding registers program memory note: during normal operation, the wrerr is read as ? 1 ?. this can indicate that a write operation was prematurely terminated by a reset, or a write operation was attempted improperly.
? 2009 microchip technology inc. preliminary ds39931b-page 97 pic18f46j50 family register 6-1: eecon1: eeprom co ntrol register 1 (access fa6h) u-0 u-0 r/w-0 r/w-0 r/w-x r/w-0 r/s-0 u-0 ? ? wprog free wrerr wren wr ? bit 7 bit 0 legend: s = settable bit (cannot be cleared in software) r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5 wprog: one word-wide program bit 1 = program 2 bytes on the next wr command 0 = program 64 bytes on the next wr command bit 4 free: flash erase enable bit 1 = perform an erase operation on the next wr command (cleared by hardware after completion of erase) 0 = perform write only bit 3 wrerr: flash program error flag bit 1 = a write operation is prematurely terminated (any reset during self-timed programming in normal operation, or an improper write attempt) 0 = the write operation completed bit 2 wren: flash program write enable bit 1 = allows write cycles to flash program memory 0 = inhibits write cycles to flash program memory bit 1 wr: write control bit 1 = initiates a program memory erase cycle or write cycle (the operation is self-timed and the bit is cleared by hardware once write is complete. the wr bit can only be set (not cleared) in software.) 0 = write cycle is complete bit 0 unimplemented: read as ? 0 ?
pic18f46j50 family ds39931b-page 98 preliminary ? 2009 microchip technology inc. 6.2.2 table latch register (tablat) the table latch (tablat) is an 8-bit register mapped into the special function register (sfr) space. the table latch register is used to hold 8-bit data during data transfers between program memory and data ram. 6.2.3 table pointer register (tblptr) the table pointer (tblptr) register addresses a byte within the program memory. the tblptr comprises three sfr registers: table pointer upper byte, table pointer high byte and table pointer low byte (tblptru:tblptrh:tblptrl). these three registers join to form a 22-bit wide pointer. the low-order 21 bits allow the device to address up to 2 mbytes of program memory space. the 22 nd bit allows access to the device id, the user id and the configuration bits. the table pointer register, tblptr, is used by the tblrd and tblwt instructions. these instructions can update the tblptr in one of four ways based on the table operation. table 6-1 provides these operations. these operations on the tblptr only affect the low-order 21 bits. 6.2.4 table pointer boundaries tblptr is used in reads, writes and erases of the flash program memory. when a tblrd is executed, all 22 bits of the tblptr determine which byte is read from program memory into tablat. when a tblwt is executed, the seven least significant bits (lsbs) of the table pointer register (tblptr<6:0>) determine which of the 64 program memory holding registers is written to. when the timed write to program memory begins (via the wr bit), the 12 most significant bits (msbs) of the tblptr (tblptr<21:10>) determine which program memory block of 1024 bytes is written to. for more information, see section 6.5 ?writing to flash program memory? . when an erase of program memory is executed, the 12 msbs of the table pointer register point to the 1024-byte block that will be erased. the lsbs are ignored. figure 6-3 illustrates the relevant boundaries of tblptr based on flash program memory operations. table 6-1: table pointer operations with tblrd and tblwt instructions figure 6-3: table pointer boundaries based on operation example operation on table pointer tblrd* tblwt* tblptr is not modified tblrd*+ tblwt*+ tblptr is incremented after the read/write tblrd*- tblwt*- tblptr is decremented after the read/write tblrd+* tblwt+* tblptr is incremented before the read/write 21 16 15 87 0 erase: tblptr<20:10> table write: tblptr<20:6> table read: tblptr<21:0> tblptrl tblptrh tblptru
? 2009 microchip technology inc. preliminary ds39931b-page 99 pic18f46j50 family 6.3 reading the flash program memory the tblrd instruction is used to retrieve data from program memory and places it into data ram. table reads from program memory are performed one byte at a time. tblptr points to a byte address in program space. executing tblrd places the byte pointed to into tablat. in addition, tblptr can be modified automatically for the next table read operation. the internal program memory is typically organized by words. the lsb of the address selects between the high and low bytes of the word. figure 6-4 illustrates the interface between the internal program memory and the tablat. figure 6-4: reads from flash program memory example 6-1: reading a flash program memory word (even byte address) program memory (odd byte address) tblrd tablat tblptr = xxxxx1 fetch instruction register (ir) read register tblptr = xxxxx0 movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the word movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl read_word tblrd*+ ; read into tablat and increment movf tablat, w ; get data movwf word_even tblrd*+ ; read into tablat and increment movf tablat, w ; get data movwf word_odd
pic18f46j50 family ds39931b-page 100 preliminary ? 2009 microchip technology inc. 6.4 erasing flash program memory the minimum erase block is 512 words or 1024 bytes. only through the use of an external programmer, or through icsp control, can larger blocks of program memory be bulk erased. word erase in the flash array is not supported. when initiating an erase sequence from the micro- controller itself, a block of 1024 bytes of program memory is erased. the most significant 12 bits of the tblptr<21:10> point to the block being erased; tblptr<9:0> are ignored. the eecon1 register commands the erase operation. the wren bit must be set to enable write operations. the free bit is set to select an erase operation. for protection, the write initiate sequence for eecon2 must be used. a long write is necessary for erasing the internal flash. instruction execution is halted while in a long write cycle. the long write will be terminated by the internal programming timer. 6.4.1 flash program memory erase sequence the sequence of events for erasing a block of internal program memory location is: 1. load table pointer register with address of row being erased. 2. set the wren and free bits (eecon1<2,4>) to enable the erase operation. 3. disable interrupts. 4. write 55h to eecon2. 5. write 0aah to eecon2. 6. set the wr bit; this will begin the erase cycle. 7. the cpu will stall for the duration of the erase for t ie (see parameter d133b). 8. re-enable interrupts. example 6-2: erasing flash program memory movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the memory block movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl erase_row bsf eecon1, wren ; enable write to memory bsf eecon1, free ; enable erase operation bcf intcon, gie ; disable interrupts required movlw 55h sequence movwf eecon2 ; write 55h movlw 0aah movwf eecon2 ; write 0aah bsf eecon1, wr ; start erase (cpu stall) bsf intcon, gie ; re-enable interrupts
? 2009 microchip technology inc. preliminary ds39931b-page 101 pic18f46j50 family 6.5 writing to flash program memory the programming block is 32 words or 64 bytes. programming one word or 2 bytes at a time is also supported. table writes are used internally to load the holding registers needed to program the flash memory. there are 64 holding registers used by the table writes for programming. since the table latch (tablat) is only a single byte, the tblwt instruction may need to be executed 64 times for each programming operation (if wprog = 0 ). all of the table write operations will essentially be short writes because only the holding registers are written. at the end of updating the 64 holding registers, the eecon1 register must be written to in order to start the programming operation with a long write. the long write is necessary for programming the internal flash. instruction execution is halted while in a long write cycle. the long write will be terminated by the internal programming timer. the on-chip timer controls the write time. the write/erase voltages are generated by an on-chip charge pump, rated to operate over the voltage range of the device. figure 6-5: table writes to flash program memory 6.5.1 flash program memory write sequence the sequence of events for programming an internal program memory location should be: 1. read 1024 bytes into ram. 2. update data values in ram as necessary. 3. load table pointer register with address being erased. 4. execute the erase procedure. 5. load table pointer register with address of first byte being written, minus 1. 6. write the 64 bytes into the holding registers with auto-increment. 7. set the wren bit (eecon1<2>) to enable byte writes. 8. disable interrupts. 9. write 55h to eecon2. 10. write 0aah to eecon2. 11. set the wr bit. this will begin the write cycle. 12. the cpu will stall for the duration of the write for t iw (see parameter d133a). 13. re-enable interrupts. 14. repeat steps 6 through 13 until all 1024 bytes are written to program memory. 15. verify the memory (table read). an example of the required code is provided in example 6-3 on the following page. note 1: unlike previous pic ? devices, devices of the pic18f46j50 family do not reset the holding registers after a write occurs. the holding registers must be cleared or overwritten before a programming sequence. 2: to maintain the endurance of the program memory cells, each flash byte should not be programmed more than once between erase operations. before attempting to modify the contents of the target cell a second time, an erase of the target page, or a bulk erase of the entire memory, must be performed. tablat tblptr = xxxx3f tblptr = xxxxx1 tblptr = xxxxx0 write register tblptr = xxxxx2 program memory holding register holding register holding register holding register 8 8 8 8 note: before setting the wr bit, the table pointer address needs to be within the intended address range of the 64 bytes in the holding register.
pic18f46j50 family ds39931b-page 102 preliminary ? 2009 microchip technology inc. example 6-3: writing to flash program memory movlw code_addr_upper ; load tblptr with the base address movwf tblptru ; of the memory block, minus 1 movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl erase_block bsf eecon1, wren ; enable write to memory bsf eecon1, free ; enable erase operation bcf intcon, gie ; disable interrupts movlw 55h movwf eecon2 ; write 55h movlw 0aah movwf eecon2 ; write 0aah bsf eecon1, wr ; start erase (cpu stall) bsf intcon, gie ; re-enable interrupts movlw d'16' movwf write_counter ; need to write 16 blocks of 64 to write ; one erase block of 1024 restart_buffer movlw d'64' movwf counter movlw buffer_addr_high ; point to buffer movwf fsr0h movlw buffer_addr_low movwf fsr0l fill_buffer ... ; read the new data from i2c, spi, ; psp, usart, etc. write_buffer movlw d?64 ; number of bytes in holding register movwf counter write_byte_to_hregs movff postinc0, wreg ; get low byte of buffer data movwf tablat ; present data to table latch tblwt+* ; write data, perform a short write ; to internal tblwt holding register. decfsz counter ; loop until buffers are full bra write_byte_to_hregs program_memory bsf eecon1, wren ; enable write to memory bcf intcon, gie ; disable interrupts movlw 55h required movwf eecon2 ; write 55h sequence movlw 0aah movwf eecon2 ; write 0aah bsf eecon1, wr ; start program (cpu stall) bsf intcon, gie ; re-enable interrupts bcf eecon1, wren ; disable write to memory decfsz write_counter ; done with one write cycle bra restart_buffer ; if not done replacing the erase block
? 2009 microchip technology inc. preliminary ds39931b-page 103 pic18f46j50 family 6.5.2 flash program memory write sequence (word proramming). the pic18f46j50 family of devices has a feature that allows programming a single word (two bytes). this feature is enabled when the wprog bit is set. if the memory location is already erased, the following sequence is required to enable this feature: 1. load the table pointer register with the address of the data to be written. (it must be an even address.) 2. write the 2 bytes into the holding registers by performing table writes. (do not post-increment on the second table write.) 3. set the wren bit (eecon1<2>) to enable writes and the wprog bit (eecon1<5>) to select word write mode. 4. disable interrupts. 5. write 55h to eecon2. 6. write 0aah to eecon2. 7. set the wr bit; this will begin the write cycle. 8. the cpu will stall for the duration of the write for t iw (see parameter d133a). 9. re-enable interrupts. example 6-4: single-word write to flash program memory movlw code_addr_upper ; load tblptr with the base address movwf tblptru movlw code_addr_high movwf tblptrh movlw code_addr_low ; the table pointer must be loaded with an even address movwf tblptrl movlw data0 ; lsb of word to be written movwf tablat tblwt*+ movlw data1 ; msb of word to be written movwf tablat tblwt* ; the last table write must not increment the table pointer! the table pointer needs to point to the msb before starting the write operation. program_memory bsf eecon1, wprog ; enable single word write bsf eecon1, wren ; enable write to memory bcf intcon, gie ; disable interrupts movlw 55h required movwf eecon2 ; write 55h sequence movlw 0aah movwf eecon2 ; write aah bsf eecon1, wr ; start program (cpu stall) bsf intcon, gie ; re-enable interrupts bcf eecon1, wprog ; disable single word write bcf eecon1, wren ; disable write to memory
pic18f46j50 family ds39931b-page 104 preliminary ? 2009 microchip technology inc. 6.5.3 write verify depending on the application, good programming practice may dictate that the value written to the memory should be verified against the original value. this should be used in applications where excessive writes can stress bits near the specification limit. 6.5.4 unexpected termination of write operation if a write is terminated by an unplanned event, such as loss of power or an unexpected reset, the memory location just programmed should be verified and repro- grammed if needed. if the write operation is interrupted by a mclr reset or a wdt time-out reset during normal operation, the user can check the wrerr bit and rewrite the location(s) as needed. 6.6 flash program operation during code protection see section 26.6 ?program verification and code protection? for details on code protection of flash program memory. table 6-2: registers associated with program flash memory name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: tblptru ? ? bit 21 program memory table pointer upper byte (tblptr<20:16>) 61 tbpltrh program memory table pointer high byte (tblptr<15:8>) 61 tblptrl program memory table pointer low byte (tblptr<7:0>) 61 tablat program memory table latch 61 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 61 eecon2 program memory control register 2 (not a physical register) 63 eecon1 ? ? wprog free wrerr wren wr ?63 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used during flash program memory access.
? 2009 microchip technology inc. preliminary ds39931b-page 105 pic18f46j50 family 7.0 8 x 8 hardware multiplier 7.1 introduction all pic18 devices include an 8 x 8 hardware multiplier as part of the alu. the multiplier performs an unsigned operation and yields a 16-bit result that is stored in the product register pair, prodh:prodl. the multiplier?s operation does not affect any flags in the status register. making multiplication a hardware operation allows it to be completed in a single instruction cycle. this has the advantages of higher computational throughput and reduced code size for multiplication algorithms and allows the pic18 devices to be used in many applica- tions previously reserved for digital signal processors. table 7-1 provides a comparison of various hardware and software multiply operations, along with the savings in memory and execution time. 7.2 operation example 7-1 provides the instruction sequence for an 8 x 8 unsigned multiplication. only one instruction is required when one of the arguments is already loaded in the wreg register. example 7-2 provides the instruction sequence for an 8 x 8 signed multiplication. to account for the sign bits of the arguments, each argument?s most significant bit (msb) is tested and the appropriate subtractions are done. example 7-1: 8 x 8 unsigned multiply routine example 7-2: 8 x 8 signed multiply routine table 7-1: performance comparison fo r various multiply operations movf arg1, w ; mulwf arg2 ; arg1 * arg2 -> ; prodh:prodl movf arg1, w mulwf arg2 ; arg1 * arg2 -> ; prodh:prodl btfsc arg2, sb ; test sign bit subwf prodh, f ; prodh = prodh ; - arg1 movf arg2, w btfsc arg1, sb ; test sign bit subwf prodh, f ; prodh = prodh ; - arg2 routine multiply method program memory (words) cycles (max) time @ 48 mhz @ 10 mhz @ 4 mhz 8 x 8 unsigned without hardware multiply 13 69 5.7 s27.6 s69 s hardware multiply 1 1 83.3 ns 400 ns 1 s 8 x 8 signed without hardware multiply 33 91 7.5 s36.4 s91 s hardware multiply 6 6 500 ns 2.4 s6 s 16 x 16 unsigned without hardware multiply 21 242 20.1 s96.8 s242 s hardware multiply 28 28 2.3 s 11.2 s28 s 16 x 16 signed without hardware multiply 52 254 21.6 s 102.6 s254 s hardware multiply 35 40 3.3 s16.0 s40 s
pic18f46j50 family ds39931b-page 106 preliminary ? 2009 microchip technology inc. example 7-3 provides the instruction sequence for a 16 x 16 unsigned multiplication. equation 7-1 provides the algorithm that is used. the 32-bit result is stored in four registers (res<3:0>). equation 7-1: 16 x 16 unsigned multiplication algorithm example 7-3: 16 x 16 unsigned multiply routine example 7-4 provides the sequence to do a 16 x 16 signed multiply. equation 7-2 provides the algorithm used. the 32-bit result is stored in four registers (res<3:0>). to account for the sign bits of the arguments, the msb for each argument pair is tested and the appropriate subtractions are done. equation 7-2: 16 x 16 signed multiplication algorithm example 7-4: 16 x 16 signed multiply routine res3:res0 = arg1h:arg1l arg2h:arg2l = (arg1h arg2h 2 16 ) + (arg1h arg2l 2 8 ) + (arg1l arg2h 2 8 ) + (arg1l arg2l) movf arg1l, w mulwf arg2l ; arg1l * arg2l-> ; prodh:prodl movff prodh, res1 ; movff prodl, res0 ; ; movf arg1h, w mulwf arg2h ; arg1h * arg2h-> ; prodh:prodl movff prodh, res3 ; movff prodl, res2 ; ; movf arg1l, w mulwf arg2h ; arg1l * arg2h-> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; ; movf arg1h, w ; mulwf arg2l ; arg1h * arg2l-> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; res3:res0 = arg1h:arg1l arg2h:arg2l = (arg1h arg2h 2 16 ) + (arg1h arg2l 2 8 ) + (arg1l arg2h 2 8 ) + (arg1l arg2l) + (-1 arg2h<7> arg1h:arg1l 2 16 ) + (-1 arg1h<7> arg2h:arg2l 2 16 ) movf arg1l, w mulwf arg2l ; arg1l * arg2l -> ; prodh:prodl movff prodh, res1 ; movff prodl, res0 ; ; movf arg1h, w mulwf arg2h ; arg1h * arg2h -> ; prodh:prodl movff prodh, res3 ; movff prodl, res2 ; ; movf arg1l, w mulwf arg2h ; arg1l * arg2h -> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; ; movf arg1h, w ; mulwf arg2l ; arg1h * arg2l -> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; ; btfss arg2h, 7 ; arg2h:arg2l neg? bra sign_arg1 ; no, check arg1 movf arg1l, w ; subwf res2 ; movf arg1h, w ; subwfb res3 ; sign_arg1 btfss arg1h, 7 ; arg1h:arg1l neg? bra cont_code ; no, done movf arg2l, w ; subwf res2 ; movf arg2h, w ; subwfb res3 ; cont_code :
? 2009 microchip technology inc. preliminary ds39931b-page 107 pic18f46j50 family 8.0 interrupts devices of the pic18f46j50 family have multiple inter- rupt sources and an interrupt priority feature that allows most interrupt sources to be assigned a high-priority level or a low-priority level. the high-priority interrupt vector is at 0008h and the low-priority interrupt vector is at 0018h. high-priority interrupt events will interrupt any low-priority interrupts that may be in progress. there are 13 registers, which are used to control interrupt operation. these registers are: ? rcon ?intcon ? intcon2 ? intcon3 ? pir1, pir2, pir3 ? pie1, pie2, pie3 ? ipr1, ipr2, ipr3 it is recommended that the microchip header files supplied with mplab ? ide be used for the symbolic bit names in these registers. this allows the assembler/compiler to automatically take care of the placement of these bits within the specified register. in general, interrupt sources have three bits to control their operation. they are: ? flag bit to indicate that an interrupt event occurred ? enable bit that allows program execution to branch to the interrupt vector address when the flag bit is set ? priority bit to select high priority or low priority the interrupt priority feature is enabled by setting the ipen bit (rcon<7>). when interrupt priority is enabled, there are two bits which enable interrupts globally. setting the gieh bit (intcon<7>) enables all interrupts that have the priority bit set (high priority). setting the giel bit (intcon<6>) enables all interrupts that have the priority bit cleared (low priority). when the interrupt flag, enable bit and appropriate global interrupt enable bit are set, the interrupt will vector immediately to address 0008h or 0018h, depending on the priority bit setting. individual interrupts can be disabled through their corresponding enable bits. when the ipen bit is cleared (default state), the interrupt priority feature is disabled and interrupts are compatible with pic ? mid-range devices. in compatibility mode, the interrupt priority bits for each source have no effect. intcon<6> is the peie bit, which enables/disables all peripheral interrupt sources. intcon<7> is the gie bit, which enables/disables all interrupt sources. all interrupts branch to address 0008h in compatibility mode. when an interrupt is responded to, the global interrupt enable bit is cleared to disable further interrupts. if the ipen bit is cleared, this is the gie bit. if interrupt priority levels are used, this will be either the gieh or giel bit. high-priority interrupt sources can interrupt a low-priority interrupt. low-priority interrupts are not processed while high-priority interrupts are in progress. the return address is pushed onto the stack and the pc is loaded with the interrupt vector address (0008h or 0018h). once in the interrupt service routine, the source(s) of the interrupt can be determined by polling the interrupt flag bits. the interrupt flag bits must be cleared in software before re-enabling interrupts to avoid recursive interrupts. the ?return from interrupt? instruction, retfie , exits the interrupt routine and sets the gie bit (gieh or giel if priority levels are used), which re-enables interrupts. for external interrupt events, such as the intx pins or the portb input change interrupt, the interrupt latency will be three to four instruction cycles. the exact latency is the same for one or two-cycle instructions. individual interrupt flag bits are set regardless of the status of their corresponding enable bit or the gie bit. note: do not use the movff instruction to modify any of the interrupt control registers while any interrupt is enabled. doing so may cause erratic microcontroller behavior.
pic18f46j50 family ds39931b-page 108 preliminary ? 2009 microchip technology inc. figure 8-1: pic18f46j50 family interrupt logic tmr0ie gie/gieh peie/giel wake-up if in interrupt to cpu vector to location 0008h int2if int2ie int2ip int1if int1ie int1ip tmr0if tmr0ie tmr0ip rbif rbie rbip ipen tmr0if tmr0ip int1if int1ie int1ip int2if int2ie int2ip rbif rbie rbip int0if int0ie peie/giel interrupt to cpu vector to location ipen ipen 0018h pir1<7:0> pie1<7:0> ipr1<7:0> high-priority interrupt generation low-priority interrupt generation idle or sleep modes gie/gieh int3if int3ie int3ip int3if int3ie int3ip pir2<7:0> pie2<7:0> ipr2<7:0> pir3<7:0> pie3<7:0> ipr3<7:0> pir1<7:0> pie1<7:0> ipr1<7:0> pir2<7:0> pie2<7:0> ipr2<7:0> pir3<7:0> pie3<7:0> ipr3<7:0> ipen
? 2009 microchip technology inc. preliminary ds39931b-page 109 pic18f46j50 family 8.1 intcon registers the intcon registers are readable and writable registers, which contain various enable, priority and flag bits. note: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global interrupt enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling. register 8-1: intcon: interrupt co ntrol register (access ff2h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-x gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 gie/gieh: global interrupt enable bit when ipen = 0 : 1 = enables all unmasked interrupts 0 = disables all interrupts when ipen = 1 : 1 = enables all high-priority interrupts 0 = disables all interrupts bit 6 peie/giel: peripheral interrupt enable bit when ipen = 0 : 1 = enables all unmasked peripheral interrupts 0 = disables all peripheral interrupts when ipen = 1 : 1 = enables all low-priority peripheral interrupts 0 = disables all low-priority peripheral interrupts bit 5 tmr0ie: tmr0 overflow interrupt enable bit 1 = enables the tmr0 overflow interrupt 0 = disables the tmr0 overflow interrupt bit 4 int0ie: int0 external interrupt enable bit 1 = enables the int0 external interrupt 0 = disables the int0 external interrupt bit 3 rbie: rb port change interrupt enable bit 1 = enables the rb port change interrupt 0 = disables the rb port change interrupt bit 2 tmr0if: tmr0 overflow interrupt flag bit 1 = tmr0 register has overflowed (must be cleared in software) 0 = tmr0 register did not overflow bit 1 int0if: int0 external interrupt flag bit 1 = the int0 external interrupt occurred (must be cleared in software) 0 = the int0 external interrupt did not occur bit 0 rbif: rb port change interrupt flag bit (1) 1 = at least one of the rb<7:4> pins changed state (must be cleared in software) 0 = none of the rb<7:4> pins have changed state note 1: a mismatch condition will continue to set this bit. reading portb and waiting 1 t cy will end the mismatch condition and allow the bit to be cleared.
pic18f46j50 family ds39931b-page 110 preliminary ? 2009 microchip technology inc. register 8-2: intcon2: interrupt control register 2 (access ff1h) r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rbpu intedg0 intedg1 intedg2 intedg3 tmr0ip int3ip rbip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rbpu : portb pull-up enable bit 1 = all portb pull-ups are disabled 0 = portb pull-ups are enabled by individual port latch values bit 6 intedg0: external interrupt 0 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 5 intedg1: external interrupt 1 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 4 intedg2: external interrupt 2 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 3 intedg3: external interrupt 3 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 2 tmr0ip: tmr0 overflow interrupt priority bit 1 =high priority 0 = low priority bit 1 int3ip: int3 external interrupt priority bit 1 =high priority 0 = low priority bit 0 rbip: rb port change interrupt priority bit 1 =high priority 0 = low priority note: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global interrupt enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling.
? 2009 microchip technology inc. preliminary ds39931b-page 111 pic18f46j50 family register 8-3: intcon3: interrupt control register 3 (access ff0h) r/w-1 r/w-1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 int2ip int1ip int3ie int2ie int1ie int3if int2if int1if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 int2ip: int2 external interrupt priority bit 1 =high priority 0 = low priority bit 6 int1ip: int1 external interrupt priority bit 1 =high priority 0 = low priority bit 5 int3ie: int3 external interrupt enable bit 1 = enables the int3 external interrupt 0 = disables the int3 external interrupt bit 4 int2ie: int2 external interrupt enable bit 1 = enables the int2 external interrupt 0 = disables the int2 external interrupt bit 3 int1ie: int1 external interrupt enable bit 1 = enables the int1 external interrupt 0 = disables the int1 external interrupt bit 2 int3if: int3 external interrupt flag bit 1 = the int3 external interrupt occurred (must be cleared in software) 0 = the int3 external interrupt did not occur bit 1 int2if: int2 external interrupt flag bit 1 = the int2 external interrupt occurred (must be cleared in software) 0 = the int2 external interrupt did not occur bit 0 int1if: int1 external interrupt flag bit 1 = the int1 external interrupt occurred (must be cleared in software) 0 = the int1 external interrupt did not occur note: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global interrupt enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling.
pic18f46j50 family ds39931b-page 112 preliminary ? 2009 microchip technology inc. 8.2 pir registers the pir registers contain the individual flag bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are three peripheral interrupt request (flag) registers (pir1, pir2, pir3). note 1: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global interrupt enable bit, gie (intcon<7>). 2: user software should ensure the appropriate interrupt flag bits are cleared prior to enabling an interrupt and after servicing that interrupt. register 8-4: pir1: peripheral interrupt request (flag) register 1 (access f9eh) r/w-0 r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 pmpif (1) adif rc1if tx1if ssp1if ccp1if tmr2if tmr1if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 pmpif: parallel master port read/write interrupt flag bit (1) 1 = a read or a write operation has taken place (must be cleared in software) 0 = no read or write has occurred bit 6 adif: a/d converter interrupt flag bit 1 = an a/d conversion completed (must be cleared in software) 0 = the a/d conversion is not complete bit 5 rc1if: eusart1 receive interrupt flag bit 1 = the eusart1 receive buffer, rcreg1, is full (cleared when rcreg1 is read) 0 = the eusart1 receive buffer is empty bit 4 tx1if: eusart1 transmit interrupt flag bit 1 = the eusart1 transmit buffer, txreg1, is empty (cleared when txreg1 is written) 0 = the eusart1 transmit buffer is full bit 3 ssp1if: master synchronous serial port 1 interrupt flag bit 1 = the transmission/reception is complete (must be cleared in software) 0 = waiting to transmit/receive bit 2 ccp1if: eccp1 interrupt flag bit capture mode: 1 = a tmr1/tmr3 register capture occurred (must be cleared in software) 0 = no tmr1/tmr3 register capture occurred compare mode: 1 = a tmr1/tmr3 register compare match occurred (must be cleared in software) 0 = no tmr1/tmr3 register compare match occurred pwm mode: unused in this mode. bit 1 tmr2if: tmr2 to pr2 match interrupt flag bit 1 = tmr2 to pr2 match occurred (must be cleared in software) 0 = no tmr2 to pr2 match occurred bit 0 tmr1if: tmr1 overflow interrupt flag bit 1 = tmr1 register overflowed (must be cleared in software) 0 = tmr1 register did not overflow note 1: these bits are unimplemented on 28-pin devices.
? 2009 microchip technology inc. preliminary ds39931b-page 113 pic18f46j50 family register 8-5: pir2: peripheral interrupt request (flag) register 2 (access fa1h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 oscfif cm2if cm1if usbif bcl1if hlvdif tmr3if ccp2if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 oscfif: oscillator fail interrupt flag bit 1 = device oscillator failed, clock input has changed to intosc (must be cleared in software) 0 = device clock operating bit 6 cm2if: comparator 2 interrupt flag bit 1 = comparator input has changed (must be cleared in software) 0 = comparator input has not changed bit 5 cm1if: comparator 1 interrupt flag bit 1 = comparator input has changed (must be cleared in software) 0 = comparator input has not changed bit 4 usbif: usb interrupt flag bit 1 = usb has requested an interrupt (must be cleared in software) 0 = no usb interrupt request bit 3 bcl1if: bus collision interrupt flag bit (mssp1 module) 1 = a bus collision occurred (must be cleared in software) 0 = no bus collision occurred bit 2 hlvdif: high/low-voltage detect (hlvd) interrupt flag bit 1 = a high/low-voltage condition occurred (must be cleared in software) 0 = an hlvd event has not occurred bit 1 tmr3if: tmr3 overflow interrupt flag bit 1 = tmr3 register overflowed (must be cleared in software) 0 = tmr3 register did not overflow bit 0 ccp2if: eccp2 interrupt flag bit capture mode: 1 = a tmr1/tmr3 register capture occurred (must be cleared in software) 0 = no tmr1/tmr3 register capture occurred compare mode: 1 = a tmr1/tmr3 register compare match occurred (must be cleared in software) 0 = no tmr1/tmr3 register compare match occurred pwm mode: unused in this mode.
pic18f46j50 family ds39931b-page 114 preliminary ? 2009 microchip technology inc. register 8-6: pir3: peripheral interrupt request (flag) register 3 (access fa4h) r/w-0 r/w-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ssp2if bcl2if rc2if tx2if tmr4if ctmuif tmr3gif rtccif bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ssp2if: master synchronous serial port 2 interrupt flag bit 1 = the transmission/reception is complete (must be cleared in software) 0 = waiting to transmit/receive bit 6 bcl2if: bus collision interrupt flag bit (mssp2 module) 1 = a bus collision occurred (must be cleared in software) 0 = no bus collision occurred bit 5 rc2if: eusart2 receive interrupt flag bit 1 = the eusart2 receive buffer, rcreg2, is full (cleared when rcreg2 is read) 0 = the eusart2 receive buffer is empty bit 4 tx2if: eusart2 transmit interrupt flag bit 1 = the eusart2 transmit buffer, txreg2, is empty (cleared when txreg2 is written) 0 = the eusart2 transmit buffer is full bit 3 tmr4if: tmr4 to pr4 match interrupt flag bit 1 = tmr4 to pr4 match occurred (must be cleared in software) 0 = no tmr4 to pr4 match occurred bit 2 ctmuif: charge time measurement unit interrupt flag bit 1 = a ctmu event has occurred (must be cleared in software) 0 = ctmu event has not occurred bit 1 tmr3gif: timer3 gate event interrupt flag bit 1 = a timer3 gate event completed (must be cleared in software) 0 = no timer3 gate event completed bit 0 rtccif: rtcc interrupt flag bit 1 = rtcc interrupt occurred (must be cleared in software) 0 = no rtcc interrupt occurred
? 2009 microchip technology inc. preliminary ds39931b-page 115 pic18f46j50 family 8.3 pie registers the pie registers contain the individual enable bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are three peripheral interrupt enable registers (pie1, pie2, pie3). when ipen = 0 , the peie bit must be set to enable any of these peripheral interrupts. register 8-7: pie1: peripheral inte rrupt enable register 1 (access f9dh) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 pmpie (1) adie rc1ie tx1ie ssp1ie ccp1ie tmr2ie tmr1ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 pmpie: parallel master port read/write interrupt enable bit (1) 1 = enables the pmp read/write interrupt 0 = disables the pmp read/write interrupt bit 6 adie: a/d converter interrupt enable bit 1 = enables the a/d interrupt 0 = disables the a/d interrupt bit 5 rc1ie: eusart1 receive interrupt enable bit 1 = enables the eusart1 receive interrupt 0 = disables the eusart1 receive interrupt bit 4 tx1ie: eusart1 transmit interrupt enable bit 1 = enables the eusart1 transmit interrupt 0 = disables the eusart1 transmit interrupt bit 3 ssp1ie: master synchronous serial port 1 interrupt enable bit 1 = enables the mssp1 interrupt 0 = disables the mssp1 interrupt bit 2 ccp1ie: eccp1 interrupt enable bit 1 = enables the eccp1 interrupt 0 = disables the eccp1 interrupt bit 1 tmr2ie: tmr2 to pr2 match interrupt enable bit 1 = enables the tmr2 to pr2 match interrupt 0 = disables the tmr2 to pr2 match interrupt bit 0 tmr1ie: tmr1 overflow interrupt enable bit 1 = enables the tmr1 overflow interrupt 0 = disables the tmr1 overflow interrupt note 1: these bits are unimplemented on 28-pin devices.
pic18f46j50 family ds39931b-page 116 preliminary ? 2009 microchip technology inc. register 8-8: pie2: peripheral interrupt enable register 2 (access fa0h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 oscfie cm2ie cm1ie usbie bcl1ie hlvdie tmr3ie ccp2ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 oscfie: oscillator fail interrupt enable bit 1 = enabled 0 = disabled bit 6 cm2ie: comparator 2 interrupt enable bit 1 = enabled 0 = disabled bit 5 cm1ie: comparator 1 interrupt enable bit 1 = enabled 0 = disabled bit 4 usbie: usb interrupt enable bit 1 = enabled 0 = disabled bit 3 bcl1ie: bus collision interrupt enable bit (mssp1 module) 1 = enabled 0 = disabled bit 2 hlvdie: high/low-voltage detect interrupt enable bit 1 = enabled 0 = disabled bit 1 tmr3ie: tmr3 overflow interrupt enable bit 1 = enabled 0 = disabled bit 0 ccp2ie: eccp2 interrupt enable bit 1 = enabled 0 = disabled
? 2009 microchip technology inc. preliminary ds39931b-page 117 pic18f46j50 family register 8-9: pie3: peripheral interrupt enable register 3 (access fa3h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ssp2ie bcl2ie rc2ie tx2ie tmr4ie ctmuie tmr3gie rtccie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ssp2ie: master synchronous serial port 2 interrupt enable bit 1 = enabled 0 = disabled bit 6 bcl2ie: bus collision interrupt enable bit (mssp2 module) 1 = enabled 0 = disabled bit 5 rc2ie: eusart2 receive interrupt enable bit 1 = enabled 0 = disabled bit 4 tx2ie: eusart2 transmit interrupt enable bit 1 = enabled 0 = disabled bit 3 tmr4ie: tmr4 to pr4 match interrupt enable bit 1 = enabled 0 = disabled bit 2 ctmuie: charge time measurement unit (ctmu) interrupt enable bit 1 = enabled 0 = disabled bit 1 tmr3gie : timer3 gate interrupt enable bit 1 = enabled 0 = disabled bit 0 rtccie : rtcc interrupt enable bit 1 = enabled 0 = disabled
pic18f46j50 family ds39931b-page 118 preliminary ? 2009 microchip technology inc. 8.4 ipr registers the ipr registers contain the individual priority bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are three peripheral interrupt priority registers (ipr1, ipr2, ipr3). using the priority bits requires that the interrupt priority enable (ipen) bit be set. register 8-10: ipr1: peripheral interrupt priority register 1 (access f9fh) r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 pmpip (1) adip rc1ip tx1ip ssp1ip ccp1ip tmr2ip tmr1ip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 pmpip: parallel master port read/write interrupt priority bit (1) 1 =high priority 0 = low priority bit 6 adip: a/d converter interrupt priority bit 1 =high priority 0 = low priority bit 5 rc1ip: eusart1 receive interrupt priority bit 1 =high priority 0 = low priority bit 4 tx1ip: eusart1 transmit interrupt priority bit 1 =high priority 0 = low priority bit 3 ssp1ip: master synchronous serial port interrupt priority bit (mssp1 module) 1 =high priority 0 = low priority bit 2 ccp1ip: eccp1 interrupt priority bit 1 =high priority 0 = low priority bit 1 tmr2ip: tmr2 to pr2 match interrupt priority bit 1 =high priority 0 = low priority bit 0 tmr1ip: tmr1 overflow interrupt priority bit 1 =high priority 0 = low priority note 1: these bits are unimplemented on 28-pin devices.
? 2009 microchip technology inc. preliminary ds39931b-page 119 pic18f46j50 family register 8-11: ipr2: peripheral interrup t priority register 2 (access fa2h) r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 oscfip cm2ip cm1ip usbip bcl1ip hlvdip tmr3ip ccp2ip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 oscfip: oscillator fail interrupt priority bit 1 =high priority 0 = low priority bit 6 cm2ip: comparator 2 interrupt priority bit 1 =high priority 0 = low priority bit 5 c12ip: comparator 1 interrupt priority bit 1 =high priority 0 = low priority bit 4 usbip: usb interrupt priority bit 1 =high priority 0 = low priority bit 3 bcl1ip: bus collision interrupt priority bit (mssp1 module) 1 =high priority 0 = low priority bit 2 hlvdip: high/low-voltage detect interrupt priority bit 1 =high priority 0 = low priority bit 1 tmr3ip: tmr3 overflow interrupt priority bit 1 =high priority 0 = low priority bit 0 ccp2ip: eccp2 interrupt priority bit 1 =high priority 0 = low priority
pic18f46j50 family ds39931b-page 120 preliminary ? 2009 microchip technology inc. register 8-12: ipr3: peripheral interrup t priority register 3 (access fa5h) r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 ssp2ip bcl2ip rc2ip tx2ip tmr4ip ctmuip tmr3gip rtccip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ssp2ip: master synchronous serial port 2 interrupt priority bit 1 =high priority 0 = low priority bit 6 bcl2ip: bus collision interrupt priority bit (mssp2 module) 1 =high priority 0 = low priority bit 5 rc2ip: eusart2 receive interrupt priority bit 1 =high priority 0 = low priority bit 4 tx2ip: eusart2 transmit interrupt priority bit 1 =high priority 0 = low priority bit 3 tmr4ie: tmr4 to pr4 interrupt priority bit 1 =high priority 0 = low priority bit 2 ctmuip: charge time measurement unit (ctmu) interrupt priority bit 1 =high priority 0 = low priority bit 1 tmr3gip: timer3 gate interrupt priority bit 1 =high priority 0 = low priority bit 0 rtccip: rtcc interrupt priority bit 1 =high priority 0 = low priority
? 2009 microchip technology inc. preliminary ds39931b-page 121 pic18f46j50 family 8.5 rcon register the rcon register contains bits used to determine the cause of the last reset or wake-up from idle or sleep mode. rcon also contains the bit that enables interrupt priorities (ipen). register 8-13: rcon: reset cont rol register (access fd0h) r/w-0 u-0 r/w-1 r/w-1 r-1 r-1 r/w-0 r/w-0 ipen ?cm ri to pd por bor bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ipen: interrupt priority enable bit 1 = enable priority levels on interrupts 0 = disable priority levels on interrupts (pic16cxxx compatibility mode) bit 6 unimplemented: read as ? 0 ? bit 5 cm: configuration mismatch flag bit for details on bit operation, see register 4-1. bit 4 ri : reset instruction flag bit for details on bit operation, see register 4-1. bit 3 to : watchdog timer time-out flag bit for details on bit operation, see register 4-1. bit 2 pd : power-down detection flag bit for details on bit operation, see register 4-1. bit 1 por : power-on reset status bit for details on bit operation, see register 4-1. bit 0 bor : brown-out reset status bit for details on bit operation, see register 4-1.
pic18f46j50 family ds39931b-page 122 preliminary ? 2009 microchip technology inc. 8.6 intx pin interrupts external interrupts on the int0, int1, int2 and int3 pins are edge-triggered. if the corresponding intedgx bit in the intcon2 register is set (= 1 ), the interrupt is triggered by a rising edge; if the bit is clear, the trigger is on the falling edge. when a valid edge appears on the intx pin, the corresponding flag bit and intxif are set. this interrupt can be disabled by clearing the corresponding enable bit, intxie. flag bit, intxif, must be cleared in software in the interrupt service routine before re-enabling the interrupt. all external interrupts (int0, int1, int2 and int3) can wake-up the processor from the power-managed modes if bit, intxie, was set prior to going into the power-managed modes. if the global interrupt enable bit, gie, is set, the processor will branch to the interrupt vector following wake-up. interrupt priority for int1, int2 and int3 is determined by the value contained in the interrupt priority bits, int1ip (intcon3<6>), int2ip (intcon3<7>) and int3ip (intcon2<1>). there is no priority bit associated with int0. it is always a high-priority interrupt source. 8.7 tmr0 interrupt in 8-bit mode (which is the default), an overflow in the tmr0 register (ffh 00h) will set flag bit, tmr0if. in 16-bit mode, an overflow in the tmr0h:tmr0l register pair (ffffh 0000h) will set tmr0if. the interrupt can be enabled/disabled by setting/clearing enable bit, tmr0ie (intcon<5>). interrupt priority for timer0 is determined by the value contained in the interrupt prior- ity bit, tmr0ip (intcon2<2>). see section 11.0 ?timer0 module? for further details on the timer0 module. 8.8 portb interrupt-on-change an input change on portb<7:4> sets flag bit, rbif (intcon<0>). the interrupt can be enabled/disabled by setting/clearing enable bit, rbie (intcon<3>). interrupt priority for portb interrupt-on-change is determined by the value contained in the interrupt priority bit, rbip (intcon2<0>). 8.9 context saving during interrupts during interrupts, the return pc address is saved on the stack. additionally, the wreg, status and bsr registers are saved on the fast return stack. if a fast return from interrupt is not used (see section 5.3 ?data memory organization? ), the user may need to save the wreg, status and bsr registers on entry to the interrupt service routine. depending on the user?s application, other registers may also need to be saved. example 8-1 saves and restores the wreg, status and bsr registers during an interrupt service routine. example 8-1: saving status, wreg and bsr registers in ram movwf w_temp ; w_temp is in virtual bank movff status, status_temp ; status_temp located anywhere movff bsr, bsr_temp ; bsr_tmep located anywhere ; ; user isr code ; movff bsr_temp, bsr ; restore bsr movf w_temp, w ; restore wreg movff status_temp, status ; restore status
? 2009 microchip technology inc. preliminary ds39931b-page 123 pic18f46j50 family 9.0 i/o ports depending on the device selected and features enabled, there are up to five ports available. some pins of the i/o ports are multiplexed with an alternate function from the peripheral features on the device. in general, when a peripheral is enabled, that pin may not be used as a general purpose i/o pin. each port has three registers for its operation. these registers are: ? tris register (data direction register) ? port register (reads the levels on the pins of the device) ? lat register (data latch) the data latch (lat register) is useful for read-modify- write operations on the value that the i/o pins are driving. figure 9-1 displays a simplified model of a generic i/o port, without the interfaces to other peripherals. figure 9-1: generic i/o port operation 9.1 i/o port pin capabilities when developing an application, the capabilities of the port pins must be considered. outputs on some pins have higher output drive strength than others. similarly, some pins can tolerate higher than v dd input levels. 9.1.1 pin output drive the output pin drive strengths vary for groups of pins intended to meet the needs for a variety of applications. portb and portc are designed to drive higher loads, such as leds. all other ports are designed for small loads, typically indication only. table 9-1 sum- marizes the output capabilities. refer to section 29.0 ?electrical characteristics? for more details. table 9-1: output drive levels 9.1.2 input pins and voltage considerations the voltage tolerance of pins used as device inputs is dependent on the pin?s input function. pins that are used as digital only inputs are able to handle dc voltages up to 5.5v; a level typical for digital logic circuits. in contrast, pins that also have analog input functions of any kind can only tolerate voltages up to v dd . voltage excursions beyond v dd on these pins should be avoided. table 9-2 summarizes the input capabilities. refer to section 29.0 ?electrical characteristics? for more details. table 9-2: input voltage levels data bus wr lat wr tris rd port data latch tris latch rd tris input buffer i/o pin (1) q d ck q d ck en qd en rd lat or port note 1: i/o pins have diode protection to v dd and v ss . port drive description porta minimum intended for indication. portd porte portb high suitable for direct led drive levels. portc port or pin tolerated input description porta<7:0> v dd only v dd input levels tolerated. portb<3:0> portc<2:0> porte<2:0> portb<7:4> 5.5v tolerates input levels above v dd , useful for most standard logic. portc<7:6> portd<7:0> portc<5:4> (usb) designed for usb specifications.
pic18f46j50 family ds39931b-page 124 preliminary ? 2009 microchip technology inc. 9.1.3 interfacing to a 5v system though the v ddmax of the pic18f46j50 family is 3.6v, these devices are still capable of interfacing with 5v systems, even if the v ih of the target system is above 3.6v. this is accomplished by adding a pull-up resistor to the port pin (figure 9-2), clearing the lat bit for that pin and manipulating the corresponding tris bit (figure 9-1) to either allow the line to be pulled high or to drive the pin low. only port pins that are tolerant of voltages up to 5.5v can be used for this type of interface (refer to section 9.1.2 ?input pins and voltage considerations? ). figure 9-2: +5v system hardware interface example 9-1: communicating with the +5v system 9.1.4 open-drain outputs the output pins for several peripherals are also equipped with a configurable open-drain output option. this allows the peripherals to communicate with external digital logic operating at a higher voltage level, without the use of level translators. the open-drain option is implemented on port pins specifically associated with the data and clock outputs of the eusarts, the mssp modules (in spi mode) and the eccp modules. it is selectively enabled by setting the open-drain control bit for the corresponding module in the odcon registers (register 9-1, register 9-2 and register 9-3). their configuration is discussed in more detail with the individual port where these peripherals are multiplexed. output functions that are routed through the pps module may also use the open-drain option. the open-drain functionality will follow the i/o pin assignment in the pps module. when the open-drain option is required, the output pin must also be tied through an external pull-up resistor provided by the user to a higher voltage level, up to 5.5v (figure 9-3). when a digital logic high signal is output, it is pulled up to the higher voltage level. figure 9-3: using the open-drain output (usart shown as example) 9.1.5 ttl input buffer option many of the digital i/o ports use schmitt trigger (st) input buffers. while this form of buffering works well with many types of input, some applications may require ttl level signals to interface with external logic devices. this is particularly true for the parallel master port (pmp), which is likely to be interfaced to ttl level logic or memory devices. the inputs for the pmp can be optionally configured for ttl buffers with the pmpttl bit in the padcfg1 reg- ister (register 9-4). setting this bit configures all data and control input pins for the pmp to use ttl buffers. by default, these pmp inputs use the port?s st buffers. rd7 +5v device +5v pic18f46j50 bcf latd, 7 ; set up lat register so ; changing tris bit will ; drive line low bcf trisd, 7 ; send a 0 to the 5v system bcf trisd, 7 ; send a 1 to the 5v system tx x +5v (at logic ? 1 ?) 3.3v v dd 5v pic18f46j50
? 2009 microchip technology inc. preliminary ds39931b-page 125 pic18f46j50 family register 9-1: odcon1: peripheral open -drain control register 1 (banked f42h) u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 ? ? ? ? ? ? eccp2od eccp1od bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-2 unimplemented: read as ? 0 ? bit 1 eccp2od: eccp2 open-drain output enable bit 1 = open-drain capability enabled 0 = open-drain capability disabled bit 0 eccp1od: eccp1 open-drain output enable bit 1 = open-drain capability enabled 0 = open-drain capability disabled register 9-2: odcon2: peripheral open -drain control register 2 (banked f41h) u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 ? ? ? ? ? ? u2od u1od bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-2 unimplemented: read as ? 0 ? bit 1 u2od: usart2 open-drain output enable bit 1 = open-drain capability enabled 0 = open-drain capability disabled bit 0 u1od: usart1 open-drain output enable bit 1 = open-drain capability enabled 0 = open-drain capability disabled
pic18f46j50 family ds39931b-page 126 preliminary ? 2009 microchip technology inc. register 9-3: odcon3: peripheral open -drain control register 3 (banked f40h) u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 ? ? ? ? ? ? spi2od spi1od bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-2 unimplemented: read as ? 0 ? bit 1 spi2od: spi2 open-drain output enable bit 1 = open-drain capability enabled 0 = open-drain capability disabled bit 0 spi1od: spi1 open-drain output enable bit 1 = open-drain capability enabled 0 = open-drain capability disabled register 9-4: padcfg1: pad configurat ion control register 1 (banked f3ch) u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 ? ? ? ? ? rtsecsel1 (1) rtsecsel0 (1) pmpttl bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-3 unimplemented: read as ? 0 ? bit 2-1 rtsecsel<1:0>: rtcc seconds clock output select bits (1) 11 = reserved; do not use 10 = rtcc source clock is selected for the rtcc pin (can be intrc, t1osc or t1cki depending upon the rtcosc (config3l<1>) and t1oscen (t1con<3>) bit settings) 01 = rtcc seconds clock is selected for the rtcc pin 00 = rtcc alarm pulse is selected for the rtcc pin bit 0 pmpttl: pmp module ttl input buffer select bit 1 = pmp module uses ttl input buffers 0 = pmp module uses schmitt trigger input buffers note 1: to enable the actual rtcc output, the rtcoe (rtccfg<2>) bit needs to be set.
? 2009 microchip technology inc. preliminary ds39931b-page 127 pic18f46j50 family 9.2 porta, trisa and lata registers porta is a 7-bit wide, bidirectional port. it may function as a 5-bit port, depending on the oscillator mode selected. setting a trisa bit (= 1 ) will make the corresponding porta pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisa bit (= 0 ) will make the corresponding porta pin an output (i.e., put the contents of the output latch on the selected pin). reading the porta register reads the status of the pins, whereas writing to it, will write to the port latch. the data latch (lata) register is also memory mapped. read-modify-write operations on the lata register read and write the latched output value for porta. the other porta pins are multiplexed with analog inputs, the analog v ref + and v ref - inputs and the com- parator voltage reference output. the operation of pins, ra<3:0> and ra5, as a/d converter inputs is selected by clearing or setting the control bits in the adcon1 register (a/d control register 1). pins, ra0 and ra3, may also be used as comparator inputs and by setting the appropriate bits in the cmcon register. to use ra<3:0> as digital inputs, it is also necessary to turn off the comparators. all porta pins have ttl input levels and full cmos output drivers. the trisa register controls the direction of the porta pins, even when they are being used as analog inputs. the user must ensure the bits in the trisa register are maintained set when using them as analog inputs. example 9-2: initializing porta note: on a power-on reset (por), ra5 and ra<3:0> are configured as analog inputs and read as ? 0 ?. clrf porta ; initialize porta by ; clearing output ; data latches clrf lata ; alternate method ; to clear output ; data latches movlw 07h ; configure a/d movwf adcon1 ; for digital inputs movwf 07h ; configure comparators movwf cmcon ; for digital input movlw 0cfh ; value used to ; initialize data ; direction movwf trisa ; set ra<3:0> as inputs ; ra<5:4> as outputs
pic18f46j50 family ds39931b-page 128 preliminary ? 2009 microchip technology inc. table 9-3: porta i/o summary pin function tris setting i/o i/o type description ra0/an0/c1ina/ ulpwu/rp0 ra0 1 i/o dig porta<0> data input; disabled when analog input enabled. 0 ttl lata<0> data output; not affected by analog input. an0 1 i ana a/d input channel 0 and comparator c1- input. default input configuration on por; does not affect digital output. c1ina 1 i ana comparator 1 input a. ulpwu 1 i ana ultra low-power wake-up input. rp0 1 1/o st remappable peripheral pin 0 input. 0 dig remappable peripheral pin 0 output. ra1/an1/c2ina/ pma7/rp1 ra1 1 i dig porta<1> data input; disabled when analog input enabled. 0 o ttl lata<1> data output; not affected by analog input. an1 1 i ana a/d input channel 1 and comparator c2- input. default input configuration on por; does not affect digital output. c2ina 1 i ana comparator 1 input a. pma7 (1) 1 i/o st/ ttl parallel master port io_addr_in[7] . 0 dig parallel master port address. rp1 1 i/o st remappable peripheral pin 1 input. 0 dig remappable peripheral pin 1 output ra2/an2/ v ref -/cv ref / c2inb ra2 0 o dig lata<2> data output; not affected by analog input. disabled when cv ref output enabled. 1 i ttl porta<2> data input. disabled when analog functions enabled; disabled when cv ref output enabled. an2 1 i ana a/d input channel 2 and comparator c2+ input. default input configuration on por; not affected by analog output. v ref - 1 i ana a/d and comparator voltage reference low input. cv ref x o ana comparator voltage reference output. enabling this feature disables digital i/o. c2inb i i ana comparator 2 input b. 0 o ana ctmu pulse generator charger for the c2inb comparator input. ra3/an3/v ref +/ c1inb ra3 0 o dig lata<3> data output; not affected by analog input. 1 i ttl porta<3> data input; disabled when analog input enabled. an3 1 i ana a/d input channel 3 and comparator c1+ input. default input configuration on por. v ref + 1 i ana a/d and comparator voltage reference high input. c1inb 1 i ana comparator 1 input b legend: dig = digital level output; ttl = ttl input buffer; st = schmitt trigger input buffer; ana = analog level input/output; x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: this bit is only available on 44-pin devices.
? 2009 microchip technology inc. preliminary ds39931b-page 129 pic18f46j50 family table 9-4: summary of regist ers associated with porta ra5/an4/ss1 / hlvdin/rcv/ rp2 ra5 0 o dig lata<5> data output; not affected by analog input. 1 i ttl porta<5> data input; disabled when analog input enabled. an4 1 i ana a/d input channel 4. default configuration on por. ss1 1 i ttl slave select input for mssp1. hlvdin 1 i ana high/low-voltage detect external trip point reference input. rcv 1 i ttl external usb transceiver rcv input. rp2 1 i st remappable peripheral pin 2 input. 0 o dig remappable peripheral pin 2 output. osc2/clko/ ra6 osc2 x o ana main oscillator feedback output connection (hs mode). clko x o dig system cycle clock output (f osc /4) in rc and ec oscillator modes. ra6 1 i ttl porta<6> data input. 0 o dig lata<6> data output. osc1/clki/ra7 osc1 1 i ana main oscillator input connection. clki 1 i ana main clock input connection. ra7 1 i ttl porta<6> data input. 0 o dig lata<6> data output. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page porta ra7 ra6 ra5 ? ra3 ra2 ra1 ra0 79 lata lat7 lat6 lat5 ? lat3lat2lat1lat0 84 trisa tris7 tris6 trisa5 ? trisa3 trisa2 trisa1 trisa0 84 ancon0 pcfg7 (1) pcfg6 (1) pcfg5 (1) pcfg4 pcfg3 pcfg2 pcfg1 pcfg0 82 cmxcon con coe cpol evpol1 evpol0 cref cch1 cch0 82, 82 cvrcon cvren cvroe cvrr r cvr3 cvr2 cvr1 cvr0 85 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by porta. note 1: these bits are only available in 44-pin devices. table 9-3: porta i/o summary (continued) pin function tris setting i/o i/o type description legend: dig = digital level output; ttl = ttl input buffer; st = schmitt trigger input buffer; ana = analog level input/output; x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: this bit is only available on 44-pin devices.
pic18f46j50 family ds39931b-page 130 preliminary ? 2009 microchip technology inc. 9.3 portb, trisb and latb registers portb is an 8-bit wide, bidirectional port. the corre- sponding data direction register is trisb. setting a trisb bit (= 1 ) will make the corresponding portb pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisb bit (= 0 ) will make the corresponding portb pin an output (i.e., put the contents of the output latch on the selected pin). the data latch register (latb) is also memory mapped. read-modify-write operations on the latb register read and write the latched output value for portb. example 9-3: initializing portb each of the portb pins has a weak internal pull-up. a single control bit can turn on all the pull-ups. this is performed by clearing bit, rbpu (intcon2<7>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on a por. the integrated weak pull-ups consist of a semiconductor structure similar to, but somewhat different, from a discrete resistor. on an unloaded i/o pin, the weak pull-ups are intended to provide logic high indication, but will not necessarily pull the pin all the way to v dd levels. four of the portb pins (rb<7:4>) have an interrupt- on-change feature. only pins configured as inputs can cause this interrupt to occur (i.e., any rb<7:4> pin configured as an output is excluded from the interrupt- on-change comparison). the input pins (of rb<7:4>) are compared with the old value latched on the last read of portb. the ?mismatch? outputs of rb<7:4> are ored together to generate the rb port change interrupt with flag bit, rbif (intcon<0>). this interrupt can wake the device from sleep mode or any of the idle modes. application software can clear the interrupt flag by following these steps: 1. any read or write of portb (except with the movff (any), portb instruction). 2. wait one instruction cycle (such as executing a nop instruction). 3. clear flag bit, rbif. a mismatch condition continues to set flag bit, rbif. reading portb will end the mismatch condition and allow flag bit, rbif, to be cleared after one instruction cycle of delay. the interrupt-on-change feature is recommended for wake-up on key depression operation and operations where portb is only used for the interrupt-on-change feature. polling of portb is not recommended while using the interrupt-on-change feature. the rb5 pin is multiplexed with the timer0 module clock input and one of the comparator outputs to become the rb5/kbi1/sdi1/sda1/rp8 pin. note: on a por, the rb<3:0> bits are configured as analog inputs by default and read as ? 0 ?; rb<7:4> bits are configured as digital inputs. clrf portb ; initialize portb by ; clearing output ; data latches clrf latb ; alternate method ; to clear output ; data latches movlw 0x3f ; configure as digital i/o movff wreg adcon1 ; pins in this example movlw 0cfh ; value used to ; initialize data ; direction movwf trisb ; set rb<3:0> as inputs ; rb<5:4> as outputs ; rb<7:6> as inputs
? 2009 microchip technology inc. preliminary ds39931b-page 131 pic18f46j50 family table 9-5: portb i/o summary pin function tris setting i/o i/o type description rb0/an12/ int0/rp3 rb0 1 1 ttl portb<0> data input; weak pull-up when rbpu bit is cleared. disabled when analog input enabled. (1) 0 o dig latb<0> data output; not affected by analog input. an12 1 i ana a/d input channel 12. (1) int0 1 i st external interrupt 0 input. rp3 1 i st remappable peripheral pin 3 input. 0 o dig remappable peripheral pin 3 output. rb1/an10/ rtcc/rp4 rb1 1 i ttl portb<1> data input; weak pull-up when rbpu bit is cleared. disabled when analog input enabled. (1) 0 o dig latb<1> data output; not affected by analog input. an10 1 i ana a/d input channel 10. (1) rtcc 0 o dig asynchronous serial transmit data output (usart module). rp4 1 i st remappable peripheral pin 4 input. 0 o dig remappable peripheral pin 4 output. rb2/an8/ ctedg1/vmo/ refo/rp5 rb2 1 i ttl portb<2> data input; weak pull-up when rbpu bit is cleared. disabled when analog input enabled. (1) 0 o dig latb<2> data output; not affected by analog input. an8 1 i ana a/d input channel 8. (1) ctedg1 1 i st ctmu edge 1 input. vmo 0 o dig external usb transceiver d ? data output. refo 0 o dig reference output clock. rp5 1 i st remappable peripheral pin 5 input. 0 o dig remappable peripheral pin 5 output. rb3/an9/ ctedg2/ pma2/vpo/ rp6 rb3 0 o dig latb<3> data output; not affected by analog input. 1 i ttl portb<3> data input; weak pull-up when rbpu bit is cleared. disabled when analog input enabled. (1) an9 1 i ana a/d input channel 9. (1) ctedg2 1 i st ctmu edge 2 input. pma2 0 o dig parallel master port address. vpo 0 i dig external usb transceiver d+ data output. rp6 1 i st remappable peripheral pin 6 input. 0 o dig remappable peripheral pin 6 output. legend: dig = digital level output; ttl = ttl input buffer; st = schmitt trigger input buffer; ana = analog level input/output; x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: configuration on por is determined by the pbaden configuration bit. pins are configured as analog inputs by default when pbaden is set and digital inputs when pbaden is cleared. 2: all other pin functions are disabled when icsp? or icd are enabled.
pic18f46j50 family ds39931b-page 132 preliminary ? 2009 microchip technology inc. rb4/kbi0/ an11/rp7/ sck1/scl1 rb4 0 o dig latb<4> data output; not affected by analog input. 1 i ttl portb<4> data input; weak pull-up when rbpu bit is cleared. disabled when analog input enabled. (1) kbi0 1 i ttl interrupt-on-change pin. an11 1 i ana a/d input channel 11. (1) rp7 1 i st remappable peripheral pin 7 input. 0 o dig remappable peripheral pin 7 output. sck1 1 i st/ttl parallel master port io_addr_in<1> . 0 o dig parallel master port address. scl1 1 ii 2 c/ smbus i 2 c? clock input (mssp1 module). 0 odigi 2 c clock output (mssp1 module). rb5/kbi1/ sdi1/sda1/ rp8 rb5 0 o dig latb<5> data output. 1 i ttl portb<5> data input; weak pull-up when rbpu bit is cleared. kbi1 1 i ttl interrupt-on-change pin. sdi1 1 i st spi data input (mssp1 module). sda1 1 ii 2 c/ smbus i 2 c data input (mssp1 module). 0 odigi 2 c/smbus. rp8 1 i st remappable peripheral pin 8 input. 0 o dig remappable peripheral pin 8 output. rb6/kbi2/ pgc/rp9 rb6 0 o dig latb<6> data output. 1 i ttl portb<6> data input; weak pull-up when rbpu bit is cleared. kbi2 1 i ttl interrupt-on-change pin. pgc x i st serial execution (icsp?) clock input for icsp and icd operation. (2) rp9 1 i st remappable peripheral pin 9 input. 0 o dig remappable peripheral pin 9 output. rb7/kbi3/ pgd/rp10 rb7 0 o dig latb<7> data output. 1 i ttl portb<7> data input; weak pull-up when rbpu bit is cleared. kbi3 1 i ttl interrupt-on-change pin. pgd x o dig serial execution data output for icsp and icd operation. (2) x i st serial execution data input for icsp and icd operation. (2) rp10 1 i st remappable peripheral pin 10 input. 0 o st remappable peripheral pin 10 output. table 9-5: portb i/o summary (continued) pin function tris setting i/o i/o type description legend: dig = digital level output; ttl = ttl input buffer; st = schmitt trigger input buffer; ana = analog level input/output; x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: configuration on por is determined by the pbaden configuration bit. pins are configured as analog inputs by default when pbaden is set and digital inputs when pbaden is cleared. 2: all other pin functions are disabled when icsp? or icd are enabled.
? 2009 microchip technology inc. preliminary ds39931b-page 133 pic18f46j50 family table 9-6: summary of registers associated with portb name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 84 latb latb7 latb6 latb5 latb4 latb3 latb2 latb1 latb0 84 trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 84 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 81 intcon2 rbpu intedg0 intedg1 intedg2 intedg3 tmr0ip int3ip rbip 81 intcon3 int2ip int1ip int3ie int2ie int1ie int3if int2if int1if 81 adcon0 pcfg7 pcfg6 pcfg5 pcfg4 pcfg3 pcfg2 pcfg1 pcfg0 82 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by portb.
pic18f46j50 family ds39931b-page 134 preliminary ? 2009 microchip technology inc. 9.4 portc, trisc and latc registers portc is an 8-bit wide, bidirectional port. the corre- sponding data direction register is trisc. setting a trisc bit (= 1 ) will make the corresponding portc pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisc bit (= 0 ) will make the corresponding portc pin an output (i.e., put the contents of the output latch on the selected pin). the data latch register (latc) is also memory mapped. read-modify-write operations on the latc register read and write the latched output value for portc. portc is multiplexed with several peripheral functions (see table ). the pins have schmitt trigger input buffers. when enabling peripheral functions, care should be taken in defining tris bits for each portc pin. some peripherals override the tris bit to make a pin an output, while other peripherals override the tris bit to make a pin an input. the user should refer to the corresponding peripheral section for additional information. pins rc4 and rc5 are multiplexed with the usb module. depending on the configuration of the module, they can serve as the differential data lines for the on-chip usb transceiver, or the data inputs from an external usb transceiver. when used as general purpose inputs, both rc4 and rc5 input buffers depend on the level of the voltage applied to the v usb pin, instead of v dd like all other general purpose i/o pins. therefore, if the rc4 or rc5 general purpose input capability will be used, the v usb pin should not be left floating. unlike other portc pins, rc4 and rc5 do not have trisc bits associated with them. as digital ports, they can only function as digital inputs. when configured for usb operation, the data direction is determined by the configuration and status of the usb module at a given time. if an external transceiver is used, rc4 and rc5 always function as inputs from the transceiver. if the on- chip transceiver is used, the data direction is determined by the operation being performed by the module at that time. the contents of the trisc register are affected by peripheral overrides. reading trisc always returns the current contents, even though a peripheral device may be overriding one or more of the pins. example 9-4: initializing portc note: on a power-on reset, portc pins (except rc2, rc4 and rc5) are config- ured as digital inputs. rc2 will default as an analog input (controlled by the ancon1 register). to use pins rc4 and rc5 as digital inputs, the usb module must be disabled (ucon<3> = 0 ) and the on-chip usb transceiver must be disabled (ucfg<3> = 1 ). the internal usb transceiver has a por value of enabled. clrf portc ; initialize portc by ; clearing output ; data latches clrf latc ; alternate method ; to clear output ; data latches movlw 0x3f ; value used to ; initialize data ; direction movwf trisc ; set rc<5:0> as inputs ; rc<7:6> as outputs movlb 0x0f ; ancon register is not in access bank bsf ancon1,pcfg11 ;configure rc2/an11 as digital input
? 2009 microchip technology inc. preliminary ds39931b-page 135 pic18f46j50 family table 9-7: portc i/o summary (1) pin function tris setting i/o i/o type description rc0/t1oso/ t1cki/rp11 rc0 1 i st portc<0> data input. 0 o dig latc<0> data output. t1oso x o ana timer1 oscillator output; enabled when timer1 oscillator enabled. disables digital i/o. t1cki 1 i st timer1 digital clock input. rp11 1 i st remappable peripheral pin 11 input. 0 o dig remappable peripheral pin 11 output. rc1/t1osi/ uoe /rp12 rc1 1 i st portc<1> data input. 0 o dig latc<1> data output. t1osi x i ana timer1 oscillator input; enabled when timer1 oscillator enabled. disables digital i/o. uoe 0 o dig external usb transceiver noe output. rp12 1 i st remappable peripheral pin 12 input. 0 o dig remappable peripheral pin 12 output. rc2/an11/ ctpls/rp13 rc2 1 i st portc<2> data input. 0 o dig portc<2> data output. an11 1 i ana a/d input channel 11. ctpls 0 o dig ctmu pulse generator output. rp13 1 i st remappable peripheral pin 13 input. 0 o dig remappable peripheral pin 13 output. rc4/d-/vm rc4 x i ttl portc<4> data input. d- x i xcvr usb bus minus line output. x o xcvr usb bus minus line input. vm 1 i ttl external usb transceiver vp input. rc5/d+/vp rc5 x i ttl portc<5> data input. d+ x i xcvr usb bus plus line input. x o xcvr usb bus plus line output. vp 1 i ttl external usb transceiver vp input. legend: dig = digital level output; ttl = ttl input buffer; st = schmitt trigger input buffer; ana = analog level input/output; i 2 c/smb = i 2 c/smbus input buffer; x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: enhanced pwm output is available only on pic18f4xj50 devices. 2: this bit is only available on 44-pin devices.
pic18f46j50 family ds39931b-page 136 preliminary ? 2009 microchip technology inc. table 9-8: summary of regist ers associated with portc rc6/pma5/ tx1/ck1/rp17 rc6 1 i st portc<6> data input. 0 o dig latc<6> data output. pma5 (2) 1 i st/ttl parallel master port io_addr_in<5> . 0 o dig parallel master port address. tx1 0 o dig asynchronous serial transmit data output (eusart module); takes priority over port data. user must configure as output. ck1 1 i st synchronous serial clock input (eusart module). 0 o dig synchronous serial clock output (eusart module); takes priority over port data. rp17 1 i st remappable peripheral pin 17 input. 0 o dig remappable peripheral pin 17 output. rc7/rx1/dt1/ sdo1/rp18 rc7 1 i st portc<7> data input. 0 o dig latc<7> data output. rx1 1 i st asynchronous serial receive data input (eusart module). dt1 1 1 st synchronous serial data input (eusart module). user must configure as an input. 0 o dig synchronous serial data output (eusart module); takes priority over port data. sdo1 0 o dig spi data output (mssp1 module). rp18 1 i st remappable peripheral pin 18 input. 0 o dig remappable peripheral pin 18 output. table 9-7: portc i/o summary (1) (continued) pin function tris setting i/o i/o type description legend: dig = digital level output; ttl = ttl input buffer; st = schmitt trigger input buffer; ana = analog level input/output; i 2 c/smb = i 2 c/smbus input buffer; x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: enhanced pwm output is available only on pic18f4xj50 devices. 2: this bit is only available on 44-pin devices. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: portc rc7 rc6 rc5 rc4 ? rc2 rc1 rc0 84 latc latc7 latc6 latc5 latc4 ? latc2 latc1 latc0 84 trisc trisc7 trisc6 trisc5 trisc4 ? trisc2 trisc1 trisc0 84
? 2009 microchip technology inc. preliminary ds39931b-page 137 pic18f46j50 family 9.5 portd, trisd and latd registers portd is an 8-bit wide, bidirectional port. the corre- sponding data direction register is trisd. setting a trisd bit (= 1 ) will make the corresponding portd pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisd bit (= 0 ) will make the corresponding portd pin an output (i.e., put the contents of the output latch on the selected pin). the data latch register (latd) is also memory mapped. read-modify-write operations on the latd register read and write the latched output value for portd. all pins on portd are implemented with schmitt trigger input buffers. each pin is individually configurable as an input or output. example 9-5: initializing portd each of the portd pins has a weak internal pull-up. a single control bit can turn on all the pull-ups. this is per- formed by setting bit, rdpu (porte<7>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on a por. the integrated weak pull-ups consist of a semi- conductor structure similar to, but somewhat different, from a discrete resistor. on an unloaded i/o pin, the weak pull-ups are intended to provide logic high indica- tion, but will not necessarily pull the pin all the way to v dd levels. note that the pull-ups can be used for any set of features, similar to the pull-ups found on portb. note: portd is available only in 44-pin devices. note: on a por, these pins are configured as digital inputs. clrf portd ; initialize portd by ; clearing output ; data latches clrf latd ; alternate method ; to clear output ; data latches movlw 0cfh ; value used to ; initialize data ; direction movwf trisd ; set rd<3:0> as inputs ; rd<5:4> as outputs ; rd<7:6> as inputs table 9-9: portd i/o summary pin function tris setting i/o i/o type description rd0/pmd0/ scl2 rd0 1 i st portd<0> data input. 0 o dig latd<0> data output. pmd0 1 i st/ttl parallel master port data in. 0 o dig parallel master port data out. scl2 1 ii 2 c/ smb i 2 c? clock input (mssp2 module); input type depends on module setting. 0 odigi 2 c clock output (mssp2 module); takes priority over port data. rd1/pmd1/ sda2 rd1 1 i st portd<1> data input. 0 o dig latd<1> data output. pmd1 1 i ttl parallel master port data in. 0 o dig parallel master port data out. sda2 1 ii 2 c/ smb i 2 c data input (mssp2 module); input type depends on mod- ule setting. 0 odigi 2 c data output (mssp2 module); takes priority over port data. rd2/pmd2/ rp19 rd2 1 i st portd<2> data input. 0 o dig latd<2> data output. pmd2 1 i ttl parallel master port data in. 0 o dig parallel master port data out. rp19 1 i st remappable peripheral pin 19 input. 0 o dig remappable peripheral pin 19 output. legend: dig = digital level output; ttl = ttl input buffer; st = schmitt trigger input buffer; i 2 c/smb = i 2 c/smbus input buffer; x = don?t care (tris bit does not affect port direction or is overridden for this option).
pic18f46j50 family ds39931b-page 138 preliminary ? 2009 microchip technology inc. table 9-10: summary of regist ers associated with portd rd3/pmd3/ rp20 rd3 1 i dig portd<3> data input. 0 o dig latd<3> data output. pmd3 1 i st/ttl parallel master port data in. 0 o dig parallel master port data out. rp20 1 i st remappable peripheral pin 20 input. 0 o dig remappable peripheral pin 20 output. rd4/pmd4/ rp21 rd4 1 i st portd<4> data input. 0 o dig latd<4> data output. pmd4 1 i ttl parallel master port data in. 0 o dig parallel master port data out. rp21 1 i st remappable peripheral pin 21 input. 0 o dig remappable peripheral pin 21 output. rd5/pmd5/ rp22 rd5 1 i st portd<5> data input. 0 o dig latd<5> data output. pmd5 1 i ttl parallel master port data in. 0 o dig parallel master port data out. rp22 1 i st remappable peripheral pin 22 input. 0 o dig remappable peripheral pin 22 output. rd6/pmd6/ rp23 rd6 1 i st portd<6> data input. 0 o dig latd<6> data output. pmd6 1 i ttl parallel master port data in. 0 o dig parallel master port data out. rp23 1 i st remappable peripheral pin 23 input. 0 o dig remappable peripheral pin 23 output. rd7/pmd7/ rp24 rd7 1 i st portd<7> data input. 0 o dig latd<7> data output. pmd7 1 i ttl parallel master port data in. 0 o dig parallel master port data out. rp24 1 i st remappable peripheral pin 24 input. 0 o dig remappable peripheral pin 24 output. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page portd (1) rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0 84 latd (1) latd7 latd6 latd5 latd4 latd3 latd2 latd1 latd0 84 trisd (1) trisd7 trisd6 trisd5 trisd4 trisd3 trisd2 trisd1 trisd0 84 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by portd. note 1: these registers are not available in 28-pin devices. table 9-9: portd i/o summary (continued) pin function tris setting i/o i/o type description legend: dig = digital level output; ttl = ttl input buffer; st = schmitt trigger input buffer; i 2 c/smb = i 2 c/smbus input buffer; x = don?t care (tris bit does not affect port direction or is overridden for this option).
? 2009 microchip technology inc. preliminary ds39931b-page 139 pic18f46j50 family 9.6 porte, trise and late registers depending on the particular pic18f46j50 family device selected, porte is implemented in two different ways. for 44-pin devices, porte is a 3-bit wide port. three pins (re0/an5/pmrd, re1/an6/pmwr and re2/ an7/pmcs) are individually configurable as inputs or outputs. these pins have schmitt trigger input buffers. when selected as analog inputs, these pins will read as ? 0 ?s. the corresponding data direction register is trise. setting a trise bit (= 1 ) will make the corresponding porte pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trise bit (= 0 ) will make the corresponding porte pin an output (i.e., put the contents of the output latch on the selected pin). trise controls the direction of the re pins, even when they are being used as analog inputs. the user must make sure to keep the pins configured as inputs when using them as analog inputs. the data latch register (late) is also memory mapped. read-modify-write operations on the late register read and write the latched output value for porte. example 9-6: initializing porte each of the porte pins has a weak internal pull-up. a single control bit can turn on all the pull-ups. this is per- formed by setting bit, repu (porte<6>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on a por. the integrated weak pull-ups consist of a semi- conductor structure similar to, but somewhat different, from a discrete resistor. on an unloaded i/o pin, the weak pull-ups are intended to provide logic high indica- tion, but will not necessarily pull the pin all the way to v dd levels. note that the pull-ups can be used for any set of features, similar to the pull-ups found on portb note: porte is available only in 44-pin devices. note: on a por, re<2:0> are configured as analog inputs. clrf porte ; initialize porte by ; clearing output ; data latches clrf late ; alternate method ; to clear output ; data latches movlw 0ah ; configure a/d movwf adcon1 ; for digital inputs movlw 03h ; value used to ; initialize data ; direction movwf trise ; set re<0> as inputs ; re<1> as outputs ; re<2> as inputs
pic18f46j50 family ds39931b-page 140 preliminary ? 2009 microchip technology inc. table 9-11: porte i/o summary table 9-12: summary of regist ers associated with porte pin function tris setting i/o i/o type description re0/an5/ pmrd re0 1 i st porte<0> data input; disabled when analog input enabled. 0 o dig late<0> data output; not affected by analog input. an5 1 i ana a/d input channel 5; default input configuration on por. pmrd 1 i st/ttl parallel master port io_rd_in . 0 o dig parallel master port read strobe. re1/an6/ pmwr re1 1 i st porte<1> data input; disabled when analog input enabled. 0 o dig late<1> data output; not affected by analog input. an6 1 i ana a/d input channel 6; default input configuration on por. pmwr 1 i st/ttl parallel master port io_wr_in . 0 o dig parallel master port write strobe. re2/an7/ pmcs re2 1 i st porte<2> data input; disabled when analog input enabled. 0 o dig late<2> data output; not affected by analog input. an7 1 i ana a/d input channel 7; default input configuration on por. pmcs 0 o dig parallel master port byte enable. v ss 1 ? ? p ? ground reference for logic and i/o pins. v ss 2 av ss 1 ? ? p ? ground reference for analog modules. v dd 1 ? ? p ? positive supply for peripheral digital logic and i/o pins. v dd 2 v ddcore /v cap v ddcore ? p ? positive supply for microcontroller core logic (regulator disabled). v cap ? p ? external filter capacitor connection (regulator enabled). av dd 1 ?? p ? positive supply for analog modules. av dd 2? v usb ? ? p ? usb voltage input pin. legend: dig = digital level output; ttl = ttl input buffer; st = schmitt trigger input buffer; ana = analog level i = input; o = output; p = power name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page porte (1) rdpu repu ? ? ? re2 re1 re0 84 late (1) ? ? ? ? ? late2 late1 late0 84 trise (1) ? ? ? ? ? trise2 trise1 trise0 84 ancon0 pcfg7 (2) pcfg6 (2) pcfg5 (2) pcfg4 pcfg3 pcfg2 pcfg1 pcfg0 86 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by porte. note 1: these registers are not available in 28-pin devices. 2: these bits are only available in 44-pin devices. note: bit 7 rdpu: portd pull-up enable bit 0 = all portd pull-ups are disabled 1 = portd pull-ups are enabled for any input pad bit 6 repu: porte pull-up enable bit 0 = all porte pull-ups are disabled 1 = porte pull-ups are enabled for any input pad
? 2009 microchip technology inc. preliminary ds39931b-page 141 pic18f46j50 family 9.7 peripheral pin select (pps) a major challenge in general purpose devices is provid- ing the largest possible set of peripheral features while minimizing the conflict of features on i/o pins. the challenge is even greater on low pin count devices similar to the pic18f46j50 family. in an application that needs to use more than one peripheral multiplexed on single pin, inconvenient workarounds in application code or a complete redesign may be the only option. the peripheral pin select (pps) feature provides an alternative to these choices by enabling the user?s peripheral set selection and their placement on a wide range of i/o pins. by increasing the pinout options available on a particular device, users can better tailor the microcontroller to their entire application, rather than trimming the application to fit the device. the pps feature operates over a fixed subset of digital i/o pins. users may independently map the input and/ or output of any one of the many digital peripherals to any one of these i/o pins. pps is performed in software and generally does not require the device to be reprogrammed. hardware safeguards are included that prevent accidental or spurious changes to the peripheral mapping once it has been established. 9.7.1 available pins the pps feature is used with a range of up to 22 pins; the number of available pins is dependent on the particular device and its pin count. pins that support the pps feature include the designation ?rpn? in their full pin designation, where ?rp? designates a remappable peripheral and ?n? is the remappable pin number. see table 1-2 for pinout options in each package offering. 9.7.2 available peripherals the peripherals managed by the pps are all digital only peripherals. these include general serial commu- nications (uart and spi), general purpose timer clock inputs, timer-related peripherals (input capture and output compare) and external interrupt inputs. also included are the outputs of the comparator module, since these are discrete digital signals. the pps module is not applied to i 2 c, change notifica- tion inputs, rtcc alarm outputs or peripherals with analog inputs. additionally, the mssp1 and eusart1 modules are not routed through the pps module. a key difference between pin select and non-pin select peripherals is that pin select peripherals are not asso- ciated with a default i/o pin. the peripheral must always be assigned to a specific i/o pin before it can be used. in contrast, non-pin select peripherals are always available on a default pin, assuming that the peripheral is active and not conflicting with another peripheral. 9.7.2.1 peripheral pin select function priority when a pin selectable peripheral is active on a given i/o pin, it takes priority over all other digital i/o and digital communication peripherals associated with the pin. priority is given regardless of the type of peripheral that is mapped. pin select peripherals never take priority over any analog functions associated with the pin. 9.7.3 controlling peripheral pin select pps features are controlled through two sets of special function registers (sfrs): one to map peripheral inputs and the other to map outputs. because they are separately controlled, a particular peripheral?s input and output (if the peripheral has both) can be placed on any selectable function pin without constraint. the association of a peripheral to a peripheral selectable pin is handled in two different ways, depending on whether an input or an output is being mapped.
pic18f46j50 family ds39931b-page 142 preliminary ? 2009 microchip technology inc. 9.7.3.1 input mapping the inputs of the pps options are mapped on the basis of the peripheral; that is, a control register associated with a peripheral dictates the pin it will be mapped to. the rpinrx registers are used to configure peripheral input mapping (see register 9-6 through register 9-20). each register contains a 5-bit field which is associated with one of the pin selectable peripherals. pro- gramming a given peripheral?s bit field with an appropriate 5-bit value maps the rpn pin with that value to that peripheral. for any given device, the valid range of values for any of the bit fields corresponds to the maximum number of peripheral pin selections supported by the device. table 9-13: selectable input sources (maps input to function) (1) input name function name register configuration bits external interrupt 1 int1 rpinr1 intr1r<4:0> external interrupt 2 int2 rpinr2 intr2r<4:0> external interrupt 3 int3 rpinr3 intr3r<4:0> timer0 external clock input t0cki rpinr4 t0ckr<4:0> timer3 external clock input t3cki rpinr6 t3ckr<4:0> input capture 1 ccp1 rpinr7 ic1r<4:0> input capture 2 ccp2 rpinr8 ic2r<4:0> timer1 gate input t1g rpinr12 t1gr<4:0> timer3 gate input t3g rpinr13 t3gr<4:0> eusart2 asynchronous receive/synchronous receive rx2/dt2 rpinr16 rx2dt2r<4:0> eusart2 asynchronous clock input ck2 rpinr17 ck2r<4:0> spi2 data input sdi2 rpinr21 sdi2r<4:0> spi2 clock input sck2in rpinr22 sck2r<4:0> spi2 slave select input ss2in rpinr23 ss2r<4:0> pwm fault input flt0 rpinr24 ocfar<4:0> note 1: unless otherwise noted, all inputs use the schmitt trigger input buffers.
? 2009 microchip technology inc. preliminary ds39931b-page 143 pic18f46j50 family 9.7.3.2 output mapping in contrast to inputs, the outputs of the pps options are mapped on the basis of the pin. in this case, a control register associated with a particular pin dictates the peripheral output to be mapped. the rporx registers are used to control output mapping. the value of the bit field corresponds to one of the peripherals and that peripheral?s output is mapped to the pin (see table 9-14). because of the mapping technique, the list of peripherals for output mapping also includes a null value of ? 00000 ?. this permits any given pin to remain disconnected from the output of any of the pin selectable peripherals. table 9-14: selectable output sources (maps function to output) function output function number (1) output name null 0 null (2) c1out 1 comparator 1 output c2out 2 comparator 2 output tx2/ck2 5 eusart2 asynchronous transmit/asynchronous clock output dt2 6 eusart2 synchronous transmit sdo2 9 spi2 data output sck2 10 spi2 clock output ssdma 12 spi dma slave select ulpout 13 ultra low-power wake-up event ccp1/p1a 14 eccp1 compare or pwm output channel a p1b 15 eccp1 enhanced pwm output, channel b p1c 16 eccp1 enhanced pwm output, channel c p1d 17 eccp1 enhanced pwm output, channel d ccp2/p2a 18 eccp2 compare or pwm output p2b 19 eccp2 enhanced pwm output, channel b p2c 20 eccp2 enhanced pwm output, channel c p2d 21 eccp2 enhanced pwm output, channel d note 1: value assigned to the rp<4:0> pins corresponds to the peripheral output function number. 2: the null function is assigned to all rpn outputs at device reset and disables the rpn output function.
pic18f46j50 family ds39931b-page 144 preliminary ? 2009 microchip technology inc. 9.7.3.3 mapping limitations the control schema of the pps is extremely flexible. other than systematic blocks that prevent signal con- tention caused by two physical pins being configured as the same functional input or two functional outputs configured as the same pin, there are no hardware enforced lock outs. the flexibility extends to the point of allowing a single input to drive multiple peripherals or a single functional output to drive multiple output pins. 9.7.4 controlling configuration changes because peripheral remapping can be changed during run time, some restrictions on peripheral remapping are needed to prevent accidental configuration changes. pic18f devices include three features to prevent alterations to the peripheral map: ? control register lock sequence ? continuous state monitoring ? configuration bit remapping lock 9.7.4.1 control register lock under normal operation, writes to the rpinrx and rporx registers are not allowed. attempted writes will appear to execute normally, but the contents of the registers will remain unchanged. to change these reg- isters, they must be unlocked in hardware. the register lock is controlled by th e iolock bit (ppscon<0>). setting iolock prevents writes to the control registers; clearing iolock allows writes. to set or clear iolock, a specific command sequence must be executed: 1. write 55h to eecon2<7:0>. 2. write aah to eecon2<7:0>. 3. clear (or set) iolock as a single operation. iolock remains in one state until changed. this allows all of the pps registers to be configured with a single unlock sequence followed by an update to all control registers, then locked with a second lock sequence. 9.7.4.2 continuous state monitoring in addition to being protected from direct writes, the contents of the rpinrx and rporx registers are constantly monitored in hardware by shadow registers. if an unexpected change in any of the registers occurs (such as cell disturbances caused by esd or other external events), a configuration mismatch reset will be triggered. 9.7.4.3 configuration bit pin select lock as an additional level of safety, the device can be con- figured to prevent more than one write session to the rpinrx and rporx registers. the iol1way (config3h<0>) configuration bit blocks the iolock bit from being cleared after it has been set once. if iolock remains set, the register unlock procedure will not execute and the pps control registers cannot be written to. the only way to clear the bit and re-enable peripheral remapping is to perform a device reset. in the default (unprogrammed) state, iol1way is set, restricting users to one write session. programming iol1way allows users unlimited access (with the proper use of the unlock sequence) to the pps registers. 9.7.5 considerations for peripheral pin selection the ability to control peripheral pin selection introduces several considerations into application design that could be overlooked. this is particularly true for several common peripherals that are available only as remappable peripherals. the main consideration is that the pps is not available on default pins in the device?s default (reset) state. since all rpinrx registers reset to ? 11111 ? and all rporx registers reset to ? 00000 ?, all pps inputs are tied to rp31 and all pps outputs are disconnected. this situation requires the user to initialize the device with the proper peripheral configuration before any other application code is executed. since the iolock bit resets in the unlocked state, it is not necessary to execute the unlock sequence after the device has come out of reset. for application safety, however, it is best to set iolock and lock the configuration after writing to the control registers. the unlock sequence is timing critical. therefore, it is recommended that the unlock sequence be executed as an assembly language routine with interrupts temporarily disabled. if the bulk of the application is written in c or another high-level language, the unlock sequence should be performed by writing in-line assembly. note: in tying pps inputs to rp31, rp31 does not have to exist on a device for the registers to be reset to it.
? 2009 microchip technology inc. preliminary ds39931b-page 145 pic18f46j50 family choosing the configuration requires the review of all ppss and their pin assignments, especially those that will not be used in the application. in all cases, unused pin selectable peripherals should be disabled com- pletely. unused peripherals should have their inputs assigned to an unused rpn pin function. i/o pins with unused rpn functions should be configured with the null peripheral output. the assignment of a peripheral to a particular pin does not automatically perform any other configuration of the pin?s i/o circuitry. in theory, this means adding a pin selectable output to a pin may mean inadvertently driv- ing an existing peripheral input when the output is driven. users must be familiar with the behavior of other fixed peripherals that share a remappable pin and know when to enable or disable them. to be safe, fixed digital peripherals that share the same pin should be disabled when not in use. along these lines, configuring a remappable pin for a specific peripheral does not automatically turn that feature on. the peripheral must be specifically config- ured for operation and enabled, as if it were tied to a fixed pin. where this happens in the application code (immediately following device reset and peripheral configuration or inside the main application routine) depends on the peripheral and its use in the application. a final consideration is that the pps functions neither override analog inputs nor reconfigure pins with analog functions for digital i/o. if a pin is configured as an analog input on device reset, it must be explicitly reconfigured as digital i/o when used with a pps. example 9-7 provides a configuration for bidirectional communication with flow control using eusart2. the following input and output functions are used: ? input function rx2 ? output function tx2 example 9-7: configuring eusart2 input and output functions note: if the configuration bit, iol1way = 1 , once the iolock bit is set, it cannot be cleared, preventing any future rp register changes. the iolock bit is cleared back to ? 0 ? on any device reset. //************************************* // unlock registers //************************************* _asm movlb 0x0e ;pps registers are in bank 14 bcf intcon, gie ;disable interrupts for unlock sequence movlw 0x55 movwf eecon2, 0 movlw 0xaa movwf eecon2, 0 bcf ppscon, iolock, banked ;write protect off _endasm //*************************** // configure input functions // (see table 9-13) //*************************** //*************************** // assign rx2 to pin rp0 //*************************** _asm movlw 0x00 movwf rpinr16, banked _endasm //*************************** // configure output functions // (see table 9-14) //*************************** //*************************** // assign tx2 to pin rp1 //*************************** _asm movlw 0x05 movwf rpor1, banked _endasm //************************************* // lock registers _asm bcf intcon, gie ;disable interrupts for unlock sequence movlw 0x55 movwf eecon2, 0 movlw 0xaa movwf eecon2, 0 bsf ppscon, iolock, banked ;pps write protected _endasm
pic18f46j50 family ds39931b-page 146 preliminary ? 2009 microchip technology inc. 9.7.6 peripheral pin select registers the pic18f46j50 family of devices implements a total of 37 registers for remappable peripheral configuration of 44-pin devices. the 28-pin devices have 31 registers for remappable peripheral configuration. note: input and output register values can only be changed if pps = 0 . see example 9-7 for a specific command sequence. register 9-5: ppscon: peripheral pin select input register 0 (banked effh) (1) u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 ? ? ? ? ? ? ?iolock bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-1 unimplemented: read as ? 0 ? bit 0 iolock: i/o lock enable bit 1 = i/o lock is active, rporx and rpinrx registers are write-protected 0 = i/o lock is not active, pin configurations can be changed note 1: register values can only be changed if ppscon = 0 .
? 2009 microchip technology inc. preliminary ds39931b-page 147 pic18f46j50 family register 9-6: rpinr1: peripheral pin select input register 1 (banked ee7h) u-0 u-0 u-0 r/w -1 r/w -1 r/w -1 r/w -1 r/w -1 ? ? ? intr1r4 intr1r3 intr1r2 intr1r1 intr1r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 intr1r<4:0>: assign external interrupt 1 (int1) to the corresponding rpn pin bits register 9-7: rpinr2: peripheral pin select input register 2 (banked ee8h) u-0 u-0 u-0 r/w -1 r/w -1 r/w -1 r/w -1 r/w -1 ? ? ? intr2r4 intr2r3 intr2r2 intr2r1 intr2r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 intr2r<4:0>: assign external interrupt 2 (int2) to the corresponding rpn pin bits register 9-8: rpinr3: peripheral pin select input register 3 (banked ee9h) u-0 u-0 u-0 r/w -1 r/w -1 r/w -1 r/w -1 r/w -1 ? ? ? intr3r4 intr3r3 intr3r2 intr3r1 intr3r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 intr3r<4:0>: assign external interrupt 3 (int3) to the corresponding rpn pin bits
pic18f46j50 family ds39931b-page 148 preliminary ? 2009 microchip technology inc. register 9-9: rpinr4: peripheral pin select input register 4 (banked eeah) u-0 u-0 u-0 r/w -1 r/w -1 r/w -1 r/w -1 r/w -1 ? ? ? t0ckr4 t0ckr3 t0ckr2 t0ckr1 t0ckr0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 t0ckr<4:0>: timer0 external clock input (t0cki) to the corresponding rpn pin bits register 9-10: rpinr6: peripheral pin select input register 6 (banked eech) u-0 u-0 u-0 r/w -1 r/w -1 r/w -1 r/w -1 r/w -1 ? ? ? t3ckr4 t3ckr3 t3ckr2 t3ckr1 t3ckr0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 t3ckr<4:0>: timer 3 external clock input (t3cki) to the corresponding rpn pin bits register 9-11: rpinr7: peripheral pin select input register 7 (banked eedh) u-0 u-0 u-0 r/w -1 r/w -1 r/w -1 r/w -1 r/w -1 ? ? ? ic1r4 ic1r3 ic1r2 ic1r1 ic1r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 ic1r<4:0>: assign input capture 1 (eccp1) to the corresponding rpn pin bits
? 2009 microchip technology inc. preliminary ds39931b-page 149 pic18f46j50 family register 9-12: rpinr8: peripheral pin select input register 8 (banked eeeh) u-0 u-0 u-0 r/w -1 r/w -1 r/w -1 r/w -1 r/w -1 ? ? ? ic2r4 ic2r3 ic2r2 ic2r1 ic2r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 ic2r<4:0>: assign input capture 2 (eccp2) to the corresponding rpn pin bits register 9-13: rpinr12: peripheral pin select input register 12 (banked ef2h) u-0 u-0 u-0 r/w -1 r/w -1 r/w -1 r/w -1 r/w -1 ? ? ? t1gr4 t1gr3 t1gr2 t1gr1 t1gr0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 t1gr<4:0>: timer1 gate input (t1g) to the corresponding rpn pin bits register 9-14: rpinr13: peripheral pin select input register 13 (banked ef3h) u-0 u-0 u-0 r/w -1 r/w -1 r/w -1 r/w -1 r/w -1 ? ? ? t3gr4 t3gr3 t3gr2 t3gr1 t3gr0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 t3gr<4:0>: timer3 gate input (t3g) to the corresponding rpn pin bits
pic18f46j50 family ds39931b-page 150 preliminary ? 2009 microchip technology inc. register 9-15: rpinr16: peripheral pin select input register 16 (banked ef6h) u-0 u-0 u-0 r/w -1 r/w -1 r/w -1 r/w -1 r/w -1 ? ? ? rx2dt2r4 rx2dt2r3 rx2dt2r2 rx2dt2r1 rx2dt2r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rx2dt2r<4:0>: eusart2 synchronous/asynchronous receive (rx2/dt2) to the corresponding rpn pin bits register 9-16: rpinr17: peripheral pin select input register 17 (banked ef7h) u-0 u-0 u-0 r/w -1 r/w -1 r/w -1 r/w -1 r/w -1 ? ? ? ck2r4 ck2r3 ck2r2 ck2r1 ck2r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 ck2r<4:0>: eusart2 clock input (ck2) to the corresponding rpn pin bits register 9-17: rpinr21: peripheral pin select input register 21 (banked efbh) u-0 u-0 u-0 r/w -1 r/w -1 r/w -1 r/w -1 r/w -1 ? ? ? sdi2r4 sdi2r3 sdi2r2 sdi2r1 sdi2r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 sdi2r<4:0>: assign spi2 data input (sdi2) to the corresponding rpn pin bits
? 2009 microchip technology inc. preliminary ds39931b-page 151 pic18f46j50 family register 9-18: rpinr22: peripheral pin select input register 22 (banked efch) u-0 u-0 u-0 r/w -1 r/w -1 r/w -1 r/w -1 r/w -1 ? ? ? sck2r4 sck2r3 sck2r2 sck2r1 sck2r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 sck2r<4:0>: assign spi2 data input (sdi2) to the corresponding rpn pin bits register 9-19: rpinr23: peripheral pin select input register 23 (banked efdh) u-0 u-0 u-0 r/w -1 r/w -1 r/w -1 r/w -1 r/w -1 ? ? ? ss2r4 ss2r3 ss2r2 ss2r1 ss2r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 ss2r<4:0>: assign spi2 slave select input (ss2in) to the corresponding rpn pin bits register 9-20: rpinr24: peripheral pin select input register 24 (banked efeh) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? ocfar4 ocfar3 ocfar2 ocfar1 ocfar0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 ocfar<4:0>: assign pwm fault input (flt0) to the corresponding rpn pin bits
pic18f46j50 family ds39931b-page 152 preliminary ? 2009 microchip technology inc. register 9-21: rpor0: peripheral pin se lect output register 0 (banked ec6h) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp0r4 rp0r3 rp0r2 rp0r1 rp0r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp0r<4:0>: peripheral output function is assigned to rp0 output pin bits (see table 9-14 for peripheral function numbers) register 9-22: rpor1: peripheral pin se lect output register 1 (banked ec7h) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp1r4 rp1r3 rp1r2 rp1r1 rp1r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp1r<4:0>: peripheral output function is assigned to rp1 output pin bits (see table 9-14 for peripheral function numbers) register 9-23: rpor2: peripheral pin se lect output register 2 (banked ec8h) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp2r4 rp2r3 rp2r2 rp2r1 rp2r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp2r<4:0>: peripheral output function is assigned to rp2 output pin bits (see table 9-14 for peripheral function numbers)
? 2009 microchip technology inc. preliminary ds39931b-page 153 pic18f46j50 family register 9-24: rpor3: peripheral pin se lect output register 3 (banked ec9h) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp3r4 rp3r3 rp3r2 rp3r1 rp3r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp3r<4:0>: peripheral output function is assigned to rp3 output pin bits (see table 9-14 for peripheral function numbers) register 9-25: rpor4: peripheral pin se lect output register 4 (banked ecah) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp4r4 rp4r3 rp4r2 rp4r1 rp4r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp4r<4:0>: peripheral output function is assigned to rp4 output pin bits (see table 9-14 for peripheral function numbers) register 9-26: rpor5: peripheral pin se lect output register 5 (banked ecbh) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp5r4 rp5r3 rp5r2 rp5r1 rp5r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp5r<4:0>: peripheral output function is assigned to rp5 output pin bits (see table 9-14 for peripheral function numbers)
pic18f46j50 family ds39931b-page 154 preliminary ? 2009 microchip technology inc. register 9-27: rpor6: peripheral pin se lect output register 6 (banked ecch) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp6r4 rp6r3 rp6r2 rp6r1 rp6r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp6r<4:0>: peripheral output function is assigned to rp6 output pin bits (see table 9-14 for peripheral function numbers) register 9-28: rpor7: peripheral pin se lect output register 7 (banked ecdh) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp7r4 rp7r3 rp7r2 rp7r1 rp7r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp7r<4:0>: peripheral output function is assigned to rp7 output pin bits (see table 9-14 for peripheral function numbers) register 9-29: rpor8: peripheral pin se lect output register 8 (banked eceh) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp8r4 rp8r3 rp8r2 rp8r1 rp8r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp8r<4:0>: peripheral output function is assigned to rp8 output pin bits (see table 9-14 for peripheral function numbers)
? 2009 microchip technology inc. preliminary ds39931b-page 155 pic18f46j50 family register 9-30: rpor9: peripheral pin se lect output register 9 (banked ecfh) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp9r4 rp9r3 rp9r2 rp9r1 rp9r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp9r<4:0>: peripheral output function is assigned to rp9 output pin bits (see table 9-14 for peripheral function numbers) register 9-31: rpor10: peripheral pin se lect output register 10 (banked ed0h) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp10r4 rp10r3 rp10r2 rp10r1 rp10r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp10r<4:0>: peripheral output function is assigned to rp10 output pin bits (see table 9-14 for peripheral function numbers) register 9-32: rpor11: peripheral pin sele ct output register 11 (banked ed1h) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp11r4 rp11r3 rp11r2 rp11r1 rp11r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp11r<4:0>: peripheral output function is assigned to rp11 output pin bits (see table 9-14 for peripheral function numbers)
pic18f46j50 family ds39931b-page 156 preliminary ? 2009 microchip technology inc. register 9-33: rpor12: peripheral pin se lect output register 12 (banked ed2h) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp12r4 rp12r3 rp12r2 rp12r1 rp12r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp12r<4:0>: peripheral output function is assigned to rp12 output pin bits (see table 9-14 for peripheral function numbers) register 9-34: rpor13: peripheral pin se lect output register 13 (banked ed3h) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp13r4 rp13r3 rp13r2 rp13r1 rp13r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp13r<4:0>: peripheral output function is assigned to rp13 output pin bits (see table 9-14 for peripheral function numbers) register 9-35: rpor17: peripheral pin se lect output register 17 (banked ed7h) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp17r4 rp17r3 rp17r2 rp17r1 rp17r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp17r<4:0>: peripheral output function is assigned to rp17 output pin bits (see table 9-14 for peripheral function numbers)
? 2009 microchip technology inc. preliminary ds39931b-page 157 pic18f46j50 family register 9-36: rpor18: peripheral pin se lect output register 18 (banked ed8h) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp18r4 rp18r3 rp18r2 rp18r1 rp18r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp18r<4:0>: peripheral output function is assigned to rp18 output pin bits (see table 9-14 for peripheral function numbers) register 9-37: rpor19: peripheral pin se lect output register 19 (banked ed9h) (1) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp19r4 rp19r3 rp19r2 rp19r1 rp19r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp19r<4:0>: peripheral output function is assigned to rp19 output pin bits (see table 9-14 for peripheral function numbers) note 1: rp19 pins are not available on 28-pin devices. register 9-38: rpor20: peripheral pin se lect output register 20 (banked edah) (1) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp20r4 rp20r3 rp20r2 rp20r1 rp20r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp20r<4:0>: peripheral output function is assigned to rp20 output pin bits (see table 9-14 for peripheral function numbers) note 1: rp20 pins are not available on 28-pin devices.
pic18f46j50 family ds39931b-page 158 preliminary ? 2009 microchip technology inc. register 9-39: rpor21: peripheral pin se lect output register 21 (banked edbh) (1) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp21r4 rp21r3 rp21r2 rp21r1 rp21r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp21r<4:0>: peripheral output function is assigned to rp21 output pin bits (see table 9-14 for peripheral function numbers) note 1: rp21 pins are not available on 28-pin devices. register 9-40: rpor22: peripheral pin se lect output register 22 (banked edch) (1) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp22r4 rp22r3 rp22r2 rp22r1 rp22r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp22r<4:0>: peripheral output function is assigned to rp22 output pin bits (see table 9-14 for peripheral function numbers) note 1: rp22 pins are not available on 28-pin devices. register 9-41: rpor23: peripheral pin se lect output register 23 (banked eddh) (1) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp23r4 rp23r3 rp23r2 rp23r1 rp23r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp23r<4:0>: peripheral output function is assigned to rp23 output pin bits (see table 9-14 for peripheral function numbers) note 1: rp23 pins are not available on 28-pin devices.
? 2009 microchip technology inc. preliminary ds39931b-page 159 pic18f46j50 family register 9-42: rpor24: peripheral pin se lect output register 24 (banked edeh) (1) u-0 u-0 u-0 r/w -0 r/w -0 r/w -0 r/w -0 r/w -0 ? ? ? rp24r4 rp24r3 rp24r2 rp24r1 rp24r0 bit 7 bit 0 legend: r/w = readable, writable if iolock = 0 r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 rp24r<4:0>: peripheral output function is assigned to rp24 output pin bits (see table 9-14 for peripheral function numbers) note 1: rp24 pins are not available on 28-pin devices.
pic18f46j50 family ds39931b-page 160 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39931b-page 161 pic18f46j50 family 10.0 parallel master port (pmp) the parallel master port module (pmp) is an 8-bit parallel i/o module, specifically designed to communi- cate with a wide variety of parallel devices, such as communication peripherals, lcds, external memory devices and microcontrollers. because the interface to parallel peripherals varies significantly, the pmp is highly configurable. the pmp module can be configured to serve as either a pmp or as a parallel slave port (psp). key features of the pmp module are: ? up to 16 bits of addressing when using data/address multiplexing ? up to 8 programmable address lines ? one chip select line ? programmable strobe options: - individual read and write strobes or; - read/write strobe with enable strobe ? address auto-increment/auto-decrement ? programmable address/data multiplexing ? programmable polarity on control signals ? legacy parallel slave port support ? enhanced parallel slave support: - address support - 4-byte deep, auto-incrementing buffer ? programmable wait states ? selectable input voltage levels figure 10-1: pmp module overview pma<0> pmbe pmrd pmwr pmd<7:0> pmenb pmrd/pmwr pmcs pma<1> pma<7:2> pmall pmalh pma<7:0> eeprom address bus data bus control lines pic18 lcd fifo microcontroller 8-bit data up to 8-bit address parallel master port buffer pma<15:8>
pic18f46j50 family ds39931b-page 162 preliminary ? 2009 microchip technology inc. 10.1 module registers the pmp module has a total of 14 special function registers (sfrs) for its operation, plus one additional register to set configuration options. of these, eight registers are used for control and six are used for pmp data transfer. 10.1.1 control registers the eight pmp control registers are: ? pmconh and pmconl ? pmmodeh and pmmodel ? pmstatl and pmstath ? pmeh and pmel the pmcon registers (register 10-1 and register 10-2) control basic module operations, includ- ing turning the module on or off. they also configure address multiplexing and control strobe configuration. the pmmode registers (register 10-3 and register 10-4) configure the various master and slave modes, the data width and interrupt generation. the pmeh and pmel registers (register 10-5 and register 10-6) configure the module?s operation at the hardware (i/o pin) level. the pmstat registers (register 10-5 and register 10-6) provide status flags for the module?s input and output buffers, depending on the operating mode. register 10-1: pmconh: parallel port control register high byte (banked f5fh) (1) r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 pmpen ? psidl adrmux1 adrmux0 ptbeen ptwren ptrden bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 pmpen: parallel master port enable bit 1 = pmp enabled 0 = pmp disabled, no off-chip access performed bit 6 unimplemented: read as ? 0 ? bit 5 psidl: stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 4-3 adrmux<1:0>: address/data multiplexing selection bits 11 = reserved 10 = all 16 bits of address are multiplexed on pmd<7:0> pins 01 = lower 8 bits of address are multiplexed on pmd<7:0> pins (only eight bits of address are available in this mode) 00 = address and data appear on separate pins (only eight bits of address are available in this mode) bit 2 ptbeen: byte enable port enable bit (16-bit master mode) 1 = pmbe port enabled 0 = pmbe port disabled bit 1 ptwren: write enable strobe port enable bit 1 = pmwr/pmenb port enabled 0 = pmwr/pmenb port disabled bit 0 ptrden: read/write strobe port enable bit 1 = pmrd/pmwr port enabled 0 = pmrd/pmwr port disabled note 1: this register is only available in 44-pin devices.
? 2009 microchip technology inc. preliminary ds39931b-page 163 pic18f46j50 family register 10-2: pmconl: parallel port control register low byte (banked f5eh) (1) r/w-0 r/w-0 r/w-0 (2) u-0 r/w-0 (2) r/w-0 r/w-0 r/w-0 csf1 csf0 alp ? cs1p bep wrsp rdsp bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 csf<1:0>: chip select function bits 11 = reserved 10 = chip select function is enabled and pmcs acts as chip select (in master mode). up to 13 address bits only can be generated. 01 = reserved 00 = chip select function is disabled (in master mode). all 16 address bits can be generated. bit 5 alp: address latch polarity bit (2) 1 = active-high (pmall and pmalh) 0 = active-low (pmall and pmalh ) bit 4 unimplemented: maintain as ? 0 ? bit 3 cs1p: chip select polarity bit (2) 1 = active-high (pmcs) 0 =active-low (pmcs ) bit 2 bep: byte enable polarity bit 1 = byte enable active-high (pmbe) 0 = byte enable active-low (pmbe ) bit 1 wrsp: write strobe polarity bit for slave modes and master mode 2 (pmmodeh <1 : 0> = 00 , 01 , 10 ) : 1 = write strobe active-high (pmwr) 0 = write strobe active-low (pmwr ) for master mode 1 (pmmodeh <1 : 0> = 11 ): 1 = enable strobe active-high (pmenb) 0 = enable strobe active-low (pmenb ) bit 0 rdsp: read strobe polarity bit for slave modes and master mode 2 (pmmodeh <1 : 0> = 00 ,01 ,10 ) : 1 = read strobe active-high (pmrd) 0 = read strobe active-low (pmrd ) for master mode 1 (pmmodeh <1 : 0> = 11 ) : 1 = read/write strobe active-high (pmrd/pmwr) 0 = read/write strobe active-low (pmrd /pmwr ) note 1: this register is only available in 44-pin devices. 2: these bits have no effect when their corresponding pins are used as address lines.
pic18f46j50 family ds39931b-page 164 preliminary ? 2009 microchip technology inc. register 10-3: pmmodeh: parallel port mo de register high byte (banked f5dh) (1) r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 busy irqm1 irqm0 incm1 incm0 mode16 mode1 mode0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 busy: busy bit (master mode only) 1 = port is busy 0 = port is not busy bit 6-5 irqm<1:0>: interrupt request mode bits 11 = interrupt generated when read buffer 3 is read or write buffer 3 is written (buffered psp mode) or on a read or write operation when pma<1:0> = 11 (addressable psp mode only) 10 = no interrupt generated, processor stall activated 01 = interrupt generated at the end of the read/write cycle 00 = no interrupt generated bit 4-3 incm<1:0>: increment mode bits 11 = psp read and write buffers auto-increment (legacy psp mode only) 10 = decrement addr<15,13:0> by 1 every read/write cycle 01 = increment addr<15,13:0> by 1 every read/write cycle 00 = no increment or decrement of address bit 2 mode16: 8/16-bit mode bit 1 = 16-bit mode: data register is 16 bits, a read or write to the data register invokes two 8-bit transfers 0 = 8-bit mode: data register is 8 bits, a read or write to the data register invokes one 8-bit transfer bit 1-0 mode<1:0>: parallel port mode select bits 11 = master mode 1 (pmcs, pmrd/pmwr, pmenb, pmbe, pma and pmd<7:0>) 10 = master mode 2 (pmcs, pmrd, pmwr, pmbe, pma and pmd<7:0>) 01 = enhanced psp, control signals (pmrd, pmwr, pmcs, pmd<7:0> and pma<1:0>) 00 = legacy parallel slave port, control signals (pmrd, pmwr, pmcs and pmd<7:0>) note 1: this register is only available in 44-pin devices.
? 2009 microchip technology inc. preliminary ds39931b-page 165 pic18f46j50 family register 10-4: pmmodel: parallel port mode register low byte (banked f5ch) (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 waitb1 (2) waitb0 (2) waitm3 waitm2 waitm1 waitm0 waite1 (2) waite0 (2) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 waitb<1:0>: data setup to read/write wait state configuration bits (2) 11 = data wait of 4 t cy ; multiplexed address phase of 4 t cy 10 = data wait of 3 t cy ; multiplexed address phase of 3 t cy 01 = data wait of 2 t cy ; multiplexed address phase of 2 t cy 00 = data wait of 1 t cy ; multiplexed address phase of 1 t cy bit 5-2 waitm<3:0>: read to byte enable strobe wait state configuration bits 1111 = wait of additional 15 t cy . . . 0001 = wait of additional 1 t cy 0000 = no additional wait cycles (operation forced into one t cy ) bit 1-0 waite<1:0>: data hold after strobe wait state configuration bits (2) 11 = wait of 4 t cy 10 = wait of 3 t cy 01 = wait of 2 t cy 00 = wait of 1 t cy note 1: this register is only available in 44-pin devices. 2: waitbx and waitex bits are ignored whenever waitm<3:0> = 0000 .
pic18f46j50 family ds39931b-page 166 preliminary ? 2009 microchip technology inc. register 10-5: pmeh: parallel port enabl e register high byte (banked f57h) (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 pten15 pten14 pten13 pten12 pten11 pten10 pten9 pten8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 pten<15:14>: pmcs1 port enable bits 1 = pma<15:14> function as either pma<15:14> or pmcs2 and pmcs1 0 = pma<15:14> function as port i/o bit 5-0 pten<13:8>: pmp address port enable bits 1 = pma<13:8> function as pmp address lines 0 = pma<13:8> function as port i/o note 1: this register is only available in 44-pin devices. register 10-6: pmel: parallel port enabl e register low byte (banked f56h) (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 pten7 pten6 pten5 pten4 pten3 pten2 pten1 pten0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-2 pten<7:2>: pmp address port enable bits 1 = pma<7:2> function as pmp address lines 0 = pma<7:2> function as port i/o bit 1-0 pten<1:0>: pmalh/pmall strobe enable bits 1 = pma<1:0> function as either pma<1:0> or pmalh and pmall 0 = pma<1:0> pads functions as port i/o note 1: this register is only available in 44-pin devices.
? 2009 microchip technology inc. preliminary ds39931b-page 167 pic18f46j50 family register 10-7: pmstath: parallel port status register high byte (banked f55h) (1) r-0 r/w-0 u-0 u-0 r-0 r-0 r-0 r-0 ibf ibov ? ? ib3f ib2f ib1f ib0f bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ibf: input buffer full status bit 1 = all writable input buffer registers are full 0 = some or all of the writable input buffer registers are empty bit 6 ibov: input buffer overflow status bit 1 = a write attempt to a full input byte register occurred (must be cleared in software) 0 = no overflow occurred bit 5-4 unimplemented: read as ? 0 ? bit 3-0 ib3f:ib0f: input buffer x status full bits 1 = input buffer contains data that has not been read (reading buffer will clear this bit) 0 = input buffer does not contain any unread data note 1: this register is only available in 44-pin devices. register 10-8: pmstatl: parallel port st atus register low byte (banked f54h) (1) r-1 r/w-0 u-0 u-0 r-1 r-1 r-1 r-1 obe obuf ? ? ob3e ob2e ob1e ob0e bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 obe: output buffer empty status bit 1 = all readable output buffer registers are empty 0 = some or all of the readable output buffer registers are full bit 6 obuf: output buffer underflow status bit 1 = a read occurred from an empty output byte register (must be cleared in software) 0 = no underflow occurred bit 5-4 unimplemented: read as ? 0 ? bit 3-0 ob3e:ob0e: output buffer x status empty bits 1 = output buffer is empty (writing data to the buffer will clear this bit) 0 = output buffer contains data that has not been transmitted note 1: this register is only available in 44-pin devices.
pic18f46j50 family ds39931b-page 168 preliminary ? 2009 microchip technology inc. 10.1.2 data registers the pmp module uses eight registers for transferring data into and out of the microcontroller. they are arranged as four pairs to allow the option of 16-bit data operations: ? pmdin1h and pmdin1l ? pmdin2h and pmdin2l ? pmaddrh/pmdout1h and pmaddrl/pmdout1l ? pmdout2h and pmdout2l the pmdin1 register is used for incoming data in slave modes, and both input and output data in master modes. the pmdin2 register is used for buffering input data in select slave modes. the pmaddr/pmdout1 registers are actually a single register pair; the name and function are dictated by the module?s operating mode. in master modes, the registers function as the pmaddrh and pmaddrl registers and contain the address of any incoming or outgoing data. in slave modes, the registers function as pmdout1h and pmdout1l and are used for outgoing data. pmaddrh differs from pmaddrl in that it can also have limited pmp control functions. when the module is operating in select master mode configurations, the upper two bits of the register can be used to determine the operation of chip select signals. if these are not used, pmaddr simply functions to hold the upper 8 bits of the address. register 10-9 provides the function of the individual bits in pmaddrh. the pmdout2h and pmdout2l registers are only used in buffered slave modes and serve as a buffer for outgoing data. 10.1.3 pad config uration control register in addition to the module level configuration options, the pmp module can also be configured at the i/o pin for electrical operation. this option allows users to select either the normal schmitt trigger input buffer on digital i/o pins shared with the pmp, or use ttl level compatible buffers instead. buffer configuration is controlled by the pmpttl bit in the padcfg1 register.
? 2009 microchip technology inc. preliminary ds39931b-page 169 pic18f46j50 family register 10-9: pmaddrh: parallel port address register high byte (master modes only) (access f6fh) (1) u0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? cs1 parallel master port address high byte<13:8> bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? r = reserved -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 cs1: chip select bit if pmcon <7 : 6> = 10 : 1 = chip select is active 0 = chip select is inactive if pmcon <7 : 6> = 11 or 0 0 : bit functions as addr<14>. bit 5-0 parallel master port address: high byte<13:8> bits note 1: in enhanced slave mode, pmaddrh functions as pmdout1h, one of the output data buffer registers. register 10-10: pmaddrl: parallel port address register low byte (master modes only) (access f6eh) (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 parallel master port address low byte<7:0> bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? r = reserved -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 parallel master port address: low byte<7:0> bits note 1: in enhanced slave mode, pmaddrl functions as pmdout1l, one of the output data buffer registers.
pic18f46j50 family ds39931b-page 170 preliminary ? 2009 microchip technology inc. 10.2 slave port modes the primary mode of operation for the module is configured using the mode<1:0> bits in the pmmodeh register. the setting affects whether the module acts as a slave or a master, and it determines the usage of the control pins. 10.2.1 legacy mode (psp) in legacy mode (pmmodeh<1:0> = 00 and pmpen = 1 ), the module is configured as a parallel slave port (psp) with the associated enabled module pins dedicated to the module. in this mode, an external device, such as another microcontroller or micro- processor, can asynchronously read and write data using the 8-bit data bus (pmd<7:0>), the read (pmrd), write (pmwr) and chip select (pmcs1) inputs. it acts as a slave on the bus and responds to the read/write control signals. figure 10-2 displays the connection of the psp. when chip select is active and a write strobe occurs (pmcs = 1 and pmwr = 1 ), the data from pmd<7:0> is captured into the pmdin1l register. figure 10-2: legacy parallel slave port example pmd<7:0> pmrd pmwr master address bus data bus control lines pmcs1 pmd<7:0> pmrd pmwr pic18 slave pmcs
? 2009 microchip technology inc. preliminary ds39931b-page 171 pic18f46j50 family 10.2.2 write to slave port when chip select is active and a write strobe occurs (pmcs = 1 and pmwr = 1 ), the data from pmd<7:0> is captured into the lower pmdin1l register. the pmpif and ibf flag bits are set when the write ends.the timing for the control signals in write mode is displayed in figure 10-3. the polarity of the control signals are configurable. 10.2.3 read from slave port when chip select is active and a read strobe occurs (pmcs = 1 and pmrd = 1 ), the data from the pmdout1l register (pmdout1l<7:0>) is presented onto pmd<7:0>. figure 10-4 provides the timing for the control signals in read mode. figure 10-3: parallel slave port write waveforms figure 10-4: parallel slave port read waveforms pmcs1 | q4 | q1 | q2 | q3 | q4 pmwr pmrd pmd<7:0> ibf obe pmpif pmcs1 | q4 | q1 | q2 | q3 | q4 pmwr pmrd pmd<7:0> ibf obe pmpif
pic18f46j50 family ds39931b-page 172 preliminary ? 2009 microchip technology inc. 10.2.4 buffered parallel slave port mode buffered parallel slave port mode is functionally identical to the legacy psp mode with one exception, the implementation of 4-level read and write buffers. buffered psp mode is enabled by setting the incm bits in the pmmodeh register. if the incm<1:0> bits are set to ? 11 ?, the pmp module will act as the buffered psp. when the buffered mode is active, the pmdin1l, pmdin1h, pmdin2l and pmdin2h registers become the write buffers and the pmdout1l, pmdout1h, pmdout2l and pmdout2h registers become the read buffers. buffers are numbered 0 through 3, start- ing with the lower byte of pmdin1l to pmdin2h as the read buffers and pmdout1l to pmdout2h as the write buffers. 10.2.4.1 read from slave port for read operations, the bytes will be sent out sequentially, starting with buffer 0 (pmdout1l<7:0>) and ending with buffer 3 (pmdout2h<7:0>) for every read strobe. the module maintains an internal pointer to keep track of which buffer is to be read. each buffer has a corresponding read status bit, obxe, in the pmstatl register. this bit is cleared when a buffer contains data that has not been written to the bus, and is set when data is written to the bus. if the current buf- fer location being read from is empty, a buffer underflow is generated, and the buffer overflow flag bit obuf is set. if all four obxe status bits are set, then the output buffer empty flag (obe) will also be set. 10.2.4.2 write to slave port for write operations, the data has to be stored sequentially, starting with buffer 0 (pmdin1l<7:0>) and ending with buffer 3 (pmdin2h<7:0>). as with read operations, the module maintains an internal pointer to the buffer that is to be written next. the input buffers have their own write status bits, ibxf in the pmstath register. the bit is set when the buffer contains unread incoming data, and cleared when the data has been read. the flag bit is set on the write strobe. if a write occurs on a buffer when its associated ibxf bit is set, the buffer overflow flag, ibov, is set; any incoming data in the buffer will be lost. if all four ibxf flags are set, the input buffer full flag (ibf) is set. in buffered slave mode, the module can be configured to generate an interrupt on every read or write strobe (irqm<1:0> = 01 ). it can be configured to generate an interrupt on a read from read buffer 3 or a write to write buffer 3, which is essentially an interrupt every fourth read or write strobe (rqm<1:0> = 11 ). when interrupting every fourth byte for input data, all input buffer registers should be read to clear the ibxf flags. if these flags are not cleared, then there is a risk of hitting an overflow condition. figure 10-5: parallel master/slave connection buffered example pmd<7:0> pmrd pmwr pmcs1 data bus control lines pmrd pmwr pic18 slave pmcs pmdout1l (0) pmdout1h (1) pmdout2l (2) pmdout2h (3) pmdin1l (0) pmdin1h (1) pmdin2l (2) pmdin2h (3) pmd<7:0> write address pointer read address pointer master
? 2009 microchip technology inc. preliminary ds39931b-page 173 pic18f46j50 family 10.2.5 addressable parallel slave port mode in the addressable parallel slave port mode ( pmmodeh<1:0> = 01 ), the module is configured with two extra inputs, pma<1:0>, which are the address lines 1 and 0. this makes the 4-byte buffer space directly addressable as fixed pairs of read and write buffers. as with legacy buffered mode, data is output from pmdout1l, pmdout1h, pmdout2l and pmdout2h, and is read in pmdin1l, pmdin1h, pmdin2l and pmdin2h. table 10-1 provides the buffer addressing for the incoming address to the input and output registers. table 10-1: slave mode buffer addressing figure 10-6: parallel master/slave connection addressed buffer example 10.2.5.1 read from slave port when chip select is active and a read strobe occurs (pmcs = 1 and pmrd = 1 ), the data from one of the four output bytes is presented onto pmd<7:0>. which byte is read depends on the 2-bit address placed on addr<1:0>. table 10-1 provides the corresponding output registers and their associated address. when an output buffer is read, the corresponding obxe bit is set. the obxe flag bit is set when all the buffers are empty. if any buffer is already empty, obxe = 1 , the next read to that buffer will generate an obuf event. figure 10-7: parallel slave port read waveforms pma<1:0> output register (buffer) input register (buffer) 00 pmdout1l (0) pmdin1l (0) 01 pmdout1h (1) pmdin1h (1) 10 pmdout2l (2) pmdin2l (2) 11 pmdout2h((3) pmdin2h (3) pmd<7:0> pmrd pmwr master pmcs1 pma<1:0> address bus data bus control lines pmrd pmwr pic18f slave pmcs pmdout1l (0) pmdout1h (1) pmdout2l (2) pmdout2h (3) pmdin1l (0) pmdin1h (1) pmdin2l (2) pmdin2h (3) pmd<7:0> write address decode read address decode pma<1:0> | q4 | q1 | q2 | q3 | q4 pmcs pmwr pmrd pmd<7:0> pma<1:0> obe pmpif
pic18f46j50 family ds39931b-page 174 preliminary ? 2009 microchip technology inc. 10.2.5.2 write to slave port when chip select is active and a write strobe occurs (pmcs = 1 and pmwr = 1 ), the data from pmd<7:0> is captured into one of the four input buffer bytes. which byte is written depends on the 2-bit address placed on addrl<1:0>. table 10-1 provides the corresponding input registers and their associated address. when an input buffer is written, the corresponding ibxf bit is set. the ibf flag bit is set when all the buffers are written. if any buffer is already written (ibxf = 1 ), the next write strobe to that buffer will generate an obuf event and the byte will be discarded. figure 10-8: parallel slave port write waveforms pmcs | q4 | q1 | q2 | q3 | q4 pmwr pmrd pmd<7:0> ibf pmpif pma<1:0>
? 2009 microchip technology inc. preliminary ds39931b-page 175 pic18f46j50 family 10.3 master port modes in its master modes, the pmp module provides an 8-bit data bus, up to 16 bits of address, and all the necessary control signals to operate a variety of external parallel devices, such as memory devices, peripherals and slave microcontrollers. to use the pmp as a master, the module must be enabled (pmpen = 1 ) and the mode must be set to one of the two possible master modes (pmmodeh<1:0> = 10 or 11 ). because there are a number of parallel devices with a variety of control methods, the pmp module is designed to be extremely flexible to accommodate a range of configurations. some of these features include: ? 8-bit and 16-bit data modes on an 8-bit data bus ? configurable address/data multiplexing ? up to two chip select lines ? up to 16 selectable address lines ? address auto-increment and auto-decrement ? selectable polarity on all control lines ? configurable wait states at different stages of the read/write cycle 10.3.1 pmp and i/o pin control multiple control bits are used to configure the presence or absence of control and address signals in the module. these bits are ptbeen, ptwren, ptrden and pten<15:0>. they give the user the ability to con- serve pins for other functions and allow flexibility to control the external address. when any one of these bits is set, the associated function is present on its associated pin; when clear, the associated pin reverts to its defined i/o port function. setting a ptenx bit will enable the associated pin as an address pin and drive the corresponding data contained in the pmaddr register. clearing a ptenx bit will force the pin to revert to its original i/o function. for the pins configured as chip select (pmcs1 or pmcs2) with the corresponding ptenx bit set, the pten0 and pten1 bits will also control the pmall and pmalh signals. when multiplexing is used, the associated address latch signals should be enabled. 10.3.2 read/write control the pmp module supports two distinct read/write signaling methods. in master mode 1, read and write strobes are combined into a single control line, pmrd/pmwr. a second control line, pmenb, deter- mines when a read or write action is to be taken. in master mode 2, separate read and write strobes (pmrd and pmwr) are supplied on separate pins. all control signals (pmrd, pmwr, pmbe, pmenb, pmal and pmcsx) can be individually configured as either positive or negative polarity. configuration is controlled by separate bits in the pmconl register. note that the polarity of control signals that share the same output pin (for example, pmwr and pmenb) are controlled by the same bit; the configuration depends on which master port mode is being used. 10.3.3 data width the pmp supports data widths of both 8 bits and 16 bits. the data width is selected by the mode16 bit (pmmodeh<2>). because the data path into and out of the module is only 8 bits wide, 16-bit operations are always handled in a multiplexed fashion, with the least significant byte (lsb) of data being presented first. to differentiate data bytes, the byte enable control strobe, pmbe, is used to signal when the most significant byte (msb) of data is being presented on the data lines. 10.3.4 address multiplexing in either of the master modes (pmmodeh<1:0> = 1x ), the user can configure the address bus to be multiplexed together with the data bus. this is accomplished by using the adrmux<1:0> bits (pmconh<4:3>). there are three address multiplexing modes available; typical pinout configurations for these modes are displayed in figure 10-9, figure 10-10 and figure 10-11. in demultiplexed mode (pmconh<4:3> = 00 ), data and address information are completely separated. data bits are presented on pmd<7:0> and address bits are presented on pmaddrh<6:0> and pmaddrl<7:0>. in partially multiplexed mode (pmconh<4:3> = 01 ), the lower eight bits of the address are multiplexed with the data pins on pmd<7:0>. the upper eight bits of address are unaffected and are presented on pmaddrh<6:0>. the pma0 pin is used as an address latch, and presents the address latch low (pmall) enable strobe. the read and write sequences are extended by a complete cpu cycle during which the address is presented on the pmd<7:0> pins. in fully multiplexed mode (pmconh<4:3> = 10 ), the entire 16 bits of the address are multiplexed with the data pins on pmd<7:0>. the pma0 and pma1 pins are used to present address latch low (pmall) enable and address latch high (pmalh) enable strobes, respectively. the read and write sequences are extended by two complete cpu cycles. during the first cycle, the lower eight bits of the address are presented on the pmd<7:0> pins with the pmall strobe active. during the second cycle, the upper eight bits of the address are presented on the pmd<7:0> pins with the pmalh strobe active. in the event the upper address bits are configured as chip select pins, the corresponding address bits are automatically forced to ? 0 ?.
pic18f46j50 family ds39931b-page 176 preliminary ? 2009 microchip technology inc. figure 10-9: demultiplexed addressing mode (separate read and write strobes with chip select) figure 10-10: partially multiplexed addressing mode (separate read and write strobes with chip select) figure 10-11: fully multiplexed addressing mode (separate read and write strobes with chip select) pmrd pmwr pmd<7:0> pmcs pma<7:0> pic18f address bus data bus control lines pmrd pmwr pmd<7:0> pmcs pmall pma<7:0> pic18f address bus multiplexed data and address bus control lines pmrd pmwr pmd<7:0> pmcs pmalh pma<13:8> pic18f multiplexed data and address bus control lines pmall
? 2009 microchip technology inc. preliminary ds39931b-page 177 pic18f46j50 family 10.3.5 chip select features up to two chip select lines, pmcs1 and pmcs2, are available for the master modes of the pmp. the two chip select lines are multiplexed with the most signifi- cant bit (msb) of the address bus (pmaddrh<6>). when a pin is configured as a chip select, it is not included in any address auto-increment/decrement. the function of the chip select signals is configured using the chip select function bits (pmconl<7:6>). 10.3.6 auto-increment/decrement while the module is operating in one of the master modes, the incmx bits (pmmodeh<4:3>) control the behavior of the address value. the address can be made to automatically increment or decrement after each read and write operation. the address increments once each operation is completed and the busy bit goes to ? 0 ?. if the chip select signals are disabled and configured as address bits, the bits will participate in the increment and decrement operations; otherwise, the cs1 bit values will be unaffected. 10.3.7 wait states in master mode, the user has control over the duration of the read, write and address cycles by configuring the module wait states. three portions of the cycle, the beginning, middle and end, are configured using the corresponding waitbx, waitmx and waitex bits in the pmmodel register. the waitbx bits (pmmodel<7:6>) set the number of wait cycles for the data setup prior to the pmrd/pmwt strobe in mode 10, or prior to the pmenb strobe in mode 11. the waitmx bits (pmmodel<5:2>) set the number of wait cycles for the pmrd/pmwt strobe in mode 10, or for the pmenb strobe in mode 11. when this wait state setting is ? 0 ?, then waitb and waite have no effect. the waite bits (pmmodel<1:0>) define the number of wait cycles for the data hold time after the pmrd/pmwt strobe in mode 10, or after the pmenb strobe in mode 11. 10.3.8 read operation to perform a read on the pmp, the user reads the pmdin1l register. this causes the pmp to output the desired values on the chip select lines and the address bus. then the read line (pmrd) is strobed. the read data is placed into the pmdin1l register. if the 16-bit mode is enabled (mode16 = 1 ), the read of the low byte of the pmdin1l register will initiate two bus reads. the first read data byte is placed into the pmdin1l register, and the second read data is placed into the pmdin1h. note that the read data obtained from the pmdin1l register is actually the read value from the previous read operation. hence, the first user read will be a dummy read to initiate the first bus read and fill the read register. also, the requested read value will not be ready until after the busy bit is observed low. thus, in a back-to-back read operation, the data read from the register will be the same for both reads. the next read of the register will yield the new value. 10.3.9 write operation to perform a write onto the parallel bus, the user writes to the pmdin1l register. this causes the module to first output the desired values on the chip select lines and the address bus. the write data from the pmdin1l register is placed onto the pmd<7:0> data bus. then the write line (pmwr) is strobed. if the 16-bit mode is enabled (mode16 = 1 ), the write to the pmdin1l register will initiate two bus writes. first write will con- sist of the data contained in pmdin1l and the second write will contain the pmdin1h. 10.3.10 parallel master port status 10.3.10.1 the busy bit in addition to the pmp interrupt, a busy bit is provided to indicate the status of the module. this bit is used only in master mode. while any read or write operation is in progress, the busy bit is set for all but the very last cpu cycle of the operation. in effect, if a single-cycle read or write operation is requested, the busy bit will never be active. this allows back-to-back transfers. while the bit is set, any request by the user to initiate a new operation will be ignored (i.e., writing or reading the lower byte of the pmdin1l register will neither initiate a read nor a write). 10.3.10.2 interrupts when the pmp module interrupt is enabled for master mode, the module will interrupt on every completed read or write cycle; otherwise, the busy bit is available to query the status of the module.
pic18f46j50 family ds39931b-page 178 preliminary ? 2009 microchip technology inc. 10.3.11 master mode timing this section contains a number of timing examples that represent the common master mode configuration options. these options vary from 8-bit to 16-bit data, fully demultiplexed to fully multiplexed address and wait states. figure 10-12: read and write timing, 8-bit data, demultiplexed address figure 10-13: read timing, 8-bit data, partially multiplexed address figure 10-14: read timing, 8-bit data, wait states enabled, partially multiplexed address pmwr pmrd pmpif pmd<7:0> pmcs1 pma<7:0> q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 busy q2 q3 q4 q1 pmwr pmrd pmall pmd<7:0> pmcs1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 pmpif busy address<7:0> data pmrd pmwr pmall pmd<7:0> pmcs1 q1- - - pmpif q1- - - q1- - - q1- - - q1- - - q1- - - q1- - - q1- - - q1- - - q1- - - q1- - - q1- - - q1- - - q1- - - waitm<3:0> = 0010 waite<1:0> = 00 waitb<1:0> = 01 busy address<7:0> data
? 2009 microchip technology inc. preliminary ds39931b-page 179 pic18f46j50 family figure 10-15: write timing, 8-bit data, partially multiplexed address figure 10-16: write timing, 8-bit data, wait states enabled, partially multiplexed address figure 10-17: read timing, 8-bit data, partially multiplexed address, enable strobe pmwr pmrd pmall pmd<7:0> pmcs1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 pmpif data busy address<7:0> pmwr pmrd pmall pmd<7:0> pmcs1 q1- - - pmpif data q1- - - q1- - - q1- - - q1- - - q1- - - q1- - - q1- - - q1- - - q1- - - q1- - - q1- - - q1- - - q1- - - waitm<3:0> = 0010 waite<1:0> = 00 waitb<1:0> = 01 busy address<7:0> pmrd/pmwr pmenb pmall pmd<7:0> pmcs1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 pmpif busy address<7:0> data
pic18f46j50 family ds39931b-page 180 preliminary ? 2009 microchip technology inc. figure 10-18: write timing, 8-bit data, partially multiplexed address, enable strobe figure 10-19: read timing, 8-bit data, fully multiplexed 16-bit address figure 10-20: write timing, 8-bit data, fully multiplexed 16-bit address pmrd/pmwr pmenb pmall pmd<7:0> pmcs1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 pmpif data busy address<7:0> pmwr pmrd pmall pmd<7:0> pmcs1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 pmalh data pmpif busy address<7:0> address<13:8> pmwr pmrd pmall pmd<7:0> pmcs1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 pmalh data pmpif busy address<7:0> address<13:8>
? 2009 microchip technology inc. preliminary ds39931b-page 181 pic18f46j50 family figure 10-21: read timing, 16-bit data, demultiplexed address figure 10-22: write timing, 16-bit data, demultiplexed address figure 10-23: read timing, 16-bit multiplexed data, partially multiplexed address pmwr pmrd pmd<7:0> pmcs1 pma<7:0> q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 pmpif pmbe busy msb lsb pmwr pmrd pmd<7:0> pmcs1 pma<7:0> q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 pmpif lsb msb pmbe busy pmwr pmrd pmall pmd<7:0> pmcs1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 pmpif pmbe busy address<7:0> lsb msb
pic18f46j50 family ds39931b-page 182 preliminary ? 2009 microchip technology inc. figure 10-24: write timing, 16-bit multiplexed data, partially multiplexed address figure 10-25: read timing, 16-bit multiplexed data, fully multiplexed 16-bit address figure 10-26: write timing, 16-bit multiplexed data, fully multiplexed 16-bit address pmwr pmrd pmall pmd<7:0> pmcs1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 pmpif lsb msb pmbe busy address<7:0> pmwr pmrd pmbe pmd<7:0> pmcs1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 pmalh pmpif pmall busy q2 q3 q4 q1 address<7:0> lsb address<13:8> msb pmwr pmrd pmbe pmd<7:0> pmcs1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 pmalh pmall msb lsb pmpif busy q2 q3 q4 q1 address<7:0> address<13:8>
? 2009 microchip technology inc. preliminary ds39931b-page 183 pic18f46j50 family 10.4 application examples this section introduces some potential applications for the pmp module. 10.4.1 multiplexed memory or peripheral figure 10-27 demonstrates the hookup of a memory or another addressable peripheral in full multiplex mode. consequently, this mode achieves the best pin saving from the microcontroller perspective. however, for this configuration, there needs to be some external latches to maintain the address. figure 10-27: multiplexed addressing application example 10.4.2 partially multiplexed memory or peripheral partial multiplexing implies using more pins; however, for a few extra pins, some extra performance can be achieved. figure 10-28 provides an example of a memory or peripheral that is partially multiplexed with an external latch. if the peripheral has internal latches, as displayed in figure 10-29, then no extra circuitry is required except for the peripheral itself. figure 10-28: example of a partially multiplexed addressing application figure 10-29: example of an 8-bit multiplexed address and data application pmd<7:0> pmalh d<7:0> 373 a<13:0> d<7:0> a<7:0> 373 pmrd pmwr oe wr ce pic18f address bus data bus control lines pmcs pmall a<15:8> d<7:0> 373 a<7:0> d<7:0> a<7:0> pmrd pmwr oe wr ce pic18f address bus data bus control lines pmcs pmall pmd<7:0> ale pmrd pmwr rd wr cs pic18f address bus data bus control lines pmcs pmall ad<7:0> parallel peripheral pmd<7:0>
pic18f46j50 family ds39931b-page 184 preliminary ? 2009 microchip technology inc. 10.4.3 parallel eeprom example figure 10-30 provides an example connecting parallel eeprom to the pmp. figure 10-31 demonstrates a slight variation to this, configuring the connection for 16-bit data from a single eeprom. figure 10-30: parallel eeprom example (up to 15-bit address, 8-bit data) figure 10-31: parallel eeprom example (up to 15-bit address, 16-bit data) 10.4.4 lcd controller example the pmp module can be configured to connect to a typical lcd controller interface, as displayed in figure 10-32. in this case the pmp module is config- ured for active-high control signals since common lcd displays require active-high control. figure 10-32: lcd control example (byte mode operation) pma a d<7:0> pmrd pmwr oe wr ce pic18f address bus data bus control lines pmcs pmd<7:0> parallel eeprom pma a d<7:0> pmrd pmwr oe wr ce pic18f address bus data bus control lines pmcs pmd<7:0> parallel eeprom pmbe a0 pmrd/pmwr d<7:0> pic18f address bus data bus control lines pma0 r/w rs e lcd controller pmcs pm<7:0>
? 2009 microchip technology inc. preliminary ds39931b-page 185 pic18f46j50 family table 10-2: registers associated with pmp module name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 61 pir1 pmpif (2) adif rc1if tx1if ssp1if ccp1if tmr2if tmr1if 63 pie1 pmpie (2) adie rc1ie tx1ie ssp1ie ccp1ie tmr2ie tmr1ie 63 ipr1 pmpip (2) adip rc1ip tx1ip ssp1ip ccp1ip tmr2ip tmr1ip 63 pmconh (2) pmpen ? psidl adrmux1 adrmux0 ptbeen ptwren ptrden 65 pmconl (2) csf1 csf0 alp ? cs1p bep wrsp rdsp 65 pmaddrh (1,2) / ? cs1 parallel master port address high byte 65 pmdout1h (1,2) parallel port out data high byte (buffer 1) 65 pmaddrl (1,2) / parallel master port address low byte 65 pmdout1l (1,2) parallel port out data low byte (buffer 0) 65 pmdout2h (2) parallel port out data high byte (buffer 3) 66 pmdout2l (2) parallel port out data low byte (buffer 2) 66 pmdin1h (2) parallel port in data high byte (buffer 1) 65 pmdin1l (2) parallel port in data low byte (buffer 0) 65 pmdin2h (2) parallel port in data high byte (buffer 3) 66 pmdin2l (2) parallel port in data low byte (buffer 2) 66 pmmodeh (2) busy irqm1 irqm0 incm1 incm0 mode16 mode1 mode0 66 pmmodel (2) waitb1 waitb0 waitm3 waitm2 waitm1 waitm0 waite1 waite0 66 pmeh (2) ?pten14 ? ? ? ? ? ?66 pmel (2) pten7 pten6 pten5 pten4 pten3 pten2 pten1 pten0 66 pmstath (2) ibf ibov ? ? ib3f ib2f ib1f ib0f 66 pmstatl (2) obe obuf ? ? ob3e ob2e ob1e ob0e 66 padcfg1 ? ? ? ? ? rtsecsel1 rtsecsel0 pmpttl 66 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used during pmp operation. note 1: the pmaddrh/pmdout1h and pmaddrl/pmdout1l register pairs share the physical registers and addresses, but have different functions determined by the module?s operating mode. 2: these bits and/or registers are only available in 44-pin devices.
pic18f46j50 family ds39931b-page 186 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39931b-page 187 pic18f46j50 family 11.0 timer0 module the timer0 module incorporates the following features: ? software selectable operation as a timer or counter in both 8-bit or 16-bit modes ? readable and writable registers ? dedicated 8-bit, software programmable prescaler ? selectable clock source (internal or external) ? edge select for external clock ? interrupt-on-overflow the t0con register (register 11-1) controls all aspects of the module?s operation, including the prescale selection. it is both readable and writable. figure 11-1 provides a simplified block diagram of the timer0 module in 8-bit mode. figure 11-2 provides a simplified block diagram of the timer0 module in 16-bit mode. register 11-1: t0con: timer0 co ntrol register (access fd5h) r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 tmr0on t08bit t0cs t0se psa t0ps2 t0ps1 t0ps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr0on: timer0 on/off control bit 1 = enables timer0 0 = stops timer0 bit 6 t08bit : timer0 8-bit/16-bit control bit 1 = timer0 is configured as an 8-bit timer/counter 0 = timer0 is configured as a 16-bit timer/counter bit 5 t0cs : timer0 clock source select bit 1 = transition on t0cki pin 0 = internal instruction cycle clock (clko) bit 4 t0se : timer0 source edge select bit 1 = increment on high-to-low transition on t0cki pin 0 = increment on low-to-high transition on t0cki pin bit 3 psa : timer0 prescaler assignment bit 1 = timer0 prescaler is not assigned. timer0 clock input bypasses prescaler. 0 = timer0 prescaler is assigned. timer0 clock input comes from prescaler output. bit 2-0 t0ps<2:0> : timer0 prescaler select bits 111 = 1:256 prescale value 110 = 1:128 prescale value 101 = 1:64 prescale value 100 = 1:32 prescale value 011 = 1:16 prescale value 010 = 1:8 prescale value 001 = 1:4 prescale value 000 = 1:2 prescale value
pic18f46j50 family ds39931b-page 188 preliminary ? 2009 microchip technology inc. 11.1 timer0 operation timer0 can operate as either a timer or a counter. the mode is selected with the t0cs bit (t0con<5>). in timer mode (t0cs = 0 ), the module increments on every clock by default unless a different prescaler value is selected (see section 11.3 ?prescaler? ). if the tmr0 register is written to, the increment is inhibited for the following two instruction cycles. the user can work around this by writing an adjusted value to the tmr0 register. the counter mode is selected by setting the t0cs bit (= 1 ). in this mode, timer0 increments either on every rising edge or falling edge of pin, t0cki. the incrementing edge is determined by the timer0 source edge select bit, t0se (t0con<4>); clearing this bit selects the rising edge. restrictions on the external clock input are discussed below. an external clock source can be used to drive timer0; however, it must meet certain requirements to ensure that the external clock can be synchronized with the internal phase clock (t osc ). there is a delay between synchronization and the onset of incrementing the timer/counter. 11.2 timer0 reads and writes in 16-bit mode tmr0h is not the actual high byte of timer0 in 16-bit mode. it is actually a buffered version of the real high byte of timer0, which is not directly readable nor writable (refer to figure 11-2). tmr0h is updated with the contents of the high byte of timer0 during a read of tmr0l. this provides the ability to read all 16 bits of timer0 without having to verify that the read of the high and low byte were valid, due to a rollover between successive reads of the high and low byte. similarly, a write to the high byte of timer0 must also take place through the tmr0h buffer register. the high byte is updated with the contents of tmr0h when a write occurs to tmr0l. this allows all 16 bits of timer0 to be updated at once. figure 11-1: timer0 block diagram (8-bit mode) figure 11-2: timer0 block diagram (16-bit mode) note: upon reset, timer0 is enabled in 8-bit mode with clock input from t0cki max. prescale. t0cki pin t0se 0 1 1 0 t0cs f osc /4 programmable prescaler sync with internal clocks tmr0l (2 t cy delay) internal data bus psa t0ps<2:0> set tmr0if on overflow 3 8 8 note: upon reset, timer0 is enabled in 8-bit mode wit h clock input from t0cki max. prescale. t0cki pin t0se 0 1 1 0 t0cs f osc /4 sync with internal clocks tmr0l (2 t cy delay) internal data bus 8 psa t0ps<2:0> set tmr0if on overflow 3 tmr0 tmr0h high byte 8 8 8 read tmr0l write tmr0l 8 programmable prescaler
? 2009 microchip technology inc. preliminary ds39931b-page 189 pic18f46j50 family 11.3 prescaler an 8-bit counter is available as a prescaler for the timer0 module. the prescaler is not directly readable or writable. its value is set by the psa and t0ps<2:0> bits (t0con<3:0>), which determine the prescaler assignment and prescale ratio. clearing the psa bit assigns the prescaler to the timer0 module. when it is assigned, prescale values from 1:2 through 1:256 in power-of-2 increments are selectable. when assigned to the timer0 module, all instructions writing to the tmr0 register (e.g., clrf tmr0 , movwf tmr0 , bsf tmr0 , etc.) clear the prescaler count. 11.3.1 switching prescaler assignment the prescaler assignment is fully under software control and can be changed ?on-the-fly? during program execution. 11.4 timer0 interrupt the tmr0 interrupt is generated when the tmr0 register overflows from ffh to 00h in 8-bit mode, or from ffffh to 0000h in 16-bit mode. this overflow sets the tmr0if flag bit. the interrupt can be masked by clearing the tmr0ie bit (intcon<5>). before re-enabling the interrupt, the tmr0if bit must be cleared in software by the interrupt service routine (isr). since timer0 is shutdown in sleep mode, the tmr0 interrupt cannot awaken the processor from sleep. table 11-1: registers associated with timer0 note: writing to tmr0 when the prescaler is assigned to timer0 will clear the prescaler count but will not change the prescaler assignment. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: tmr0l timer0 register low byte 82 tmr0h timer0 register high byte 82 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 81 t0con tmr0on t08bit t0cs t0se psa t0ps2 t0ps1 t0ps0 82 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by timer0.
pic18f46j50 family ds39931b-page 190 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39931b-page 191 pic18f46j50 family 12.0 timer1 module the timer1 timer/counter module incorporates these features: ? software selectable operation as a 16-bit timer or counter ? readable and writable 8-bit registers (tmr1h and tmr1l) ? selectable clock source (internal or external) with device clock or timer1 oscillator internal options ? interrupt-on-overflow ? reset on eccp special event trigger ? device clock status flag (t1run) ? timer with gated control figure 12-1 displays a simplified block diagram of the timer1 module. the module incorporates its own low-power oscillator to provide an additional clocking option. the timer1 oscillator can also be used as a low-power clock source for the microcontroller in power-managed operation. timer1 is controlled through the t1con control register (register 12-1). it also contains the timer1 oscillator enable bit (t1oscen). timer1 can be enabled or disabled by setting or clearing control bit, tmr1on (t1con<0>). the f osc clock source (tmr1cs<1:0> = 01 ) should not be used with the eccp capture/compare features. if the timer will be used with the capture or compare features, always select one of the other timer clocking options. register 12-1: t1con: timer1 co ntrol register (access fcdh) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 tmr1cs1 tmr1cs0 t1ckps1 t1ckps0 t1oscen t1sync rd16 tmr1on bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 tmr1cs<1:0>: timer1 clock source select bits 10 = timer1 clock source is t1osc or t1cki pin 01 = timer1 clock source is system clock (f osc ) (1) 00 = timer1 clock source is instruction clock (f osc /4) bit 5-4 t1ckps<1:0>: timer1 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 t1oscen: timer1 oscillator source select bit when tmr1cs<1:0> = 1 0 : 1 = power up the timer1 crystal driver and supply the timer1 clock from the crystal output 0 = timer1 crystal driver off (2) , timer1 clock is from the t1cki input pin when tmr1cs<1:0> = 0x : 1 = power up the timer1 crystal driver 0 = timer1 crystal driver off (2) bit 2 t1sync : timer1 external clock input synchronization select bit tmr1cs<1:0> = 10 : 1 = do not synchronize external clock input 0 = synchronize external clock input tmr1cs<1:0> = 0x : this bit is ignored. timer1 uses the internal clock when tmr1cs<1:0> = 0x . bit 1 rd16: 16-bit read/write mode enable bit 1 = enables register read/write of timer1 in one 16-bit operation 0 = enables register read/write of timer1 in two 8-bit operations bit 0 tmr1on: timer1 on bit 1 = enables timer1 0 =stops timer1 note 1: the f osc clock source should not be selected if the timer will be used with the eccp capture/compare features. 2: the timer1 oscillator crystal driver is powered whenever t1oscen (t1con) or t3oscen (t3con) = 1 . the circuit is enabled by the logical or of these two bits. when disabled, the inverter and feedback resistor are disabled to eliminate power drain. the tmr1on and tmr3on bits do not have to be enabled to power up the crystal driver.
pic18f46j50 family ds39931b-page 192 preliminary ? 2009 microchip technology inc. 12.1 timer1 gate control register the timer1 gate control register (t1gcon), displayed in register 12-2, is used to control the timer1 gate. register 12-2: t1gcon: timer1 gate control register (access f9ah) (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-x r/w-0 r/w-0 tmr1ge t1gpol t1gtm t1gspm t1ggo/t1 done t1gval t1gss1 t1gss0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr1ge: timer1 gate enable bit if tmr1on = 0 : this bit is ignored. if tmr1on = 1 : 1 = timer1 counting is controlled by the timer1 gate function 0 = timer1 counts regardless of timer1 gate function bit 6 t1gpol: timer1 gate polarity bit 1 = timer1 gate is active-high (timer1 counts when gate is high) 0 = timer1 gate is active-low (timer1 counts when gate is low) bit 5 t1gtm: timer1 gate toggle mode bit 1 = timer1 gate toggle mode is enabled 0 = timer1 gate toggle mode is disabled and toggle flip-flop is cleared timer1 gate flip-flop toggles on every rising edge. bit 4 t1gspm: timer1 gate single pulse mode bit 1 = timer1 gate single pulse mode is enabled and is controlling timer1 gate 0 = timer1 gate single pulse mode is disabled bit 3 t1ggo/t1do ne : timer1 gate single pulse acquisition status bit 1 = timer1 gate single pulse acquisition is ready, waiting for an edge 0 = timer1 gate single pulse acquisition has completed or has not been started this bit is automatically cleared when t1gspm is cleared. bit 2 t1gval: timer1 gate current state bit indicates the current state of the timer1 gate that could be provided to tmr1h:tmr1l; unaffected by timer1 gate enable (tmr1ge) bit. bit 1-0 t1gss<1:0>: timer1 gate source select bits 00 = timer1 gate pin 01 = timer0 overflow output 10 = tmr2 to match pr2 output note 1: programming the t1gcon prior to t1con is recommended.
? 2009 microchip technology inc. preliminary ds39931b-page 193 pic18f46j50 family register 12-3: tclkcon: timer cloc k control register (banked f52h) u-0 u-0 u-0 r-0 u-0 u-0 r/w-0 r/w-0 ? ? ? t1run ? ?t3ccp2t3ccp1 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 t1run: timer1 run status bit 1 = device is currently clocked by t1osc/t1cki 0 = system clock comes from an oscillator other than t1osc/t1cki bit 3-2 unimplemented: read as ? 0 ? bit 1-0 t3ccp<2:1>: eccp timer assignment bits 10 = eccp1 and eccp2 both use timer3 (capture/compare) and timer4 (pwm) 01 = eccp1 uses timer1 (compare/capture) and timer2 (pwm); eccp2 uses timer3 (capture/compare) and timer4 (pwm) 00 = eccp1 and eccp2 both use timer1 (capture/compare) and timer2 (pwm)
pic18f46j50 family ds39931b-page 194 preliminary ? 2009 microchip technology inc. 12.2 timer1 operation the timer1 module is an 8-bit or 16-bit incrementing counter, which is accessed through the tmr1h:tmr1l register pair. when used with an internal clock source, the module is a timer and increments on every instruction cycle. when used with an external clock source, the module can be used as either a timer or counter and increments on every selected edge of the external source. timer1 is enabled by configuring the tmr1on and tmr1ge bits in the t1con and t1gcon registers, respectively. when timer1 is enabled, the rc1/t1osi/uoe /rp12 and rc0/t1oso/t1cki/rp11 pins become inputs. this means the values of trisc<1:0> are ignored and the pins are read as ? 0 ?. 12.3 clock source selection the tmr1cs<1:0> and t1oscen bits of the t1con register are used to select the clock source for timer1. register 12-1 displays the clock source selections. 12.3.1 internal clock source when the internal clock source is selected, the tmr1h:tmr1l register pair will increment on multiples of f osc as determined by the timer1 prescaler. 12.3.2 external clock source when the external clock source is selected, the timer1 module may work as a timer or a counter. when enabled to count, timer1 is incremented on the rising edge of the external clock input, t1cki, or the capacitive sensing oscillator signal. either of these external clock sources can be synchronized to the microcontroller system clock or they can run asynchronously. when used as a timer with a clock oscillator, an external 32.768 khz crystal can be used in conjunction with the dedicated internal oscillator circuit. table 12-1: timer1 clo ck source selection note: in counter mode, a falling edge must be registered by the counter prior to the first incrementing rising edge after any one or more of the following conditions: ? timer1 enabled after por reset ? write to tmr1h or tmr1l ? timer1 is disabled ? timer1 is disabled (tmr1on = 0 ) when t1cki is high, then timer1 is enabled (tmr1on = 1 ) when t1cki is low. tmr1cs1 tmr1cs0 t1oscen clock source 01x clock source (f osc ) 00x instruction clock (f osc /4) 100 external clock on t1cki pin 101 oscillator circuit on t1osi/t1oso pin
? 2009 microchip technology inc. preliminary ds39931b-page 195 pic18f46j50 family figure 12-1: timer1 block diagram tmr1h tmr1l t1sync t1ckps<1:0> prescaler 1, 2, 4, 8 0 1 synchronized clock input 2 set flag bit tmr1if on overflow tmr1 (2) tmr1on note 1: st buffer is high-speed type when using t1cki. 2: timer1 register increments on rising edge. 3: synchronize does not operate while in sleep. t1g t1osc f osc /4 internal clock t1oso/t1cki t1osi t1oscen 1 0 t1cki tmr1cs<1:0> (1) synchronize (3) det sleep input tmr1ge 0 1 00 01 10 from timer0 from timer2 t1gpol d q ck q 0 1 t1gval t1gtm single pulse acq. control t1gspm t1ggo/t1do ne t1gss<1:0> en out 10 00 01 f osc internal clock match pr2 overflow r d en q q1 rd t1gcon data bus det interrupt tmr1gif set t1clk f osc /2 internal clock d en q t1g_in tmr1on
pic18f46j50 family ds39931b-page 196 preliminary ? 2009 microchip technology inc. 12.4 timer1 16-bit read/write mode timer1 can be configured for 16-bit reads and writes. when the rd16 control bit (t1con<1>) is set, the address for tmr1h is mapped to a buffer register for the high byte of timer1. a read from tmr1l loads the contents of the high byte of timer1 into the timer1 high byte buffer register. this provides the user with the ability to accurately read all 16 bits of timer1 without having to determine whether a read of the high byte, followed by a read of the low byte, has become invalid due to a rollover between reads. a write to the high byte of timer1 must also take place through the tmr1h buffer register. the timer1 high byte is updated with the contents of tmr1h when a write occurs to tmr1l. this allows a user to write all 16 bits to both the high and low bytes of timer1 at once. the high byte of timer1 is not directly readable or writable in this mode. all reads and writes must take place through the timer1 high byte buffer register. writes to tmr1h do not clear the timer1 prescaler. the prescaler is only cleared on writes to tmr1l. 12.5 timer1 oscillator an on-chip crystal oscillator circuit is incorporated between pins, t1osi (input) and t1oso (amplifier output). it is enabled by setting the timer1 oscillator enable bit, t1oscen (t1con<3>). the oscillator is a low-power circuit rated for 32 khz crystals. it will continue to run during all power-managed modes. the circuit for a typical lp oscillator is depicted in figure 12-2. table 12-2 provides the capacitor selection for the timer1 oscillator. the user must provide a software time delay to ensure proper start-up of the timer1 oscillator. figure 12-2: external components for the timer1 lp oscillator table 12-2: capacitor selection for the timer oscillator (2,3,4,5) the timer1 crystal oscillator drive level is determined based on the lpt1osc (config2l<4>) configura- tion bit. the higher drive level mode, lpt1osc = 1 , is intended to drive a wide variety of 32.768 khz crystals with a variety of load capacitance (c l ) ratings. the lower drive level mode is highly optimized for extremely low-power consumption. it is not intended to drive all types of 32.768 khz crystals. in the low drive level mode, the crystal oscillator circuit may not work correctly if excessively large discrete capacitors are placed on the t1osi and t1oso pins. this mode is only designed to work with discrete capacitances of approximately 3 pf-10 pf on each pin. crystal manufacturers usually specify a c l (load capacitance) rating for their crystals. this value is related to, but not necessarily the same as, the values that should be used for c1 and c2 in figure 12-2. see the crystal manufacturer?s applications information for more details on how to select the optimum c1 and c2 for a given crystal. the optimum value depends in part on the amount of parasitic capacitance in the circuit, which is often unknown. therefore, after values have been selected, it is highly recommended that thorough testing and validation of the oscillator be performed. note: see the notes with table 12-2 for additional information about capacitor selection. c1 c2 xtal pic18f46j50 t1osi t1oso 32.768 khz 12 pf 12 pf oscillator type freq. c1 c2 lp 32 khz 12 pf (1) 12 pf (1) note 1: microchip suggests these values as a starting point in validating the oscillator circuit. 2: higher capacitance increases the stability of the oscillator but also increases the start-up time. 3: since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appropriate values of external components. 4: capacitor values are for design guidance only. values listed would be typical of a c l = 10 pf rated crystal when lpt1osc = 1 . 5: incorrect capacitance value may result in a frequency not meeting the crystal manufacturer?s tolerance specification.
? 2009 microchip technology inc. preliminary ds39931b-page 197 pic18f46j50 family 12.5.1 using timer1 as a clock source the timer1 oscillator is also available as a clock source in power-managed modes. by setting the clock select bits, scs<1:0> (osccon<1:0>), to ? 01 ?, the device switches to sec_run mode; both the cpu and peripherals are clocked from the timer1 oscillator. if the idlen bit (osccon<7>) is cleared and a sleep instruction is executed, the device enters sec_idle mode. additional details are available in section 3.0 ?low-power modes? . whenever the timer1 oscillator is providing the clock source, the timer1 system clock status flag, t1run (tclkcon<4>), is set. this can be used to determine the controller?s current clocking mode. it can also indicate the clock source currently being used by the fail-safe clock monitor. if the clock monitor is enabled and the timer1 oscillator fails while providing the clock, polling the t1run bit will indicate whether the clock is being provided by the timer1 oscillator or another source. 12.5.2 timer1 oscillator layout considerations the timer1 oscillator circuit draws very little power during operation. due to the low-power nature of the oscillator, it may also be sensitive to rapidly changing signals in close proximity. this is especially true when the oscillator is configured for extremely low-power mode (lpt1osc = 0 ). the oscillator circuit, displayed in figure 12-2, should be located as close as possible to the microcontroller. there should be no circuits passing within the oscillator circuit boundaries other than v ss or v dd . if a high-speed circuit must be located near the oscillator (such as the eccp1 pin in output compare or pwm mode, or the primary oscillator using the osc2 pin), a grounded guard ring around the oscillator circuit, as displayed in figure 12-3, may be helpful when used on a single-sided pcb or in addition to a ground plane. figure 12-3: oscillator circuit with grounded guard ring in the low drive level mode, lpt1osc = 0 , it is critical that the rc2 i/o pin signals be kept away from the oscillator circuit. configuring rc2 as a digital output, and toggling it, can potentially disturb the oscillator circuit, even with relatively good pcb layout. if possible, it is recommended to either leave rc2 unused, or use it as an input pin with a slew rate limited signal source. if rc2 must be used as a digital output, it may be necessary to use the higher drive level oscillator mode (lpt1osc = 1 ) with many pcb lay- outs. even in the high drive level mode, careful layout procedures should still be followed when designing the oscillator circuit. in addition to dv/dt induced noise considerations, it is also important to ensure that the circuit board is clean. even a very small amount of conductive soldering flux residue can cause pcb leakage currents which can overwhelm the oscillator circuit. 12.6 timer1 interrupt the tmr1 register pair (tmr1h:tmr1l) increments from 0000h to ffffh and rolls over to 0000h. the timer1 interrupt, if enabled, is generated on overflow which is latched in interrupt flag bit, tmr1if (pir1<0>). this interrupt can be enabled or disabled by setting or clearing the timer1 interrupt enable bit, tmr1ie (pie1<0>). v dd osc1 v ss osc2 rc0 rc1 rc2 note: not drawn to scale.
pic18f46j50 family ds39931b-page 198 preliminary ? 2009 microchip technology inc. 12.7 resetting timer1 using the eccp special event trigger if eccp1 or eccp2 is configured to use timer1 and to generate a special event trigger in compare mode (ccpxm<3:0> = 1011 ), this signal will reset timer3. the trigger from eccp2 will also start an a/d conver- sion if the a/d module is enabled (see section 17.3.4 ?special event trigger? for more information). the module must be configured as either a timer or a synchronous counter to take advantage of this feature. when used this way, the ccprxh:ccprxl register pair effectively becomes a period register for timer1. if timer1 is running in asynchronous counter mode, this reset operation may not work. in the event that a write to timer1 coincides with a special event trigger, the write operation will take precedence. 12.8 timer1 gate the timer1 can be configured to count freely or the count can be enabled and disabled using the timer1 gate circuitry. this is also referred to as timer1 gate count enable. timer1 gate can also be driven by multiple selectable sources. 12.8.1 timer1 gate count enable the timer1 gate enable mode is enabled by setting the tmr1ge bit of the t1gcon register. the polarity of the timer1 gate enable mode is configured using the t1gpol bit of the t1gcon register. when timer1 gate enable mode is enabled, timer1 will increment on the rising edge of the timer1 clock source. when timer1 gate enable mode is disabled, no incrementing will occur and timer1 will hold the current count. see figure 12-4 for timing details. table 12-3: timer1 gate enable selections figure 12-4: timer1 gate count enable mode note: the special event trigger from the eccpx module will not set the tmr1if interrupt flag bit (pir1<0>). t1clk t1gpol t1g timer1 operation 00 counts 01 holds count 10 holds count 11 counts tmr1ge t1gpol t1g_in t1cki t1gval timer1 n n + 1 n + 2 n + 3 n + 4
? 2009 microchip technology inc. preliminary ds39931b-page 199 pic18f46j50 family 12.8.2 timer1 gate source selection the timer1 gate source can be selected from one of four different sources. source selection is controlled by the t1gssx bits of the t1gcon register. the polarity for each available source is also selectable. polarity selection is controlled by the t1gpol bit of the t1gcon register. table 12-4: timer1 gate sources 12.8.2.1 t1g pin gate operation the t1g pin is one source for timer1 gate control. it can be used to supply an external source to the timer1 gate circuitry. 12.8.2.2 timer0 overflow gate operation when timer0 increments from ffh to 00h, a low-to-high pulse will automatically be generated and internally supplied to the timer1 gate circuitry. 12.8.2.3 timer2 match gate operation the tmr2 register will increment until it matches the value in the pr2 register. on the very next increment cycle, tmr2 will be reset to 00h. when this reset occurs, a low-to-high pulse will automatically be generated and internally supplied to the timer1 gate circuitry. t1gss<1:0> timer1 gate source 00 timer1 gate pin 01 overflow of timer0 (tmr0 increments from ffh to 00h) 10 tmr2 to match pr2 (tmr2 increments to match pr2)
pic18f46j50 family ds39931b-page 200 preliminary ? 2009 microchip technology inc. 12.8.3 timer1 gate toggle mode when timer1 gate toggle mode is enabled, it is possible to measure the full cycle length of a timer1 gate signal, as opposed to the duration of a single level pulse. the timer1 gate source is routed through a flip-flop that changes state on every incrementing edge of the signal. see figure 12-5 for timing details. the t1gval bit will indicate when the toggled mode is active and the timer is counting. the timer1 gate toggle mode is enabled by setting the t1gtm bit of the t1gcon register. when the t1gtm bit is cleared, the flip-flop is cleared and held clear. this is necessary in order to control which edge is measured. figure 12-5: timer1 gate toggle mode tmr1ge t1gpol t1gtm t1g_in t1cki t1gval timer1 n n + 1 n + 2 n + 3 n + 4 n + 5 n + 6 n + 7 n + 8
? 2009 microchip technology inc. preliminary ds39931b-page 201 pic18f46j50 family 12.8.4 timer1 gate single pulse mode when timer1 gate single pulse mode is enabled, it is possible to capture a single pulse gate event. timer1 gate single pulse mode is first enabled by setting the t1gspm bit in the t1gcon register. next, the t1ggo/t1do ne bit in the t1gcon register must be set. the timer1 will be fully enabled on the next incre- menting edge. on the next trailing edge of the pulse, the t1ggo/t1do ne bit will automatically be cleared. no other gate events will be allowed to increment timer1 until the t1ggo/t1do ne bit is once again set in software. clearing the t1gspm bit of the t1gcon register will also clear the t1ggo/t1do ne bit. see figure 12-6 for timing details. enabling the toggle mode and the single pulse mode, simultaneously, will permit both sections to work together. this allows the cycle times on the timer1 gate source to be measured. see figure 12-7 for timing details. 12.8.5 timer1 gate value status when the timer1 gate value status is utilized, it is possible to read the most current level of the gate control value. the value is stored in the t1gval bit in the t1gcon register. the t1gval bit is valid even when the timer1 gate is not enabled (tmr1ge bit is cleared). figure 12-6: timer1 gate single pulse mode tmr1ge t1gpol t1g_in t1cki t1gval timer1 n n + 1 n + 2 t1gspm t1ggo/ t1do ne set by software cleared by hardware on falling edge of t1gval set by hardware on falling edge of t1gval cleared by software cleared by software tmr1gif counting enabled on rising edge of t1g
pic18f46j50 family ds39931b-page 202 preliminary ? 2009 microchip technology inc. figure 12-7: timer1 gate single pulse and toggle combined mode table 12-5: registers associated with timer1 as a timer/counter name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 81 pir1 pmpif (1) adif rc1if tx1if ssp1if ccp1if tmr2if tmr1if 83 pie1 pmpie (1) adie rc1ie tx1ie ssp1ie ccp1ie tmr2ie tmr1ie 83 ipr1 pmpip (1) adip rc1ip tx1ip ssp1ip ccp1ip tmr2ip tmr1ip 83 tmr1l timer1 register low byte 82 tmr1h timer1 register high byte 82 t1con tmr1cs1 tmr1cs0 t1ckps1 t1ckps0 t1oscen t1sync rd16 tmr1on 82 t1gcon tmr1ge t1gpol t1gtm t1gspm t1ggo/ t1do ne t1gval t1gss1 t1gss0 83 tclkcon ? ? ? t1run ? ? t3ccp2 t3ccp1 85 legend: shaded cells are not used by the timer1 module. note 1: these bits are only available in 44-pin devices. tmr1ge t1gpol t1g_in t1cki t1gval timer1 n n + 1 n + 2 t1gspm t1ggo/ t1do ne set by software cleared by hardware on falling edge of t1gval set by hardware on falling edge of t1gval cleared by software cleared by software tmr1gif t1gtm counting enabled on rising edge of t1g n + 4 n + 3
? 2009 microchip technology inc. preliminary ds39931b-page 203 pic18f46j50 family 13.0 timer2 module the timer2 module incorporates the following features: ? 8-bit timer and period registers (tmr2 and pr2, respectively) ? readable and writable (both registers) ? software programmable prescaler (1:1, 1:4 and 1:16) ? software programmable postscaler (1:1 through 1:16) ? interrupt on tmr2 to pr2 match ? optional use as the shift clock for the mssp modules the module is controlled through the t2con register (register 13-1) which enables or disables the timer and configures the prescaler and postscaler. timer2 can be shut off by clearing control bit, tmr2on (t2con<2>), to minimize power consumption. a simplified block diagram of the module is shown in figure 13-1. 13.1 timer2 operation in normal operation, tmr2 is incremented from 00h on each clock (f osc /4). a 4-bit counter/prescaler on the clock input gives direct input, divide-by-4 and divide-by-16 prescale options. these are selected by the prescaler control bits, t2ckps<1:0> (t2con<1:0>). the value of tmr2 is compared to that of the period register, pr2, on each clock cycle. when the two values match, the comparator generates a match signal as the timer output. this signal also resets the value of tmr2 to 00h on the next cycle and drives the output counter/postscaler (see section 13.2 ?timer2 interrupt? ). the tmr2 and pr2 registers are both directly readable and writable. the tmr2 register is cleared on any device reset, while the pr2 register initializes at ffh. both the prescaler and postscaler counters are cleared on the following events: ? a write to the tmr2 register ? a write to the t2con register ? any device reset (power-on reset (por), mclr reset, watchdog timer reset (wdtr) or brown-out reset (bor)) tmr2 is not cleared when t2con is written. register 13-1: t2con: timer2 co ntrol register (access fcah) u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-3 t2outps<3:0>: timer2 output postscale select bits 0000 = 1:1 postscale 0001 = 1:2 postscale ? ? ? 1111 = 1:16 postscale bit 2 tmr2on: timer2 on bit 1 = timer2 is on 0 = timer2 is off bit 1-0 t2ckps<1:0>: timer2 clock prescale select bits 00 = prescaler is 1 01 = prescaler is 4 1x = prescaler is 16
pic18f46j50 family ds39931b-page 204 preliminary ? 2009 microchip technology inc. 13.2 timer2 interrupt timer2 can also generate an optional device interrupt. the timer2 output signal (tmr2 to pr2 match) pro- vides the input for the 4-bit output counter/postscaler. this counter generates the tmr2 match interrupt flag, which is latched in tmr2if (pir1<1>). the interrupt is enabled by setting the tmr2 match interrupt enable bit, tmr2ie (pie1<1>). a range of 16 postscaler options (from 1:1 through 1:16 inclusive) can be selected with the postscaler control bits, t2outps<3:0> (t2con<6:3>). 13.3 timer2 output the unscaled output of tmr2 is available primarily to the eccp modules, where it is used as a time base for operations in pwm mode. timer2 can be optionally used as the shift clock source for the mssp modules operating in spi mode. additional information is provided in section 18.0 ?master synchronous serial port (mssp) module? . figure 13-1: timer2 block diagram table 13-1: registers associated with timer2 as a timer/counter name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 81 pir1 pmpif (1) adif rc1if tx1if ssp1if ccp1if tmr2if tmr1if 83 pie1 pmpie (1) adie rc1ie tx1ie ssp1ie ccp1ie tmr2ie tmr1ie 83 ipr1 pmpip (1) adip rc1ip tx1ip ssp1ip ccp1ip tmr2ip tmr1ip 83 tmr2 timer2 register 82 t2con ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 82 pr2 timer2 period register 82 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the timer2 module. note 1: these bits are only available in 44-pin devices. comparator tmr2 output tmr2 postscaler prescaler pr2 2 f osc /4 1:1 to 1:16 1:1, 1:4, 1:16 4 t2outps<3:0> t2ckps<1:0> set tmr2if internal data bus 8 reset tmr2/pr2 8 8 (to pwm or msspx) match
? 2009 microchip technology inc. preliminary ds39931b-page 205 pic18f46j50 family 14.0 timer3 module the timer3 timer/counter module incorporates these features: ? software selectable operation as a 16-bit timer or counter ? readable and writable 8-bit registers (tmr3h and tmr3l) ? selectable clock source (internal or external) with device clock or timer1 oscillator internal options ? interrupt-on-overflow ? module reset on eccp special event trigger a simplified block diagram of the timer3 module is shown in figure 14-1. the timer3 module is controlled through the t3con register (register 14-1). it also selects the clock source options for the eccp modules; see section 17.1.1 ?eccp module and timer resources? for more information. the f osc clock source (tmr3cs<1:0> = 01 ) should not be used with the eccp capture/compare features. if the timer will be used with the capture or compare features, always select one of the other timer clocking options. register 14-1: t3con: timer3 co ntrol register (access f79h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 tmr3cs1 tmr3cs0 t3ckps1 t3ckps0 t3oscen t3sync rd16 tmr3on bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 tmr3cs<1:0>: timer3 clock source select bits 10 = timer3 clock source is the timer1 oscillator or the t3cki digital input pin (assigned in pps module) 01 = timer3 clock source is the system clock (f osc ) (1) 00 = timer3 clock source is the instruction clock (f osc /4) bit 5-4 t3ckps<1:0> : timer3 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 t3oscen: timer3 oscillator source select bit when tmr3cs<1:0> = 10 : 1 = power up the timer1 crystal driver (t1osc) and supply the timer3 clock from the crystal output 0 = timer1 crystal driver off (2) , timer3 clock is from the t3cki digital input pin assigned in pps module when tmr3cs<1:0> = 0x : 1 = power up the timer1 crystal driver (t1osc) 0 = timer1 crystal driver off (2) bit 2 t3sync : timer3 external clock input synchronization control bit when tmr3cs<1:0> = 10 : 1 = do not synchronize external clock input 0 = synchronize external clock input when tmr3cs<1:0> = 0x : this bit is ignored; timer3 uses the internal clock. bit 1 rd16: 16-bit read/write mode enable bit 1 = enables register read/write of timer3 in one 16-bit operation 0 = enables register read/write of timer3 in two 8-bit operations bit 0 tmr3on: timer3 on bit 1 = enables timer3 0 = stops timer3 note 1: the f osc clock source should not be selected if the timer will be used with the eccp capture/compare features. 2: the timer1 oscillator crystal driver is powered whenever t1oscen (t1con) or t3oscen (t3con) = 1 . the circuit is enabled by the logical or of these two bits. when disabled, the inverter and feedback resistor are disabled to eliminate power drain. the tmr1on and tmr3on bits do not have to be enabled to power up the crystal driver.
pic18f46j50 family ds39931b-page 206 preliminary ? 2009 microchip technology inc. 14.1 timer3 gate control register the timer3 gate control register (t3gcon), provided in register 14-2, is used to control the timer3 gate. register 14-2: t3gcon: timer3 gate control register (access f97h) (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-x r/w-0 r/w-0 tmr3ge t3gpol t3gtm t3gspm t3ggo/t3do ne t3gval t3gss1 t3gss0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr3ge: timer3 gate enable bit if tmr3on = 0 : this bit is ignored. if tmr3on = 1 : 1 = timer3 counting is controlled by the timer3 gate function 0 = timer3 counts regardless of timer3 gate function bit 6 t3gpol: timer3 gate polarity bit 1 = timer3 gate is active-high (timer3 counts when gate is high) 0 = timer3 gate is active-low (timer3 counts when gate is low) bit 5 t3gtm: timer3 gate toggle mode bit 1 = timer3 gate toggle mode is enabled. 0 = timer3 gate toggle mode is disabled and toggle flip-flop is cleared timer3 gate flip-flop toggles on every rising edge. bit 4 t3gspm: timer3 gate single pulse mode bit 1 = timer3 gate single pulse mode is enabled and is controlling timer3 gate 0 = timer3 gate single pulse mode is disabled bit 3 t3ggo/t3do ne : timer3 gate single pulse acquisition status bit 1 = timer3 gate single pulse acquisition is ready, waiting for an edge 0 = timer3 gate single pulse acquisition has completed or has not been started this bit is automatically cleared when t3gspm is cleared. bit 2 t3gval: timer3 gate current state bit indicates the current state of the timer3 gate that could be provided to tmr3h:tmr3l. unaffected by timer3 gate enable bit (tmr3ge). bit 1-0 t3gss<1:0>: timer3 gate source select bits 10 = tmr2 to match pr2 output 01 = timer0 overflow output 00 = timer3 gate pin (t3g) note 1: programming the t3gcon prior to t3con is recommended.
? 2009 microchip technology inc. preliminary ds39931b-page 207 pic18f46j50 family register 14-3: tclkcon: timer cloc k control register (banked f52h) u-0 u-0 u-0 r-0 u-0 u-0 r/w-0 r/w-0 ? ? ? t1run ? ?t3ccp2t3ccp1 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 t1run: timer1 run status bit 1 = device is currently clocked by t1osc/t1cki 0 = system clock comes from an oscillator other than t1osc/t1cki bit 3-2 unimplemented: read as ? 0 ? bit 1-0 t3ccp<2:1>: eccp timer assignment bits 10 = eccp1 and eccp2 both use timer3 (capture/compare) and timer4 (pwm) 01 = eccp1 uses timer1 (compare/capture) and timer2 (pwm); eccp2 uses timer3 (capture/compare) and timer4 (pwm) 00 = eccp1 and eccp2 both use timer1 (capture/compare) and timer2 (pwm)
pic18f46j50 family ds39931b-page 208 preliminary ? 2009 microchip technology inc. 14.2 timer3 operation timer3 can operate in one of three modes: ?timer ? synchronous counter ? asynchronous counter ? timer with gated control the operating mode is determined by the clock select bits, tmr3csx (t3con<7:6>). when the tmr3csx bits are cleared (= 0 0 ), timer3 increments on every internal instruction cycle (f osc /4). when tmr3csx = 01 , the timer3 clock source is the system clock (f osc ), and when it is ? 10 ?, timer3 works as a counter from the external clock from the t3cki pin (on the rising edge after the first falling edge) or the timer1 oscillator. figure 14-1: timer3 block diagram tmr3h tmr3l t3sync t3ckps<1:0> prescaler 1, 2, 4, 8 0 1 synchronized clock input 2 set flag bit tmr1if on overflow tmr3 (2) tmr3on note 1: st buffer is high-speed type when using t3cki. 2: timer3 register increments on rising edge. 3: synchronize does not operate while in sleep. 4: if t3oscen = 1 , clock is from timer1 crystal output. if t3oscen = 0 , clock is from t3cki digital input pin assigned in the pps module. t3g f osc /4 internal clock tmr3cs<1:0> synchronize (3) det sleep input tmr3ge 0 1 00 01 10 from timer0 from timer2 t3gpol d q ck q 0 1 t3gval t3gtm single pulse acq. control t3gspm t3ggo/t3do ne t3gss<1:0> 10 00 01 f osc internal clock match pr2 overflow r d en q q1 rd t3gcon data bus det interrupt tmr3gif set t3clk f osc /2 internal clock d en q t3g_in tmr3on t3cki (1) or t1osc (4)
? 2009 microchip technology inc. preliminary ds39931b-page 209 pic18f46j50 family 14.3 timer3 16-bit read/write mode timer3 can be configured for 16-bit reads and writes (see section 14.3 ?timer3 16-bit read/write mode? ). when the rd16 control bit (t3con<1>) is set, the address for tmr3h is mapped to a buffer reg- ister for the high byte of timer3. a read from tmr3l will load the contents of the high byte of timer3 into the timer3 high byte buffer register. this provides the user with the ability to accurately read all 16 bits of timer3 without having to determine whether a read of the high byte, followed by a read of the low byte, has become invalid due to a rollover between reads. a write to the high byte of timer3 must also take place through the tmr3h buffer register. the timer3 high byte is updated with the contents of tmr3h when a write occurs to tmr3l. this allows a user to write all 16 bits to both the high and low bytes of timer3 at once. the high byte of timer3 is not directly readable or writable in this mode. all reads and writes must take place through the timer3 high byte buffer register. writes to tmr3h do not clear the timer3 prescaler. the prescaler is only cleared on writes to tmr3l. 14.4 using the timer1 oscillator as the timer3 clock source the timer1 internal oscillator may be used as the clock source for timer3. the timer1 oscillator is enabled by setting the t1oscen (t1con<3>) bit. to use it as the timer3 clock source, the tmr3cs bit must also be set. as previously noted, this also configures timer3 to increment on every rising edge of the oscillator source. the timer1 oscillator is described in section 12.0 ?timer1 module? . 14.5 timer3 gate timer3 can be configured to count freely, or the count can be enabled and disabled using timer3 gate circuitry. this is also referred to as timer3 gate count enable. timer3 gate can also be driven by multiple selectable sources. 14.5.1 timer3 gate count enable the timer3 gate enable mode is enabled by setting the tmr3ge bit of the t3gcon register. the polarity of the timer3 gate enable mode is configured using the t3gpol bit of the t3gcon register. when timer3 gate enable mode is enabled, timer3 will increment on the rising edge of the timer3 clock source. when timer3 gate enable mode is disabled, no incrementing will occur and timer3 will hold the current count. see figure 14-2 for timing details. table 14-1: timer3 gate enable selections figure 14-2: timer3 gate count enable mode t3clk t3gpol t3g timer3 operation 00 counts 01 holds count 10 holds count 11 counts tmr3ge t3gpol t3g_in t1cki t3gval timer3 n n + 1 n + 2 n + 3 n + 4
pic18f46j50 family ds39931b-page 210 preliminary ? 2009 microchip technology inc. 14.5.2 timer3 gate source selection the timer3 gate source can be selected from one of four different sources. source selection is controlled by the t3gssx bits of the t3gcon register. the polarity for each available source is also selectable. polarity selection is controlled by the t3gpol bit of the t3gcon register. table 14-2: timer3 gate sources 14.5.2.1 t3g pin gate operation the t3g pin is one source for timer3 gate control. it can be used to supply an external source to the timer3 gate circuitry. 14.5.2.2 timer0 overflow gate operation when timer0 increments from ffh to 00h, a low-to-high pulse will automatically be generated and internally supplied to the timer3 gate circuitry. 14.5.2.3 timer2 match gate operation the tmr2 register will increment until it matches the value in the pr2 register. on the very next increment cycle, tmr2 will be reset to 00h. when this reset occurs, a low-to-high pulse will automatically be generated and internally supplied to the timer3 gate circuitry. 14.5.3 timer3 gate toggle mode when timer3 gate toggle mode is enabled, it is possible to measure the full cycle length of a timer3 gate signal, as opposed to the duration of a single level pulse. the timer1 gate source is routed through a flip-flop that changes state on every incrementing edge of the signal. see figure 14-3 for timing details. the t3gval bit will indicate when the toggled mode is active and the timer is counting. timer3 gate toggle mode is enabled by setting the t3gtm bit of the t3gcon register. when the t3gtm bit is cleared, the flip-flop is cleared and held clear. this is necessary in order to control which edge is measured. figure 14-3: timer3 gate toggle mode t3gss<1:0> timer3 gate source 00 timer3 gate pin 01 overflow of timer0 (tmr0 increments from ffh to 00h) 10 tmr2 to match pr2 (tmr2 increments to match pr2) 11 reserved tmr3ge t3gpol t3gtm t3g_in t1cki t3gval timer3 n n + 1 n + 2 n + 3 n + 4 n + 5 n + 6 n + 7 n + 8
? 2009 microchip technology inc. preliminary ds39931b-page 211 pic18f46j50 family 14.5.4 timer3 gate single pulse mode when timer3 gate single pulse mode is enabled, it is possible to capture a single pulse gate event. timer3 gate single pulse mode is first enabled by setting the t3gspm bit in the t3gcon register. next, the t3ggo/t3do ne bit in the t3gcon register must be set. the timer3 will be fully enabled on the next increment- ing edge. on the next trailing edge of the pulse, the t3ggo/t3do ne bit will automatically be cleared. no other gate events will be allowed to increment timer3 until the t3ggo/t3do ne bit is once again set in software. clearing the t3gspm bit of the t3gcon register will also clear the t3ggo/t3do ne bit. see figure 14-4 for timing details. enabling the toggle mode and the single pulse mode, simultaneously, will permit both sections to work together. this allows the cycle times on the timer3 gate source to be measured. see figure 14-5 for timing details. figure 14-4: timer3 gate single pulse mode tmr3ge t3gpol t3g_in t1cki t3gval timer3 n n + 1 n + 2 t3gspm t3ggo/ t3do ne set by software cleared by hardware on falling edge of t3gval set by hardware on falling edge of t3gval cleared by software cleared by software tmr3gif counting enabled on rising edge of t3g
pic18f46j50 family ds39931b-page 212 preliminary ? 2009 microchip technology inc. figure 14-5: timer3 gate single pulse and toggle combined mode 14.5.5 timer3 gate value status when timer3 gate value status is utilized, it is possible to read the most current level of the gate control value. the value is stored in the t3gval bit in the t3gcon register. the t3gval bit is valid even when the timer3 gate is not enabled (tmr3ge bit is cleared). 14.5.6 timer3 gate event interrupt when the timer3 gate event interrupt is enabled, it is possible to generate an interrupt upon the completion of a gate event. when the falling edge of t3gval occurs, the tmr3gif flag bit in the pir3 register will be set. if the tmr3gie bit in the pie3 register is set, then an interrupt will be recognized. the tmr3gif flag bit operates even when the timer3 gate is not enabled (tmr3ge bit is cleared). tmr3ge t3gpol t3g_in t1cki t3gval timer3 n n + 1 n + 2 t3gspm t3ggo/ t3do ne set by software cleared by hardware on falling edge of t3gval set by hardware on falling edge of t3gval cleared by software cleared by software tmr3gif t3gtm counting enabled on rising edge of t3g n + 4 n + 3
? 2009 microchip technology inc. preliminary ds39931b-page 213 pic18f46j50 family 14.6 timer3 interrupt the tmr3 register pair (tmr3h:tmr3l) increments from 0000h to ffffh and overflows to 0000h. the timer3 interrupt, if enabled, is generated on overflow and is latched in interrupt flag bit, tmr3if (pir2<1>). this interrupt can be enabled or disabled by setting or clearing the timer3 interrupt enable bit, tmr3ie (pie2<1>). 14.7 resetting timer3 using the eccp special event trigger if eccp1 or eccp2 is configured to use timer3 and to generate a special event trigger in compare mode (ccpxm<3:0> = 1011 ), this signal will reset timer3. the trigger from eccp2 will also start an a/d conver- sion if the a/d module is enabled (see section 17.3.4 ?special event trigger? for more information). the module must be configured as either a timer or synchronous counter to take advantage of this feature. when used this way, the ccprxh:ccprxl register pair effectively becomes a period register for timer3. if timer3 is running in asynchronous counter mode, the reset operation may not work. in the event that a write to timer3 coincides with a special event trigger from an eccp module, the write will take precedence. table 14-3: registers associated with timer3 as a timer/counter note: the special event triggers from the eccpx module will not set the tmr3if interrupt flag bit (pir1<0>). name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 81 pir2 oscfif cm2if cm1if usbif bcl1if hlvdif tmr3if ccp2if 83 pie2 oscfie cm2ie cm1ie usbie bcl1ie hlvdie tmr3ie ccp2ie 83 ipr2 oscfip cm2ip cm1ip usbip bcl1ip hlvdip tmr3ip ccp2ip 83 tmr3l timer3 register low byte 84 tmr3h timer3 register high byte 84 t1con tmr1cs1 tmr1cs0 t1ckps1 t1ckps0 t1oscen t1sync rd16 tmr1on 82 t3con tmr3cs1 tmr3cs0 t3ckps1 t3ckps0 t3oscen t3sync rd16 tmr3on 84 t3gcon tmr3ge t3gpol t3gtm t3gspm t3ggo/ t3do ne t3gval t3gss1 t3gss0 84 tclkcon ? ? ? t1run ? ? t3ccp2 t3ccp1 85 pir3 ssp2if bcl2if rc2if tx2if tmr4if ctmuif tmr3gif rtccif 83 pie3 ssp2ie bcl2ie rc2ie tx2ie tmr4ie ctmuie tmr3gie rtccie 83 ipr3 ssp2ip bcl2ip rc2ip tx2ip tmr4ip ctmuip tmr3gip rtccip 83 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the timer3 module.
pic18f46j50 family ds39931b-page 214 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39931b-page 215 pic18f46j50 family 15.0 timer4 module the timer4 timer module has the following features: ? 8-bit timer register (tmr4) ? 8-bit period register (pr4) ? readable and writable (both registers) ? software programmable prescaler (1:1, 1:4, 1:16) ? software programmable postscaler (1:1 to 1:16) ? interrupt on tmr4 match of pr4 timer4 has a control register shown in register 15-1. timer4 can be shut off by clearing control bit, tmr4on (t4con<2>), to minimize power consumption. the prescaler and postscaler selection of timer4 is also controlled by this register. figure 15-1 is a simplified block diagram of the timer4 module. 15.1 timer4 operation timer4 can be used as the pwm time base for the pwm mode of the eccp modules. the tmr4 register is readable and writable and is cleared on any device reset. the input clock (f osc /4) has a prescale option of 1:1, 1:4 or 1:16, selected by control bits, t4ckps<1:0> (t4con<1:0>). the match output of tmr4 goes through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling inclusive) to generate a tmr4 interrupt, latched in flag bit, tmr4if (pir3<3>). the prescaler and postscaler counters are cleared when any of the following occurs: ? a write to the tmr4 register ? a write to the t4con register ? any device reset (power-on reset (por), mclr reset, watchdog timer reset (wdtr) or brown-out reset (bor)) tmr4 is not cleared when t4con is written. register 15-1: t4con: timer4 co ntrol register (access f76h) u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? t4outps3 t4outps2 t4outps1 t4outps0 tmr4on t4ckps1 t4ckps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-3 t4outps<3:0>: timer4 output postscale select bits 0000 = 1:1 postscale 0001 = 1:2 postscale ? ? ? 1111 = 1:16 postscale bit 2 tmr4on : timer4 on bit 1 = timer4 is on 0 = timer4 is off bit 1-0 t4ckps<1:0>: timer4 clock prescale select bits 00 = prescaler is 1 01 = prescaler is 4 1x = prescaler is 16
pic18f46j50 family ds39931b-page 216 preliminary ? 2009 microchip technology inc. 15.2 timer4 interrupt the timer4 module has an 8-bit period register, pr4, which is both readable and writable. timer4 increments from 00h until it matches pr4 and then resets to 00h on the next increment cycle. the pr4 register is initialized to ffh upon reset. 15.3 output of tmr4 the output of tmr4 (before the postscaler) is used only as a pwm time base for the eccp modules. it is not used as a baud rate clock for the mssp modules as is the timer2 output. figure 15-1: timer4 block diagram table 15-1: registers associated with timer4 as a timer/counter name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 81 ipr3 ssp2ip bcl2ip rc2ip tx2ip tmr4ip ctmuip tmr3gip rtccip 83 pir3 ssp2if bcl2if rc2if tx2if tmr4if ctmuif tmr3gif rtccif 83 pie3 ssp2ie bcl2ie rc2ie tx2ie tmr4ie ctmuie tmr3gie rtccie 83 tmr4 timer4 register 84 t4con ? t4outps3 t4outps2 t4outps1 t4outps0 tmr4on t4ckps1 t4ckps0 84 pr4 timer4 period register 84 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the timer4 module. comparator tmr4 output tmr4 postscaler prescaler pr4 2 f osc /4 1:1 to 1:16 1:1, 1:4, 1:16 4 t4outps<3:0> t4ckps<1:0> set tmr4if internal data bus 8 reset tmr4/pr4 8 8 (to pwm) match
? 2009 microchip technology inc. preliminary ds39931b-page 217 pic18f46j50 family 16.0 real-time clock and calendar (rtcc) the key features of the real-time clock and calendar (rtcc) module are: ? time: hours, minutes and seconds ? 24-hour format (military time) ? calendar: weekday, date, month and year ? alarm configurable ? year range: 2000 to 2099 ? leap year correction ? bcd format for compact firmware ? optimized for low-power operation ? user calibration with auto-adjust ? calibration range: 2.64 seconds error per month ? requirements: external 32.768 khz clock crystal ? alarm pulse or seconds clock output on rtcc pin the rtcc module is intended for applications where accurate time must be maintained for an extended period with minimum to no intervention from the cpu. the module is optimized for low-power usage in order to provide extended battery life while keeping track of time. the module is a 100-year clock and calendar with auto- matic leap year detection. the range of the clock is from 00:00:00 (midnight) on january 1, 2000 to 23:59:59 on december 31, 2099. hours are measured in 24-hour (military time) format. the clock provides a granularity of one second with half-second visibility to the user. figure 16-1: rtcc block diagram rtcc prescalers rtcc timer comparator compare registers repeat counter year mthdy wkdyhr minsec almthdy alwdhr alminsec with masks rtcc interrupt logic rtccfg alrmrpt alarm event 0.5s rtcc clock domain alarm pulse rtcc interrupt cpu clock domain rtcval alrmval rtcc pin rtcoe 32.768 khz input from timer1 oscillator internal rc
pic18f46j50 family ds39931b-page 218 preliminary ? 2009 microchip technology inc. 16.1 rtcc module registers the rtcc module registers are divided into following categories: rtcc control registers ? rtccfg ? rtccal ? padcfg1 ?alrmcfg ?alrmrpt rtcc value registers ? rtcvalh and rtcvall ? can access the following registers - year -month -day - weekday -hour - minute - second alarm value registers ? alrmvalh and alrmvall ? can access the following registers: - alrmmnth -alrmday -alrmwd -alrmhr - alrmmin - alrmsec note: the rtcvalh and rtcvall registers can be accessed through rtcrpt<1:0>. alrmvalh and alrmvall can be accessed through alrmptr<1:0>.
? 2009 microchip technology inc. preliminary ds39931b-page 219 pic18f46j50 family 16.1.1 rtcc control registers register 16-1: rtccfg: rtcc configuration register (banked f3fh) (1) r/w-0 u-0 r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 rtcen (2) ? rtcwren rtcsync halfsec (3) rtcoe rtcptr1 rtcptr0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rtcen: rtcc enable bit (2) 1 = rtcc module is enabled 0 = rtcc module is disabled bit 6 unimplemented: read as ? 0 ? bit 5 rtcwren: rtcc value registers write enable bit 1 = rtcvalh and rtcvall registers can be written to by the user 0 = rtcvalh and rtcvall registers are locked out from being written to by the user bit 4 rtcsync: rtcc value registers read synchronization bit 1 = rtcvalh, rtcvall and alcfgrpt registers can change while reading due to a rollover ripple resulting in an invalid data read if the register is read twice and results in the same data, the data can be assumed to be valid. 0 = rtcvalh, rtcvall or alcfgrpt registers can be read without concern over a rollover ripple bit 3 halfsec: half-second status bit (3) 1 = second half period of a second 0 = first half period of a second bit 2 rtcoe: rtcc output enable bit 1 = rtcc clock output enabled 0 = rtcc clock output disabled bit 1-0 rtcptr<1:0>: rtcc value register window pointer bits points to the corresponding rtcc value registers when reading the rtcvalh and rtcvall registers; the rtcptr<1:0> value decrements on every read or write of rtcvalh until it reaches ? 00 ?. rtcval <1 5: 8>: 00 = minutes 01 = weekday 10 = month 11 = reserved rtcval <7 : 0>: 00 = seconds 01 = hours 10 = day 11 = year note 1: the rtccfg register is only affected by a por. 2: a write to the rtcen bit is only allowed when rtcwren = 1 . 3: this bit is read-only. it is cleared to ? 0 ? on a write to the lower half of the minsec register.
pic18f46j50 family ds39931b-page 220 preliminary ? 2009 microchip technology inc. register 16-2: rtccal: rtcc calibration register (banked f3eh) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 cal7 cal6 cal5 cal4 cal3 cal2 cal1 cal0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 cal<7:0>: rtc drift calibration bits 01111111 = maximum positive adjustment; adds 508 rtc clock pulses every minute . . . 00000001 = minimum positive adjustment; adds four rtc clock pulses every minute 00000000 = no adjustment 11111111 = minimum negative adjustment; subtracts four rtc clock pulses every minute . . . 10000000 = maximum negative adjustment; subtracts 512 rtc clock pulses every minute register 16-3: padcfg1: pad conf iguration register (banked f3ch) u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 ? ? ? ? ? rtsecsel1 (1) rtsecsel0 (1) pmpttl bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-3 unimplemented: read as ? 0 ? bit 2-1 rtsecsel<1:0>: rtcc seconds clock output select bits (1) 11 = reserved. do not use 10 = rtcc source clock is selected for the rtcc pin (pin can be intrc or t1osc, depending on the rtcosc (config3l<1>) setting) 01 = rtcc seconds clock is selected for the rtcc pin 00 = rtcc alarm pulse is selected for the rtcc pin bit 0 pmpttl: pmp module ttl input buffer select bit 1 = pmp module uses ttl input buffers 0 = pmp module uses schmitt input buffers note 1: to enable the actual rtcc output, the rtcoe (rtccfg<2>) bit must be set.
? 2009 microchip technology inc. preliminary ds39931b-page 221 pic18f46j50 family register 16-4: alrmcfg: alarm configuration re gister (access f91h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 alrmen chime amask3 amask2 amask1 amask0 alrmptr1 alrmptr0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 alrmen: alarm enable bit 1 = alarm is enabled (cleared automatically after an alarm event whenever arpt<7:0> = 0000 0000 and chime = 0 ) 0 = alarm is disabled bit 6 chime: chime enable bit 1 = chime is enabled; arpt<7:0> bits are allowed to roll over from 00h to ffh 0 = chime is disabled; arpt<7:0> bits stop once they reach 00h bit 5-2 amask<3:0>: alarm mask configuration bits 0000 = every half second 0001 = every second 0010 = every 10 seconds 0011 = every minute 0100 = every 10 minutes 0101 = every hour 0110 = once a day 0111 = once a week 1000 = once a month 1001 = once a year (except when configured for february 29 th , once every four years) 101x = reserved ? do not use 11xx = reserved ? do not use bit 1-0 alrmptr<1:0>: alarm value register window pointer bits points to the corresponding alarm value registers when reading the alrmvalh and alrmvall registers. the alrmptr<1:0> value decrements on every read or write of alrmvalh until it reaches ? 00 ?. alrmval <1 5: 8>: 00 = alrmmin 01 =alrmwd 10 =alrmmnth 11 = unimplemented alrmval <7 : 0>: 00 = alrmsec 01 =alrmhr 10 =alrmday 11 = unimplemented
pic18f46j50 family ds39931b-page 222 preliminary ? 2009 microchip technology inc. register 16-5: alrmrpt: alarm ca libration register (access f90h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 arpt7 arpt6 arpt5 arpt4 arpt3 arpt2 arpt1 arpt0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 arpt<7:0>: alarm repeat counter value bits 11111111 = alarm will repeat 255 more times . . . 00000000 = alarm will not repeat the counter decrements on any alarm event. the counter is prevented from rolling over from 00h to ffh unless chime = 1 .
? 2009 microchip technology inc. preliminary ds39931b-page 223 pic18f46j50 family 16.1.2 rtcvalh and rtcvall register mappings register 16-6: reserved register (access f99h, ptr 11b) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 unimplemented: read as ? 0 ? register 16-7: year: year value register (access f98h, ptr 11b) (1) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x yrten3 yrten2 yrten1 yrten0 yrone3 yrone2 yrone1 yrone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 yrten<3:0>: binary coded decimal value of year?s tens digit bits contains a value from 0 to 9. bit 3-0 yrone<3:0>: binary coded decimal value of year?s ones digit bits contains a value from 0 to 9. note 1: a write to the year register is only allowed when rtcwren = 1 . register 16-8: month: month value register (access f99h, ptr 10b) (1) u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x ? ? ? mthten0 mthone3 mthone2 mthone1 mthone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 mthten0: binary coded decimal value of month?s tens digit bit contains a value of 0 or 1. bit 3-0 mthone<3:0>: binary coded decimal value of month?s ones digit bits contains a value from 0 to 9. note 1: a write to this register is only allowed when rtcwren = 1 .
pic18f46j50 family ds39931b-page 224 preliminary ? 2009 microchip technology inc. register 16-9: day: day value register (access f98h, ptr 10b) (1) u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? ? dayten1 dayten0 dayone3 dayone2 dayone1 dayone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-4 dayten<1:0>: binary coded decimal value of day?s tens digit bits contains a value from 0 to 3. bit 3-0 dayone<3:0>: binary coded decimal value of day?s ones digit bits contains a value from 0 to 9. note 1: a write to this register is only allowed when rtcwren = 1 . register 16-10: wkdy: weekday valu e register (access f99h, ptr 01b) (1) u-0 u-0 u-0 u-0 u-0 r/w-x r/w-x r/w-x ? ? ? ? ? wday2 wday1 wday0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-3 unimplemented: read as ? 0 ? bit 2-0 wday<2:0>: binary coded decimal value of weekday digit bits contains a value from 0 to 6. note 1: a write to this register is only allowed when rtcwren = 1 .
? 2009 microchip technology inc. preliminary ds39931b-page 225 pic18f46j50 family register 16-11: hours: hours value register (access f98h, ptr 01b) (1) u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? ? hrten1 hrten0 hrone3 hrone2 hrone1 hrone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-4 hrten<1:0>: binary coded decimal value of hour?s tens digit bits contains a value from 0 to 2. bit 3-0 hrone<3:0>: binary coded decimal value of hour?s ones digit bits contains a value from 0 to 9. note 1: a write to this register is only allowed when rtcwren = 1 . register 16-12: minutes: minutes value register (access f99h, ptr 00b) u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? minten2 minten1 minten0 minone3 minone2 minone1 minone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-4 minten<2:0>: binary coded decimal value of minute?s tens digit bits contains a value from 0 to 5. bit 3-0 minone<3:0>: binary coded decimal value of minute?s ones digit bits contains a value from 0 to 9. register 16-13: seconds: seconds valu e register (access f98h, ptr 00b) u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? secten2 secten1 secten0 secone3 secone2 secone1 secone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-4 secten<2:0>: binary coded decimal value of second?s tens digit bits contains a value from 0 to 5. bit 3-0 secone<3:0>: binary coded decimal value of second?s ones digit bits contains a value from 0 to 9.
pic18f46j50 family ds39931b-page 226 preliminary ? 2009 microchip technology inc. 16.1.3 alrmvalh and alrmvall register mappings register 16-14: alrmmnth: alarm month value register (access f8fh, ptr 10b) (1) u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x ? ? ? mthten0 mthone3 mthone2 mthone1 mthone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 mthten0: binary coded decimal value of month?s tens digit bit contains a value of 0 or 1. bit 3-0 mthone<3:0>: binary coded decimal value of month?s ones digit bits contains a value from 0 to 9. note 1: a write to this register is only allowed when rtcwren = 1 . register 16-15: alrmday: alarm day value register (access f8eh, ptr 10b) (1) u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? ? dayten1 dayten0 dayone3 dayone2 dayone1 dayone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-4 dayten<1:0>: binary coded decimal value of day?s tens digit bits contains a value from 0 to 3. bit 3-0 dayone<3:0>: binary coded decimal value of day?s ones digit bits contains a value from 0 to 9. note 1: a write to this register is only allowed when rtcwren = 1 .
? 2009 microchip technology inc. preliminary ds39931b-page 227 pic18f46j50 family register 16-16: alrmwd: alarm weekday value register (access f8fh, ptr 01b) (1) u-0 u-0 u-0 u-0 u-0 r/w-x r/w-x r/w-x ? ? ? ? ? wday2 wday1 wday0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-3 unimplemented: read as ? 0 ? bit 2-0 wday<2:0>: binary coded decimal value of weekday digit bits contains a value from 0 to 6. note 1: a write to this register is only allowed when rtcwren = 1 . register 16-17: alrmhr: alarm hours va lue register (access f8eh, ptr 01b) (1) u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? ? hrten1 hrten0 hrone3 hrone2 hrone1 hrone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-4 hrten<1:0>: binary coded decimal value of hour?s tens digit bits contains a value from 0 to 2. bit 3-0 hrone3:hrone0: binary coded decimal value of hour?s ones digit bits contains a value from 0 to 9. note 1: a write to this register is only allowed when rtcwren = 1 .
pic18f46j50 family ds39931b-page 228 preliminary ? 2009 microchip technology inc. register 16-18: alrmmin: alarm minutes value register (access f8fh, ptr 00b) u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? minten2 minten1 minten0 minone3 minone2 minone1 minone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-4 minten<2:0>: binary coded decimal value of minute?s tens digit bits contains a value from 0 to 5. bit 3-0 minone<3:0>: binary coded decimal value of minute?s ones digit bits contains a value from 0 to 9. register 16-19: alrmsec: alarm seconds value register (access f8eh, ptr 00b) u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? secten2 secten1 secten0 secone3 secone2 secone1 secone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-4 secten<2:0>: binary coded decimal value of second?s tens digit bits contains a value from 0 to 5. bit 3-0 secone<3:0>: binary coded decimal value of second?s ones digit bits contains a value from 0 to 9.
? 2009 microchip technology inc. preliminary ds39931b-page 229 pic18f46j50 family 16.1.4 rtcen bit write an attempt to write to the rtcen bit while rtcwren = 0 will be ignored. rtcwren must be set before a write to rtcen can take place. like the rtcen bit, the rtcvalh and rtcvall registers can only be written to when rtcwren = 1 . a write to these registers, while rtcwren = 0 , will be ignored. 16.2 operation 16.2.1 register interface the register interface for the rtcc and alarm values is implemented using the binary coded decimal (bcd) format. this simplifies the firmware, when using the module, as each of the digits is contained within its own 4-bit value (see figure 16-2 and figure 16-3). figure 16-2: timer digit format figure 16-3: alarm digit format 0-6 0-9 0-9 0-3 0-9 0-9 0-9 0-9 0-2 0-5 0-5 0/1 day of week year day hours (24-hour format) minutes seconds 1/2 second bit 0-1 0-9 month (binary format) 0-6 0-3 0-9 0-9 0-9 0-9 0-2 0-5 0-5 day of week day hours (24-hour format) minutes seconds 0-1 0-9 month
pic18f46j50 family ds39931b-page 230 preliminary ? 2009 microchip technology inc. 16.2.2 clock source as mentioned earlier, the rtcc module is intended to be clocked by an external real-time clock crystal oscillating at 32.768 khz, but also can be clocked by the intrc. the rtcc clock selection is decided by the rtcosc bit (config3l<1>). calibration of the crystal can be done through this module to yield an error of 3 seconds or less per month. (for further details, see section 16.2.9 ?calibration? .) figure 16-4: clock source multiplexing 16.2.2.1 real-time clock enable the rtcc module can be clocked by an external, 32.768 khz crystal (timer1 oscillator or t1cki input) or the intrc oscillator, which can be selected in config3l<1>. if the timer1 oscillator will be used as the clock source for the rtcc, make sure to enable it by setting t1con<3> (t1oscen). the selected rtc clock can be brought out to the rtcc pin by the rtsecsel<1:0> bits in the padcfg register. 16.2.3 digit carry rules this section explains which timer values are affected when there is a rollover. ? time of day: from 23:59:59 to 00:00:00 with a carry to the day field ? month: from 12/31 to 01/01 with a carry to the year field ? day of week: from 6 to 0 with no carry (see table 16-1) ? year carry: from 99 to 00; this also surpasses the use of the rtcc for the day to month rollover schedule, see table 16-2. considering that the following values are in bcd format, the carry to the upper bcd digit will occur at a count of 10 and not at 16 (seconds, minutes, hours, weekday, days and months). table 16-1: day of week schedule note 1: writing to the lower half of the minsec register resets all counters, allowing fraction of a second synchronization; clock prescaler is held in reset when rtcen = 0 . 32.768 khz xtal 1:16384 half second (1) half-second clock one-second clock year month day day of week second hour:minute clock prescaler (1) from t1osc internal rc config 3l<1> day of week sunday 0 monday 1 tuesday 2 wednesday 3 thursday 4 friday 5 saturday 6
? 2009 microchip technology inc. preliminary ds39931b-page 231 pic18f46j50 family table 16-2: day to month rollover schedule 16.2.4 leap year since the year range on the rtcc module is 2000 to 2099, the leap year calculation is determined by any year divisible by ?4? in the above range. only february is effected in a leap year. february will have 29 days in a leap year and 28 days in any other year. 16.2.5 general functionality all timer registers containing a time value of seconds or greater are writable. the us er configures the time by writing the required year, month, day, hour, minutes and seconds to the timer registers, via register pointers (see section 16.2.8 ?register mapping? ). the timer uses the newly written values and proceeds with the count from the required starting point. the rtcc is enabled by setting the rtcen bit (rtccfgl<7>). if enabled, while adjusting these registers, the timer still continues to increment. however, any time the minsec register is written to, both of the timer prescalers are reset to ? 0 ?. this allows fraction of a second synchronization. the timer registers are updated in the same cycle as the write instruction?s execution by the cpu. the user must ensure that when rtcen = 1 , the updated registers will not be incremented at the same time. this can be accomplished in several ways: ? by checking the rtcsync bit (rtccfg<4>) ? by checking the preceding digits from which a carry can occur ? by updating the registers immediately following the seconds pulse (or alarm interrupt) the user has visibility to the half-second field of the counter. this value is read-only and can be reset only by writing to the lower half of the seconds register. 16.2.6 safety window for register reads and writes the rtcsync bit indicates a time window during which the rtcc clock domain registers can be safely read and written without concern about a rollover. when rtcsync = 0 , the registers can be safely accessed by the cpu. whether rtcsync = 1 or 0 , the user should employ a firmware solution to ensure that the data read did not fall on a rollover boundary, resulting in an invalid or partial read. this firmware solution would consist of reading each register twice and then comparing the two values. if the two values matched, then, a rollover did not occur. 16.2.7 write lock in order to perform a write to any of the rtcc timer registers, the rtcwren bit (rtccfg<5>) must be set. to avoid accidental writes to the rtcc timer register, it is recommended that the rtcwren bit (rtccfg<5>) be kept clear at any time other than while writing to. for the rtcwren bit to be set, there is only one instruction cycle time window allowed between the 55h/aa sequence and the setting of rtcwren. for that reason, it is recommended that users follow the code example in example 16-1. example 16-1: setting the rtcwren bit 16.2.8 register mapping to limit the register interface, the rtcc timer and alarm timer registers are accessed through corresponding register pointers. the rtcc value reg- ister window (rtcvalh<15:8> and rtcvall<7:0>) uses the rtcptr bits (rtccfg<1:0>) to select the required timer register pair. by reading or writing to the rtcvalh register, the rtcc pointer value (rtcptr<1:0>) decrements by 1 until it reaches ? 00 ?. once it reaches ? 00 ?, the minutes and seconds value will be accessible through rtcvalh and rtcvall until the pointer value is manually changed. month maximum day field 01 (january) 31 02 (february) 28 or 29 (1) 03 (march) 31 04 (april) 30 05 (may) 31 06 (june) 30 07 (july) 31 08 (august) 31 09 (september) 30 10 (october) 31 11 (november) 30 12 (december) 31 note 1: see section 16.2.4 ?leap year? . movlb 0x0f ;rtccfg is banked bcf intcon, gie ;disable interrupts movlw 0x55 movwf eecon2 movlw 0xaa movwf eecon2 bsf rtccfg,rtcwren
pic18f46j50 family ds39931b-page 232 preliminary ? 2009 microchip technology inc. table 16-3: rtcvalh and rtcvall register mapping the alarm value register window (alrmvalh and alrmvall) uses the alrmptr bits (alrmcfg<1:0>) to select the desired alarm register pair. by reading or writing to the alrmvalh register, the alarm pointer value, alrmptr<1:0>, decrements by 1 until it reaches ? 00 ?. once it reaches ? 00 ?, the alrmmin and alrmsec value will be accessible through alrmvalh and alrmvall until the pointer value is manually changed. table 16-4: alrmval register mapping 16.2.9 calibration the real-time crystal input can be calibrated using the periodic auto-adjust feature. when properly calibrated, the rtcc can provide an error of less than three seconds per month. to perform this calibration, find the number of error clock pulses and store the value in the lower half of the rtccal register. the 8-bit, signed value ? loaded into rtccal ? is multiplied by ?4? and will either be added or subtracted from the rtcc timer, once every minute. to calibrate the rtcc module: 1. use another timer resource on the device to find the error of the 32.768 khz crystal. 2. convert the number of error clock pulses per minute (see equation 16-1). equation 16-1: converting error clock pulses ? if the oscillator is faster than ideal (negative result from step 2), the rcfgcall register value needs to be negative. this causes the specified number of clock pulses to be subtracted from the timer counter once every minute. ? if the oscillator is slower than ideal (positive result from step 2), the rcfgcall register value needs to be positive. this causes the specified number of clock pulses to be added to the timer counter once every minute. 3. load the rtccal register with the correct value. writes to the rtccal register should occur only when the timer is turned off, or immediately after the rising edge of the seconds pulse. rtcptr<1:0> rtcc value register window rtcval<15:8> rtcval<7:0> 00 minutes seconds 01 weekday hours 10 month day 11 ? year alrmptr<1:0> alarm value register window alrmval<15:8> alrmval<7:0> 00 alrmmin alrmsec 01 alrmwd alrmhr 10 alrmmnth alrmday 11 ?? note: in determining the crystal?s error value, it is the user?s responsibility to include the crystal?s initial error from drift due to temperature or crystal aging. (ideal frequency (32,758) ? measured frequency) * 60 = error clocks per minute
? 2009 microchip technology inc. preliminary ds39931b-page 233 pic18f46j50 family 16.3 alarm the alarm features and characteristics are: ? configurable from half a second to one year ? enabled using the alrmen bit (alrmcfg<7>, register 16-4) ? offers one-time and repeat alarm options 16.3.1 configuring the alarm the alarm feature is enabled using the alrmen bit. this bit is cleared when an alarm is issued. the bit will not be cleared if the chime bit = 1 or if alrmrpt 0 . the interval selection of the alarm is configured through the alrmcfg bits (amask<3:0>). (see figure 16-5.) these bits determine which and how many digits of the alarm must match the clock value for the alarm to occur. the alarm can also be configured to repeat based on a preconfigured interval. the number of times this occurs after the alarm is enabled is stored in the alrmrpt register. figure 16-5: alarm mask settings note: while the alarm is enabled (alrmen = 1 ), changing any of the registers ? other than the rtccal, alrmcfg and alrmrpt registers and the chime bit ? can result in a false alarm event leading to a false alarm interrupt. to avoid this, only change the timer and alarm values while the alarm is disabled (alrmen = 0 ). it is recom- mended that the alrmcfg and alrmrpt registers and chime bit be changed when rtcsync = 0 . note 1: annually, except when configured for february 29. s ss mss mm s s hh mm ss dhhmmss dd hh mm ss mm d d h h mm s s day of the week month day hours minutes seconds alarm mask setting amask3:amask0 0000 ? every half second 0001 ? every second 0010 ? every 10 seconds 0011 ? every minute 0100 ? every 10 minutes 0101 ? every hour 0110 ? every day 0111 ? every week 1000 ? every month 1001 ? every year (1)
pic18f46j50 family ds39931b-page 234 preliminary ? 2009 microchip technology inc. when alrmcfg = 00 and the chime bit = 0 (alrmcfg<6>), the repeat function is disabled and only a single alarm will occur. the alarm can be repeated up to 255 times by loading the alrmrpt register with ffh. after each alarm is issued, the alrmrpt register is decremented by one. once the register has reached ? 00 ?, the alarm will be issued one last time. after the alarm is issued a last time, the alrmen bit is cleared automatically and the alarm turned off. indefinite repetition of the alarm can occur if the chime bit = 1 . when chime = 1 , the alarm is not disabled when the alrmrpt register reaches ? 00 ?, but it rolls over to ff and continues counting indefinitely. 16.3.2 alarm interrupt at every alarm event, an interrupt is generated. addi- tionally, an alarm pulse output is provided that operates at half the frequency of the alarm. the alarm pulse output is completely synchronous with the rtcc clock and can be used as a trigger clock to other peripherals. this output is available on the rtcc pin. the output pulse is a clock with a 50% duty cycle and a frequency half that of the alarm event (see figure 16-6). the rtcc pin also can output the seconds clock. the user can select between the alarm pulse, generated by the rtcc module, or the seconds clock output. the rtsecsel (padcfg1<2:1>) bits select between these two outputs: ? alarm pulse ? rtsecsel<2:1> = 00 ? seconds clock ? rtsecsel<2:1> = 0 figure 16-6: timer pulse generation 16.4 low-power modes the timer and alarm can optionally continue to operate while in sleep, idle and even deep sleep mode. an alarm event can be used to wake-up the microcontroller from any of these low-power modes. 16.5 reset 16.5.1 device reset when a device reset occurs, the alcfgrpt register is forced to its reset state causing the alarm to be dis- abled (if enabled prior to the reset). if the rtcc was enabled, it will continue to operate when a basic device reset occurs. 16.5.2 power-on reset (por) the rtccfg and alrmrpt registers are reset only on a por. once the device exits the por state, the clock registers should be reloaded with the desired values. the timer prescaler values can be reset only by writing to the seconds register. no device reset can affect the prescalers. rtcen bit alrmen bit rtcc alarm event rtcc pin
? 2009 microchip technology inc. preliminary ds39931b-page 235 pic18f46j50 family 16.6 register maps table 16-5, table 16-6 and table 16-7 summarize the registers associated with the rtcc module. table 16-5: rtcc control registers file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets rtccfg rtcen ? rtcwren rtcsync halfsec rtcoe rtcptr1 rtcptr0 0000 rtccal cal7 cal6 cal5 cal4 cal3 cal2 cal1 cal0 0000 padcfg1 ? ? ? ? ? rtsecsel1 rtsecsel0 pmpttl 0000 alrmcfg alrmen chime amask3 amask2 amask1 amask0 alrmptr1 alrmptr0 0000 alrmrpt arpt7 arpt6 arpt5 arpt4 arpt3 arpt2 arpt1 arpt0 0000 pir3 ssp2if bcl2if rc2if tx2if tmr4if ctmuif tmr3gif rtcccif 0000 pie3 ssp2ie bcl2ie rc2ie tx2ie tmr4ie ctmuie tmr3gie rtcccie 0000 ipr3 ssp2ip bcl2ip rc2ip tx2ip tmr4ip ctmuip tmr3gip rtcccip 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal for 44-pin devices. table 16-6: rtcc value registers file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets rtcvalh rtcc value register window high byte, based on rtcptr<1:0> xxxx rtcvall rtcc value register window low byte, based on rtcptr<1:0> xxxx rtccfg rtcen ? rtcwren rtcsync halfsec rtcoe rtcptr1 rtcptr0 0000 alrmcfg alrmen chime amask3 amask2 amask1 amask0 alrmptr1 alrmptr0 0000 alrmvalh alarm value register window high byte, based on alrmptr<1:0> xxxx alrmvall alarm value register window low byte, based on alrmptr<1:0> xxxx legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal for 44-pin devices. table 16-7: alarm value registers file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets alrmrpt arpt7 arpt6 arpt5 arpt4 arpt3 arpt2 arpt1 arpt0 0000 alrmvalh alarm value register window high byte, based on alrmptr<1:0> xxxx alrmvall alarm value register window low byte, based on alrmptr<1:0> xxxx rtccal cal7 cal6 cal5 cal4 cal3 cal2 cal1 cal0 0000 rtcvalh rtcc value register window high byte, based on rtcptr<1:0> xxxx rtcvall rtcc value register window low byte, based on rtcptr<1:0> xxxx legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal for 44-pin devices.
pic18f46j50 family ds39931b-page 236 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39931b-page 237 pic18f46j50 family 17.0 enhanced capture/compare/pwm (eccp) module pic18f46j50 family devices have two enhanced capture/compare/pwm (eccp) modules: eccp1 and eccp2. these modules contain a 16-bit register, which can operate as a 16-bit capture register, a 16-bit compare register or a pwm master/slave duty cycle register. these eccp modules are upward compatible with ccp eccp1 and eccp2 are implemented as standard ccp modules with enhanced pwm capabilities. these include: ? provision for two or four output channels ? output steering modes ? programmable polarity ? programmable dead-band control ? automatic shutdown and restart the enhanced features are discussed in detail in section 17.5 ?pwm (enhanced mode)? . note: register and bit names referencing one of the two eccp modules substitute an ?x? for the module number. for example, regis- ters ccp 1 con and ccp 2 con, which have the same definitions, are called ccp x con. figures and diagrams use eccp1-based names, but those names also apply to eccp2, with a ?2? replacing the illustration name?s ?1?. when writing firmware, the ?x? in register and bit names must be replaced with the appropriate module number. note: pxa, pxb, pxc and pxd are associated with the remappable pins (rpn).
pic18f46j50 family ds39931b-page 238 preliminary ? 2009 microchip technology inc. register 17-1: ccpxcon: enhanced capture/compare/pwm x control register (access fbah, fb4h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 pxm1 pxm0 dcxb1 dcxb0 ccpxm3 ccpxm2 ccpxm1 ccpxm0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 pxm<1:0>: enhanced pwm output configuration bits if ccpxm <3 : 2> = 00 , 01 , 10 : xx = pxa assigned as capture/compare input/output; pxb, pxc and pxd assigned as port pins if ccpxm <3 : 2> = 11 : 00 = single output: pxa, pxb, pxc and pxd controlled by steering (see section 17.5.7 ?pulse steering mode? ) 01 = full-bridge output forward: pxd modulated; pxa active; pxb, pxc inactive 10 = half-bridge output: pxa, pxb modulated with dead-band control; pxc and pxd assigned as port pins 11 = full-bridge output reverse: pxb modulated; pxc active; pxa and pxd inactive bit 5-4 dcxb<1:0> : pwm duty cycle bit 1 and bit 0 capture mode: unused. compare mode: unused. pwm mode: these bits are the two lsbs of the 10-bit pwm duty cycle. the eight msbs of the duty cycle are found in ccprxl. bit 3-0 ccpxm<3:0> : eccpx mode select bits 0000 = capture/compare/pwm off (resets eccpx module) 0001 = reserved 0010 = compare mode, toggle output on match 0011 = capture mode 0100 = capture mode, every falling edge 0101 = capture mode, every rising edge 0110 = capture mode, every 4 th rising edge 0111 = capture mode, every 16 th rising edge 1000 = compare mode, initialize eccpx pin low, set output on compare match (set ccpxif) 1001 = compare mode, initialize eccpx pin high, clear output on compare match (set ccpxif) 1010 = compare mode, generate software interrupt only, eccpx pin reverts to i/o state 1011 = compare mode, trigger special event (eccpx resets tmr1 or tmr3, starts a/d conversion, sets ccxif bit) 1100 = pwm mode; pxa and pxc active-high; pxb and pxd active-high 1101 = pwm mode; pxa and pxc active-high; pxb and pxd active-low 1110 = pwm mode; pxa and pxc active-low; pxb and pxd active-high 1111 = pwm mode; pxa and pxc active-low; pxb and pxd active-low
? 2009 microchip technology inc. preliminary ds39931b-page 239 pic18f46j50 family in addition to the expanded range of modes available through the ccpxcon and eccpxas registers, the eccp modules have two additional registers associated with enhanced pwm operation and auto-shutdown features. they are: ? eccpxdel (enhanced pwm control) ? pstrxcon (pulse steering control) 17.1 eccp outputs and configuration the enhanced ccp module may have up to four pwm outputs, depending on the selected operating mode. these outputs, designated pxa through pxd, are routed through the peripheral pin select (pps) module. therefore, individual functions may be mapped to any of the remappable i/o pins, rpn. the outputs that are active depend on the eccp operating mode selected. the pin assignments are summarized in table 17-4. to configure the i/o pins as pwm outputs, the proper pwm mode must be selected by setting the pxm<1:0> and ccpxm<3:0> bits. the appropriate tris direction bits for the port pins must also be set as outputs and the output functions need to be assigned to i/o pins in the pps module. (for details on configuring the module, see section 9.7 ?peripheral pin select (pps)? .) 17.1.1 eccp module and timer resources the eccp modules utilize timers 1, 2, 3 or 4, depending on the mode selected. timer1 and timer3 are available to modules in capture or compare modes, while timer2 and timer4 are available for modules in pwm mode. table 17-1: eccp mode ? timer resource the assignment of a particular timer to a module is determined by the timer-to-eccp enable bits in the tclkcon register (register 12-3). the interactions between the two modules are depicted in figure 17-1. capture operations are designed to be used when the timer is configured for synchronous counter mode. capture operations may not work as expected if the associated timer is configured for asynchronous counter mode. eccp mode timer resource capture timer1 or timer3 compare timer1 or timer3 pwm timer2 or timer4
pic18f46j50 family ds39931b-page 240 preliminary ? 2009 microchip technology inc. 17.2 capture mode in capture mode, the ccprxh:ccprxl register pair captures the 16-bit value of the tmr1 or tmr3 registers when an event occurs on the corresponding eccpx pin. an event is defined as one of the following: ? every falling edge ? every rising edge ?every 4 th rising edge ?every 16 th rising edge the event is selected by the mode select bits, ccpxm<3:0>, of the ccpxcon register. when a capture is made, the interrupt request flag bit, ccpxif, is set; it must be cleared by software. if another capture occurs before the value in register ccprx is read, the old captured value is overwritten by the new captured value. 17.2.1 eccp pin configuration in capture mode, the appropriate eccpx pin should be configured as an input by setting the corresponding tris direction bit. additionally, the eccpx input function needs to be assigned to an i/o pin through the peripheral pin select module. for details on setting up the remappable pins, see section 9.7 ?peripheral pin select (pps)? . 17.2.2 timer1/timer3 mode selection the timers that are to be used with the capture feature (timer1 and/or timer3) must be running in timer mode or synchronized counter mode. in asynchronous counter mode, the capture operation may not work. the timer to be used with each eccp module is selected in the tclkcon register (register 12-3). 17.2.3 software interrupt when the capture mode is changed, a false capture interrupt may be generated. the user should keep the ccpxie interrupt enable bit clear to avoid false interrupts. the interrupt flag bit, ccpxif, should also be cleared following any such change in operating mode. 17.2.4 eccp prescaler there are four prescaler settings in capture mode; they are specified as part of the operating mode selected by the mode select bits (ccpxm<3:0>). whenever the eccp module is turned off, or capture mode is dis- abled, the prescaler counter is cleared. this means that any reset will clear the prescaler counter. switching from one capture prescaler to another may generate an interrupt. also, the prescaler counter will not be cleared; therefore, the first capture may be from a non-zero prescaler. example 17-1 provides the recommended method for switching between capture prescalers. this example also clears the prescaler counter and will not generate the ?false? interrupt. example 17-1: changing between capture prescalers figure 17-1: capture mode operation block diagram note: if the eccpx pin is configured as an out- put, a write to the port can cause a capture condition. clrf ccp1con ; turn ccp module off movlw new_capt_ps ; load wreg with the ; new prescaler mode ; value and ccp on movwf ccp1con ; load ccp1con with ; this value ccpr1h ccpr1l tmr1h tmr1l set ccp1if tmr3 enable q1:q4 ccp1con<3:0> eccp1 pin prescaler 1, 4, 16 and edge detect tmr1 enable t3ccp1 t3ccp1 tmr3h tmr3l 4 4
? 2009 microchip technology inc. preliminary ds39931b-page 241 pic18f46j50 family 17.3 compare mode in compare mode, the 16-bit ccprx register value is constantly compared against either the tmr1 or tmr3 register pair value. when a match occurs, the eccpx pin can be: ? driven high ?driven low ? toggled (high-to-low or low-to-high) ? remain unchanged (that is, reflects the state of the i/o latch) the action on the pin is based on the value of the mode select bits (ccpxm<3:0>). at the same time, the interrupt flag bit, ccpxif, is set. 17.3.1 eccp pin configuration users must configure the eccpx pin as an output by clearing the appropriate tris bit. 17.3.2 timer1/timer3 mode selection timer1 and/or timer3 must be running in timer mode or synchronized counter mode if the eccp module is using the compare feature. in asynchronous counter mode, the compare operation will not work reliably. 17.3.3 software interrupt mode when the generate software interrupt mode is chosen (ccpxm<3:0> = 1010 ), the eccpx pin is not affected; only the ccpxif interrupt flag is affected. 17.3.4 special event trigger the eccp module is equipped with a special event trigger. this is an internal hardware signal generated in compare mode to trigger actions by other modules. the special event trigger is enabled by selecting the compare special event trigger mode (ccpxm<3:0> = 1011 ). the special event trigger resets the timer register pair for whichever timer resource is currently assigned as the module?s time base. this allows the ccprx registers to serve as a programmable period register for either timer. the special event trigger can also start an a/d conver- sion. in order to do this, the a/d converter must already be enabled. figure 17-2: compare mode operation block diagram note: clearing the ccpxcon register will force the eccpx compare output latch (depend- ing on device configuration) to the default low level. this is not the portx i/o data latch. tmr1h tmr1l tmr3h tmr3l ccpr1h ccpr1l comparator t3ccp 1 set ccp1if 1 0 q s r output logic special event trigger eccp1 pin tris ccp1con<3:0> output enable 4 (timer1/timer3 reset, a/d trigger) compare match
pic18f46j50 family ds39931b-page 242 preliminary ? 2009 microchip technology inc. 17.4 pwm mode in pulse-width modulation (pwm) mode, the ccpx pin produces up to a 10-bit resolution pwm output. figure 17-3 shows a simplified block diagram of the ccp module in pwm mode. for a step-by-step procedure on how to set up a ccp module for pwm operation, see section 17.4.3. figure 17-3: simplified pwm block diagram a pwm output (figure 17-4) has a time base (period) and a time that the output stays high (duty cycle). the frequency of the pwm is the inverse of the period (1/period). figure 17-4: pwm output 17.4.1 pwm period the pwm period is specified by writing to the pr2 (pr4) register. the pwm period can be calculated using equation 17-1: equation 17-1: pwm frequency is defined as 1/[pwm period]. when tmr2 (tmr4) is equal to pr2 (pr4), the following three events occur on the next increment cycle: ? tmr2 (tmr4) is cleared ? the ccpx pin is set (exception: if pwm duty cycle = 0%, the ccpx pin will not be set) ? the pwm duty cycle is latched from ccprxl into ccprxh 17.4.2 pwm duty cycle the pwm duty cycle is specified by writing to the ccprxl register and to the ccpxcon<5:4> bits. up to 10-bit resolution is available. the ccprxl contains the eight msbs and the ccpxcon<5:4> contains the two lsbs. this 10-bit value is represented by ccprxl:ccpxcon<5:4>. equation 17-2 is used to calculate the pwm duty cycle in time. equation 17-2: ccprxl and ccpxcon<5:4> can be written to at any time, but the duty cycle value is not latched into ccprxh until after a match between pr2 (pr4) and tmr2 (tmr4) occurs (i.e., the period is complete). in pwm mode, ccprxh is a read-only register. ccprxl comparator comparator prx ccpxcon<5:4> q s r ccpx tris output enable ccprxh tmrx 2 lsbs latched from q clocks reset match tmrx = prx latch 0 9 (1) note 1: the two lsbs of the duty cycle register are held by a 2-bit latch that is part of the module?s hardware. it is physically separate from the ccprx registers. duty cycle register set ccpx pin duty cycle pin period duty cycle tmr2 (tmr4) = pr2 (tmr4) tmr2 (tmr4) = duty cycle tmr2 (tmr4) = pr2 (pr4) note: the timer2 and timer 4 postscalers (see section 14.0 ?timer3 module? and section 15.0 ?timer4 module? ) are not used in the determination of the pwm frequency. the postscaler could be used to have a servo update rate at a different frequency than the pwm output. pwm period = [(pr2) + 1] ? 4 ? t osc ? (tmr2 prescale value) pwm duty cycle = (ccpr x l:ccp x con<5:4>) ? t osc ? (tmr2 prescale value)
? 2009 microchip technology inc. preliminary ds39931b-page 243 pic18f46j50 family the ccprxh register and a 2-bit internal latch are used to double-buffer the pwm duty cycle. this double-buffering is essential for glitchless pwm operation. when the ccprxh and 2-bit latch match tmr2 (tmr4), concatenated with an internal 2-bit q clock or 2 bits of the tmr2 (tmr4) prescaler, the ccpx pin is cleared. the maximum pwm resolution (bits) for a given pwm frequency is given by equation 17-3: equation 17-3: 17.4.3 setup for pwm operation the following steps should be taken when configuring the ccp module for pwm operation: 1. set the pwm period by writing to the pr2 (pr4) register. 2. set the pwm duty cycle by writing to the ccprxl register and ccpxcon<5:4> bits. 3. make the ccpx pin an output by clearing the appropriate tris bit. 4. set the tmr2 (tmr4) prescale value, then enable timer2 (timer4) by writing to t2con (t4con). 5. configure the ccpx module for pwm operation. table 17-2: example pwm frequencies and resolutions at 40 mhz note: if the pwm duty cycle value is longer than the pwm period, the ccpx pin will not be cleared. log ( f pwm log(2) f osc ) bits pwm resolution (max) = pwm frequency 2.44 khz 9.77 khz 39.06 khz 156.25 khz 312.50 khz 416.67 khz timer prescaler (1, 4, 16)1641111 pr2 value ffh ffh ffh 3fh 1fh 17h maximum resolution (bits) 10 10 10 8 7 6.58
pic18f46j50 family ds39931b-page 244 preliminary ? 2009 microchip technology inc. table 17-3: registers associated with pwm, timer2 and timer4 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 61 rcon ipen ? cm ri to pd por bor 62 pir1 pmpif adif rc1if tx1if ssp1if ccp1if tmr2if tmr1if 63 pie1 pmpie adie rc1ie tx1ie ssp1ie ccp1ie tmr2ie tmr1ie 63 ipr1 pmpip adip rc1ip tx1ip ssp1ip ccp1ip tmr2ip tmr1ip 63 pir3 ssp2if bcl2if rc2if tx2if tmr4if ctmuif tmr3gif rtccif 63 pie3 ssp2ie bcl2ie rc2ie tx2ie tmr4ie ctmuie tmr3gie rtccie 63 ipr3 ssp2ip bcl2ip rc2ip tx2ip tmr4ip ctmuip tmr3gip rtccip 63 trisg ? ? ? trisg4 trisg3 trisg2 trisg1 trisg0 63 tmr2 (1) timer2 register 62 pr2 (1) timer2 period register 62 t2con ? t2outps3 t2outps2 t2outps1 t2o utps0 tmr2on t2ckps1 t2ckps0 62 tmr4 timer4 register 65 pr4 (1) timer4 period register 65 t4con ? t4outps3 t4outps2 t4outps1 t4o utps0 tmr4on t4ckps1 t4ckps0 65 ccpr4l capture/compare/pwm register 4 low byte 65 ccpr4h capture/compare/pwm register 4 high byte 65 ccpr5l capture/compare/pwm register 5 low byte 65 ccpr5h capture/compare/pwm register 5 high byte 65 ccp4con ? ? dc4b1 dc4b0 ccp4m3 ccp4m2 ccp4m1 ccp4m0 65 ccp5con ? ? dc5b1 dc5b0 ccp5m3 ccp5m2 ccp5m1 ccp5m0 65 odcon1 (2) ? ? ? ccp5od ccp4od eccp3od eccp2od eccp1od 66 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by pwm, timer2 or timer4. note 1: default (legacy) sfr at this address, available when wdtcon<4> = 0 . 2: configuration sfr, overlaps with default sfr at this address; available only when wdtcon<4> = 1 .
? 2009 microchip technology inc. preliminary ds39931b-page 245 pic18f46j50 family 17.5 pwm (enhanced mode) the enhanced pwm mode can generate a pwm signal on up to four different output pins with up to 10 bits of resolution. it can do this through four different pwm output modes: ? single pwm ? half-bridge pwm ? full-bridge pwm, forward mode ? full-bridge pwm, reverse mode to select an enhanced pwm mode, the pxm bits of the ccpxcon register must be set appropriately. the pwm outputs are multiplexed with i/o pins and are designated: pxa, pxb, pxc and pxd. the polarity of the pwm pins is configurable and is selected by setting the ccpxm bits in the ccpxcon register appropriately. table 17-1 provides the pin assignments for each enhanced pwm mode. figure 17-5 provides an example of a simplified block diagram of the enhanced pwm module. figure 17-5: example simplified block diagram of the enhanced pwm mode note: to prevent the generation of an incomplete waveform when the pwm is first enabled, the eccp module waits until the start of a new pwm period before generating a pwm signal. note 1: the tris register value for each pwm output must be configured appropriately. 2: any pin not used by an enhanced pwm mode is available for alternate pin functions. ccpr1l ccpr1h (slave) comparator tmr2 comparator pr2 (1) rq s duty cycle registers dc1b<1:0> clear timer2, toggle pwm pin and latch duty cycle note 1: the 8-bit timer tmr2 register is concatenated with the 2- bit internal q clock, or 2 bits of the prescaler to create the 10-bit time base. 2: these pins are remappable. tris eccp1/ rpn tris r pn tris p rn tris p rn output controller pxm<1:0> 2 ccpxm<3:0> 4 eccp1del eccpx/pxa (2) pxb (2) pxc (2) pxd (2)
pic18f46j50 family ds39931b-page 246 preliminary ? 2009 microchip technology inc. table 17-4: example pin assignments for various pwm enhanced modes figure 17-6: example pwm (enhanced mode) output relationships (active-high state) eccp mode pxm<1:0> pxa pxb pxc pxd single 00 yes (1) yes (1) yes (1) yes (1) half-bridge 10 yes yes no no full-bridge, forward 01 yes yes yes yes full-bridge, reverse 11 yes yes yes yes note 1: outputs are enabled by pulse steering in single mode (see register 17-4). 0 period 00 10 01 11 signal pr2 + 1 pxm<1:0> pxa modulated pxa modulated pxb modulated pxa active pxb inactive pxc inactive pxd modulated pxa inactive pxb modulated pxc active pxd inactive pulse width (single output) (half-bridge) (full-bridge, forward) (full-bridge, reverse) delay (1) delay (1) relationships: ? period = 4 * t osc * (pr2 + 1) * (tmr2 prescale value) ? pulse width = t osc * (ccprxl<7:0>:ccpxcon<5:4>) * (tmr2 prescale value) ? delay = 4 * t osc * (eccpxdel<6:0>) note 1: dead-band delay is programmed using the eccpxdel register ( section 17.5.6 ?programmable dead-band delay mode? ).
? 2009 microchip technology inc. preliminary ds39931b-page 247 pic18f46j50 family figure 17-7: example enhanced pwm output relationships (active-low state) 0 period 00 10 01 11 signal pr2 + 1 pxm<1:0> pxa modulated pxa modulated pxb modulated pxa active pxb inactive pxc inactive pxd modulated pxa inactive pxb modulated pxc active pxd inactive pulse width (single output) (half-bridge) (full-bridge, forward) (full-bridge, reverse) delay (1) delay (1) relationships: ? period = 4 * t osc * (pr2 + 1) * (tmr2 prescale value) ? pulse width = t osc * (ccprxl<7:0>:ccpxcon<5:4>) * (tmr2 prescale value) ? delay = 4 * t osc * (eccpxdel<6:0>) note 1: dead-band delay is programmed using the eccp1del register ( section 17.5.6 ?programmable dead-band delay mode? ).
pic18f46j50 family ds39931b-page 248 preliminary ? 2009 microchip technology inc. 17.5.1 half-bridge mode in half-bridge mode, two pins are used as outputs to drive push-pull loads. the pwm output signal is output on the pxa pin, while the complementary pwm output signal is output on the pxb pin (see figure 17-8). this mode can be used for half-bridge applications, as shown in figure 17-9, or for full-bridge applications, where four power switches are being modulated with two pwm signals. in half-bridge mode, the programmable dead-band delay can be used to prevent shoot-through current in half-bridge power devices. the value of the pxdc<6:0> bits of the eccpxdel register sets the number of instruction cycles before the output is driven active. if the value is greater than the duty cycle, the corresponding output remains inactive during the entire cycle. see section 17.5.6 ?programmable dead-band delay mode? for more details of the dead-band delay operations. since the pxa and pxb outputs are multiplexed with the port data latches, the associated tris bits must be cleared to configure pxa and pxb as outputs. figure 17-8: example of half-bridge pwm output figure 17-9: example of half-bridge applications period pulse width td td (1) pxa (2) pxb (2) td = dead-band delay period (1) (1) note 1: at this time, the tmr2 register is equal to the pr2 register. 2: output signals are shown as active-high. pxa pxb fet driver fet driver load + - + - fet driver fet driver v+ load fet driver fet driver pxa pxb standard half-bridge circuit (?push-pull?) half-bridge output driving a full-bridge circuit
? 2009 microchip technology inc. preliminary ds39931b-page 249 pic18f46j50 family 17.5.2 full-bridge mode in full-bridge mode, all four pins are used as outputs. an example of a full-bridge application is provided in figure 17-10. in the forward mode, the pxa pin is driven to its active state, the pxd pin is modulated, while the pxb and pxc pins will be driven to their inactive state as provided in figure 17-11. in the reverse mode, the pxc pin is driven to its active state, the pxb pin is modulated, while the pxa and pxd pins will be driven to their inactive state as provided figure 17-11. the pxa, pxb, pxc and pxd outputs are multiplexed with the port data latches. the associated tris bits must be cleared to configure the pxa, pxb, pxc and pxd pins as outputs. figure 17-10: example of full-bridge application pxa pxc fet driver fet driver v+ v- load fet driver fet driver pxb pxd qa qb qd qc
pic18f46j50 family ds39931b-page 250 preliminary ? 2009 microchip technology inc. figure 17-11: example of full-bridge pwm output period pulse width pxa (2) pxb (2) pxc (2) pxd (2) forward mode (1) period pulse width pxa (2) pxc (2) pxd (2) pxb (2) reverse mode (1) (1) (1) note 1: at this time, the tmr2 register is equal to the pr2 register. 2: the output signal is shown as active-high.
? 2009 microchip technology inc. preliminary ds39931b-page 251 pic18f46j50 family 17.5.2.1 direction change in full-bridge mode in the full-bridge mode, the pxm1 bit in the ccpxcon register allows users to control the forward/reverse direction. when the application firmware changes this direction control bit, the module will change to the new direction on the next pwm cycle. a direction change is initiated in software by changing the pxm1 bit of the ccpxcon register. the following sequence occurs prior to the end of the current pwm period: ? the modulated outputs (pxb and pxd) are placed in their inactive state. ? the associated unmodulated outputs (pxa and pxc) are switched to drive in the opposite direction. ? pwm modulation resumes at the beginning of the next period. see figure 17-12 for an illustration of this sequence. the full-bridge mode does not provide a dead-band delay. as one output is modulated at a time, a dead-band delay is generally not required. there is a situation where a dead-band delay is required. this situation occurs when both of the following conditions are true: 1. the direction of the pwm output changes when the duty cycle of the output is at or near 100%. 2. the turn-off time of the power switch, including the power device and driver circuit, is greater than the turn-on time. figure 17-13 shows an example of the pwm direction changing from forward to reverse, at a near 100% duty cycle. in this example, at time, t1, the pxa and pxd outputs become inactive, while the pxc output becomes active. since the turn-off time of the power devices is longer than the turn-on time, a shoot-through current will flow through power devices, qc and qd (see figure 17-10), for the duration of ?t?. the same phenomenon will occur to power devices, qa and qb, for pwm direction change from reverse to forward. if changing pwm direction at high duty cycle is required for an application, two possible solutions for eliminating the shoot-through current are: 1. reduce pwm duty cycle for one pwm period before changing directions. 2. use switch drivers that can drive the switches off faster than they can drive them on. other options to prevent shoot-through current may exist. figure 17-12: example of pwm direction change pulse width period (1) signal note 1: the direction bit, pxm1 of the ccpxcon register, is written any time during the pwm cycle. 2: when changing directions, the pxa and pxc signals switch before the end of the current pwm cycle. the modulated pxb and pxd signals are inactive at this time. the length of this time is: (1/f osc ) ? tmr2 prescale value period (2) pxa (active-high) pxb (active-high) pxc (active-high) pxd (active-high) pulse width
pic18f46j50 family ds39931b-page 252 preliminary ? 2009 microchip technology inc. figure 17-13: example of pwm direction change at near 100% duty cycle 17.5.3 start-up considerations when any pwm mode is used, the application hardware must use the proper external pull-up and/or pull-down resistors on the pwm output pins. the ccpxm<1:0> bits of the ccpxcon register allow the user to choose whether the pwm output signals are active-high or active-low for each pair of pwm output pins (pxa/pxc and pxb/pxd). the pwm output polarities must be selected before the pwm pin output drivers are enabled. changing the polarity configura- tion while the pwm pin output drivers are enable is not recommended since it may result in damage to the application circuits. the pxa, pxb, pxc and pxd output latches may not be in the proper states when the pwm module is initialized. enabling the pwm pin output drivers at the same time as the enhanced pwm modes may cause damage to the application circuit. the enhanced pwm modes must be enabled in the proper output mode and complete a full pwm cycle before enabling the pwm pin output drivers. the completion of a full pwm cycle is indicated by the tmr2if or tmr4if bit of the pir1 or pir3 register being set as the second pwm period begins. forward period reverse period pxa t on t off t = t off ? t on pxb pxc pxd external switch d potential shoot-through current note 1: all signals are shown as active-high. 2: t on is the turn-on delay of pow er switch qc and its driver. 3: t off is the turn-off delay of power switch qd and its driver. external switch c t1 pw pw note: when the microcontroller is released from reset, all of the i/o pins are in the high-impedance state. the external circuits must keep the power switch devices in the off state until the micro- controller drives the i/o pins with the proper signal levels or activates the pwm output(s).
? 2009 microchip technology inc. preliminary ds39931b-page 253 pic18f46j50 family 17.5.4 enhanced pwm auto-shutdown mode the pwm mode supports an auto-shutdown mode that will disable the pwm outputs when an external shutdown event occurs. auto-shutdown mode places the pwm output pins into a predetermined state. this mode is used to help prevent the pwm from damaging the application. the auto-shutdown sources are selected using the eccpxas<2:0> bits of the eccpxas register. a shutdown event may be generated by: ?a logic ? 0 ? on the pin that is assigned the flt0 input function ? comparator c1 ? comparator c2 ? setting the eccpxase bit in firmware a shutdown condition is indicated by the eccpxase (auto-shutdown event status) bit of the eccpxas register. if the bit is a ? 0 ?, the pwm pins are operating normally. if the bit is a ? 1 ?, the pwm outputs are in the shutdown state. when a shutdown event occurs, two things happen: the eccpxase bit is set to ? 1 ?. the eccpxase will remain set until cleared in firmware or an auto-restart occurs (see section 17.5.5 ?auto-restart mode? ). the enabled pwm pins are asynchronously placed in their shutdown states. the pwm output pins are grouped into pairs [pxa/pxc ] and [pxb/pxd]. the state of each pin pair is determined by the pssxac and pssxbd bits of the eccpxas register. each pin pair may be placed into one of three states: ? drive logic ? 1 ? ? drive logic ? 0 ? ? tri-state (high-impedance) register 17-2: eccpxas: eccpx aut o-shutdown control register (access fbeh, fb8h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 eccpxase eccpxas2 eccpxas1 eccpxas0 pssxac1 pssxac0 pssxbd1 pssxbd0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 eccpxase: eccp auto-shutdown event status bit 1 = a shutdown event has occurred; eccp outputs are in a shutdown state 0 = eccp outputs are operating bit 6-4 eccpxas<2:0>: eccp auto-shutdown source select bits 000 = auto-shutdown is disabled 001 = comparator c1out output is high 010 = comparator c2out output is high 011 = either comparator c1out or c2out is high 100 =v il on flt0 pin 101 =v il on flt0 pin or comparator c1out output is high 110 =v il on flt0 pin or comparator c2out output is high 111 =v il on flt0 pin or comparator c1out or comparator c2out is high bit 3-2 pssxac<1:0>: pins pxa and pxc shutdown state control bits 00 = drive pins pxa and pxc to ? 0 ? 01 = drive pins pxa and pxc to ? 1 ? 1x = pins pxa and pxc tri-state bit 1-0 pssxbd<1:0>: pins pxb and pxd shutdown state control bits 00 = drive pins pxb and pxd to ? 0 ? 01 = drive pins pxb and pxd to ? 1 ? 1x = pins pxb and pxd tri-state note 1: the auto-shutdown condition is a level-based signal, not an edge-based signal. as long as the level is present, the auto-shutdown will persist. 2: writing to the eccpxase bit is disabled while an auto-shutdown condition persists. 3: once the auto-shutdown condition has been removed and the pwm restarted (either through firmware or auto-restart), the pwm signal will always restart at the beginning of the next pwm period.
pic18f46j50 family ds39931b-page 254 preliminary ? 2009 microchip technology inc. figure 17-14: pwm auto-shutdown with firmware restart (pxrsen = 0 ) 17.5.5 auto-restart mode the enhanced pwm can be configured to automatically restart the pwm signal once the auto-shutdown condi- tion has been removed. auto-restart is enabled by setting the pxrsen bit in the eccpxdel register. if auto-restart is enabled, the eccpxase bit will remain set as long as the auto-shutdown condition is active. when the auto-shutdown condition is removed, the eccpxase bit will be cleared via hardware and normal operation will resume. the module will wait until the next pwm period begins, however, before re-enabling the output pin. this behav- ior allows the auto-shutdown with auto-restart features to be used in applications based on current mode pwm control. figure 17-15: pwm auto-shutdown with auto-restart enabled (pxrsen = 1 ) shutdown pwm eccpxase bit activity event shutdown event occurs shutdown event clears pwm resumes normal pwm start of pwm period eccpxase cleared by firmware pwm period shutdown pwm eccpxase bit activity event shutdown event occurs shutdown event clears pwm resumes normal pwm start of pwm period pwm period
? 2009 microchip technology inc. preliminary ds39931b-page 255 pic18f46j50 family 17.5.6 programmable dead-band delay mode in half-bridge applications, where all power switches are modulated at the pwm frequency, the power switches normally require more time to turn off than to turn on. if both the upper and lower power switches are switched at the same time (one turned on and the other turned off), both switches may be on for a short period until one switch completely turns off. during this brief interval, a very high current (shoot-through current) will flow through both power switches, shorting the bridge supply. to avoid this potentially destructive shoot-through current from flowing during switching, turning on either of the power switches is normally delayed to allow the other switch to completely turn off. in half-bridge mode, a digitally programmable dead-band delay is available to avoid shoot-through current from destroying the bridge power switches. the delay occurs at the signal transition from the non-active state to the active state. see figure 17-16 for illustration. the lower seven bits of the associated eccpxdel register (register 17-3) sets the delay period in terms of microcontroller instruction cycles (t cy or 4 t osc ). figure 17-16: example of half-bridge pwm output figure 17-17: example of half-bridge applications period pulse width td td (1) pxa (2) pxb (2) td = dead-band delay period (1) (1) note 1: at this time, the tmr2 register is equal to the pr2 register. 2: output signals are shown as active-high. pxa pxb fet driver fet driver v+ v- load + v - + v - standard half-bridge circuit (?push-pull?)
pic18f46j50 family ds39931b-page 256 preliminary ? 2009 microchip technology inc. 17.5.7 pulse steering mode in single output mode, pulse steering allows any of the pwm pins to be the modulated signal. additionally, the same pwm signal can simultaneously be available on multiple pins. once the single output mode is selected (ccpxm<3:2> = 11 and pxm<1:0> = 00 of the ccpxcon register), the user firmware can bring out the same pwm signal to one, two, three or four output pins by setting the appropriate str bits of the pstrxcon register, as provided in table 17-4. while the pwm steering mode is active, the ccpxm<1:0> bits of the ccpxcon register select the pwm output polarity for the px pins. the pwm auto-shutdown operation also applies to pwm steering mode as described in section 17.5.4 ?enhanced pwm auto-shutdown mode? . an auto-shutdown event will only affect pins that have pwm outputs enabled. register 17-3: eccpxdel: enhanced pwm co ntrol register (access fbdh, fb7h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 pxrsen pxdc6 pxdc5 pxdc4 pxdc3 pxdc2 pxdc1 pxdc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 pxrsen: pwm restart enable bit 1 = upon auto-shutdown, the eccpxase bit clears automatically once the shutdown event goes away; the pwm restarts automatically 0 = upon auto-shutdown, eccpxase must be cleared by software to restart the pwm bit 6-0 pxdc<6:0>: pwm delay count bits pxdcn = number of f osc /4 (4 * t osc ) cycles between the scheduled time when a pwm signal should transition active and the actual time it transitions active. note: the associated tris bits must be set to output (? 0 ?) to enable the pin output driver in order to see the pwm signal on the pin.
? 2009 microchip technology inc. preliminary ds39931b-page 257 pic18f46j50 family register 17-4: pstrxcon: pulse steering control register (access fbfh, fb9h) (1) r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-1 cmpl1 cmpl0 ? strsync strd strc strb stra bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 cmpl<1:0>: complementary mode output assignment steering sync bits 1 = modulated output pin toggles between pxa and pxb for each period 0 = complementary output assignment disabled; strd:stra bits used to determine steering mode bit 5 unimplemented: read as ? 0 ? bit 4 strsync: steering sync bit 1 = output steering update occurs on next pwm period 0 = output steering update occurs at the beginning of the instruction cycle boundary bit 3 strd: steering enable bit d 1 = pxd pin has the pwm waveform with polarity control from ccpxm<1:0> 0 = pxd pin is assigned to port pin bit 2 strc: steering enable bit c 1 = pxc pin has the pwm waveform with polarity control from ccpxm<1:0> 0 = pxc pin is assigned to port pin bit 1 strb: steering enable bit b 1 = pxb pin has the pwm waveform with polarity control from ccpxm<1:0> 0 = pxb pin is assigned to port pin bit 0 stra: steering enable bit a 1 = pxa pin has the pwm waveform with polarity control from ccpxm<1:0> 0 = pxa pin is assigned to port pin note 1: the pwm steering mode is available only when the ccpxcon register bits, ccpxm<3:2> = 11 , and pxm<1:0> = 00 .
pic18f46j50 family ds39931b-page 258 preliminary ? 2009 microchip technology inc. figure 17-18: simplified steering block diagram 17.5.7.1 steering synchronization the strsync bit of the pstrxcon register gives the user two selections of when the steering event will happen. when the strsync bit is ? 0 ?, the steering event will happen at the end of the instruction that writes to the pstrxcon register. in this case, the out- put signal at the px pins may be an incomplete pwm waveform. this operation is useful when the user firmware needs to immediately remove a pwm signal from the pin. when the strsync bit is ? 1 ?, the effective steering update will happen at the beginning of the next pwm period. in this case, steering on/off the pwm output will always produce a complete pwm waveform. figures 17-19 and 17-20 illustrate the timing diagrams of the pwm steering depending on the strsync setting. figure 17-19: example of steering event at end of instruction (strsync = 0) figure 17-20: example of steering event at beginning of instruction (strsync = 1) 1 0 tris rpn pin port data pxa signal stra 1 0 tris rpn pin port data strb 1 0 tris rpn pin port data strc 1 0 tris rpn pin port data strd note 1: port outputs are configured as displayed when the ccpxcon register bits, pxm<1:0> = 00 and ccpxm<3:2> = 11 . 2: single pwm output requires setting at least one of the strx bits. ccpxm1 ccpxm0 ccpxm1 ccpxm0 pwm p1n = pwm strn p1 port data pwm period port data pwm port data p1n = pwm strn p1 port data
? 2009 microchip technology inc. preliminary ds39931b-page 259 pic18f46j50 family 17.5.8 operation in power-managed modes in sleep mode, all clock sources are disabled. timer2 will not increment and the state of the module will not change. if the eccpx pin is driving a value, it will con- tinue to drive that value. when the device wakes up, it will continue from this state. if two-speed start-ups are enabled, the initial start-up frequency from hfintosc and the postscaler may not be stable immediately. in pri_idle mode, the primary clock will continue to clock the eccpx module without change. 17.5.8.1 operation with fail-safe clock monitor (fscm) if the fail-safe clock monitor (fscm) is enabled, a clock failure will force the device into the power-managed rc_run mode and the oscfif bit of the pir2 register will be set. the eccpx will then be clocked from the internal oscillator clock source, which may have a different clock frequency than the primary clock. 17.5.9 effects of a reset both power-on reset and subsequent resets will force all ports to input mode and the eccp registers to their reset states. this forces the eccp module to reset to a state compatible with previous, non-enhanced eccp modules used on other pic18 and pic16 devices. table 17-5: registers associated with eccp1 module and timer1 to timer3 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rabie tmr0if int0if rabif 79 rcon ipen sboren ? ri to pd por bor 82 pir1 pmpif (1) adif rcif txif sspif ccp1if tmr2if tmr1if 79 pie1 pmpie (1) adie rcie txie sspie ccp1ie tmr2ie tmr1ie 83 ipr1 pmpip (1) adip rcip txip sspip ccp1ip tmr2ip tmr1ip 83 pir2 oscfif cm2if cm1if usbif bcl1if hlvdif tmr3if ccp2if 83 pie2 oscfie cm2ie cm1ie usbie bcl1ie hlvdie tmr3ie ccp2ie 83 ipr2 oscfip cm2ip cm1ip usbip bcl1ip hlvdip tmr3ip ccp2ip 83 trisc trisc7 trisc6 trisc5 trisc4 ?trisc2 trisc1 trisc0 84 tmr1l timer1 register low byte 79 tmr1h timer1 register high byte 79 t1con tmr1cs1 tmr1cs0 t1ckps1 t1ckps0 t1oscen t1sync rd16 tmr1on 79 tmr2 timer2 register 79 t2con ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 79 pr2 timer2 period register 79 tmr3l timer3 register low byte 79 tmr3h timer3 register high byte 79 t3con tmr3cs1 tmr3cs0 t3ckps1 t3ckps0 t3oscen t3sync rd16 tmr3on 79 ccpr1l capture/compare/pwm register 1 low byte 79 ccpr1h capture/compare/pwm register 1 high byte 79 ccp1con p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 79 eccp1as eccp1ase eccp1as2 eccp1as1 eccp1as0 pss1ac1 pss1ac0 pss1bd1 pss1bd0 79 eccp1del p1rsen p1dc6 p1dc5 p1dc4 p1dc3 p1dc2 p1dc1 p1dc0 256 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used during eccp operation. note 1: these bits are only available on 44-pin devices.
pic18f46j50 family ds39931b-page 260 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39931b-page 261 pic18f46j50 family 18.0 master synchronous serial port (mssp) module the master synchronous serial port (mssp) module is a serial interface, useful for communicating with other peripheral or microcontroller devices. these peripheral devices include serial eeproms, shift registers, display drivers and a/d converters. 18.1 master ssp (mssp) module overview the mssp module can operate in one of two modes: ? serial peripheral interface (spi) ? inter-integrated circuit (i 2 c?) - full master mode - slave mode (with general address call) the i 2 c interface supports the following modes in hardware: ?master mode ? multi-master mode ? slave mode with 5-bit and 7-bit address masking (with address masking for both 10-bit and 7-bit addressing) all members of the pic18f46j50 family have two mssp modules, designated as mssp1 and mssp2. the modules operate independently: ? pic18f4xj50 devices ? both modules can be configured for either i 2 c or spi communication ? pic18f2xj50 devices: - mssp1 can be used for either i 2 c or spi communication - mssp2 can be used only for spi communication all of the mssp1 module-related spi and i 2 c i/o functions are hard-mapped to specific i/o pins. for mssp2 functions: ? spi i/o functions (sdo2, sdi2, sck2 and ss2 ) are all routed through the peripheral pin select (pps) module. these functions may be configured to use any of the rpn remappable pins, as described in section 9.7 ?peripheral pin select (pps)? . ?i 2 c functions (scl2 and sda2) have fixed pin locations. on all pic18f46j50 family devices, the spi dma capability can only be used in conjunction with mssp2. the spi dma feature is described in section 18.4 ?spi dma module? . note: throughout this section, generic references to an mssp module in any of its operating modes may be interpreted as being equally applicable to mssp1 or mssp2. register names and module i/o signals use the generic designator ?x? to indicate the use of a numeral to distinguish a particular module when required. control bit names are not individuated.
pic18f46j50 family ds39931b-page 262 preliminary ? 2009 microchip technology inc. 18.2 control registers each mssp module has three associated control registers. these include a status register (sspxstat) and two control registers (sspxcon1 and sspxcon2). the use of these registers and their individual configura- tion bits differ significantly depending on whether the mssp module is operated in spi or i 2 c mode. additional details are provided under the individual sections. 18.3 spi mode the spi mode allows 8 bits of data to be synchronously transmitted and received simultaneously. all four modes of spi are supported. when mssp2 is used in spi mode, it can optionally be configured to work with the spi dma submodule described in section 18.4 ?spi dma module? . to accomplish communication, typically three pins are used: ? serial data out (sdox) ? rc7/rx1/dt1/sdo1/rp18 or sdo2/remappable ? serial data in (sdix) ? rb5/kbi1/sdi1/sda1/rp8 or sdi2/remappable ? serial clock (sckx) ? rb4/kbi0/sck1/scl1/rp7 or sck2/remappable additionally, a fourth pin may be used when in a slave mode of operation: ? slave select (ssx ) ? ra5/an4/ss1 / hlvdin/rcv/rp2 or ss2 /remappable figure 18-1 depicts the block diagram of the mssp module when operating in spi mode. figure 18-1: msspx block diagram (spi mode) note: in devices with more than one mssp module, it is very important to pay close attention to the sspxcon register names. ssp1con1 and ssp1con2 control different operational aspects of the same module, while ssp1con1 and ssp2con1 control the same features for two different modules. ( ) read write internal data bus sspxsr reg sspm<3:0> bit 0 shift clock ssx control enable edge select clock select tmr2 output t osc prescaler 4, 16, 64 2 edge select 2 4 data to txx/rxx in sspxsr tris bit 2 smp:cke sdox sspxbuf reg sdix ssx sckx note: only port i/o names are used in this diagram for the sake of brevity. refer to the text for a full list of multiplexed functions.
? 2009 microchip technology inc. preliminary ds39931b-page 263 pic18f46j50 family 18.3.1 registers each mssp module has four registers for spi mode operation. these are: ? msspx control register 1 (sspxcon1) ? msspx status register (sspxstat) ? serial receive/transmit buffer register (sspxbuf) ? msspx shift register (sspxsr) ? not directly accessible sspxcon1 and sspxstat are the control and status registers in spi mode operation. the sspxcon1 register is readable and writable. the lower six bits of the sspxstat are read-only. the upper two bits of the sspxstat are read/write. sspxsr is the shift register used for shifting data in or out. sspxbuf is the buffer register to which data bytes are written to or read from. in receive operations, sspxsr and sspxbuf together create a double-buffered receiver. when sspxsr receives a complete byte, it is transferred to sspxbuf and the sspxif interrupt is set. during transmission, the sspxbuf is not double-buffered. a write to sspxbuf will write to both sspxbuf and sspxsr. register 18-1: sspxstat: msspx status register (spi mode) (access fc7h, f73h) r/w-1 r/w-1 r-1 r-1 r-1 r-1 r-1 r-1 smp cke (1) d/a psr/w ua bf bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 smp: sample bit spi master mode: 1 = input data sampled at end of data output time 0 = input data sampled at middle of data output time spi slave mode: smp must be cleared when spi is used in slave mode. bit 6 cke: spi clock select bit (1) 1 = transmit occurs on transition from active to idle clock state 0 = transmit occurs on transition from idle to active clock state bit 5 d/a : data/address bit used in i 2 c? mode only. bit 4 p: stop bit used in i 2 c mode only; this bit is cleared when the mssp module is disabled, sspen is cleared. bit 3 s: start bit used in i 2 c mode only. bit 2 r/w : read/write information bit used in i 2 c mode only. bit 1 ua: update address bit used in i 2 c mode only. bit 0 bf: buffer full status bit 1 = receive complete, sspxbuf is full 0 = receive not complete, sspxbuf is empty note 1: polarity of clock state is set by the ckp bit (sspxcon1<4>).
pic18f46j50 family ds39931b-page 264 preliminary ? 2009 microchip technology inc. register 18-2: sspxcon1: msspx control regi ster 1 (spi mode) (access fc6h, f72h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wcol sspov (1) sspen (2) ckp sspm3 (3) sspm2 (3) sspm1 (3) sspm0 (3) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 wcol: write collision detect bit 1 = the sspxbuf register is written while it is still transmitting the previous word (must be cleared in software) 0 = no collision bit 6 sspov: receive overflow indicator bit (1) spi slave mode: 1 = a new byte is received while the sspxbuf register is still holding the previous data. in case of over- flow, the data in sspxsr is lost. overflow can only occur in slave mode. the user must read the sspxbuf, even if only transmitting data, to avoid setting overflow (must be cleared in software). 0 = no overflow bit 5 sspen: master synchronous serial port enable bit (2) 1 = enables serial port and configures sckx, sdox, sdix and ssx as serial port pins 0 = disables serial port and configures these pins as i/o port pins bit 4 ckp: clock polarity select bit 1 = idle state for clock is a high level 0 = idle state for clock is a low level bit 3-0 sspm<3:0>: master synchronous serial port mode select bits (3) 0101 = spi slave mode, clock = sckx pin, ssx pin control disabled, ssx can be used as i/o pin 0100 = spi slave mode, clock = sckx pin, ssx pin control enabled 0011 = spi master mode, clock = tmr2 output/2 0010 = spi master mode, clock = f osc /64 0001 = spi master mode, clock = f osc /16 0000 = spi master mode, clock = f osc /4 note 1: in master mode, the overflow bit is not set since each new reception (and transmission) is initiated by writing to the sspxbuf register. 2: when enabled, this pin must be properly configured as input or output. 3: bit combinations not specifically listed here, are either reserved or implemented in i 2 c? mode only.
? 2009 microchip technology inc. preliminary ds39931b-page 265 pic18f46j50 family 18.3.2 operation when initializing the spi, several options need to be specified. this is done by programming the appropriate control bits (sspxcon1<5:0> and sspxstat<7:6>). these control bits allow the following to be specified: ? master mode (sckx is the clock output) ? slave mode (sckx is the clock input) ? clock polarity (idle state of sckx) ? data input sample phase (middle or end of data output time) ? clock edge (output data on rising/falling edge of sckx) ? clock rate (master mode only) ? slave select mode (slave mode only) each mssp module consists of a transmit/receive shift register (sspxsr) and a buffer register (sspxbuf). the sspxsr shifts the data in and out of the device, msb first. the sspxbuf holds the data that was written to the sspxsr until the received data is ready. once the 8 bits of data have been received, that byte is moved to the sspxbuf register. then, the buffer full (bf) detect bit (sspxstat<0>) and the interrupt flag bit, sspxif, are set. this double-buffering of the received data (sspxbuf) allows the next byte to start reception before reading the data that was just received. any write to the sspxbuf register during transmis- sion/reception of data will be ignored and the write collision detect bit, wcol (sspxcon1<7>), will be set. user software must clear the wcol bit so that it can be determined if the following write(s) to the sspxbuf register completed successfully. the buffer full bit, bf (sspxstat<0>), indicates when sspxbuf has been loaded with the received data (transmission is complete). when the sspxbuf is read, the bf bit is cleared. this data may be irrelevant if the spi is only a transmitter. generally, the mssp interrupt is used to determine when the transmission/reception has completed. if the interrupt method is not going to be used, then software polling can be done to ensure that a write collision does not occur. example 18-1 provides the loading of the sspxbuf (sspxsr) for data transmission. the sspxsr is not directly readable or writable and can only be accessed by addressing the sspxbuf register. additionally, the sspxstat register indicates the various status conditions. 18.3.3 open-drain output option the drivers for the sdox output and sckx clock pins can be optionally configured as open-drain outputs. this feature allows the voltage level on the pin to be pulled to a higher level through an external pull-up resistor, provided the sdox or sckx pin is not multi- plexed with an anx analog function. this allows the output to communicate with external circuits without the need for additional level shifters. for more information, see section 9.1.4 ?open-drain outputs? . the open-drain output option is controlled by the spi2od and spi1od bits (odcon3<1:0>). setting an spixod bit configures both sd ox and sckx pins for the corresponding open-drain operation. example 18-1: loading the ssp1buf (ssp1sr) register note: when the application software is expecting to receive valid data, the sspxbuf should be read before the next byte of transfer data is written to the sspxbuf. application software should follow this process even when the current contents of sspxbuf are not important. loop btfss ssp1stat, bf ;has data been received (transmit complete)? bra loop ;no movf ssp1buf, w ;wreg reg = contents of ssp1buf movwf rxdata ;save in user ram, if data is meaningful movf txdata, w ;w reg = contents of txdata movwf ssp1buf ;new data to xmit
pic18f46j50 family ds39931b-page 266 preliminary ? 2009 microchip technology inc. 18.3.4 enabling spi i/o to enable the serial port, mssp enable bit, sspen (sspxcon1<5>), must be set. to reset or reconfigure spi mode, clear the sspen bit, reinitialize the sspxcon1 registers and then set the sspen bit. this configures the sdix, sdox, sckx and ssx pins as serial port pins. for the pins to behave as the serial port function, the appropriate tris bits, ancon/pcfg bits and peripheral pin select registers (if using mssp2) should be correctly initialized prior to setting the sspen bit. a typical spi serial port initialization process follows: ? initialize odcon3 register (optional open-drain output control) ? initialize remappable pin functions (if using mssp2, see section 9.7 ?peripheral pin select (pps)? ) ? initialize sckx lat value to desired idle sck level (if master device) ? initialize sckx ancon/pcfg bit (if slave mode and multiplexed with anx function) ? initialize sckx tris bit as output (master mode) or input (slave mode) ? initialize sdix ancon/pcfg bit (if sdix is multiplexed with anx function) ? initialize sdix tris bit ? initialize ssx ancon/pcfg bit (if slave mode and multiplexed with anx function) ? initialize ssx tris bit (slave modes) ? initialize sdox tris bit ? initialize sspxstat register ? initialize sspxcon1 register ? set sspen bit to enable the module any mssp1 serial port function that is not desired may be overridden by programming the corresponding data direction (tris) register to the opposite value. if individual mssp2 serial port functions will not be used, they may be left unmapped. 18.3.5 typical connection figure 18-2 illustrates a typical connection between two microcontrollers. the master controller (processor 1) initiates the data transfer by sending the sckx signal. data is shifted out of both shift registers on their pro- grammed clock edge and latched on the opposite edge of the clock. both processors should be programmed to the same clock polarity (ckp), then both controllers would send and receive data at the same time. whether the data is meaningful (or dummy data) depends on the application software. this leads to three scenarios for data transmission: ? master sends valid data ? slave sends dummy data ? master sends valid data ? slave sends valid data ? master sends dummy data ? slave sends valid data figure 18-2: spi master/slave connection note: when mssp2 is used in spi master mode, the sck2 function must be config- ured as both an output and an input in the pps module. sck2 must be initialized as an output pin (by writing 0x0a to one of the rporx registers). additionally, sck2in must also be mapped to the same pin by initializing the rpinr22 register. failure to initialize sck2/sck2in as both output and input will prevent the module from receiving data on the sdi2 pin, as the module uses the sck2in signal to latch the received data. serial input buffer (sspxbuf) shift register (sspxsr) msb lsb sdox sdix processor 1 sckx spi master sspm<3:0> = 00xxb serial input buffer (sspxbuf) shift register (sspxsr) lsb msb sdix sdox processor 2 sckx spi slave sspm<3:0> = 010xb serial clock
? 2009 microchip technology inc. preliminary ds39931b-page 267 pic18f46j50 family 18.3.6 master mode the master can initiate the data transfer at any time because it controls the sckx. the master determines when the slave (processor 2, figure 18-2) is to broadcast data by the software protocol. in master mode, the data is transmitted/received as soon as the sspxbuf register is written to. if the spi is only going to receive, the sdox output could be dis- abled (programmed as an input). the sspxsr register will continue to shift in the signal present on the sdix pin at the programmed clock rate. as each byte is received, it will be loaded into the sspxbuf register as if a normal received byte (interrupts and status bits appropriately set). this could be useful in receiver applications as a ?line activity monitor? mode. the ckp is selected by appropriately programming the ckp bit (sspxcon1<4>). this then, would give waveforms for spi communication as illustrated in figure 18-3, figure 18-5 and figure 18-6, where the most significant byte (msb) is transmitted first. in master mode, the spi clock rate (bit rate) is user-programmable to be one of the following: ?f osc /4 (or t cy ) ?f osc /16 (or 4 ? t cy ) ?f osc /64 (or 16 ? t cy ) ? timer2 output/2 when using the timer2 output/2 option, the period register 2 (pr2) can be used to determine the spi bit rate. however, only pr2 values of 0x01 to 0xff are valid in this mode. figure 18-3 illustrates the waveforms for master mode. when the cke bit is set, the sdox data is valid before there is a clock edge on sckx. the change of the input sample is shown based on the state of the smp bit. the time when the sspxbuf is loaded with the received data is shown. figure 18-3: spi mode waveform (master mode) sckx (ckp = 0 sckx (ckp = 1 sckx (ckp = 0 sckx (ckp = 1 4 clock modes input sample input sample sdix bit 7 bit 0 sdox bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 sdix sspxif (smp = 1 ) (smp = 0 ) (smp = 1 ) cke = 1 ) cke = 0 ) cke = 1 ) cke = 0 ) (smp = 0 ) write to sspxbuf sspxsr to sspxbuf sdox bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 (cke = 0 ) (cke = 1 ) next q4 cycle after q2 bit 0
pic18f46j50 family ds39931b-page 268 preliminary ? 2009 microchip technology inc. 18.3.7 slave mode in slave mode, the data is transmitted and received as the external clock pulses appear on sckx. when the last bit is latched, the sspxif interrupt flag bit is set. while in slave mode, the external clock is supplied by the external clock source on the sckx pin. this external clock must meet the minimum high and low times as specified in the electrical specifications. while in sleep mode, the slave can transmit/receive data. when a byte is received, the device can be configured to wake-up from sleep. 18.3.8 slave select synchronization the ssx pin allows a synchronous slave mode. the spi must be in slave mode with the ssx pin control enabled (sspxcon1<3:0> = 04h). when the ssx pin is low, transmission and reception are enabled and the sdox pin is driven. when the ssx pin goes high, the sdox pin is no longer driven, even if in the middle of a transmitted byte and becomes a floating output. external pull-up/pull-down resistors may be desirable depending on the application. when the spi module resets, the bit counter is forced to ? 0 ?. this can be done by either forcing the ssx pin to a high level or clearing the sspen bit. to emulate two-wire communication, the sdox pin can be connected to the sdix pin. when the spi needs to operate as a receiver, the sdox pin can be configured as an input. this disables transmissions from the sdox. the sdix can always be left as an input (sdix function) since it cannot create a bus conflict. figure 18-4: slave synchronization waveform note 1: when the spi is in slave mode with the s sx pin control enabled (sspxcon1<3:0> = 0100 ), the spi module will reset if the ssx pin is set to v dd . 2: if the spi is used in slave mode with cke set, then the ssx pin control must be enabled. sckx (ckp = 1 sckx (ckp = 0 input sample sdix bit 7 sdox bit 7 bit 6 bit 7 sspxif interrupt (smp = 0 ) cke = 0 ) cke = 0 ) (smp = 0 ) write to sspxbuf sspxsr to sspxbuf ssx flag bit 0 bit 7 bit 0 next q4 cycle after q2
? 2009 microchip technology inc. preliminary ds39931b-page 269 pic18f46j50 family figure 18-5: spi mode waveform (slave mode with cke = 0 ) figure 18-6: spi mode waveform (slave mode with cke = 1 ) sckx (ckp = 1 sckx (ckp = 0 input sample sdix bit 7 sdox bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sspxif interrupt (smp = 0 ) cke = 0 ) cke = 0 ) (smp = 0 ) write to sspxbuf sspxsr to sspxbuf ssx flag optional next q4 cycle after q2 bit 0 sckx (ckp = 1 sckx (ckp = 0 input sample sdix bit 7 bit 0 sdox bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sspxif interrupt (smp = 0 ) cke = 1 ) cke = 1 ) (smp = 0 ) write to sspxbuf sspxsr to sspxbuf ssx flag not optional next q4 cycle after q2
pic18f46j50 family ds39931b-page 270 preliminary ? 2009 microchip technology inc. 18.3.9 operation in power-managed modes in spi master mode, module clocks may be operating at a different speed than when in full-power mode. in the case of sleep mode, all clocks are halted. in idle modes, a clock is provided to the peripherals. that clock can be from the primary clock source, the secondary clock (timer1 oscillator) or the intosc source. see section 2.5 ?clock sources and oscillator switching? for additional information. in most cases, the speed that the master clocks spi data is not important; however, this should be evaluated for each system. if mssp interrupts are enabled, they can wake the controller from sleep mode, or one of the idle modes, when the master completes sending data. if an exit from sleep or idle mode is not desired, mssp interrupts should be disabled. if the sleep mode is selected, all module clocks are halted and the transmission/reception will remain in that state until the device wakes. after the device returns to run mode, the module will resume transmitting and receiving data. in spi slave mode, the spi transmit/receive shift register operates asynchronously to the device. this allows the device to be placed in any power-managed mode and data to be shifted into the spi transmit/receive shift register. when all 8 bits have been received, the mssp interrupt flag bit will be set, and if enabled, will wake the device. 18.3.10 effects of a reset a reset disables the mssp module and terminates the current transfer. 18.3.11 bus mode compatibility table 18-1 provides the compatibility between the standard spi modes and the states of the ckp and cke control bits. table 18-1: spi bus modes there is also an smp bit, which controls when the data is sampled. 18.3.12 spi clock speed and module interactions because mssp1 and mssp2 are independent modules, they can operate simultaneously at different data rates. setting the sspm<3:0> bits of the sspxcon1 register determines the rate for the corresponding module. an exception is when both modules use timer2 as a time base in master mode. in this instance, any changes to the timer2 module?s operation will affect both mssp modules equally. if different bit rates are required for each module, the user should select one of the other three time base options for one of the modules. standard spi mode terminology control bits state ckp cke 0, 0 0 1 0, 1 0 0 1, 0 1 1 1, 1 1 0
? 2009 microchip technology inc. preliminary ds39931b-page 271 pic18f46j50 family table 18-2: registers associat ed with spi operation name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 61 pir1 pmpif (2) adif rc1if tx1if ssp1if ccp1if tmr2if tmr1if 63 pie1 pmpie (2) adie rc1ie tx1ie ssp1ie ccp1ie tmr2ie tmr1ie 63 ipr1 pmpip (2) adip rc1ip tx1ip ssp1ip ccp1ip tmr2ip tmr1ip 63 pir3 ssp2if bcl2if rc2if tx2if tmr4if ctmuif tmr3gif rtccif 63 pie3 ssp2ie bcl2ie rc2ie tx2ie tmr4ie ctmuie tmr3gie rtccie 63 ipr3 ssp2ip bcl2ip rc2ip tx2ip tmr4ip ctmuip tmr3gip rtccip 63 trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 64 trisc trisc7 trisc6 trisc5 trisc4 ? trisc2 trisc1 trisc0 64 trisd trisd7 trisd6 trisd5 trisd4 trisd3 trisd2 trisd1 trisd0 64 ssp1buf mssp1 receive buffer/transmit register 62 sspxcon1 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 62 sspxstat smp cke d/a p s r/w ua bf 62 ssp2buf mssp2 receive buffer/transmit register 65 odcon3 (1) ? ? ? ? ? ?spi2odspi1od66 legend: shaded cells are not used by the mssp module in spi mode. note 1: configuration sfr overlaps with default sfr at this address; available only when wdtcon<4> = 1 . 2: these bits are only available on 44-pin devices.
pic18f46j50 family ds39931b-page 272 preliminary ? 2009 microchip technology inc. 18.4 spi dma module the spi dma module contains control logic to allow the mssp2 module to perform spi direct memory access transfers. this enables the module to quickly transmit or receive large amounts of data with relatively little cpu intervention. when the spi dma module is used, mssp2 can directly read and write to general purpose sram. when the spi dma module is not enabled, mssp2 functions normally, but without dma capability. the spi dma module is composed of control logic, a destination receive address pointer, a transmit source address pointer, an interrupt manager and a byte count register for setting the size of each dma transfer. the dma module may be used with all spi master and slave modes, and supports both half-duplex and full-duplex transfers. 18.4.1 i/o pin considerations when enabled, the spi dma module uses the mssp2 module. all spi related input and output signals related to mssp2 are routed through the peripheral pin select module. the appropriate initialization procedure as described in section 18.4.6 ?using the spi dma module? will need to be followed prior to using the spi dma module. the output pins assigned to the sdo2 and sck2 functions can optionally be configured as open-drain outputs, such as for level shifting operations mentioned in the same section. 18.4.2 ram to ram copy operations although the spi dma module is primarily intended to be used for spi communication purposes, the module can also be used to perform ram to ram copy opera- tions. to do this, configure the module for full-duplex master mode operation, but assign the sdo2 output and sdi2 input functions onto the same rpn pin in the pps module. also assign sck2 out and sck2 in onto the same rpn pin (a different pin than used for sdo2 and sdi2). this will allow the module to operate in loopback mode, providing ram copy capability. 18.4.3 idle and sleep considerations the spi dma module remains fully functional when the microcontroller is in idle mode. during normal sleep, the spi dma module is not func- tional and should not be used. to avoid corrupting a transfer, user firmware should be careful to make certain that pending dma operations are complete by polling the dmaen bit in the dmacon1 register prior to putting the microcontroller into sleep. in spi slave modes, the mssp2 module is capable of transmitting and/or receiving one byte of data while in sleep mode. this allows the ssp2if flag in the pir3 register to be used as a wake-up source. when the dmaen bit is cleared, the spi dma module is effectively disabled, and the mssp2 module functions normally, but without dma capabilities. if the dmaen bit is clear prior to entering sleep, it is still possible to use the ssp2if as a wake-up source without any data loss. neither mssp2 nor the spi dma module will provide any functionality in deep sleep. upon exiting from deep sleep, all of the i/o pins, mssp2 and spi dma related registers will need to be fully reinitialized before the spi dma module can be used again. 18.4.4 registers the spi dma engine is enabled and controlled by the following special function registers: ? dmacon1 ? dmacon2 ? txaddrh ? txaddrl ? rxaddrh ? rxaddrl ? dmabch ? dmabcl
? 2009 microchip technology inc. preliminary ds39931b-page 273 pic18f46j50 family 18.4.4.1 dmacon1 the dmacon1 register is used to select the main operating mode of the spi dma module. the sscon1 and sscon0 bits are used to control the slave select pin. when mssp2 is used in spi master mode with the spi dma module, ssdma can be controlled by the dma module as an output pin. if mssp2 will be used to com- municate with an spi slave device that needs the ss pin to be toggled periodically, the spi dma hardware can automatically be used to deassert ss between each byte, every two bytes or every four bytes. alternatively, user firmware can manually generate slave select signals with normal general purpose i/o pins, if required by the slave device(s). when the txinc bit is set, the txaddr register will automatically increment after each transmitted byte. automatic transmit address increment can be disabled by clearing the txinc bit. if the automatic transmit address increment is disabled, each byte which is out- put on sdo2, will be the same (the contents of the sram pointed to by the txaddr register) for the entire dma transaction. when the rxinc bit is set, the rxaddr register will automatically increment after each received byte. automatic receive address increment can be disabled by clearing the rxinc bit. if rxinc is disabled in full-duplex or half-duplex receive modes, all incom- ing data bytes on sdi2 will overwrite the same memory location pointed to by the rxaddr register. after the spi dma transaction has completed, the last received byte will reside in the memory location pointed to by the rxaddr register. the spi dma module can be used for either half-duplex receive only communication, half-duplex transmit only communication or full-duplex simultaneous transmit and receive operations. all modes are available for both spi master and spi slave configurations. the duplex0 and duplex1 bits can be used to select the desired operating mode. the behavior of the dlyinten bit varies greatly depending on the spi operating mode. for example behavior for each of the modes, see figure 18-3 through figure 18-6. spi slave mode, dlyinten = 1 : in this mode, an ssp2if interrupt will be generated during a transfer if the time between successful byte transmission events is longer than the value set by the dlycyc<3:0> bits in the dmacon2 register. this interrupt allows slave firmware to know that the master device is taking an unusually large amount of time between byte transmis- sions. for example, this information may be useful for implementing application-defined communication protocols involving time-outs if the bus remains idle for too long. when dlyinten = 1 , the dlylvl<3:0> interrupts occur normally according to the selected setting. spi slave mode, dlyinten = 0 : in this mode, the time-out based interrupt is disabled. no additional ssp2if interrupt events will be generated by the spi dma module, other than those indicated by the intlvl<3:0> bits in the dmacon2 register. in this mode, always set dlycyc<3:0> = 0000 . spi master mode, dlyinten = 0 : the dlycyc<3:0> bits in the dmacon2 register determine the amount of additional inter-byte delay, which is added by the spi dma module during a transfer. the master mode ss2 output feature may be used. spi master mode, dlyinten = 1 : the amount of hardware overhead is slightly reduced in this mode, and the minimum inter-byte delay is 8 t cy for f osc /4, 9 t cy for f osc /16 and 15 t cy for f osc /64. this mode can potentially be used to obtain slightly higher effec- tive spi bandwidth. in this mode, the ss2 control feature cannot be used, and should always be disabled (dmacon1<7:6> = 00 ). additionally, the interrupt generating hardware (used in slave mode) remains active. to avoid extraneous ssp2if interrupt events, set the dmacon2 delay bits, dlycyc<3:0> = 1111 , and ensure that the spi serial clock rate is no slower than f osc /64. in spi master modes, the dmaen bit is used to enable the spi dma module and to initiate an spi dma trans- action. after user firmware sets the dmaen bit, the dma hardware will begin transmitting and/or receiving data bytes according to the configuration used. in spi slave modes, setting the dmaen bit will finish the initialization steps needed to prepare the spi dma module for communication (which must still be initiated by the master device). to avoid possible data corruption, once the dmaen bit is set, user firmware should not attempt to modify any of the mssp2 or spi dma related registers, with the exception of the intlvl bits in the dmacon2 register. if user firmware wants to halt an ongoing dma transac- tion, the dmaen bit can be manually cleared by the firmware. clearing the dmaen bit while a byte is currently being transmitted will not immediately halt the byte in progress. instead, any byte currently in progress will be completed before the mssp2 and spi dma modules go back to their idle conditions. if user firmware clears the dmaen bit, the txaddr, rxaddr and dmabc registers will no longer update, and the dma module will no longer make any additional read or writes to sram; therefore, state information can be lost.
pic18f46j50 family ds39931b-page 274 preliminary ? 2009 microchip technology inc. register 18-3: dmacon1: dma control register 1 (access f88h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 sscon1 sscon0 txinc rxinc duplex1 duplex0 dlyinten dmaen bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 sscon<1:0>: ssdma output control bits (master modes only) 11 = ssdma is asserted for the duration of 4 bytes; dlyinten is always reset low 01 = ssdma is asserted for the duration of 2 bytes; dlyinten is always reset low 10 = ssdma is asserted for the duration of 1 byte; dlyinten is always reset low 00 = ssdma is not controlled by the dma module; dlyinten bit is software programmable bit 5 txinc: transmit address increment enable bit allows the transmit address to increment as the transfer progresses. 1 = the transmit address is to be incremented from the initial value of txaddr<11:0> 0 = the transmit address is always set to the initial value of txaddr<11:0> bit 4 rxinc: receive address increment enable bit allows the receive address to increment as the transfer progresses. 1 = the received address is to be incremented from the intial value of rxaddr<11:0> 0 = the received address is always set to the initial value of rxaddr<11:0> bit 3-2 duplex<1:0>: transmit/receive operating mode select bits 10 = spi dma operates in full-duplex mode, data is simultaneously transmitted and received 01 = dma operates in half-duplex mode, data is transmitted only 00 = dma operates in half-duplex mode, data is received only bit 1 dlyinten: delay interrupt enable bit enables the interrupt to be invoked after the number of t cy cycles specified in dlycyc<2:0> has elapsed from the latest completed transfer. 1 = the interrupt is enabled, sscon<1:0> must be set to ? 00 ? 0 = the interrupt is disabled bit 0 dmaen: dma operation start/stop bit this bit is set by the users? software to start the dma operation. it is reset back to zero by the dma engine when the dma operation is completed or aborted. 1 = dma is in session 0 = dma is not in session
? 2009 microchip technology inc. preliminary ds39931b-page 275 pic18f46j50 family 18.4.4.2 dmacon2 the dmacon2 register contains control bits for controlling interrupt generation and inter-byte delay behavior. the intlvl<3:0> bits are used to select when an ssp2if interrupt should be generated. the function of the dlycyc<3:0> bits depends on the spi operating mode (master/slave), as well as the dlyinten setting. in spi master mode, the dlycyc<3:0> bits can be used to control how much time the module will idle between bytes in a transfer. by default, the hardware requires a minimum delay of: 8 t cy for f osc /4, 9 t cy for f osc /16 and 15 t cy for f osc /64. additional delay can be added with the dlycyc bits. in spi slave modes, the dlycyc<3:0> bits may optionally be used to trigger an additional time-out based interrupt. register 18-4: dmacon2: dma control register 2 (access f86h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 dlycyc3 dlycyc2 dlycyc1 dlycyc0 intlvl3 intlvl2 intlvl1 intlvl0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 dlycyc<3:0>: delay cycle selection bits when dlyinten = 0 , these bits specify the additional delay (above the base overhead of the hard- ware) in number of t cy cycles before the ssp2buf register is written again for the next transfer. when dlyinten = 1 , these bits specify the delay in number of t cy cycles from the latest completed transfer before an interrupt to the cpu is invoked. in this case, the additional delay before the ssp2buf register is written again is 1 t cy + (base overhead of hardware). 1111 = delay time in number of instruction cycles is 2,048 cycles 1110 = delay time in number of instruction cycles is 1,024 cycles 1101 = delay time in number of instruction cycles is 896 cycles 1100 = delay time in number of instruction cycles is 768 cycles 1011 = delay time in number of instruction cycles is 640 cycles 1010 = delay time in number of instruction cycles is 512 cycles 1001 = delay time in number of instruction cycles is 384 cycles 1000 = delay time in number of instruction cycles is 256 cycles 0111 = delay time in number of instruction cycles is 128 cycles 0110 = delay time in number of instruction cycles is 64 cycles 0101 = delay time in number of instruction cycles is 32 cycles 0100 = delay time in number of instruction cycles is 16 cycles 0011 = delay time in number of instruction cycles is 8 cycles 0010 = delay time in number of instruction cycles is 4 cycles 0001 = delay time in number of instruction cycles is 2 cycles 0000 = delay time in number of instruction cycles is 1 cycle bit 3-0 intlvl<3:0>: watermark interrupt enable bits these bits specify the amount of remaining data yet to be transferred (transmitted and/or received) upon which an interrupt is generated. 1111 = amount of remaining data to be transferred is 576 bytes 1110 = amount of remaining data to be transferred is 512 bytes 1101 = amount of remaining data to be transferred is 448 bytes 1100 = amount of remaining data to be transferred is 384 bytes 1011 = amount of remaining data to be transferred is 320 bytes 1010 = amount of remaining data to be transferred is 256 bytes 1001 = amount of remaining data to be transferred is 192 bytes 1000 = amount of remaining data to be transferred is 128 bytes 0111 = amount of remaining data to be transferred is 67 bytes 0110 = amount of remaining data to be transferred is 32 bytes 0101 = amount of remaining data to be transferred is 16 bytes 0100 = amount of remaining data to be transferred is 8 bytes 0011 = amount of remaining data to be transferred is 4 bytes 0010 = amount of remaining data to be transferred is 2 bytes 0001 = amount of remaining data to be transferred is 1 byte 0000 = transfer complete
pic18f46j50 family ds39931b-page 276 preliminary ? 2009 microchip technology inc. 18.4.4.3 dmabch and dmabcl the dmabch and dmabcl register pair forms a 10-bit byte count register, which is used by the spi dma module to send/receive up to 1,024 bytes for each dma transaction. when the dma module is actively running (dmaen = 1 ), the dma byte count register decrements after each byte is transmitted/received. the dma trans- action will halt, and the dmaen bit will be automatically cleared by hardware after the last byte has completed. after a dma transaction is complete, the dmabc register will read 0x000. prior to initiating a dma transaction by setting the dmaen bit, user firmware should load the appropriate value into the dmabch/dmabcl registers. the dmabc is a ?base zero? counter, so the actual number of bytes, which will be transmitted, follows in equation 18-1. for example, if user firmware wants to transmit 7 bytes in one transaction, dmabc should be loaded with 006h. similarly, if user firmware wishes to transmit 1,024 bytes, dmabc should be loaded with 3ffh. equation 18-1: bytes transmitted for a given dmabc 18.4.4.4 txaddrh and txaddrl the txaddrh and txaddrl registers pair together to form a 12-bit transmit source address pointer register. in modes that use txaddr (full-duplex and half-duplex transmit), the txaddr will be incre- mented after each byte is transmitted. transmitted data bytes will be taken from the memory location pointed to by the txaddr register. the contents of the memory locations pointed to by txaddr will not be modified by the dma module during a transmission. the spi dma module can read from and transmit data from all general purpose memory on the device, including memory used for usb endpoint buffers. the spi dma module cannot be used to read from the special function registers (sfrs) contained in banks 14 and 15. 18.4.4.5 rxaddrh and rxaddrl the rxaddrh and rxaddrl register pair together to form a 12-bit receive destination address pointer. in modes that use rxaddr (full-duplex and half-duplex receive), the rxaddr register will be incremented after each byte is received. received data bytes will be stored at the memory location pointed to by the rxaddr register. the spi dma module can write received data to all general purpose memory on the device, including memory used for usb endpoint buffers. the spi dma module cannot be used to modify the special function registers contained in banks 14 and 15. 18.4.5 interrupts the spi dma module alters the behavior of the ssp2if interrupt flag. in normal/non-dma modes, the ssp2if is set once after every single byte is transmitted/received through the mssp2 module. when mssp2 is used with the spi dma module, the ssp2if interrupt flag will be set according to the user-selected intlvl<3:0> value specified in the dmacon2 register. the ssp2if inter- rupt condition will also be generated once the spi dma transaction has fully completed, and the dmaen bit has been cleared by hardware. the ssp2if flag becomes set once the dma byte count value indicates that the specified intlvl has been reached. for example, if dmacon2<3:0> = 0101 (16 bytes remaining), the ssp2if interrupt flag will become set once dmabc reaches 00fh. if user firmware then clears the ssp2if interrupt flag, the flag will not be set again by the hardware until after all bytes have been fully transmitted, and the dma transaction is complete. for example, if dmabc = 00fh (implying 16 bytes are remaining) and user firmware writes ? 1111 ? to intlvl<3:0> (interrupt when 576 bytes remaining), the ssp2if interrupt flag will immediately become set. if user firmware clears this interrupt flag, a new inter- rupt condition will not be generated until either: user firmware again writes intlvl with an interrupt level higher than the actual remaining level, or the dma transaction completes and the dmaen bit is cleared. bytes xmit dmabc 1 + () note: user firmware may modify the intlvl bits while a dma transaction is in progress (dmaen = 1 ). if an intlvl value is selected which is higher than the actual remaining number of bytes (indicated by dmabc + 1 ), the ssp2if interrupt flag will immediately become set. note: if the intlvl bits are modified while a dma transaction is in progress, care should be taken to avoid inadvertently changing the dlycyc<3:0> value.
? 2009 microchip technology inc. preliminary ds39931b-page 277 pic18f46j50 family 18.4.6 using the spi dma module the following steps would typically be taken to enable and use the spi dma module: 1. configure the i/o pins, which will be used by mssp2. a) assign sck2, sdo2, sdi2 and ss2 to rpn pins as appropriate for the spi mode which will be used. only functions which will be used need to be assigned to a pin. b) initialize the associated latx registers for the desired idle spi bus state. c) if open-drain output mode on sdo2 and sck2 (master mode) is desired, set odcon3<1>. d) configure corresponding trisx bits for each i/o pin used. 2. configure and enable mssp2 for the desired spi operating mode. a) select the desired operating mode (master or slave, spi mode 0, 1, 2 and 3) and con- figure the module by writing to the ssp2stat and ssp2con1 registers. b) enable mssp2 by setting ssp2con1<5> = 1 . 3. configure the spi dma engine. a) select the desired operating mode by writing the appropriate values to dmacon2 and dmacon1. b) initialize the txaddrh/txaddrl pointer (full-duplex or half-duplex transmit only mode). c) initialize the rxaddrh/rxaddrl pointer (full-duplex or half-duplex receive only mode). d) initialize the dmabch/dmabcl byte count register with the number of bytes to be transferred in the next spi dma operation. e) set the dmaen bit (dmacon1<0>). in spi master modes, this will initiate a dma transaction. in spi slave modes, this will complete the initialization process, and the module will now be ready to begin receiving and/or transmitting data to the master device once the master starts the transaction. 4. detect the ssp2if interrupt condition (pir3<7). a) if the interrupt was configured to occur at the completion of the spi dma transaction, the dmaen bit (dmacon1<0>) will be clear. user firmware may prepare the module for another transaction by repeating steps 3.b through 3.e. b) if the interrupt was configured to occur prior to the completion of the spi dma trans- action, the dmaen bit may still be set, indicating the transaction is still in progress. user firmware would typically use this inter- rupt condition to begin preparing new data for the next dma transaction. firmware should not repeat steps 3.b. through 3.e. until the dmaen bit is cleared by the hardware, indicating the transaction is complete. example 18-2 provides example code demonstrating the initialization process and the steps needed to use the spi dma module to perform a 512-byte full-duplex, master mode transfer.
pic18f46j50 family ds39931b-page 278 preliminary ? 2009 microchip technology inc. example 18-2: 512-byte spi master mode init and transfer ;for this example, let's use rp5(rb2) for sck2, ;rp4(rb1) for sdo2, and rp3(rb0) for sdi2 ;let?s use spi master mode, cke = 0, ckp = 0, ;without using slave select signalling. initspipins: movlb 0x0f ;select bank 15, for access to odcon3 register bcf odcon3, spi2od ;let?s not use open drain outputs in this example bcf latb, rb2 ;initialize our (to be) sck2 pin low (idle). bcf latb, rb1 ;initialize our (to be) sdo2 pin to an idle state bcf trisb, rb1 ;make sdo2 output, and drive low bcf trisb, rb2 ;make sck2 output, and drive low (idle state) bsf trisb, rb0 ;sdi2 is an input, make sure it is tri-stated ;now we should unlock the pps registers, so we can ;assign the mssp2 functions to our desired i/o pins. movlb 0x0e ;select bank 14 for access to pps registers bcf intcon, gie ;i/o pin unlock sequence will not work if cpu ;services an interrupt during the sequence movlw 0x55 ;unlock sequence consists of writing 0x55 movwf eecon2 ;and 0xaa to the eecon2 register. movlw 0xaa movwf eecon2 bcf ppscon, iolock ;we may now write to rpinrx and rporx registers bsf intcon, gie ;may now turn back on interrupts if desired movlw 0x03 ;rp3 will be sdi2 movwf rpinr21 ;assign the sdi2 function to pin rp3 movlw 0x0a ;let?s assign sck2 output to pin rp4 movwf rpor4 ;rpor4 maps output signals to rp4 pin movlw 0x04 ;sck2 also needs to be configured as an input on the same pin movwf rpinr22 ;sck2 input function taken from rp4 pin movlw 0x09 ;0x09 is sdo2 output movwf rpor5 ;assign sdo2 output signal to the rp5 (rb2) pin movlb 0x0f ;done with pps registers, bank 15 has other sfrs initmssp2: clrf ssp2stat ;cke = 0, smp = 0 (sampled at middle of bit) movlw b'00000000' ;ckp = 0, spi master mode, fosc/4 movwf ssp2con1 ;mssp2 initialized bsf ssp2con1, sspen ;enable the mssp2 module initspidma: movlw b'00111010' ;full duplex, rx/txinc enabled, no sscon movwf dmacon1 ;dlyinten is set, so dlycyc3:dlycyc0 = 1111 movlw b'11110000' ;minimum delay between bytes, interrupt movwf dmacon2 ;only once when the transaction is complete
? 2009 microchip technology inc. preliminary ds39931b-page 279 pic18f46j50 family ;somewhere else in our project, lets assume we have ;allocated some ram for use as spi receive and ;transmit buffers. ; udata 0x500 ;destbuf res 0x200 ;let?s reserve 0x500-0x6ff for use as our spi ; ;receive data buffer in this example ;srcbuf res 0x200 ;lets reserve 0x700-0x8ff for use as our spi ; ;transmit data buffer in this example preparetransfer: movlw high(destbuf) ;get high byte of destbuf address (0x05) movwf rxaddrh ;load upper four bits of the rxaddr register movlw low(destbuf) ;get low byte of the destbuf address (0x00) movwf rxaddrl ;load lower eight bits of the rxaddr register movlw high(srcbuf) ;get high byte of srcbuf address (0x07) movwf txaddrh ;load upper four bits of the txaddr register movlw low(srcbuf) ;get low byte of the srcbuf address (0x00) movwf txaddrl ;load lower eight bits of the txaddr register movlw 0x01 ;lets move 0x200 (512) bytes in one dma xfer movwf dmabch ;load the upper two bits of dmabc register movlw 0xff ;actual bytes transferred is (dmabc + 1), so movwf dmabcl ;we load 0x01ff into dmabc to xfer 0x200 bytes beginxfer: bsf dmacon1, dmaen ;the spi dma module will now begin transferring ;the data taken from srcbuf, and will store ;received bytes into destbuf. ;execute whatever ;cpu is now free to do whatever it wants to ;and the dma operation will continue without ;intervention, until it completes. ;when the transfer is complete, the ssp2if flag in ;the pir3 register will become set, and the dmaen bit ;is automatically cleared by the hardware. ;the destbuf (0x500-0x7ff) will contain the received ;data. to start another transfer, firmware will need ;to reinitialize rxaddr, txaddr, dmabc and then ;set the dmaen bit. example 18-2: 512-byte spi master mode init and transfer (continued)
pic18f46j50 family ds39931b-page 280 preliminary ? 2009 microchip technology inc. 18.5 i 2 c mode the mssp module in i 2 c mode fully implements all master and slave functions (including general call support), and provides interrupts on start and stop bits in hardware to determine a free bus (multi-master function). the mssp module implements the standard mode specifications and 7-bit and 10-bit addressing. two pins are used for data transfer: ? serial clock (sclx) ? rb4/pma1/kbi0/sck1/scl1/rp7 or rd0/pmd0/scl2 ? serial data (sdax) ? rb5/pma0/kbi1/sdi1/sda1/rp8 or rd1/pmd1/sda2 the user must configure these pins as inputs by setting the associated tris bits. these pins are up to 5.5v tolerant, allowing direct use in i 2 c busses operating at voltages higher than v dd . figure 18-7: msspx block diagram (i 2 c? mode) 18.5.1 registers the mssp module has six registers for i 2 c operation. these are: ? msspx control register 1 (sspxcon1) ? msspx control register 2 (sspxcon2) ? msspx status register (sspxstat) ? serial receive/transmit buffer register (sspxbuf) ? msspx shift register (sspxsr) ? not directly accessible ? msspx address register (sspxadd) ? msspx 7-bit address mask register (sspxmsk) sspxcon1, sspxcon2 and sspxstat are the control and status registers in i 2 c mode operation. the sspxcon1 and sspxcon2 registers are readable and writable. the lower six bits of the sspxstat are read-only. the upper two bits of the sspxstat are read/write. sspxsr is the shift register used for shifting data in or out. sspxbuf is the buffer register to which data bytes are written to or read from. sspxadd contains the slave device address when the mssp is configured in i 2 c slave mode. when the mssp is configured in master mode, the lower seven bits of sspxadd act as the baud rate generator (brg) reload value. sspxmsk holds the slave address mask value when the module is configured for 7-bit address masking mode. while it is a separate register, it shares the same sfr address as sspxadd; it is only accessible when the sspm<3:0> bits are specifically set to permit access. additional details are provided in section 18.5.3.4 ?7-bit address masking mode? . in receive operations, sspxsr and sspxbuf together, create a double-buffered receiver. when sspxsr receives a complete byte, it is transferred to sspxbuf and the sspxif interrupt is set. during transmission, the sspxbuf is not double-buffered. a write to sspxbuf will write to both sspxbuf and sspxsr. read write sspxsr reg match detect sspxadd reg sspxbuf reg internal data bus addr match set, reset s, p bits (sspxstat reg) shift clock msb lsb note: only port i/o names are used in this diagram for the sake of brevity. refer to the text for a full list of multiplexed functions. sclx sdax start and stop bit detect address mask
? 2009 microchip technology inc. preliminary ds39931b-page 281 pic18f46j50 family register 18-5: sspxstat: msspx status register (i 2 c? mode) (access fc7h, f73h) r/w-1 r/w-1 r-1 r-1 r-1 r-1 r-1 r-1 smp cke d/a p (1) s (1) r/w (2,3) ua bf bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 smp: slew rate control bit in master or slave mode: 1 = slew rate control disabled for standard speed mode (100 khz and 1 mhz) 0 = slew rate control enabled for high-speed mode (400 khz) bit 6 cke: smbus select bit in master or slave mode: 1 = enable smbus specific inputs 0 = disable smbus specific inputs bit 5 d/a : data/address bit in master mode: reserved. in slave mode: 1 = indicates that the last byte received or transmitted was data 0 = indicates that the last byte received or transmitted was address bit 4 p: stop bit (1) 1 = indicates that a stop bit has been detected last 0 = stop bit was not detected last bit 3 s: start bit (1) 1 = indicates that a start bit has been detected last 0 = start bit was not detected last bit 2 r/w : read/write information bit (2,3) in slave mode: 1 = read 0 = write in master mode: 1 = transmit is in progress 0 = transmit is not in progress bit 1 ua: update address bit (10-bit slave mode only) 1 = indicates that the user needs to update the address in the sspxadd register 0 = address does not need to be updated bit 0 bf: buffer full status bit in transmit mode: 1 = sspxbuf is full 0 = sspxbuf is empty in receive mode: 1 = sspxbuf is full (does not include the ack and stop bits) 0 = sspxbuf is empty (does not include the ack and stop bits) note 1: this bit is cleared on reset and when sspen is cleared. 2: this bit holds the r/w bit information following the last address match. this bit is only valid from the address match to the next start bit, stop bit or not ack bit. 3: oring this bit with sen, rsen, pen, rcen or acken w ill indicate if the msspx is in active mode.
pic18f46j50 family ds39931b-page 282 preliminary ? 2009 microchip technology inc. register 18-6: sspxcon1: msspx control register 1 (i 2 c? mode) (access fc6h, f72h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wcol sspov sspen (1) ckp sspm3 (2) sspm2 (2) sspm1 (2) sspm0 (2) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 wcol: write collision detect bit in master transmit mode: 1 = a write to the sspxbuf register was attempted while the i 2 c conditions were not valid for a transmission to be started (must be cleared in software) 0 = no collision in slave transmit mode: 1 = the sspxbuf register is written while it is still transmitting the previous word (must be cleared in software) 0 = no collision in receive mode (master or slave modes): this is a ?don?t care? bit. bit 6 sspov: receive overflow indicator bit in receive mode: 1 = a byte is received while the sspxbuf register is still holding the previous byte (must be cleared in software) 0 = no overflow in transmit mode: this is a ?don?t care? bit in transmit mode. bit 5 sspen: master synchronous serial port enable bit (1) 1 = enables the serial port and configures the sdax and sclx pins as the serial port pins 0 = disables serial port and configures these pins as i/o port pins bit 4 ckp: sckx release control bit in slave mode: 1 = releases clock 0 = holds clock low (clock stretch); used to ensure data setup time in master mode: unused in this mode. bit 3-0 sspm<3:0>: master synchronous serial port mode select bits (2) 1111 = i 2 c slave mode, 10-bit address with start and stop bit interrupts enabled 1110 = i 2 c slave mode, 7-bit address with start and stop bit interrupts enabled 1011 = i 2 c firmware controlled master mode (slave idle) 1001 = load sspxmsk register at sspxadd sfr address (3,4) 1000 = i 2 c master mode, clock = f osc /(4 * (sspxadd + 1)) 0111 = i 2 c slave mode, 10-bit address 0110 = i 2 c slave mode, 7-bit address note 1: when enabled, the sdax and sclx pins must be configured as inputs. 2: bit combinations not specifically listed here are either reserved or implemented in spi mode only. 3: when sspm<3:0> = 1001 , any reads or writes to the sspxadd sfr address actually accesses the sspxmsk register. 4: this mode is only available when 7-bit address maski ng mode is selected (msspmsk configuration bit is ? 1 ?).
? 2009 microchip technology inc. preliminary ds39931b-page 283 pic18f46j50 family register 18-7: sspxcon2: msspx control register 2 (i 2 c? master mode) (access fc5h, f71h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 gcen (3) ackstat ackdt (1) acken (2) rcen (2) pen (2) rsen (2) sen (2) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 gcen: general call enable bit (slave mode only) (3) 1 = enable interrupt when a general call address (0000h) is received in the sspxsr 0 = general call address disabled bit 6 ackstat: acknowledge status bit (master transmit mode only) 1 = acknowledge was not received from slave 0 = acknowledge was received from slave bit 5 ackdt: acknowledge data bit (master receive mode only) (1) 1 = not acknowledge 0 = acknowledge bit 4 acken: acknowledge sequence enable bit (2) 1 = initiates acknowledge sequence on sdax and sclx pins and transmits ackdt data bit; automatically cleared by hardware 0 = acknowledge sequence idle bit 3 rcen: receive enable bit (master receive mode only) (2) 1 = enables receive mode for i 2 c 0 = receive idle bit 2 pen: stop condition enable bit (2) 1 = initiates stop condition on sdax and sclx pins; automatically cleared by hardware 0 = stop condition idle bit 1 rsen: repeated start condition enable bit (2) 1 = initiates repeated start condition on sdax and sclx pins; automatically cleared by hardware 0 = repeated start condition idle bit 0 sen: start condition enable bit (2) 1 = initiates start condition on sdax and sclx pins; automatically cleared by hardware 0 = start condition idle note 1: value that will be transmitted when the user initiates an acknowledge sequence at the end of a receive. 2: if the i 2 c module is active, these bits may not be set (no spooling) and the sspxbuf may not be written (or writes to the sspxbuf are disabled). 3: this bit is not implemented in i 2 c master mode.
pic18f46j50 family ds39931b-page 284 preliminary ? 2009 microchip technology inc. register 18-9: sspxmsk: i 2 c? slave address mask register (7-bit masking mode) (access fc8h, f74h) (1) register 18-8: sspxcon2: msspx control register 2 (i 2 c? slave mode) (access fc5h, f71h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 gcen ackstat (2) admsk5 admsk4 admsk3 admsk2 admsk1 sen (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 gcen: general call enable bit (slave mode only) 1 = enables interrupt when a general call address (0000h) is received in the sspxsr 0 = general call address disabled bit 6 ackstat: acknowledge status bit (2) unused in slave mode. bit 5-2 admsk<5:2>: slave address mask select bits (5-bit address masking) 1 = masking of corresponding bits of sspxadd enabled 0 = masking of corresponding bits of sspxadd disabled bit 1 admsk1: slave address least significant bit(s) mask select bit in 7-bit addressing mode: 1 = masking of sspxadd<1> only enabled 0 = masking of sspxadd<1> only disabled in 10-bit addressing mode: 1 = masking of sspxadd<1:0> enabled 0 = masking of sspxadd<1:0> disabled bit 0 sen: start condition enable/stretch enable bit (1) 1 = clock stretching is enabled for both slave transmit and slave receive (stretch enabled) 0 = clock stretching is disabled note 1: if the i 2 c module is active, these bits may not be set (no spooling) and the sspxbuf may not be written (or writes to the sspxbuf are disabled). 2: this bit is unimplemented in i 2 c slave mode. r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 msk7 msk6 msk5 msk4 msk3 msk2 msk1 msk0 (2) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 msk<7:0>: slave address mask select bits 1 = masking of corresponding bit of sspxadd enabled 0 = masking of corresponding bit of sspxadd disabled note 1: this register shares the same sfr address as sspxadd and is only addressable in select mssp operating modes. see section 18.5.3.4 ?7-bit address masking mode? for more details. 2: msk0 is not used as a mask bit in 7-bit addressing.
? 2009 microchip technology inc. preliminary ds39931b-page 285 pic18f46j50 family 18.5.2 operation the mssp module functions are enabled by setting the mssp enable bit, sspen (sspxcon1<5>). the sspxcon1 register allows control of the i 2 c operation. four mode selection bits (sspxcon1<3:0>) allow one of the following i 2 c modes to be selected: ?i 2 c master mode, clock ?i 2 c slave mode (7-bit address) ?i 2 c slave mode (10-bit address) ?i 2 c slave mode (7-bit address) with start and stop bit interrupts enabled ?i 2 c slave mode (10-bit address) with start and stop bit interrupts enabled ?i 2 c firmware controlled master mode, slave is idle selection of any i 2 c mode with the sspen bit set forces the sclx and sdax pins to be open-drain, provided these pins are programmed as inputs by setting the appropriate trisb or trisd bits. to ensure proper operation of the module, pull-up resistors must be provided externally to the sclx and sdax pins. 18.5.3 slave mode in slave mode, the sclx and sdax pins must be configured as inputs (trisb<5:4> set). the mssp module will override the input state with the output data when required (slave-transmitter). the i 2 c slave mode hardware will always generate an interrupt on an address match. address masking will allow the hardware to generate an interrupt for more than one address (up to 31 in 7-bit addressing and up to 63 in 10-bit addressing). through the mode select bits, the user can also choose to interrupt on start and stop bits. when an address is matched, or the data transfer after an address match is received, the hardware auto- matically will generate the acknowledge (ack ) pulse and load the sspxbuf register with the received value currently in the sspxsr register. any combination of the following conditions will cause the mssp module not to give this ack pulse: ? the buffer full bit, bf (sspxstat<0>), was set before the transfer was received. ? the overflow bit, sspov (sspxcon1<6>), was set before the transfer was received. in this case, the sspxsr register value is not loaded into the sspxbuf, but bit sspxif is set. the bf bit is cleared by reading the sspxbuf register, while bit sspov is cleared through software. the sclx clock input must have a minimum high and low for proper operation. the high and low times of the i 2 c specification, as well as the requirement of the mssp module, are shown in timing parameter 100 and parameter 101. 18.5.3.1 addressing once the mssp module has been enabled, it waits for a start condition to occur. following the start condition, the 8 bits are shifted into the sspxsr register. all incoming bits are sampled with the rising edge of the clock (sclx) line. the value of register, sspxsr<7:1>, is compared to the value of the sspxadd register. the address is compared on the falling edge of the eighth clock (sclx) pulse. if the addresses match and the bf and sspov bits are clear, the following events occur: 1. the sspxsr register value is loaded into the sspxbuf register. 2. the buffer full bit, bf, is set. 3. an ack pulse is generated. 4. the msspx interrupt flag bit, sspxif, is set (and interrupt is generated, if enabled) on the falling edge of the ninth sclx pulse. in 10-bit addressing mode, two address bytes need to be received by the slave. the five most significant bits (msbs) of the first address byte specify if this is a 10-bit address. bit r/w (sspxstat<2>) must specify a write so the slave device will receive the second address byte. for a 10-bit address, the first byte would equal ? 11110 a9 a8 0 ?, where ? a9 ? and ? a8 ? are the two msbs of the address. the sequence of events for 10-bit addressing is as follows, with steps 7 through 9 for the slave-transmitter: 1. receive first (high) byte of address (bits, sspxif, bf and ua, are set on address match). 2. update the sspxadd register with second (low) byte of address (clears bit, ua, and releases the sclx line). 3. read the sspxbuf register (clears bit, bf) and clear flag bit, sspxif. 4. receive second (low) byte of address (bits, sspxif, bf and ua, are set). 5. update the sspxadd register with the first (high) byte of address. if match releases sclx line, this will clear bit, ua. 6. read the sspxbuf register (clears bit, bf) and clear flag bit, sspxif. 7. receive repeated start condition. 8. receive first (high) byte of address (bits, sspxif and bf, are set). 9. read the sspxbuf register (clears bit, bf) and clear flag bit, sspxif.
pic18f46j50 family ds39931b-page 286 preliminary ? 2009 microchip technology inc. 18.5.3.2 address masking modes masking an address bit causes that bit to become a ?don?t care?. when one address bit is masked, two addresses will be acknowledged and cause an inter- rupt. it is possible to mask more than one address bit at a time, which greatly expands the number of addresses acknowledged. the i 2 c slave behaves the same way, whether address masking is used or not. however, when address mask- ing is used, the i 2 c slave can acknowledge multiple addresses and cause interrupts. when this occurs, it is necessary to determine which address caused the interrupt by checking sspxbuf. the pic18f46j50 family of devices is capable of using two different address masking modes in i 2 c slave operation: 5-bit address masking and 7-bit address masking. the masking mode is selected at device configuration using the msspmsk configuration bit. the default device configuration is 7-bit address masking. both masking modes, in turn, support address masking of 7-bit and 10-bit addresses. the combination of masking modes and addresses provide different ranges of acknowledgable addresses for each combination. while both masking modes function in roughly the same manner, the way they use address masks is different. 18.5.3.3 5-bit address masking mode as the name implies, 5-bit address masking mode uses an address mask of up to five bits to create a range of addresses to be acknowledged, using bits 5 through 1 of the incoming address. this allows the module to acknowledge up to 31 addresses when using 7-bit addressing, or 63 addresses with 10-bit addressing (see example 18-3). this masking mode is selected when the msspmsk configuration bit is programmed (? 0 ?). the address mask in this mode is stored in the sspxcon2 register, which stops functioning as a control register in i 2 c slave mode (register 18-8). in 7-bit address masking mode, address mask bits, admsk<5:1> (sspxcon2<5:1>), mask the corresponding address bits in the sspxadd register. for any admsk bits that are set (admsk = 1 ), the cor- responding address bit is ignored (sspxadd = x ). for the module to issue an address acknowledge, it is sufficient to match only on addresses that do not have an active address mask. in 10-bit address masking mode, bits, admsk<5:2>, mask the corresponding address bits in the sspxadd register. in addition, admsk1 simultaneously masks the two lsbs of the address (sspxadd<1:0>). for any admsk bits that are active (admsk = 1 ), the cor- responding address bit is ignored (spxadd = x ). also note, that although in 10-bit address masking mode, the upper address bits reuse part of the sspxadd register bits. the address mask bits do not interact with those bits; they only affect the lower address bits. example 18-3: address masking examples in 5-bit masking mode note 1: admsk1 masks the two least significant bits of the address. 2: the two msbs of the address are not affected by address masking. 7-bit addressing: sspxadd<7:1>= a0h ( 1010000 ) (sspxadd<0> is assumed to be ? 0 ?) admsk<5:1> = 00111 addresses acknowledged: a0h, a2h, a4h, a6h, a8h, aah, ach, aeh 10-bit addressing: sspxadd<7:0> = a0h ( 10100000 ) (the two msbs of the address are ignored in this example, since they are not affected by masking) admsk<5:1> = 00111 addresses acknowledged: a0h, a1h, a2h, a3h, a4h, a5h, a6h, a7h, a8h, a9h, aah, abh, ach, adh, aeh, afh
? 2009 microchip technology inc. preliminary ds39931b-page 287 pic18f46j50 family 18.5.3.4 7-bit address masking mode unlike 5-bit address masking mode, 7-bit address masking mode uses a mask of up to eight bits (in 10-bit addressing) to define a range of addresses than can be acknowledged, using the lowest bits of the incoming address. this allows the module to acknowledge up to 127 different addresses with 7-bit addressing, or 255 with 10-bit addressing (see example 18-4). this mode is the default configuration of the module, and is selected when msspmsk is unprogrammed (? 1 ?). the address mask for 7-bit address masking mode is stored in the sspxmsk register, instead of the sspxcon2 register. sspxmsk is a separate hard- ware register within the module, but it is not directly addressable. instead, it shares an address in the sfr space with the sspxadd register. to access the sspxmsk register, it is necessary to select mssp mode, ? 1001 ? (sspcon1<3:0> = 1001 ), and then read or write to the location of sspxadd. to use 7-bit address masking mode, it is necessary to initialize sspxmsk with a value before selecting the i 2 c slave addressing mode. thus, the required sequence of events is: 1. select sspxmsk access mode (sspxcon2<3:0> = 1001 ). 2. write the mask value to the appropriate sspxadd register address (fc8h for mssp1, f6eh for mssp2). 3. set the appropriate i 2 c slave mode (sspxcon2<3:0> = 0111 for 10-bit addressing, 0110 for 7-bit addressing). setting or clearing mask bits in sspxmsk behaves in the opposite manner of the admsk bits in 5-bit address masking mode. that is, clearing a bit in sspxmsk causes the corresponding address bit to be masked; setting the bit requires a match in that position. sspxmsk resets to all ? 1 ?s upon any reset condition and, therefore, has no effect on the standard mssp operation until written with a mask value. with 7-bit address masking mode, sspxmsk<7:1> bits mask the corresponding address bits in the sspxadd register. for any sspxmsk bits that are active (sspxmsk = 0 ), the corresponding sspxadd address bit is ignored (sspxadd = x ). for the module to issue an address acknowledge, it is sufficient to match only on addresses that do not have an active address mask. with 10-bit address masking mode, sspxmsk<7:0> bits mask the corresponding address bits in the sspxadd register. for any sspxmsk bits that are active (= 0 ), the corresponding sspxadd address bit is ignored (sspxadd = x ). example 18-4: address masking examples in 7-bit masking mode note: the two msbs of the address are not affected by address masking. 7-bit addressing: sspxadd<7:1>= 1010 000 sspxmsk<7:1>= 1111 001 addresses acknowledged = a8h, a6h, a4h, a0h 10-bit addressing: sspxadd<7:0> = 1010 0000 (the two msbs are ignored in this example since they are not affected) sspxmsk<5:1> = 1111 0 addresses acknowledged = a8h, a6h, a4h, a0h
pic18f46j50 family ds39931b-page 288 preliminary ? 2009 microchip technology inc. 18.5.3.5 reception when the r/w bit of the address byte is clear and an address match occurs, the r/w bit of the sspxstat register is cleared. the received address is loaded into the sspxbuf register and the sdax line is held low (ack ). when the address byte overflow condition exists, then the no acknowledge (ack ) pulse is given. an overflow condition is defined as either bit, bf (sspxstat<0>), is set or bit, sspov (sspxcon1<6>), is set. an mssp interrupt is generated for each data transfer byte. the interrupt flag bit, sspxif, must be cleared in software. the sspxstat register is used to determine the status of the byte. if sen is enabled (sspxcon2<0> = 1 ), sclx will be held low (clock stretch) following each data transfer. the clock must be released by setting bit, ckp (sspxcon1<4>). see section 18.5.4 ?clock stretching? for more details. 18.5.3.6 transmission when the r/w bit of the incoming address byte is set and an address match occurs, the r/w bit of the sspxstat register is set. the received address is loaded into the sspxbuf register. the ack pulse will be sent on the ninth bit and pin sclx is held low regard- less of sen (see section 18.5.4 ?clock stretching? for more details). by stretching the clock, the master will be unable to assert another clock pulse until the slave is done preparing the transmit data. the transmit data must be loaded into the sspxbuf register, which also loads the sspxsr register. then, the sclx pin should be enabled by setting bit, ckp (sspxcon1<4>). the eight data bits are shifted out on the falling edge of the sclx input. this ensures that the sdax signal is valid during the sclx high time (figure 18-10). the ack pulse from the master-receiver is latched on the rising edge of the ninth sclx input pulse. if the sdax line is high (not ack ), then the data transfer is complete. in this case, when the ack is latched by the slave, the slave logic is reset (resets the sspxstat register) and the slave monitors for another occurrence of the start bit. if the sdax line was low (ack ), the next transmit data must be loaded into the sspxbuf register. again, the sclx pin must be enabled by setting bit, ckp. an mssp interrupt is generated for each data transfer byte. the sspxif bit must be cleared in software and the sspxstat register is used to determine the status of the byte. the sspxif bit is set on the falling edge of the ninth clock pulse.
? 2009 microchip technology inc. preliminary ds39931b-page 289 pic18f46j50 family figure 18-8: i 2 c? slave mode timing with sen = 0 (reception, 7-bit address) sdax sclx sspxif (pir1<3> or pir3<7>) bf (sspxstat<0>) sspov (sspxcon1<6>) s 1 2 34 567 89 1 2 34 5 67 89 1 23 45 7 89 p a7 a6 a5 a4 a3 a2 a1 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d1 d0 ack receiving data ack receiving data r/w = 0 ack receiving address cleared in software sspxbuf is read bus master terminates transfer sspov is set because sspxbuf is still full. ack is not sent. d2 6 ckp (sspxcon1<4>) (ckp does not reset to ? 0 ? when sen = 0 )
pic18f46j50 family ds39931b-page 290 preliminary ? 2009 microchip technology inc. figure 18-9: i 2 c? slave mode timing with sen = 0 and admsk<5:1> = 01011 (reception, 7-bit address) sdax sclx sspxif (pir1<3> or pir3<7>) bf (sspxstat<0>) sspov (sspxcon1<6>) s 12345678912345678912345 789 p a7 a6 a5 x a3 x x d7d6d5d4d3d2d1 d0 d7d6d5d4d3 d1d0 ack receiving data ack receiving data r/w = 0 ack receiving address cleared in software sspxbuf is read bus master terminates transfer sspov is set because sspxbuf is still full. ack is not sent. d2 6 ckp (sspxcon1<4>) (ckp does not reset to ? 0 ? when sen = 0 ) note 1: x = don?t care (i.e., address bit can either be a ? 1 ? or a ? 0 ?). 2: in this example, an address equal to a7.a6.a5.x.a3.x.x will be acknowledged and cause an interrupt.
? 2009 microchip technology inc. preliminary ds39931b-page 291 pic18f46j50 family figure 18-10: i 2 c? slave mode timing (transmission, 7-bit address) sda scl sspif (pir1<3>) bf (sspstat<0>) a6 a5 a4 a3 a2 a1 d6 d5 d4 d3 d2 d1 d0 1 2 3 4 5 6 7 8 2 3 4 5 6 7 8 9 sspbuf is written in software cleared in software data in sampled s ack transmitting data r/w = 1 ack receiving address a7 d7 9 1 d6 d5 d4 d3 d2 d1 d0 2 3 4 5 6 7 8 9 sspbuf is written in software cleared in software from sspif isr transmitting data d7 1 ckp p ack ckp is set in software ckp is set in software scl held low while cpu responds to sspif clear by reading from sspif isr
pic18f46j50 family ds39931b-page 292 preliminary ? 2009 microchip technology inc. figure 18-11: i 2 c? slave mode timing with sen = 0 and admsk<5:1> = 01001 (reception, 10-bit address) sdax sclx sspxif (pir1<3> or pir3<7>) bf (sspxstat<0>) s 123456789 123456789 12345 789 p 1 1 1 1 0 a9 a8 a7 a6 a5 x a3 a2 x x d7 d6 d5 d4 d3 d1 d0 receive data byte ack r/w = 0 ack receive first byte of address cleared in software d2 6 cleared in software receive second byte of address cleared by hardware when sspxadd is updated with low byte of address ua (sspxstat<1>) clock is held low until update of sspxadd has taken place ua is set indicating that the sspxadd needs to be updated ua is set indicating that sspxadd needs to be updated cleared by hardware when sspxadd is updated with high byte of address sspxbuf is written with contents of sspxsr dummy read of sspxbuf to clear bf flag ack ckp (sspxcon1<4>) 12345 789 d7 d6 d5 d4 d3 d1 d0 receive data byte bus master terminates transfer d2 6 ack cleared in software cleared in software sspov (sspxcon1<6>) sspov is set because sspxbuf is still full. ack is not sent. (ckp does not reset to ? 0 ? when sen = 0 ) clock is held low until update of sspxadd has taken place note 1: x = don?t care (i.e., address bit can either be a ? 1 ? or a ? 0 ?). 2: in this example, an address equal to a9.a8.a7.a6.a5.x.a3.a2.x.x will be acknowledged and cause an interrupt. 3: note that the most significant bits of the address are not affected by the bit masking.
? 2009 microchip technology inc. preliminary ds39931b-page 293 pic18f46j50 family figure 18-12: i 2 c? slave mode timing with sen = 0 (reception, 10-bit address) sdax sclx sspxif (pir1<3> or pir3<7>) bf (sspxstat<0>) s 123456789 123456789 12345 789 p 1 1 1 1 0 a9a8 a7 a6a5 a4a3a2a1 a0 d7 d6d5d4d3 d1d0 receive data byte ack r/w = 0 ack receive first byte of address cleared in software d2 6 cleared in software receive second byte of address cleared by hardware when sspxadd is updated with low byte of address ua (sspxstat<1>) clock is held low until update of sspxadd has taken place ua is set indicating that the sspxadd needs to be updated ua is set indicating that sspxadd needs to be updated cleared by hardware when sspxadd is updated with high byte of address sspxbuf is written with contents of sspxsr dummy read of sspxbuf to clear bf flag ack ckp (sspxcon1<4>) 12345 789 d7 d6 d5 d4 d3 d1 d0 receive data byte bus master terminates transfer d2 6 ack cleared in software cleared in software sspov (sspxcon1<6>) sspov is set because sspxbuf is still full. ack is not sent. (ckp does not reset to ? 0 ? when sen = 0 ) clock is held low until update of sspxadd has taken place
pic18f46j50 family ds39931b-page 294 preliminary ? 2009 microchip technology inc. figure 18-13: i 2 c? slave mode timing (transmission, 10-bit address) sdax sclx sspxif (pir1<3> or pir3<7>) bf (sspxstat<0>) s 1234 5 6789 1 2345 678 9 12345 7 89 p 1 1 1 1 0 a9a8 a7 a6a5a4a3a2a1a0 1 1 1 1 0 a8 r/w = 1 ack ack r/w = 0 ack receive first byte of address cleared in software bus master terminates transfer a9 6 receive second byte of address cleared by hardware when sspxadd is updated with low byte of address ua (sspxstat<1>) clock is held low until update of sspxadd has taken place ua is set indicating that the sspxadd needs to be updated ua is set indicating that sspxadd needs to be updated cleared by hardware when sspxadd is updated with high byte of address. sspxbuf is written with contents of sspxsr dummy read of sspxbuf to clear bf flag receive first byte of address 12345 789 d7 d6 d5 d4 d3 d1 ack d2 6 transmitting data byte d0 dummy read of sspxbuf to clear bf flag sr cleared in software write of sspxbuf initiates transmit cleared in software completion of clears bf flag ckp (sspxcon1<4>) ckp is set in software ckp is automatically cleared in hardware, holding sclx low clock is held low until update of sspxadd has taken place data transmission clock is held low until ckp is set to ? 1 ? third address sequence bf flag is clear at the end of the
? 2009 microchip technology inc. preliminary ds39931b-page 295 pic18f46j50 family 18.5.4 clock stretching both 7-bit and 10-bit slave modes implement automatic clock stretching during a transmit sequence. the sen bit (sspxcon2<0>) allows clock stretching to be enabled during receives. setting sen will cause the sclx pin to be held low at the end of each data receive sequence. 18.5.4.1 clock stretching for 7-bit slave receive mode (sen = 1 ) in 7-bit slave receive mode, on the falling edge of the ninth clock at the end of the ack sequence, if the bf bit is set, the ckp bit in the sspxcon1 register is automatically cleared, forcing the sclx output to be held low. the ckp bit being cleared to ? 0 ? will assert the sclx line low. the ckp bit must be set in the user?s isr before reception is allowed to continue. by holding the sclx line low, the user has time to service the isr and read the contents of the sspxbuf before the master device can initiate another receive sequence. this will prevent buffer overruns from occurring (see figure 18-15). 18.5.4.2 clock stretching for 10-bit slave receive mode (sen = 1 ) in 10-bit slave receive mode, during the address sequence, clock stretching automatically takes place but ckp is not cleared. during this time, if the ua bit is set after the ninth clock, clock stretching is initiated. the ua bit is set after receiving the upper byte of the 10-bit address and following the receive of the second byte of the 10-bit address with the r/w bit cleared to ? 0 ?. the release of the clock line occurs upon updating sspxadd. clock stretching will occur on each data receive sequence as described in 7-bit mode. 18.5.4.3 clock stretching for 7-bit slave transmit mode the 7-bit slave transmit mode implements clock stretching by clearing the ckp bit after the falling edge of the ninth clock if the bf bit is clear. this occurs regardless of the state of the sen bit. the user?s interrupt service routine (isr) must set the ckp bit before transmission is allowed to continue. by holding the sclx line low, the user has time to service the isr and load the contents of the sspxbuf before the master device can initiate another transmit sequence (see figure 18-10). 18.5.4.4 clock stretching for 10-bit slave transmit mode in 10-bit slave transmit mode, clock stretching is controlled during the first two address sequences by the state of the ua bit, just as it is in 10-bit slave receive mode. the first two addresses are followed by a third address sequence, which contains the high-order bits of the 10-bit address and the r/w bit set to ? 1 ?. after the third address sequence is performed, the ua bit is not set, the module is now configured in transmit mode and clock stretching is controlled by the bf flag as in 7-bit slave transmit mode (see figure 18-13). note 1: if the user reads the contents of the sspxbuf before the falling edge of the ninth clock, thus clearing the bf bit, the ckp bit will not be cleared and clock stretching will not occur. 2: the ckp bit can be set in software regardless of the state of the bf bit. the user should be careful to clear the bf bit in the isr before the next receive sequence in order to prevent an overflow condition. note: if the user polls the ua bit and clears it by updating the sspxadd register before the falling edge of the ninth clock occurs, and if the user has not cleared the bf bit by reading the sspxbuf register before that time, then the ckp bit will still not be asserted low. clock stretching on the basis of the state of the bf bit only occurs during a data sequence, not an address sequence. note 1: if the user loads the contents of sspxbuf, setting the bf bit before the falling edge of the ninth clock, the ckp bit will not be cleared and clock stretching will not occur. 2: the ckp bit can be set in software regardless of the state of the bf bit.
pic18f46j50 family ds39931b-page 296 preliminary ? 2009 microchip technology inc. 18.5.4.5 clock synchronization and ckp bit when the ckp bit is cleared, the sclx output is forced to ? 0 ?. however, clearing the ckp bit will not assert the sclx output low until the sclx output is already sampled low. therefore, the ckp bit will not assert the sclx line until an external i 2 c master device has already asserted the sclx line. the sclx output will remain low until the ckp bit is set and all other devices on the i 2 c bus have deasserted sclx. this ensures that a write to the ckp bit will not violate the minimum high time requirement for sclx (see figure 18-14). figure 18-14: clock synchronization timing sdax sclx dx ? 1 dx wr q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 sspxcon1 ckp master device deasserts clock master device asserts clock
? 2009 microchip technology inc. preliminary ds39931b-page 297 pic18f46j50 family figure 18-15: i 2 c? slave mode timing with sen = 1 (reception, 7-bit address) sdax sclx sspxif (pir1<3> or pir3<7>) bf (sspxstat<0>) sspov (sspxcon1<6>) s 1 234 56 7 8 9 1 2345 67 89 1 23 45 7 89 p a7 a6 a5 a4 a3 a2 a1 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d1 d0 ack receiving data ack receiving data r/w = 0 ack receiving address cleared in software sspxbuf is read bus master terminates transfer sspov is set because sspxbuf is still full. ack is not sent. d2 6 ckp (sspxcon1<4>) ckp written to ? 1 ? in if bf is cleared prior to the falling edge of the 9th clock, ckp will not be reset to ? 0 ? and no clock stretching will occur software clock is held low until ckp is set to ? 1 ? clock is not held low because buffer full bit is clear prior to falling edge of 9th clock clock is not held low because ack = 1 bf is set after falling edge of the 9th clock, ckp is reset to ? 0 ? and clock stretching occurs
pic18f46j50 family ds39931b-page 298 preliminary ? 2009 microchip technology inc. figure 18-16: i 2 c? slave mode timing with sen = 1 (reception, 10-bit address) sdax sclx sspxif (pir1<3> or pir3<7>) bf (sspxstat<0>) s 123456789 123456789 12345 789 p 1 1 1 1 0 a9a8 a7 a6a5a4a3a2a1 a0 d7d6d5d4d3 d1d0 receive data byte ack r/w = 0 ack receive first byte of address cleared in software d2 6 cleared in software receive second byte of address cleared by hardware when sspxadd is updated with low byte of address after falling edge ua (sspxstat<1>) clock is held low until update of sspxadd has taken place ua is set indicating that the sspxadd needs to be updated ua is set indicating that sspxadd needs to be updated cleared by hardware when sspxadd is updated with high byte of address after falling edge sspxbuf is written with contents of sspxsr dummy read of sspxbuf to clear bf flag ack ckp (sspxcon1<4>) 12345 789 d7 d6 d5 d4 d3 d1 d0 receive data byte bus master terminates transfer d2 6 ack cleared in software cleared in software sspov (sspxcon1<6>) ckp written to ? 1 ? note: an update of the sspxadd register before the falling edge of the ninth clock will have no effect on ua and ua will remain set. note: an update of the sspxadd register before the falling edge of the ninth clock will have no effect on ua and ua will remain set. in software clock is held low until update of sspxadd has taken place of ninth clock of ninth clock sspov is set because sspxbuf is still full. ack is not sent. dummy read of sspxbuf to clear bf flag clock is held low until ckp is set to ? 1 ? clock is not held low because ack = 1
? 2009 microchip technology inc. preliminary ds39931b-page 299 pic18f46j50 family 18.5.5 general call address support the addressing procedure for the i 2 c bus is such that the first byte after the start condition usually determines which device will be the slave addressed by the master. the exception is the general call address which can address all devices. when this address is used, all devices should, in theory, respond with an acknowledge. the general call address is one of eight addresses reserved for specific purposes by the i 2 c protocol. it consists of all ? 0 ?s with r/w = 0 . the general call address is recognized when the general call enable bit, gcen, is enabled (sspxcon2<7> set). following a start bit detect, 8 bits are shifted into the sspxsr and the address is compared against the sspxadd. it is also compared to the general call address and fixed in hardware. if the general call address matches, the sspxsr is transferred to the sspxbuf, the bf flag bit is set (eighth bit), and on the falling edge of the ninth bit (ack bit), the sspxif interrupt flag bit is set. when the interrupt is serviced, the source for the interrupt can be checked by reading the contents of the sspxbuf. the value can be used to determine if the address was device-specific or a general call address. in 10-bit mode, the sspxadd is required to be updated for the second half of the address to match and the ua bit is set (sspxstat<1>). if the general call address is sampled when the gcen bit is set, while the slave is configured in 10-bit addressing mode, then the second half of the address is not necessary, the ua bit will not be set and the slave will begin receiving data after the acknowledge (figure 18-17). figure 18-17: slave mode general call address sequence (7-bit or 10-bit addressing mode) 18.5.6 master mode master mode is enabled by setting and clearing the appropriate sspm bits in sspxcon1 and by setting the sspen bit. in master mode, the sclx and sdax lines are manipulated by the mssp hardware if the tris bits are set. master mode of operation is supported by interrupt generation on the detection of the start and stop con- ditions. the start (s) and stop (p) bits are cleared from a reset or when the mssp module is disabled. control of the i 2 c bus may be taken when the stop bit is set, or the bus is idle, with both the start and stop bits clear. in firmware controlled master mode, user code conducts all i 2 c bus operations based on start and stop bit conditions. once master mode is enabled, the user has six options. 1. assert a start condition on sdax and sclx. 2. assert a repeated start condition on sdax and sclx. 3. write to the sspxbuf register initiating transmission of data/address. 4. configure the i 2 c port to receive data. 5. generate an acknowledge condition at the end of a received byte of data. 6. generate a stop condition on sdax and sclx. sdax sclx s sspxif bf (sspxstat<0>) sspov (sspxcon1<6>) cleared in software sspxbuf is read r/w = 0 ack general call address address is compared to general call address gcen (sspxcon2<7>) receiving data ack 123456789123456789 d7 d6 d5 d4 d3 d2 d1 d0 after ack , set interrupt ? 0 ? ? 1 ?
pic18f46j50 family ds39931b-page 300 preliminary ? 2009 microchip technology inc. the following events will cause the mssp interrupt flag bit, sspxif, to be set (and mssp interrupt, if enabled): ? start condition ? stop condition ? data transfer byte transmitted/received ? acknowledge transmitted ? repeated start figure 18-18: msspx block diagram (i 2 c? master mode) note: the mssp module, when configured in i 2 c master mode, does not allow queueing of events. for instance, the user is not allowed to initiate a start condition and immediately write the sspxbuf register to initiate transmission before the start condition is complete. in this case, the sspxbuf will not be written to and the wcol bit will be set, indicating that a write to the sspxbuf did not occur. read write sspxsr start bit, stop bit, sspxbuf internal data bus set/reset s, p (sspxstat), wcol (sspxcon1) shift clock msb lsb sdax acknowledge generate stop bit detect write collision detect clock arbitration state counter for end of xmit/rcv sclx sclx in bus collision sdax in receive enable clock cntl clock arbitrate/wcol detect (hold off clock source) sspxadd<6:0> baud set sspxif, bclxif reset ackstat, pen (sspxcon2) rate generator sspm<3:0> start bit detect
? 2009 microchip technology inc. preliminary ds39931b-page 301 pic18f46j50 family 18.5.6.1 i 2 c master mode operation the master device generates all of the serial clock pulses and the start and stop conditions. a transfer is ended with a stop condition or with a repeated start condition. since the repeated start condition is also the beginning of the next serial transfer, the i 2 c bus will not be released. in master transmitter mode, serial data is output through sdax while sclx outputs the serial clock. the first byte transmitted contains the slave address of the receiving device (7 bits) and the read/write (r/w ) bit. in this case, the r/w bit will be logic ? 0 ?. serial data is transmitted 8 bits at a time. after each byte is transmit- ted, an acknowledge bit is received. s and p conditions are output to indicate the beginning and the end of a serial transfer. in master receive mode, the first byte transmitted contains the slave address of the transmitting device (7 bits) and the r/w bit. in this case, the r/w bit will be logic ? 1 ?. thus, the first byte transmitted is a 7-bit slave address, followed by a ? 1 ? to indicate the receive bit. serial data is received via sdax, while sclx outputs the serial clock. serial data is received 8 bits at a time. after each byte is received, an acknowledge bit is transmitted. s and p conditions indicate the beginning and end of transmission. the brg, used for the spi mode operation, is used to set the sclx clock frequency for either 100 khz, 400 khz or 1 mhz i 2 c operation. see section 18.5.7 ?baud rate? for more details. a typical transmit sequence would go as follows: 1. the user generates a start condition by setting the start enable bit, sen (sspxcon2<0>). 2. sspxif is set. the mssp module will wait for the required start time before any other operation takes place. 3. the user loads the sspxbuf with the slave address to transmit. 4. address is shifted out of the sdax pin until all 8 bits are transmitted. 5. the mssp module shifts in the ack bit from the slave device and writes its value into the sspxcon2 register (sspxcon2<6>). 6. the mssp module generates an interrupt at the end of the ninth clock cycle by setting the sspxif bit. 7. the user loads the sspxbuf with 8 bits of data. 8. data is shifted out the sdax pin until all 8 bits are transmitted. 9. the mssp module shifts in the ack bit from the slave device and writes its value into the sspxcon2 register (sspxcon2<6>). 10. the mssp module generates an interrupt at the end of the ninth clock cycle by setting the sspxif bit. 11. the user generates a stop condition by setting the stop enable bit, pen (sspxcon2<2>). 12. interrupt is generated once the stop condition is complete. 18.5.7 baud rate in i 2 c master mode, the brg reload value is placed in the lower seven bits of the sspxadd register (figure 18-19). when a write occurs to sspxbuf, the baud rate generator will automatically begin counting. the brg counts down to 0 and stops until another reload has taken place. the brg count is decre- mented twice per instruction cycle (t cy ) on the q2 and q4 clocks. in i 2 c master mode, the brg is reloaded automatically. once the given operation is complete (i.e., transmis- sion of the last data bit is followed by ack ), the internal clock will automatically stop counting and the sclx pin will remain in its last state. table 18-3 demonstrates clock rates based on instruction cycles and the brg value loaded into sspxadd.
pic18f46j50 family ds39931b-page 302 preliminary ? 2009 microchip technology inc. 18.5.7.1 baud rate and module interdependence because mssp1 and mssp2 are independent, they can operate simultaneously in i 2 c master mode at different baud rates. this is done by using different brg reload values for each module. because this mode derives its basic clock source from the system clock, any changes to the clock will affect both modules in the same proportion. it may be possible to change one or both baud rates back to a previous value by changing the brg reload value. figure 18-19: baud rate generator block diagram table 18-3: i 2 c? clock rate w/brg f osc f cy f cy * 2 brg value f scl (2 rollovers of brg) 40 mhz 10 mhz 20 mhz 18h 400 khz (1) 40 mhz 10 mhz 20 mhz 1fh 312.5 khz 40 mhz 10 mhz 20 mhz 63h 100 khz 16 mhz 4 mhz 8 mhz 09h 400 khz (1) 16 mhz 4 mhz 8 mhz 0ch 308 khz 16 mhz 4 mhz 8 mhz 27h 100 khz 4 mhz 1 mhz 2 mhz 02h 333 khz (1) 4 mhz 1 mhz 2 mhz 09h 100 khz 4 mhz 1 mhz 2 mhz 00h 1 mhz (1) note 1: the i 2 c interface does not conform to the 400 khz i 2 c specification (which applies to rates greater than 100 khz) in all details, but may be used with care where higher rates are required by the application. sspm<3:0> brg down counter clko f osc /4 sspxadd<6:0> sspm<3:0> sclx reload control reload
? 2009 microchip technology inc. preliminary ds39931b-page 303 pic18f46j50 family 18.5.7.2 clock arbitration clock arbitration occurs when the master, during any receive, transmit or repeated start/stop condition, deasserts the sclx pin (sclx allowed to float high). when the sclx pin is allowed to float high, the brg is suspended from counting until the sclx pin is actually sampled high. when the sclx pin is sampled high, the brg is reloaded with the contents of sspxadd<6:0> and begins counting. this ensures that the sclx high time will always be at least one brg rollover count in the event that the clock is held low by an external device (figure 18-20). figure 18-20: baud rate generator timing with cl ock arbitration 18.5.8 i 2 c master mode start condition timing to initiate a start condition, the user sets the start enable bit, sen (sspxcon2<0>). if the sdax and sclx pins are sampled high, the brg is reloaded with the contents of sspxadd<6:0> and starts its count. if sclx and sdax are both sampled high when the baud rate generator times out (t brg ), the sdax pin is driven low. the action of the sdax being driven low while sclx is high is the start condition and causes the start bit (sspxstat<3>) to be set. following this, the brg is reloaded with the contents of sspxadd<6:0> and resumes its count. when the brg times out (t brg ), the sen bit (sspxcon2<0>) will be automatically cleared by hardware. the brg is sus- pended, leaving the sdax line held low and the start condition is complete. 18.5.8.1 wcol status flag if the user writes the sspxbuf when a start sequence is in progress, the wcol bit is set and the contents of the buffer are unchanged (the write does not occur). figure 18-21: first start bit timing sdax sclx sclx deasserted but slave holds dx ? 1 dx brg sclx is sampled high, reload takes place and brg starts its count 03h 02h 01h 00h (hold off) 03h 02h reload brg value sclx low (clock arbitration) sclx allowed to transition high brg decrements on q2 and q4 cycles note: if, at the beginning of the start condition, the sdax and sclx pins are already sampled low, or if during the start condition, the sclx line is sampled low, before the sdax line is driven low, a bus collision occurs, the bus collision interrupt flag, bclxif, is set, the start condition is aborted and the i 2 c module is reset into its idle state. note: because queueing of events is not allowed, writing to the lower five bits of sspxcon2 is disabled until the start condition is complete. sdax sclx s t brg 1st bit 2nd bit t brg sdax = 1 , at completion of start bit, sclx = 1 write to sspxbuf occurs here t brg hardware clears sen bit t brg write to sen bit occurs here set s bit (sspxstat<3>) and sets sspxif bit
pic18f46j50 family ds39931b-page 304 preliminary ? 2009 microchip technology inc. 18.5.9 i 2 c master mode repeated start condition timing a repeated start condition occurs when the rsen bit (sspxcon2<1>) is programmed high and the i 2 c logic module is in the idle state. when the rsen bit is set, the sclx pin is asserted low. when the sclx pin is sampled low, the brg is loaded with the contents of sspxadd<5:0> and begins counting. the sdax pin is released (brought high) for one brg count (t brg ). when the brg times out, and if sdax is sampled high, the sclx pin will be deasserted (brought high). when sclx is sampled high, the brg is reloaded with the contents of sspxadd<6:0> and begins counting. sdax and sclx must be sampled high for one t brg . this action is then followed by assertion of the sdax pin (sdax = 0 ) for one t brg while sclx is high. following this, the rsen bit (sspxcon2<1>) will be automatically cleared and the brg will not be reloaded, leaving the sdax pin held low. as soon as a start condition is detected on the sdax and sclx pins, the start bit (sspxstat<3>) will be set. the sspxif bit will not be set until the brg has timed out. immediately following the sspxif bit getting set, the user may write the sspxbuf with the 7-bit address in 7-bit mode, or the default first address in 10-bit mode. after the first eight bits are transmitted and an ack is received, the user may then transmit an additional 8 bits of address (10-bit mode) or 8 bits of data (7-bit mode). 18.5.9.1 wcol status flag if the user writes the sspxbuf when a repeated start sequence is in progress, the wcol is set and the contents of the buffer are unchanged (the write does not occur). figure 18-22: repeated start condition waveform note 1: if rsen is programmed while any other event is in progress, it will not take effect. 2: a bus collision during the repeated start condition occurs if: ? sdax is sampled low when sclx goes from low-to-high. ? sclx goes low before sdax is asserted low. this may indicate that another master is attempting to transmit a data ? 1 ?. note: because queueing of events is not allowed, writing of the lower five bits of sspxcon2 is disabled until the repeated start condition is complete. sdax sclx sr = repeated start write to sspxcon2 write to sspxbuf occurs here on falling edge of ninth clock, end of xmit at completion of start bit, hardware clears rsen bit 1st bit s bit set by hardware t brg sdax = 1 , sdax = 1 , sclx (no change). sclx = 1 occurs here: and sets sspxif rsen bit set by hardware t brg t brg t brg t brg
? 2009 microchip technology inc. preliminary ds39931b-page 305 pic18f46j50 family 18.5.10 i 2 c master mode transmission transmission of a data byte, a 7-bit address or the other half of a 10-bit address, is accomplished by simply writing a value to the sspxbuf register. this action will set the buffer full flag bit, bf, and allow the brg to begin counting and start the next transmission. each bit of address/data will be shifted out onto the sdax pin after the falling edge of sclx is asserted (see data hold time specification parameter 106). sclx is held low for one brg rollover count (t brg ). data should be valid before sclx is released high (see data setup time specification parameter 107). when the sclx pin is released high, it is held that way for t brg . the data on the sdax pin must remain stable for that duration and some hold time after the next falling edge of sclx. after the eighth bit is shifted out (the falling edge of the eighth clock), the bf flag is cleared and the master releases sdax. this allows the slave device being addressed to respond with an ack bit during the ninth bit time if an address match occurred, or if data was received properly. the status of ack is written into the ackdt bit on the falling edge of the ninth clock. if the master receives an acknowledge, the acknowl- edge status bit, ackstat, is cleared; if not, the bit is set. after the ninth clock, the sspxif bit is set and the master clock (brg) is suspended until the next data byte is loaded into the sspxbuf, leaving sclx low and sdax unchanged (figure 18-23). after the write to the sspxbuf, each bit of the address will be shifted out on the falling edge of sclx until all seven address bits and the r/w bit are completed. on the falling edge of the eighth clock, the master will deassert the sdax pin, allowing the slave to respond with an acknowledge. on the falling edge of the ninth clock, the master will sample the sdax pin to see if the address was recognized by a slave. the status of the ack bit is loaded into the ackstat status bit (sspxcon2<6>). following the falling edge of the ninth clock transmission of the address, the sspxif flag is set, the bf flag is cleared and the brg is turned off until another write to the sspxbuf takes place, holding sclx low and allowing sdax to float. 18.5.10.1 bf status flag in transmit mode, the bf bit (sspxstat<0>) is set when the cpu writes to sspxbuf and is cleared when all eight bits are shifted out. 18.5.10.2 wcol status flag if the user writes the sspxbuf when a transmit is already in progress (i.e., sspxsr is still shifting out a data byte), the wcol bit is set and the contents of the buffer are unchanged (the write does not occur) after 2t cy after the sspxbuf write. if sspxbuf is rewritten within 2 t cy , the wcol bit is set and sspxbuf is updated. this may result in a corrupted transfer. the user should verify that the wcol bit is clear after each write to sspxbuf to ensure the transfer is correct. in all cases, wcol must be cleared in software. 18.5.10.3 ackstat status flag in transmit mode, the ackstat bit (sspxcon2<6>) is cleared when the slave has sent an acknowledge (ack = 0 ) and is set when the slave does not acknowl- edge (ack = 1 ). a slave sends an acknowledge when it has recognized its address (including a general call), or when the slave has properly received its data. 18.5.11 i 2 c master mode reception master mode reception is enabled by programming the receive enable bit, rcen (sspxcon2<3>). the brg begins counting and on each rollover, the state of the sclx pin changes (high-to-low/low-to-high) and data is shifted into the sspxsr. after the falling edge of the eighth clock, the receive enable flag is automatically cleared, the contents of the sspxsr are loaded into the sspxbuf, the bf flag bit is set, the sspxif flag bit is set and the brg is suspended from counting, holding sclx low. the mssp is now in idle state awaiting the next command. when the buffer is read by the cpu, the bf flag bit is automatically cleared. the user can then send an acknowledge bit at the end of reception by setting the acknowledge sequence enable bit, acken (sspxcon2<4>). 18.5.11.1 bf status flag in receive operation, the bf bit is set when an address or data byte is loaded into sspxbuf from sspxsr. it is cleared when the sspxbuf register is read. 18.5.11.2 sspov status flag in receive operation, the sspov bit is set when 8 bits are received into the sspxsr and the bf flag bit is already set from a previous reception. 18.5.11.3 wcol status flag if users write the sspxbuf when a receive is already in progress (i.e., sspxsr is still shifting in a data byte), the wcol bit is set and the contents of the buffer are unchanged (the write does not occur). note: the mssp module must be in an inactive state before the rcen bit is set or the rcen bit will be disregarded.
pic18f46j50 family ds39931b-page 306 preliminary ? 2009 microchip technology inc. figure 18-23: i 2 c? master mode waveform (transmission, 7-bit or 10-bit address) sdax sclx sspxif bf (sspxstat<0>) sen a7 a6 a5 a4 a3 a2 a1 ack = 0 d7 d6 d5 d4 d3 d2 d1 d0 ack transmitting data or second half r/w = 0 transmit address to slave 123456789 123456789 p cleared in software service routine sspxbuf is written in software from mssp interrupt after start condition, sen cleared by hardware s sspxbuf written with 7-bit address and r/w , start transmit sclx held low while cpu responds to sspxif sen = 0 of 10-bit address write sspxcon2<0> (sen = 1 ), start condition begins from slave, clear ackstat bit (sspxcon2<6>) ackstat in sspxcon2 = 1 cleared in software sspxbuf written pen r/w cleared in software
? 2009 microchip technology inc. preliminary ds39931b-page 307 pic18f46j50 family figure 18-24: i 2 c? master mode waveform (reception, 7-bit address) p 9 8 7 6 5 d0 d1 d2 d3 d4 d5 d6 d7 s a7 a6 a5 a4 a3 a2 a1 sdax sclx 12 3 4 5 6 7 8 9 12 3 4 5 678 9 1234 bus master terminates transfer ack receiving data from slave receiving data from slave d0 d1 d2 d3 d4 d5 d6 d7 ack r/w = 0 transmit address to slave sspxif bf ack is not sent write to sspxcon2<0> (sen = 1 ), write to sspxbuf occurs here, ack from slave master configured as a receiver by programming sspxcon2<3> (rcen = 1 ) pen bit = 1 written here data shifted in on falling edge of clk cleared in software start xmit sen = 0 sspov sdax = 0 , sclx = 1 , while cpu (sspxstat<0>) ack cleared in software cleared in software set sspxif interrupt at end of receive set p bit (sspxstat<4>) and sspxif ack from master, set sspxif at end set sspxif interrupt at end of acknowledge sequence set sspxif interrupt at end of acknowledge sequence of receive set acken, start acknowledge sequence, sdax = ackdt = 1 rcen cleared automatically rcen = 1 , start next receive write to sspxcon2<4> to start acknowledge sequence, sdax = ackdt (sspxcon2<5>) = 0 rcen cleared automatically responds to sspxif acken begin start condition cleared in software sdax = ackdt = 0 last bit is shifted into sspxsr and contents are unloaded into sspxbuf cleared in software sspov is set because sspxbuf is still full
pic18f46j50 family ds39931b-page 308 preliminary ? 2009 microchip technology inc. 18.5.12 acknowledge sequence timing an acknowledge sequence is enabled by setting the acknowledge sequence enable bit, acken (sspxcon2<4>). when this bit is set, the sclx pin is pulled low and the contents of the acknowledge data bit are presented on the sdax pin. if the user wishes to generate an acknowledge, then the ackdt bit should be cleared. if not, the user should set the ackdt bit before starting an acknowledge sequence. the brg then counts for one rollover period (t brg ) and the sclx pin is deasserted (pulled high). when the sclx pin is sampled high (clock arbitration), the brg counts for t brg ; the sclx pin is then pulled low. following this, the acken bit is automatically cleared, the brg is turned off and the mssp module then goes into an inactive state (figure 18-25). 18.5.12.1 wcol status flag if the user writes the sspxbuf when an acknowledge sequence is in progress, then wcol is set and the contents of the buffer are unchanged (the write does not occur). 18.5.13 stop condition timing a stop bit is asserted on the sdax pin at the end of a receive/transmit by setting the stop sequence enable bit, pen (sspxcon2<2>). at the end of a receive/transmit, the sclx line is held low after the falling edge of the ninth clock. when the pen bit is set, the master will assert the sdax line low. when the sdax line is sampled low, the brg is reloaded and counts down to 0 . when the brg times out, the sclx pin will be brought high and one baud rate generator rollover count (t brg ) later, the sdax pin will be deasserted. when the sdax pin is sampled high while sclx is high, the stop bit (sspxstat<4>) is set. a t brg later, the pen bit is cleared and the sspxif bit is set (figure 18-26). 18.5.13.1 wcol status flag if the user writes the sspxbuf when a stop sequence is in progress, then the wcol bit is set and the contents of the buffer are unchanged (the write does not occur). figure 18-25: acknowledge sequence waveform figure 18-26: stop condition receive or transmit mode sdax sclx sspxif set at acknowledge sequence starts here, write to sspxcon2, acken automatically cleared cleared in t brg t brg the end of receive 8 acken = 1 , ackdt = 0 d0 9 sspxif software sspxif set at the end of acknowledge sequence cleared in software ack note: t brg = one baud rate generator period. sclx sdax sdax asserted low before rising edge of clock write to sspxcon2, set pen falling edge of sclx = 1 for t brg , followed by sdax = 1 for t brg 9th clock sclx brought high after t brg t brg t brg after sdax sampled high. p bit (sspxstat<4>) is set t brg to set up stop condition ack p t brg pen bit (sspxcon2<2>) is cleared by hardware and the sspxif bit is set note: t brg = one baud rate generator period.
? 2009 microchip technology inc. preliminary ds39931b-page 309 pic18f46j50 family 18.5.14 sleep operation while in sleep mode, the i 2 c module can receive addresses or data and when an address match or complete byte transfer occurs, wake the processor from sleep (if the mssp interrupt is enabled). 18.5.15 effects of a reset a reset disables the mssp module and terminates the current transfer. 18.5.16 multi-master mode in multi-master mode, the interrupt generation on the detection of the start and stop conditions allows the determination of when the bus is free. the start and stop bits are cleared from a reset or when the mssp module is disabled. control of the i 2 c bus may be taken when the p bit (sspxstat<4>) is set, or the bus is idle, with both the start and stop bits clear. when the bus is busy, enabling the mssp interrupt will generate the interrupt when the stop condition occurs. in multi-master operation, the sdax line must be monitored for arbitration to see if the signal level is the expected output level. this check is performed in hardware with the result placed in the bclxif bit. the states where arbitration can be lost are: ? address transfer ? data transfer ? a start condition ? a repeated start condition ? an acknowledge condition 18.5.17 multi -master communication, bus collision and bus arbitration multi-master mode support is achieved by bus arbitra- tion. when the master outputs address/data bits onto the sdax pin, arbitration takes place when the master out- puts a ? 1 ? on sdax, by letting sdax float high and another master asserts a ? 0 ?. when the sclx pin floats high, data should be stable. if the expected data on sdax is a ? 1 ? and the data sampled on the sdax pin = 0 , then a bus collision has taken place. the master will set the bus collision interrupt flag, bclxif, and reset the i 2 c port to its idle state (figure 18-27). if a transmit was in progress when the bus collision occurred, the transmission is halted, the bf flag is cleared, the sdax and sclx lines are deasserted and the sspxbuf can be written to. when the user services the bus collision interrupt service routine and if the i 2 c bus is free, the user can resume communication by asserting a start condition. if a start, repeated start, stop or acknowledge condition was in progress when the bus collision occurred, the con- dition is aborted, the sdax and sclx lines are deasserted and the respective control bits in the sspxcon2 register are cleared. when the user services the bus collision interrupt service routine (isr), and if the i 2 c bus is free, the user can resume communication by asserting a start condition. the master will continue to monitor the sdax and sclx pins. if a stop condition occurs, the sspxif bit will be set. a write to the sspxbuf will start the transmission of data at the first data bit regardless of where the transmitter left off when the bus collision occurred. in multi-master mode, the interrupt generation on the detection of start and stop conditions allows the deter- mination of when the bus is free. control of the i 2 c bus can be taken when the stop bit is set in the sspxstat register, or the bus is idle and the start and stop bits are cleared. figure 18-27: bus collision timing for transmit and acknowledge sdax sclx bclxif sdax released sdax line pulled low by another source sample sdax. while sclx is high, data doesn?t match what is driven bus collision has occurred set bus collision interrupt (bclxif) by the master; by master data changes while sclx = 0
pic18f46j50 family ds39931b-page 310 preliminary ? 2009 microchip technology inc. 18.5.17.1 bus collision during a start condition during a start condition, a bus collision occurs if: a) sdax or sclx is sampled low at the beginning of the start condition (figure 18-28). b) sclx is sampled low before sdax is asserted low (figure 18-29). during a start condition, both the sdax and the sclx pins are monitored. if the sdax pin is already low, or the sclx pin is already low, then all of the following occur: ? the start condition is aborted ? the bclxif flag is set ? the mssp module is reset to its inactive state (figure 18-28) the start condition begins with the sdax and sclx pins deasserted. when the sdax pin is sampled high, the brg is loaded from sspxadd<6:0> and counts down to 0. if the sclx pin is sampled low while sdax is high, a bus collision occurs because it is assumed that another master is attempting to drive a data ? 1 ? during the start condition. if the sdax pin is sampled low during this count, the brg is reset and the sdax line is asserted early (figure 18-30). if, however, a ? 1 ? is sampled on the sdax pin, the sdax pin is asserted low at the end of the brg count. the brg is then reloaded and counts down to 0. if the sclx pin is sampled as ? 0 ? during this time, a bus collision does not occur. at the end of the brg count, the sclx pin is asserted low. figure 18-28: bus collision duri ng start condition (sdax only) note: the reason that bus collision is not a factor during a start condition is that no two bus masters can assert a start condition at the exact same time. therefore, one master will always assert sdax before the other. this condition does not cause a bus colli- sion because the two masters must be allowed to arbitrate the first address following the start condition. if the address is the same, arbitration must be allowed to continue into the data portion, repeated start or stop conditions. sdax sclx sen sdax sampled low before sdax goes low before the sen bit is set. s bit and sspxif set because msspx module reset into idle state. sen cleared automatically because of bus collision. s bit and sspxif set because set sen, enable start condition if sdax = 1 , sclx = 1 sdax = 0 , sclx = 1 . bclxif s sspxif sdax = 0 , sclx = 1 . sspxif and bclxif are cleared in software sspxif and bclxif are cleared in software set bclxif, start condition. set bclxif.
? 2009 microchip technology inc. preliminary ds39931b-page 311 pic18f46j50 family figure 18-29: bus collision d uring start condition (sclx = 0 ) figure 18-30: brg reset due to sdax arbitration during start condition sdax sclx sen bus collision occurs. set bclxif. sclx = 0 before sdax = 0 , set sen, enable start sequence if sdax = 1 , sclx = 1 t brg t brg sdax = 0 , sclx = 1 bclxif s sspxif interrupt cleared in software bus collision occurs. set bclxif. sclx = 0 before brg time-out, ? 0 ?? 0 ? ? 0 ? ? 0 ? sdax sclx sen set s less than t brg t brg sdax = 0 , sclx = 1 bclxif s sspxif s interrupts cleared in software set sspxif sdax = 0 , sclx = 1 , sclx pulled low after brg time-out set sspxif ? 0 ? sdax pulled low by other master. reset brg and assert sdax. set sen, enable start sequence if sdax = 1 , sclx = 1
pic18f46j50 family ds39931b-page 312 preliminary ? 2009 microchip technology inc. 18.5.17.2 bus collision during a repeated start condition during a repeated start condition, a bus collision occurs if: a) a low level is sampled on sdax when sclx goes from a low level to a high level. b) sclx goes low before sdax is asserted low, indicating that another master is attempting to transmit a data ? 1 ?. when the user deasserts sdax and the pin is allowed to float high, the brg is loaded with sspxadd<6:0> and counts down to 0. the sclx pin is then deasserted and when sampled high, the sdax pin is sampled. if sdax is low, a bus collision has occurred (i.e., another master is attempting to transmit a data ? 0 ?, see figure 18-31). if sdax is sampled high, the brg is reloaded and begins counting. if sdax goes from high-to-low before the brg times out, no bus collision occurs because no two masters can assert sdax at exactly the same time. if sclx goes from high-to-low before the brg times out and sdax has not already been asserted, a bus collision occurs. in this case, another master is attempting to transmit a data ? 1 ? during the repeated start condition (see figure 18-32). if, at the end of the brg time-out, both sclx and sdax are still high, the sdax pin is driven low and the brg is reloaded and begins counting. at the end of the count, regardless of the status of the sclx pin, the sclx pin is driven low and the repeated start condition is complete. figure 18-31: bus collision during a repeated start condition (case 1) figure 18-32: bus collision during repeated start condition (case 2) sdax sclx rsen bclxif s sspxif sample sdax when sclx goes high. if sdax = 0 , set bclxif and release sdax and sclx. cleared in software ? 0 ? ? 0 ? sdax sclx bclxif rsen s sspxif interrupt cleared in software sclx goes low before sdax, set bclxif. release sdax and sclx. t brg t brg ? 0 ?
? 2009 microchip technology inc. preliminary ds39931b-page 313 pic18f46j50 family 18.5.17.3 bus collision during a stop condition bus collision occurs during a stop condition if: a) after the sdax pin has been deasserted and allowed to float high, sdax is sampled low after the brg has timed out. b) after the sclx pin is deasserted, sclx is sampled low before sdax goes high. the stop condition begins with sdax asserted low. when sdax is sampled low, the sclx pin is allowed to float. when the pin is sampled high (clock arbitration), the brg is loaded with sspxadd<6:0> and counts down to 0. after the brg times out, sdax is sampled. if sdax is sampled low, a bus collision has occurred. this is due to another master attempting to drive a data ? 0 ? (figure 18-33). if the sclx pin is sampled low before sdax is allowed to float high, a bus collision occurs. this is another case of another master attempting to drive a data ? 0 ? (figure 18-34). figure 18-33: bus collision during a stop condition (case 1) figure 18-34: bus collision during a stop condition (case 2) sdax sclx bclxif pen p sspxif t brg t brg t brg sdax asserted low sdax sampled low after t brg , set bclxif ? 0 ? ? 0 ? sdax sclx bclxif pen p sspxif t brg t brg t brg assert sdax sclx goes low before sdax goes high, set bclxif ? 0 ? ? 0 ?
pic18f46j50 family ds39931b-page 314 preliminary ? 2009 microchip technology inc. table 18-4: registers associated with i 2 c? operation name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 61 pir1 pmpif (3) adif rc1if tx1if ssp1if ccp1if tmr2if tmr1if 63 pie1 pmpie (3) adie rc1ie tx1ie ssp1ie ccp1ie tmr2ie tmr1ie 63 ipr1 pmpip (3) adip rc1ip tx1ip ssp1ip ccp1ip tmr2ip tmr1ip 63 pir2 oscfif cm2if cm1if usbif bcl1if hlvdif tmr3if ccp2if 63 pie2 oscfie cm2ie cm1ie usbie bcl1ie hlvdie tmr3ie ccp2ie 63 ipr2 oscfip cm2ip cm1ip usbip bcl1ip hlvdip tmr3ip ccp2ip 63 pir3 ssp2if bcl2if rc2if tx2if tmr4if ctmuif tmr3gif rtccif 63 pie3 ssp2ie bcl2ie rc2ie tx2ie tmr4ie ctmuie tmr3gie rtccie 63 ipr3 ssp2ip bcl2ip rc2ip tx2ip tmr4ip ctmuip tmr3gip rtccip 63 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 64 trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 64 ssp1buf mssp1 receive buffer/transmit register 63 sspxadd mssp1 address register (i 2 c? slave mode), mssp1 baud rate reload register (i 2 c master mode) 62, 65 sspxmsk (1) msk7 msk6 msk5 msk4 msk3 msk2 msk1 msk0 62, 65 sspxcon1 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 62, 65 sspxcon2 gcen ackstat ackdt acken rcen pen rsen sen 62, 65 gcen ackstat admsk5 (2) admsk4 (2) admsk3 (2) admsk2 (2) admsk1 (2) sen sspxstat smp cke d/a psr/w ua bf 62, 65 ssp2buf mssp2 receive buffer/transmit register 65 ssp2add mssp2 address register (i 2 c slave mode), mssp2 baud rate reload register (i 2 c master mode) 65 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the msspx module in i 2 c? mode. note 1: sspxmsk shares the same address in sfr space as sspxadd, but is only accessible in certain i 2 c slave mode operations in 7-bit masking mode. see section 18.5.3.4 ?7-bit address masking mode? for more details. 2: alternate bit definitions for use in i 2 c slave mode operations only. 3: these bits are only available on 44-pin devices.
? 2009 microchip technology inc. preliminary ds39931b-page 315 pic18f46j50 family 19.0 enhanced universal synchronous asynchronous receiver transmitter (eusart) the enhanced universal synchronous asynchronous receiver transmitter (eusart) module is one of two serial i/o modules. (generically, the eusart is also known as a serial communications interface or sci.) the eusart can be configured as a full-duplex asynchronous system that can communicate with peripheral devices, such as crt terminals and personal computers. it can also be configured as a half-duplex synchronous system that can communicate with peripheral devices, such as a/d or d/a integrated circuits, serial eeproms and so on. the enhanced usart module implements additional features, including automatic baud rate detection and calibration, automatic wake-up on sync break recep- tion and 12-bit break character transmit. these make it ideally suited for use in local interconnect network bus (lin bus) systems. all members of the pic18f46j50 family are equipped with two independent eusart modules, referred to as eusart1 and eusart2. they can be configured in the following modes: ? asynchronous (full-duplex) with: - auto-wake-up on character reception - auto-baud calibration - 12-bit break character transmission ? synchronous ? master (half-duplex) with selectable clock polarity ? synchronous ? slave (half-duplex) with selectable clock polarity the pins of eusart1 and eusart2 are multiplexed with the functions of portc (rc6/tx1/ck1/rp17 and rc7/rx1/dt1/sdo1/rp18) and remapped (rpn1/tx2/ck2 and rpn2/rx2/dt2), respectively. in order to configure these pins as an eusart: ? for eusart1: - spen bit (rcsta1<7>) must be set (= 1 ) - trisc<7> bit must be set (= 1 ) - trisc<6> bit must be cleared (= 0 ) for asynchronous and synchronous master modes - trisc<6> bit must be set (= 1 ) for synchronous slave mode ? for eusart2: - spen bit (rcsta2<7>) must be set (= 1 ) - tris bit for rpn2/rx2/dt2 = 1 - tris bit for rpn1/tx2/ck2 = 0 for asynchronous and synchronous master modes - trisc<6> bit must be set (= 1 ) for synchronous slave mode the txx/ckx i/o pins have an optional open-drain output capability. by default, when this pin is used by the eusart as an output, it will function as a standard push-pull cmos output. the txx/ckx i/o pins? open-drain, output feature can be enabled by setting the corresponding uxod bit in the odcon2 register. for more details, see section 18.3.3 ?open-drain output option? . the operation of each enhanced usart module is controlled through three registers: ? transmit status and control (txstax) ? receive status and control (rcstax) ? baud rate control (baudconx) these are covered in detail in register 19-1, register 19-2 and register 19-3, respectively. note: the eusart control will automatically reconfigure the pin from input to output as needed. note: throughout this section, references to register and bit names that may be associ- ated with a specific eusart module are referred to generically by the use of ?x? in place of the specific module number. thus, ?rcstax? might refer to the receive status register for either eusart1 or eusart2.
pic18f46j50 family ds39931b-page 316 preliminary ? 2009 microchip technology inc. register 19-1: txstax: transmit status and control register (access fadh, fa8h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-1 r/w-0 csrc tx9 txen (1) sync sendb brgh trmt tx9d bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 csrc: clock source select bit asynchronous mode: don?t care. synchronous mode: 1 = master mode (clock generated internally from brg) 0 = slave mode (clock from external source) bit 6 tx9: 9-bit transmit enable bit 1 = selects 9-bit transmission 0 = selects 8-bit transmission bit 5 txen: transmit enable bit (1) 1 = transmit enabled 0 = transmit disabled bit 4 sync: eusart mode select bit 1 = synchronous mode 0 = asynchronous mode bit 3 sendb: send break character bit asynchronous mode: 1 = send sync break on next transmission (cleared by hardware upon completion) 0 = sync break transmission completed synchronous mode: don?t care. bit 2 brgh: high baud rate select bit asynchronous mode: 1 = high speed 0 = low speed synchronous mode: unused in this mode. bit 1 trmt: transmit shift register status bit 1 = tsr empty 0 = tsr full bit 0 tx9d: 9 th bit of transmit data can be address/data bit or a parity bit. note 1: sren/cren overrides txen in sync mode.
? 2009 microchip technology inc. preliminary ds39931b-page 317 pic18f46j50 family register 19-2: rcstax: receive status and control register (access fach, f9ch) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 r-0 r-x spen rx9 sren cren adden ferr oerr rx9d bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 spen: serial port enable bit 1 = serial port enabled (configures rxx/dtx and txx/ckx pins as serial port pins) 0 = serial port disabled (held in reset) bit 6 rx9: 9-bit receive enable bit 1 = selects 9-bit reception 0 = selects 8-bit reception bit 5 sren: single receive enable bit asynchronous mode : don?t care. synchronous mode ? master: 1 = enables single receive 0 = disables single receive this bit is cleared after reception is complete. synchronous mode ? slave: don?t care. bit 4 cren: continuous receive enable bit asynchronous mode: 1 = enables receiver 0 = disables receiver synchronous mode: 1 = enables continuous receive until enable bit, cren, is cleared (cren overrides sren) 0 = disables continuous receive bit 3 adden: address detect enable bit asynchronous mode 9-bit (rx9 = 1 ) : 1 = enables address detection, enables interrupt and loads the receive buffer when rsr<8> is set 0 = disables address detection, all bytes are received and ninth bit can be used as parity bit asynchronous mode 9-bit (rx9 = 0 ) : don?t care. bit 2 ferr: framing error bit 1 = framing error (can be updated by reading rcregx register and receiving next valid byte) 0 = no framing error bit 1 oerr: overrun error bit 1 = overrun error (can be cleared by clearing bit cren) 0 = no overrun error bit 0 rx9d: 9 th bit of received data this can be address/data bit or a parity bit and must be calculated by user firmware.
pic18f46j50 family ds39931b-page 318 preliminary ? 2009 microchip technology inc. register 19-3: baudconx: baud rate contro l register (access f7eh, f7ch) r/w-0 r-1 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 abdovf rcidl rxdtp txckp brg16 ? wue abden bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 abdovf: auto-baud acquisition rollover status bit 1 = a brg rollover has occurred during auto-baud rate detect mode (must be cleared in software) 0 = no brg rollover has occurred bit 6 rcidl: receive operation idle status bit 1 = receive operation is idle 0 = receive operation is active bit 5 rxdtp: data/receive polarity select bit asynchronous mode: 1 = receive data (rxx) is inverted (active-low) 0 = receive data (rxx) is not inverted (active-high) synchronous mode: 1 = data (dtx) is inverted (active-low) 0 = data (dtx) is not inverted (active-high) bit 4 txckp: synchronous clock polarity select bit asynchronous mode: 1 = idle state for transmit (txx) is a low level 0 = idle state for transmit (txx) is a high level synchronous mode: 1 = idle state for clock (ckx) is a high level 0 = idle state for clock (ckx) is a low level bit 3 brg16: 16-bit baud rate register enable bit 1 = 16-bit baud rate generator ? spbrghx and spbrgx 0 = 8-bit baud rate generator ? spbrgx only (compatible mode), spbrghx value ignored bit 2 unimplemented: read as ? 0 ? bit 1 wue: wake-up enable bit asynchronous mode: 1 = eusart will continue to sample the rxx pin ? interrupt generated on falling edge; bit cleared in hardware on following rising edge 0 = rxx pin not monitored or rising edge detected synchronous mode: unused in this mode. bit 0 abden: auto-baud detect enable bit asynchronous mode: 1 = enable baud rate measurement on the next character; requires reception of a sync field (55h); cleared in hardware upon completion 0 = baud rate measurement disabled or completed synchronous mode: unused in this mode.
? 2009 microchip technology inc. preliminary ds39931b-page 319 pic18f46j50 family 19.1 baud rate generator (brg) the brg is a dedicated, 8-bit or 16-bit generator that supports both the asynchronous and synchronous modes of the eusart. by default, the brg operates in 8-bit mode; setting the brg16 bit (baudconx<3>) selects 16-bit mode. the spbrghx:spbrgx register pair controls the period of a free-running timer. in asynchronous mode, bits brgh (txstax<2>) and brg16 (baudconx<3>) also control the baud rate. in synchronous mode, brgh is ignored. table 19-1 provides the formula for computation of the baud rate for different eusart modes, which only apply in master mode (internally generated clock). given the desired baud rate and f osc , the nearest integer value for the spbrghx:spbrgx registers can be calculated using the formulas in table 19-1. from this, the error in baud rate can be determined. an example calculation is provided in example 19-1. typical baud rates and error values for the various asynchronous modes are provided in table 19-2. it may be advantageous to use the high baud rate (brgh = 1 ) or the 16-bit brg to reduce the baud rate error, or achieve a slow baud rate for a fast oscillator frequency. writing a new value to the spbrghx:spbrgx registers causes the brg timer to be reset (or cleared). this ensures the brg does not wait for a timer overflow before outputting the new baud rate. 19.1.1 operation in power-managed modes the device clock is used to generate the desired baud rate. when one of the power-managed modes is entered, the new clock source may be operating at a different frequency. this may require an adjustment to the value in the spbrgx register pair. 19.1.2 sampling the data on the rxx pin (either rc7/pma4/rx1/dt1/sdo1/rp18 or rpn2/rx2/dt2) is sampled three times by a majority detect circuit to determine if a high or a low level is present at the rxx pin. table 19-1: baud rate formulas configuration bits brg/eusart mode baud rate formula sync brg16 brgh 000 8-bit/asynchronous f osc /[64 (n + 1)] 001 8-bit/asynchronous f osc /[16 (n + 1)] 010 16-bit/asynchronous 011 16-bit/asynchronous f osc /[4 (n + 1)] 10x 8-bit/synchronous 11x 16-bit/synchronous legend: x = don?t care, n = value of spbrghx:spbrgx register pair
pic18f46j50 family ds39931b-page 320 preliminary ? 2009 microchip technology inc. example 19-1: calculating baud rate error table 19-2: registers associated with baud rate generator name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: txstax csrc tx9 txen sync sendb brgh trmt tx9d 63 rcstax spen rx9 sren cren adden ferr oerr rx9d 63 baudconx abdovf rcidl rxdtp txckp brg16 ? wue abden 64 spbrghx eusartx baud rate generator register high byte 64 spbrgx eusartx baud rate generator register low byte 63 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the brg. for a device with fosc of 16 mhz, desired baud rate of 9600, asynchronous mode, and 8-bit brg: desired baud rate = fosc/(64 ([spbrghx:spbrgx] + 1)) solving for spbrghx:spbrgx: x = ((fosc/desired baud rate)/64) ? 1 = ((16000000/9600)/64) ? 1 = [25.042] = 25 calculated baud rate=16000000/(64 (25 + 1)) = 9615 error = (calculated baud rate ? desired baud rate)/desired baud rate = (9615 ? 9600)/9600 = 0.16%
? 2009 microchip technology inc. preliminary ds39931b-page 321 pic18f46j50 family table 19-3: baud rates for asynchronous modes baud rate (k) sync = 0 , brgh = 0 , brg16 = 0 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3???????????? 1.2 ? ? ? 1.221 1.73 255 1.202 0.16 129 1.201 -0.16 103 2.4 2.441 1.73 255 2.404 0.16 129 2.404 0.16 64 2.403 -0.16 51 9.6 9.615 0.16 64 9.766 1.73 31 9.766 1.73 15 9.615 -0.16 12 19.2 19.531 1.73 31 19.531 1.73 15 19.531 1.73 7 ? ? ? 57.6 56.818 -1.36 10 62.500 8.51 4 52.083 -9.58 2 ? ? ? 115.2 125.000 8.51 4 104.167 -9.58 2 78.125 -32.18 1 ? ? ? baud rate (k) sync = 0 , brgh = 0 , brg16 = 0 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.16 207 0.300 -0.16 103 0.300 -0.16 51 1.2 1.202 0.16 51 1.201 -0.16 25 1.201 -0.16 12 2.4 2.404 0.16 25 2.403 -0.16 12 ? ? ? 9.6 8.929 -6.99 6 ? ? ? ? ? ? 19.2 20.833 8.51 2 ? ? ? ? ? ? 57.6 62.500 8.51 0 ? ? ? ? ? ? 115.2 62.500 -45.75 0 ? ? ? ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 0 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3???????????? 1.2???????????? 2.4 ? ? ? ? ? ? 2.441 1.73 255 2.403 -0.16 207 9.6 9.766 1.73 255 9.615 0.16 129 9.615 0.16 64 9615. -0.16 51 19.2 19.231 0.16 129 19.231 0.16 64 19.531 1.73 31 19.230 -0.16 25 57.6 58.140 0.94 42 56.818 -1.36 21 56.818 -1.36 10 55.555 3.55 8 115.2 113.636 -1.36 21 113.636 -1.36 10 125.000 8.51 4 ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 0 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 ? ? ? ? ? ? 0.300 -0.16 207 1.2 1.202 0.16 207 1.201 -0.16 103 1.201 -0.16 51 2.4 2.404 0.16 103 2.403 -0.16 51 2.403 -0.16 25 9.6 9.615 0.16 25 9.615 -0.16 12 ? ? ? 19.2 19.231 0.16 12 ? ? ? ? ? ? 57.6 62.500 8.51 3 ? ? ? ? ? ? 115.2 125.000 8.51 1 ? ? ? ? ? ?
pic18f46j50 family ds39931b-page 322 preliminary ? 2009 microchip technology inc. baud rate (k) sync = 0 , brgh = 0 , brg16 = 1 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.00 8332 0.300 0.02 4165 0.300 0.02 2082 0.300 -0.04 1665 1.2 1.200 0.02 2082 1.200 -0.03 1041 1.200 -0.03 520 1.201 -0.16 415 2.4 2.402 0.06 1040 2.399 -0.03 520 2.404 0.16 259 2.403 -0.16 207 9.6 9.615 0.16 259 9.615 0.16 129 9.615 0.16 64 9.615 -0.16 51 19.2 19.231 0.16 129 19.231 0.16 64 19.531 1.73 31 19.230 -0.16 25 57.6 58.140 0.94 42 56.818 -1.36 21 56.818 -1.36 10 55.555 3.55 8 115.2 113.636 -1.36 21 113.636 -1.36 10 125.000 8.51 4 ? ? ? baud rate (k) sync = 0 , brgh = 0 , brg16 = 1 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.04 832 0.300 -0.16 415 0.300 -0.16 207 1.2 1.202 0.16 207 1.201 -0.16 103 1.201 -0.16 51 2.4 2.404 0.16 103 2.403 -0.16 51 2.403 -0.16 25 9.6 9.615 0.16 25 9.615 -0.16 12 ? ? ? 19.2 19.231 0.16 12 ? ? ? ? ? ? 57.6 62.500 8.51 3 ? ? ? ? ? ? 115.2 125.000 8.51 1 ? ? ? ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 1 or sync = 1 , brg16 = 1 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.00 33332 0.300 0.00 16665 0.300 0.00 8332 0.300 -0.01 6665 1.2 1.200 0.00 8332 1.200 0.02 4165 1.200 0.02 2082 1.200 -0.04 1665 2.4 2.400 0.02 4165 2.400 0.02 2082 2.402 0.06 1040 2.400 -0.04 832 9.6 9.606 0.06 1040 9.596 -0.03 520 9.615 0.16 259 9.615 -0.16 207 19.2 19.193 -0.03 520 19.231 0.16 259 19.231 0.16 129 19.230 -0.16 103 57.6 57.803 0.35 172 57.471 -0.22 86 58.140 0.94 42 57.142 0.79 34 115.2 114.943 -0.22 86 116.279 0.94 42 113.636 -1.36 21 117.647 -2.12 16 baud rate (k) sync = 0 , brgh = 1 , brg16 = 1 or sync = 1 , brg16 = 1 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.01 3332 0.300 -0.04 1665 0.300 -0.04 832 1.2 1.200 0.04 832 1.201 -0.16 415 1.201 -0.16 207 2.4 2.404 0.16 415 2.403 -0.16 207 2.403 -0.16 103 9.6 9.615 0.16 103 9.615 -0.16 51 9.615 -0.16 25 19.2 19.231 0.16 51 19.230 -0.16 25 19.230 -0.16 12 57.6 58.824 2.12 16 55.555 3.55 8 ? ? ? 115.2 111.111 -3.55 8 ? ? ? ? ? ? table 19-3: baud rates for asynchronous modes (continued)
? 2009 microchip technology inc. preliminary ds39931b-page 323 pic18f46j50 family 19.1.3 auto-baud rate detect the enhanced usart module supports the automatic detection and calibration of baud rate. this feature is active only in asynchronous mode and while the wue bit is clear. the automatic baud rate measurement sequence (figure 19-1) begins whenever a start bit is received and the abden bit is set. the calculation is self-averaging. in the auto-baud rate detect (abd) mode, the clock to the brg is reversed. rather than the brg clocking the incoming rxx signal, the rxx signal is timing the brg. in abd mode, the internal brg is used as a counter to time the bit period of the incoming serial byte stream. once the abden bit is set, the state machine will clear the brg and look for a start bit. the abd must receive a byte with the value, 55h (ascii ?u?, which is also the lin bus sync character), in order to calculate the proper bit rate. the measurement is taken over both a low and high bit time in order to minimize any effects caused by asymmetry of the incoming signal. after a start bit, the spbrgx begins counting up, using the preselected clock source on the first rising edge of rxx. after eight bits on the rxx pin or the fifth rising edge, an accumu- lated value totalling the proper brg period is left in the spbrghx:spbrgx register pair. once the 5 th edge is seen (this should correspond to the stop bit), the abden bit is automatically cleared. if a rollover of the brg occurs (an overflow from ffffh to 0000h), the event is trapped by the abdovf status bit (baudconx<7>). it is set in hardware by brg roll- overs and can be set or cleared by the user in software. abd mode remains active after rollover events and the abden bit remains set (figure 19-2). while calibrating the baud rate period, the brg registers are clocked at 1/8 th the preconfigured clock rate. note that the brg clock will be configured by the brg16 and brgh bits. independent of the brg16 bit setting, both the spbrgx and spbrghx will be used as a 16-bit counter. this allows the user to verify that no carry occurred for 8-bit modes by checking for 00h in the spbrghx register. refer to table 19-4 for counter clock rates to the brg. while the abd sequence takes place, the eusart state machine is held in idle. the rcxif interrupt is set once the fifth rising edge on rxx is detected. the value in the rcregx needs to be read to clear the rcxif interrupt. the contents of rcregx should be discarded. table 19-4: brg counter clock rates 19.1.3.1 abd and eusart transmission since the brg clock is reversed during abd acquisi- tion, the eusart transmitter cannot be used during abd. this means that whenever the abden bit is set, txregx cannot be written to. users should also ensure that abden does not become set during a transmit sequence. failing to do this may result in unpredictable eusart operation. note 1: if the wue bit is set with the abden bit, auto-baud rate detection will occur on the byte following the break character. 2: it is up to the user to determine that the incoming character baud rate is within the range of the selected brg clock source. some combinations of oscillator frequency and eusart baud rates are not possible due to bit error rates. overall system timing and communication baud rates must be taken into consideration when using the auto-baud rate detection feature. brg16 brgh brg counter clock 00 f osc /512 01 f osc /128 10 f osc /128 11 f osc /32 note: during the abd sequence, spbrgx and spbrghx are both used as a 16-bit counter, independent of brg16 setting.
pic18f46j50 family ds39931b-page 324 preliminary ? 2009 microchip technology inc. figure 19-1: automatic baud rate calculation figure 19-2: brg overflow sequence brg value rxx pin abden bit rcxif bit bit 0 bit 1 (interrupt) read rcregx brg clock start auto-cleared set by user xxxxh 0000h edge #1 bit 2 bit 3 edge #2 bit 4 bit 5 edge #3 bit 6 bit 7 edge #4 001ch note: the abd sequence requires the eusart module to be configured in asynchronous mode and wue = 0. spbrgx xxxxh 1ch spbrghx xxxxh 00h edge #5 stop bit start bit 0 xxxxh 0000h 0000h ffffh brg clock abden bit rxx pin abdovf bit brg value
? 2009 microchip technology inc. preliminary ds39931b-page 325 pic18f46j50 family 19.2 eusart asynchronous mode the asynchronous mode of operation is selected by clearing the sync bit (txstax<4>). in this mode, the eusart uses standard non-return-to-zero (nrz) format (one start bit, eight or nine data bits and one stop bit). the most common data format is 8 bits. an on-chip dedicated 8-bit/16-bit brg can be used to derive standard baud rate frequencies from the oscillator. the eusart transmits and receives the lsb first. the eusart?s transmitter and receiver are functionally independent but use the same data format and baud rate. the brg produces a clock, either x16 or x64 of the bit shift rate, depending on the brgh and brg16 bits (txstax<2> and baudconx<3>). parity is not supported by the hardware but can be implemented in software and stored as the ninth data bit. when operating in asynchronous mode, the eusart module consists of the following important elements: ? baud rate generator ? sampling circuit ? asynchronous transmitter ? asynchronous receiver ? auto-wake-up on sync break character ? 12-bit break character transmit ? auto-baud rate detection 19.2.1 eusart asynchronous transmitter figure 19-3 displays the eusart transmitter block diagram. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register, txregx. the txregx register is loaded with data in software. the tsr register is not loaded until the stop bit has been transmitted from the previous load. as soon as the stop bit is transmitted, the tsr is loaded with new data from the txregx register (if available). once the txregx register transfers the data to the tsr register (occurs in one t cy ), the txregx register is empty and the txxif flag bit is set. this interrupt can be enabled or disabled by setting or clearing the interrupt enable bit, txxie. txxif will be set regardless of the state of txxie; it cannot be cleared in software. txxif is also not cleared immediately upon loading txregx, but becomes valid in the second instruction cycle following the load instruction. polling txxif immediately following a load of txregx will return invalid results. while txxif indicates the status of the txregx register; another bit, trmt (txstax<1>), shows the status of the tsr register. trmt is a read-only bit, which is set when the tsr register is empty. no inter- rupt logic is tied to this bit so the user has to poll this bit in order to determine if the tsr register is empty. to set up an asynchronous transmission: 1. initialize the spbrghx:spbrgx registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing bit, sync, and setting bit, spen. 3. if interrupts are desired, set enable bit, txxie. 4. if 9-bit transmission is desired, set transmit bit, tx9. can be used as address/data bit. 5. enable the transmission by setting bit, txen, which will also set bit, txxif. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit, tx9d. 7. load data to the txregx register (starts transmission). 8. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. figure 19-3: eusart transmit block diagram note 1: the tsr register is not mapped in data memory, so it is not available to the user. 2: flag bit, txxif, is set when enable bit, txen, is set. txxif txxie interrupt txen baud rate clk spbrgx baud rate generator tx9d msb lsb data bus txregx register tsr register (8) 0 tx9 trmt spen txx pin pin buffer and control 8 ? ? ? spbrghx brg16
pic18f46j50 family ds39931b-page 326 preliminary ? 2009 microchip technology inc. figure 19-4: asynchronous transmission figure 19-5: asynchronous transmission (back-to-back) table 19-5: registers associated with asynchronous transmission name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 61 pir1 pmpif (1) adif rc1if tx1if ssp1if ccp1if tmr2if tmr1if 63 pie1 pmpie (1) adie rc1ie tx1ie ssp1ie ccp1ie tmr2ie tmr1ie 63 ipr1 pmpip (1) adip rc1ip tx1ip ssp1ip ccp1ip tmr2ip tmr1ip 63 pir3 ssp2if bcl2if rc2if tx2if tmr4if ctmuif tmr3gif rtccif 63 pie3 ssp2ie bcl2ie rc2ie tx2ie tmr4ie ctmuie tmr3gie rtccie 63 ipr3 ssp2ip bcl2ip rc2ip tx2ip tmr4ip ctmuip tmr3gip rtccip 63 rcstax spen rx9 sren cren adden ferr oerr rx9d 63 txregx eusartx transmit register 63 txstax csrc tx9 txen sync sendb brgh trmt tx9d 63 baudconx abdovf rcidl rxdtp txdtp brg16 ? wue abden 64 spbrghx eusartx baud rate generator register high byte 63 spbrgx eusartx baud rate generator register low byte 63 odcon2 ? ? ? ? u2od u1od 66 legend: ? = unimplemented locations read as ? 0 ?. shaded cells are not used for asynchronous transmission. note 1: these bits are only available on 44-pin devices. word 1 word 1 transmit shift reg start bit bit 0 bit 1 bit 7/8 write to txregx brg output (shift clock) txx (pin) txxif bit (transmit buffer reg. empty flag) trmt bit (transmit shift reg. empty flag) 1 t cy stop bit word 1 transmit shift reg. write to txregx brg output (shift clock) txx (pin) txxif bit (interrupt reg. flag) trmt bit (transmit shift reg. empty flag) word 1 word 2 word 1 word 2 stop bit start bit transmit shift reg. word 1 word 2 bit 0 bit 1 bit 7/8 bit 0 note: this timing diagram shows two consecutive transmissions. 1 t cy 1 t cy start bit
? 2009 microchip technology inc. preliminary ds39931b-page 327 pic18f46j50 family 19.2.2 eusart asynchronous receiver the receiver block diagram is displayed in figure 19-6. the data is received on the rxx pin and drives the data recovery block. the data recovery block is actually a high-speed shifter operating at x16 times the baud rate, whereas the main receive serial shifter operates at the bit rate or at f osc . this mode would typically be used in rs-232 systems. to set up an asynchronous reception: 1. initialize the spbrghx:spbrgx registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing bit, sync, and setting bit, spen. 3. if interrupts are desired, set enable bit, rcxie. 4. if 9-bit reception is desired, set bit, rx9. 5. enable the reception by setting bit, cren. 6. flag bit, rcxif, will be set when reception is complete and an interrupt will be generated if enable bit, rcxie, was set. 7. read the rcstax register to get the ninth bit (if enabled) and determine if any error occurred during reception. 8. read the 8-bit received data by reading the rcregx register. 9. if any error occurred, clear the error by clearing enable bit, cren. 10. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. 19.2.3 setting up 9-bit mode with address detect this mode would typically be used in rs-485 systems. to set up an asynchronous reception with address detect enable: 1. initialize the spbrghx:spbrgx registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing the sync bit and setting the spen bit. 3. if interrupts are required, set the rcen bit and select the desired priority level with the rcxip bit. 4. set the rx9 bit to enable 9-bit reception. 5. set the adden bit to enable address detect. 6. enable reception by setting the cren bit. 7. the rcxif bit will be set when reception is complete. the interrupt will be acknowledged if the rcxie and gie bits are set. 8. read the rcstax register to determine if any error occurred during reception, as well as read bit 9 of data (if applicable). 9. read rcregx to determine if the device is being addressed. 10. if any error occurred, clear the cren bit. 11. if the device has been addressed, clear the adden bit to allow all received data into the receive buffer and interrupt the cpu. figure 19-6: eusartx receive block diagram x64 baud rate clk baud rate generator rxx pin buffer and control spen data recovery cren oerr ferr rsr register msb lsb rx9d rcregx register fifo interrupt rcxif rcxie data bus 8 64 16 or stop start (8) 7 1 0 rx9 ? ? ? spbrgx spbrghx brg16 or 4
pic18f46j50 family ds39931b-page 328 preliminary ? 2009 microchip technology inc. figure 19-7: asynchronous reception table 19-6: registers associated with asynchronous reception 19.2.4 auto-wake-up on sync break character during sleep mode, all clocks to the eusart are suspended. because of this, the brg is inactive and a proper byte reception cannot be performed. the auto-wake-up feature allows the controller to wake-up due to activity on the rxx/dtx line while the eusart is operating in asynchronous mode. the auto-wake-up feature is enabled by setting the wue bit (baudconx<1>). once set, the typical receive sequence on rxx/dtx is disabled and the eusart remains in an idle state, monitoring for a wake-up event independent of the cpu mode. a wake-up event consists of a high-to-low transition on the rxx/dtx line. (this coincides with the start of a sync break or a wake-up signal character for the lin protocol.) following a wake-up event, the module generates an rcxif interrupt. the interrupt is generated synchro- nously to the q clocks in normal operating modes (figure 19-8) and asynchronously if the device is in sleep mode (figure 19-9). the interrupt condition is cleared by reading the rcregx register. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 61 pir1 pmpif (1) adif rc1if tx1if ssp1if ccp1if tmr2if tmr1if 63 pie1 pmpie (1) adie rc1ie tx1ie ssp1ie ccp1ie tmr2ie tmr1ie 63 ipr1 pmpip (1) adip rc1ip tx1ip ssp1ip ccp1ip tmr2ip tmr1ip 63 pir3 ssp2if bcl2if rc2if tx2if tmr4if ctmuif tmr3gif rtccif 63 pie3 ssp2ie bcl2ie rc2ie tx2ie tmr4ie ctmuie tmr3gie rtccie 63 ipr3 ssp2ip bcl2ip rc2ip tx2ip tmr4ip ctmuip tmr3gip rtccip 63 rcstax spen rx9 sren cren adden ferr oerr rx9d 63 rcregx eusartx receive register 63 txstax csrc tx9 txen sync sendb brgh trmt tx9d 63 baudconx abdovf rcidl rxdtp txckp brg16 ? wue abden 64 spbrghx eusartx baud rate generator register high byte 63 spbrgx eusartx baud rate generator register low byte 63 legend: ? = unimplemented locations read as ? 0 ?. shaded cells are not used for asynchronous reception. note 1: these bits are only available on 44-pin devices. start bit bit 7/8 bit 1 bit 0 bit 7/8 bit 0 stop bit start bit start bit bit 7/8 stop bit rxx (pin) rcv buffer reg rcv shift reg read rcv buffer reg rcregx rcxif (interrupt flag) oerr bit cren word 1 rcregx word 2 rcregx stop bit note: this timing diagram shows three words appearing on the rx x input. the rcregx (receive buffer) is read after the third word causing the oerr (overrun) bit to be set.
? 2009 microchip technology inc. preliminary ds39931b-page 329 pic18f46j50 family the wue bit is automatically cleared once a low-to-high transition is observed on the rxx line following the wake-up event. at this point, the eusart module is in idle mode and returns to normal operation. this signals to the user that the sync break event is over. 19.2.4.1 special considerations using auto-wake-up since auto-wake-up functions by sensing rising edge transitions on rxx/dtx, information with any state changes before the stop bit may signal a false end-of-character (eoc) and cause data or framing errors. to work properly, therefore, the initial character in the transmission must be all ? 0 ?s. this can be 00h (8 bytes) for standard rs-232 devices or 000h (12 bits) for lin bus. oscillator start-up time must also be considered, especially in applications using oscillators with longer start-up intervals (i.e., hs or hspll mode). the sync break (or wake-up signal) character must be of sufficient length and be followed by a sufficient interval to allow enough time for the selected oscillator to start and provide proper initialization of the eusart. 19.2.4.2 special considerations using the wue bit the timing of wue and rcxif events may cause some confusion when it comes to determining the validity of received data. as noted, setting the wue bit places the eusart in an idle mode. the wake-up event causes a receive interrupt by setting the rcxif bit. the wue bit is cleared after this when a rising edge is seen on rxx/dtx. the interrupt condition is then cleared by reading the rcregx register. ordinarily, the data in rcregx will be dummy data and should be discarded. the fact that the wue bit has been cleared (or is still set) and the rcxif flag is set should not be used as an indicator of the integrity of the data in rcregx. users should consider implementing a parallel method in firmware to verify received data integrity. to assure that no actual data is lost, check the rcidl bit to verify that a receive operation is not in process. if a receive operation is not occurring, the wue bit may then be set just prior to entering the sleep mode. figure 19-8: auto-wake-up bit (wue) timings during no rmal operation figure 19-9: auto-wake-up bit (wue) timings during sleep q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 wue bit (1) rxx/dtx line rcxif note 1: the eusart remains in idle while the wue bit is set. bit set by user cleared due to user read of rcregx auto-cleared q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 wue bit (2) rxx/dtx line rcxif cleared due to user read of rcregx sleep command executed note 1: if the wake-up event requires long oscillator warm-up time, the auto-clear of the wue bit can occur before the oscillator is ready. this sequence s hould not depend on the presence of q clocks. 2: the eusart remains in idle while the wue bit is set. sleep ends note 1 auto-cleared bit set by user
pic18f46j50 family ds39931b-page 330 preliminary ? 2009 microchip technology inc. 19.2.5 break character sequence the eusart module has the capability of sending the special break character sequences that are required by the lin bus standard. the break character transmit consists of a start bit, followed by twelve ? 0 ? bits and a stop bit. the frame break character is sent whenever the sendb and txen bits (txstax<3> and txstax<5>) are set while the transmit shift register is loaded with data. note that the value of data written to txregx will be ignored and all ? 0 ?s will be transmitted. the sendb bit is automatically reset by hardware after the corresponding stop bit is sent. this allows the user to preload the transmit fifo with the next transmit byte following the break character (typically, the sync character in the lin specification). note that the data value written to the txregx for the break character is ignored. the write simply serves the purpose of initiating the proper sequence. the trmt bit indicates when the transmit operation is active or idle, just as it does during normal transmis- sion. see figure 19-10 for the timing of the break character sequence. 19.2.5.1 break and sync transmit sequence the following sequence will send a message frame header made up of a break, followed by an auto-baud sync byte. this sequence is typical of a lin bus master. 1. configure the eusart for the desired mode. 2. set the txen and sendb bits to set up the break character. 3. load the txregx with a dummy character to initiate transmission (the value is ignored). 4. write ?55h? to txregx to load the sync character into the transmit fifo buffer. 5. after the break has been sent, the sendb bit is reset by hardware. the sync character now transmits in the preconfigured mode. when the txregx becomes empty, as indicated by the txxif, the next data byte can be written to txregx. 19.2.6 receiving a break character the enhanced usart module can receive a break character in two ways. the first method forces configuration of the baud rate at a frequency of 9/13 the typical speed. this allows for the stop bit transition to be at the correct sampling location (13 bits for break versus start bit and 8 data bits for typical data). the second method uses the auto-wake-up feature described in section 19.2.4 ?auto-wake-up on sync break character? . by enabling this feature, the eusart will sample the next two transitions on rxx/dtx, cause an rcxif interrupt and receive the next data byte followed by another interrupt. note that following a break character, the user will typically want to enable the auto-baud rate detect feature. for both methods, the user can set the abden bit once the txxif interrupt is observed. figure 19-10: send break character sequence write to txregx brg output (shift clock) start bit bit 0 bit 1 bit 11 stop bit break txxif bit (transmit buffer reg. empty flag) txx (pin) trmt bit (transmit shift reg. empty flag) sendb bit (transmit shift reg. empty flag) sendb sampled here auto-cleared dummy write
? 2009 microchip technology inc. preliminary ds39931b-page 331 pic18f46j50 family 19.3 eusart synchronous master mode the synchronous master mode is entered by setting the csrc bit (txstax<7>). in this mode, the data is transmitted in a half-duplex manner (i.e., transmission and reception do not occur at the same time). when transmitting data, the reception is inhibited and vice versa. synchronous mode is entered by setting bit, sync (txstax<4>). in addition, enable bit, spen (rcstax<7>), is set in order to configure the txx and rxx pins to ckx (clock) and dtx (data) lines, respectively. the master mode indicates that the processor trans- mits the master clock on the ckx line. clock polarity is selected with the txckp bit (baudconx<4>). setting txckp sets the idle state on ckx as high, while clear- ing the bit sets the idle state as low. this option is provided to support microwire devices with this module. 19.3.1 eusart synchronous master transmission the eusart transmitter block diagram is shown in figure 19-3. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register, txregx. the txregx register is loaded with data in software. the tsr register is not loaded until the last bit has been transmitted from the previous load. as soon as the last bit is transmitted, the tsr is loaded with new data from the txregx (if available). once the txregx register transfers the data to the tsr register (occurs in one t cy ), the txregx is empty and the txxif flag bit is set. the interrupt can be enabled or disabled by setting or clearing the interrupt enable bit, txxie. txxif is set regardless of the state of enable bit, txxie; it cannot be cleared in software. it will reset only when new data is loaded into the txregx register. while flag bit, txxif, indicates the status of the txregx register, another bit, trmt (txstax<1>), shows the status of the tsr register. trmt is a read-only bit which is set when the tsr is empty. no interrupt logic is tied to this bit, so the user must poll this bit in order to determine if the tsr register is empty. the tsr is not mapped in data memory so it is not available to the user. to set up a synchronous master transmission: 1. initialize the spbrghx:spbrgx registers for the appropriate baud rate. set or clear the brg16 bit, as required, to achieve the required baud rate. 2. enable the synchronous master serial port by setting bits, sync, spen and csrc. 3. if interrupts are desired, set enable bit, txxie. 4. if 9-bit transmission is required, set bit, tx9. 5. enable the transmission by setting bit, txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit, tx9d. 7. start transmission by loading data to the txregx register. 8. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. figure 19-11: synchronous transmission bit 0 bit 1 bit 7 word 1 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1q2 q3 q4 q1 q2 q3 q4 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 bit 2 bit 0 bit 1 bit 7 rc7/rx1/dt1/ rc6/tx1/ck1/rp17 pin write to txreg1 reg tx1if bit (interrupt flag) txen bit ? 1 ? ? 1 ? word 2 trmt bit write word 1 write word 2 note: sync master mode, spbrgx = 0 , continuous transmission of two 8-bit word s. this example is equally applicable to eusart2 (rpn1/tx2/ck2 and rpn2/rx2/dt2). rc6/tx1/ck1/rp17 pin (txckp = 0 ) (txckp = 1 ) sdo1/rp18
pic18f46j50 family ds39931b-page 332 preliminary ? 2009 microchip technology inc. figure 19-12: synchronous tr ansmission (through txen) table 19-7: registers associated with synchronous master transmission name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 61 pir1 pmpif (1) adif rc1if tx1if ssp1if ccp1if tmr2if tmr1if 63 pie1 pmpie (1) adie rc1ie tx1ie ssp1ie ccp1ie tmr2ie tmr1ie 63 ipr1 pmpip (1) adip rc1ip tx1ip ssp1ip ccp1ip tmr2ip tmr1ip 63 pir3 ssp2if bcl2if rc2if tx2if tmr4if ctmuif tmr3gif rtccif 63 pie3 ssp2ie bcl2ie rc2ie tx2ie tmr4ie ctmuie tmr3gie rtccie 63 ipr3 ssp2ip bcl2ip rc2ip tx2ip tmr4ip ctmuip tmr3gip rtccip 63 rcstax spen rx9 sren cren adden ferr oerr rx9d 63 txregx eusartx transmit register 63 txstax csrc tx9 txen sync sendb brgh trmt tx9d 63 baudconx abdovf rcidl rxdtp txckp brg16 ? wue abden 64 spbrghx eusartx baud rate generator register high byte 63 spbrgx eusartx baud rate generator register low byte 63 odcon2 ? ? ? ? u2od u1od 66 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous master transmission. note 1: these pins are only available on 44-pin devices. rc7/rx1/dt1/ rc6/tx1/ck1/rp17 pin write to txreg1 reg tx1if bit trmt bit bit 0 bit 1 bit 2 bit 6 bit 7 txen bit note: this example is equally applicable to eu sart2 (rpn1/tx2/ck2 and rpn2/rx2/dt2). sdo1/rp18 pin
? 2009 microchip technology inc. preliminary ds39931b-page 333 pic18f46j50 family 19.3.2 eusart synchronous master reception once synchronous mode is selected, reception is enabled by setting either the single receive enable bit, sren (rcstax<5>) or the continuous receive enable bit, cren (rcstax<4>). data is sampled on the rxx pin on the falling edge of the clock. if enable bit, sren, is set, only a single word is received. if enable bit, cren, is set, the reception is continuous until cren is cleared. if both bits are set, then cren takes precedence. to set up a synchronous master reception: 1. initialize the spbrghx:spbrgx registers for the appropriate baud rate. set or clear the brg16 bit, as required, to achieve the desired baud rate. 2. enable the synchronous master serial port by setting bits, sync, spen and csrc. 3. ensure bits, cren and sren, are clear. 4. if interrupts are desired, set enable bit, rcxie. 5. if 9-bit reception is desired, set bit, rx9. 6. if a single reception is required, set bit, sren. for continuous reception, set bit, cren. 7. interrupt flag bit, rcxif, will be set when reception is complete and an interrupt will be generated if the enable bit, rcxie, was set. 8. read the rcstax register to get the ninth bit (if enabled) and determine if any error occurred during reception. 9. read the 8-bit received data by reading the rcregx register. 10. if any error occurred, clear the error by clearing bit, cren. 11. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. figure 19-13: synchronous reception (master mode, sren) cren bit rc7/rx1/dt1/ rc6/tx1/ck1/rp17 write to bit sren sren bit rc1if bit (interrupt) read rcreg1 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q2 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 ? 0 ? bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7 ? 0 ? q1 q2 q3 q4 note: timing diagram demonstrates sync master mode with bit sren = 1 and bit brgh = 0 . this example is equally applicable to eusart2 (rpn1/tx2/ck2 and rpn2/rx2/dt2). rc6/tx1/ck1/rp17 sdo1/rp18 pin pin (txckp = 0 ) pin (txckp = 1 )
pic18f46j50 family ds39931b-page 334 preliminary ? 2009 microchip technology inc. table 19-8: registers associated with synchronous master reception name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 61 pir1 pmpif (1) adif rc1if tx1if ssp1if ccp1if tmr2if tmr1if 63 pie1 pmpie (1) adie rc1ie tx1ie ssp1ie ccp1ie tmr2ie tmr1ie 63 ipr1 pmpip (1) adip rc1ip tx1ip ssp1ip ccp1ip tmr2ip tmr1ip 63 pir3 ssp2if bcl2if rc2if tx2if tmr4if ctmuif tmr3gif rtccif 63 pie3 ssp2ie bcl2ie rc2ie tx2ie tmr4ie ctmuie tmr3gie rtccie 63 ipr3 ssp2ip bcl2ip rc2ip tx2ip tmr4ip ctmuip tmr3gip rtccip 63 rcstax spen rx9 sren cren adden ferr oerr rx9d 63 rcregx eusartx receive register 63 txstax csrc tx9 txen sync sendb brgh trmt tx9d 63 baudconx abdovf rcidl rxdtp txckp brg16 ? wue abden 64 spbrghx eusartx baud rate generator register high byte 63 spbrgx eusartx baud rate generator register low byte 63 odcon2 ? ? ? ? u2od u1od 66 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous master reception. note 1: these pins are only available on 44-pin devices.
? 2009 microchip technology inc. preliminary ds39931b-page 335 pic18f46j50 family 19.4 eusart synchronous slave mode synchronous slave mode is entered by clearing bit, csrc (txstax<7>). this mode differs from the synchronous master mode in that the shift clock is sup- plied externally at the ckx pin (instead of being supplied internally in master mode). this allows the device to transfer or receive data while in any low-power mode. 19.4.1 eusart synchronous slave transmission the operation of the synchronous master and slave modes is identical, except in the case of sleep mode. if two words are written to the txregx and then the sleep instruction is executed, the following will occur: a) the first word will immediately transfer to the tsr register and transmit. b) the second word will remain in the txregx register. c) flag bit, txxif, will not be set. d) when the first word has been shifted out of tsr, the txregx register will transfer the second word to the tsr and flag bit, txxif, will now be set. e) if enable bit, txxie, is set, the interrupt will wake the chip from sleep. if the global interrupt is enabled, the program will branch to the interrupt vector. to set up a synchronous slave transmission: 1. enable the synchronous slave serial port by setting bits, sync and spen, and clearing bit, csrc. 2. clear bits, cren and sren. 3. if interrupts are desired, set enable bit, txxie. 4. if 9-bit transmission is desired, set bit, tx9. 5. enable the transmission by setting enable bit, txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit, tx9d. 7. start transmission by loading data to the txregx register. 8. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set.
pic18f46j50 family ds39931b-page 336 preliminary ? 2009 microchip technology inc. table 19-9: registers associated with synchronous slave transmission name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 61 pir1 pmpif (1) adif rc1if tx1if ssp1if ccp1if tmr2if tmr1if 63 pie1 pmpie (1) adie rc1ie tx1ie ssp1ie ccp1ie tmr2ie tmr1ie 63 ipr1 pmpip (1) adip rc1ip tx1ip ssp1ip ccp1ip tmr2ip tmr1ip 63 pir3 ssp2if bcl2if rc2if tx2if tmr4if ctmuif tmr3gif rtccif 63 pie3 ssp2ie bcl2ie rc2ie tx2ie tmr4ie ctmuie tmr3gie rtccie 63 ipr3 ssp2ip bcl2ip rc2ip tx2ip tmr4ip ctmuip tmr3gip rtccip 63 rcstax spen rx9 sren cren adden ferr oerr rx9d 63 txregx eusartx transmit register 63 txstax csrc tx9 txen sync sendb brgh trmt tx9d 63 baudconx abdovf rcidl rxdtp txckp brg16 ? wue abden 64 spbrghx eusartx baud rate generator register high byte 63 spbrgx eusartx baud rate generator register low byte 63 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous slave transmission. note 1: these pins are only available on 44-pin devices.
? 2009 microchip technology inc. preliminary ds39931b-page 337 pic18f46j50 family 19.4.2 eusart synchronous slave reception the operation of the synchronous master and slave modes is identical, except in the case of sleep, or any idle mode and bit, sren, which is a ?don?t care? in slave mode. if receive is enabled by setting the cren bit prior to entering sleep or any idle mode, then a word may be received while in this low-power mode. once the word is received, the rsr register will transfer the data to the rcregx register. if the rcxie enable bit is set, the interrupt generated will wake the chip from the low-power mode. if the global interrupt is enabled, the program will branch to the interrupt vector. to set up a synchronous slave reception: 1. enable the synchronous master serial port by setting bits, sync and spen, and clearing bit, csrc. 2. if interrupts are desired, set enable bit, rcxie. 3. if 9-bit reception is desired, set bit, rx9. 4. to enable reception, set enable bit, cren. 5. flag bit, rcxif, will be set when reception is complete. an interrupt will be generated if enable bit, rcxie, was set. 6. read the rcstax register to get the ninth bit (if enabled) and determine if any error occurred during reception. 7. read the 8-bit received data by reading the rcregx register. 8. if any error occurred, clear the error by clearing bit, cren. 9. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. table 19-10: registers associated with synchronous slave reception name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 61 pir1 pmpif (1) adif rc1if tx1if ssp1if ccp1if tmr2if tmr1if 63 pie1 pmpie (1) adie rc1ie tx1ie ssp1ie ccp1ie tmr2ie tmr1ie 63 ipr1 pmpip (1) adip rc1ip tx1ip ssp1ip ccp1ip tmr2ip tmr1ip 63 pir3 ssp2if bcl2if rc2if tx2if tmr4if ctmuif tmr3gif rtccif 63 pie3 ssp2ie bcl2ie rc2ie tx2ie tmr4ie ctmuie tmr3gie rtccie 63 ipr3 ssp2ip bcl2ip rc2ip tx2ip tmr4ip ctmuip tmr3gip rtccip 63 rcstax spen rx9 sren cren adden ferr oerr rx9d 63 rcregx eusartx receive register 63 txstax csrc tx9 txen sync sendb brgh trmt tx9d 63 baudconx abdovf rcidl rxdtp txckp brg16 ? wue abden 64 spbrghx eusartx baud rate generator register high byte 63 spbrgx eusartx baud rate generator register low byte 63 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous slave reception. note 1: these pins are only available on 44-pin devices.
pic18f46j50 family ds39931b-page 338 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39931b-page 339 pic18f46j50 family 20.0 10-bit analog-to-digital converter (a/d) module the analog-to-digital (a/d) converter module has 10 inputs for the 28-pin devices and 13 for the 44-pin devices. additionally, two internal channels are available for sampling the v ddcore and v bg absolute reference voltage. this module allows conversion of an analog input signal to a corresponding 10-bit digital number. the module has six registers: ? a/d control register 0 (adcon0) ? a/d control register 1 (adcon1) ? a/d port configuration register 2 (ancon0) ? a/d port configuration register 1 (ancon1) ? a/d result registers (adresh and adresl) the adcon0 register, in register 20-1, controls the operation of the a/d module. the adcon1 register, in register 20-2, configures the a/d clock source, programmed acquisition time and justification. the ancon0 and ancon1 registers, in register 20-3 and register 20-4, configure the functions of the port pins. register 20-1: adcon0: a/d contro l register 0 (access fc2h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 vcfg1 vcfg0 chs3 chs2 chs1 chs0 go/done adon bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 vcfg1: voltage reference configuration bit (v ref - source) 1 = v ref - (an2) 0 = av ss bit 6 vcfg0: voltage reference configuration bit (v ref + source) 1 = v ref + (an3) 0 = av dd bit 5-2 chs<3:0>: analog channel select bits (2) 0000 = channel 00 (an0) 0001 = channel 01 (an1) 0010 = channel 02 (an2) 0011 = channel 03 (an3) 0100 = channel 04 (an4) 0101 = channel 05 (an5) (1) 0110 = channel 06 (an6) (1) 0111 = channel 07 (an7) (1) 1000 = channel 08 (an8) 1001 = channel 09 (an9) 1010 = channel 10 (an10) 1011 = channel 11 (an11) 1100 = channel 12 (an12) 1101 =(reserved) 1110 = v ddcore 1111 = v bg absolute reference (~1.2v) (3) bit 1 go/done : a/d conversion status bit when adon = 1 : 1 = a/d conversion in progress 0 = a/d idle bit 0 adon: a/d on bit 1 = a/d converter module is enabled 0 = a/d converter module is disabled note 1: these channels are not implemented on 28-pin devices. 2: performing a conversion on unimplemented channels will return random values. 3: for best accuracy, the band gap reference circuit should be enabled (ancon1<7> = 1 ) at least 10 ms before performing a conversion on this channel.
pic18f46j50 family ds39931b-page 340 preliminary ? 2009 microchip technology inc. register 20-2: adcon1: a/d contro l register 1 (access fc1h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 adfm adcal acqt2 acqt1 acqt0 adcs2 adcs1 adcs0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 adfm: a/d result format select bit 1 = right justified 0 = left justified bit 6 adcal: a/d calibration bit 1 = calibration is performed on next a/d conversion 0 = normal a/d converter operation bit 5-3 acqt<2:0>: a/d acquisition time select bits 111 = 20 t ad 110 = 16 t ad 101 = 12 t ad 100 = 8 t ad 011 = 6 t ad 010 = 4 t ad 001 = 2 t ad 000 = 0 t ad bit 2-0 adcs<2:0>: a/d conversion clock select bits 110 = f osc /64 101 = f osc /16 100 = f osc /4 011 = f rc (clock derived from a/d rc oscillator) (1) 010 = f osc /32 001 = f osc /8 000 = f osc /2 note 1: if the a/d frc clock source is selected, a delay of one t cy (instruction cycle) is added before the a/d clock starts. this allows the sleep instruction to be executed before starting a conversion.
? 2009 microchip technology inc. preliminary ds39931b-page 341 pic18f46j50 family the ancon0 and ancon1 registers are used to configure the operation of the i/o pin associated with each analog channel. setting any one of the pcfg bits configures the corresponding pin to operate as a digital only i/o. clearing a bit configures the pin to operate as an analog input for either the a/d converter or the comparator module; all digital peripherals are disabled and digital inputs read as ? 0 ?. as a rule, i/o pins that are multiplexed with analog inputs default to analog operation on device resets. in order to correctly perform a/d conversions on the v bg band gap reference (adcon0<5:2> = 1111 ), the refer- ence circuit must be powered on first. the vbgen bit in the ancon1 register allows the firmware to manually request that the band gap reference circuit should be enabled. for best accuracy, firmware should allow a settling time of at least 10 ms prior to performing the first acquisition on this channel after enabling the band gap reference. the reference circuit may already have been turned on if some other hardware module (such as the on-chip voltage regulator, comparators or hlvd) has already requested it. in this case, the initial turn-on settling time may have already elapsed and firmware does not need to wait as long before measuring v bg . once the acqui- sition is complete, firmware may clear the vbgen bit, which will save a small amount of power if no other modules are still requesting the v bg reference. register 20-3: ancon0: a/d port config uration register 2 (banked f48h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 pcfg7 (1) pcfg6 (1) pcfg5 (1) pcfg4 pcfg3 pcfg2 pcfg1 pcfg0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 pcfg<7:0>: analog port configuration bits (an7-an0) 1 = pin configured as a digital port 0 = pin configured as an analog channel ? digital input disabled and reads ? 0 ? note 1: these bits are only available only on 44-pin devices. register 20-4: ancon1: a/d port config uration register 1 (banked f49h) r/w-0 r u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 vbgen ? ? pcfg12 pcfg11 pcfg10 pcfg9 pcfg8 bit 7 bit 0 legend: r = reserved r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 vbgen: 1.2v band gap reference enable bit 1 = 1.2v band gap reference is powered on 0 = 1.2v band gap reference is turned off to save power (if no other modules are requesting it) bit 6 reserved: always maintain as ? 0 ? for lowest power consumption bit 5 unimplemented: read as ? 0 ? bit 4-0 pcfg<12:8>: analog port configuration bits (an12-an8) 1 = pin configured as a digital port 0 = pin configured as an analog channel ? digital input disabled and reads ? 0 ?
pic18f46j50 family ds39931b-page 342 preliminary ? 2009 microchip technology inc. the analog reference voltage is software select- able to either the device?s positive and negative supply voltage (av dd and av ss ), or the voltage level on the ra3/an3/v ref +/c1inb and ra2/an2/v ref -/cv ref /c2inb pins. the a/d converter has a unique feature of being able to operate while the device is in sleep mode. to operate in sleep, the a/d conversion clock must be derived from the a/d?s internal rc oscillator. the output of the sample and hold is the input into the converter, which generates the result via successive approximation. each port pin associated with the a/d converter can be configured as an analog input or as a digital i/o. the adresh and adresl registers contain the result of the a/d conversion. when the a/d conversion is com- plete, the result is loaded into the adresh:adresl register pair, the go/done bit (adcon0<1>) is cleared and the a/d interrupt flag bit, adif, is set. a device reset forces all registers to their reset state. this forces the a/d module to be turned off and any conversion in progress is aborted. the value in the adresh:adresl register pair is not modified for a power-on reset (por). these registers will contain unknown data after a por. figure 20-1 provides the block diagram of the a/d module. figure 20-1: a/d block diagram (input voltage) v ain v ref + reference voltage v dd (2) vcfg<1:0> chs<3:0> an7 (1) an4 an3 an2 an1 an0 0111 0100 0011 0010 0001 0000 10-bit a/d v ref - v ss (2) converter v bg v ddcore /v cap an12 an11 an10 1111 1110 1100 1011 1010 note 1: channels an5, an6 and an7 are not available on 28-pin devices. 2: i/o pins have diode protection to v dd and v ss . an6 (1) 0110 an5 (1) 0101 an9 1001 an8 1000
? 2009 microchip technology inc. preliminary ds39931b-page 343 pic18f46j50 family after the a/d module has been configured as desired, the selected channel must be acquired before the conversion is started. the analog input channels must have their corresponding tris bits selected as an input. to determine acquisition time, see section 20.1 ?a/d acquisition requirements? . after this acquisi- tion time has elapsed, the a/d conversion can be started. an acquisition time can be programmed to occur between setting the go/done bit and the actual start of the conversion. the following steps should be followed to do an a/d conversion: 1. configure the a/d module: ? configure the required adc pins as analog pins using ancon0, ancon1 ? set voltage reference using adcon0 ? select a/d input channel (adcon0) ? select a/d acquisition time (adcon1) ? select a/d conversion clock (adcon1) ? turn on a/d module (adcon0) 2. configure a/d interrupt (if desired): ? clear adif bit ? set adie bit ?set gie bit 3. wait the required acquisition time (if required). 4. start conversion: ? set go/done bit (adcon0<1>) 5. wait for a/d conversion to complete, by either: ? polling for the go/done bit to be cleared or ? waiting for the a/d interrupt 6. read a/d result registers (adresh:adresl); clear bit, adif, if required. 7. for next conversion, go to step 1 or step 2, as required. the a/d conversion time per bit is defined as t ad . a minimum wait of 2 t ad is required before next acquisition starts. figure 20-2: analog input model v ain c pin r s anx 5 pf v dd v t = 0.6v v t = 0.6v i leakage r ic 1k sampling switch ss r ss c hold = 25 pf v ss sampling switch 123 4 (k ) v dd 100 na legend: c pin v t i leakage r ic ss c hold = input capacitance = threshold voltage = leakage current at the pin due to = interconnect resistance = sampling switch = sample/hold capacitance (from dac) various junctions = sampling switch resistance r ss
pic18f46j50 family ds39931b-page 344 preliminary ? 2009 microchip technology inc. 20.1 a/d acquisition requirements for the a/d converter to meet its specified accuracy, the charge holding capacitor (c hold ) must be allowed to fully charge to the input channel voltage level. the analog input model is illustrated in figure 20-2. the source impedance (r s ) and the internal sampling switch (r ss ) impedance directly affect the time required to charge the capacitor c hold . the sampling switch (r ss ) impedance varies over the device voltage (v dd ). the source impedance affects the offset voltage at the analog input (due to pin leakage current). the maximum recommended impedance for analog sources is 10 k . after the analog input channel is selected (changed), the channel must be sampled for at least the minimum acquisition time before starting a conversion. to calculate the minimum acquisition time, equation 20-1 may be used. this equation assumes that 1/2 lsb error is used (1024 steps for the a/d). the 1/2 lsb error is the maximum error allowed for the a/d to meet its specified resolution. equation 20-3 provides the calculation of the minimum required acquisition time, t acq . this calculation is based on the following application system assumptions: c hold =25 pf rs = 2.5 k conversion error 1/2 lsb v dd =3v rss = 2 k temperature = 85 c (system max.) equation 20-1: acquisition time equation 20-2: a/d minimum charging time equation 20-3: calculating the minimum required acquisition time note: when the conversion is started, the holding capacitor is disconnected from the input pin. t acq = amplifier settling time + holding capacitor charging time + temperature coefficient =t amp + t c + t coff v hold = (v ref ? (v ref /2048)) ? (1 ? e (-t c /c hold (r ic + r ss + r s )) ) or t c = -(c hold )(r ic + r ss + r s ) ln(1/2048) t acq =t amp + t c + t coff t amp =0.2 s t coff = (temp ? 25c)(0.02 s/c) (85c ? 25c)(0.02 s/c) 1.2 s temperature coefficient is only required for temperatures > 25c. below 25c, t coff = 0 s. t c = -(c hold )(r ic + r ss + r s ) ln(1/2048) s -(25 pf) (1 k + 2 k + 2.5 k ) ln(0.0004883) s 1.05 s t acq =0.2 s + 1.05 s + 1.2 s 2.45 s
? 2009 microchip technology inc. preliminary ds39931b-page 345 pic18f46j50 family 20.2 selecting and configuring automatic acquisition time the adcon1 register allows the user to select an acquisition time that occurs each time the go/done bit is set. when the go/done bit is set, sampling is stopped and a conversion begins. the user is responsible for ensur- ing the required acquisition time has passed between selecting the desired input channel and setting the go/done bit. this occurs when the acqt<2:0> bits (adcon1<5:3>) remain in their reset state (? 000 ?) and is compatible with devices that do not offer programmable acquisition times. if desired, the acqt bits can be set to select a pro- grammable acquisition time for the a/d module. when the go/done bit is set, the a/d module continues to sample the input for the selected acquisition time, then automatically begins a conversion. since the acquisi- tion time is programmed, there may be no need to wait for an acquisition time between selecting a channel and setting the go/done bit. in either case, when the conversion is completed, the go/done bit is cleared, the adif flag is set and the a/d begins sampling the currently selected channel again. if an acquisition time is programmed, there is nothing to indicate if the acquisition time has ended or if the conversion has begun. 20.3 selecting the a/d conversion clock the a/d conversion time per bit is defined as t ad . the a/d conversion requires 11 t ad per 10-bit conversion. the source of the a/d conversion clock is software selectable. there are seven possible options for t ad : ?2 t osc ?4 t osc ?8 t osc ?16 t osc ?32 t osc ?64 t osc ? internal rc oscillator for correct a/d conversions, the a/d conversion clock (t ad ) must be as short as possible but greater than the minimum t ad (see parameter 130 in table 29-30 for more information). table 20-1 provides the resultant t ad times derived from the device operating frequencies and the a/d clock source selected. table 20-1: t ad vs. device operating frequencies 20.4 configuring analog port pins the ancon0, ancon1 and trisa registers control the operation of the a/d port pins. the port pins needed as analog inputs must have their corresponding tris bits set (input). if the tris bit is cleared (output), the digital output level (v oh or v ol ) will be converted. the a/d operation is independent of the state of the chs<3:0> bits and the tris bits. ad clock source (t ad )maximum device frequency operation adcs<2:0> 2 t osc 000 2.86 mhz 4 t osc 100 5.71 mhz 8 t osc 001 11.43 mhz 16 t osc 101 22.86 mhz 32 t osc 010 45.71 mhz 64 t osc 110 48.0 mhz rc (2) 011 1.00 mhz (1) note 1: the rc source has a typical t ad time of 4 s. 2: for device frequencies above 1 mhz, the device must be in sleep mode for the entire conversion or the a/d accuracy may be out of specification. note 1: when reading the port register, all pins configured as analog input channels will read as cleared (a low level). pins config- ured as digital inputs will convert an analog input. analog levels on a digitally configured input will be accurately converted. 2: analog levels on any pin defined as a digital input may cause the digital input buffer to consume current out of the device?s specification limits.
pic18f46j50 family ds39931b-page 346 preliminary ? 2009 microchip technology inc. 20.5 a/d conversions figure 20-3 displays the operation of the a/d converter after the go/done bit has been set and the acqt<2:0> bits are cleared. a conversion is started after the following instruction to allow entry into sleep mode before the conversion begins. figure 20-4 displays the operation of the a/d converter after the go/done bit has been set, the acqt<2:0> bits are set to ? 010 ? and selecting a 4 t ad acquisition time before the conversion starts. clearing the go/done bit during a conversion will abort the current conversion. the a/d result register pair will not be updated with the partially completed a/d conversion sample. this means the adresh:adresl registers will continue to contain the value of the last completed conversion (or the last value written to the adresh:adresl registers). after the a/d conversion is completed or aborted, a 2t ad wait is required before the next acquisition can be started. after this wait, acquisition on the selected channel is automatically started. 20.6 use of the eccp2 trigger an a/d conversion can be started by the special event trigger of the eccp2 module. this requires that the ccp2m<3:0> bits (ccp2con<3:0>) be programmed as ? 1011 ? and that the a/d module is enabled (adon bit is set). when the trigger occurs, the go/done bit will be set, starting the a/d acquisition and conversion, and the timer1 (or timer3) counter will be reset to zero. timer1 (or timer3) is reset to automatically repeat the a/d acquisition period with minimal software overhead (moving adresh/adresl to the desired location). the appropriate analog input channel must be selected and the minimum acquisition period is either timed by the user, or an appropriate t acq time is selected before the special event trigger sets the go/done bit (starts a conversion). if the a/d module is not enabled (adon is cleared), the special event trigger will be ignored by the a/d module but will still reset the timer1 (or timer3) counter. figure 20-3: a/d conversion t ad cycles (acqt<2:0> = 000 , t acq = 0 ) figure 20-4: a/d conversion t ad cycles (acqt<2:0> = 010 , t acq = 4 t ad ) note: the go/done bit should not be set in the same instruction that turns on the a/d. t ad 1 t ad 2 t ad 3 t ad 4 t ad 5 t ad 6 t ad 7 t ad 8 t ad 11 set go/done bit holding capacitor is disconnected from analog input (typically 100 ns) t ad 9 t ad 10 t cy - t ad next q4: adresh/adresl are loaded, go/done bit is cleared, adif bit is set, holding capacitor is connected to analog input. conversion starts b0 b9 b6 b5 b4 b3 b2 b1 b8 b7 1 2 3 4 5 6 7 8 11 set go/done bit (holding capacitor is disconnected) 9 10 next q4: adresh:adresl are loaded, go/done bit is cleared, adif bit is set, holding capacitor is reconnected to analog input. conversion starts 1 2 3 4 (holding capacitor continues acquiring input) t acqt cycles t ad cycles automatic acquisition time b0 b9 b6 b5 b4 b3 b2 b1 b8 b7
? 2009 microchip technology inc. preliminary ds39931b-page 347 pic18f46j50 family 20.7 a/d converter calibration the a/d converter in the pic18f46j50 family of devices includes a self-calibration feature, which com- pensates for any offset generated within the module. the calibration process is automated and is initiated by setting the adcal bit (adcon1<6>). the next time the go/done bit is set, the module will perform a ?dummy? conversion (that is, with reading none of the input channels) and store the resulting value internally to compensate for the offset. thus, subsequent offsets will be compensated. example 20-1 provides an example of a calibration routine. the calibration process assumes that the device is in a relatively steady-state operating condition. if a/d calibration is used, it should be performed after each device reset or if there are other major changes in operating conditions. 20.8 operation in power-managed modes the selection of the automatic acquisition time and a/d conversion clock is determined in part by the clock source and frequency while in a power-managed mode. if the a/d is expected to operate while the device is in a power-managed mode, the acqt<2:0> and adcs<2:0> bits in adcon1 should be updated in accordance with the power-managed mode clock that will be used. after the power-managed mode is entered (either of the power-managed run modes), an a/d acquisition or conversion may be started. once an acquisition or conversion is started, the device should continue to be clocked by the same power-managed mode clock source until the conversion has been com- pleted. if desired, the device may be placed into the corresponding power-managed idle mode during the conversion. if the power-managed mode clock frequency is less than 1 mhz, the a/d rc clock source should be selected. operation in the sleep mode requires the a/d rc clock to be selected. if bits, acqt<2:0>, are set to ? 000 ? and a conversion is started, the conversion will be delayed one instruction cycle to allow execution of the sleep instruction and entry to sleep mode. the idlen and scs bits in the osccon register must have already been cleared prior to starting the conversion. example 20-1: sample a/d calibration routine bcf ancon0,pcfg0 ;make channel 0 analog bsf adcon0,adon ;enable a/d module bsf adcon1,adcal ;enable calibration bsf adcon0,go ;start a dummy a/d conversion calibration ; btfsc adcon0,go ;wait for the dummy conversion to finish bra calibration ; bcf adcon1,adcal ;calibration done, turn off calibration enable ;proceed with the actual a/d conversion
pic18f46j50 family ds39931b-page 348 preliminary ? 2009 microchip technology inc. table 20-2: summary of a/d registers name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 61 pir1 pmpif (1) adif rc1if tx1if ssp1if ccp1if tmr2if tmr1if 63 pie1 pmpie (1) adie rc1ie tx1ie ssp1ie ccp1ie tmr2ie tmr1ie 63 ipr1 pmpip (1) adip rc1ip tx1ip ssp1ip ccp1ip tmr2ip tmr1ip 63 pir2 oscfif cm2if cm1if usbif bcl1if hlvdif tmr3if ccp2if 63 pie2 oscfie cm2ie cm1ie usbie bcl1ie hlvdie tmr3ie ccp2ie 63 ipr2 oscfip cm2ip cm1ip usbip bcl1ip hlvdip tmr3ip ccp2ip 63 adresh a/d result register high byte 62 adresl a/d result register low byte 62 adcon0 vcfg1 vcfg0 chs3 chs3 chs1 chs0 go/done adon 62 ancon0 pcfg7 (1) pcfg6 (1) pcfg5 (1) pcfg4 pcfg3 pcfg2 pcfg1 pcfg0 66 adcon1 adfm adcal acqt2 acqt1 acqt0 adcs2 adcs1 adcs0 62 ancon1 vbgen r ? pcfg12 pcfg11 pcfg10 pcfg9 pcfg8 66 ccp2con p2m1 p2m0 dc2b1 dc2b0 ccp2m3 ccp2m2 ccp2m1 ccp2m0 63 porta ra7 ra6 ra5 ? ra3 ra2 ra1 ra0 64 trisa trisa7 trisa6 trisa5 ? trisa3 trisa2 trisa1 trisa0 64 legend: ? = unimplemented, read as ? 0 ?, r = reserved. shaded cells are not used for a/d conversion. note 1: these bits are only available on 44-pin devices.
? 2009 microchip technology inc. preliminary ds39931b-page 349 pic18f46j50 family 21.0 universal serial bus (usb) this section describes the details of the usb peripheral. because of the very specific nature of the module, knowledge of usb is expected. some high-level usb information is provided in section 21.9 ?overview of usb? only for application design reference. designers are encouraged to refer to the official specification published by the usb implementers forum (usb-if) for the latest information. usb specification revision 2.0 is the most current specification at the time of publication of this document. 21.1 overview of the usb peripheral pic18f46j50 family devices contain a full-speed and low-speed, compatible usb serial interface engine (sie) that allows fast communication between any usb host and the pic ? mcu. the sie can be interfaced directly to the usb, utilizing the internal transceiver. some special hardware features have been included to improve performance. dual access port memory in the device?s data memory space (usb ram) has been supplied to share direct memory access between the microcontroller core and the sie. buffer descriptors are also provided, allowing users to freely program end- point memory usage within the usb ram space. figure 21-1 provides a general overview of the usb peripheral and its features. figure 21-1: usb peripheral and options 3.8 kbyte usb ram usb sie usb control and transceiver p p d+ d- internal pull-ups external 3.3v supply fsen upuen utrdis usb clock from the oscillator module optional external pull-ups (1) (low (full pic18f46j50 family usb bus fs speed) speed) note 1: the internal pull-up resistors should be disabled (upuen = 0 ) if external pull-up resistors are used. configuration v usb
pic18f46j50 family ds39931b-page 350 preliminary ? 2009 microchip technology inc. 21.2 usb status and control the operation of the usb module is configured and managed through three control registers. in addition, a total of 22 registers are used to manage the actual usb transactions. the registers are: ? usb control register (ucon) ? usb configuration register (ucfg) ? usb transfer status register (ustat) ? usb device address register (uaddr) ? frame number registers (ufrmh:ufrml) ? endpoint enable registers 0 through 15 (uepn) 21.2.1 usb control register (ucon) the usb control register (register 21-1) contains bits needed to control the module behavior during transfers. the register contains bits that control the following: ? main usb peripheral enable ? ping-pong buffer pointer reset ? control of the suspend mode ? packet transfer disable in addition, the usb control register contains a status bit, se0 (ucon<5>), which is used to indicate the occurrence of a single-ended zero on the bus. when the usb module is enabled, this bit should be monitored to determine whether the differential data lines have come out of a single-ended zero condition. this helps to differentiate the initial power-up state from the usb reset signal. the overall operation of the usb module is controlled by the usben bit (ucon<3>). setting this bit activates the module and resets all of the ppbi bits in the buffer descriptor table (bdt) to ? 0 ?. this bit also activates the internal pull-up resistors, if they are enabled. thus, this bit can be used as a soft attach/detach to the usb. although all status and control bits are ignored when this bit is clear, the module needs to be fully preconfig- ured prior to setting this bit. the usb clock source should have been already configured for the correct frequency and running. if the pll is being used, it should be enabled at least 2 ms (enough time for the pll to lock) before attempting to set the usben bit. note: when disabling the usb module, make sure the suspnd bit (ucon<1>) is clear prior to clearing the usben bit. clearing the usben bit when the module is in the suspended state may prevent the module from fully powering down
? 2009 microchip technology inc. preliminary ds39931b-page 351 pic18f46j50 family register 21-1: ucon: usb cont rol register (access f65h) u-0 r/w-0 r-x r/c-0 r/w-0 r/w-0 r/w-0 u-0 ? ppbrst se0 pktdis usben (1) resume suspnd ? bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 ppbrst: ping-pong buffers reset bit 1 = reset all ping-pong buffer pointers to the even buffer descriptor (bd) banks 0 = ping-pong buffer pointers not being reset bit 5 se0: live single-ended zero flag bit 1 = single-ended zero active on the usb bus 0 = no single-ended zero detected bit 4 pktdis: packet transfer disable bit 1 = sie token and packet processing disabled, automatically set when a setup token is received 0 = sie token and packet processing enabled bit 3 usben: usb module enable bit (1) 1 = usb module and supporting circuitry enabled (device attached) 0 = usb module and supporting circuitry disabled (device detached) bit 2 resume: resume signaling enable bit 1 = resume signaling activated 0 = resume signaling disabled bit 1 suspnd: suspend usb bit 1 = usb module and supporting circuitry in power conserve mode, sie clock inactive 0 = usb module and supporting circuitry in normal operation, sie clocked at the configured rate bit 0 unimplemented : read as ? 0 ? note 1: make sure the usb clock source is correctly configured before setting this bit.
pic18f46j50 family ds39931b-page 352 preliminary ? 2009 microchip technology inc. the ppbrst bit (ucon<6>) controls the reset status when double-buffering mode (ping-pong buffering) is used. when the ppbrst bit is set, all ping-pong buffer pointers are set to the even buffers. ppbrst has to be cleared by firmware. this bit is ignored in buffering modes not using ping-pong buffering. the pktdis bit (ucon<4>) is a flag indicating that the sie has disabled packet transmission and reception. this bit is set by the sie when a setup token is received to allow setup processing. this bit cannot be set by the microcontroller, only cleared; clearing it allows the sie to continue transmission and/or reception. any pending events within the buffer descriptor table will still be available, indicated within the ustat register?s fifo buffer. the resume bit (ucon<2>) allows the peripheral to perform a remote wake-up by executing resume signaling. to generate a valid remote wake-up, firmware must set resume for 10 ms and then clear the bit. for more information on resume signaling, see sections 7.1.7.5, 11.4.4 and 11.9 in the usb 2.0 specification. the suspnd bit (ucon<1>) places the module and supporting circuitry in a low-power mode. the input clock to the sie is also disabled. this bit should be set by the software in response to an idleif interrupt. it should be reset by the microcontroller firmware after an actvif interrupt is observed. when this bit is active, the device remains attached to the bus but the trans- ceiver outputs remain idle. the voltage on the v usb pin may vary depending on the value of this bit. setting this bit before a idleif request will result in unpredictable bus behavior. 21.2.2 usb configuration register (ucfg) prior to communicating over usb, the module?s associated internal and/or external hardware must be configured. most of the configuration is performed with the ucfg register (register 21-2).the ufcg register contains most of the bits that control the system level behavior of the usb module. these include: ? bus speed (full speed versus low speed) ? on-chip pull-up resistor enable ? on-chip transceiver enable ? ping-pong buffer usage the ucfg register also contains two bits, which aid in module testing, debugging and usb certifications. these bits control output enable state monitoring and eye pattern generation. 21.2.2.1 internal transceiver the usb peripheral has a built-in, usb 2.0, full-speed and low-speed capable transceiver, internally con- nected to the sie. this feature is useful for low-cost, single chip applications. the utrdis bit (ucfg<3>) controls the transceiver; it is enabled by default (utrdis = 0 ). the fsen bit (ucfg<2>) controls the transceiver speed; setting the bit enables full-speed operation. the on-chip usb pull-up resistors are controlled by the upuen bit (ucfg<4>). they can only be selected when the on-chip transceiver is enabled. the internal usb transceiver obtains power from the v usb pin. in order to meet usb signalling level specifi- cations, v usb must be supplied with a voltage source between 3.0v and 3.6v. the best electrical signal quality is obtained when a 3.3v supply is used and locally bypassed with a high quality ceramic capacitor (ex: 0.1 f). the capacitor should be placed as close as possible to the v usb and v ss pins. v usb should always be maintained v dd . if the usb module is not used, but rc4 or rc5 are used as general purpose inputs, v usb should still be connected to a power source (such as v dd ). the input thresholds for the rc4 and rc5 pins are dependent upon the v usb supply level. the d+ and d- signal lines can be routed directly to their respective pins on the usb connector or cable (for hard-wired applications). no additional resistors, capacitors, or magnetic components are required as the d+ and d- drivers have controlled slew rate and output impedance intended to match with the characteristic impedance of the usb cable. in order to achieve optimum usb signal quality, the d+ and d- traces between the microcontroller and usb connector (or cable) should be less than 19 cm long. both traces should be equal in length and they should be routed parallel to each other. ideally, these traces should be designed to have a characteristic impedance matching that of the usb cable. note: while in suspend mode, a typical bus-powered usb device is limited to 2.5 ma of current. this is the complete current which may be drawn by the pic device and its supporting circuitry. care should be taken to assure minimum current draw when the device enters suspend mode. note: the usb speed, transceiver and pull-up should only be configured during the module setup phase. it is not recom- mended to switch these settings while the module is enabled.
? 2009 microchip technology inc. preliminary ds39931b-page 353 pic18f46j50 family register 21-2: ucfg: usb config uration register (banked f39h) r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 uteye uoemon ? upuen (1,2) utrdis (1,3) fsen (1) ppb1 ppb0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 uteye: usb eye pattern test enable bit 1 = eye pattern test enabled 0 = eye pattern test disabled bit 6 uoemon: usb oe monitor enable bit 1 =uoe signal active, indicating intervals during which the d+/d- lines are driving 0 =uoe signal inactive bit 5 unimplemented: read as ? 0 ? bit 4 upuen: usb on-chip pull-up enable bit (1,2) 1 = on-chip pull-up enabled (pull-up on d+ with fsen = 1 or d- with fsen = 0 ) 0 = on-chip pull-up disabled bit 3 utrdis: on-chip transceiver disable bit (1,3) 1 = on-chip transceiver disabled 0 = on-chip transceiver active bit 2 fsen: full-speed enable bit (1) 1 = full-speed device: controls transceiver edge rates; requires input clock at 48 mhz 0 = low-speed device: controls transceiver edge rates; requires input clock at 6 mhz bit 1-0 ppb<1:0>: ping-pong buffers configuration bits 11 = even/odd ping-pong buffers enabled for endpoints 1 to 15 10 = even/odd ping-pong buffers enabled for all endpoints 01 = even/odd ping-pong buffer enabled for out endpoint 0 00 = even/odd ping-pong buffers disabled note 1: the upuen, utrdis and fsen bits should never be changed while the usb module is enabled. these values must be preconfigured prior to enabling the module. 2: this bit is only valid when the on-chip transceiver is active (utrdis = 0 ); otherwise, it is ignored. 3: if utrdis is set, the uoe signal will be active ? independent of the uoemon bit setting.
pic18f46j50 family ds39931b-page 354 preliminary ? 2009 microchip technology inc. 21.2.2.2 internal pull-up resistors the pic18f46j50 family devices have built-in pull-up resistors designed to meet the requirements for low-speed and full-speed usb. the upuen bit (ucfg<4>) enables the internal pull-ups. figure 21-1 shows the pull-ups and their control. 21.2.2.3 external pull-up resistors external pull-ups may also be used. the v usb pin may be used to pull up d+ or d-. the pull-up resistor must be 1.5 k (5%) as required by the usb specifications. figure 21-2 provides an example of external circuitry. figure 21-2: external circuitry 21.2.2.4 ping-pong buffer configuration the usage of ping-pong buffers is configured using the ppb<1:0> bits. refer to section 21.4.4 ?ping-pong buffering? for a complete explanation of the ping-pong buffers. 21.2.2.5 eye pattern test enable an automatic eye pattern test can be generated by the module when the ucfg<7> bit is set. the eye pattern output will be observable based on module settings, meaning that the user is first responsible for configuring the sie clock settings, pull-up resistor and transceiver mode. in addition, the module has to be enabled. once uteye is set, the module emulates a switch from a receive to transmit state and will start transmitting a j-k-j-k bit sequence (k-j-k-j for full speed). the sequence will be repeated indefinitely while the eye pattern test mode is enabled. note that this bit should never be set while the module is connected to an actual usb system. this test mode is intended for board verification to aid with usb certi- fication tests. it is intended to show a system developer the noise integrity of the usb signals which can be affected by board traces, impedance mismatches and proximity to other system components. it does not properly test the transition from a receive to a transmit state. although the eye pattern is not meant to replace the more complex usb certification test, it should aid during first order system debugging. note: a compliant usb device should never source any current onto the +5v v bus line of the usb cable. additionally, usb devices should not source any current on the d+ and d- data lines whenever the +5v v bus line is less than 1.17v. in order to be usb compliant, applications which are not purely bus-powered should moni- tor the v bus line and avoid turning on the usb module and the d+ or d- pull-up resistor until v bus is greater than 1.17v. v bus can be connected to and monitored by a 5v tolerant i/o pin, or if a resistive divider is used, by an analog capable pin. pic ? mcu host controller/hub v usb d+ d- note: the above setting shows a typical connection for a full-speed configuration using an on-chip regulator and an external pull-up resistor. 1.5 k
? 2009 microchip technology inc. preliminary ds39931b-page 355 pic18f46j50 family 21.2.3 usb status register (ustat) the usb status register reports the transaction status within the sie. when the sie issues a usb transfer complete interrupt, ustat should be read to determine the status of the transfer. ustat contains the transfer endpoint number, direction and ping-pong buffer pointer value (if used). the ustat register is actually a read window into a four-byte status fifo, maintained by the sie. it allows the microcontroller to process one transfer while the sie processes additional endpoints (figure 21-3). when the sie completes using a buffer for reading or writing data, it updates the ustat register. if another usb transfer is performed before a transaction complete interrupt is serviced, the sie will store the status of the next transfer into the status fifo. clearing the transfer complete flag bit, trnif, causes the sie to advance the fifo. if the next data in the fifo holding register is valid, the sie will reassert the interrupt within 5 t cy of clearing trnif. if no additional data is present, trnif will remain clear; ustat data will no longer be reliable. figure 21-3: ustat fifo note: the data in the usb status register is valid only when the trnif interrupt flag is asserted. note: if an endpoint request is received while the ustat fifo is full, the sie will automatically issue a nak back to the host. data bus ustat from sie 4-byte fifo for ustat clearing trnif advances fifo register 21-3: ustat: usb status register (access f64h) u-0 r-x r-x r-x r-x r-x r-x u-0 ? endp3 endp2 endp1 endp0 dir ppbi (1) ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-3 endp<3:0>: encoded number of last endpoint activity bits (represents the number of the bdt updated by the last usb transfer) 1111 = endpoint 15 1110 = endpoint 14 . . . 0001 = endpoint 1 0000 = endpoint 0 bit 2 dir: last bd direction indicator bit 1 = the last transaction was an in token 0 = the last transaction was an out or setup token bit 1 ppbi: ping-pong bd pointer indicator bit (1) 1 = the last transaction was to the odd bd bank 0 = the last transaction was to the even bd bank bit 0 unimplemented: read as ? 0 ? note 1: this bit is only valid for endpoints with available even and odd bd registers.
pic18f46j50 family ds39931b-page 356 preliminary ? 2009 microchip technology inc. 21.2.4 usb endpoint control each of the 16 possible bidirectional endpoints has its own independent control register, uepn (where ?n? represents the endpoint number). each register has an identical complement of control bits. register 21-4 provides the prototype. the ephshk bit (uepn<4>) controls handshaking for the endpoint; setting this bit enables usb handshaking. typically, this bit is always set except when using isochronous endpoints. the epcondis bit (uepn<3>) is used to enable or disable usb control operations (setup) through the endpoint. clearing this bit enables setup transac- tions. note that the corresponding epinen and epouten bits must be set to enable in and out transactions. for endpoint 0, this bit should always be cleared since the usb specifications identify endpoint 0 as the default control endpoint. the epouten bit (uepn<2>) is used to enable or disable usb out transactions from the host. setting this bit enables out transactions. similarly, the epinen bit (uepn<1>) enables or disables usb in transactions from the host. the epstall bit (uepn<0>) is used to indicate a stall condition for the endpoint. if a stall is issued on a particular endpoint, the epstall bit for that end- point pair will be set by the sie. this bit remains set until it is cleared through firmware, or until the sie is reset. register 21-4: uepn: usb endpoint n co ntrol register (uep0 through uep15) (banked f26h-f35h) u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? ephshk epcondis epouten epinen epstall bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 ephshk: endpoint handshake enable bit 1 = endpoint handshake enabled 0 = endpoint handshake disabled (typically used for isochronous endpoints) bit 3 epcondis: bidirectional endpoint control bit if epouten = 1 and epinen = 1 : 1 = disable endpoint n from control transfers; only in and out transfers allowed 0 = enable endpoint n for control (setup) transfers; in and out transfers also allowed bit 2 epouten: endpoint output enable bit 1 = endpoint n output enabled 0 = endpoint n output disabled bit 1 epinen: endpoint input enable bit 1 = endpoint n input enabled 0 = endpoint n input disabled bit 0 epstall: endpoint stall indicator bit 1 = endpoint n has issued one or more stall packets 0 = endpoint n has not issued any stall packets
? 2009 microchip technology inc. preliminary ds39931b-page 357 pic18f46j50 family 21.2.5 usb address register (uaddr) the usb address register contains the unique usb address that the peripheral will decode when active. uaddr is reset to 00h when a usb reset is received, indicated by urstif, or when a reset is received from the microcontroller. the usb address must be written by the microcontroller during the usb setup phase (enumeration) as part of the microchip usb firmware support. 21.2.6 usb frame number registers (ufrmh:ufrml) the frame number registers contain the 11-bit frame number. the low-order byte is contained in ufrml, while the three high-order bits are contained in ufrmh. the register pair is updated with the current frame number whenever a sof token is received. for the microcontroller, these registers are read-only. the frame number registers are primarily used for isochronous transfers. the contents of the ufrmh and ufrml registers are only valid when the 48 mhz sie clock is active (i.e., contents are inaccurate when suspnd (ucon<1>) bit = 1 ). 21.3 usb ram usb data moves between the microcontroller core and the sie through a memory space known as the usb ram. this is a special dual access memory that is mapped into the normal data memory space in banks 0 through 14 (00h to ebfh) for a total of 3.8 kbytes (figure 21-4). bank 4 (400h through 4ffh) is used specifically for endpoint buffer control, while banks 0 through 3 and banks 5 through 14 are available for usb data. depending on the type of buffering being used, all but 8 bytes of bank 4 may also be available for use as usb buffer space. although usb ram is available to the microcontroller as data memory, the sections that are being accessed by the sie should not be accessed by the microcontroller. a semaphore mechanism is used to determine the access to a particular buffer at any given time. this is discussed in section 21.4.1.1 ?buffer ownership? . figure 21-4: implementation of usb ram in data memory space 400h 4ffh 500h usb data or buffer descriptors, usb data or user data user data usb data or sfrs 3ffh 000h fffh banks 0 (usb ram) to 14 access ram 060h 05fh ec0h ebfh user data
pic18f46j50 family ds39931b-page 358 preliminary ? 2009 microchip technology inc. 21.4 buffer descriptors and the buffer descriptor table the registers in bank 4 are used specifically for end- point buffer control in a structure known as the buffer descriptor table (bdt). this provides a flexible method for users to construct and control endpoint buffers of various lengths and configuration. the bdt is composed of buffer descriptors (bd) which are used to define and control the actual buffers in the usb ram space. each bd, in turn, consists of four registers, where n represents one of the 64 possible bds (range of 0 to 63): ? bdnstat: bd status register ? bdncnt: bd byte count register ? bdnadrl: bd address low register ? bdnadrh: bd address high register bds always occur as a four-byte block in the sequence, bdnstat:bdncnt:bdnadrl:bdnadrh. the address of bdnstat is always an offset of (4n ? 1) (in hexa- decimal) from 400h, with n being the buffer descriptor number. depending on the buffering configuration used ( section 21.4.4 ?ping-pong buffering? ), there are up to 32, 33 or 64 sets of buffer descriptors. at a minimum, the bdt must be at least 8 bytes long. this is because the usb specification mandates that every device must have endpoint ?0? with both input and output for initial setup. depending on the endpoint and buffering configuration, the bdt can be as long as 256 bytes. although they can be thought of as special function registers, the buffer descriptor status and address registers are not hardware mapped, as conventional microcontroller sfrs in bank 15 are. if the endpoint cor- responding to a particular bd is not enabled, its registers are not used. instead of appearing as unimplemented addresses, however, they appear as available ram. only when an endpoint is enabled by setting the uepn<1> bit does the memory at those addresses become functional as bd registers. as with any address in the data memory space, the bd registers have an indeterminate value on any device reset. figure 21-5 provides an example of a bd for a 64-byte buffer, starting at 500h. a particular set of bd registers is only valid if the corresponding endpoint has been enabled using the uepn register. all bd registers are available in usb ram. the bd for each endpoint should be set up prior to enabling the endpoint. 21.4.1 bd status and configuration buffer descriptors not only define the size of an end- point buffer, but also determine its configuration and control. most of the configuration is done with the bd status register, bdnstat. each bd has its own unique and correspondingly numbered bdnstat register. figure 21-5: example of a buffer descriptor unlike other control registers, the bit configuration for the bdnstat register is context sensitive. there are two distinct configurations, depending on whether the microcontroller or the usb module is modifying the bd and buffer at a particular time. only three bit definitions are shared between the two. 21.4.1.1 buffer ownership because the buffers and their bds are shared between the cpu and the usb module, a simple semaphore mechanism is used to distinguish which is allowed to update the bd and associated buffers in memory. this is done by using the uown bit (bdnstat<7>) as a semaphore to distinguish which is allowed to update the bd and associated buffers in memory. uown is the only bit that is shared between the two configurations of bdnstat. when uown is clear, the bd entry is ?owned? by the microcontroller core. when the uown bit is set, the bd entry and the buffer memory are ?owned? by the usb peripheral. the core should not modify the bd or its corresponding data buffer during this time. note that the microcontroller core can still read bdnstat while the sie owns the buffer and vice versa. the buffer descriptors have a different meaning based on the source of the register update. prior to placing ownership with the usb peripheral, the user can configure the basic operation of the peripheral through the bdnstat bits. during this time, the byte count and buffer location registers can also be set. when uown is set, the user can no longer depend on the values that were written to the bds. from this point, the sie updates the bds as necessary, overwriting the original bd values. the bdnstat register is updated by the sie with the token pid and the transfer count, bdncnt, is updated. 400h usb data buffer buffer bd0stat bd0cnt bd0adrl bd0adrh 401h 402h 403h 500h 53fh descriptor note: memory regions not to scale. 40h 00h 05h starting size of block (xxh) registers address contents address
? 2009 microchip technology inc. preliminary ds39931b-page 359 pic18f46j50 family the bdnstat byte of the bdt should always be the last byte updated when preparing to arm an endpoint. the sie will clear the uown bit when a transaction has completed. no hardware mechanism exists to block access when the uown bit is set. thus, unexpected behavior can occur if the microcontroller attempts to modify memory when the sie owns it. similarly, reading such memory may produce inaccurate data until the usb peripheral returns ownership to the microcontroller. 21.4.1.2 bdnstat register (cpu mode) when uown = 0 , the microcontroller core owns the bd. at this point, the other seven bits of the register take on control functions. the data toggle sync enable bit, dtsen (bdnstat<3>), controls data toggle parity checking. setting dtsen enables data toggle synchronization by the sie. when enabled, it checks the data packet?s par- ity against the value of dts (bdnstat<6>). if a packet arrives with an incorrect synchronization, the data will essentially be ignored. it will not be written to the usb ram and the usb transfer complete interrupt flag will not be set. the sie will send an ack token back to the host to acknowledge receipt, however. the effects of the dtsen bit on the sie are summarized in table 21-1. the buffer stall bit, bstall (bdnstat<2>), provides support for control transfers, usually one-time stalls on endpoint 0. it also provides support for the set_feature/clear_feature commands speci- fied in chapter 9 of the usb specification; typically, continuous stalls to any endpoint other than the default control endpoint. the bstall bit enables buffer stalls. setting bstall causes the sie to return a stall token to the host if a received token would use the bd in that location. the epstall bit in the corresponding uepn control register is set and a stall interrupt is generated when a stall is issued to the host. the uown bit remains set and the bds are not changed unless a setup token is received. in this case, the stall condition is cleared and the ownership of the bd is returned to the microcontroller core. the bd<9:8> bits (bdnstat<1:0>) store the two most significant digits of the sie byte count; the lower 8 digits are stored in the corresponding bdncnt register. see section 21.4.2 ?bd byte count? for more information. table 21-1: effect of dtsen bit on odd/even (data0/data1) packet reception out packet from host bdnstat settings device response after receiving packet dtsen dts handshake uown trnif bdnstat and ustat status data0 10 ack 01 updated data1 10 ack 10 not updated data0 11 ack 10 not updated data1 11 ack 01 updated either 0x ack 01 updated either, with error xx nak 10 not updated legend: x = don?t care
pic18f46j50 family ds39931b-page 360 preliminary ? 2009 microchip technology inc. register 21-5: bdnstat: buffer descriptor n status register (bd0stat through bd63stat), cpu mode (banked 4xxh) r/w-x r/w-x u-0 u-0 r/w-x r/w-x r/w-x r/w-x uown (1) dts (2) ? (3) ? (3) dtsen bstall bc9 bc8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 uown: usb own bit (1) 0 = the microcontroller core owns the bd and its corresponding buffer bit 6 dts: data toggle synchronization bit (2) 1 = data 1 packet 0 = data 0 packet bit 5-4 unimplemented: these bits should always be programmed to ? 0 ? (3) bit 3 dtsen: data toggle synchronization enable bit 1 = data toggle synchronization is enabled; data packets with incorrect sync value will be ignored except for a setup transaction, which is accepted even if the data toggle bits do not match 0 = no data toggle synchronization is performed bit 2 bstall: buffer stall enable bit 1 = buffer stall enabled; stall handshake issued if a token is received that would use the bd in the given location (uown bit remains set, bd value is unchanged) 0 = buffer stall disabled bit 1-0 bc<9:8>: byte count 9 and 8 bits the byte count bits represent the number of bytes that will be transmitted for an in token or received during an out token. together with bc<7:0>, the valid byte counts are 0-1023. note 1: this bit must be initialized by the user to the desired value prior to enabling the usb module. 2: this bit is ignored unless dtsen = 1 . 3: if these bits are set, usb communication may not work. hence, these bits should always be maintained as ? 0 ?.
? 2009 microchip technology inc. preliminary ds39931b-page 361 pic18f46j50 family 21.4.1.3 bdnstat register (sie mode) when the bd and its buffer are owned by the sie, most of the bits in bdnstat take on a different meaning. the configuration is shown in register 21-6. once uown is set, any data or control settings previously written there by the user will be overwritten with data from the sie. the bdnstat register is updated by the sie with the token packet identifier (pid) which is stored in bdnstat<5:2>. the transfer count in the correspond- ing bdncnt register is updated. values that overflow the 8-bit register carry over to the two most significant digits of the count, stored in bdnstat<1:0>. 21.4.2 bd byte count the byte count represents the total number of bytes that will be transmitted during an in transfer. after an in transfer, the sie will return the number of bytes sent to the host. for an out transfer, the byte count represents the maximum number of bytes that can be received and stored in usb ram. after an out transfer, the sie will return the actual number of bytes received. if the number of bytes received exceeds the corresponding byte count, the data packet will be rejected and a nak handshake will be generated. when this happens, the byte count will not be updated. the 10-bit byte count is distributed over two registers. the lower 8 bits of the count reside in the bdncnt register. the upper two bits reside in bdnstat<1:0>. this represents a valid byte range of 0 to 1023. 21.4.3 bd address validation the bd address register pair contains the starting ram address location for the corresponding endpoint buffer. no mechanism is available in hardware to validate the bd address. if the value of the bd address does not point to an address in the usb ram, or if it points to an address within another endpoint?s buffer, data is likely to be lost or overwritten. similarly, overlapping a receive buffer (out endpoint) with a bd location in use can yield unexpected results. when developing usb applications, the user may want to consider the inclusion of software-based address validation in their code. register 21-6: bdnstat: buffer descriptor n status register (bd0stat through bd63stat), sie mode (data ret urned by the sie to the mcu) (banked 4xxh) r/w-x r-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x uown ? pid3 pid2 pid1 pid0 bc9 bc8 bit 7 bit 0 legend: r = reserved r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 uown: usb own bit 1 = the sie owns the bd and its corresponding buffer bit 6 reserved: not written by the sie bit 5-2 pid<3:0>: packet identifier bits the received token pid value of the last transfer (in, out or setup transactions only). bit 1-0 bc<9:8>: byte count 9 and 8 bits these bits are updated by the sie to reflect the actual number of bytes received on an out transfer and the actual number of bytes transmitted on an in transfer.
pic18f46j50 family ds39931b-page 362 preliminary ? 2009 microchip technology inc. 21.4.4 ping-pong buffering an endpoint is defined to have a ping-pong buffer when it has two sets of bd entries: one set for an even transfer and one set for an odd transfer. this allows the cpu to process one bd while the sie is processing the other bd. double-buffering bds in this way allows for maximum throughput to/from the usb. the usb module supports four modes of operation: ? no ping-pong support ? ping-pong buffer support for out endpoint 0 only ? ping-pong buffer support for all endpoints ? ping-pong buffer support for all other endpoints except endpoint 0 the ping-pong buffer settings are configured using the ppb<1:0> bits in the ucfg register. the usb module keeps track of the ping-pong pointer individually for each endpoint. all pointers are initially reset to the even bd when the module is enabled. after the completion of a transaction (uown cleared by the sie), the pointer is toggled to the odd bd. after the completion of the next transaction, the pointer is toggled back to the even bd and so on. the even/odd status of the last transaction is stored in the ppbi bit of the ustat register. the user can reset all ping-pong pointers to even using the ppbrst bit. figure 21-6 shows the four different modes of operation and how usb ram is filled with the bds. bds have a fixed relationship to a particular endpoint, depending on the buffering configuration. table 21-2 provides the mapping of bds to endpoints. this relationship also means that gaps may occur in the bdt if endpoints are not enabled contiguously. this theoretically means that the bds for disabled endpoints could be used as buffer space. in practice, users should avoid using such spaces in the bdt unless a method of validating bd addresses is implemented. figure 21-6: buffer descriptor t able mapping for buffering modes ep1 in even ep1 out even ep1 out odd ep1 in odd descriptor descriptor descriptor descriptor ep1 in ep15 in ep1 out ep0 out ppb<1:0> = 00 ep0 in ep1 in no ping-pong ep15 in ep0 in ep0 out even ppb<1:0> = 01 ep0 out odd ep1 out ping-pong buffer ep15 in odd ep0 in even ep0 out even ppb<1:0> = 10 ep0 out odd ep0 in odd ping-pong buffers descriptor descriptor descriptor descriptor descriptor descriptor descriptor descriptor descriptor descriptor descriptor descriptor 400h 4ffh 4ffh 4ffh 400h 400h 47fh 483h available as data ram available as data ram maximum memory used: 128 bytes maximum bds: 32 (bd0 to bd31) maximum memory used: 132 bytes maximum bds: 33 (bd0 to bd32) maximum memory used: 256 bytes maximum bds: 6 4 (bd0 to bd63) note: memory area not shown to scale. descriptor descriptor descriptor descriptor buffers on ep0 out on all eps ep1 in even ep1 out even ep1 out odd ep1 in odd descriptor descriptor descriptor descriptor ep15 in odd ep0 out ppb<1:0> = 11 ep0 in ping-pong buffers descriptor descriptor descriptor 4ffh 400h maximum memory used: 248 bytes maximum bds: 62 (bd0 to bd61) on all other eps except ep0 available as data ram 4f7h
? 2009 microchip technology inc. preliminary ds39931b-page 363 pic18f46j50 family table 21-2: assignment of buffer descriptors for the different buffering modes table 21-3: summary of usb buffer descriptor table registers endpoint bds assigned to endpoint mode 0 (no ping-pong) mode 1 (ping-pong on ep0 out) mode 2 (ping-pong on all eps) mode 3 (ping-pong on all other eps, except ep0) out in out in out in out in 0 0 1 0 (e), 1 (o) 2 0 (e), 1 (o) 2 (e), 3 (o) 0 1 1 2 3 3 4 4 (e), 5 (o) 6 (e), 7 (o) 2 (e), 3 (o) 4 (e), 5 (o) 2 4 5 5 6 8 (e), 9 (o) 10 (e), 11 (o) 6 (e), 7 (o) 8 (e), 9 (o) 3 6 7 7 8 12 (e), 13 (o) 14 (e), 15 (o) 10 (e), 11 (o) 12 (e), 13 (o) 4 8 9 9 10 16 (e), 17 (o) 18 (e), 19 (o) 14 (e), 15 (o) 16 (e), 17 (o) 5 10 11 11 12 20 (e), 21 (o) 22 (e), 23 (o) 18 (e), 19 (o) 20 (e), 21 (o) 6 12 13 13 14 24 (e), 25 (o) 26 (e), 27 (o) 22 (e), 23 (o) 24 (e), 25 (o) 7 14 15 15 16 28 (e), 29 (o) 30 (e), 31 (o) 26 (e), 27 (o) 28 (e), 29 (o) 8 16 17 17 18 32 (e), 33 (o) 34 (e), 35 (o) 30 (e), 31 (o) 32 (e), 33 (o) 9 18 19 19 20 36 (e), 37 (o) 38 (e), 39 (o) 34 (e), 35 (o) 36 (e), 37 (o) 10 20 21 21 22 40 (e), 41 (o) 42 (e), 43 (o) 38 (e), 39 (o) 40 (e), 41 (o) 11 22 23 23 24 44 (e), 45 (o) 46 (e), 47 (o) 42 (e), 43 (o) 44 (e), 45 (o) 12 24 25 25 26 48 (e), 49 (o) 50 (e), 51 (o) 46 (e), 47 (o) 48 (e), 49 (o) 13 26 27 27 28 52 (e), 53 (o) 54 (e), 55 (o) 50 (e), 51 (o) 52 (e), 53 (o) 14 28 29 29 30 56 (e), 57 (o) 58 (e), 59 (o) 54 (e), 55 (o) 56 (e), 57 (o) 15 30 31 31 32 60 (e), 61 (o) 62 (e), 63 (o) 58 (e), 59 (o) 60 (e), 61 (o) legend: (e) = even transaction buffer, (o) = odd transaction buffer name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bdnstat (1) uown dts (4) pid3 (2) pid2 (2) pid1 (2) dtsen (3) pid0 (2) bstall (3) bc9 bc8 bdncnt (1) byte count bdnadrl (1) buffer address low bdnadrh (1) buffer address high note 1: for buffer descriptor registers, n may have a value of 0 to 63. for the sake of brevity, all 64 registers are shown as one generic prototype. all registers have indeterminate reset values ( xxxx xxxx ). 2: bits 5 through 2 of the bdnstat register are used by the sie to return pid<3:0> values once the register is turned over to the sie (uown bit is set). once the registers have been under sie control, the values written for dtsen and bstall are no longer valid. 3: prior to turning the buffer descriptor over to the sie (uown bit is cleared), bits 5 through 2 of the bdnstat register are used to configure the dtsen and bstall settings. 4: this bit is ignored unless dtsen = 1 .
pic18f46j50 family ds39931b-page 364 preliminary ? 2009 microchip technology inc. 21.5 usb interrupts the usb module can generate multiple interrupt con- ditions. to accommodate all of these interrupt sources, the module is provided with its own interrupt logic structure, similar to that of the microcontroller. usb interrupts are enabled with one set of control registers and trapped with a separate set of flag registers. all sources are funneled into a single usb interrupt request, usbif (pir2<4>), in the microcontroller?s interrupt logic. figure 21-7 provides the interrupt logic for the usb module. there are two layers of interrupt registers in the usb module. the top level consists of overall usb status interrupts; these are enabled and flagged in the uie and uir registers, respectively. the second level consists of usb error conditions, which are enabled and flagged in the ueir and ueie registers. an interrupt condition in any of these triggers a usb error interrupt flag (uerrif) in the top level. interrupts may be used to trap routine events in a usb transaction. figure 21-8 provides some common events within a usb frame and their corresponding interrupts. figure 21-7: usb interrupt logic funnel figure 21-8: example of a usb transaction and interrupt events btsef btsee btoef btoee dfn8ef dfn8ee crc16ef crc16ee crc5ef crc5ee pidef pidee sofif sofie trnif trnie idleif idleie stallif stallie actvif actvie urstif urstie uerrif uerrie usbif second level usb interrupts (usb error conditions) ueir (flag) and ueie (enable) registers top level usb interrupts (usb status interrupts) uir (flag) and uie (enable) registers usb reset sof reset setup data status sof setup token data ack out token empty data ack start-of-frame (sof) in token data ack sofif urstif 1 ms frame differential data from host from host to h o s t from host to host from host from host from host to h o s t transaction control transfer (1) transaction complete note 1: the control transfer shown here is only an example showin g events that can occur for every transaction. typical control transfers will spread across multiple frames. set trnif set trnif set trnif
? 2009 microchip technology inc. preliminary ds39931b-page 365 pic18f46j50 family 21.5.1 usb interrupt status register (uir) the usb interrupt status register (register 21-7) con- tains the flag bits for each of the usb status interrupt sources. each of these sources has a corresponding interrupt enable bit in the uie register. all of the usb status flags are ored together to generate the usbif interrupt flag for the microcontroller?s interrupt funnel. once an interrupt bit has been set by the sie, it must be cleared by software by writing a ? 0 ?. the flag bits can also be set in software, which can aid in firmware debugging. when the usb module is in the low-power suspend mode (ucon<1> = 1 ), the sie does not get clocked. when in this state, the sie cannot process packets and, therefore, cannot detect new interrupt conditions other than the activity detect interrupt, actvif. the actvif bit is typically used by usb firmware to detect when the microcontroller should bring the usb module out of the low-power suspend mode (ucon<1> = 0 ). register 21-7: uir: usb interrupt status register (access f62h) u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 r/w-0 ? sofif stallif idleif (1) trnif (2) actvif (3) uerrif (4) urstif bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 sofif: start-of-frame token interrupt bit 1 = a start-of-frame token received by the sie 0 = no start-of-frame token received by the sie bit 5 stallif: a stall handshake interrupt bit 1 = a stall handshake was sent by the sie 0 = a stall handshake has not been sent bit 4 idleif: idle detect interrupt bit (1) 1 = idle condition detected (constant idle state of 3 ms or more) 0 = no idle condition detected bit 3 trnif: transaction complete interrupt bit (2) 1 = processing of pending transaction is complete; read ustat register for endpoint information 0 = processing of pending transaction is not complete or no transaction is pending bit 2 actvif: bus activity detect interrupt bit (3) 1 = activity on the d+/d- lines was detected 0 = no activity detected on the d+/d- lines bit 1 uerrif: usb error condition interrupt bit (4) 1 = an unmasked error condition has occurred 0 = no unmasked error condition has occurred. bit 0 urstif: usb reset interrupt bit 1 = valid usb reset occurred; 00h is loaded into uaddr register 0 = no usb reset has occurred note 1: once an idle state is detected, the user may want to place the usb module in suspend mode. 2: clearing this bit will cause the ustat fifo to advance (valid only for in, out and setup tokens). 3: this bit is typically unmasked only following the detection of a uidle interrupt event. 4: only error conditions enabled through the ueie register will set this bit. this bit is a status bit only and cannot be set or cleared by the user.
pic18f46j50 family ds39931b-page 366 preliminary ? 2009 microchip technology inc. 21.5.1.1 bus activity detect interrupt bit (actvif) the actvif bit cannot be cleared immediately after the usb module wakes up from suspend or while the usb module is suspended. a few clock cycles are required to synchronize the internal hardware state machine before the actvif bit can be cleared by firmware. clearing the actvif bit before the internal hardware is synchronized may not have an effect on the value of actvif. additionally, if the usb module uses the clock from the 96 mhz pll source, then after clearing the suspnd bit, the usb module may not be immediately operational while waiting for the 96 mhz pll to lock. the application code should clear the actvif flag as provided in example 21-1. example 21-1: clearing actvif bit (uir<2>) note: only one actvif interrupt is generated when resuming from the usb bus idle con- dition. if user firmware clears the actvif bit, the bit will not immediately become set again, even when there is continuous bus traffic. bus traffic must cease long enough to generate another idleif condition before another actvif interrupt can be generated. assembly: bcf ucon, suspnd loop: btfss uir, actvif bra done bcf uir, actvif bra loop done: c: uconbits.suspnd = 0; while (uirbits.actvif) { uirbits.actvif = 0; }
? 2009 microchip technology inc. preliminary ds39931b-page 367 pic18f46j50 family 21.5.2 usb interrupt enable register (uie) the usb interrupt enable (uie) register (register 21-8) contains the enable bits for the usb status interrupt sources. setting any of these bits will enable the respective interrupt source in the uir register. the values in this register only affect the propagation of an interrupt condition to the microcontroller?s inter- rupt logic. the flag bits are still set by their interrupt conditions, allowing them to be polled and serviced without actually generating an interrupt. register 21-8: uie: usb interrup t enable register (banked f36h) u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? sofie stallie idleie trnie actvie uerrie urstie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 sofie: start-of-frame token interrupt enable bit 1 = start-of-frame token interrupt enabled 0 = start-of-frame token interrupt disabled bit 5 stallie: stall handshake interrupt enable bit 1 = stall interrupt enabled 0 = stall interrupt disabled bit 4 idleie: idle detect interrupt enable bit 1 = idle detect interrupt enabled 0 = idle detect interrupt disabled bit 3 trnie: transaction complete interrupt enable bit 1 = transaction interrupt enabled 0 = transaction interrupt disabled bit 2 actvie: bus activity detect interrupt enable bit 1 = bus activity detect interrupt enabled 0 = bus activity detect interrupt disabled bit 1 uerrie: usb error interrupt enable bit 1 = usb error interrupt enabled 0 = usb error interrupt disabled bit 0 urstie: usb reset interrupt enable bit 1 = usb reset interrupt enabled 0 = usb reset interrupt disabled
pic18f46j50 family ds39931b-page 368 preliminary ? 2009 microchip technology inc. 21.5.3 usb error interrupt status register (ueir) the usb error interrupt status register (register 21-9) contains the flag bits for each of the error sources within the usb peripheral. each of these sources is controlled by a corresponding interrupt enable bit in the ueie register. all of the usb error flags are ored together to generate the usb error interrupt flag (uerrif) at the top level of the interrupt logic. each error bit is set as soon as the error condition is detected. thus, the interrupt will typically not correspond with the end of a token being processed. once an interrupt bit has been set by the sie, it must be cleared by software by writing a ? 0 ?. register 21-9: ueir: usb error interrupt status register (access f63h) r/c-0 u-0 u-0 r/c-0 r/c-0 r/c-0 r/c-0 r/c-0 btsef ? ? btoef dfn8ef crc16ef crc5ef pidef bit 7 bit 0 legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 btsef: bit stuff error flag bit 1 = a bit stuff error has been detected 0 = no bit stuff error bit 6-5 unimplemented: read as ? 0 ? bit 4 btoef: bus turnaround time-out error flag bit 1 = bus turnaround time-out has occurred (more than 16 bit times of idle from previous eop elapsed) 0 = no bus turnaround time-out bit 3 dfn8ef: data field size error flag bit 1 = the data field was not an integral number of bytes 0 = the data field was an integral number of bytes bit 2 crc16ef: crc16 failure flag bit 1 = the crc16 failed 0 = the crc16 passed bit 1 crc5ef: crc5 host error flag bit 1 = the token packet was rejected due to a crc5 error 0 = the token packet was accepted bit 0 pidef: pid check failure flag bit 1 = pid check failed 0 = pid check passed
? 2009 microchip technology inc. preliminary ds39931b-page 369 pic18f46j50 family 21.5.4 usb error interrupt enable register (ueie) the usb error interrupt enable register (register 21-10) contains the enable bits for each of the usb error interrupt sources. setting any of these bits will enable the respective error interrupt source in the ueir register to propagate into the uerr bit at the top level of the interrupt logic. as with the uie register, the enable bits only affect the propagation of an interrupt condition to the micro- controller?s interrupt logic. the flag bits are still set by their interrupt conditions, allowing them to be polled and serviced without actually generating an interrupt. register 21-10: ueie: usb error inte rrupt enable register (banked f37h) r/w-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 btsee ? ? btoee dfn8ee crc16ee crc5ee pidee bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 btsee: bit stuff error interrupt enable bit 1 = bit stuff error interrupt enabled 0 = bit stuff error interrupt disabled bit 6-5 unimplemented: read as ? 0 ? bit 4 btoee: bus turnaround time-out error interrupt enable bit 1 = bus turnaround time-out error interrupt enabled 0 = bus turnaround time-out error interrupt disabled bit 3 dfn8ee: data field size error interrupt enable bit 1 = data field size error interrupt enabled 0 = data field size error interrupt disabled bit 2 crc16ee: crc16 failure interrupt enable bit 1 = crc16 failure interrupt enabled 0 = crc16 failure interrupt disabled bit 1 crc5ee: crc5 host error interrupt enable bit 1 = crc5 host error interrupt enabled 0 = crc5 host error interrupt disabled bit 0 pidee: pid check failure interrupt enable bit 1 = pid check failure interrupt enabled 0 = pid check failure interrupt disabled
pic18f46j50 family ds39931b-page 370 preliminary ? 2009 microchip technology inc. 21.6 usb power modes many usb applications will likely have several different sets of power requirements and configuration. the most common power modes encountered are bus power only, self-power only and dual power with self-power dominance. the most common cases are presented here. also provided is a means of estimating the current consumption of the usb transceiver. 21.6.1 bus power only in bus power only mode, all power for the application is drawn from the usb (figure 21-9). this is effectively the simplest power method for the device. in order to meet the inrush current requirements of the usb 2.0 specification, the total effective capacitance appearing across v bus and ground must be no more than 10 f. if not, some kind of inrush timing is required. for more details, see section 7.2.4 of the usb 2.0 specification. according to the usb 2.0 specification, all usb devices must also support a low-power suspend mode. in the usb suspend mode, devices must consume no more than 2.5 ma from the 5v v bus line of the usb cable. the host signals the usb device to enter the suspend mode by stopping all usb traffic to that device for more than 3 ms. this condition will cause the idleif bit in the uir register to become set. during the usb suspend mode, the d+ or d- pull-up resistor must remain active, which will consume some of the allowed suspend current: 2.5 ma budget. figure 21-9: bus power only 21.6.2 self-power only in self-power only mode, the usb application provides its own power, with very little power being pulled from the usb. see figure 21-10 for an example. note that an attach indication is added to indicate when the usb has been connected and the host is actively powering v bus . in order to meet compliance specifications, the usb module (and the d+ or d- pull-up resistor) should not be enabled until the host actively drives v bus high. one of the 5.5v tolerant i/o pins may be used for this purpose. the application should never source any current onto the 5v v bus pin of the usb cable. figure 21-10: self-power only 21.6.3 dual power with self-power dominance some applications may require a dual power option. this allows the application to use internal power primarily, but switch to power from the usb when no internal power is available. see figure 21-11 for a simple dual power with self-power dominance mode example, which automatically switches between self-power only and usb bus power only modes. dual power devices must also meet all of the special requirements for inrush current and suspend mode current and must not enable the usb module until v bus is driven high. see section 21.6.1 ?bus power only? and section 21.6.2 ?self-power only? for descriptions of those requirements. additionally, dual power devices must never source current onto the 5v v bus pin of the usb cable. figure 21-11: dual power example v dd v usb v ss v bus ~5v 3.3v low i q regulator note: users should keep in mind the limits for devices drawing power from the usb. according to usb specification 2.0, this cannot exceed 100 ma per low-power device or 500 ma per high-power device. v dd v usb v ss v self ~3.3v attach sense 100 k 100 k v bus ~5v 5.5v tolerant i/o pin v dd v usb i/o pin v ss attach sense v bus v self 100 k ~3.3v ~5v 100 k 3.3v low i q regulator
? 2009 microchip technology inc. preliminary ds39931b-page 371 pic18f46j50 family 21.6.4 usb transceiver current consumption the usb transceiver consumes a variable amount of current depending on the characteristic impedance of the usb cable, the length of the cable, the v usb supply voltage and the actual data patterns moving across the usb cable. longer cables have larger capacitances and consume more total energy when switching output states. data patterns that consist of ?in? traffic consume far more current than ?out? traffic. in traffic requires the pic ? mcu to drive the usb cable, whereas out traffic requires that the host drive the usb cable. the data that is sent across the usb cable is nrzi encoded. in the nrzi encoding scheme, ? 0 ? bits cause a toggling of the output state of the transceiver (either from a ?j? state to a ?k? state, or vise versa). with the exception of the effects of bit stuffing, nrzi encoded ? 1 ? bits do not cause the output state of the transceiver to change. therefore, in traffic consisting of data bits of value, ? 0 ?, cause the most current consumption, as the transceiver must charge/discharge the usb cable in order to change states. more details about nrzi encoding and bit stuffing can be found in the usb 2.0 specification?s section 7.1, although knowledge of such details is not required to make usb applications using the pic18f46j50 family of microcontrollers. among other things, the sie handles bit stuffing/unstuffing, nrzi encoding/decoding and crc generation/checking in hardware. the total transceiver current consumption will be application-specific. however, to help estimate how much current actually may be required in full-speed applications, equation 21-1 can be used. see equation 21-2 to know how this equation can be used for a theoretical application. equation 21-1: estimating usb t ransceiver current consumption i xcvr =+ i pullup (40 ma ? v usb ? p zero ? p in ? l cable ) (3.3v ? 5m) legend: v usb ? voltage applied to the v usb pin in volts (should be 3.0v to 3.6v). p zero ? percentage (in decimal) of the in traffic bits sent by the pic ? mcu that are a value of ? 0 ?. p in ? percentage (in decimal) of total bus bandwidth that is used for in traffic. l cable ? length (in meters) of the usb cable. the usb 2.0 specification requires that full-speed applications use cables no longer than 5m. i pullup ? current which the nominal, 1.5 k pull-up resistor (when enabled) must supply to the usb cable. on the host or hub end of the usb cable, 15 k nominal resistors (14.25 k to 24.8 k ) are present which pull both the d+ and d- lines to ground. during bus idle conditions (such as between packets or during usb suspend mode), this results in up to 218 a of quiescent current drawn at 3.3v. i pullup is also dependant on bus traffic conditions and can be as high as 2.2 ma when the usb bandwidth is fully utilized (either in or out traffic) for data that drives the lines to the ?k? state most of the time.
pic18f46j50 family ds39931b-page 372 preliminary ? 2009 microchip technology inc. equation 21-2: calculating usb transceiver current ? for this example, the following assumptions are made about the application: ? 3.3v will be applied to v usb and v dd , with the core voltage regulator enabled. ? this is a full-speed application that uses one interrupt in endpoint that can send one packet of 64 bytes every 1 ms, with no restrictions on the values of the bytes being sent. the application may or may not have additional traffic on out endpoints. ? a regular usb ?b? or ?mini-b? connector will be used on the application circuit board. in this case, p zero = 100% = 1, because there should be no restriction on the value of the data moving through the in endpoint. all 64 kbps of data could potentially be bytes of value, 00h. since ? 0 ? bits cause toggling of the output state of the transceiver, they cause the usb transceiver to consume extra current charging/discharging the cable. in this case, 100% of the data bits sent can be of value ? 0 ?. this should be considered the ?max? value, as normal data will consist of a fair mix of ones and zeros. this application uses 64 kbps for in traffic out of the total bus bandwidth of 1.5 mbps (12 mbps), therefore: since a regular ?b? or ?mini-b? connector is used in this application, the end user may plug in any type of cable up to the maximum allowed 5m length. therefore, we use the worst-case length: l cable = 5 meters assume i pullup = 2.2 ma. the actual value of i pullup will likely be closer to 218 a, but allow for the worst-case. usb bandwidth is shared between all the devices which are plugged into the root port (via hubs). if the application is plugged into a usb 1.1 hub that has other devices plugged into it, your device may see host to device traffic on the bus, even if it is not addressed to your device. since any traffic, regardless of source, can increase the i pullup current above the base 218 a, it is safest to allow for the worst-case of 2.2 ma. therefore: ? the calculated value should be considered an approximation and additional guardband or application-specific product testing is recommended. the transceiver current is ?in addition to? the rest of the current consumed by the pic18f46j50 family device that is needed to run the core, drive the other i/o lines, power the various modules, etc. pin = 64 kbps 1.5 mbps = 4.3% = 0.043 i xcvr = + 2.2 ma = 3.9 ma (40 ma ? 3.3v ? 1 ? 0.043 ? 5m) (3.3v ? 5m)
? 2009 microchip technology inc. preliminary ds39931b-page 373 pic18f46j50 family 21.7 oscillator the usb module has specific clock requirements. for full-speed operation, the clock source must be 48 mhz. even so, the microcontroller core and other peripherals are not required to run at that clock speed. available clocking options are described in detail in section 2.3 ?oscillator settings for usb? . 21.8 usb firmware and drivers microchip provides a number of application-specific resources, such as usb firmware and driver support. refer to www.microchip.com for the latest firmware and driver support. table 21-4: registers associat ed with usb module operation (1) name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 details on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 61 ipr2 oscfip cm2ip cm1ip usbip bcl1ip hlvdip tmr3ip ccp2ip 63 pir2 oscfif cm2if cm1if usbif bcl1if hlvdif tmr3if ccp2if 63 pie2 oscfie cm2ie cm1ie usbie bcl1ie hlvdie tmr3ie ccp2ie 63 ucon ? ppbrst se0 pktdis usben resume suspnd ?65 ucfg uteye uoemon ? upuen utrdis fsen ppb1 ppb0 66 ustat ? endp3 endp2 endp1 endp0 dir ppbi ?65 uaddr ? addr6 addr5 addr4 addr3 addr2 addr1 addr0 66 ufrml frm7 frm6 frm5 frm4 frm3 frm2 frm1 frm0 65 ufrmh ? ? ? ? ? frm10 frm9 frm8 65 uir ? sofif stallif idleif trnif actvif uerrif urstif 65 uie ? sofie stallie idleie trnie actvie uerrie urstie 66 ueir btsef ? ? btoef dfn8ef crc16ef crc5ef pidef 65 ueie btsee ? ? btoee dfn8ee crc16ee crc5ee pidee 66 uep0 ? ? ? ephshk epcondis epouten epinen epstall 67 uep1 ? ? ? ephshk epcondis epouten epinen epstall 67 uep2 ? ? ? ephshk epcondis epouten epinen epstall 67 uep3 ? ? ? ephshk epcondis epouten epinen epstall 67 uep4 ? ? ? ephshk epcondis epouten epinen epstall 67 uep5 ? ? ? ephshk epcondis epouten epinen epstall 67 uep6 ? ? ? ephshk epcondis epouten epinen epstall 67 uep7 ? ? ? ephshk epcondis epouten epinen epstall 66 uep8 ? ? ? ephshk epcondis epouten epinen epstall 66 uep9 ? ? ? ephshk epcondis epouten epinen epstall 66 uep10 ? ? ? ephshk epcondis epouten epinen epstall 66 uep11 ? ? ? ephshk epcondis epouten epinen epstall 66 uep12 ? ? ? ephshk epcondis epouten epinen epstall 66 uep13 ? ? ? ephshk epcondis epouten epinen epstall 66 uep14 ? ? ? ephshk epcondis epouten epinen epstall 66 uep15 ? ? ? ephshk epcondis epouten epinen epstall 66 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the usb module. note 1: this table includes only those hardware mapped sfrs locate d in bank 15 of the data memory space. the buffer descriptor registers, which are mapped into bank 4 and ar e not true sfrs, are listed separately in table 21-3.
pic18f46j50 family ds39931b-page 374 preliminary ? 2009 microchip technology inc. 21.9 overview of usb this section presents some of the basic usb concepts and useful information necessary to design a usb device. although much information is provided in this section, there is a plethora of information provided within the usb specifications and class specifications. thus, the reader is encouraged to refer to the usb specifications for more information (www.usb.org). if you are very familiar with the details of usb, then this section serves as a basic, high-level refresher of usb. 21.9.1 layered framework usb device functionality is structured into a layered framework graphically illustrated in figure 21-12. each level is associated with a functional level within the device. the highest layer, other than the device, is the configuration. a device may have multiple configura- tions. for example, a particular device may have multiple power requirements based on self-power only or bus power only modes. for each configuration, there may be multiple interfaces. each interface could support a particular mode of that configuration. below the interface is the endpoint(s). data is directly moved at this level. there can be as many as 16 bidirectional endpoints. endpoint 0 is always a control endpoint, and by default, when the device is on the bus, endpoint 0 must be available to configure the device. 21.9.2 frames information communicated on the bus is grouped into 1 ms time slots, referred to as frames. each frame can contain many transactions to various devices and endpoints. see figure 21-8 for an example of a transaction within a frame. 21.9.3 transfers there are four transfer types defined in the usb specification. ? isochronous: this type provides a transfer method for large amounts of data (up to 1023 bytes) with timely delivery ensured; however, the data integrity is not ensured. this is good for streaming applications where small data loss is not critical, such as audio. ? bulk: this type of transfer method allows for large amounts of data to be transferred with ensured data integrity; however, the delivery timeliness is not ensured. ? interrupt: this type of transfer provides for ensured timely delivery for small blocks of data, plus data integrity is ensured. ? control: this type provides for device setup control. while full-speed devices support all transfer types, low-speed devices are limited to interrupt and control transfers only. 21.9.4 power power is available from the usb. the usb specifica- tion defines the bus power requirements. devices may either be self-powered or bus-powered. self-powered devices draw power from an external source, while bus-powered devices use power supplied from the bus. figure 21-12: usb layers device configuration interface endpoint interface endpoint endpoint endpoint endpoint to other configurations (if any) to other interfaces (if any)
? 2009 microchip technology inc. preliminary ds39931b-page 375 pic18f46j50 family the usb specification limits the power taken from the bus. each device is ensured 100 ma at approximately 5v (one unit load). additional power may be requested, up to a maximum of 500 ma. note that power above one unit load is a request and the host or hub is not obligated to provide the extra cur- rent. thus, a device capable of consuming more than one unit load must be able to maintain a low-power configuration of a one unit load or less, if necessary. the usb specification also defines a suspend mode. in this situation, current must be limited to 500 a, averaged over one second. a device must enter a suspend state after 3 ms of inactivity (i.e., no sof tokens for 3 ms). a device entering suspend mode must drop current consumption within 10 ms after suspend. likewise, when signaling a wake-up, the device must signal a wake-up within 10 ms of drawing current above the suspend limit. 21.9.5 enumeration when the device is initially attached to the bus, the host enters an enumeration process in an attempt to identify the device. essentially, the host interrogates the device, gathering information such as power consumption, data rates and sizes, protocol and other descriptive information; descriptors contain this information. a typical enumeration process would be as follows: 1. usb reset ? reset the device. thus, the device is not configured and does not have an address (address 0). 2. get device descriptor ? the host requests a small portion of the device descriptor. 3. usb reset ? reset the device again. 4. set address ? the host assigns an address to the device. 5. get device descriptor ? the host retrieves the device descriptor, gathering info such as manufacturer, type of device, maximum control packet size. 6. get configuration descriptors. 7. get any other descriptors. 8. set a configuration. the exact enumeration process depends on the host. 21.9.6 descriptors there are eight different standard descriptor types, of which, five are most important for this device. 21.9.6.1 device descriptor the device descriptor provides general information, such as manufacturer, product number, serial number, the class of the device and the number of configurations. there is only one device descriptor. 21.9.6.2 configuration descriptor the configuration descriptor provides information on the power requirements of the device and how many different interfaces are supported when in this configu- ration. there may be more than one configuration for a device (i.e., low-power and high-power configurations). 21.9.6.3 interface descriptor the interface descriptor details the number of end- points used in this interface, as well as the class of the interface. there may be more than one interface for a configuration. 21.9.6.4 endpoint descriptor the endpoint descriptor identifies the transfer type ( section 21.9.3 ?transfers? ) and direction, and some other specifics for the endpoint. there may be many endpoints in a device and endpoints may be shared in different configurations. 21.9.6.5 string descriptor many of the previous descriptors reference one or more string descriptors. string descriptors provide human readable information about the layer ( section 21.9.1 ?layered framework? ) they describe. often these strings show up in the host to help the user identify the device. string descriptors are generally optional to save memory and are encoded in a unicode format. 21.9.7 bus speed each usb device must indicate its bus presence and speed to the host. this is accomplished through a 1.5 k resistor, which is connected to the bus at the time of the attachment event. depending on the speed of the device, the resistor either pulls up the d+ or d- line to 3.3v. for a low-speed device, the pull-up resistor is connected to the d- line. for a full-speed device, the pull-up resistor is connected to the d+ line. 21.9.8 class specifications and drivers usb specifications include class specifications, which operating system vendors optionally support. examples of classes include audio, mass storage, communications and human interface (hid). in most cases, a driver is required at the host side to ?talk? to the usb device. in custom applications, a driver may need to be developed. fortunately, drivers are available for most common host systems for the most common classes of devices. thus, these drivers can be reused.
pic18f46j50 family ds39931b-page 376 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39931b-page 377 pic18f46j50 family 22.0 comparator module the analog comparator module contains two compara- tors that can be independently configured in a variety of ways. the inputs can be selected from the analog inputs and two internal voltage references. the digital outputs are available at the pin level and can also be read through the control register. multiple output and interrupt event generation is also available. figure 22-1 provides a generic single comparator from the module. key features of the module are: ? independent comparator control ? programmable input configuration ? output to both pin and register levels ? programmable output polarity ? independent interrupt generation for each comparator with configurable interrupt-on-change 22.1 registers the cmxcon registers (register 22-1) select the input and output configuration for each comparator, as well as the settings for interrupt generation. the cmstat register (register 22-2) provides the out- put results of the comparators. the bits in this register are read-only. figure 22-1: comparator si mplified block diagram cx v in - v in + coe cxout 0 3 0 1 cch<1:0> cxinb v irv cxina cv ref con interrupt logic evpol<4:3> coutx (cmstat<1:0>) cmxif cpol polarity logic cref
pic18f46j50 family ds39931b-page 378 preliminary ? 2009 microchip technology inc. register 22-1: cmxcon: comparator cont rol x register (access fd2h, fd1h) r/w-0 r/w-0 r/w-0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 con coe cpol evpol1 evpol0 cref cch1 cch0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 con: comparator enable bit 1 = comparator is enabled 0 = comparator is disabled bit 6 coe: comparator output enable bit 1 = comparator output is present on the cxout pin (assigned in the pps module) 0 = comparator output is internal only bit 5 cpol: comparator output polarity select bit 1 = comparator output is inverted 0 = comparator output is not inverted bit 4-3 evpol<1:0>: interrupt polarity select bits 11 = interrupt generation on any change of the output (1) 10 = interrupt generation only on high-to-low transition of the output 01 = interrupt generation only on low-to-high transition of the output 00 = interrupt generation is disabled bit 2 cref: comparator reference select bit (non-inverting input) 1 = non-inverting input connects to internal cv ref voltage 0 = non-inverting input connects to cxina pin bit 1-0 cch<1:0>: comparator channel select bits 11 = inverting input of comparator connects to v irv (0.6v) 00 = inverting input of comparator connects to cxinb pin note 1: the cmxif is automatically set any time this mode is selected and must be cleared by the application after the initial configuration.
? 2009 microchip technology inc. preliminary ds39931b-page 379 pic18f46j50 family register 22-2: cmstat: comparator status register (access f70h) u-0 u-0 u-0 u-0 u-0 u-0 r-1 r-1 ? ? ? ? ? ? cout2 cout1 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-2 unimplemented: read as ? 0 ? bit 1-0 cout<2:1>: comparator x status bits if cpol = 0 (non-inverted polarity): 1 = comparator v in + > v in - 0 = comparator v in + < v in - if cpol = 1 (inverted polarity): 1 = comparator v in + < v in - 0 = comparator v in + > v in -
pic18f46j50 family ds39931b-page 380 preliminary ? 2009 microchip technology inc. 22.2 comparator operation a single comparator is shown in figure 22-2, along with the relationship between the analog input levels and the digital output. when the analog input at v in + is less than the analog input, v in -, the output of the compara- tor is a digital low level. when the analog input at v in + is greater than the analog input, v in -, the output of the comparator is a digital high level. the shaded areas of the output of the comparator in figure 22-2 represent the uncertainty due to input offsets and response time. figure 22-2: single comparator 22.3 comparator response time response time is the minimum time, after selecting a new reference voltage or input source, before the comparator output has a valid level. the response time of the comparator differs from the settling time of the voltage reference. therefore, both of these times must be considered when determining the total response to a comparator input change. otherwise, the maximum delay of the comparators should be used (see section 29.0 ?electrical characteristics? ). 22.4 analog input connection considerations figure 22-3 provides a simplified circuit for an analog input. since the analog pins are connected to a digital output, they have reverse biased diodes to v dd and v ss . the analog input, therefore, must be between v ss and v dd . if the input voltage deviates from this range by more than 0.6v in either direction, one of the diodes is forward biased and a latch-up condition may occur. a maximum source impedance of 10 k is recommended for the analog sources. any external component connected to an analog input pin, such as a capacitor or a zener diode, should have very little leakage current. figure 22-3: comparator analog input model output v in - v in + ? + v in + v in - output va r s < 10k a in c pin 5 pf v dd v t = 0.6v v t = 0.6v r ic i leakage 100 na v ss legend: c pin = input capacitance v t = threshold voltage i leakage = leakage current at the pin due to various junctions r ic = interconnect resistance r s = source impedance va = analog voltage comparator input
? 2009 microchip technology inc. preliminary ds39931b-page 381 pic18f46j50 family 22.5 comparator control and configuration each comparator has up to eight possible combina- tions of inputs: up to four external analog inputs, and one of two internal voltage references. both comparators allow a selection of the signal from pin, cxina, or the voltage from the comparator refer- ence (cv ref ) on the non-inverting channel. this is compared to either cxinb, ctmu or the microcon- troller?s fixed internal reference voltage (v irv , 0.6v nominal) on the inverting channel. table 22-1 provides the comparator inputs and outputs tied to fixed i/o pins. table 22-1: comparator inputs and outputs 22.5.1 comparator enable and input selection setting the con bit of the cmxcon register (cmxcon<7>) enables the comparator for operation. clearing the con bit disables the comparator, resulting in minimum current consumption. the cch<1:0> bits in the cmxcon register (cmxcon<1:0>) direct either one of three analog input pins, or the internal reference voltage (v irv ), to the comparator v in -. depending on the comparator operat- ing mode, either an external or internal voltage reference may be used. the analog signal present at v in - is compared to the signal at v in + and the digital output of the comparator is adjusted accordingly. the external reference is used when cref = 0 (cmxcon<2>) and v in + is connected to the cxina pin. when external voltage references are used, the comparator module can be configured to have the reference sources externally. the reference signal must be between v ss and v dd , and can be applied to either pin of the comparator. the comparator module also allows the selection of an internally generated voltage reference (cv ref ) from the comparator voltage reference module. this module is described in more detail in section 22.0 ?compara- tor module? . the reference from the comparator voltage reference module is only available when cref = 1 . in this mode, the internal voltage reference is applied to the comparator?s v in + pin. 22.5.2 comparator enable and output selection the comparator outputs are read through the cmstat register. the cmstat<0> reads the comparator 1 out- put and cmstat<1> reads the comparator 2 output. these bits are read-only. the comparator outputs may also be directly output to the rpn i/o pins by setting the coe bit (cmxcon<6>). when enabled, multiplexers in the output path of the pins switch to the output of the comparator. by default, the comparator?s output is at logic high whenever the voltage on v in + is greater than on v in -. the polarity of the comparator outputs can be inverted using the cpol bit (cmxcon<5>). the uncertainty of each of the comparators is related to the input offset voltage and the response time given in the specifications, as discussed in section 22.2 ?comparator operation? . comparator input or output i/o pin 1 c1ina (v in +) ra0 c1inb (v in -) ra3 c1out remapped rpn 2 c2ina(v in +) ra1 c2inb(v in -) ra2 c2out remapped rpn note: the comparator input pin selected by cch<1:0> must be configured as an input by setting both the corresponding tris and pcfg bits in the ancon1 register.
pic18f46j50 family ds39931b-page 382 preliminary ? 2009 microchip technology inc. 22.6 comparator interrupts the comparator interrupt flag is set whenever any of the following occurs: - low-to-high transition of the comparator output - high-to-low transition of the comparator output - any change in the comparator output the comparator interrupt selection is done by the evpol<1:0> bits in the cmxcon register (cmxcon<4:3>). in order to provide maximum flexibility, the output of the comparator may be inverted using the cpol bit in the cmxcon register (cmxcon<5>). this is functionally identical to reversing the inverting and non-inverting inputs of the comparator for a particular mode. an interrupt is generated on the low-to-high or high-to- low transition of the comparator output. this mode of interrupt generation is dependent on evpol<1:0> in the cmxcon register. when evpol<1:0> = 01 or 10 , the interrupt is generated on a low-to-high or high-to- low transition of the comparator output. once the interrupt is generated, it is required to clear the interrupt flag by software. when evpol<1:0> = 11 , the comparator interrupt flag is set whenever there is a change in the output value of either comparator. software will need to maintain information about the status of the output bits, as read from cmstat<1:0>, to determine the actual change that occurred. the cmxif bits (pir2<6:5>) are the comparator interrupt flags. the cmxif bits must be reset by clearing them. since it is also possible to write a ? 1 ? to this register, a simulated interrupt may be initiated. table 22-2 provides the interrupt generation corresponding to comparator input voltages and evpol bit settings. both the cmxie bits (pie2<6:5>) and the peie bit (intcon<6>) must be set to enable the interrupt. in addition, the gie bit (intcon<7>) must also be set. if any of these bits are clear, the interrupt is not enabled, though the cmxif bits will still be set if an interrupt condition occurs. figure 22-3 provides a simplified diagram of the interrupt section. table 22-2: comparator interrupt generation cpol evpol<1:0> comparator input change coutx transition interrupt generated 0 00 v in + > v in - low-to-high no v in + < v in -high-to-low no 01 v in + > v in - low-to-high yes v in + < v in -high-to-low no 10 v in + > v in - low-to-high no v in + < v in -high-to-low yes 11 v in + > v in - low-to-high yes v in + < v in -high-to-low yes 1 00 v in + > v in -high-to-low no v in + < v in - low-to-high no 01 v in + > v in -high-to-low no v in + < v in - low-to-high yes 10 v in + > v in -high-to-low yes v in + < v in - low-to-high no 11 v in + > v in -high-to-low yes v in + < v in - low-to-high yes
? 2009 microchip technology inc. preliminary ds39931b-page 383 pic18f46j50 family 22.7 comparator operation during sleep when a comparator is active and the device is placed in sleep mode, the comparator remains active and the interrupt is functional if enabled. this interrupt will wake-up the device from sleep mode when enabled. each operational comparator will consume additional current. to minimize power consumption while in sleep mode, turn off the comparators (con = 0 ) before entering sleep. if the device wakes up from sleep, the contents of the cmxcon register are not affected. 22.8 effects of a reset a device reset forces the cmxcon registers to their reset state. this forces both comparators and the voltage reference to the off state. table 22-3: registers associ ated with comparator module name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 61 pir2 oscfif cm2if cm1if usbif bcl1if hlvdif tmr3if ccp2if 63 pie2 oscfie cm2ie cm1ie usbie bcl1ie hlvdie tmr3ie ccp2ie 63 ipr2 oscfip cm2ip cm1ip usbip bcl1ip hlvdip tmr3ip ccp2ip 63 cmxcon con coe cpol evpol1 evpol0 cref cch1 cch0 62 cvrcon (1) cvren cvroe cvrr r cvr3 cvr2 cvr1 cvr0 66 cmstat ? ? ? ? ? ? cout2 cout1 65 ancon0 pcfg7 (1) pcfg6 (1) pcfg5 (1) pcfg4 pcfg3 pcfg2 pcfg1 pcfg0 66 trisa trisa7 trisa6 trisa5 ? trisa3 trisa2 trisa1 trisa0 64 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not related to comparator operation. note 1: these bits and/or registers are not implemented on 28-pin devices.
pic18f46j50 family ds39931b-page 384 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39931b-page 385 pic18f46j50 family 23.0 comparator voltage reference module the comparator voltage reference is a 16-tap resistor ladder network that provides a selectable reference voltage. although its primary purpose is to provide a reference for the analog comparators, it may also be used independently of them. figure 23-1 provides a block diagram of the module. the resistor ladder is segmented to provide two ranges of cv ref values and has a power-down function to conserve power when the reference is not being used. the module?s supply reference is provided by v dd /v ss . figure 23-1: comparator voltage reference block diagram 16-to-1 mux cvr<3:0> 8r r cvren 8r r r r r r r 16 steps cvrr cv ref v dd
pic18f46j50 family ds39931b-page 386 preliminary ? 2009 microchip technology inc. 23.1 configuring the comparator voltage reference the comparator voltage reference module is controlled through the cvrcon register (register 23-1). the comparator voltage reference provides two ranges of output voltage, each with 16 distinct levels. the range to be used is selected by the cvrr bit (cvrcon<5>). the primary difference between the ranges is the size of the steps selected by the cv ref selection bits (cvr<3:0>), with one range offering finer resolution. the equations used to calculate the output of the comparator voltage reference are as follows: equation 23-1: calculating output of the comparator voltage reference the settling time of the comparator voltage reference must be considered when changing the cv ref output (see table 29-3 in section 29.0 ?electrical characteristics? ). when cvrr = 1 : cv ref = ((cvr<3:0>)/24) x (v dd ) when cvrr = 0 : cv ref =(v dd /4) + ((cvr<3:0>)/32) x (v dd ) register 23-1: cvrcon: comparator vo ltage reference control register (banked f53h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 cvren cvroe (1) cvrr r cvr3 cvr2 cvr1 cvr0 bit 7 bit 0 legend: r = reserved r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 cvren: comparator voltage reference enable bit 1 =cv ref circuit powered on 0 =cv ref circuit powered down bit 6 cvroe: comparator v ref output enable bit (1) 1 =cv ref voltage level is also output on the ra2/an2/v ref -/cv ref /c2inb pin 0 =cv ref voltage is disconnected from the ra2/an2/v ref -/cv ref /c2inb pin bit 5 cvrr: comparator v ref range selection bit 1 = 0 to 0.667 v dd , with v dd /24 step size (low range) 0 = 0.25 v dd to 0.75 v dd , with v dd /32 step size (high range) bit 4 reserved: always maintain as ? 0 ? bit 3-0 cvr<3:0>: comparator v ref value selection bits (0 (cvr<3:0>) 15) when cvrr = 1 : cv ref = ((cvr<3:0>)/24) ? (v dd ) when cvrr = 0 : cv ref = (v dd /4) + ((cvr<3:0>)/32) ? (v dd ) note 1: cvroe overrides the tris bit setting.
? 2009 microchip technology inc. preliminary ds39931b-page 387 pic18f46j50 family 23.2 voltage reference accuracy/error the full range of voltage reference cannot be realized due to the construction of the module. the transistors on the top and bottom of the resistor ladder network (see figure 23-1) keep cv ref from approaching the reference source rails. the voltage reference is derived from the reference source; therefore, the cv ref output changes with fluctuations in that source. the accuracy of the voltage reference can be found in section 29.0 ?electrical characteristics? . 23.3 connection considerations the voltage reference module operates independently of the comparator module. the output of the reference generator may be connected to the ra2 pin if the cvroe bit is set. enabling the voltage reference out- put onto ra2 when it is configured as a digital input will increase current consumption. the ra2 pin can be used as a simple d/a output with limited drive capability. due to the limited current drive capability, a buffer must be used on the voltage reference output for external connections to v ref . see figure 23-2 for an example buffering technique. 23.4 operation during sleep when the device wakes up from sleep through an interrupt or a watchdog timer time-out, the contents of the cvrcon register are not affected. to minimize current consumption in sleep mode, the voltage reference should be disabled. 23.5 effects of a reset a device reset disables the voltage reference by clearing bit, cvren (cvrcon<7>). this reset also disconnects the reference from the ra2 pin by clearing bit, cvroe (cvrcon<6>) and selects the high-voltage range by clearing bit, cvrr (cvrcon<5>). the cvr value select bits are also cleared. figure 23-2: comparator voltage reference output buffer example table 23-1: registers associated with comparator voltage reference name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: cvrcon cvren cvroe cvrr r cvr3 cvr2 cvr1 cvr0 66 cm1con con coe cpol evpol1 evpol0 cref cch1 cch0 62 cm2con con coe cpol evpol1 evpol0 cref cch1 cch0 62 trisa trisa7 trisa6 trisa5 ? trisa3 trisa2 trisa1 trisa0 64 ancon0 pcfg7 (1) pcfg6 (1) pcfg5 (1) pcfg4 pcfg3 pcfg2 pcfg1 pcfg0 66 ancon1 vbgen r ? pcfg12 pcfg11 pcfg10 pcfg9 pcfg8 66 legend: ? = unimplemented, read as ? 0 ?, r = reserved. shaded cells are not used with the comparator voltage reference. note 1: these bits are only available on 44-pin devices. cv ref output + ? cv ref module voltage reference output impedance r (1) ra2 note 1: r is dependent upon the comparator voltage reference configuration bits, cvrcon<5> and cvrcon<3:0>. pic18f46j50
pic18f46j50 family ds39931b-page 388 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39931b-page 389 pic18f46j50 family 24.0 high/low voltage detect (hlvd) the high/low-voltage detect (hlvd) module can be used to monitor the absolute voltage on v dd or the hlvdin pin. this is a programmable circuit that allows the user to specify both a device voltage trip point and the direction of change from that point. if the module detects an excursion past the trip point in that direction, an interrupt flag is set. if the interrupt is enabled, the program execution will branch to the inter- rupt vector address and the software can then respond to the interrupt. the high/low-voltage detect control register (register 24-1) completely controls the operation of the hlvd module. this allows the circuitry to be ?turned off? by the user under software control, which minimizes the current consumption for the device. figure 24-1 provides a block diagram for the hlvd module. the module is enabled by setting the hlvden bit. each time the module is enabled, the circuitry requires some time to stabilize. the irvst bit is a read-only bit that indicates when the circuit is stable. the module can generate an interrupt only after the circuit is stable and irvst is set. the vdirmag bit determines the overall operation of the module. when vdirmag is cleared, the module monitors for drops in v dd below a predetermined set point. when the bit is set, the module monitors for rises in v dd above the set point. register 24-1: hlvdcon: high/low-voltage detect control register (access f85h) r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 vdirmag bgvst irvst hlvden hlvdl3 (1) hlvdl2 (1) hlvdl1 (1) hlvdl0 (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 vdirmag: voltage direction magnitude select bit 1 = event occurs when voltage equals or exceeds trip point (hlvdl<3:0>) 0 = event occurs when voltage equals or falls below trip point (hlvdl<3:0>) bit 6 bgvst: band gap reference voltages stable status flag bit 1 = indicates internal band gap voltage references is stable 0 = indicates internal band gap voltage reference is not stable bit 5 irvst: internal reference voltage stable flag bit 1 = indicates that the voltage detect logic will generate the interrupt flag at the specified voltage range 0 = indicates that the voltage detect logic will not generate the interrupt flag at the specified voltage range and the hlvd interrupt should not be enabled bit 4 hlvden: high/low-voltage detect power enable bit 1 = hlvd enabled 0 = hlvd disabled bit 3-0 hlvdl<3:0>: voltage detection limit bits (1) 1111 = external analog input is used (input comes from the hlvdin pin) 1110 = maximum setting . . . 0000 = minimum setting note 1: see table 29-8 in section 29.0 ?electrical characteristics? for specifications.
pic18f46j50 family ds39931b-page 390 preliminary ? 2009 microchip technology inc. 24.1 operation when the hlvd module is enabled, a comparator uses an internally generated reference voltage as the set point. the set point is compared with the trip point, where each node in the resistor divider represents a trip point voltage. the ?trip point? voltage is the voltage level at which the device detects a high or low-voltage event, depending on the configuration of the module. when the supply voltage is equal to the trip point, the voltage tapped off of the resistor array is equal to the internal reference voltage generated by the voltage reference module. the comparator then generates an interrupt signal by setting the hlvdif bit. the trip point voltage is software programmable to any one of 16 values. the trip point is selected by programming the hlvdl<3:0> bits (hlvdcon<3:0>). additionally, the hlvd module allows the user to supply the trip voltage to the module from an external source. this mode is enabled when bits, hlvdl<3:0>, are set to ? 1111 ?. in this state, the comparator input is multiplexed from the external input pin, hlvdin. this gives users flexibility because it allows them to configure the hlvd interrupt to occur at any voltage in the valid operating range. figure 24-1: hlvd module block diagram (with external input) set v dd 16-to-1 mux hlvdcon hlvdl<3:0> register hlvdin v dd externally generated trip point hlvdif hlvden internal voltage reference vdirmag 1.2v typical
? 2009 microchip technology inc. preliminary ds39931b-page 391 pic18f46j50 family 24.2 hlvd setup to set up the hlvd module: 1. disable the module by clearing the hlvden bit (hlvdcon<4>). 2. write the value to the hlvdl<3:0> bits that selects the desired hlvd trip point. 3. set the vdirmag bit to detect one of the following: ? high voltage (vdirmag = 1 ) ? low voltage (vdirmag = 0 ) 4. enable the hlvd module by setting the hlvden bit. 5. clear the hlvd interrupt flag, hlvdif (pir2<2>), which may have been set from a previous interrupt. 6. if interrupts are desired, enable the hlvd inter- rupt by setting the hlvdie and gie/gieh bits (pie2<2> and intcon<7>). an interrupt will not be generated until the irvst bit is set. 24.3 current consumption when the module is enabled, the hlvd comparator and voltage divider are enabled and will consume static current. the total current consumption, when enabled, is specified in electrical specification parameter d022b ( i hlvd ) ( section 29.2 ?dc characteristics: power- down and supply current pic18f46j50 family (industrial)? ). depending on the application, the hlvd module does not need to operate constantly. to decrease the current requirements, the hlvd circuitry may only need to be enabled for short periods where the voltage is checked. after doing the check, the hlvd module may be disabled. 24.4 hlvd start-up time the internal reference voltage of the hlvd module, specified in electrical specification parameter d420(see table 29-8 in section 29.0 ?electrical characteristics? ), may be used by other internal cir- cuitry, such as the programmable brown-out reset (bor). if the hlvd or other circuits using the voltage reference are disabled to lower the device?s current consumption, the reference voltage circuit will require time to become stable before a low or high-voltage condition can be reliably detected. this start-up time, t irvst , is an interval that is independent of device clock speed. it is specified in electrical specification parameter 36 (table 29-13). the hlvd interrupt flag is not enabled until t irvst has expired and a stable reference voltage is reached. for this reason, brief excursions beyond the set point may not be detected during this interval. refer to figure 24-2 or figure 24-3.
pic18f46j50 family ds39931b-page 392 preliminary ? 2009 microchip technology inc. figure 24-2: low-voltage detect operation (vdirmag = 0 ) v hlvd v dd hlvdif v hlvd v dd enable hlvd t irvst hlvdif may not be set enable hlvd hlvdif hlvdif cleared in software hlvdif cleared in software hlvdif cleared in software, case 1: case 2: hlvdif remains set since hlvd condition still exists t irvst internal reference is stable internal reference is stable irvst irvst
? 2009 microchip technology inc. preliminary ds39931b-page 393 pic18f46j50 family figure 24-3: high-voltage detect operation (vdirmag = 1 ) 24.5 applications in many applications, it is desirable to have the ability to detect a drop below, or rise above, a particular threshold. for example, the hlvd module could be enabled periodically to detect universal serial bus (usb) attach or detach. for general battery applications, figure 24-4 provides a possible voltage curve. over time, the device voltage decreases. when the device voltage reaches voltage, v a , the hlvd logic generates an interrupt at time, t a . the interrupt could cause the execution of an isr, which would allow the application to perform ?housekeeping tasks? and perform a controlled shutdown before the device voltage exits the valid operating range at t b . the hlvd, thus, would give the application a time window, represented by the difference between t a and t b , to safely exit. figure 24-4: typical high/ low-voltage detect application v hlvd v dd hlvdif v hlvd v dd enable hlvd t irvst hlvdif may not be set enable hlvd hlvdif hlvdif cleared in software hlvdif cleared in software hlvdif cleared in software, case 1: case 2: hlvdif remains set since hlvd condition still exists t irvst irvst internal reference is stable internal reference is stable irvst time voltage v a v b t a t b v a = hlvd trip point v b = minimum valid device operating voltage legend:
pic18f46j50 family ds39931b-page 394 preliminary ? 2009 microchip technology inc. 24.6 operation during sleep when enabled, the hlvd circuitry continues to operate during sleep. if the device voltage crosses the trip point, the hlvdif bit will be set and the device will wake-up from sleep. device execution will continue from the interrupt vector address if interrupts have been globally enabled. 24.7 effects of a reset a device reset forces all registers to their reset state. this forces the hlvd module to be turned off. table 24-1: registers associated wi th high/low-voltage detect module name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page hlvdcon vdirmag bgvst irvst hlvden hlvdl3 hlvdl2 hlvdl1 hlvdl0 64 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 61 pir2 oscfif cm2if cm1if usbif bcl1if hlvdif tmr3if ccp2if 63 pie2 oscfie cm2ie cm1ie usbie bcl1ie hlvdie tmr3ie ccp2ie 63 ipr2 oscfip cm2ip cm1ip usbip bcl1ip hlvdip tmr3ip ccp2ip 63 legend: ? = unimplemented, read as ? 0 ?. shaded cells are unused by the hlvd module.
? 2009 microchip technology inc. preliminary ds39931b-page 395 pic18f46j50 family 25.0 charge time measurement unit (ctmu) the charge time measurement unit (ctmu) is a flexible analog module that provides accurate differen- tial time measurement between pulse sources, as well as asynchronous pulse generation. by working with other on-chip analog modules, the ctmu can be used to precisely measure time, measure capacitance, measure relative changes in capacitance or generate output pulses with a specific time delay. the ctmu is ideal for interfacing with capacitive-based sensors. the module includes the following key features: ? up to 13 channels available for capacitive or time measurement input ? on-chip precision current source ? four-edge input trigger sources ? polarity control for each edge source ? control of edge sequence ? control of response to edges ? time measurement resolution of 1 nanosecond ? high precision time measurement ? time delay of external or internal signal asynchronous to system clock ? accurate current source suitable for capacitive measurement the ctmu works in conjunction with the a/d converter to provide up to 13 channels for time or charge measurement, depending on the specific device and the number of a/d channels available. when config- ured for time delay, the ctmu is connected to one of the analog comparators. the level-sensitive input edge sources can be selected from four sources: two external inputs, timer1 or output compare module 1. figure 25-1 provides a block diagram of the ctmu. figure 25-1: ctmu block diagram ctedg1 ctedg2 current source edge control logic ctmucon pulse generator a/d converter comparator 2 input timer1 eccp1 current control itrim<5:0> irng<1:0> ctmuicon ctmu control logic edgen edgseqen edg1selx edg1pol edg2selx edg2pol edg1stat edg2stat tgen idissen ctpls comparator 2 output
pic18f46j50 family ds39931b-page 396 preliminary ? 2009 microchip technology inc. 25.1 ctmu operation the ctmu works by using a fixed current source to charge a circuit. the type of circuit depends on the type of measurement being made. in the case of charge measurement, the current is fixed, and the amount of time the current is applied to the circuit is fixed. the amount of voltage read by the a/d is then a measure- ment of the capacitance of the circuit. in the case of time measurement, the current, as well as the capaci- tance of the circuit, is fixed. in this case, the voltage read by the a/d is then representative of the amount of time elapsed from the time the current source starts and stops charging the circuit. if the ctmu is being used as a time delay, both capaci- tance and current source are fixed, as well as the voltage supplied to the comparator circuit. the delay of a signal is determined by the amount of time it takes the voltage to charge to the comparator threshold voltage. 25.1.1 theory of operation the operation of the ctmu is based on the equation for charge: more simply, the amount of charge measured in coulombs in a circuit is defined as current in amperes ( i ) multiplied by the amount of time in seconds that the current flows ( t ). charge is also defined as the capacitance in farads ( c ) multiplied by the voltage of the circuit ( v ). it follows that: the ctmu module provides a constant, known current source. the a/d converter is used to measure ( v ) in the equation, leaving two unknowns: capacitance ( c ) and time ( t ). the above equation can be used to calcu- late capacitance or time, by either the relationship using the known fixed capacitance of the circuit: or by: using a fixed time that the current source is applied to the circuit. 25.1.2 current source at the heart of the ctmu is a precision current source, designed to provide a constant reference for measure- ments. the level of current is user-selectable across three ranges or a total of two orders of magnitude, with the ability to trim the output in 2% increments (nominal). the current range is selected by the irng<1:0> bits (ctmuicon<9:8>), with a value of ? 00 ? representing the lowest range. current trim is provided by the itrim<5:0> bits (ctmuicon<7:2>). these six bits allow trimming of the current source in steps of approximately 2% per step. note that half of the range adjusts the current source positively and the other half reduces the current source. a value of ? 000000 ? is the neutral position (no change). a value of ? 100000 ? is the maximum negative adjustment (approximately -62%) and ? 011111 ? is the maximum positive adjustment (approximately +62%). 25.1.3 edge selection and control ctmu measurements are controlled by edge events occurring on the module?s two input channels. each channel, referred to as edge 1 and edge 2, can be con- figured to receive input pulses from one of the edge input pins (ctedg1 and ctedg2), timer1 or output compare module 1. the input channels are level- sensitive, responding to the instantaneous level on the channel rather than a transition between levels. the inputs are selected using the edg1sel and edg2sel bit pairs (ctmuconl<3:2 and 6:5>). in addition to source, each channel can be configured for event polarity using the edge2pol and edge1pol bits (ctmuconl<7,4>). the input channels can also be filtered for an edge event sequence (edge 1 occur- ring before edge 2) by setting the edgseqen bit (ctmuconh<2>). 25.1.4 edge status the ctmucon register also contains two status bits: edg2stat and edg1stat (ctmuconl<1:0>). their primary function is to show if an edge response has occurred on the corresponding channel. the ctmu automatically sets a particular bit when an edge response is detected on its channel. the level-sensitive nature of the input channels also means that the status bits become set immediately if the channel?s configura- tion is changed and is the same as the channel?s current state. the module uses the edge status bits to control the cur- rent source output to external analog modules (such as the a/d converter). current is only supplied to external modules when only one (but not both) of the status bits is set, and shuts current off when both bits are either set or cleared. this allows the ctmu to measure cur- rent only during the interval between edges. after both status bits are set, it is necessary to clear them before another measurement is taken. both bits should be cleared simultaneously, if possible, to avoid re-enabling the ctmu current source. in addition to being set by the ctmu hardware, the edge status bits can also be set by software. this is also the user?s application to manually enable or disable the current source. setting either one (but not both) of the bits enables the current source. setting or clearing both bits at once disables the source. ci dv dt ------ - ? = it ? cv . ? = tcv ? () i ? = cit ? () v ? =
? 2009 microchip technology inc. preliminary ds39931b-page 397 pic18f46j50 family 25.1.5 interrupts the ctmu sets its interrupt flag (pir3<2>) whenever the current source is enabled, then disabled. an inter- rupt is generated only if the corresponding interrupt enable bit (pie3<2>) is also set. if edge sequencing is not enabled (i.e., edge 1 must occur before edge 2), it is necessary to monitor the edge status bits and determine which edge occurred last and caused the interrupt. 25.2 ctmu module initialization the following sequence is a general guideline used to initialize the ctmu module: 1. select the current source range using the irng bits (ctmuicon<1:0>). 2. adjust the current source trim using the itrim bits (ctmuicon<7:2>). 3. configure the edge input sources for edge 1 and edge 2 by setting the edg1sel and edg2sel bits (ctmuconl<3:2 and 6:5>). 4. configure the input polarities for the edge inputs using the edg1pol and edg2pol bits (ctmuconl<4,7>). the default configuration is for negative edge polarity (high-to-low transitions). 5. enable edge sequencing using the edgseqen bit (ctmuconh<2>). by default, edge sequencing is disabled. 6. select the operating mode (measurement or time delay) with the tgen bit. the default mode is time/capacitance measurement. 7. discharge the connected circuit by setting the idissen bit (ctmuconh<1>); after waiting a sufficient time for the circuit to discharge, clear idissen. 8. disable the module by clearing the ctmuen bit (ctmuconh<7>). 9. enable the module by setting the ctmuen bit. 10. clear the edge status bits: edg2stat and edg1stat (ctmuconl<1:0>). 11. enable both edge inputs by setting the edgen bit (ctmuconh<3>). depending on the type of measurement or pulse generation being performed, one or more additional modules may also need to be initialized and configured with the ctmu module: ? edge source generation: in addition to the external edge input pins, both timer1 and the output compare/pwm1 module can be used as edge sources for the ctmu. ? capacitance or time measurement: the ctmu module uses the a/d converter to measure the voltage across a capacitor that is connected to one of the analog input channels. ? pulse generation: when generating system clock independent output pulses, the ctmu module uses comparator 2 and the associated comparator voltage reference. 25.3 calibrating the ctmu module the ctmu requires calibration for precise measure- ments of capacitance and time, as well as for accurate time delay. if the application only requires measurement of a relative change in capacitance or time, calibration is usually not necessary. an example of this type of appli- cation would include a capacitive touch switch, in which the touch circuit has a baseline capacitance, and the added capacitance of the human body changes the overall capacitance of a circuit. if actual capacitance or time measurement is required, two hardware calibrations must take place: the current source needs calibration to set it to a precise current, and the circuit being measured needs calibration to measure and/or nullify all other capacitance other than that to be measured. 25.3.1 current source calibration the current source on board the ctmu module has a range of 60% nominal for each of three current ranges. therefore, for precise measurements, it is pos- sible to measure and adjust this current source by placing a high precision resistor, r cal , onto an unused analog channel. an example circuit is shown in figure 25-2. the current source measurement is performed using the following steps: 1. initialize the a/d converter. 2. initialize the ctmu. 3. enable the current source by setting edg1stat (ctmuconl<0>). 4. issue settling time delay. 5. perform a/d conversion. 6. calculate the current source current using i=v/r cal , where r cal is a high precision resistance and v is measured by performing an a/d conversion.
pic18f46j50 family ds39931b-page 398 preliminary ? 2009 microchip technology inc. the ctmu current source may be trimmed with the trim bits in ctmuicon using an iterative process to get an exact desired current. alternatively, the nominal value without adjustment may be used; it may be stored by the software for use in all subsequent capacitive or time measurements. to calculate the value for r cal , the nominal current must be chosen, and then the resistance can be calculated. for example, if the a/d converter reference voltage is 3.3v, use 70% of full scale, or 2.31v as the desired approximate voltage to be read by the a/d converter. if the range of the ctmu current source is selected to be 0.55 a, the resistor value needed is cal- culated as r cal = 2.31v/0.55 a , for a value of 4.2 m ? . similarly, if the current source is chosen to be 5.5 a, r cal would be 420,000 ? , and 42,000 ? if the current source is set to 55 a. figure 25-2: ctmu current source calibration circuit a value of 70% of full-scale voltage is chosen to make sure that the a/d converter was in a range that is well above the noise floor. keep in mind that if an exact cur- rent is chosen that is to incorporate the trimming bits from ctmuicon, the resistor value of r cal may need to be adjusted accordingly. r cal may also be adjusted to allow for available resistor values. r cal should be of the highest precision available, keeping in mind the amount of precision needed for the circuit that the ctmu will be used to measure. a recommended minimum would be 0.1% tolerance. the following examples show one typical method for performing a ctmu current calibration. example 25-1 demonstrates how to initialize the a/d converter and the ctmu; this routine is typical for applications using both modules. example 25-2 demonstrates one method for the actual calibration routine. pic18f46j50 device a/d converter ctmu anx r cal current source mux a/d
? 2009 microchip technology inc. preliminary ds39931b-page 399 pic18f46j50 family example 25-1: setup for ct mu calibration routines #include "p18cxxx.h" /**************************************************************************/ /*setup ctmu *****************************************************************/ /**************************************************************************/ void setup(void) { //ctmucon - ctmu control register ctmuconh = 0x00; //make sure ctmu is disabled ctmuconl = 0x90; //ctmu continues to run when emulator is stopped,ctmu continues //to run in idle mode,time generation mode disabled, edges are blocked //no edge sequence order, analog current source not grounded, trigger //output disabled, edge2 polarity = positive level, edge2 source = //source 0, edge1 polarity = positive level, edge1 source = source 0, //ctmuicon - ctmu current control register ctmuicon = 0x01; //0.55ua, nominal - no adjustment /**************************************************************************/ //setup ad converter; /**************************************************************************/ trisa=0x04; //set channel 2 as an input // configured an2 as an analog channel // ancon0 ancon0 = 0xfb; // ancon1 ancon1 = 0x1f; // adcon1 adcon1bits.adfm=1; // resulst format 1= right justified adcon1bits.adcal=0; // normal a/d conversion operation adcon1bits.acqt=1; // acquition time 7 = 20tad 2 = 4tad 1=2tad adcon1bits.adcs=2; // clock conversion bits 6= fosc/64 2=fosc/32 ancon1bits.vbgen=1; // turn on the bandgap needed for rev a0 parts // adcon0 adcon0bits.vcfg0 =0; // vref+ = avdd adcon0bits.vcfg1 =0; // vref- = avss adcon0bits.chs=2; // select adc channel adcon0bits.adon=1; // turn on adc }
pic18f46j50 family ds39931b-page 400 preliminary ? 2009 microchip technology inc. example 25-2: current calibration routine #include "p18cxxx.h" #define count 500 //@ 8mhz = 125us. #define delay for(i=0;i ? 2009 microchip technology inc. preliminary ds39931b-page 401 pic18f46j50 family 25.3.2 capacitance calibration there is a small amount of capacitance from the inter- nal a/d converter sample capacitor as well as stray capacitance from the circuit board traces and pads that affect the precision of capacitance measurements. a measurement of the stray capacitance can be taken by making sure the desired capacitance to be measured has been removed. the measurement is then performed using the following steps: 1. initialize the a/d converter and the ctmu. 2. set edg1stat (= 1 ). 3. wait for a fixed delay of time t . 4. clear edg1stat. 5. perform an a/d conversion. 6. calculate the stray and a/d sample capaci- tances: where i is known from the current source measurement step, t is a fixed delay and v is measured by performing an a/d conversion. this measured value is then stored and used for calculations of time measurement or subtracted for capacitance measurement. for calibration, it is expected that the capacitance of c stray + c ad is approximately known. c ad is approximately 4 pf. an iterative process may need to be used to adjust the time, t , that the circuit is charged to obtain a reasonable voltage reading from the a/d converter. the value of t may be determined by setting c offset to a theoretical value, then solving for t . for example, if c stray is theoretically calculated to be 11 pf, and v is expected to be 70% of v dd , or 2.31v, then t would be: or 63 s. see example 25-3 for a typical routine for ctmu capacitance calibration. c offset c stray c ad + it ? () v ? == (4 pf + 11 pf) ? 2.31v/0.55 a
pic18f46j50 family ds39931b-page 402 preliminary ? 2009 microchip technology inc. example 25-3: capacitance calibration routine #include "p18cxxx.h" #define count 25 //@ 8mhz intfrc = 62.5 us. #define etime count*2.5 //time in us #define delay for(i=0;i ? 2009 microchip technology inc. preliminary ds39931b-page 403 pic18f46j50 family 25.4 measuring capacitance with the ctmu there are two separate methods of measuring capaci- tance with the ctmu. the first is the absolute method, in which the actual capacitance value is desired. the second is the relative method, in which the actual capacitance is not needed, rather an indication of a change in capacitance is required. 25.4.1 absolute capacitance measurement for absolute capacitance measurements, both the current and capacitance calibration steps found in section 25.3 ?calibrating the ctmu module? should be followed. capacitance measurements are then performed using the following steps: 1. initialize the a/d converter. 2. initialize the ctmu. 3. set edg1stat. 4. wait for a fixed delay, t . 5. clear edg1stat. 6. perform an a/d conversion. 7. calculate the total capacitance, c total = (i * t)/v , where i is known from the current source measurement step (see section 25.3.1 ?current source calibration? ), t is a fixed delay and v is measured by performing an a/d conversion. 8. subtract the stray and a/d capacitance ( c offset from section 25.3.2 ?capacitance calibration? ) from c total to determine the measured capacitance. 25.4.2 relative charge measurement an application may not require precise capacitance measurements. for example, when detecting a valid press of a capacitance-based switch, detecting a rela- tive change of capacitance is of interest. in this type of application, when the switch is open (or not touched), the total capacitance is the capacitance of the combina- tion of the board traces, the a/d converter, etc. a larger voltage will be measured by the a/d converter. when the switch is closed (or is touched), the total capacitance is larger due to the addition of the capacitance of the human body to the above listed capacitances, and a smaller voltage will be measured by the a/d converter. detecting capacitance changes is easily accomplished with the ctmu using these steps: 1. initialize the a/d converter and the ctmu. 2. set edg1stat. 3. wait for a fixed delay. 4. clear edg1stat. 5. perform an a/d conversion. the voltage measured by performing the a/d conver- sion is an indication of the relative capacitance. note that in this case, no calibration of the current source or circuit capacitance measurement is needed. see example 25-4 for a sample software routine for a capacitive touch switch.
pic18f46j50 family ds39931b-page 404 preliminary ? 2009 microchip technology inc. example 25-4: routine fo r capacitive touch switch #include "p18cxxx.h" #define count 500 //@ 8mhz = 125us. #define delay for(i=0;i opensw - trip + hyst) { switchstate = unpressed; } }
? 2009 microchip technology inc. preliminary ds39931b-page 405 pic18f46j50 family 25.5 measuring time with the ctmu module time can be precisely measured after the ratio ( c/i ) is measured from the current and capacitance calibration step by following these steps: 1. initialize the a/d converter and the ctmu. 2. set edg1stat. 3. set edg2stat. 4. perform an a/d conversion. 5. calculate the time between edges as t = (c/i) * v , where i is calculated in the current calibration step ( section 25.3.1 ?current source calibration? ), c is calculated in the capacitance calibration step ( section 25.3.2 ?capacitance calibration? ) and v is measured by performing the a/d conversion. it is assumed that the time measured is small enough that the capacitance, c offset , provides a valid voltage to the a/d converter. for the smallest time measure- ment, always set the a/d channel select register (ad1chs) to an unused a/d channel; the correspond- ing pin for which is not connected to any circuit board trace. this minimizes added stray capacitance, keeping the total circuit capacitance close to that of the a/d converter itself (4-5 pf). to measure longer time intervals, an external capacitor may be connected to an a/d channel and this channel selected when making a time measurement. figure 25-3: typical connections and internal configuration for time measurement a/d converter ctmu ctedg1 ctedg2 an x output pulse edg1 edg2 c ad r pr current source pic18f46j50 device
pic18f46j50 family ds39931b-page 406 preliminary ? 2009 microchip technology inc. 25.6 creating a delay with the ctmu module a unique feature on board the ctmu module is its ability to generate system clock independent output pulses based on an external capacitor value. this is accomplished using the internal comparator voltage reference module, comparator 2 input pin and an external capacitor. the pulse is output onto the ctpls pin. to enable this mode, set the tgen bit. see figure 25-4 for an example circuit. c pulse is chosen by the user to determine the output pulse width on ctpls. the pulse width is calculated by t =( c pulse / i )* v , where i is known from the current source measurement step ( section 25.3.1 ?current source calibration? ) and v is the internal reference voltage (cv ref ). an example use of this feature is for interfacing with variable capacitive-based sensors, such as a humidity sensor. as the humidity varies, the pulse width output on ctpls will vary. the ctpls output pin can be connected to an input capture pin and the varying pulse width is measured to determine the humidity in the application. follow these steps to use this feature: 1. initialize comparator 2. 2. initialize the comparator voltage reference. 3. initialize the ctmu and enable time delay generation by setting the tgen bit. 4. set edg1stat. 5. when c pulse charges to the value of the voltage reference trip point, an output pulse is generated on ctpls. figure 25-4: typical co nnections and internal co nfiguration for pulse delay generation 25.7 operation during sleep/idle modes 25.7.1 sleep mode and deep sleep modes when the device enters any sleep mode, the ctmu module current source is always disabled. if the ctmu is performing an operation that depends on the current source when sleep mode is invoked, the operation may not terminate correctly. capacitance and time measurements may return erroneous values. 25.7.2 idle mode the behavior of the ctmu in idle mode is determined by the ctmusidl bit (ctmuconh<5>). if ctmusidl is cleared, the module will continue to operate in idle mode. if ctmusidl is set, the module?s current source is disabled when the device enters idle mode. if the module is performing an operation when idle mode is invoked, in this case, the results will be similar to those with sleep mode. 25.8 effects of a reset on ctmu upon reset, all registers of the ctmu are cleared. this leaves the ctmu module disabled, its current source is turned off and all configuration options return to their default settings. the module needs to be re-initialized following any reset. if the ctmu is in the process of taking a measurement at the time of reset, the measurement will be lost. a partial charge may exist on the circuit that was being measured, and should be properly discharged before the ctmu makes subsequent attempts to make a measurement. the circuit is discharged by setting and then clearing the idissen bit (ctmuconh<1>) while the a/d converter is connected to the appropriate channel. c2 cv ref ctpls pic18f46j50 device current source comparator ctmu ctedg1 c2inb c pulse edg1
? 2009 microchip technology inc. preliminary ds39931b-page 407 pic18f46j50 family 25.9 registers there are three control registers for the ctmu: ? ctmuconh ? ctmuconl ? ctmuicon the ctmuconh and ctmuconl registers (register 25-1 and register 25-2) contain control bits for configuring the ctmu module edge source selec- tion, edge source polarity selection, edge sequencing, a/d trigger, analog circuit capacitor discharge and enables. the ctmuicon register (register 25-3) has bits for selecting the current source range and current source trim. register 25-1: ctmuconh: ctmu cont rol register high (access fb3h) r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 ctmuen ? ctmusidl tgen edgen edgseqen idissen ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ctmuen: ctmu enable bit 1 = module is enabled 0 = module is disabled bit 6 unimplemented: read as ? 0 ? bit 5 ctmusidl: stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 4 tgen: time generation enable bit 1 = enables edge delay generation 0 = disables edge delay generation bit 3 edgen: edge enable bit 1 = edges are not blocked 0 = edges are blocked bit 2 edgseqen: edge sequence enable bit 1 = edge 1 event must occur before edge 2 event can occur 0 = no edge sequence is needed bit 1 idissen: analog current source control bit 1 = analog current source output is grounded 0 = analog current source output is not grounded bit 0 reserved: write as ? 0 ?
pic18f46j50 family ds39931b-page 408 preliminary ? 2009 microchip technology inc. register 25-2: ctmuconl : ctmu control register low (access fb2h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-x r/w-x edg2pol edg2sel1 edg2sel0 edg1pol ed g1sel1 edg1sel0 edg2stat edg1stat bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 edg2pol: edge 2 polarity select bit 1 = edge 2 programmed for a positive edge response 0 = edge 2 programmed for a negative edge response bit 6-5 edg2sel<1:0>: edge 2 source select bits 11 = ctedg1 pin 10 = ctedg2 pin 01 = eccp1 output compare module 00 = timer1 module bit 4 edg1pol: edge 1 polarity select bit 1 = edge 1 programmed for a positive edge response 0 = edge 1 programmed for a negative edge response bit 3-2 edg1sel<1:0>: edge 1 source select bits 11 = ctedg1 pin 10 = ctedg2 pin 01 = eccp1 output compare module 00 = timer1 module bit 1 edg2stat: edge 2 status bit 1 = edge 2 event has occurred 0 = edge 2 event has not occurred bit 0 edg1stat: edge 1 status bit 1 = edge 1 event has occurred 0 = edge 1 event has not occurred
? 2009 microchip technology inc. preliminary ds39931b-page 409 pic18f46j50 family table 25-1: registers associated with ctmu module register 25-3: ctmuicon: ctmu current control register (access fb1h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 itrim5 itrim4 itrim3 itrim2 itrim1 itrim0 irng1 irng0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-2 itrim<5:0>: current source trim bits 011111 = maximum positive change from nominal current 011110 . . . 000001 = minimum positive change from nominal current 000000 = nominal current output specified by irng<1:0> 111111 = minimum negative change from nominal current . . . 100010 100001 = maximum negative change from nominal current bit 1-0 irng<1:0>: current source range select bits 11 = 100 base current 10 = 10 base current 01 = base current level (0.55 a nominal) 00 = current source disabled name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: ctmuconh ctmuen ? ctmusidl tgen edgen edgseqen idissen ?63 ctmuconl edg2pol edg2sel1 edg2sel0 edg1pol edg1sel1 edg1sel0 edg2stat edg1stat 63 ctmuicon itrim5 itrim4 itrim3 it rim2 itrim1 itri m0 irng1 irng0 63 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not us ed during eccp operation.
pic18f46j50 family ds39931b-page 410 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39931b-page 411 pic18f46j50 family 26.0 special features of the cpu pic18f46j50 family devices include several features intended to maximize reliability and minimize cost through elimination of external components. these are: ? oscillator selection ? resets: - power-on reset (por) - power-up timer (pwrt) - oscillator start-up timer (ost) - brown-out reset (bor) ? interrupts ? watchdog timer (wdt) ? fail-safe clock monitor (fscm) ? two-speed start-up ? code protection ? in-circuit serial programming (icsp) the oscillator can be configured for the application depending on frequency, power, accuracy and cost. all of the options are discussed in detail in section 2.0 ?oscillator configurations? . a complete discussion of device resets and interrupts is available in previous sections of this data sheet. in addition to their power-up and oscillator start-up timers provided for resets, the pic18f46j50 family of devices has a configurable watchdog timer (wdt), which is controlled in software. the inclusion of an internal rc oscillator also provides the additional benefits of a fail-safe clock monitor (fscm) and two-speed start-up. fscm provides for background monitoring of the peripheral clock and automatic switchover in the event of its failure. two-speed start-up enables code to be executed almost immediately on start-up, while the primary clock source completes its start-up delays. all of these features are enabled and configured by setting the appropriate configuration register bits. 26.1 configuration bits the configuration bits can be programmed to select various device configurations. the configuration data is stored in the last four words of flash program memory; figure 5-1 depicts this. the configuration data gets loaded into the volatile configuration registers, config1l through config4h, which are readable and mapped to program memory starting at location 300000h. table 26-2 provides a complete list. a detailed explana- tion of the various bit functions is provided in register 26-1 through register 26-6. 26.1.1 considerations for configuring the pic18f46j50 family devices unlike some previous pic18 microcontrollers, devices of the pic18f46j50 family do not use persistent mem- ory registers to store configuration information. the configuration registers, config1l through config4h, are implemented as volatile memory. immediately after power-up, or after a device reset, the microcontroller hardware automatically loads the config1l through config4l registers with configu- ration data stored in nonvolatile flash program memory. the last four words of flash program memory, known as the flash configuration words (fcw), are used to store the configuration data. table 26-1 provides the flash program memory, which will be loaded into the corresponding configuration register. when creating applications for these devices, users should always specifically allocate the location of the fcw for configuration data. this is to make certain that program code is not stored in this address when the code is compiled. the four most significant bits (msb) of the fcw corre- sponding to config1h, config2h, config3h and config4h should always be programmed to ? 1111 ?. this makes these fcws appear to be nop instructions in the remote event that their locations are ever executed by accident. the four msbs of the config1h, config2h, config3h and config4h registers are not imple- mented, so writing ? 1 ?s to their corresponding fcw has no effect on device operation. to prevent inadvertent configuration changes during code execution, the configuration registers, config1l through config4l, are loaded only once per power-up or reset cycle. user?s firmware can still change the configuration by using self-reprogramming to modify the contents of the fcw. modifying the fcw will not change the active contents being used in the config1l through config4h registers until after the device is reset.
pic18f46j50 family ds39931b-page 412 preliminary ? 2009 microchip technology inc. table 26-1: mapping of the flash co nfiguration words to the configuration registers table 26-2: configuration bits and device ids configuration register (volatile) configuration register address flash configuration byte address config1l 300000h xxxf8h config1h 300001h xxxf9h config2l 300002h xxxfah config2h 300003h xxxfbh config3l 300004h xxxfch config3h 300005h xxxfdh config4l 300006h xxxfeh config4h 300007h xxxffh file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 default/ unprog. value (1) 300000h config1l debug xinst stvren ? plldiv2 plldiv1 plldiv0 wdten 111- 1111 300001h config1h ? (2) ? (2) ? (2) ? (2) ? cp0 cpdiv1 cpdiv0 1111 -111 300002h config2l ieso fcmen ? lpt1osc t1dig fosc2 fosc1 fosc0 11-1 1111 300003h config2h ? (2) ? (2) ? (2) ? (2) wdtps3 wdtps2 wdtps1 wdtps0 1111 1111 300004h config3l dswdtps3 dswdtps2 dswdtps1 dswdtps0 dswdten dsboren rtcosc dswdtosc 1111 1111 300005h config3h ? (2) ? (2) ? (2) ? (2) msspmsk ? ? iol1way 1111 1--1 300006h config4l wpcfg wpend wpfp5 wpfp4 wpfp3 wpfp2 wpfp1 wpfp0 1111 1111 300007h config4h ? (2) ? (2) ? (2) ? (2) ? ? ?wpdis 1111 ---1 3ffffeh devid1 dev2 dev1 dev0 rev4 rev3 rev2 rev1 rev0 xxx0 0000 (3) 3fffffh devid2 dev10 dev9 dev8 dev7 dev6 dev5 dev4 dev3 0100 00xx (3) legend: x = unknown, u = unchanged, - = unimplemented. shaded cells are unimplemented, read as ? 0 ?. note 1: values reflect the unprogrammed state as received from the factory and following power-on resets. in all other reset states, th e configuration bytes maintain their previously programmed states. 2: the value of these bits in program me mory should always be programmed to ? 1 ?. this ensures that the location is executed as a nop if it is accidentally executed. 3: see register 26-9 and register 26-10 for devid values. these registers are read-only and cannot be programmed by the user.
? 2009 microchip technology inc. preliminary ds39931b-page 413 pic18f46j50 family register 26-1: config1l: configuration register 1 low (byte address 300000h) r/wo-1 r/wo-1 r/wo-1 u-0 r/wo-1 r/wo-1 r/wo-1 r/wo-1 debug xinst stvren ? plldiv2 plldiv1 plldiv0 wdten bit 7 bit 0 legend: r = readable bit wo = write-once bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 debug : background debugger enable bit 1 = background debugger disabled; rb6 and rb7 configured as general purpose i/o pins 0 = background debugger enabled; rb6 and rb7 are dedicated to in-circuit debug bit 6 xinst: extended instruction set enable bit 1 = instruction set extension and indexed addressing mode enabled 0 = instruction set extension and indexed addressing mode disabled bit 5 stvren : stack overflow/underflow reset enable bit 1 = reset on stack overflow/underflow enabled 0 = reset on stack overflow/underflow disabled bit 4 unimplemented: read as ? 0 ? bit 3-1 plldiv<2:0>: oscillator selection bits divider must be selected to provide a 4 mhz input into the 96 mhz pll. 111 = no divide ? oscillator used directly (4 mhz input) 110 = oscillator divided by 2 (8 mhz input) 101 = oscillator divided by 3 (12 mhz input) 100 = oscillator divided by 4 (16 mhz input) 011 = oscillator divided by 5 (20 mhz input) 010 = oscillator divided by 6 (24 mhz input) 001 = oscillator divided by 10 (40 mhz input) 000 = oscillator divided by 12 (48 mhz input) bit 0 wdten: watchdog timer enable bit 1 = wdt enabled 0 = wdt disabled (control is placed on swdten bit)
pic18f46j50 family ds39931b-page 414 preliminary ? 2009 microchip technology inc. register 26-2: config1h: co nfiguration register 1 hi gh (byte address 300001h) u-1 u-1 u-1 u-1 u-0 r/wo-1 r/wo-1 r/wo-1 ? ? ? ? ? cp0 cpdiv1 cpdiv0 bit 7 bit 0 legend: r = readable bit wo = write-once bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: program the corresponding flash configuration bit to ? 1 ? bit 3 unimplemented: maintain as ? 0 ? bit 2 cp0: code protection bit 1 = program memory is not code-protected 0 = program memory is code-protected bit 1-0 cpdiv<1:0>: cpu system clock selection bits 11 = no cpu system clock divide 10 = cpu system clock divided by 2 01 = cpu system clock divided by 3 00 = cpu system clock divided by 6
? 2009 microchip technology inc. preliminary ds39931b-page 415 pic18f46j50 family register 26-3: config2l: configuration re gister 2 low (byte address 300002h) r/wo-1 r/wo-1 u-0 r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 ieso fcmen ? lpt1osc t1dig fosc2 fosc1 fosc0 bit 7 bit 0 legend: r = readable bit wo = write-once bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ieso: two-speed start-up (internal/external oscillator switchover) control bit 1 = two-speed start-up enabled 0 = two-speed start-up disabled bit 6 fcmen: fail-safe clock monitor enable bit 1 = fail-safe clock monitor enabled 0 = fail-safe clock monitor disabled bit 5 unimplemented: read as ? 0 ? bit 4 lpt1osc: low-power timer1 oscillator enable bit 1 = timer1 oscillator configured for high-power operation 0 = timer1 oscillator configured for low-power operation bit 3 t1dig: secondary clock source t1oscen enforcement bit 1 = secondary oscillator clock source may be selected (osccon<1:0> = 01 ) regardless of t1con<3> t1oscen state 0 = secondary oscillator clock source may not be selected unless t1con<3> = 1 bit 2-0 fosc<2:0>: oscillator selection bits 111 = ecpll oscillator with pll software controlled, clko on ra6 110 = ec oscillator with clko on ra6 101 = hspll oscillator with pll software controlled 100 = hs oscillator 011 = intoscpllo, internal oscillator with pll software controlled, clko on ra6, port function on ra7 010 = intoscpll, internal oscillator with pll software controlled, port function on ra6 and ra7 001 = intosco internal oscillator block (intrc/intosc) with clko on ra6, port function on ra7 000 = intosc internal oscillator block (intrc/intosc), port function on ra6 and ra7
pic18f46j50 family ds39931b-page 416 preliminary ? 2009 microchip technology inc. register 26-4: config2h: co nfiguration register 2 high (byte address 300003h) u-1 u-1 u-1 u-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 ? ? ? ? wdtps3 wdtps2 wdtps1 wdtps0 bit 7 bit 0 legend: r = readable bit wo = write-once bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: program the corresponding flash configuration bit to ? 1 ? bit 3-0 wdtps<3:0>: watchdog timer postscale select bits 1111 = 1:32,768 1110 = 1:16,384 1101 = 1:8,192 1100 = 1:4,096 1011 = 1:2,048 1010 = 1:1,024 1001 = 1:512 1000 = 1:256 0111 = 1:128 0110 = 1:64 0101 = 1:32 0100 = 1:16 0011 = 1:8 0010 = 1:4 0001 = 1:2 0000 = 1:1
? 2009 microchip technology inc. preliminary ds39931b-page 417 pic18f46j50 family register 26-5: config3l: configuration regi ster 3 low (byte address 300004h) r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 dswdtps3 (1) dswdtps2 (1) dswdtps1 (1) dswdtps0 (1) dswdten (1) dsboren rtcosc dswdtosc (1) bit 7 bit 0 legend: r = readable bit wo = write-once bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 dswdtps<3:0>: deep sleep watchdog timer postscale select bits (1) the dswdt prescaler is 32. this creates an approximate base time unit of 1 ms. 1111 = 1:2,147,483,648 (25.7 days) 1110 = 1:536,870,912 (6.4 days) 1101 = 1:134,217,728 (38.5 hours) 1100 = 1:33,554,432 (9.6 hours) 1011 = 1:8,388,608 (2.4 hours) 1010 = 1:2,097,152 (36 minutes) 1001 = 1:524,288 (9 minutes) 1000 = 1:131,072 (135 seconds) 0111 = 1:32,768 (34 seconds) 0110 = 1:8,192 (8.5 seconds) 0101 = 1:2,048 (2.1 seconds) 0100 = 1:512 (528 ms) 0011 = 1:128 (132 ms) 0010 = 1:32 (33 ms) 0001 = 1:8 (8.3 ms) 0000 = 1:2 (2.1 ms) bit 3 dswdten: deep sleep watchdog timer enable bit (1) 1 = dswdt enabled 0 = dswdt disabled bit 2 dsboren: ?f? device deep sleep bor enable bit, ?lf? device v dd bor enable bit for ?f? devices: 1 = v dd sensing bor enabled in deep sleep 0 = v dd sensing bor circuit is always disabled for ?lf? devices: 1 = v dd sensing bor circuit is always enabled 0 = v dd sensing bor circuit is always disabled bit 1 rtcosc: rtcc reference clock select bit 1 = rtcc uses t1osc/t1cki as reference clock 0 = rtcc uses intrc as reference clock bit 0 dswdtosc: dswdt reference clock select bit (1) 1 = dswdt uses intrc as reference clock 0 = dswdt uses t1osc/t1cki as reference clock note 1: functions are not available on ?lf? devices.
pic18f46j50 family ds39931b-page 418 preliminary ? 2009 microchip technology inc. register 26-6: config3h: configuration register 3 high (byte address 300005h) u-1 u-1 u-1 u-1 r/wo-1 u-0 u-0 r/wo-1 ? ? ? ? msspmsk ? ?iol1way bit 7 bit 0 legend: r = readable bit wo = write-once bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: program the corresponding flash configuration bit to ? 1 ? bit 3 msspmsk: mssp 7-bit address masking mode enable bit 1 = 7-bit address masking mode enabled 0 = 5-bit address masking mode enabled bit 2-1 unimplemented: read as ? 0 ? bit 0 iol1way: iolock one-way set enable bit 1 = iolock bit (ppscon<0>) can be set once, provided the unlock sequence has been completed. once set, the peripheral pin select registers cannot be written to a second time. 0 = iolock bit (ppscon<0>) can be set and cleared as needed, provided the unlock sequence has been completed register 26-7: config4l: configuration register 4 low (byte address 300006h) r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 r/wo-1 wpcfg wpend wpfp5 wpfp4 wpfp3 wpfp2 wpfp1 wpfp0 bit 7 bit 0 legend: r = readable bit wo = write-once bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 wpcfg: write/erase protect configuration region select bit (valid when wpdis = 0 ) 1 = configuration words page is not erase/write-protected unless wpend and wpfp<5:0> settings include the configuration words page (1) 0 = configuration words page is erase/write-protected, regardless of wpend and wpfp<5:0> (1) bit 6 wpend: write/erase protect region select bit (valid when wpdis = 0 ) 1 = flash pages wpfp<5:0> to (configuration words page) are write/erase protected 0 = flash pages 0 to wpfp<5:0> are erase/write-protected bit 5-0 wpfp<5:0>: write/erase protect page start/end location bits used with wpend bit to define which pages in flash will be write/erase protected. note 1: the ?configuration words page? contains the fcws and is the last page of implemented flash memory on a given device. each page consists of 1,024 bytes. for example, on a device with 64 kbytes of flash, the first page is 0 and the last page (configuration words page) is 63 (3fh).
? 2009 microchip technology inc. preliminary ds39931b-page 419 pic18f46j50 family register 26-8: config4h: configuration register 4 high (byte address 300007h) u-1 u-1 u-1 u-1 u-0 u-0 u-0 r/wo-1 ? ? ? ? ? ? ?wpdis bit 7 bit 0 legend: r = readable bit wo = write-once bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: program the corresponding flash configuration bit to ? 1 ? bit 3-1 unimplemented: read as ? 0 ? bit 0 wpdis: write-protect disable bit 1 = wpfp<5:0>, wpend and wpcfg bits ignored; all flash memory may be erased or written 0 = wpfp<5:0>, wpend and wpcfg bits enabled; erase/write-protect active for the selected region(s) register 26-9: devid1: device id register 1 for pic18f46j50 family devices (byte address 3ffffeh) rrrrrrrr dev2 dev1 dev0 rev4 rev3 rev2 rev1 rev0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 dev<2:0>: device id bits these bits are used with dev<10:3> bits in device id register 2 to identify the part number. see register 26-10. bit 4-0 rev<4:0>: revision id bits these bits are used to indicate the device revision.
pic18f46j50 family ds39931b-page 420 preliminary ? 2009 microchip technology inc. register 26-10: devid2: device id register 2 for pic18f46j50 family devices (byte address 3fffffh) rrrrrrrr dev10 dev9 dev8 dev7 dev6 dev5 dev4 dev3 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 dev<10:3>: device id bits these bits are used with the dev<2:0> bits in the device id register 1 to identify the part number. dev<10:3> (devid2<7:0>) dev<2:0> (devid2<7:5>) device 0100 1100 101 pic18f46j50 0100 1100 100 pic18f45j50 0100 1100 011 pic18f44j50 0100 1100 010 pic18f26j50 0100 1100 001 pic18f25j50 0100 1100 000 pic18f24j50 0100 1101 011 pic18lf46j50 0100 1101 010 pic18lf45j50 0100 1101 001 pic18lf44j50 0100 1101 000 pic18lf26j50 0100 1100 111 pic18lf25j50 0100 1100 110 pic18lf24j50
? 2009 microchip technology inc. preliminary ds39931b-page 421 pic18f46j50 family 26.2 watchdog timer (wdt) pic18f46j50 family devices have both a conventional wdt circuit and a dedicated, deep sleep capable watchdog timer. when enabled, the conventional wdt operates in normal run, idle and sleep modes. this data sheet section describes the conventional wdt circuit. the dedicated, deep sleep capable wdt can only be enabled in deep sleep mode. this timer is described in section 3.6.4 ?deep sleep watchdog timer (dswdt)? . the conventional wdt is driven by the intrc oscilla- tor. when the wdt is enabled, the clock source is also enabled. the nominal wdt period is 4 ms and has the same stability as the intrc oscillator. the 4 ms period of the wdt is multiplied by a 16-bit postscaler. any output of the wdt postscaler is selected by a multiplexer, controlled by the wdtps bits in configuration register 2h. available periods range from about 4 ms to 135 seconds (2.25 minutes depending on voltage, temperature and wdt postscaler). the wdt and postscaler are cleared whenever a sleep or clrwdt instruction is executed, or a clock failure (primary or timer1 oscillator) has occurred. 26.2.1 control register the wdtcon register (register 26-11) is a readable and writable register. the swdten bit enables or dis- ables wdt operation. this allows software to override the wdten configuration bit and enable the wdt only if it has been disabled by the configuration bit. lvdstat is a read-only status bit that is continuously updated and provides information about the current level of v ddcore . this bit is only valid when the on-chip voltage regulator is enabled. figure 26-1: wdt block diagram note 1: the clrwdt and sleep instructions clear the wdt and postscaler counts when executed. 2: when a clrwdt instruction is executed, the postscaler count will be cleared. intrc oscillator wdt wake-up from reset wdt wdt counter programmable postscaler 1:1 to 1:32,768 enable wdt wdtps<3:0> swdten clrwdt 4 power-managed reset all device resets sleep intrc control 128 modes
pic18f46j50 family ds39931b-page 422 preliminary ? 2009 microchip technology inc. table 26-3: summary of watchdog timer registers register 26-11: wdtcon: watchdog time r control register (access fc0h) r/w-1 r-x r-x u-0 r/w-0 r/w-0 r/w-0 r/w-0 regslp lvdstat (2) ulplvl ? ds ulpen ulpsink swdten (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 regslp: voltage regulator low-power operation enable bit 1 = on-chip regulator enters low-power operation when device enters sleep mode 0 = on-chip regulator is active even in sleep mode bit 6 lvdstat: low-voltage detect status bit (2) 1 = v ddcore > 2.45v nominal 0 = v ddcore < 2.45v nominal bit 5 ulplvl: ultra low-power wake-up output bit (not valid unless ulpen = 1 ) 1 = voltage on ra0 > ~0.5v 0 = voltage on ra0 < ~0.5v bit 4 unimplemented : read as ? 0 ? bit 3 ds: deep sleep wake-up status bit (used in conjunction with rcon, por and bor bits to determine reset source) (2) 1 = if the last exit from reset was caused by a normal wake-up from deep sleep 0 = if the last exit from reset was not due to a wake-up from deep sleep bit 2 ulpen: ultra low-power wake-up module enable bit 1 = ultra low-power wake-up module is enabled; ulplvl bit indicates comparator output 0 = ultra low-power wake-up module is disabled bit 1 ulpsink: ultra low-power wake-up current sink enable bit 1 = ultra low-power wake-up current sink is enabled (if ulpen = 1 ) 0 = ultra low-power wake-up current sink is disabled bit 0 swdten: software controlled watchdog timer enable bit (1) 1 = watchdog timer is on 0 = watchdog timer is off note 1: this bit has no effect if the configuration bit, wdten, is enabled. 2: not available on devices where the on-chip voltage regulator is disabled (?lf? devices). name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page: rcon ipen ? cm ri to pd por bor 62 wdtcon regslp lvdstat ulplvl ? ds ulpen ulpsink swdten 62 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the watchdog timer.
? 2009 microchip technology inc. preliminary ds39931b-page 423 pic18f46j50 family 26.3 on-chip voltage regulator the digital core logic of the pic18f46j50 family devices is designed on an advanced manufacturing process, which requires 2.0v to 2.7v. the digital core logic obtains power from the v ddcore /v cap power supply pin. however, in many applications it may be inconvenient to run the i/o pins at the same core logic voltage, as it would restrict the ability of the device to interface with other, higher voltage devices, such as those run at a nominal 3.3v. therefore, all pic18f46j50 family devices implement a dual power supply rail topology. the core logic obtains power from the v ddcore /v cap pin, while the general purpose i/o pins obtain power from the v dd pin of the microcontroller, which may be supplied with a voltage between 2.15v to 3.6v (?f? device) or 2.0v to 3.6v (?lf? device). this dual supply topology allows the microcontroller to interface with standard 3.3v logic devices, while running the core logic at a lower voltage of nominally 2.5v. in order to make the microcontroller more convenient to use, an integrated 2.5v low dropout, low quiescent current linear regulator has been integrated on the die inside pic18f46j50 family devices. this regulator is designed specifically to supply the core logic of the device. it allows pic18f46j50 family devices to effectively run from a single power supply rail, without the need for external regulators. the on-chip voltage regulator is always enabled on ?f? devices. the v ddcore /v cap pin serves simultaneously as the regulator output pin and the core logic supply power input pin. a capacitor should be connected to the v ddcore /v cap pin to ground and is necessary for regu- lator stability. for example connections for pic18f and pic18lf devices, see figure 26-2. on ?lf? devices, the on-chip regulator is always disabled. this allows the device to save a small amount of quiescent current consumption, which may be advantageous in some types of applications, such as those which will entirely be running at a nominal 2.5v. on ?lf? devices, the v ddcore /v cap pin still serves as the core logic power supply input pin, and therefore, must be connected to a 2.0v to 2.7v supply rail at the application circuit board level. on these devices, the i/o pins may still optionally be supplied with a voltage between 2.0v to 3.6v, provided that v dd is always greater than, or equal to, v ddcore /v cap . for example connections for pic18f and pic18lf devices, see figure 26-2. the specifications for core voltage and capacitance are listed in section 29.3 ?dc characteristics: pic18f46j50 family (industrial)? . 26.3.1 voltage regulator tracking mode and low-voltage detection when it is enabled, the on-chip regulator provides a con- stant voltage of 2.5v nominal to the digital core logic. the regulator can provide this level from a v dd of about 2.5v, all the way up to the device?s v ddmax . it does not have the capability to boost v dd levels below 2.5v. when the v dd supply input voltage drops too low to regulate 2.5v, the regulator enters tracking mode. in tracking mode, the regulator output follows v dd , with a typical voltage drop of 100 mv or less. the on-chip regulator includes a simple low-voltage detect (lvd) circuit. this circuit is separate and independent of the high/low-voltage detect (hlvd) module described in section 24.0 ?high/low voltage detect (hlvd)? . the on-chip regulator lvd circuit con- tinuously monitors the v ddcore voltage level and updates the lvdstat bit in the wdtcon register. the lvd detect threshold is set slightly below the normal regulation set point of the on-chip regulator. application firmware may optionally poll the lvdstat bit to determine when it is safe to run at maximum rated frequency, so as not to inadvertently violate the voltage versus frequency requirements provided by figure 29-1. the v ddcore monitoring lvd circuit is only active when the on-chip regulator is enabled. on ?lf? devices, the analog-to-digital converter and the hlvd module can still be used to provide firmware with v dd and v ddcore voltage level information. note 1: the on-chip voltage regulator is only available in parts designated with an ?f?, such as pic18 f 25j50. the on-chip regulator is disabled on devices with ?lf? in their part number. 2: the v ddcore /v cap pin must never be left floating. on ?f? devices, it must be con- nected to a capacitor, of size c efc , to ground. on ?lf? devices, v ddcore /v cap must be connected to a power supply source between 2.0v and 2.7v. note: in parts designated with an ?lf?, such as pic18lf46j50, v ddcore must never exceed v dd .
pic18f46j50 family ds39931b-page 424 preliminary ? 2009 microchip technology inc. figure 26-2: connections for the on-chip regulator 26.3.2 on-chip regulator and bor when the on-chip regulator is enabled, pic18f46j50 family devices also have a simple brown-out capability. if the voltage supplied to the regulator is inadequate to maintain a minimum output level; the regulator reset circuitry will generate a brown-out reset (bor). this event is captured by the bor flag bit (rcon<0>). the operation of the bor is described in more detail in section 4.4 ?brown-out reset (bor)? and section 4.4.1 ?detecting bor? . the brown-out voltage levels are specific in section 29.1 ?dc characteristics: supply voltage pic18f46j50 family (industrial)? . 26.3.3 power-up requirements the on-chip regulator is designed to meet the power-up requirements for the device. if the application does not use the regulator, then strict power-up conditions must be adhered to. while powering up, v ddcore should not exceed v dd by 0.3 volts. 26.3.4 operation in sleep mode when enabled, the on-chip regulator always consumes a small incremental amount of current over i dd . this includes when the device is in sleep mode, even though the core digital logic does not require much power. to provide additional savings in applications where power resources are critical, the regulator can be configured to automatically enter a lower quiescent draw standby mode whenever the device goes into sleep mode. this feature is controlled by the regslp bit (wdtcon<7>, register 26-11). if this bit is set upon entry into sleep mode, the regulator will transition into a lower power state. in this state, the regulator still provides a regulated output voltage necessary to maintain sram state information, but consumes less quiescent current. substantial sleep mode power savings can be obtained by setting the regslp bit, but device wake-up time will increase in order to insure the regulator has enough time to stabilize. v dd v ddcore /v cap v ss pic18lfxxj50 3.3v 2.5v v dd v ddcore /v cap v ss c f 3.3v or v dd v ddcore /v cap v ss 2.5v pic18fxxj50 devices (regulator enabled): pic18lfxxj50 devices (regulator disabled): pic18fxxj50 pic18lfxxj50
? 2009 microchip technology inc. preliminary ds39931b-page 425 pic18f46j50 family 26.4 two-speed start-up the two-speed start-up feature helps to minimize the latency period, from oscillator start-up to code execu- tion, by allowing the microcontroller to use the intrc oscillator as a clock source until the primary clock source is available. it is enabled by setting the ieso configuration bit. two-speed start-up should be enabled only if the primary oscillator mode is hs or hspll (crystal-based) modes. since the ec and ecpll modes do not require an oscillator start-up timer (ost) delay, two-speed start-up should be disabled. when enabled, resets and wake-ups from sleep mode cause the device to configure itself to run from the inter- nal oscillator block as the clock source, following the time-out of the power-up timer after a power-on reset is enabled. this allows almost immediate code execution while the primary oscillator starts and the ost is running. once the ost times out, the device automatically switches to pri_run mode. in all other power-managed modes, two-speed start-up is not used. the device will be clocked by the currently selected clock source until the primary clock source becomes available. the setting of the ieso bit is ignored. figure 26-3: timing transition for two-speed start-up (intrc to hspll) 26.4.1 special considerations for using two-speed start-up while using the intrc oscillator in two-speed start-up, the device still obeys the normal command sequences for entering power-managed modes, including serial sleep instructions (refer to section 3.1.4 ?multiple sleep commands? ). in practice, this means that user code can change the scs<1:0> bit settings or issue sleep instructions before the ost times out. this would allow an applica- tion to briefly wake-up, perform routine ?housekeeping? tasks and return to sleep before the device starts to operate from the primary oscillator. user code can also check if the primary clock source is currently providing the device clocking by checking the status of the osts bit (osccon<3>). if the bit is set, the primary oscillator is providing the clock. otherwise, the internal oscillator block is providing the clock during wake-up from reset or sleep mode. 26.5 fail-safe clock monitor the fail-safe clock monitor (fscm) allows the microcontroller to continue operation in the event of an external oscillator failure by automatically switching the device clock to the internal oscillator block. the fscm function is enabled by setting the fcmen configuration bit. when fscm is enabled, the intrc oscillator runs at all times to monitor clocks to peripherals and provide a backup clock in the event of a clock failure. clock monitoring (shown in figure 26-4) is accomplished by creating a sample clock signal, which is the intrc out- put divided by 64. this allows ample time between fscm sample clocks for a peripheral clock edge to occur. the peripheral device clock and the sample clock are presented as inputs to the clock monitor latch. the clock monitor is set on the falling edge of the device clock source but cleared on the rising edge of the sample clock. q1 q3 q4 osc1 peripheral program pc pc + 2 intrc pll clock q1 pc + 6 q2 output q3 q4 q1 cpu clock pc + 4 clock counter q2 q2 q3 note1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. wake from interrupt event t pll (1) 12 n-1n clock osts bit set transition t ost (1)
pic18f46j50 family ds39931b-page 426 preliminary ? 2009 microchip technology inc. figure 26-4: fscm block diagram clock failure is tested for on the falling edge of the sample clock. if a sample clock falling edge occurs while the clock monitor is still set, and a clock failure has been detected (figure 26-5), the following results: ? the fscm generates an oscillator fail interrupt by setting bit, oscfif (pir2<7>); ? the device clock source is switched to the internal oscillator block (osccon is not updated to show the current clock source ? this is the fail-safe condition); and ?the wdt is reset. during switchover, the postscaler frequency from the internal oscillator block may not be sufficiently stable for timing sensitive applications. in these cases, it may be desirable to select another clock configuration and enter an alternate power-managed mode. this can be done to attempt a partial recovery or execute a controlled shutdown. see section 3.1.4 ?multiple sleep commands? and section 26.4.1 ?special considerations for using two-speed start-up? for more details. the fscm will detect failures of the primary or secondary clock sources only. if the internal oscillator block fails, no failure would be detected, nor would any action be possible. 26.5.1 fscm and the watchdog timer both the fscm and the wdt are clocked by the intrc oscillator. since the wdt operates with a separate divider and counter, disabling the wdt has no effect on the operation of the intrc oscillator when the fscm is enabled. as already noted, the clock source is switched to the intrc clock when a clock failure is detected; this may mean a substantial change in the speed of code execu- tion. if the wdt is enabled with a small prescale value, a decrease in clock speed allows a wdt time-out to occur and a subsequent device reset. for this reason, fail-safe clock monitor events also reset the wdt and postscaler, allowing it to start timing from when execu- tion speed was changed and decreasing the likelihood of an erroneous time-out. figure 26-5: fscm timing diagram peripheral intrc 64 s c q (32 s) 488 hz (2.048 ms) clock monitor latch (edge-triggered) clock failure detected source clock q oscfif clock monitor device clock output sample clock failure detected oscillator failure note: the device clock is normally at a much higher freque ncy than the sample clock. the relative frequencies in this example have been chosen for clarity. output (q ) clock monitor test clock monitor test clock monitor test
? 2009 microchip technology inc. preliminary ds39931b-page 427 pic18f46j50 family 26.5.2 exiting fail-safe operation the fail-safe clock monitor condition is terminated by either a device reset or by entering a power-managed mode. on reset, the controller starts the primary clock source specified in configuration register 2h (with any required start-up delays that are required for the oscil- lator mode, such as ost or pll timer). the intrc oscillator provides the device clock until the primary clock source becomes ready (similar to a two-speed start-up). the clock source is then switched to the primary clock (indicated by the osts bit in the osccon register becoming set). the fscm then resumes monitoring the peripheral clock. the primary clock source may never become ready during start-up. in this case, operation is clocked by the intrc oscillator. the osccon register will remain in its reset state until a power-managed mode is entered. 26.5.3 fscm interrupts in power-managed modes by entering a power-managed mode, the clock multiplexer selects the clock source selected by the osccon register. fscm of the power-managed clock source resumes in the power-managed mode. if an oscillator failure occurs during power-managed operation, the subsequent events depend on whether or not the oscillator failure interrupt is enabled. if enabled (oscfif = 1 ), code execution will be clocked by the intrc multiplexer. an automatic transition back to the failed clock source will not occur. if the interrupt is disabled, subsequent interrupts while in idle mode will cause the cpu to begin executing instructions while being clocked by the intrc source. 26.5.4 por or wake-up from sleep the fscm is designed to detect oscillator failure at any point after the device has exited power-on reset (por) or low-power sleep mode. when the primary device clock is either the ec or intrc modes, monitoring can begin immediately following these events. for hs or hspll modes, the situation is somewhat different. since the oscillator may require a start-up time considerably longer than the fscm sample clock time, a false clock failure may be detected. to prevent this, the internal oscillator block is automatically config- ured as the device clock and functions until the primary clock is stable (the ost and pll timers have timed out). this is identical to two-speed start-up mode. once the primary clock is stable, the intrc returns to its role as the fscm source. as noted in section 26.4.1 ?special considerations for using two-speed start-up? , it is also possible to select another clock configuration and enter an alternate power-managed mode while waiting for the primary clock to become stable. when the new power-managed mode is selected, the primary clock is disabled. 26.6 program verification and code protection for all devices in the pic18f46j50 family of devices, the on-chip program memory space is treated as a single block. code protection for this block is controlled by one configuration bit, cp0. this bit inhibits external reads and writes to the program memory space. it has no direct effect in normal execution mode. 26.6.1 configuration register protection the configuration registers are protected against untoward changes or reads in two ways. the primary protection is the write-once feature of the configuration bits, which prevents reconfiguration once the bit has been programmed during a power cycle. to safeguard against unpredictable events, configuration bit changes resulting from individual cell level disruptions (such as esd events) will cause a parity error and trigger a device reset. this is seen by the user as a configuration mismatch (cm) reset. the data for the configuration registers is derived from the fcw in program memory. when the cp0 bit is set, the source data for device configuration is also protected as a consequence. note: the same logic that prevents false oscillator failure interrupts on por, or wake-up from sleep, will also prevent the detection of the oscillator?s failure to start at all following these events. this can be avoided by monitoring the osts bit and using a timing routine to determine if the oscillator is taking too long to start. even so, no oscillator failure interrupt will be flagged.
pic18f46j50 family ds39931b-page 428 preliminary ? 2009 microchip technology inc. 26.7 in-circuit serial programming (icsp) pic18f46j50 family microcontrollers can be serially programmed while in the end application circuit. this is simply done with two lines for clock and data and three other lines for power, ground and the programming voltage. this allows customers to manufacture boards with unprogrammed devices and then program the microcontroller just before shipping the product. this also allows the most recent firmware or a custom firmware to be programmed. 26.8 in-circuit debugger when the debug configuration bit is programmed to a ? 0 ?, the in-circuit debugger functionality is enabled. this function allows simple debugging functions when used with mplab ? ide. when the microcontroller has this feature enabled, some resources are not available for general use. table 26-4 lists the resources required by the background debugger. table 26-4: debugger resources i/o pins: rb6, rb7 stack: 2 levels program memory: 512 bytes data memory: 10 bytes
? 2009 microchip technology inc. preliminary ds39931b-page 429 pic18f46j50 family 27.0 instruction set summary the pic18f46j50 family of devices incorporates the standard set of 75 pic18 core instructions, and an extended set of eight new instructions for the optimiza- tion of code that is recursive or that utilizes a software stack. the extended set is discussed later in this section. 27.1 standard instruction set the standard pic18 instruction set adds many enhancements to the previous pic ? mcu instruction sets, while maintaining an easy migration from these pic mcu instruction sets. most instructions are a single program memory word (16 bits), but there are four instructions that require two program memory locations. each single-word instruction is a 16-bit word divided into an opcode, which specifies the instruction type and one or more operands, which further specify the operation of the instruction. the instruction set is highly orthogonal and is grouped into four basic categories: ? byte-oriented operations ? bit-oriented operations ? literal operations ? control operations the pic18 instruction set summary in table 27-2 lists the byte-oriented , bit-oriented , literal and control operations. table 27-1 provides the opcode field descriptions. most byte-oriented instructions have three operands: 1. the file register (specified by ?f?) 2. the destination of the result (specified by ?d?) 3. the accessed memory (specified by ?a?) the file register designator, ?f?, specifies which file register is to be used by the instruction. the destination designator, ?d?, specifies where the result of the operation is to be placed. if ?d? is ? 0 ?, the result is placed in the wreg register. if ?d? is ? 1 ?, the result is placed in the file register specified in the instruction. all bit-oriented instructions have three operands: 1. the file register (specified by ?f?) 2. the bit in the file register (specified by ?b?) 3. the accessed memory (specified by ?a?) the bit field designator ?b? selects the number of the bit affected by the operation, while the file register desig- nator, ?f?, represents the number of the file in which the bit is located. the literal instructions may use some of the following operands: ? a literal value to be loaded into a file register (specified by ?k?) ? the desired fsr register to load the literal value into (specified by ?f?) ? no operand required (specified by ???) the control instructions may use some of the following operands: ? a program memory address (specified by ?n?) ? the mode of the call or return instructions (specified by ?s?) ? the mode of the table read and table write instructions (specified by ?m?) ? no operand required (specified by ???) all instructions are a single word, except for four double-word instructions. these instructions were made double-word to contain the required information in 32 bits. in the second word, the 4 msbs are ? 1 ?s. if this second word is executed as an instruction (by itself), it will execute as a nop . all single-word instructions are executed in a single instruction cycle, unless a conditional test is true or the program counter (pc) is changed as a result of the instruction. in these cases, the execution takes two instruction cycles with the additional instruction cycle(s) executed as a nop . the double-word instructions execute in two instruction cycles. one instruction cycle consists of four oscillator periods. thus, for an oscillator frequency of 4 mhz, the normal instruction execution time is 1 s. if a conditional test is true, or the program counter is changed as a result of an instruction, the instruction execution time is 2 s. two-word branch instructions (if true) would take 3 s. figure 27-1 provides the general formats that the instructions can have. all examples use the convention ?nnh? to represent a hexadecimal number. the instruction set summary, provided in table 27-2, lists the standard instructions recognized by the microchip mpasm tm assembler. section 27.1.1 ?standard instruction set? provides a description of each instruction.
pic18f46j50 family ds39931b-page 430 preliminary ? 2009 microchip technology inc. table 27-1: opcode field descriptions field description a ram access bit: a = 0 : ram location in access ram (bsr register is ignored) a = 1 : ram bank is specified by bsr register bbb bit address within an 8-bit file register (0 to 7) bsr bank select register. used to select the current ram bank c, dc, z, ov, n alu status bits: c arry, d igit c arry, z ero, ov erflow, n egative d destination select bit: d = 0 : store result in wreg d = 1 : store result in file register f dest destination: either the wreg register or the specified register file location f 8-bit register file address (00h to ff h), or 2-bit fsr designator (0h to 3h) f s 12-bit register file address (000h to fffh). this is the source address f d 12-bit register file address (000h to fffh). this is the destination address gie global interrupt enable bit k literal field, constant data or label (may be either an 8-bit, 12-bit or a 20-bit value) label label name mm the mode of the tblptr register for the table read and table write instructions used only with table read and table write instructions * no change to register (such as tb lptr with table reads and writes) *+ post-increment register (such as tblptr with table reads and writes) *- post-decrement register (such as tblptr with table reads and writes) +* pre-increment register (such as tb lptr with table reads and writes) n the relative address (2?s complement number) for relative branch instructions or the direct address for call/branch and return instructions pc program counter pcl program counter low byte pch program counter high byte pclath program counter high byte latch pclatu program counter upper byte latch pd power-down bit prodh product of multiply high byte prodl product of multiply low byte s fast call/return mode select bit: s = 0 : do not update into/from shadow registers s = 1 : certain registers loaded into/from shadow registers (fast mode) tblptr 21-bit table pointer (points to a program memory location) tablat 8-bit table latch to time-out bit tos top-of-stack u unused or unchanged wdt watchdog timer wreg working register (accumulator) x don?t care (? 0 ? or ? 1 ?). the assembler will generate code with x = 0 ; it is the recommended form of use for compatibility with all microchip software tools z s 7-bit offset value for indirect addressing of register files (source) z d 7-bit offset value for indirect addressing of register files (destination) { } optional argument [text] indicates indexed addressing (text) the contents of text [expr] specifies bit n of the register indicated by the pointer, expr assigned to < > register bit field in the set of italics user-defined term (font is courier new)
? 2009 microchip technology inc. preliminary ds39931b-page 431 pic18f46j50 family example 27-1: general format for instructions byte-oriented file register operations 15 10 9 8 7 0 d = 0 for result destination to be wreg register opcode d a f (file #) d = 1 for result destination to be file register (f) a = 0 to force access bank bit-oriented file register operations 15 12 11 9 8 7 0 opcode b (bit #) a f (file #) b = 3-bit position of bit in file register (f) literal operations 15 8 7 0 opcode k (literal) k = 8-bit immediate value byte to byte move operations (2-word) 15 12 11 0 opcode f (source file #) call, goto and branch operations 15 8 7 0 opcode n<7:0> (literal) n = 20-bit immediate value a = 1 for bsr to select bank f = 8-bit file register address a = 0 to force access bank a = 1 for bsr to select bank f = 8-bit file register address 15 12 11 0 1111 n<19:8> (literal) 15 12 11 0 1111 f (destination file #) f = 12-bit file register address control operations example instruction addwf myreg, w, b movff myreg1, myreg2 bsf myreg, bit, b movlw 7fh goto label 15 8 7 0 opcode n<7:0> (literal) 15 12 11 0 1111 n<19:8> (literal) call myfunc 15 11 10 0 opcode n<10:0> (literal) s = fast bit bra myfunc 15 8 7 0 opcode n<7:0> (literal) bc myfunc s
pic18f46j50 family ds39931b-page 432 preliminary ? 2009 microchip technology inc. table 27-2: pic18f46j50 family instruction set mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb byte-oriented operations addwf addwfc andwf clrf comf cpfseq cpfsgt cpfslt decf decfsz dcfsnz incf incfsz infsnz iorwf movf movff movwf mulwf negf rlcf rlncf rrcf rrncf setf subfwb subwf subwfb swapf tstfsz xorwf f, d, a f, d, a f, d, a f, a f, d, a f, a f, a f, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f s , f d f, a f, a f, a f, d, a f, d, a f, d, a f, d, a f, a f, d, a f, d, a f, d, a f, d, a f, a f, d, a add wreg and f add wreg and carry bit to f and wreg with f clear f complement f compare f with wreg, skip = compare f with wreg, skip > compare f with wreg, skip < decrement f decrement f, skip if 0 decrement f, skip if not 0 increment f increment f, skip if 0 increment f, skip if not 0 inclusive or wreg with f move f move f s (source) to 1st word f d (destination) 2nd word move wreg to f multiply wreg with f negate f rotate left f through carry rotate left f (no carry) rotate right f through carry rotate right f (no carry) set f subtract f from wreg with borrow subtract wreg from f subtract wreg from f with borrow swap nibbles in f test f, skip if 0 exclusive or wreg with f 1 1 1 1 1 1 (2 or 3) 1 (2 or 3) 1 (2 or 3) 1 1 (2 or 3) 1 (2 or 3) 1 1 (2 or 3) 1 (2 or 3) 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 (2 or 3) 1 0010 0010 0001 0110 0001 0110 0110 0110 0000 0010 0100 0010 0011 0100 0001 0101 1100 1111 0110 0000 0110 0011 0100 0011 0100 0110 0101 0101 0101 0011 0110 0001 01da 00da 01da 101a 11da 001a 010a 000a 01da 11da 11da 10da 11da 10da 00da 00da ffff ffff 111a 001a 110a 01da 01da 00da 00da 100a 01da 11da 10da 10da 011a 10da ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff c, dc, z, ov, n c, dc, z, ov, n z, n z z, n none none none c, dc, z, ov, n none none c, dc, z, ov, n none none z, n z, n none none none c, dc, z, ov, n c, z, n z, n c, z, n z, n none c, dc, z, ov, n c, dc, z, ov, n c, dc, z, ov, n none none z, n 1, 2 1, 2 1,2 2 1, 2 4 4 1, 2 1, 2, 3, 4 1, 2, 3, 4 1, 2 1, 2, 3, 4 4 1, 2 1, 2 1 1, 2 1, 2 1, 2 1, 2 4 1, 2 note 1: when a port register is modified as a function of itself (e.g., movf portb , 1 , 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and, where applicable, d = 1 ), the prescaler will be cleared if assigned. 3: if the program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the second word of these instructions will be executed as a nop unless the first word of the instruction retrieves the information embedded in these 16 bits. this ensures that all program memory locations have a valid instruction.
? 2009 microchip technology inc. preliminary ds39931b-page 433 pic18f46j50 family bit-oriented operations bcf bsf btfsc btfss btg f, b, a f, b, a f, b, a f, b, a f, b, a bit clear f bit set f bit test f, skip if clear bit test f, skip if set bit toggle f 1 1 1 (2 or 3) 1 (2 or 3) 1 1001 1000 1011 1010 0111 bbba bbba bbba bbba bbba ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff none none none none none 1, 2 1, 2 3, 4 3, 4 1, 2 control operations bc bn bnc bnn bnov bnz bov bra bz call clrwdt daw goto nop nop pop push rcall reset retfie retlw return sleep n n n n n n n n n n, s ? ? n ? ? ? ? n s k s ? branch if carry branch if negative branch if not carry branch if not negative branch if not overflow branch if not zero branch if overflow branch unconditionally branch if zero call subroutine 1st word 2nd word clear watchdog timer decimal adjust wreg go to address 1st word 2nd word no operation no operation pop top of return stack (tos) push top of return stack (tos) relative call software device reset return from interrupt enable return with literal in wreg return from subroutine go into standby mode 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 2 1 (2) 2 1 1 2 1 1 1 1 2 1 2 2 2 1 1110 1110 1110 1110 1110 1110 1110 1101 1110 1110 1111 0000 0000 1110 1111 0000 1111 0000 0000 1101 0000 0000 0000 0000 0000 0010 0110 0011 0111 0101 0001 0100 0nnn 0000 110s kkkk 0000 0000 1111 kkkk 0000 xxxx 0000 0000 1nnn 0000 0000 1100 0000 0000 nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn kkkk kkkk 0000 0000 kkkk kkkk 0000 xxxx 0000 0000 nnnn 1111 0001 kkkk 0001 0000 nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn kkkk kkkk 0100 0111 kkkk kkkk 0000 xxxx 0110 0101 nnnn 1111 000s kkkk 001s 0011 none none none none none none none none none none to , pd c none none none none none none all gie/gieh, peie/giel none none to , pd 4 table 27-2: pic18f46j50 family instruction set (continued) mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb note 1: when a port register is modified as a function of itself (e.g., movf portb , 1 , 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and, where applicable, d = 1 ), the prescaler will be cleared if assigned. 3: if the program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the second word of these instructions will be executed as a nop unless the first word of the instruction retrieves the information embedded in these 16 bits. this ensures that all program memory locations have a valid instruction.
pic18f46j50 family ds39931b-page 434 preliminary ? 2009 microchip technology inc. literal operations addlw andlw iorlw lfsr movlb movlw mullw retlw sublw xorlw k k k f, k k k k k k k add literal and wreg and literal with wreg inclusive or literal with wreg move literal (12-bit) 2nd word to fsr(f) 1st word move literal to bsr<3:0> move literal to wreg multiply literal with wreg return with literal in wreg subtract wreg from literal exclusive or literal with wreg 1 1 1 2 1 1 1 2 1 1 0000 0000 0000 1110 1111 0000 0000 0000 0000 0000 0000 1111 1011 1001 1110 0000 0001 1110 1101 1100 1000 1010 kkkk kkkk kkkk 00ff kkkk 0000 kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk c, dc, z, ov, n z, n z, n none none none none none c, dc, z, ov, n z, n data memory ? program memory operations tblrd* tblrd*+ tblrd*- tblrd+* tblwt* tblwt*+ tblwt*- tblwt+* table read table read with post-increment table read with post-decrement table read with pre-increment table write table write with post-increment table write with post-decrement table write with pre-increment 2 2 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1000 1001 1010 1011 1100 1101 1110 1111 none none none none none none none none table 27-2: pic18f46j50 family instruction set (continued) mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb note 1: when a port register is modified as a function of itself (e.g., movf portb , 1 , 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and, where applicable, d = 1 ), the prescaler will be cleared if assigned. 3: if the program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the second word of these instructions will be executed as a nop unless the first word of the instruction retrieves the information embedded in these 16 bits. this ensures that all program memory locations have a valid instruction.
? 2009 microchip technology inc. preliminary ds39931b-page 435 pic18f46j50 family 27.1.1 standard instruction set addlw add literal to w syntax: addlw k operands: 0 k 255 operation: (w) + k w status affected: n, ov, c, dc, z encoding: 0000 1111 kkkk kkkk description: the contents of w are added to the 8-bit literal ?k? and the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: addlw 15h before instruction w = 10h after instruction w = 25h addwf add w to f syntax: addwf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) + (f) dest status affected: n, ov, c, dc, z encoding: 0010 01da ffff ffff description: add w to register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: addwf reg, 0, 0 before instruction w = 17h reg = 0c2h after instruction w = 0d9h reg = 0c2h note: all pic18 instructions may take an optional label argument preceding the instruction mnemonic for use in symbolic addressing. if a label is used, the instruction format then becomes: {label} instruction argument(s).
pic18f46j50 family ds39931b-page 436 preliminary ? 2009 microchip technology inc. addwfc add w and carry bit to f syntax: addwfc f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) + (f) + (c) dest status affected: n,ov, c, dc, z encoding: 0010 00da ffff ffff description: add w, the carry flag and data memory location ?f?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed in data memory location ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: addwfc reg, 0, 1 before instruction carry bit = 1 reg = 02h w=4dh after instruction carry bit = 0 reg = 02h w = 50h andlw and literal with w syntax: andlw k operands: 0 k 255 operation: (w) .and. k w status affected: n, z encoding: 0000 1011 kkkk kkkk description: the contents of w are anded with the 8-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: andlw 05fh before instruction w=a3h after instruction w = 03h
? 2009 microchip technology inc. preliminary ds39931b-page 437 pic18f46j50 family andwf and w with f syntax: andwf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) .and. (f) dest status affected: n, z encoding: 0001 01da ffff ffff description: the contents of w are anded with register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: andwf reg, 0, 0 before instruction w = 17h reg = c2h after instruction w = 02h reg = c2h bc branch if carry syntax: bc n operands: -128 n 127 operation: if carry bit is ? 1 ?, (pc) + 2 + 2n pc status affected: none encoding: 1110 0010 nnnn nnnn description: if the carry bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bc 5 before instruction pc = address (here) after instruction if carry = 1; pc = address (here + 12) if carry = 0; pc = address (here + 2)
pic18f46j50 family ds39931b-page 438 preliminary ? 2009 microchip technology inc. bcf bit clear f syntax: bcf f, b {,a} operands: 0 f 255 0 b 7 a [0,1] operation: 0 f status affected: none encoding: 1001 bbba ffff ffff description: bit ?b? in register ?f? is cleared. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: bcf flag_reg, 7, 0 before instruction flag_reg = c7h after instruction flag_reg = 47h bn branch if negative syntax: bn n operands: -128 n 127 operation: if negative bit is ? 1 ?, (pc) + 2 + 2n pc status affected: none encoding: 1110 0110 nnnn nnnn description: if the negative bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bn jump before instruction pc = address (here) after instruction if negative = 1; pc = address (jump) if negative = 0; pc = address (here + 2)
? 2009 microchip technology inc. preliminary ds39931b-page 439 pic18f46j50 family bnc branch if not carry syntax: bnc n operands: -128 n 127 operation: if carry bit is ? 0 ?, (pc) + 2 + 2n pc status affected: none encoding: 1110 0011 nnnn nnnn description: if the carry bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnc jump before instruction pc = address (here) after instruction if carry = 0; pc = address (jump) if carry = 1; pc = address (here + 2) bnn branch if not negative syntax: bnn n operands: -128 n 127 operation: if negative bit is ? 0 ?, (pc) + 2 + 2n pc status affected: none encoding: 1110 0111 nnnn nnnn description: if the negative bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnn jump before instruction pc = address (here) after instruction if negative = 0; pc = address (jump) if negative = 1; pc = address (here + 2)
pic18f46j50 family ds39931b-page 440 preliminary ? 2009 microchip technology inc. bnov branch if not overflow syntax: bnov n operands: -128 n 127 operation: if overflow bit is ? 0 ?, (pc) + 2 + 2n pc status affected: none encoding: 1110 0101 nnnn nnnn description: if the overflow bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnov jump before instruction pc = address (here) after instruction if overflow = 0; pc = address (jump) if overflow = 1; pc = address (here + 2) bnz branch if not zero syntax: bnz n operands: -128 n 127 operation: if zero bit is ? 0 ?, (pc) + 2 + 2n pc status affected: none encoding: 1110 0001 nnnn nnnn description: if the zero bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnz jump before instruction pc = address (here) after instruction if zero = 0; pc = address (jump) if zero = 1; pc = address (here + 2)
? 2009 microchip technology inc. preliminary ds39931b-page 441 pic18f46j50 family bra unconditional branch syntax: bra n operands: -1024 n 1023 operation: (pc) + 2 + 2n pc status affected: none encoding: 1101 0nnn nnnn nnnn description: add the 2?s complement number ?2n? to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is a two-cycle instruction. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation example: here bra jump before instruction pc = address (here) after instruction pc = address (jump) bsf bit set f syntax: bsf f, b {,a} operands: 0 f 255 0 b 7 a [0,1] operation: 1 f status affected: none encoding: 1000 bbba ffff ffff description: bit ?b? in register ?f? is set. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: bsf flag_reg, 7, 1 before instruction flag_reg = 0ah after instruction flag_reg = 8ah
pic18f46j50 family ds39931b-page 442 preliminary ? 2009 microchip technology inc. btfsc bit test file, skip if clear syntax: btfsc f, b {,a} operands: 0 f 255 0 b 7 a [0,1] operation: skip if (f) = 0 status affected: none encoding: 1011 bbba ffff ffff description: if bit ?b? in register ?f? is ? 0 ?, then the next instruction is skipped. if bit ?b? is ? 0 ?, then the next instruction fetched during the current instruction execution is dis- carded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here false true btfsc : : flag, 1, 0 before instruction pc = address (here) after instruction if flag<1> = 0; pc = address (true) if flag<1> = 1; pc = address (false) btfss bit test file, skip if set syntax: btfss f, b {,a} operands: 0 f 255 0 b < 7 a [0,1] operation: skip if (f) = 1 status affected: none encoding: 1010 bbba ffff ffff description: if bit ?b? in register ?f? is ? 1 ?, then the next instruction is skipped. if bit ?b? is ? 1 ?, then the next instruction fetched during the current instruction execution is dis- carded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here false true btfss : : flag, 1, 0 before instruction pc = address (here) after instruction if flag<1> = 0; pc = address (false) if flag<1> = 1; pc = address (true)
? 2009 microchip technology inc. preliminary ds39931b-page 443 pic18f46j50 family btg bit toggle f syntax: btg f, b {,a} operands: 0 f 255 0 b < 7 a [0,1] operation: (f ) f status affected: none encoding: 0111 bbba ffff ffff description: bit ?b? in data memory location ?f? is inverted. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: btg portc, 4, 0 before instruction: portc = 0111 0101 [75h] after instruction: portc = 0110 0101 [65h] bov branch if overflow syntax: bov n operands: -128 n 127 operation: if overflow bit is ? 1 ?, (pc) + 2 + 2n pc status affected: none encoding: 1110 0100 nnnn nnnn description: if the overflow bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bov jump before instruction pc = address (here) after instruction if overflow = 1; pc = address (jump) if overflow = 0; pc = address (here + 2)
pic18f46j50 family ds39931b-page 444 preliminary ? 2009 microchip technology inc. bz branch if zero syntax: bz n operands: -128 n 127 operation: if zero bit is ? 1 ?, (pc) + 2 + 2n pc status affected: none encoding: 1110 0000 nnnn nnnn description: if the zero bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bz jump before instruction pc = address (here) after instruction if zero = 1; pc = address (jump) if zero = 0; pc = address (here + 2) call subroutine call syntax: call k {,s} operands: 0 k 1048575 s [0,1] operation: (pc) + 4 tos, k pc<20:1>; if s = 1 , (w) ws, (status) statuss, (bsr) bsrs status affected: none encoding: 1st word (k<7:0>) 2nd word(k<19:8>) 1110 1111 110s k 19 kkk k 7 kkk kkkk kkkk 0 kkkk 8 description: subroutine call of entire 2-mbyte memory range. first, return address (pc + 4) is pushed onto the return stack. if ?s? = 1 , the w, status and bsr registers are also pushed into their respective shadow registers, ws, statuss and bsrs. if ?s? = 0 , no update occurs (default). then, the 20-bit value ?k? is loaded into pc<20:1>. call is a two-cycle instruction. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k?<7:0>, push pc to stack read literal ?k?<19:8>, write to pc no operation no operation no operation no operation example: here call there,1 before instruction pc = address (here) after instruction pc = address (there) tos = address (here + 4) ws = w bsrs = bsr statuss = status
? 2009 microchip technology inc. preliminary ds39931b-page 445 pic18f46j50 family clrf clear f syntax: clrf f {,a} operands: 0 f 255 a [0,1] operation: 000h f, 1 z status affected: z encoding: 0110 101a ffff ffff description: clears the contents of the specified register. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: clrf flag_reg,1 before instruction flag_reg = 5ah after instruction flag_reg = 00h clrwdt clear watchdog timer syntax: clrwdt operands: none operation: 000h wdt, 000h wdt postscaler, 1 to, 1 pd status affected: to , pd encoding: 0000 0000 0000 0100 description: clrwdt instruction resets the watchdog timer. it also resets the postscaler of the wdt. status bits, to and pd , are set. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation process data no operation example: clrwdt before instruction wdt counter = ? after instruction wdt counter = 00h wdt postscaler = 0 to =1 pd =1
pic18f46j50 family ds39931b-page 446 preliminary ? 2009 microchip technology inc. comf complement f syntax: comf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: f dest status affected: n, z encoding: 0001 11da ffff ffff description: the contents of register ?f? are complemented. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: comf reg, 0, 0 before instruction reg = 13h after instruction reg = 13h w=ech cpfseq compare f with w, skip if f = w syntax: cpfseq f {,a} operands: 0 f 255 a [0,1] operation: (f) ? (w), skip if (f) = (w) (unsigned comparison) status affected: none encoding: 0110 001a ffff ffff description: compares the contents of data mem- ory location ?f? to the contents of w by performing an unsigned subtraction. if ?f? = w , then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here cpfseq reg, 0 nequal : equal : before instruction pc address = here w=? reg = ? after instruction if reg = w; pc = address (equal) if reg w; pc = address (nequal)
? 2009 microchip technology inc. preliminary ds39931b-page 447 pic18f46j50 family cpfsgt compare f with w, skip if f > w syntax: cpfsgt f {,a} operands: 0 f 255 a [0,1] operation: (f) ? ( w), skip if (f) > (w) (unsigned comparison) status affected: none encoding: 0110 010a ffff ffff description: compares the contents of data mem- ory location ?f? to the contents of the w by performing an unsigned subtraction. if the contents of ?f? are greater than the contents of wreg , then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here cpfsgt reg, 0 ngreater : greater : before instruction pc = address (here) w= ? after instruction if reg > w; pc = address (greater) if reg w; pc = address (ngreater) cpfslt compare f with w, skip if f < w syntax: cpfslt f {,a} operands: 0 f 255 a [0,1] operation: (f) ? ( w), skip if (f) < (w) (unsigned comparison) status affected: none encoding: 0110 000a ffff ffff description: compares the contents of data mem- ory location ?f? to the contents of w by performing an unsigned subtraction. if the contents of ?f? are less than the contents of w, then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here cpfslt reg, 1 nless : less : before instruction pc = address (here) w= ? after instruction if reg < w; pc = address (less) if reg w; pc = address (nless)
pic18f46j50 family ds39931b-page 448 preliminary ? 2009 microchip technology inc. daw decimal adjust w register syntax: daw operands: none operation: if [w<3:0> > 9] or [dc = 1 ] then, (w<3:0>) + 6 w<3:0>; else, (w<3:0>) w<3:0> if [w<7:4> > 9] or [c = 1 ] then, (w<7:4>) + 6 w<7:4>, c = 1 ; else, (w<7:4>) w<7:4> status affected: c encoding: 0000 0000 0000 0111 description: daw adjusts the eight-bit value in w, resulting from the earlier addition of two variables (each in packed bcd format) and produces a correct packed bcd result. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register w process data write w example 1: daw before instruction w=a5h c=0 dc = 0 after instruction w = 05h c=1 dc = 0 example 2: before instruction w=ceh c=0 dc = 0 after instruction w = 34h c=1 dc = 0 decf decrement f syntax: decf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? 1 dest status affected: c, dc, n, ov, z encoding: 0000 01da ffff ffff description: decrement register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: decf cnt, 1, 0 before instruction cnt = 01h z=0 after instruction cnt = 00h z=1
? 2009 microchip technology inc. preliminary ds39931b-page 449 pic18f46j50 family decfsz decrement f, skip if 0 syntax: decfsz f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? 1 dest, skip if result = 0 status affected: none encoding: 0010 11da ffff ffff description: the contents of register ?f? are decremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here decfsz cnt, 1, 1 goto loop continue before instruction pc = address (here) after instruction cnt = cnt ? 1 if cnt = 0; pc = address (continue) if cnt 0; pc = address (here + 2) dcfsnz decrement f, skip if not 0 syntax: dcfsnz f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? 1 dest, skip if result 0 status affected: none encoding: 0100 11da ffff ffff description: the contents of register ?f? are decremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is not ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here dcfsnz temp, 1, 0 zero : nzero : before instruction temp = ? after instruction temp = temp ? 1, if temp = 0; pc = address (zero) if temp 0; pc = address (nzero)
pic18f46j50 family ds39931b-page 450 preliminary ? 2009 microchip technology inc. goto unconditional branch syntax: goto k operands: 0 k 1048575 operation: k pc<20:1> status affected: none encoding: 1st word (k<7:0>) 2nd word(k<19:8>) 1110 1111 1111 k 19 kkk k 7 kkk kkkk kkkk 0 kkkk 8 description: goto allows an unconditional branch anywhere within entire 2-mbyte mem- ory range. the 20-bit value ?k? is loaded into pc<20:1>. goto is always a two-cycle instruction. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k?<7:0>, no operation read literal ?k?<19:8>, write to pc no operation no operation no operation no operation example: goto there after instruction pc = address (there) incf increment f syntax: incf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) + 1 dest status affected: c, dc, n, ov, z encoding: 0010 10da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: incf cnt, 1, 0 before instruction cnt = ffh z=0 c=? dc = ? after instruction cnt = 00h z=1 c=1 dc = 1
? 2009 microchip technology inc. preliminary ds39931b-page 451 pic18f46j50 family incfsz increment f, skip if 0 syntax: incfsz f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) + 1 dest, skip if result = 0 status affected: none encoding: 0011 11da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f?. (default) if the result is ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here incfsz cnt, 1, 0 nzero : zero : before instruction pc = address (here) after instruction cnt = cnt + 1 if cnt = 0; pc = address (zero) if cnt 0; pc = address (nzero) infsnz increment f, skip if not 0 syntax: infsnz f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) + 1 dest, skip if result 0 status affected: none encoding: 0100 10da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is not ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here infsnz reg, 1, 0 zero nzero before instruction pc = address (here) after instruction reg = reg + 1 if reg 0; pc = address (nzero) if reg = 0; pc = address (zero)
pic18f46j50 family ds39931b-page 452 preliminary ? 2009 microchip technology inc. iorlw inclusive or literal with w syntax: iorlw k operands: 0 k 255 operation: (w) .or. k w status affected: n, z encoding: 0000 1001 kkkk kkkk description: the contents of w are ored with the eight-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: iorlw 35h before instruction w=9ah after instruction w=bfh iorwf inclusive or w with f syntax: iorwf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) .or. (f) dest status affected: n, z encoding: 0001 00da ffff ffff description: inclusive or w with register ?f?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: iorwf result, 0, 1 before instruction result = 13h w = 91h after instruction result = 13h w = 93h
? 2009 microchip technology inc. preliminary ds39931b-page 453 pic18f46j50 family lfsr load fsr syntax: lfsr f, k operands: 0 f 2 0 k 4095 operation: k fsrf status affected: none encoding: 1110 1111 1110 0000 00ff k 7 kkk k 11 kkk kkkk description: the 12-bit literal ?k? is loaded into the file select register pointed to by ?f?. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? msb process data write literal ?k? msb to fsrfh decode read literal ?k? lsb process data write literal ?k? to fsrfl example: lfsr 2, 3abh after instruction fsr2h = 03h fsr2l = abh movf move f syntax: movf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: f dest status affected: n, z encoding: 0101 00da ffff ffff description: the contents of register ?f? are moved to a destination dependent upon the status of ?d?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). location ?f? can be anywhere in the 256-byte bank. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write w example: movf reg, 0, 0 before instruction reg = 22h w=ffh after instruction reg = 22h w = 22h
pic18f46j50 family ds39931b-page 454 preliminary ? 2009 microchip technology inc. movff move f to f syntax: movff f s ,f d operands: 0 f s 4095 0 f d 4095 operation: (f s ) f d status affected: none encoding: 1st word (source) 2nd word (destin.) 1100 1111 ffff ffff ffff ffff ffff s ffff d description: the contents of source register ?f s ? are moved to destination register ?f d ?. location of source ?f s ? can be anywhere in the 4096-byte data space (000h to fffh) and location of destination ?f d ? can also be anywhere from 000h to fffh. either source or destination can be w (a useful special situation). movff is particularly useful for transferring a data memory location to a peripheral register (such as the transmit buffer or an i/o port). the movff instruction cannot use the pcl, tosu, tosh or tosl as the destination register words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read register ?f? (src) process data no operation decode no operation no dummy read no operation write register ?f? (dest) example: movff reg1, reg2 before instruction reg1 = 33h reg2 = 11h after instruction reg1 = 33h reg2 = 33h movlb move literal to low nibble in bsr syntax: movlw k operands: 0 k 255 operation: k bsr status affected: none encoding: 0000 0001 kkkk kkkk description: the eight-bit literal ?k? is loaded into the bank select register (bsr). the value of bsr<7:4> always remains ? 0 ? regardless of the value of k 7 :k 4 . words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write literal ?k? to bsr example: movlb 5 before instruction bsr register = 02h after instruction bsr register = 05h
? 2009 microchip technology inc. preliminary ds39931b-page 455 pic18f46j50 family movlw move literal to w syntax: movlw k operands: 0 k 255 operation: k w status affected: none encoding: 0000 1110 kkkk kkkk description: the eight-bit literal ?k? is loaded into w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: movlw 5ah after instruction w=5ah movwf move w to f syntax: movwf f {,a} operands: 0 f 255 a [0,1] operation: (w) f status affected: none encoding: 0110 111a ffff ffff description: move data from w to register ?f?. location ?f? can be anywhere in the 256-byte bank. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: movwf reg, 0 before instruction w=4fh reg = ffh after instruction w=4fh reg = 4fh
pic18f46j50 family ds39931b-page 456 preliminary ? 2009 microchip technology inc. mullw multiply literal with w syntax: mullw k operands: 0 k 255 operation: (w) x k prodh:prodl status affected: none encoding: 0000 1101 kkkk kkkk description: an unsigned multiplication is carried out between the contents of w and the 8-bit literal ?k?. the 16-bit result is placed in prodh:prodl register pair. prodh contains the high byte. w is unchanged. none of the status flags are affected. note that neither overflow nor carry is possible in this operation. a zero result is possible but not detected. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write registers prodh: prodl example: mullw 0c4h before instruction w=e2h prodh = ? prodl = ? after instruction w=e2h prodh = adh prodl = 08h mulwf multiply w with f syntax: mulwf f {,a} operands: 0 f 255 a [0,1] operation: (w) x (f) prodh:prodl status affected: none encoding: 0000 001a ffff ffff description: an unsigned multiplication is carried out between the contents of w and the register file location ?f?. the 16-bit result is stored in the prodh:prodl register pair. prodh contains the high byte. both w and ?f? are unchanged. none of the status flags are affected. note that neither overflow nor carry is possible in this operation. a zero result is possible but not detected. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write registers prodh: prodl example: mulwf reg, 1 before instruction w=c4h reg = b5h prodh = ? prodl = ? after instruction w=c4h reg = b5h prodh = 8ah prodl = 94h
? 2009 microchip technology inc. preliminary ds39931b-page 457 pic18f46j50 family negf negate f syntax: negf f {,a} operands: 0 f 255 a [0,1] operation: (f ) + 1 f status affected: n, ov, c, dc, z encoding: 0110 110a ffff ffff description: location ?f? is negated using two?s complement. the result is placed in the data memory location ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: negf reg, 1 before instruction reg = 0011 1010 [3ah] after instruction reg = 1100 0110 [c6h] nop no operation syntax: nop operands: none operation: no operation status affected: none encoding: 0000 1111 0000 xxxx 0000 xxxx 0000 xxxx description: no operation. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation example: none.
pic18f46j50 family ds39931b-page 458 preliminary ? 2009 microchip technology inc. pop pop top of return stack syntax: pop operands: none operation: (tos) bit bucket status affected: none encoding: 0000 0000 0000 0110 description: the tos value is pulled off the return stack and is discarded. the tos value then becomes the previous value that was pushed onto the return stack. this instruction is provided to enable the user to properly manage the return stack to incorporate a software stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation pop tos value no operation example: pop goto new before instruction tos = 0031a2h stack (1 level down) = 014332h after instruction tos = 014332h pc = new push push top of return stack syntax: push operands: none operation: (pc + 2) tos status affected: none encoding: 0000 0000 0000 0101 description: the pc + 2 is pushed onto the top of the return stack. the previous tos value is pushed down on the stack. this instruction allows implementing a software stack by modifying tos and then pushing it onto the return stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode push pc + 2 onto return stack no operation no operation example: push before instruction tos = 345ah pc = 0124h after instruction pc = 0126h tos = 0126h stack (1 level down) = 345ah
? 2009 microchip technology inc. preliminary ds39931b-page 459 pic18f46j50 family rcall relative call syntax: rcall n operands: -1024 n 1023 operation: (pc) + 2 tos, (pc) + 2 + 2n pc status affected: none encoding: 1101 1nnn nnnn nnnn description: subroutine call with a jump up to 1k from the current location. first, return address (pc + 2) is pushed onto the stack. then, add the 2?s complement number ?2n? to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is a two-cycle instruction. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?n? push pc to stack process data write to pc no operation no operation no operation no operation example: here rcall jump before instruction pc = address (here) after instruction pc = address (jump) tos = address (here + 2) reset reset syntax: reset operands: none operation: reset all registers and flags that are affected by a mclr reset. status affected: all encoding: 0000 0000 1111 1111 description: this instruction provides a way to execute a mclr reset in software. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode start reset no operation no operation example: reset after instruction registers = reset value flags* = reset value
pic18f46j50 family ds39931b-page 460 preliminary ? 2009 microchip technology inc. retfie return from interrupt syntax: retfie {s} operands: s [0,1] operation: (tos) pc, 1 gie/gieh or peie/giel; if s = 1 , (ws) w, (statuss) status, (bsrs) bsr, pclatu, pclath are unchanged status affected: gie/gieh, peie/giel. encoding: 0000 0000 0001 000s description: return from interrupt. stack is popped and top-of-stack (tos) is loaded into the pc. interrupts are enabled by setting either the high or low-priority global interrupt enable bit. if ?s? = 1 , the contents of the shadow registers ws, statuss and bsrs are loaded into their corresponding registers w, status and bsr. if ?s? = 0 , no update of these registers occurs (default). words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation pop pc from stack set gieh or giel no operation no operation no operation no operation example: retfie 1 after interrupt pc = tos w=ws bsr = bsrs status = statuss gie/gieh, peie/giel = 1 retlw return literal to w syntax: retlw k operands: 0 k 255 operation: k w, (tos) pc, pclatu, pclath are unchanged status affected: none encoding: 0000 1100 kkkk kkkk description: w is loaded with the eight-bit literal ?k?. the program counter is loaded from the top of the stack (the return address). the high address latch (pclath) remains unchanged. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data pop pc from stack, write to w no operation no operation no operation no operation example: call table ; w contains table ; offset value ; w now has ; table value : table addwf pcl ; w = offset retlw k0 ; begin table retlw k1 ; : : retlw kn ; end of table before instruction w = 07h after instruction w = value of kn
? 2009 microchip technology inc. preliminary ds39931b-page 461 pic18f46j50 family return return from subroutine syntax: return {s} operands: s [0,1] operation: (tos) pc; if s = 1 , (ws) w, (statuss) status, (bsrs) bsr, pclatu, pclath are unchanged status affected: none encoding: 0000 0000 0001 001s description: return from subroutine. the stack is popped and the top of the stack (tos) is loaded into the program counter. if ?s?= 1 , the contents of the shadow registers ws, statuss and bsrs are loaded into their corresponding registers w, status and bsr. if ?s? = 0 , no update of these registers occurs (default). words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation process data pop pc from stack no operation no operation no operation no operation example: return after instruction: pc = tos rlcf rotate left f through carry syntax: rlcf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) dest, (f<7>) c, (c) dest<0> status affected: c, n, z encoding: 0011 01da ffff ffff description: the contents of register ?f? are rotated one bit to the left through the carry flag. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: rlcf reg, 0, 0 before instruction reg = 1110 0110 c=0 after instruction reg = 1110 0110 w= 1100 1100 c=1 c register f
pic18f46j50 family ds39931b-page 462 preliminary ? 2009 microchip technology inc. rlncf rotate left f (no carry) syntax: rlncf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) dest, (f<7>) dest<0> status affected: n, z encoding: 0100 01da ffff ffff description: the contents of register ?f? are rotated one bit to the left. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction oper- ates in indexed lite ral offset address- ing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: rlncf reg, 1, 0 before instruction reg = 1010 1011 after instruction reg = 0101 0111 register f rrcf rotate right f through carry syntax: rrcf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) dest, (f<0>) c, (c) dest<7> status affected: c, n, z encoding: 0011 00da ffff ffff description: the contents of register ?f? are rotated one bit to the right through the carry flag. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: rrcf reg, 0, 0 before instruction reg = 1110 0110 c=0 after instruction reg = 1110 0110 w= 0111 0011 c=0 c register f
? 2009 microchip technology inc. preliminary ds39931b-page 463 pic18f46j50 family rrncf rotate right f (no carry) syntax: rrncf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) dest, (f<0>) dest<7> status affected: n, z encoding: 0100 00da ffff ffff description: the contents of register ?f? are rotated one bit to the right. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? is ? 1 ?, then the bank will be selected as per the bsr value (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: rrncf reg, 1, 0 before instruction reg = 1101 0111 after instruction reg = 1110 1011 example 2: rrncf reg, 0, 0 before instruction w=? reg = 1101 0111 after instruction w= 1110 1011 reg = 1101 0111 register f setf set f syntax: setf f {,a} operands: 0 f 255 a [0,1] operation: ffh f status affected: none encoding: 0110 100a ffff ffff description: the contents of the specified register are set to ffh. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: setf reg,1 before instruction reg = 5ah after instruction reg = ffh
pic18f46j50 family ds39931b-page 464 preliminary ? 2009 microchip technology inc. sleep enter sleep mode syntax: sleep operands: none operation: 00h wdt, 0 wdt postscaler, 1 to , 0 pd status affected: to , pd encoding: 0000 0000 0000 0011 description: the power-down status bit (pd ) is cleared. the time-out status bit (to ) is set. the watchdog timer and its postscaler are cleared. the processor is put into sleep mode with the oscillator stopped. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation process data go to sleep example: sleep before instruction to =? pd =? after instruction to =1 ? pd =0 ? if wdt causes wake-up, this bit is cleared. subfwb subtract f from w with borrow syntax: subfwb f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) ? (f) ? (c ) dest status affected: n, ov, c, dc, z encoding: 0101 01da ffff ffff description: subtract register ?f? and carry flag (borrow) from w (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: subfwb reg, 1, 0 before instruction reg = 3 w=2 c=1 after instruction reg = ff w=2 c=0 z=0 n = 1 ; result is negative example 2: subfwb reg, 0, 0 before instruction reg = 2 w=5 c=1 after instruction reg = 2 w=3 c=1 z=0 n = 0 ; result is positive example 3: subfwb reg, 1, 0 before instruction reg = 1 w=2 c=0 after instruction reg = 0 w=2 c=1 z = 1 ; result is zero n=0
? 2009 microchip technology inc. preliminary ds39931b-page 465 pic18f46j50 family sublw subtract w from literal syntax: sublw k operands: 0 k 255 operation: k ? (w) w status affected: n, ov, c, dc, z encoding: 0000 1000 kkkk kkkk description: w is subtracted from the eight-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example 1: sublw 02h before instruction w = 01h c=? after instruction w = 01h c = 1 ; result is positive z=0 n=0 example 2: sublw 02h before instruction w = 02h c=? after instruction w = 00h c = 1 ; result is zero z=1 n=0 example 3: sublw 02h before instruction w = 03h c=? after instruction w = ffh ; (2?s complement) c = 0 ; result is negative z=0 n=1 subwf subtract w from f syntax: subwf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? (w) dest status affected: n, ov, c, dc, z encoding: 0101 11da ffff ffff description: subtract w from register ?f? (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: subwf reg, 1, 0 before instruction reg = 3 w=2 c=? after instruction reg = 1 w=2 c = 1 ; result is positive z=0 n=0 example 2: subwf reg, 0, 0 before instruction reg = 2 w=2 c=? after instruction reg = 2 w=0 c = 1 ; result is zero z=1 n=0 example 3: subwf reg, 1, 0 before instruction reg = 1 w=2 c=? after instruction reg = ffh ;(2?s complement) w=2 c = 0 ; result is negative z=0 n=1
pic18f46j50 family ds39931b-page 466 preliminary ? 2009 microchip technology inc. subwfb subtract w from f with borrow syntax: subwfb f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? (w) ? (c ) dest status affected: n, ov, c, dc, z encoding: 0101 10da ffff ffff description: subtract w and the carry flag (borrow) from register ?f? (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addr essing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: subwfb reg, 1, 0 before instruction reg = 19h (0001 1001) w=0dh (0000 1101) c=1 after instruction reg = 0ch (0000 1011) w=0dh (0000 1101) c=1 z=0 n = 0 ; result is positive example 2: subwfb reg, 0, 0 before instruction reg = 1bh (0001 1011) w=1ah (0001 1010) c=0 after instruction reg = 1bh (0001 1011) w = 00h c=1 z = 1 ; result is zero n=0 example 3: subwfb reg, 1, 0 before instruction reg = 03h (0000 0011) w=0eh (0000 1101) c=1 after instruction reg = f5h (1111 0100) ; [2?s comp] w=0eh (0000 1101) c=0 z=0 n = 1 ; result is negative swapf swap f syntax: swapf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f<3:0>) dest<7:4>, (f<7:4>) dest<3:0> status affected: none encoding: 0011 10da ffff ffff description: the upper and lower nibbles of register ?f? are exchanged. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: swapf reg, 1, 0 before instruction reg = 53h after instruction reg = 35h
? 2009 microchip technology inc. preliminary ds39931b-page 467 pic18f46j50 family tblrd table read syntax: tblrd ( *; *+; *-; +*) operands: none operation: if tblrd *, (prog mem (tblptr)) tablat, tblptr ? no change; if tblrd *+, (prog mem (tblptr)) tablat, (tblptr) + 1 tblptr; if tblrd *-, (prog mem (tblptr)) tablat, (tblptr) ? 1 tblptr; if tblrd +*, (tblptr) + 1 tblptr, (prog mem (tblptr)) tablat status affected: none encoding: 0000 0000 0000 10nn nn=0 * =1 *+ =2 *- =3 +* description: this instruction is used to read the contents of program memory (p.m.). to address the program memory, a pointer called table pointer (tblptr) is used. the tblptr (a 21-bit pointer) points to each byte in the program memory. tblptr has a 2-mbyte address range. tblptr<0> = 0 : least significant byte of program memory word tblptr<0> = 1 : most significant byte of program memory word the tblrd instruction can modify the value of tblptr as follows: ? no change ? post-increment ? post-decrement ? pre-increment words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation no operation no operation (read program memory) no operation no operation (write tablat) tblrd table read (continued) example 1: tblrd *+ ; before instruction tablat = 55h tblptr = 00a356h memory(00a356h) = 34h after instruction tablat = 34h tblptr = 00a357h example 2: tblrd +* ; before instruction tablat = aah tblptr = 01a357h memory(01a357h) = 12h memory(01a358h) = 34h after instruction tablat = 34h tblptr = 01a358h
pic18f46j50 family ds39931b-page 468 preliminary ? 2009 microchip technology inc. tblwt table write syntax: tblwt ( *; *+; *-; +*) operands: none operation: if tblwt*, (tablat) holding register, tblptr ? no change; if tblwt*+, (tablat) holding register, (tblptr) + 1 tblptr; if tblwt*-, (tablat) holding register, (tblptr) ? 1 tblptr; if tblwt+*, (tblptr) + 1 tblptr, (tablat) holding register status affected: none encoding: 0000 0000 0000 11nn nn=0 * =1 *+ =2 *- =3 +* description: this instruction uses the 3 lsbs of tblptr to determine which of the 8 holding registers the tablat is written to. the holding registers are used to program the contents of program memory (p.m.). (refer to section 5.0 ?memory organization? for additional details on programming flash memory.) the tblptr (a 21-bit pointer) points to each byte in the program memory. tblptr has a 2-mbyte address range. the lsb of the tblptr selects which byte of the program memory location to access. tblptr<0> = 0 : least significant byte of program memory word tblptr<0> = 1 : most significant byte of program memory word the tblwt instruction can modify the value of tblptr as follows: ? no change ? post-increment ? post-decrement ? pre-increment words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation no operation no operation (read tablat) no operation no operation (write to holding register) tblwt table write (continued) example 1: tblwt *+; before instruction tablat = 55h tblptr = 00a356h holding register (00a356h) = ffh after instructions (table write completion) tablat = 55h tblptr = 00a357h holding register (00a356h) = 55h example 2: tblwt +*; before instruction tablat = 34h tblptr = 01389ah holding register (01389ah) = ffh holding register (01389bh) = ffh after instruction (table write completion) tablat = 34h tblptr = 01389bh holding register (01389ah) = ffh holding register (01389bh) = 34h
? 2009 microchip technology inc. preliminary ds39931b-page 469 pic18f46j50 family tstfsz test f, skip if 0 syntax: tstfsz f {,a} operands: 0 f 255 a [0,1] operation: skip if f = 0 status affected: none encoding: 0110 011a ffff ffff description: if ?f? = 0 , the next instruction fetched during the current instruction execution is discarded and a nop is executed, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here tstfsz cnt, 1 nzero : zero : before instruction pc = address (here) after instruction if cnt = 00h, pc = address (zero) if cnt 00h, pc = address (nzero) xorlw exclusive or literal with w syntax: xorlw k operands: 0 k 255 operation: (w) .xor. k w status affected: n, z encoding: 0000 1010 kkkk kkkk description: the contents of w are xored with the 8-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: xorlw 0afh before instruction w=b5h after instruction w=1ah
pic18f46j50 family ds39931b-page 470 preliminary ? 2009 microchip technology inc. xorwf exclusive or w with f syntax: xorwf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) .xor. (f) dest status affected: n, z encoding: 0001 10da ffff ffff description: exclusive or the contents of w with register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in the register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 27.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: xorwf reg, 1, 0 before instruction reg = afh w=b5h after instruction reg = 1ah w=b5h
? 2009 microchip technology inc. preliminary ds39931b-page 471 pic18f46j50 family 27.2 extended instruction set in addition to the standard 75 instructions of the pic18 instruction set, the pic18f46j50 family of devices also provide an optional extension to the core cpu function- ality. the added features include eight additional instructions that augment indirect and indexed addressing operations and the implementation of indexed literal offset addressing for many of the standard pic18 instructions. the additional features of the extended instruction set are enabled by default on unprogrammed devices. users must properly set or clear the xinst configuration bit during programming to enable or disable these features. the instructions in the extended set can all be classified as literal operations, which either manipulate the file select registers (fsr), or use them for indexed addressing. two of the instructions, addfsr and subfsr , each have an additional special instanti- ation for using fsr2. these versions ( addulnk and subulnk ) allow for automatic return after execution. the extended instructions are specifically implemented to optimize re-entrant program code (that is, code that is recursive or that uses a software stack) written in high-level languages, particularly c. among other things, they allow users working in high-level languages to perform certain operations on data structures more efficiently. these include: ? dynamic allocation and deallocation of software stack space when entering and leaving subroutines ? function pointer invocation ? software stack pointer manipulation ? manipulation of variables located in a software stack a summary of the instructions in the extended instruc- tion set is provided in table 27-3. detailed descriptions are provided in section 27.2.2 ?extended instruction set? . the opcode field descriptions in table 27-1 (page 430) apply to both the standard and extended pic18 instruction sets. 27.2.1 extended instruction syntax most of the extended instructions use indexed argu- ments, using one of the fsrs and some offset to specify a source or destination register. when an argument for an instruction serves as part of indexed addressing, it is enclosed in square brackets (?[ ]?). this is done to indi- cate that the argument is used as an index or offset. the mpasm? assembler will flag an error if it determines that an index or offset value is not bracketed. when the extended instruction set is enabled, brackets are also used to indicate index arguments in byte-oriented and bit-oriented instructions. this is in addition to other changes in their syntax. for more details, see section 27.2.3.1 ?extended instruction syntax with standard pic18 commands? . table 27-3: extensions to the pic18 instruction set note: the instruction set extension and the indexed literal offset addressing mode were designed for optimizing applications written in c; the user may likely never use these instructions directly in assembler. the syntax for these commands is provided as a reference for users who may be reviewing code that has been generated by a compiler. note: in the past, square brackets have been used to denote optional arguments in the pic18 and earlier instruction sets. in this text and going forward, optional arguments are denoted by braces (?{ }?). mnemonic, operands description cycles 16-bit instruction word status affected msb lsb addfsr addulnk callw movsf movss pushl subfsr subulnk f, k k z s , f d z s , z d k f, k k add literal to fsr add literal to fsr2 and return call subroutine using wreg move z s (source) to 1st word f d (destination) 2nd word move z s (source) to 1st word z d (destination) 2nd word store literal at fsr2, decrement fsr2 subtract literal from fsr subtract literal from fsr2 and return 1 2 2 2 2 1 1 2 1110 1110 0000 1110 1111 1110 1111 1110 1110 1110 1000 1000 0000 1011 ffff 1011 xxxx 1010 1001 1001 ffkk 11kk 0001 0zzz ffff 1zzz xzzz kkkk ffkk 11kk kkkk kkkk 0100 zzzz ffff zzzz zzzz kkkk kkkk kkkk none none none none ? none ? none ? none none
pic18f46j50 family ds39931b-page 472 preliminary ? 2009 microchip technology inc. 27.2.2 extended instruction set addfsr add literal to fsr syntax: addfsr f, k operands: 0 k 63 f [ 0, 1, 2 ] operation: fsr(f) + k fsr(f) status affected: none encoding: 1110 1000 ffkk kkkk description: the 6-bit literal ?k? is added to the contents of the fsr specified by ?f?. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to fsr example: addfsr 2, 23h before instruction fsr2 = 03ffh after instruction fsr2 = 0422h addulnk add literal to fsr2 and return syntax: addulnk k operands: 0 k 63 operation: fsr2 + k fsr2, (tos) pc status affected: none encoding: 1110 1000 11kk kkkk description: the 6-bit literal ?k? is added to the contents of fsr2. a return is then executed by loading the pc with the tos. the instruction takes two cycles to execute; a nop is performed during the second cycle. this may be thought of as a special case of the addfsr instruction, where f = 3 (binary ? 11 ?); it operates only on fsr2. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to fsr no operation no operation no operation no operation example: addulnk 23h before instruction fsr2 = 03ffh pc = 0100h after instruction fsr2 = 0422h pc = (tos) note: all pic18 instructions may take an optional label argument preceding the instruction mnemonic for use in symbolic addressing. if a label is used, the instruction format then becomes: {label} instruction argument(s).
? 2009 microchip technology inc. preliminary ds39931b-page 473 pic18f46j50 family callw subroutine call using wreg syntax: callw operands: none operation: (pc + 2) tos, (w) pcl, (pclath) pch, (pclatu) pcu status affected: none encoding: 0000 0000 0001 0100 description first, the return address (pc + 2) is pushed onto the return stack. next, the contents of w are written to pcl; the existing value is discarded. then, the contents of pclath and pclatu are latched into pch and pcu, respec- tively. the second cycle is executed as a nop instruction while the new next instruction is fetched. unlike call , there is no option to update w, status or bsr. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read wreg push pc to stack no operation no operation no operation no operation no operation example: here callw before instruction pc = address (here) pclath = 10h pclatu = 00h w = 06h after instruction pc = 001006h tos = address (here + 2) pclath = 10h pclatu = 00h w = 06h movsf move indexed to f syntax: movsf [z s ], f d operands: 0 z s 127 0 f d 4095 operation: ((fsr2) + z s ) f d status affected: none encoding: 1st word (source) 2nd word (destin.) 1110 1111 1011 ffff 0zzz ffff zzzz s ffff d description: the contents of the source register are moved to destination register ?f d ?. the actual address of the source register is determined by adding the 7-bit literal offset ?z s ?, in the first word, to the value of fsr2. the address of the destina- tion register is specified by the 12-bit lit- eral ?f d ? in the second word. both addresses can be anywhere in the 4096-byte data space (000h to fffh). the movsf instruction cannot use the pcl, tosu, tosh or tosl as the destination register. if the resultant source address points to an indirect addressing register, the value returned will be 00h. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode determine source addr determine source addr read source reg decode no operation no dummy read no operation write register ?f? (dest) example: movsf [05h], reg2 before instruction fsr2 = 80h contents of 85h = 33h reg2 = 11h after instruction fsr2 = 80h contents of 85h = 33h reg2 = 33h
pic18f46j50 family ds39931b-page 474 preliminary ? 2009 microchip technology inc. movss move indexed to indexed syntax: movss [z s ], [z d ] operands: 0 z s 127 0 z d 127 operation: ((fsr2) + z s ) ((fsr2) + z d ) status affected: none encoding: 1st word (source) 2nd word (dest.) 1110 1111 1011 xxxx 1zzz xzzz zzzz s zzzz d description the contents of the source register are moved to the destination register. the addresses of the source and destina- tion registers are determined by adding the 7-bit literal offsets ?z s ? or ?z d ?, respectively, to the value of fsr2. both registers can be located anywhere in the 4096-byte data memory space (000h to fffh). the movss instruction cannot use the pcl, tosu, tosh or tosl as the destination register. if the resultant source address points to an indirect addressing register, the value returned will be 00h. if the resultant destination address points to an indirect addressing register, the instruction will execute as a nop . words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode determine source addr determine source addr read source reg decode determine dest addr determine dest addr write to dest reg example: movss [05h], [06h] before instruction fsr2 = 80h contents of 85h = 33h contents of 86h = 11h after instruction fsr2 = 80h contents of 85h = 33h contents of 86h = 33h pushl store literal at fsr2, decrement fsr2 syntax: pushl k operands: 0 k 255 operation: k (fsr2), fsr2 ? 1 fsr2 status affected: none encoding: 1110 1010 kkkk kkkk description: the 8-bit literal ?k? is written to the data memory address specified by fsr2. fsr2 is decremented by 1 after the operation. this instruction allows users to push values onto a software stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read ?k? process data write to destination example: pushl 08h before instruction fsr2h:fsr2l = 01ech memory (01ech) = 00h after instruction fsr2h:fsr2l = 01ebh memory (01ech) = 08h
? 2009 microchip technology inc. preliminary ds39931b-page 475 pic18f46j50 family subfsr subtract literal from fsr syntax: subfsr f, k operands: 0 k 63 f [ 0, 1, 2 ] operation: fsrf ? k fsrf status affected: none encoding: 1110 1001 ffkk kkkk description: the 6-bit literal ?k? is subtracted from the contents of the fsr specified by ?f?. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: subfsr 2, 23h before instruction fsr2 = 03ffh after instruction fsr2 = 03dch subulnk subtract literal from fsr2 and return syntax: subulnk k operands: 0 k 63 operation: fsr2 ? k fsr2, (tos) pc status affected: none encoding: 1110 1001 11kk kkkk description: the 6-bit literal ?k? is subtracted from the contents of the fsr2. a return is then executed by loading the pc with the tos. the instruction takes two cycles to execute; a nop is performed during the second cycle. this may be thought of as a special case of the subfsr instruction, where f = 3 (binary ? 11 ?); it operates only on fsr2. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination no operation no operation no operation no operation example: subulnk 23h before instruction fsr2 = 03ffh pc = 0100h after instruction fsr2 = 03dch pc = (tos)
pic18f46j50 family ds39931b-page 476 preliminary ? 2009 microchip technology inc. 27.2.3 byte-oriented and bit-oriented instructions in indexed literal offset mode in addition to eight new commands in the extended set, enabling the extended instruction set also enables indexed literal offset addressing ( section 5.6.1 ?indexed addressing with literal offset? ). this has a significant impact on the way that many commands of the standard pic18 instruction set are interpreted. when the extended set is disabled, addresses embed- ded in opcodes are treated as literal memory locations: either as a location in the access bank (a = 0 ) or in a gpr bank designated by the bsr (a = 1 ). when the extended instruction set is enabled and a = 0 , however, a file register argument of 5fh or less is interpreted as an offset from the pointer value in fsr2 and not as a literal address. for practical purposes, this means that all instructions that use the access ram bit as an argument ? that is, all byte-oriented and bit-oriented instructions, or almost half of the core pic18 instruc- tions ? may behave differently when the extended instruction set is enabled. when the content of fsr2 is 00h, the boundaries of the access ram are essentially remapped to their original values. this may be useful in creating backward-compatible code. if this technique is used, it may be necessary to save the value of fsr2 and restore it when moving back and forth between c and assembly routines in order to preserve the stack pointer. users must also keep in mind the syntax requirements of the extended instruction set (see section 27.2.3.1 ?extended instruction syntax with standard pic18 commands? ). although the indexed literal offset mode can be very useful for dynamic stack and pointer manipulation, it can also be very annoying if a simple arithmetic opera- tion is carried out on the wrong register. users who are accustomed to the pic18 programming must keep in mind that, when the extended instruction set is enabled, register addresses of 5fh or less are used for indexed literal offset addressing. representative examples of typical byte-oriented and bit-oriented instructions in the indexed literal offset mode are provided on the following page to show how execution is affected. the operand conditions provided in the examples are applicable to all instructions of these types. 27.2.3.1 extended instruction syntax with standard pic18 commands when the extended instruction set is enabled, the file register argument ?f? in the standard byte-oriented and bit-oriented commands is replaced with the literal offset value ?k?. as already noted, this occurs only when ?f? is less than or equal to 5fh. when an offset value is used, it must be indicated by square brackets (?[ ]?). as with the extended instructions, the use of brackets indicates to the compiler that the value is to be interpreted as an index or an offset. omitting the brackets, or using a value greater than 5fh within the brackets, will generate an error in the mpasm assembler. if the index argument is properly bracketed for indexed literal offset addressing, the access ram argument is never specified; it will automatically be assumed to be ? 0 ?. this is in contrast to standard operation (extended instruction set disabled) when ?a? is set on the basis of the target address. declaring the access ram bit in this mode will also generate an error in the mpasm assembler. the destination argument ?d? functions as before. in the latest versions of the mpasm assembler, language support for the extended instruction set must be explicitly invoked. this is done with either the command line option, /y , or the pe directive in the source listing. 27.2.4 considerations when enabling the extended instruction set it is important to note that the extensions to the instruc- tion set may not be beneficial to all users. in particular, users who are not writing code that uses a software stack may not benefit from using the extensions to the instruction set. additionally, the indexed literal offset addressing mode may create issues with legacy applications written to the pic18 assembler. this is because instructions in the legacy code may attempt to address registers in the access bank below 5fh. since these addresses are interpreted as literal offsets to fsr2 when the instruction set extension is enabled, the application may read or write to the wrong data addresses. when porting an application to the pic18f46j50 fam- ily, it is very important to consider the type of code. a large, re-entrant application that is written in c and would benefit from efficient compilation will do well when using the instruction set extensions. legacy applications that heavily use the access bank will most likely not benefit from using the extended instruction set. note: enabling the pic18 instruction set exten- sion may cause legacy applications to behave erratically or fail entirely
? 2009 microchip technology inc. preliminary ds39931b-page 477 pic18f46j50 family addwf add w to indexed (indexed literal offset mode) syntax: addwf [k] {,d} operands: 0 k 95 d [0,1] operation: (w) + ((fsr2) + k) dest status affected: n, ov, c, dc, z encoding: 0010 01d0 kkkk kkkk description: the contents of w are added to the contents of the register indicated by fsr2, offset by the value ?k?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read ?k? process data write to destination example: addwf [ofst] ,0 before instruction w = 17h ofst = 2ch fsr2 = 0a00h contents of 0a2ch = 20h after instruction w = 37h contents of 0a2ch = 20h bsf bit set indexed (indexed literal offset mode) syntax: bsf [k], b operands: 0 f 95 0 b 7 operation: 1 ((fsr2) + k) status affected: none encoding: 1000 bbb0 kkkk kkkk description: bit ?b? of the register indicated by fsr2, offset by the value ?k?, is set. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: bsf [flag_ofst], 7 before instruction flag_ofst = 0ah fsr2 = 0a00h contents of 0a0ah = 55h after instruction contents of 0a0ah = d5h setf set indexed (indexed literal offset mode) syntax: setf [k] operands: 0 k 95 operation: ffh ((fsr2) + k) status affected: none encoding: 0110 1000 kkkk kkkk description: the contents of the register indicated by fsr2, offset by ?k?, are set to ffh. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read ?k? process data write register example: setf [ofst] before instruction ofst = 2ch fsr2 = 0a00h contents of 0a2ch = 00h after instruction contents of 0a2ch = ffh
pic18f46j50 family ds39931b-page 478 preliminary ? 2009 microchip technology inc. 27.2.5 special considerations with microchip mplab ? ide tools the latest versions of microchip?s software tools have been designed to fully support the extended instruction set for the pic18f46j50 family. this includes the mplab c18 c compiler, mpasm assembly language and mplab integrated development environment (ide). when selecting a target device for software development, mplab ide will automatically set default configuration bits for that device. the default setting for the xinst configuration bit is ? 0 ?, disabling the extended instruction set and indexed literal offset addressing. for proper execution of applications developed to take advantage of the extended instruction set, xinst must be set during programming. to develop software for the extended instruction set, the user must enable support for the instructions and the indexed addressing mode in their language tool(s). depending on the environment being used, this may be done in several ways: ? a menu option or dialog box within the environ- ment that allows the user to configure the language tool and its settings for the project ? a command line option ? a directive in the source code these options vary between different compilers, assemblers and development environments. users are encouraged to review the documentation accompany- ing their development systems for the appropriate information.
? 2009 microchip technology inc. preliminary ds39931b-page 479 pic18f46j50 family 28.0 development support the pic ? microcontrollers are supported with a full range of hardware and software development tools: ? integrated development environment - mplab ? ide software ? assemblers/compilers/linkers - mpasm tm assembler - mplab c18 and mplab c30 c compilers -mplink tm object linker/ mplib tm object librarian - mplab asm30 assembler/linker/library ? simulators - mplab sim software simulator ?emulators - mplab ice 2000 in-circuit emulator - mplab real ice? in-circuit emulator ? in-circuit debugger - mplab icd 2 ? device programmers - picstart ? plus development programmer - mplab pm3 device programmer - pickit? 2 development programmer ? low-cost demonstration and development boards and evaluation kits 28.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8/16-bit micro- controller market. the mplab ide is a windows ? operating system-based application that contains: ? a single graphical interface to all debugging tools - simulator - programmer (sold separately) - emulator (sold separately) - in-circuit debugger (sold separately) ? a full-featured editor with color-coded context ? a multiple project manager ? customizable data windows with direct edit of contents ? high-level source code debugging ? visual device initializer for easy register initialization ? mouse over variable inspection ? drag and drop variables from source to watch windows ? extensive on-line help ? integration of select third party tools, such as hi-tech software c compilers and iar c compilers the mplab ide allows you to: ? edit your source files (either assembly or c) ? one touch assemble (or compile) and download to pic mcu emulator and simulator tools (automatically updates all project information) ? debug using: - source files (assembly or c) - mixed assembly and c - machine code mplab ide supports multiple debugging tools in a single development paradigm, from the cost-effective simulators, through low-cost in-circuit debuggers, to full-featured emulators. this eliminates the learning curve when upgrading to tools with increased flexibility and power.
pic18f46j50 family ds39931b-page 480 preliminary ? 2009 microchip technology inc. 28.2 mpasm assembler the mpasm assembler is a full-featured, universal macro assembler for all pic mcus. the mpasm assembler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol reference, absolute lst files that contain source lines and generated machine code and coff files for debugging. the mpasm assembler features include: ? integration into mplab ide projects ? user-defined macros to streamline assembly code ? conditional assembly for multi-purpose source files ? directives that allow complete control over the assembly process 28.3 mplab c18 and mplab c30 c compilers the mplab c18 and mplab c30 code development systems are complete ansi c compilers for microchip?s pic18 and pic24 families of microcon- trollers and the dspic30 and dspic33 family of digital signal controllers. these compilers provide powerful integration capabilities, superior code optimization and ease of use not found with other compilers. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. 28.4 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c18 c compiler. it can link relocatable objects from precompiled libraries, using directives from a linker script. the mplib object librarian manages the creation and modification of library files of precompiled code. when a routine from a library is called from a source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the object linker/library features include: ? efficient linking of single libraries instead of many smaller files ? enhanced code maintainability by grouping related modules together ? flexible creation of libraries with easy module listing, replacement, deletion and extraction 28.5 mplab asm30 assembler, linker and librarian mplab asm30 assembler produces relocatable machine code from symbolic assembly language for dspic30f devices. mplab c30 c compiler uses the assembler to produce its object file. the assembler generates relocatable object files that can then be archived or linked with other relocatable object files and archives to create an executable file. notable features of the assembler include: ? support for the entire dspic30f instruction set ? support for fixed-point and floating-point data ? command line interface ? rich directive set ? flexible macro language ? mplab ide compatibility 28.6 mplab sim software simulator the mplab sim software simulator allows code development in a pc-hosted environment by simulat- ing the pic mcus and dspic ? dscs on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a comprehensive stimulus controller. registers can be logged to files for further run-time analysis. the trace buffer and logic analyzer display extend the power of the simulator to record and track program execution, actions on i/o, most peripherals and internal registers. the mplab sim software simulator fully supports symbolic debugging using the mplab c18 and mplab c30 c compilers, and the mpasm and mplab asm30 assemblers. the software simulator offers the flexibility to develop and debug code outside of the hardware laboratory environment, making it an excellent, economical software development tool.
? 2009 microchip technology inc. preliminary ds39931b-page 481 pic18f46j50 family 28.7 mplab ice 2000 high-performance in-circuit emulator the mplab ice 2000 in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for pic microcontrollers. software control of the mplab ice 2000 in-circuit emulator is advanced by the mplab integrated development environment, which allows editing, building, downloading and source debugging from a single environment. the mplab ice 2000 is a full-featured emulator system with enhanced trace, trigger and data monitor- ing features. interchangeable processor modules allow the system to be easily reconfigured for emulation of different processors. the architecture of the mplab ice 2000 in-circuit emulator allows expansion to support new pic microcontrollers. the mplab ice 2000 in-circuit emulator system has been designed as a real-time emulation system with advanced features that are typically found on more expensive development tools. the pc platform and microsoft ? windows ? 32-bit operating system were chosen to best make these features available in a simple, unified application. 28.8 mplab real ice in-circuit emulator system mplab real ice in-circuit emulator system is microchip?s next generation high-speed emulator for microchip flash dsc and mcu devices. it debugs and programs pic ? flash mcus and dspic ? flash dscs with the easy-to-use, powerful graphical user interface of the mplab integrated development environment (ide), included with each kit. the mplab real ice probe is connected to the design engineer?s pc using a high-speed usb 2.0 interface and is connected to the target with either a connector compatible with the popular mplab icd 2 system (rj11) or with the new high-speed, noise tolerant, low- voltage differential signal (lvds) interconnection (cat5). mplab real ice is field upgradeable through future firmware downloads in mplab ide. in upcoming releases of mplab ide, new devices will be supported, and new features will be added, such as software break- points and assembly code trace. mplab real ice offers significant advantages over competitive emulators including low-cost, full-speed emulation, real-time variable watches, trace analysis, complex breakpoints, a ruggedized probe interface and long (up to three meters) interconnection cables. 28.9 mplab icd 2 in-circuit debugger microchip?s in-circuit debugger, mplab icd 2, is a powerful, low-cost, run-time development tool, connecting to the host pc via an rs-232 or high-speed usb interface. this tool is based on the flash pic mcus and can be used to develop for these and other pic mcus and dspic dscs. the mplab icd 2 utilizes the in-circuit debugging capability built into the flash devices. this feature, along with microchip?s in-circuit serial programming tm (icsp tm ) protocol, offers cost- effective, in-circuit flash debugging from the graphical user interface of the mplab integrated development environment. this enables a designer to develop and debug source code by setting breakpoints, single step- ping and watching variables, and cpu status and peripheral registers. running at full speed enables testing hardware and applications in real time. mplab icd 2 also serves as a development programmer for selected pic devices. 28.10 mplab pm3 device programmer the mplab pm3 device programmer is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features a large lcd display (128 x 64) for menus and error messages and a modu- lar, detachable socket assembly to support various package types. the icsp? cable assembly is included as a standard item. in stand-alone mode, the mplab pm3 device programmer can read, verify and program pic devices without a pc connection. it can also set code protection in this mode. the mplab pm3 connects to the host pc via an rs-232 or usb cable. the mplab pm3 has high-speed communications and optimized algorithms for quick programming of large memory devices and incorporates an sd/mmc card for file storage and secure data applications.
pic18f46j50 family ds39931b-page 482 preliminary ? 2009 microchip technology inc. 28.11 picstart plus development programmer the picstart plus development programmer is an easy-to-use, low-cost, prototype programmer. it connects to the pc via a com (rs-232) port. mplab integrated development environment software makes using the programmer simple and efficient. the picstart plus development programmer supports most pic devices in dip packages up to 40 pins. larger pin count devices, such as the pic16c92x and pic17c76x, may be supported with an adapter socket. the picstart plus development programmer is ce compliant. 28.12 pickit 2 development programmer the pickit? 2 development programmer is a low-cost programmer and selected flash device debugger with an easy-to-use interface for programming many of microchip?s baseline, mid-range and pic18f families of flash memory microcontrollers. the pickit 2 starter kit includes a prototyping development board, twelve sequential lessons, software and hi-tech?s picc? lite c compiler, and is designed to help get up to speed quickly using pic ? microcontrollers. the kit provides everything needed to program, evaluate and develop applications using microchip?s powerful, mid-range flash memory family of microcontrollers. 28.13 demonstration, development and evaluation boards a wide variety of demonstration, development and evaluation boards for various pic mcus and dspic dscs allows quick application development on fully func- tional systems. most boards include prototyping areas for adding custom circuitry and provide application firmware and source code for examination and modification. the boards support a variety of features, including leds, temperature sensors, switches, speakers, rs-232 interfaces, lcd displays, potentiometers and additional eeprom memory. the demonstration and development boards can be used in teaching environments, for prototyping custom circuits and for learning about various microcontroller applications. in addition to the picdem? and dspicdem? demon- stration/development board series of circuits, microchip has a line of evaluation kits and demonstration software for analog filter design, k ee l oq ? security ics, can, irda ? , powersmart battery management, seeval ? evaluation system, sigma-delta adc, flow rate sensing, plus many more. check the microchip web page (www.microchip.com) for the complete list of demonstration, development and evaluation kits.
? 2009 microchip technology inc. preliminary ds39931b-page 483 pic18f46j50 family 29.0 electrical characteristics absolute maximum ratings (?) ambient temperature under bias................................................................................................. ............-40c to +125c storage temperature ............................................................................................................ .................. -65c to +150c voltage on any digital only i/o pin or mclr with respect to v ss (except v dd ) ........................................... -0.3v to 6.0v voltage on any combined digital and analog pin with respect to v ss (except v dd )........................ -0.3v to (v dd + 0.3v) voltage on v ddcore with respect to v ss ................................................................................................... -0.3v to 2.75v voltage on v dd with respect to v ss ........................................................................................................... -0.3v to 4.0v voltage on v usb with respect to v ss ................................................................................................ (v dd ? 0.3v) to 4.0v total power dissipation (note 1) ............................................................................................................................... 1.0w maximum current out of v ss pin ........................................................................................................................... 300 ma maximum current into v dd pin ........................................................................................................................... ...250 ma maximum output current sunk by any portb, portc and ra6 i/o pin...............................................................2 5ma maximum output current sunk by any porta (except ra6), portd and porte i/o pin......................................4 ma maximum output current sourced by any portb, portc and ra6 i/o pin .........................................................25 ma maximum output current sourced by any porta (except ra6), portd and porte i/o pin ................................4 ma maximum current sunk by all ports ...................................................................................................................... .200 ma maximum current sourced by all ports ........................................................................................... .......................200 ma note 1: power dissipation is calculated as follows: p dis = v dd x {i dd ? i oh } + {(v dd ? v oh ) x i oh } + (v ol x i ol ) ? notice: stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure to maximum rating conditions for extended periods may affect device reliability.
pic18f46j50 family ds39931b-page 484 preliminary ? 2009 microchip technology inc. figure 29-1: pic18f46j50 family v dd frequency graph (industrial) figure 29-2: pic18lf46j50 family v ddcore frequency graph (industrial) (1) 0 note 1: when the usb module is enabled, v usb should be provided 3.0v-3.6v while v dd must be 2.35v. when the usb module is not enabled, the wider limits shaded in grey apply. v usb should be maintained v dd , but may optionally be high-impedance when the usb module is not in use. frequency voltage (v dd ) 4.0v 2.15v 48 mhz 3.5v 3.0v 2.5v 3.6v 8 mhz pic18f46j50 family valid operating range 2.35v (1) frequency voltage (v ddcore ) 3.00v 2.00v 48 mhz 2.75v 2.50v 2.25v 2.75v 8 mhz 2.35v (2) note 1: v dd and v ddcore must be maintained so that v ddcore v dd . 2: when the usb module is enabled, v usb should be provided 3.0v-3.6v while v ddcore must be 2.35v. when the usb module is not enabled, the wi der limits shaded in grey apply. v usb should be maintained v dd , but may optionally be high-impedance when the usb module is not in use. 0 pic18lf46j50 family valid operating range
? 2009 microchip technology inc. preliminary ds39931b-page 485 pic18f46j50 family 29.1 dc characteristics: supply voltage pic18f46j50 family (industrial) pic18f46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. symbol characteristic min typ max units conditions d001 v dd supply voltage 2.15 ? 3.6 v pic18f4xj50, pic18f2xj50 d001a v dd supply voltage 2.0 ? 3.6 v pic18lf4xj50, pic18lf2xj50 d001b v ddcore external supply for microcontroller core 2.0 ? 2.75 v pic18lf4xj50, pic18lf2xj50 d001c av dd analog supply voltage v dd ? 0.3 ? v dd + 0.3 v d001d av ss analog ground potential v ss ? 0.3 ? v ss + 0.3 v d001e v usb usb supply voltage 3.0 3.3 3.6 v usb module enabled (2) d002 v dr ram data retention voltage (1) 1.5 ? ? v d003 v por v dd start voltage to ensure internal power-on reset signal ? ? 0.7 v see section 4.3 ?power-on reset (por)? for details d004 s vdd v dd rise rate to ensure internal power-on reset signal 0.05 ? ? v/ms see section 4.3 ?power-on reset (por)? for details d005 v bor v ddcore brown-out reset voltage ? 2.0 ? v pic18f4xj50, pic18f2xj50 only d006 v dsbor v dd brown-out reset voltage ? 1.8 ? v dsboren = 1 on ?lf? device or ?f? device in deep sleep note 1: this is the limit to which v ddcore can be lowered in sleep mode, or during a device reset, without losing ram data. 2: v usb should always be maintained v dd , but may be left floating when the usb module is disabled and rc4/rc5 will not be used as general purpose inputs.
pic18f46j50 family ds39931b-page 486 preliminary ? 2009 microchip technology inc. 29.2 dc characteristics: power-down and supply current pic18f46j50 family (industrial) pic18lf46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions power-down current (i pd ) (1) ? sleep mode pic18lfxxj50 0.01 1.4 a -40c v dd = 2.0v, v ddcore = 2.0v sleep mode, regslp = 1 0.06 1.4 a +25c 0.52 6.0 a +60c 1.8 10.2 a +85c pic18lfxxj50 0.035 1.5 a -40c v dd = 2.5v, v ddcore = 2.5v 0.13 1.5 a +25c 0.63 8.0 a +60c 2.2 12.6 a +85c pic18fxxj50 2.4 5.0 a -40c v dd = 2.15v vddcore = 10 f capacitor 3.0 5.0 a +25c 3.8 8.0 a +60c 5.6 16 a +85c pic18fxxj50 3.5 7.0 a -40c v dd = 3.3v vddcore = 10 f capacitor 3.2 7.0 a +25c 4.2 10 a +60c 6.4 19 a +85c power-down current (i pd ) (1) ? deep sleep mode pic18fxxj50 1 25 na -40c v dd = 2.15v, v ddcore = 10 f capacitor deep sleep mode 15 100 na +25c 115 250 na +60c 0.46 1.0 a +85c pic18fxxj50 3 50 na -40c v dd = 3.3v, v ddcore = 10 f capacitor 33 150 na +25c 191 389 na +60c 0.65 2.0 a +85c note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. all features that add delta current are disabled (usb module, wdt, etc.). the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd /v ss ; mclr = v dd ; wdt disabled unless otherwise specified. 3: low-power timer1 with standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: this is the module differential current when the usb module is enabled and clocked at 48 mhz, but with no usb cable attached. when the usb cable is attached or data is being transmitted, the current consumption may be much higher (see section 21.6.4 ?usb transceiver current consumption? ). during usb suspend mode (usben = 1 , suspnd = 1 , bus in idle state), the usb module current will be dominated by the d+ or d- pull-up resistor. the integrated pull-up resistors use ?resistor switching? according to the resistor_ecn supplement to the usb 2.0 specifications, and therefore, may be as low as 900 during idle conditions.
? 2009 microchip technology inc. preliminary ds39931b-page 487 pic18f46j50 family supply current (i dd ) (2) pic18lfxxj50 5.3 14.2 a -40c v dd = 2.0v, v ddcore = 2.0v f osc = 31 khz ( rc_run mode, internal rc oscillator, intsrc = 0 ) 6.2 14.2 a +25c 8.5 19.0 a +85c pic18lfxxj50 8.0 16.5 a -40c v dd = 2.5v, v ddcore = 2.5v 8.7 16.5 a +25c 11.3 22.4 a +85c pic18fxxj50 37 77 a -40c v dd = 2.15v v ddcore = 10 f capacitor 48 77 a +25c 60 93 a +85c pic18fxxj50 45 84 a -40c v dd = 3.3v v ddcore = 10 f capacitor 54 84 a +25c 65 108 a +85c pic18lfxxj50 1.1 1.5 ma -40c v dd = 2.0v, v ddcore = 2.0 f osc = 4 mhz, rc_run mode, internal rc oscillator 1.1 1.5 ma +25c 1.2 1.6 ma +85c pic18lfxxj50 1.5 1.7 ma -40c v dd = 2.5v, v ddcore = 2.5v 1.6 1.7 ma +25c 1.6 1.9 ma +85c pic18fxxj50 1.3 2.6 ma -40c v dd = 2.15v, v ddcore = 10 f 1.4 2.6 ma +25c 1.4 2.8 ma +85c pic18fxxj50 1.6 2.9 ma -40c v dd = 3.3v, v ddcore = 10 f 1.6 2.9 ma +25c 1.6 3.0 ma +85c 29.2 dc characteristics: power-down and supply current pic18f46j50 family (industrial) (continued) pic18lf46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. all features that add delta current are disabled (usb module, wdt, etc.). the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd /v ss ; mclr = v dd ; wdt disabled unless otherwise specified. 3: low-power timer1 with standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: this is the module differential current when the usb module is enabled and clocked at 48 mhz, but with no usb cable attached. when the usb cable is attached or data is being transmitted, the current consumption may be much higher (see section 21.6.4 ?usb transceiver current consumption? ). during usb suspend mode (usben = 1 , suspnd = 1 , bus in idle state), the usb module current will be dominated by the d+ or d- pull-up resistor. the integrated pull-up resistors use ?resistor switching? according to the resistor_ecn supplement to the usb 2.0 specifications, and therefore, may be as low as 900 during idle conditions.
pic18f46j50 family ds39931b-page 488 preliminary ? 2009 microchip technology inc. supply current (i dd ) (2) pic18lfxxj50 1.9 3.6 ma -40c v dd = 2.0v, v ddcore = 2.0v f osc = 8 mhz, rc_run mode, internal rc oscillator 2.0 3.8 ma +25c 2.0 3.8 ma +85c pic18lfxxj50 2.8 4.8 ma -40c v dd = 2.5v, v ddcore = 2.5v 2.8 4.8 ma +25c 2.8 4.9 ma +85c pic18fxxj50 2.3 4.2 ma -40c v dd = 2.15v, v ddcore = 10 f 2.3 4.2 ma +25c 2.4 4.5 ma +85c pic18fxxj50 2.8 5.1 ma -40c v dd = 3.3v, v ddcore = 10 f 2.8 5.1 ma +25c 2.8 5.4 ma +85c pic18lfxxj50 1.9 9.4 a -40c v dd = 2.0v, v ddcore = 2.0v f osc = 31 khz, rc_idle mode, internal rc oscillator, intsrc = 0 2.3 9.4 a +25c 4.5 17.2 a +85c pic18lfxxj50 2.4 10.5 a -40c v dd = 2.5v, v ddcore = 2.5v 2.8 10.5 a +25c 5.4 19.5 a +85c pic18fxxj50 33.3 75 a -40c v dd = 2.15v, v ddcore = 10 f 43.8 75 a +25c 55.3 92 a +85c pic18fxxj50 36.1 82 a -40c v dd = 3.3v, v ddcore = 10 f 44.5 82 a +25c 56.3 105 a +85c 29.2 dc characteristics: power-down and supply current pic18f46j50 family (industrial) (continued) pic18lf46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. all features that add delta current are disabled (usb module, wdt, etc.). the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd /v ss ; mclr = v dd ; wdt disabled unless otherwise specified. 3: low-power timer1 with standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: this is the module differential current when the usb module is enabled and clocked at 48 mhz, but with no usb cable attached. when the usb cable is attached or data is being transmitted, the current consumption may be much higher (see section 21.6.4 ?usb transceiver current consumption? ). during usb suspend mode (usben = 1 , suspnd = 1 , bus in idle state), the usb module current will be dominated by the d+ or d- pull-up resistor. the integrated pull-up resistors use ?resistor switching? according to the resistor_ecn supplement to the usb 2.0 specifications, and therefore, may be as low as 900 during idle conditions.
? 2009 microchip technology inc. preliminary ds39931b-page 489 pic18f46j50 family supply current (i dd ) (2) pic18lfxxj50 0.531 0.980 ma -40c v dd = 2.0v, v ddcore = 2.0v f osc = 4 mhz, rc_idle mode, internal rc oscillator 0.571 0.980 ma +25c 0.608 1.12 ma +85c pic18lfxxj50 0.625 1.14 ma -40c v dd = 2.5v, v ddcore = 2.5v 0.681 1.14 ma +25c 0.725 1.25 ma +85c pic18fxxj50 0.613 1.21 ma -40c v dd = 2.15v, v ddcore = 10 f 0.680 1.21 ma +25c 0.730 1.30 ma +85c pic18fxxj50 0.673 1.27 ma -40c v dd = 3.3v, v ddcore = 10 f 0.728 1.27 ma +25c 0.779 1.45 ma +85c pic18lfxxj50 0.750 1.4 ma -40c v dd = 2.0v, v ddcore = 2.0v f osc = 8 mhz, rc_idle mode, internal rc oscillator 0.797 1.5 ma +25c 0.839 1.6 ma +85c pic18lfxxj50 0.91 2.4 ma -40c v dd = 2.5v, v ddcore = 2.5v 0.96 2.4 ma +25c 1.01 2.5 ma +85c pic18fxxj50 0.87 2.1 ma -40c v dd = 2.15v, v ddcore = 10 f 0.93 2.1 ma +25c 0.98 2.3 ma +85c pic18fxxj50 0.95 2.6 ma -40c v dd = 3.3v, v ddcore = 10 f 1.01 2.6 ma +25c 1.06 2.7 ma +85c 29.2 dc characteristics: power-down and supply current pic18f46j50 family (industrial) (continued) pic18lf46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. all features that add delta current are disabled (usb module, wdt, etc.). the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd /v ss ; mclr = v dd ; wdt disabled unless otherwise specified. 3: low-power timer1 with standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: this is the module differential current when the usb module is enabled and clocked at 48 mhz, but with no usb cable attached. when the usb cable is attached or data is being transmitted, the current consumption may be much higher (see section 21.6.4 ?usb transceiver current consumption? ). during usb suspend mode (usben = 1 , suspnd = 1 , bus in idle state), the usb module current will be dominated by the d+ or d- pull-up resistor. the integrated pull-up resistors use ?resistor switching? according to the resistor_ecn supplement to the usb 2.0 specifications, and therefore, may be as low as 900 during idle conditions.
pic18f46j50 family ds39931b-page 490 preliminary ? 2009 microchip technology inc. supply current (i dd ) (2) pic18lfxxj50 0.879 1.25 ma -40c v dd = 2.0v, v ddcore = 2.0v f osc = 4 mhz, pri_run mode, ec oscillator 0.881 1.25 ma +25c 0.891 1.36 ma +85c pic18lfxxj50 1.35 1.70 ma -40c v dd = 2.5v, v ddcore = 2.5v 1.30 1.70 ma +25c 1.27 1.82 ma +85c pic18fxxj50 1.09 1.60 ma -40c v dd = 2.15v, v ddcore = 10 f 1.09 1.60 ma +25c 1.11 1.70 ma +85c pic18fxxj50 1.36 1.95 ma -40c v dd = 3.3v, v ddcore = 10 f 1.36 1.89 ma +25c 1.41 1.92 ma +85c pic18lfxxj50 10.9 14.8 ma -40c v dd = 2.5v, v ddcore = 2.5v f osc = 48 mhz, pri_run mode, ec oscillator 10.6 14.8 ma +25c 10.6 15.2 ma +85c pic18fxxj50 12.9 23.2 ma -40c v dd = 3.3v, v ddcore = 10 f 12.8 22.7 ma +25c 12.7 22.7 ma +85c 29.2 dc characteristics: power-down and supply current pic18f46j50 family (industrial) (continued) pic18lf46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. all features that add delta current are disabled (usb module, wdt, etc.). the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd /v ss ; mclr = v dd ; wdt disabled unless otherwise specified. 3: low-power timer1 with standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: this is the module differential current when the usb module is enabled and clocked at 48 mhz, but with no usb cable attached. when the usb cable is attached or data is being transmitted, the current consumption may be much higher (see section 21.6.4 ?usb transceiver current consumption? ). during usb suspend mode (usben = 1 , suspnd = 1 , bus in idle state), the usb module current will be dominated by the d+ or d- pull-up resistor. the integrated pull-up resistors use ?resistor switching? according to the resistor_ecn supplement to the usb 2.0 specifications, and therefore, may be as low as 900 during idle conditions.
? 2009 microchip technology inc. preliminary ds39931b-page 491 pic18f46j50 family pic18lfxxj50 0.28 0.70 ma -40c v dd = 2.0v, v ddcore = 2.0v f osc = 4 mhz pri_idle mode, ec oscillator 0.30 0.70 ma +25c 0.34 0.75 ma +85c pic18lfxxj50 0.37 1.0 ma -40c v dd = 2.5v, v ddcore = 2.5v 0.40 1.0 ma +25c 0.50 1.1 ma +85c pic18fxxj50 0.36 0.85 ma -40c v dd = 2.15v, v ddcore = 10 f capacitor 0.38 0.85 ma +25c 0.41 0.90 ma +85c pic18fxxj50 0.45 1.3 ma -40c v dd = 3.3v, v ddcore = 10 f capacitor 0.48 1.2 ma +25c 0.55 1.2 ma +85c pic18lfxxj50 4.5 6.5 ma -40c v dd = 2.5v, v ddcore = 2.5v f osc = 48 mhz pri_idle mode, ec oscillator 4.5 6.5 ma +25c 4.6 6.5 ma +85c pic18fxxj50 4.8 12.4 ma -40c v dd = 3.3v, v ddcore = 10 f capacitor 4.9 11.5 ma +25c 5.1 11.5 ma +85c 29.2 dc characteristics: power-down and supply current pic18f46j50 family (industrial) (continued) pic18lf46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. all features that add delta current are disabled (usb module, wdt, etc.). the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd /v ss ; mclr = v dd ; wdt disabled unless otherwise specified. 3: low-power timer1 with standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: this is the module differential current when the usb module is enabled and clocked at 48 mhz, but with no usb cable attached. when the usb cable is attached or data is being transmitted, the current consumption may be much higher (see section 21.6.4 ?usb transceiver current consumption? ). during usb suspend mode (usben = 1 , suspnd = 1 , bus in idle state), the usb module current will be dominated by the d+ or d- pull-up resistor. the integrated pull-up resistors use ?resistor switching? according to the resistor_ecn supplement to the usb 2.0 specifications, and therefore, may be as low as 900 during idle conditions.
pic18f46j50 family ds39931b-page 492 preliminary ? 2009 microchip technology inc. pic18lfxxj50 8.2 11 ma -40c v dd = 2.5v, v ddcore = 2.5v f osc = 24 mhz pri_run mode, ecpll oscillator (4 mhz input) 8.1 11 ma +25c 8.0 10 ma +85c pic18fxxj50 8.1 15 ma -40c v dd = 3.3v, v ddcore = 10 f capacitor 8.1 14 ma +25c 8.1 14 ma +85c pic18lfxxj50 12 14 ma -40c v dd = 2.5v, v ddcore = 2.5v f osc = 48 mhz pri_run mode, ecpll oscillator (4 mhz input) 12 14 ma +25c 11 14 ma +85c pic18fxxj50 14 24 ma -40c v dd = 3.3v, v ddcore = 10 f capacitor 14 23 ma +25c 14 23 ma +85c 29.2 dc characteristics: power-down and supply current pic18f46j50 family (industrial) (continued) pic18lf46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. all features that add delta current are disabled (usb module, wdt, etc.). the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd /v ss ; mclr = v dd ; wdt disabled unless otherwise specified. 3: low-power timer1 with standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: this is the module differential current when the usb module is enabled and clocked at 48 mhz, but with no usb cable attached. when the usb cable is attached or data is being transmitted, the current consumption may be much higher (see section 21.6.4 ?usb transceiver current consumption? ). during usb suspend mode (usben = 1 , suspnd = 1 , bus in idle state), the usb module current will be dominated by the d+ or d- pull-up resistor. the integrated pull-up resistors use ?resistor switching? according to the resistor_ecn supplement to the usb 2.0 specifications, and therefore, may be as low as 900 during idle conditions.
? 2009 microchip technology inc. preliminary ds39931b-page 493 pic18f46j50 family pic18lfxxj50 9.9 45 a -40c v dd = 2.5v, v ddcore = 2.5v f osc = 32 khz (3) sec_run mode, lpt1osc = 0 11 45 a +25c 13 61 a +85c pic18fxxj50 39 95 a -40c v dd = 2.15v, v ddcore = 10 f capacitor 50 95 a +25c 57 105 a +85c pic18fxxj50 42 110 a -40c v dd = 3.3v, v ddcore = 10 f capacitor 54 110 a +25c 57 150 a +85c pic18lfxxj50 3.5 31 a -40c v dd = 2.5v, v ddcore = 2.5v f osc = 32 khz (3) sec_idle mode, lpt1osc = 0 3.8 31 a +25c 4.3 50 a +85c pic18fxxj50 34 87 a -40c v dd = 2.15v, v ddcore = 10 f capacitor 45 89 a +25c 56 97 a +85c pic18fxxj50 35 100 a -40c v dd = 3.3v, v ddcore = 10 f capacitor 46 100 a +25c 56 140 a +85c 29.2 dc characteristics: power-down and supply current pic18f46j50 family (industrial) (continued) pic18lf46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. all features that add delta current are disabled (usb module, wdt, etc.). the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd /v ss ; mclr = v dd ; wdt disabled unless otherwise specified. 3: low-power timer1 with standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: this is the module differential current when the usb module is enabled and clocked at 48 mhz, but with no usb cable attached. when the usb cable is attached or data is being transmitted, the current consumption may be much higher (see section 21.6.4 ?usb transceiver current consumption? ). during usb suspend mode (usben = 1 , suspnd = 1 , bus in idle state), the usb module current will be dominated by the d+ or d- pull-up resistor. the integrated pull-up resistors use ?resistor switching? according to the resistor_ecn supplement to the usb 2.0 specifications, and therefore, may be as low as 900 during idle conditions.
pic18f46j50 family ds39931b-page 494 preliminary ? 2009 microchip technology inc. d022 ( i wdt ) module differential currents ( i wdt , i hlvd , i oscb , i ad , i usb ) watchdog timer 0.84 8.0 a -40c v dd = 2.5v, v ddcore = 2.5v pic18lfxxj50 0.96 8.0 a +25c 0.97 10.4 a +85c 0.65 7.0 a -40c v dd = 2.15v, v ddcore = 10 f capacitor pic18fxxj50 0.78 7.0 a +25c 0.77 10 a +85c 1.3 12.1 a -40c v dd = 3.3v, v ddcore = 10 f capacitor 1.3 12.1 a +25c 1.3 13.6 a +85c d022b ( i hlvd ) high/low-voltage detect 3.9 8.0 a -40c v dd = 2.5v, v ddcore = 2.5v pic18lfxxj50 4.7 8.0 a +25c 5.4 9.0 a +85c 2.6 6.0 a -40c v dd = 2.15v, v ddcore = 10 f capacitor pic18fxxj50 3.1 6.0 a +25c 3.5 8.0 a +85c 3.5 9.0 a -40c v dd = 3.3v, v ddcore = 10 f capacitor 4.1 9.0 a +25c 4.5 12 a +85c d025 ( i oscb ) real-time clock/calendar with low-power timer1 oscillator 0.80 4.0 a -40c v dd = 2.15v, v ddcore = 10 f capacitor pic18fxxj50 32.768 khz (3) , t1oscen = 1 , lpt1osc = 0 0.83 4.5 a +25c 0.95 4.5 a +60c 1.2 4.5 a +85c 0.75 4.5 a -40c v dd = 2.5v, v ddcore = 10 f capacitor 0.92 5.0 a +25c 1.1 5.0 a +60c 1.1 5.0 a +85c 0.95 6.5 a -40c v dd = 3.3v, v ddcore = 10 f capacitor 1.1 6.5 a +25c 1.2 8.0 a +60c 1.4 8.0 a +85c 29.2 dc characteristics: power-down and supply current pic18f46j50 family (industrial) (continued) pic18lf46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. all features that add delta current are disabled (usb module, wdt, etc.). the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd /v ss ; mclr = v dd ; wdt disabled unless otherwise specified. 3: low-power timer1 with standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: this is the module differential current when the usb module is enabled and clocked at 48 mhz, but with no usb cable attached. when the usb cable is attached or data is being transmitted, the current consumption may be much higher (see section 21.6.4 ?usb transceiver current consumption? ). during usb suspend mode (usben = 1 , suspnd = 1 , bus in idle state), the usb module current will be dominated by the d+ or d- pull-up resistor. the integrated pull-up resistors use ?resistor switching? according to the resistor_ecn supplement to the usb 2.0 specifications, and therefore, may be as low as 900 during idle conditions.
? 2009 microchip technology inc. preliminary ds39931b-page 495 pic18f46j50 family d026 ( i ad ) module differential currents ( i wdt , i hlvd , i oscb , i ad , i usb ) a/d converter 3.0 10 a -40c v dd = 2.5v, v ddcore = 2.5v pic18lfxxj50 a/d on, not converting 3.0 10 a +25c 3.0 10 a +85c 3.0 10 a -40c v dd = 2.15v, v ddcore = 10 f capacitor pic18fxxj50 a/d on, not converting 3.0 10 a +25c 3.0 10 a +85c 3.2 11 a -40c v dd = 3.3v, v ddcore = 10 f capacitor 3.2 11 a +25c 3.2 11 a +85c d027 ( i usb ) usb module 1.6 3.2 ma -40c v dd and v usb = 3.3v, v ddcore = 10 f capacitor pic18fxxj50 usb enabled, no cable connected. (4) traffic makes a difference, see section 21.6.4 ?usb transceiver current consumption? 1.6 3.2 ma +25c 1.5 3.2 ma +85c 29.2 dc characteristics: power-down and supply current pic18f46j50 family (industrial) (continued) pic18lf46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f46j50 family standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. all features that add delta current are disabled (usb module, wdt, etc.). the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd /v ss ; mclr = v dd ; wdt disabled unless otherwise specified. 3: low-power timer1 with standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: this is the module differential current when the usb module is enabled and clocked at 48 mhz, but with no usb cable attached. when the usb cable is attached or data is being transmitted, the current consumption may be much higher (see section 21.6.4 ?usb transceiver current consumption? ). during usb suspend mode (usben = 1 , suspnd = 1 , bus in idle state), the usb module current will be dominated by the d+ or d- pull-up resistor. the integrated pull-up resistors use ?resistor switching? according to the resistor_ecn supplement to the usb 2.0 specifications, and therefore, may be as low as 900 during idle conditions.
pic18f46j50 family ds39931b-page 496 preliminary ? 2009 microchip technology inc. 29.3 dc characteristics:pic18f46j50 family (industrial) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. symbol characteristic min max units conditions v il input low voltage all i/o ports: d030 with ttl buffer (4) v ss 0.15 v dd vv dd < 3.3v d030a with ttl buffer (4) v ss 0.8 v 3.3v < v dd < 3.6v d031 with schmitt trigger buffer v ss 0.2 v dd v d032 mclr v ss 0.2 v dd v d033 osc1 v ss 0.3 v dd v hs, hspll modes d033a d034 osc1 t1osi v ss v ss 0.2 v dd 0.3 v v ec, ecpll modes t1oscen = 1 v ih input high voltage i/o ports without 5.5v to le r an c e: d040 with ttl buffer (4) 0.25 v dd + 0.8v v dd vv dd < 3.3v d040a with ttl buffer (4) 2.0 v dd v3.3v < v dd < 3.6v d041 with schmitt trigger buffer 0.8 v dd v dd v i/o ports with 5.5v tolerance: (5) dxxx with ttl buffer 0.25 v dd + 0.8v 5.5 v v dd < 3.3v dxxxa 2.0 5.5 v 3.3v v dd 3.6v dxxx with schmitt trigger buffer 0.8 v dd 5.5 v d042 mclr 0.8 v dd 5.5 v d043 osc1 0.7 v dd v dd v hs, hspll modes d043a d044 osc1 t1osi 0.8 v dd 1.6 v dd v dd v v ec, ecpll modes t1oscen = 1 i il input leakage current (1,2) d060 i/o ports ? 0.2 av ss v pin v dd , pin at high-impedance d061 mclr ?0.2 a vss v pin v dd d063 osc1 ? 0.2 a vss v pin v dd i pu weak pull-up current d070 i purb portb, portd (3) and porte (3) weak pull-up current 80 400 av dd = 3.3v, v pin = v ss note 1: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 2: negative current is defined as current sourced by the pin. 3: only available in 44-pin devices. 4: when used as general purpose inputs, the rc4 and rc5 thresholds are referenced to v usb instead of v dd . 5: refer to table 9-2 for pin tolerance levels.
? 2009 microchip technology inc. preliminary ds39931b-page 497 pic18f46j50 family v ol output low voltage d080 i/o ports: porta (except ra6), portd, porte ?0.4vi ol = 2 ma, v dd = 3.3v, -40 c to +85 c portb, portc, ra6 ? 0.4 v i ol = 8.5 ma, v dd = 3.3v, -40 c to +85 c v oh output high voltage d090 i/o ports: v porta (except ra6), portd, porte 2.4 ? v i oh = -2 ma, v dd = 3.3v, -40 c to +85 c portb, portc, ra6 2.4 ? v i oh = -6 ma, v dd = 3.3v, -40 c to +85 c capacitive loading specs on output pins d101 c io all i/o pins and osc2 ? 50 pf to meet the ac timing specifications d102 c b sclx, sdax ? 400 pf i 2 c? specification 29.3 dc characteristics:pic18f46j50 family (industrial) (continued) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. symbol characteristic min max units conditions note 1: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 2: negative current is defined as current sourced by the pin. 3: only available in 44-pin devices. 4: when used as general purpose inputs, the rc4 and rc5 thresholds are referenced to v usb instead of v dd . 5: refer to table 9-2 for pin tolerance levels.
pic18f46j50 family ds39931b-page 498 preliminary ? 2009 microchip technology inc. table 29-1: memory programming requirements table 29-2: comparator specifications table 29-3: voltage reference specifications dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. sym characteristic min typ? max units conditions program flash memory d130 e p cell endurance 10k ? ? e/w -40 c to +85 c d131 v pr v dd core for read v min ?2.75vv min = minimum operating voltage d132b v pew v ddcore for self-timed erase or write 2.25 ? 2.75 v d133a t iw self-timed write cycle time ? 2.8 ? ms 64 bytes d133b t ie self-timed block erase cycle time ?33.0?ms d134 t retd characteristic retention 20 ? ? year provided no other specifications are violated d135 i ddp supply current during programming ?3?ma ? data in ?typ? column is at 3.3v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. operating conditions: 3.0v < v dd < 3.6v, -40c < t a < +85c (unless otherwise stated) param no. sym characteristics min typ max units comments d300 v ioff input offset voltage ? +/-5 +/-25 mv d301 v icm input common mode voltage 0 ? v dd v v irv internal reference voltage 0.57 0.60 0.63 v d302 cmrr common mode rejection ratio 55 ? ? db 300 t resp response time (1) ?150400 ns 301 t mc 2 ov comparator mode change to output valid ?? 10 s note 1: response time measured with one comparator input at v dd /2, while the other input transitions from v ss to v dd . operating conditions: 3.0v < v dd < 3.6v, -40c < t a < +85c (unless otherwise stated) param no. sym characteristics min typ max units comments d310 v res resolution v dd /24 ? v dd /32 lsb d311 vr aa absolute accuracy ? ? 1/2 lsb d312 vr ur unit resistor value (r) ? 2k ? 310 t set settling time (1) ? ? 10 s note 1: settling time measured while cvrr = 1 and cvr<3:0> bits transition from ? 0000 ? to ? 1111 ?.
? 2009 microchip technology inc. preliminary ds39931b-page 499 pic18f46j50 family table 29-4: internal voltag e regulator specifications table 29-5: ulpwu specifications table 29-6: ctmu current source specifications operating conditions: -40c < t a < +85c (unless otherwise stated) param no. sym characteristics min typ max units comments v rgout regulator output voltage 2.35 2.5 2.7 v regulator enabled, v dd = 3.0v c efc external filter capacitor value (1) 5.4 10 18 f esr < 3 recommended esr < 5 required note 1: c efc applies for pic18 f devices in the family. for pic18 lf devices in the family, there is no specific minimum or maximum capacitance for v ddcore , although proper supply rail bypassing should still be used. dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. sym characteristic min typ? max units conditions d100 i ulp ultra low-power wake-up current ?60 ? na net of i/o leakage and current sink at 1.6v on pin, v dd = 3.3v see application note an879, ? using the microchip ultra low-power wake-up module ? (ds00879) ? data in ?typ? column is at 3.3v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. dc characteristics standard operating conditions: 2.0v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. sym characteristic min typ (1) max units conditions i out 1 ctmu current source, base range ? 550 ? na ctmuicon<1:0> = 01 i out 2 ctmu current source, 10x range ? 5.5 ? a ctmuicon<1:0> = 10 i out 3 ctmu current source, 100x range ? 55 ? a ctmuicon<1:0> = 11 note 1: nominal value at center point of current trim range (ctmuicon<7:2> = 000000 ).
pic18f46j50 family ds39931b-page 500 preliminary ? 2009 microchip technology inc. table 29-7: usb mo dule specifications operating conditions: -40c < t a < +85c (unless otherwise stated) param no. sym characteristics min typ max units comments d313 v usb usb voltage 3.0 ? 3.6 v voltage on v usb pin must be in this range for proper usb operation d314 i il input leakage on d+ or d- ? ? +/-0.2 av ss < v pin < v usb d315 v ilusb input low voltage for usb buffer ??0.8 vfor v usb range d316 v ihusb input high voltage for usb buffer 2.0 ? ? v for v usb range d318 v difs differential input sensitivity ? ? 0.2 v the difference between d+ and d- must exceed this value while v cm is met d319 v cm differential common mode range 0.8 ? 2.5 v d320 z out driver output impedance (1) 28 ? 44 d321 v ol voltage output low 0.0 ? 0.3 v 1.5 k load connected to 3.6v d322 v oh voltage output high 2.8 ? 3.6 v 1.5 k load connected to ground note 1: the d+ and d- signal lines have built-in impedance matching resistors. no external resistors, capacitors or magnetic components are necessary on the d+/d- signal paths between the pic18f46j50 family device and a usb cable.
? 2009 microchip technology inc. preliminary ds39931b-page 501 pic18f46j50 family figure 29-3: high/low-voltage detect characteristics table 29-8: high/low-volt age detect characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. symbol characteristic min typ max units conditions d420 hlvd voltage on v dd transition high-to-low hlvdl<3:0> = 1000 2.33 2.45 2.57 v hlvdl<3:0> = 1001 2.47 2.60 2.73 v hlvdl<3:0> = 1010 2.66 2.80 2.94 v hlvdl<3:0> = 1011 2.76 2.90 3.05 v hlvdl<3:0> = 1100 2.85 3.00 3.15 v hlvdl<3:0> = 1101 2.97 3.13 3.29 v hlvdl<3:0> = 1110 3.23 3.40 3.57 v d421 t irvst time for internal reference voltage to become stable ?20? s d422 t lvd high/low-voltage detect pulse width 200 ? ? s v hlvd hlvdif v dd (hlvdif set by hardware) (hlvdif can be cleared in software) v hlvd for vdirmag = 1 : for vdirmag = 0 : v dd
pic18f46j50 family ds39931b-page 502 preliminary ? 2009 microchip technology inc. 29.4 ac (timing) characteristics 29.4.1 timing parameter symbology the timing parameter symbols have been created following one of the following formats: 1. tpps2pps 3. t cc : st (i 2 c specifications only) 2. tpps 4. ts (i 2 c specifications only) t f frequency t time lowercase letters (pp) and their meanings: pp cc ccp1 osc osc1 ck clko rd rd cs cs rw rd or wr di sdi sc sck do sdo ss ss dt data in t0 t0cki io i/o port t1 t13cki mc mclr wr wr uppercase letters and their meanings: s f fall p period hhigh rrise i invalid (high-impedance) v valid l low z high-impedance i 2 c only aa output access high high buf bus free low low t cc : st (i 2 c specifications only) cc hd hold su setup st dat data input hold sto stop condition sta start condition
? 2009 microchip technology inc. preliminary ds39931b-page 503 pic18f46j50 family 29.4.2 timing conditions the temperature and voltages specified in table 29-9 apply to all timing specifications unless otherwise noted. figure 29-4 specifies the load conditions for the timing specifications. table 29-9: temperature and vo ltage specifications ? ac figure 29-4: load conditions for device timing specifications 29.4.3 timing diagrams and specifications figure 29-5: external clock timing ac characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial operating voltage v dd range as described in section 29.1 and section 29.3 . v dd /2 c l r l pin pin v ss v ss c l r l =464 c l = 50 pf for all pins except osc2/clko/ra6 and including d and e outputs as ports c l = 15 pf for osc2/clko/ra6 load condition 1 load condition 2 osc1 clko q4 q1 q2 q3 q4 q1 1 2 3 3 4 4
pic18f46j50 family ds39931b-page 504 preliminary ? 2009 microchip technology inc. table 29-10: external clo ck timing requirements table 29-11: pll clock timing specifications (v ddcore = 2.35v to 2.75v) table 29-12: internal rc accuracy (intosc and intrc sources) param. no. symbol characteristic min max units conditions 1a f osc external clki frequency (1) dc 48 mhz ec oscillator mode dc 48 ecpll oscillator mode (2) oscillator frequency (1) 4 16 mhz hs oscillator mode 416 (4) hspll oscillator mode (3) 1t osc external clki period (1) 20.8 ? ns ec oscillator mode 20.8 ? ecpll oscillator mode (2) oscillator period (1) 62.5 250 ns hs oscillator mode 62.5 (4) 250 hspll oscillator mode (3) 2t cy instruction cycle time (1) 83.3 dc ns t cy = 4/f osc , industrial 3t os l, t os h external clock in (osc1) high or low time 10 ? ns ec oscillator mode 4t os r, t os f external clock in (osc1) rise or fall time ? 7.5 ns ec oscillator mode note 1: instruction cycle period (t cy ) equals four times the input oscillator time base period for all configurations except pll. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator operation and/or higher than expected current consumption. all devices are tested to operate at ?min.? values with an external clock applied to the osc1/clki pin. when an external clock input is used, the ?max.? cycle time limit is ?dc? (no clock) for all devices. 2: in order to use the pll, the external clock frequency must be either 4, 8, 12, 16, 20, 24, 40 or 48 mhz. 3: in order to use the pll, the crystal/resonator must produce a frequency of either 4, 8, 12 or 16 mhz. 4: this is the maximum crystal/resonator driver frequency. the internal f osc frequency when running from the pll can be up to 48 mhz. param no. sym characteristic min typ? max units conditions f10 f osc oscillator frequency range 4 ? 48 mhz f11 f sys on-chip vco system frequency ? 96 ? mhz f12 t rc pll start-up time (lock time) ? ? 2 ms param no. device min typ max units conditions intosc accuracy @ freq = 8 mhz, 4 mhz, 2 mhz, 1 mhz, 500 khz, 250 khz, 125 khz, 31 khz (1) all devices -1 +/-0.15 +1 % 0c to +85c v dd = 2.4v-3.6v v ddcore = 2.3v-2.7v -1 +/-0.25 +1 % -40c to +85c v dd = 2.0v-3.6v v ddcore = 2.0v-2.7v intrc accuracy @ freq = 31 khz (1) all devices 20.3 ? 42.2 khz -40c to +85c v dd = 2.0v-3.6v v ddcore = 2.0v-2.7v note 1: the accuracy specification of the 31 khz clock is determined by which source is providing it at a given time. when intsrc (osctune<7>) is ? 1 ?, use the intosc accuracy specification. when intsrc is ? 0 ?, use the intrc accuracy specification.
? 2009 microchip technology inc. preliminary ds39931b-page 505 pic18f46j50 family figure 29-6: clko and i/o timing table 29-13: clko and i/o timing requirements param no. symbol characteristic min typ max units conditions 10 t os h2 ck losc1 to clko ? 75 200 ns (note 1) 11 t os h2 ck hosc1 to clko ? 75 200 ns (note 1) 12 t ck rclko rise time ? 15 30 ns (note 1) 13 t ck fclko fall time ? 15 30 ns (note 1) 14 t ck l2 io vclko to port out valid ? ? 0.5 t cy + 20 ns 15 t io v2 ck h port in valid before clko 0.25 t cy + 25 ? ? ns 16 t ck h2 io i port in hold after clko 0??ns 17 t os h2 io vosc1 (q1 cycle) to port out valid ? 50 150 ns 18 t os h2 io iosc1 (q2 cycle) to port input invalid (i/o in hold time) 100 ? ? ns 19 t io v2 os h port input valid to osc1 (i/o in setup time) 0??ns 20 t io r port output rise time ? ? 6 ns 21 t io f port output fall time ? ? 5 ns 22? t inp intx pin high or low time t cy ??ns 23? t rbp rb7:rb4 change intx high or low time t cy ??ns ? these parameters are asynchronous events not related to any internal clock edges. note 1: measurements are taken in ec mode, where clko output is 4 x t osc . note: refer to figure 29-4 for load conditions. osc1 clko i/o pin (input) i/o pin (output) q4 q1 q2 q3 10 13 14 17 20, 21 19 18 15 11 12 16 old value new value
pic18f46j50 family ds39931b-page 506 preliminary ? 2009 microchip technology inc. figure 29-7: reset, watchdog timer, oscillator start-up timer and power-up timer timing table 29-14: reset, watchdog timer, oscill ator start-up timer, power-up timer and brown-out reset requirements param. no. symbol characteristic min typ max units conditions 30 t mc lmclr pulse width (low) 2 ? ? s 31 t wdt watchdog timer time-out period (no postscaler) 2.67 4.0 5.53 ms 32 t ost oscillator start-up timer period 1024 t osc ? 1024 t osc ?t osc = osc1 period 33 t pwrt power-up timer period ? 1.0 ? ms 34 t ioz i/o high-impedance from mclr low or watchdog timer reset ??3 t cy + 2 s (note 1) 36 t irvst time for internal reference voltage to become stable ?20? s 37 t lvd high/low-voltage detect pulse width ?200? s 38 t csd cpu start-up time ? 200 ? s (note 2) note 1: the maximum t ioz is the lesser of (3 t cy + 2 s) or 700 s. 2: mclr rising edge to code execution, assuming t pwrt (and t ost if applicable) has already expired. v dd mclr internal por pwrt time-out oscillator time-out internal reset watchdog timer reset 33 32 30 31 34 i/o pins 34 note: refer to figure 29-4 for load conditions.
? 2009 microchip technology inc. preliminary ds39931b-page 507 pic18f46j50 family figure 29-8: timer0 and timer1 external clock timings table 29-15: timer0 and timer1 external clock requirements param no. symbol characteristic min max units conditions 40 t t 0h t0cki high pulse width no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 41 t t 0l t0cki low pulse width no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 42 t t 0p t0cki period no prescaler t cy + 10 ? ns with prescaler greater of: 20 ns or (t cy + 40)/n ?nsn = prescale value (1, 2, 4,..., 256) 45 t t 1h t1cki/t3cki high time synchronous, no prescaler 0.5 t cy + 20 ? ns synchronous, with prescaler 10 ? ns asynchronous 30 ? ns 46 t t 1l t1cki/t3cki low time synchronous, no prescaler 0.5 t cy + 5 ? ns synchronous, with prescaler 10 ? ns asynchronous 30 ? ns 47 t t 1p t1cki/t3cki input period synchronous greater of: 20 ns or (t cy + 40)/n ?nsn = prescale value (1, 2, 4, 8) asynchronous 83 ? ns f t 1 t1cki input frequency range (1) dc 12 mhz 48 t cke 2 tmr i delay from external t1cki clock edge to timer increment 2 t osc 7 t osc ? note 1: the timer1 oscillator is designed to drive 32.768 khz crystals. when t1cki is used as a digital input, frequencies up to 12 mhz are supported. note: refer to figure 29-4 for load conditions. 46 47 45 48 41 42 40 t0cki t1oso/t1cki tmr0 or tmr1
pic18f46j50 family ds39931b-page 508 preliminary ? 2009 microchip technology inc. figure 29-9: enhanced capture/compare/pwm timings table 29-16: enhanced capture/compare/pwm requirements param no. symbol characteristic min max units conditions 50 t cc l eccpx input low time no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 51 t cc h eccpx input high time no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 52 t cc p eccpx input period 3 t cy + 40 n ?nsn = prescale value (1, 4 or 16) 53 t cc r eccpx output fall time ? 25 ns 54 t cc f eccpx output fall time ? 25 ns note: refer to figure 29-4 for load conditions. eccpx (capture mode) 50 51 52 eccpx 53 54 (compare or pwm mode)
? 2009 microchip technology inc. preliminary ds39931b-page 509 pic18f46j50 family figure 29-10: parallel master port read timing diagram table 29-17: parallel master port read timing requirements param. no symbol characteristics min typ max units pm1 pmall/pmalh pulse width ? 0.5 t cy ?ns pm2 address out valid to pmall/pmalh invalid (address setup time) ? 0.75 t cy ?ns pm3 pmall/pmalh invalid to address out invalid (address hold time) ? 0.25 t cy ?ns pm5 pmrd pulse width ? 0.5 t cy ?ns pm6 pmrd or pmenb active to data in valid (data setup time) ???ns pm7 pmrd or pmenb inactive to data in invalid (data hold time) ???ns q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 system pmall/pmalh pmd<7:0> address pma<13:18> operating conditions: 2.0v < v dd < 3.6v, -40c < t a < +85c unless otherwise stated. pmwr pmcs<2:1> pmrd clock pm2 pm3 pm6 pm7 pm5 pm1 data address<7:0>
pic18f46j50 family ds39931b-page 510 preliminary ? 2009 microchip technology inc. figure 29-11: parallel master port write timing diagram table 29-18: parallel master port write timing requirements param. no symbol characteristics min typ max units pm11 pmwr pulse width ? 0.5 t cy ?ns pm12 data out valid before pmwr or pmenb goes inactive (data setup time) ???ns pm13 pmwr or pmemb invalid to data out invalid (data hold time) ???ns pm16 pmcs pulse width t cy ? 5 ? ? ns q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 system pmall/ pmd<7:0> address pma<13:18> pmwr pmcs<2:1> pmrd clock pm12 pm13 pm11 pm16 data address<7:0> pmalh note: operating conditions: 2.0v < v dd < 3.6v, -40c < t a < +85c unless otherwise stated.
? 2009 microchip technology inc. preliminary ds39931b-page 511 pic18f46j50 family figure 29-12: example spi master mode timing (cke = 0 ) table 29-19: example spi mode requirements (master mode, cke = 0 ) param no. symbol characteristic min max units conditions 73 t di v2 sc h, t di v2 sc l setup time of sdix data input to sckx edge 35 ? ns v dd = 3.3v, v ddcore = 2.5v 100 ? ns v dd = 2.15v, v ddcore = 2.15v 73a t b 2 b last clock edge of byte 1 to the 1st clock edge of byte 2 1.5 t cy + 40 ? ns 74 t sc h2 di l, t sc l2 di l hold time of sdix data input to sckx edge 30 ? ns v dd = 3.3v, v ddcore = 2.5v 83 ? ns v dd = 2.15v 75 t do r sdox data output rise time ? 25 ns portb or portc 76 t do f sdox data output fall time ? 25 ns portb or portc 78 t sc r sckx output rise time (master mode) ? 25 ns portb or portc 79 t sc f sckx output fall time (master mode) ? 25 ns portb or portc sckx (ckp = 0 ) sckx (ckp = 1 ) sdox sdix 73 74 75, 76 78 79 79 78 msb lsb bit 6 - - - - - - 1 msb in lsb in bit 6 - - - - 1 note: refer to figure 29-4 for load conditions.
pic18f46j50 family ds39931b-page 512 preliminary ? 2009 microchip technology inc. figure 29-13: example spi master mode timing (cke = 1 ) table 29-20: example spi mode requirements (master mode, cke = 1 ) param. no. symbol characteristic min max units conditions 73 t di v2 sc h, t di v2 sc l setup time of sdix data input to sckx edge 35 ? ns v dd = 3.3v, v ddcore = 2.5v 100 ? ns v dd = 2.15v, v ddcore = 2.15v 74 t sc h2 di l, t sc l2 di l hold time of sdix data input to sckx edge 30 ? ns v dd = 3.3v, v ddcore = 2.5v 83 ? ns v dd = 2.15v 75 t do r sdox data output rise time ? 25 ns portb or portc 76 t do f sdox data output fall time ? 25 ns portb or portc 78 t sc r sckx output rise time (master mode) ? 25 ns portb or portc 79 t sc f sckx output fall time (master mode) ? 25 ns portb or portc 81 t do v2 sc h, t do v2 sc l sdox data output setup to sckx edge t cy ?ns sckx (ckp = 0 ) sckx (ckp = 1 ) sdox sdix 81 74 75, 76 78 msb 79 73 msb in bit 6 - - - - - - 1 lsb in bit 6 - - - - 1 lsb note: refer to figure 29-4 for load conditions.
? 2009 microchip technology inc. preliminary ds39931b-page 513 pic18f46j50 family figure 29-14: example spi slave mode timing (cke = 0 ) table 29-21: example spi mode requirements (slave mode timing, cke = 0 ) param no. symbol characteristic min max units conditions 70 t ss l2 sc h, t ss l2 sc l ssx to sckx or sckx input 3 t cy ?ns 70a t ss l2wb ssx to write to sspxbuf 3 t cy ?ns 71 t sc h sckx input high time (slave mode) continuous 1.25 t cy + 30 ? ns 71a single byte 40 ? ns (note 1) 72 t sc l sckx input low time (slave mode) continuous 1.25 t cy + 30 ? ns 72a single byte 40 ? ns (note 1) 73 t di v2 sc h, t di v2 sc l setup time of sdix data input to sckx edge 25 ? ns 73a t b 2 b last clock edge of byte 1 to the first clock edge of byte 2 1.5 t cy + 40 ? ns (note 2) 74 t sc h2 di l, t sc l2 di l hold time of sdix data input to sckx edge 35 ? ns v dd = 3.3v, v ddcore = 2.5v 100 ? ns v dd = 2.15v 75 t do r sdox data output rise time ? 25 ns portb or portc 76 t do f sdox data output fall time ? 25 ns portb or portc 77 t ss h2 do z ssx to sdox output high-impedance 10 70 ns 80 t sc h2 do v, t sc l2 do v sdox data output valid after sckx edge ? 50 ns v dd = 3.3v, v ddcore = 2.5v ? 100 ns v dd = 2.15v 83 t sc h2 ss h, t sc l2 ss h ssx after sckx edge 1.5 t cy + 40 ? ns note 1: requires the use of parameter #73a. 2: only if parameter #71a and #72a are used. ssx sckx (ckp = 0 ) sckx (ckp = 1 ) sdox sdi 70 71 72 73 74 75, 76 77 80 sdix msb lsb bit 6 - - - - - - 1 bit 6 - - - - 1 lsb in 83 note: refer to figure 29-4 for load conditions. msb in
pic18f46j50 family ds39931b-page 514 preliminary ? 2009 microchip technology inc. figure 29-15: example spi slave mode timing (cke = 1 ) table 29-22: example spi slave mode requirements (cke = 1 ) param no. symbol characteristic min max units conditions 70 t ss l2 sc h, t ss l2 sc l ssx to sckx or sckx input 3 t cy ?ns 70a t ss l2wb ssx to write to sspxbuf 3 t cy ?ns 71 t sc h sckx input high time (slave mode) continuous 1.25 t cy + 30 ? ns 71a single byte 40 ? ns (note 1) 72 t sc l sckx input low time (slave mode) continuous 1.25 t cy + 30 ? ns 72a single byte 40 ? ns (note 1) 73 t di v2 sc h, t di v2 sc l setup time of sdix data input to sckx edge 25 ? ns 73a t b 2 b last clock edge of byte 1 to the first clock edge of byte 2 1.5 t cy + 40 ? ns (note 2) 74 t sc h2 di l, t sc l2 di l hold time of sdix data input to sckx edge 35 ? ns v dd = 3.3v, v ddcore = 2.5v 100 ? ns v dd = 2.15v 75 t do r sdox data output rise time ? 25 ns 76 t do f sdox data output fall time ? 25 ns 77 t ss h2 do z ssx to sdox output high-impedance 10 70 ns 80 t sc h2 do v, t sc l2 do v sdox data output valid after sckx edge ? 50 ns v dd = 3.3v, v ddcore = 2.5v ?100nsv dd = 2.15v 81 t do v2 sc h, t do v2 sc l sdox data output setup to sckx edge t cy ?ns 82 t ss l2 do v sdox data output valid after ssx edge ? 50 ns 83 t sc h2 ss h, t sc l2 ss h ssx after sckx edge 1.5 t cy + 40 ? ns note 1: requires the use of parameter #73a. 2: only if parameter #71a and #72a are used. ssx sckx (ckp = 0 ) sckx (ckp = 1 ) sdox sdi 70 71 72 82 sdix 74 75, 76 msb bit 6 - - - - - - 1 lsb 77 bit 6 - - - - 1 lsb in 80 83 note: refer to figure 29-4 for load conditions. 73 msb in
? 2009 microchip technology inc. preliminary ds39931b-page 515 pic18f46j50 family figure 29-16: i 2 c? bus start/stop bits timing table 29-23: i 2 c? bus start/stop bits requirements (slave mode) figure 29-17: i 2 c? bus data timing param. no. symbol characteristic min max units conditions 90 t su : sta start condition 100 khz mode 4700 ? ns only relevant for repeated start condition setup time 400 khz mode 600 ? 91 t hd : sta start condition 100 khz mode 4000 ? ns after this period, the first clock pulse is generated hold time 400 khz mode 600 ? 92 t su : sto stop condition 100 khz mode 4700 ? ns setup time 400 khz mode 600 ? 93 t hd : sto stop condition 100 khz mode 4000 ? ns hold time 400 khz mode 600 ? note: refer to figure 29-4 for load conditions. 91 92 93 sclx sdax start condition stop condition 90 note: refer to figure 29-4 for load conditions. 90 91 92 100 101 103 106 107 109 109 110 102 sclx sdax in sdax out
pic18f46j50 family ds39931b-page 516 preliminary ? 2009 microchip technology inc. table 29-24: i 2 c? bus data requirements (slave mode) param. no. symbol characteristic min max units conditions 100 t high clock high time 100 khz mode 4.0 ? s 400 khz mode 0.6 ? s mssp modules 1.5 t cy ? 101 t low clock low time 100 khz mode 4.7 ? s 400 khz mode 1.3 ? s mssp modules 1.5 t cy ? 102 t r sdax and sclx rise time 100 khz mode ? 1000 ns 400 khz mode 20 + 0.1 c b 300 ns c b is specified to be from 10 to 400 pf 103 t f sdax and sclx fall time 100 khz mode ? 300 ns 400 khz mode 20 + 0.1 c b 300 ns c b is specified to be from 10 to 400 pf 90 t su : sta start condition setup time 100 khz mode 4.7 ? s only relevant for repeated start condition 400 khz mode 0.6 ? s 91 t hd : sta start condition hold time 100 khz mode 4.0 ? s after this period, the first clock pulse is generated 400 khz mode 0.6 ? s 106 t hd : dat data input hold time 100 khz mode 0 ? ns 400 khz mode 0 0.9 s 107 t su : dat data input setup time 100 khz mode 250 ? ns (note 2) 400 khz mode 100 ? ns 92 t su : sto stop condition setup time 100 khz mode 4.7 ? s 400 khz mode 0.6 ? s 109 t aa output valid from clock 100 khz mode ? 3500 ns (note 1) 400 khz mode ? ? ns 110 t buf bus free time 100 khz mode 4.7 ? s time the bus must be free before a new transmission can start 400 khz mode 1.3 ? s d102 c b bus capacitive loading ? 400 pf note 1: as a transmitter, the device must provi de this internal minimum delay time to bridge the undefined region (min. 300 ns) of the falling edge of sclx to avoid unint ended generation of start or stop conditions. 2: a fast mode i 2 c? bus device can be us ed in a standard mode i 2 c bus system, but the requirement, t su : dat 250 ns, must then be met. this will automatically be the case if the device does not stretch the low period of the sclx signal. if such a device does stretch the low period of the sclx signal, it must output the next data bit to the sdax line, t r max. + t su : dat = 1000 + 250 = 1250 ns (according to the standard mode i 2 c bus specification), bef ore the sclx line is released.
? 2009 microchip technology inc. preliminary ds39931b-page 517 pic18f46j50 family figure 29-18: msspx i 2 c? bus start/stop bits timing waveforms table 29-25: msspx i 2 c? bus start/stop bits requirements figure 29-19: msspx i 2 c? bus data timing param. no. symbol characteristic min max units conditions 90 t su : sta start condition 100 khz mode 2(t osc )(brg + 1) ? ns only relevant for repeated start condition setup time 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode (1) 2(t osc )(brg + 1) ? 91 t hd : sta start condition 100 khz mode 2(t osc )(brg + 1) ? ns after this period, the first clock pulse is generated hold time 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode (1) 2(t osc )(brg + 1) ? 92 t su : sto stop condition 100 khz mode 2(t osc )(brg + 1) ? ns setup time 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode (1) 2(t osc )(brg + 1) ? 93 t hd : sto stop condition 100 khz mode 2(t osc )(brg + 1) ? ns hold time 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode (1) 2(t osc )(brg + 1) ? note 1: maximum pin capacitance = 10 pf for all i 2 c? pins. note: refer to figure 29-4 for load conditions. 91 93 sclx sdax start condition stop condition 90 92 note: refer to figure 29-4 for load conditions. 90 91 92 100 101 103 106 107 109 109 110 102 sclx sdax in sdax out
pic18f46j50 family ds39931b-page 518 preliminary ? 2009 microchip technology inc. table 29-26: msspx i 2 c? bus data requirements param. no. symbol characteristic min max units conditions 100 t high clock high time 100 khz mode 2(t osc )(brg + 1) ? s 400 khz mode 2(t osc )(brg + 1) ? s 1 mhz mode (1) 2(t osc )(brg + 1) ? s 101 t low clock low time 100 khz mode 2(t osc )(brg + 1) ? s 400 khz mode 2(t osc )(brg + 1) ? s 1 mhz mode (1) 2(t osc )(brg + 1) ? s 102 t r sdax and sclx rise time 100 khz mode ? 1000 ns c b is specified to be from 10 to 400 pf 400 khz mode 20 + 0.1 c b 300 ns 1 mhz mode (1) ? 300 ns 103 t f sdax and sclx fall time 100 khz mode ? 300 ns c b is specified to be from 10 to 400 pf 400 khz mode 20 + 0.1 c b 300 ns 1 mhz mode (1) ? 100 ns 90 t su : sta start condition setup time 100 khz mode 2(t osc )(brg + 1) ? s only relevant for repeated start condition 400 khz mode 2(t osc )(brg + 1) ? s 1 mhz mode (1) 2(t osc )(brg + 1) ? s 91 t hd : sta start condition hold time 100 khz mode 2(t osc )(brg + 1) ? s after this period, the first clock pulse is generated 400 khz mode 2(t osc )(brg + 1) ? s 1 mhz mode (1) 2(t osc )(brg + 1) ? s 106 t hd : dat data input hold time 100 khz mode 0 ? ns 400 khz mode 0 0.9 s 1 mhz mode (1) tbd ? ns 107 t su : dat data input setup time 100 khz mode 250 ? ns (note 2) 400 khz mode 100 ? ns 1 mhz mode (1) tbd ? ns 92 t su : sto stop condition setup time 100 khz mode 2(t osc )(brg + 1) ? s 400 khz mode 2(t osc )(brg + 1) ? s 1 mhz mode (1) 2(t osc )(brg + 1) ? s 109 t aa output valid from clock 100 khz mode ? 3500 ns 400 khz mode ? 1000 ns 1 mhz mode (1) ??ns 110 t buf bus free time 100 khz mode 4.7 ? s time the bus must be free before a new transmission can start 400 khz mode 1.3 ? s 1 mhz mode (1) tbd ? s d102 c b bus capacitive loading ? 400 pf legend: tbd = to be determined note 1: maximum pin capacitance = 10 pf for all i 2 c? pins. 2: a fast mode i 2 c bus device can be used in a standard mode i 2 c bus system, but parameter #107 250 ns must then be met. this will automatically be the case if the device does not stretch the low period of the sclx signal. if such a device does stretch the low period of the sclx signal, it must output the next data bit to the sdax line, parameter #102 + parameter #107 = 1000 + 250 = 1250 ns (for 100 khz mode), before the sclx line is released.
? 2009 microchip technology inc. preliminary ds39931b-page 519 pic18f46j50 family figure 29-20: eusartx synchronous transmission (master/slave) timing table 29-27: eusartx synchronous transmission requirements figure 29-21: eusartx synchronous receive (master/slave) timing table 29-28: eusartx synchrono us receive requirements param no. symbol characteristic min max units conditions 120 t ck h2 dt v sync xmit (master and slave ) clock high to data out valid ? 40 ns 121 t ckrf clock out rise time and fall time (master mode) ? 20 ns 122 t dtrf data out rise time and fall time ? 20 ns param. no. symbol characteristic min max units conditions 125 t dt v2 ckl sync rcv (master and slave ) data hold before ckx (dtx hold time) 10 ? ns 126 t ck l2 dtl data hold after ckx (dtx hold time) 15 ? ns 121 121 120 122 txx/ckx rxx/dtx pin pin note: refer to figure 29-4 for load conditions. 125 126 txx/ckx rxx/dtx pin pin note: refer to figure 29-4 for load conditions.
pic18f46j50 family ds39931b-page 520 preliminary ? 2009 microchip technology inc. table 29-29: a/d converter characteristics: pic18f46j50 family (industrial) figure 29-22: a/d conversion timing param no. symbol characteristic min typ max units conditions a01 n r resolution ? ? 10 bit v ref 3.0v a03 e il integral linearity error ? ? <1 lsb v ref 3.0v a04 e dl differential linearity error ? ? <1 lsb v ref 3.0v a06 e off offset error ? ? <3 lsb v ref 3.0v a07 e gn gain error ? ? <3.5 lsb v ref 3.0v a10 monotonicity guaranteed (1) ?v ss v ain v ref a20 v ref reference voltage range (v refh ? v refl ) 2.0 3 ? ? ? ? v v v dd < 3.0v v dd 3.0v a21 v refh reference voltage high v refl ?v dd + 0.3v v a22 v refl reference voltage low v ss ? 0.3v ? v refh v a25 v ain analog input voltage v refl ?v refh v a30 z ain recommended impedance of analog voltage source ?? 10k a50 i ref v ref input current (2) ? ? ? ? 5 150 a a during v ain acquisition. during a/d conversion cycle. note 1: the a/d conversion result never decreases with an increase in the input voltage and has no missing codes. 2: v refh current is from ra3/an3/v ref +/c1inb pin or v dd , whichever is selected as the v refh source. v refl current is from ra2/an2/v ref -/cv ref /c2inb pin or v ss , whichever is selected as the v refl source. 131 130 132 bsf adcon0, go q4 a/d clk a/d data adres adif go sample old_data sampling stopped done new_data (note 2) 987 21 0 note 1: if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. 2: this is a minimal rc delay (typically 100 ns), which al so disconnects the holding capacitor from the analog input. . . . . . . t cy (note 1)
? 2009 microchip technology inc. preliminary ds39931b-page 521 pic18f46j50 family table 29-30: a/d conversion requirements figure 29-23: usb signal timing table 29-31: usb low-speed timing requirements table 29-32: usb full-speed requirements param no. symbol characteristic min max units conditions 130 t ad a/d clock period 0.7 25.0 (1) st osc based, v ref 3.0v 131 t cnv conversion time (not including acquisition time) (2) 11 12 t ad 132 t acq acquisition time (3) 1.4 ? s-40 c to +85 c 135 t swc switching time from convert sample ? (note 4) 137 t dis discharge time 0.2 ? s note 1: the time of the a/d clock period is dependent on the device frequency and the t ad clock divider. 2: adres registers may be read on the following t cy cycle. 3: the time for the holding capacitor to acquire the ?new? input voltage when the voltage changes full scale after the conversion (v dd to v ss or v ss to v dd ). the source impedance (r s ) on the input channels is 50 . 4: on the following cycle of the device clock. param no. symbol characteristic min typ max units conditions t lr transition rise time 75 ? 300 ns c l = 200 to 600 pf t lf transition fall time 75 ? 300 ns c l = 200 to 600 pf t lrfm rise/fall time matching 80 ? 125 % param no. symbol characteristic min typ max units conditions t fr transition rise time 4 ? 20 ns c l = 50 pf t ff transition fall time 4 ? 20 ns c l = 50 pf t frfm rise/fall time matching 90 ? 111.1 % v crs usb data differential lines 90% 10% t lr , t fr t lf , t ff
pic18f46j50 family ds39931b-page 522 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39931b-page 523 pic18f46j50 family 30.0 packaging information 30.1 package marking information legend: xx...x customer-specific information y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code pb-free jedec designator for matte tin (sn) * this package is pb-free. the pb-free jedec designator ( ) can be found on the outer packaging for this package. note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line, thus limiting the number of available characters for customer-specific information. 3 e 28-lead soic (.300?) xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx yywwnnn example pic18f26j50/so 0910017 28-lead qfn xxxxxxxx xxxxxxxx yywwnnn example 18f26j50 /ml 0910017 3 e 3 e 28-lead spdip xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx yywwnnn example -i/sp pic18f26j50 0910017 3 e 28-lead ssop xxxxxxxxxxxx xxxxxxxxxxxx yywwnnn example 18f26j50 /ss 0910017 3 e
pic18f46j50 family ds39931b-page 524 preliminary ? 2009 microchip technology inc. xxxxxxxxxx 44-lead qfn xxxxxxxxxx xxxxxxxxxx yywwnnn 18f46j50 example -i/ml 0910017 44-lead tqfp xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx yywwnnn example 18f46j50 -i/pt 0910017 3 e 3 e
? 2009 microchip technology inc. preliminary ds39931b-page 525 pic18f46j50 family 30.2 package details the following sections give the technical details of the packages. 
       
      
 !"   !"#$%&" '  ()"&'"!&)
&#*& &  & #   +%&,  & !& - '!
!#.#

&"#'
#%! 

& "!
!
#%! 

& "!
!! 
&$#/  !#  '!
#&
   .0 1,2 1!'!
 
&$& "!
**&
"&&
 ! !" 3
& '
!&" & 4# *!( !!& 
  4 %&

&#& && 255***'
  
'5 4 6&! 7,8. '!
9'&! 7 7: ; 7"') 
%! 7 < &  1,
&
&  = =  
##4 4!!   -  1!&
&   = = 
"# &

"# >#& .  - -- 
##4>#& .  <  :  9&  - -?   &
& 9  -  9# 4!!  <   6  9#>#& )    9
* 9#>#& )  <  :  
* + 1 = = - note 1 n 12 d e1 eb c e l a2 e b b1 a1 a 3 
   

  * ,1
pic18f46j50 family ds39931b-page 526 preliminary ? 2009 microchip technology inc.   
#$
 %  
  &'   
% !"   !"#$%&" '  ()"&'"!&)
&#*& &  & #   '!
!#.#

&"#'
#%! 

& "!
!
#%! 

& "!
!! 
&$#''  !# - '!
#&
   .0 1,2 1!'!
 
&$& "!
**&
"&&
 ! .32 % '!
("!"*&
"&&
 (%
%
'&
 "
!!
 !" 3
& '
!&" & 4# *!( !!& 
  4 %&

&#& && 255***'
  
'5 4 6&! 99. . '!
9'&! 7 7: ; 7"') 
%! 7 < &  ?1, :  8 &  = =  
##4 4!!  ?  < &#
%%   = = :  >#& .  < < 
##4>#& .  - ? :  9&     3
&9& 9    3
& & 9 .3 9# 4!!   =  3
&  @ @ <@ 9#>#& )  = -< l l1 c a2 a1 a e e1 d n 1 2 note 1 b e 
   

  * ,-1
? 2009 microchip technology inc. preliminary ds39931b-page 527 pic18f46j50 family   
 %  
%  ( ) *'&   
%+ !"   !"#$%&" '  ()"&'"!&)
&#*& &  & #   +%&,  & !& - '!
!#.#

&"#'
#%! 

& "!
!
#%! 

& "!
!! 
&$#''  !#  '!
#&
   .0 1,2 1!'!
 
&$& "!
**&
"&&
 ! .32 % '!
("!"*&
"&&
 (%
%
'&
 "
!!
 !" 3
& '
!&" & 4# *!( !!& 
  4 %&

&#& && 255***'
  
'5 4 6&! 99. . '!
9'&! 7 7: ; 7"') 
%! 7 < &  1, :  8 &  = = ? 
##4 4!!   = = &#
%%+   = - :  >#& . -1, 
##4>#& . 1, :  9&  1, , '% a
&
b  =  3
&9& 9  =  3
& & 9 .3 3
&
@ = <@ 9# 4!!  < = -- 9#>#& ) - =  
# %&
@ = @ 
# %&1
&&
' @ = @ c h h l l1 a2 a1 a note 1 12 3 b e e e1 d n 
   

  * ,1
pic18f46j50 family ds39931b-page 528 preliminary ? 2009 microchip technology inc.    , -) !   . /  010   ,-! 2 # '&&  +   .# !"   !"#$%&" '  ()"&'"!&)
&#*& &  & #   4!!*!"&# - '!
#&
   .0 1,2 1!'!
 
&$& "!
**&
"&&
 ! .32 % '!
("!"*&
"&&
 (%
%
'&
 "
!!
 !" 3
& '
!&" & 4# *!( !!& 
  4 %&

&#& && 255***'
  
'5 4 6&! 99. . '!
9'&! 7 7: ; 7"') 
%! 7 < &  ?1, :  8 &  <   &#
%%     ,
&& 4!! - .3 :  >#& . ?1, .$
!##>#& . -? -  :  9&  ?1, .$
!##9&  -? -  ,
&&>#& ) - - - ,
&&9& 9    ,
&&&
.$
!## c  = = d exposed d2 e b k e2 e l n note 1 1 2 2 1 n a a1 a3 top view bottom view pad 
   

  * ,1
? 2009 microchip technology inc. preliminary ds39931b-page 529 pic18f46j50 family    , -) !   . /  010   ,-! 2 # '&&  +   .# !" 3
& '
!&" & 4# *!( !!& 
  4 %&

&#& && 255***'
  
'5 4
pic18f46j50 family ds39931b-page 530 preliminary ? 2009 microchip technology inc. 33   , -) !   . /  1   ,-! !"   !"#$%&" '  ()"&'"!&)
&#*& &  & #   4!!*!"&# - '!
#&
   .0 1,2 1!'!
 
&$& "!
**&
"&&
 ! .32 % '!
("!"*&
"&&
 (%
%
'&
 "
!!
 !" 3
& '
!&" & 4# *!( !!& 
  4 %&

&#& && 255***'
  
'5 4 6&! 99. . '!
9'&! 7 7: ; 7"') 
%! 7  &  ?1, :  8 &  <   &#
%%     ,
&& 4!! - .3 :  >#& . <1, .$
!##>#& . ?- ? ?< :  9&  <1, .$
!##9&  ?- ? ?< ,
&&>#& )  - -< ,
&&9& 9 -   ,
&&&
.$
!## c  = = d exposed pad d2 e b k l e2 2 1 n note 1 2 1 e n bottom view top view a3 a1 a 
   

  * ,-1
? 2009 microchip technology inc. preliminary ds39931b-page 531 pic18f46j50 family 33   , -) !   . /  1   ,-! !" 3
& '
!&" & 4# *!( !!& 
  4 %&

&#& && 255***'
  
'5 4
pic18f46j50 family ds39931b-page 532 preliminary ? 2009 microchip technology inc. 33   4# , -5 4  61616  ) '  4,- !"   !"#$%&" '  ()"&'"!&)
&#*& &  & #   , '% !&
 ! 
&
d!e'   - '!
!#.#

&"#'
#%! 

& "!
!
#%! 

& "!
!! 
&$#''  !#  '!
#&
   .0 1,2 1!'!
 
&$& "!
**&
"&&
 ! .32 % '!
("!"*&
"&&
 (%
%
'&
 "
!!
 !" 3
& '
!&" & 4# *!( !!& 
  4 %&

&#& && 255***'
  
'5 4 6&! 99. . '!
9'&! 7 7: ; 7"') 
%9#! 7  9#&  <1, :  8 &  = =  
##4 4!!     &#
%%   =  3
&9& 9  ?  3
& & 9 .3 3
& @ -@ @ :  >#& . 1, :  9&  1, 
##4>#& . 1, 
##49&  1, 9# 4!!   =  9#>#& ) - -  
# %&
@ @ -@ 
# %&1
&&
' @ @ -@ a e e1 d d1 e b note 1 note 2 n 123 c a1 l a2 l1 
   

  * ,?1
? 2009 microchip technology inc. preliminary ds39931b-page 533 pic18f46j50 family 33   4# , -5 4  61616  ) '  4,- !" 3
& '
!&" & 4# *!( !!& 
  4 %&

&#& && 255***'
  
'5 4
pic18f46j50 family ds39931b-page 534 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39931b-page 535 pic18f46j50 family appendix a: revision history revision a (september 2008) original data sheet for the pic18f46j50 family of devices. revision b (march 2009) changes to the electrical characteristics and minor text edits throughout the document. appendix b: device differences the differences between the devices listed in this data sheet are shown in table b-1, table b-1: device differences between pic18f46j50 family members features pic18f24j50 pic18f25j50 pic18f26j50 pic18f44j50 pic18f45j50 pic18f46j50 program memory 16k 32k 64k 16k 32k 64k program memory (instructions) 8,192 16,384 32,768 8,192 16,384 32,768 i/o ports (pins) ports a, b, c ports a, b, c, d, e 10-bit adc module 10 input channels 13 input channels packages 28-pin qfn, soic, ssop and spdip (300 mil) 44-pin qfn and tqfp
pic18f46j50 family ds39931b-page 536 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39931b-page 537 pic18f46j50 family index a a/d ................................................................................... 339 a/d converter interrupt, configuring ....................... 343 acquisition requirements ........................................ 344 adcal bit ................................................................ 347 adresh register .................................................... 342 analog port pins, configuring .................................. 345 associated registers ............................................... 348 automatic acquisition time ...................................... 345 calibration ................................................................ 347 configuring the module ............................................ 343 conversion clock (t ad ) ........................................... 345 conversion requirements ....................................... 521 conversion status (go/done bit) .......................... 342 conversions ............................................................. 346 converter characteristics ........................................ 520 operation in power-managed modes ...................... 347 special event trigger (eccpx) ............................... 346 use of the eccp2 trigger ....................................... 346 absolute maximum ratings ............................................. 483 ac (timing) characteristics ............................................. 502 load conditions for device timing specifications ................................................... 503 parameter symbology ............................................. 502 temperature and voltage specific ations ................. 503 timing conditions .................................................... 503 ackstat ........................................................................ 305 ackstat status flag ..................................................... 305 adcal bit ........................................................................ 347 adcon0 register go/done bit ........................................................... 342 addfsr .......................................................................... 472 addlw ............................................................................ 435 addulnk ........................................................................ 472 addwf ............................................................................ 435 addwfc ......................................................................... 436 adresl register ............................................................ 342 analog-to-digital converter. see a/d. andlw ............................................................................ 436 andwf ............................................................................ 437 assembler mpasm assembler .................................................. 480 auto-wake-up on sync break character ......................... 328 b baud rate generator ....................................................... 301 bc .................................................................................... 437 bcf .................................................................................. 438 bf .................................................................................... 305 bf status flag ................................................................. 305 block diagrams +5v system hardware interface .............................. 124 8-bit multiplexed address and data application ....................................................... 183 a/d ........................................................................... 342 analog input model .................................................. 343 baud rate generator ............................................... 302 capture mode operation ......................................... 240 clock source multiplexing ........................................ 230 comparator analog input model .............................. 380 comparator output .................................................. 377 comparator voltage reference ............................... 385 comparator voltage reference output buffer example ................................................ 387 ctmu ...................................................................... 395 ctmu current source calibration circuit ............... 398 ctmu typical connections and internal configuration for pulse delay generation ....... 406 ctmu typical connections and internal configuration for time measurement .............. 405 demultiplexed addressing mode ............................. 176 device clock .............................................................. 28 enhanced pwm mode ............................................. 245 eusart transmit ................................................... 325 eusartx receive .................................................. 327 fail-safe clock monitor ........................................... 426 fully multiplexed addressing mode ......................... 176 generic i/o port operation ...................................... 123 high/low-voltage detect with external input .......... 390 interrupt logic .......................................................... 108 lcd control ............................................................. 184 legacy parallel slave port ...................................... 170 msspx (i 2 c master mode) ...................................... 300 msspx (i 2 c mode) .................................................. 280 msspx (spi mode) ................................................. 262 multiplexed addressing application ......................... 183 on-chip reset circuit ................................................ 55 parallel eeprom (up to 15-bit address, 16-bit data) ..................................................... 184 parallel eeprom (up to 15-bit address, 8-bit data) ....................................................... 184 parallel master/slave connection addressed buffer ............................................. 173 parallel master/slave connection buffered ............. 172 partially multiplexed addressing application ........... 183 partially multiplexed addressing mode .................... 176 pic18f2xj50 (28-pin) .............................................. 12 pic18f4xj50 (44-pin) .............................................. 13 pmp module ............................................................ 161 pwm operation (simplified) .................................... 242 reads from flash program memory ........................ 99 rtcc ....................................................................... 217 simplified steering ................................................... 258 single comparator ................................................... 380 table read operation ............................................... 95 table write operation ............................................... 96 table writes to flash program memory .................. 101 timer0 in 16-bit mode ............................................. 188 timer0 in 8-bit mode ............................................... 188 timer1 ..................................................................... 195 timer2 ..................................................................... 204 timer3 ..................................................................... 208 timer4 ..................................................................... 216 usb interrupt logic ................................................. 364 usb peripheral and options ................................... 349 using the open-drain output .................................. 124 ustat fifo ............................................................ 355 watchdog timer ...................................................... 421 bn .................................................................................... 438 bnc ................................................................................. 439 bnn ................................................................................. 439 bnov .............................................................................. 440 bnz ................................................................................. 440 bor. see brown-out reset. bov ................................................................................. 443
pic18f46j50 family ds39931b-page 538 preliminary ? 2009 microchip technology inc. bra .................................................................................. 441 break character (12-bit) transmit and receive .............. 330 brg. see baud rate generator. brown-out reset (bor) ..................................................... 57 and on-chip voltage regulator ............................... 424 detecting .................................................................... 57 disabling in sleep mode ............................................ 57 bsf .................................................................................. 441 btfsc ............................................................................. 442 btfss .............................................................................. 442 btg .................................................................................. 443 bz ..................................................................................... 444 c c compilers mplab c18 ............................................................. 480 mplab c30 ............................................................. 480 calibration (a/d converter) .............................................. 347 call ................................................................................ 444 callw ............................................................................. 473 capture (eccp module) .................................................. 240 ccprxh:ccprxl registers ................................... 240 eccp pin configuration .......................................... 240 prescaler .................................................................. 240 software interrupt .................................................... 240 timer1/timer3 mode selection ................................ 240 clock sources .................................................................... 34 effects of power-managed modes ............................. 37 selecting the 31 khz source ...................................... 34 selection using osccon register ........................... 34 clrf ................................................................................ 445 clrwdt .......................................................................... 445 code examples 16 x 16 signed multiply routine .............................. 106 16 x 16 unsigned multiply routine .......................... 106 512-byte spi master mode init and transfer ........... 278 8 x 8 signed multiply routine .................................. 105 8 x 8 unsigned multiply routine .............................. 105 a/d calibration routine ........................................... 347 calculating baud rate error .................................... 320 capacitance calibration routine ............................. 402 capacitive touch switch routine ............................ 404 changing between capture prescalers ................... 240 communicating with the +5v system ...................... 124 computed goto using an offset value ................... 73 configuring eusart2 input and output functions .............................................. 145 current calibration routine ..................................... 400 erasing flash program memory .............................. 100 fast register stack .................................................... 73 how to clear ram (bank 1) using indirect addressing ............................................ 89 initializing porta .................................................... 127 initializing portb .................................................... 130 initializing portc .................................................... 134 initializing portd .................................................... 137 initializing porte .................................................... 139 loading the ssp1buf (ssp1sr) register ............. 265 reading a flash program memory word .................. 99 saving status, wreg and bsr registers in ram ............................................. 122 setting the rtcwren bit ....................................... 231 setup for ctmu calibration routines ...................... 399 two-word instructions ............................................... 75 ultra low-power wake-up initialization ..................... 53 writing to flash program memory ........................... 102 code protection ............................................................... 411 comf .............................................................................. 446 comparator ...................................................................... 377 analog input connection considerations ................ 380 associated registers ............................................... 383 configuration ........................................................... 381 control ..................................................................... 381 effects of a reset .................................................... 383 enable and input selection ...................................... 381 enable and output selection ................................... 381 interrupts ................................................................. 382 operation ................................................................. 380 operation during sleep ........................................... 383 registers ................................................................. 377 response time ........................................................ 380 comparator specifications ............................................... 498 comparator voltage reference ....................................... 385 accuracy and error .................................................. 387 associated registers ............................................... 387 configuring .............................................................. 386 connection considerations ...................................... 387 effects of a reset .................................................... 387 operation during sleep ........................................... 387 compare (eccp module) ................................................ 241 ccprx register ...................................................... 241 pin configuration ..................................................... 241 software interrupt .................................................... 241 special event trigger ...................................... 213, 241 timer1/timer3 mode selection ................................ 241 compare (eccpx module) special event trigger .............................................. 346 computed goto ............................................................... 73 configuration bits ............................................................ 411 configuration mismatch (cm) reset .................................. 58 configuration register protection .................................... 427 configuration registers bits and device ids ................................................. 412 mapping flash configuration words ....................... 412 core features easy migration ........................................................... 10 expanded memory ....................................................... 9 extended instruction set ........................................... 10 nanowatt technology .................................................. 9 oscillator options and features .................................. 9 universal serial bus (usb) .......................................... 9 cpfseq .......................................................................... 446 cpfsgt .......................................................................... 447 cpfslt ........................................................................... 447 crystal oscillator/ceramic resonators .............................. 29 ctmu associated registers ............................................... 409 calibrating ............................................................... 397 creating a delay with ............................................... 406 effects of a reset .................................................... 406 initialization .............................................................. 397 measuring capacitance with .................................... 403 measuring time with ................................................ 405 operation ................................................................. 396 operation during idle mode ..................................... 406 operation during sleep mode ................................. 406 ctmu current source specifications .............................. 499 customer change notification service ............................ 549 customer notification service ......................................... 549 customer support ............................................................ 549
? 2009 microchip technology inc. preliminary ds39931b-page 539 pic18f46j50 family d data addressing modes ..................................................... 89 comparing addressing modes with the extended instruction set enabled ..................... 93 direct .......................................................................... 89 indexed literal offset ................................................. 92 bsr ................................................................... 94 instructions affected .......................................... 92 mapping access bank ....................................... 94 indirect ....................................................................... 89 inherent and literal .................................................... 89 data memory ..................................................................... 76 access bank .............................................................. 78 bank select register (bsr) ....................................... 76 extended instruction set ............................................ 91 general purpose registers ........................................ 78 memory maps access bank special function registers .......... 79 non-access bank special function registers .................................................... 80 pic18f46j50 family devices ........................... 77 special function registers ........................................ 79 context defined sfrs ....................................... 81 usb ram ................................................................... 76 daw ................................................................................. 448 dc characteristics ........................................................... 496 power-down and supply current ............................ 486 supply voltage ......................................................... 485 dcfsnz .......................................................................... 449 decf ............................................................................... 448 decfsz ........................................................................... 449 development support ...................................................... 479 device differences ........................................................... 535 device overview .................................................................. 9 details on individual family members ....................... 10 features (28-pin devices) ......................................... 11 features (44-pin devices) ......................................... 11 other special features .............................................. 10 direct addressing ............................................................... 90 e effect on standard picmcu instructions ......................... 476 electrical characteristics .................................................. 483 absolute maximum ratings ..................................... 483 dc characteristics ........................................... 485?496 enhanced capture/compare/pwm (eccp) .................... 237 associated registers ............................................... 259 capture mode. see capture. compare mode. see compare. eccp mode and timer resources .......................... 239 enhanced pwm mode ............................................. 245 auto-restart ..................................................... 254 auto-shutdown ................................................ 253 direction change in full-bridge output mode ............................................ 251 full-bridge application ..................................... 249 full-bridge mode ............................................. 249 half-bridge application .................................... 248 half-bridge application examples ................... 255 half-bridge mode ............................................. 248 output relationships (active-high and active-low) ....................................... 246 output relationships diagram ......................... 247 programmable dead-band delay .................... 255 shoot-through current .................................... 255 start-up considerations ................................... 252 outputs and configuration ....................................... 239 enhanced universal synchronous asynchronous receiver transmitter (eusart). see eusart. equations a/d acquisition time ............................................... 344 a/d minimum charging time .................................. 344 bytes transmitted for a given dmabc ................... 276 calculating the minimum required acquisition time .............................................. 344 calculating usb transceiver current ...................... 372 estimating usb transceiver current consumption ................................................... 371 errata ................................................................................... 7 eusart .......................................................................... 315 asynchronous mode ................................................ 325 12-bit break transmit and receive ................. 330 associated registers, reception ..................... 328 associated registers, transmission ............... 326 auto-wake-up on sync break ......................... 328 receiver .......................................................... 327 setting up 9-bit mode with address detect ........................................ 327 transmitter ...................................................... 325 baud rate generator operation in power-managed mode ................ 319 baud rate generator (brg) ................................... 319 associated registers ....................................... 320 auto-baud rate detect .................................... 323 baud rates, asynchronous modes ................. 321 formulas .......................................................... 319 high baud rate select (brgh bit) ................. 319 sampling ......................................................... 319 synchronous master mode ...................................... 331 associated registers, reception ..................... 334 associated registers, transmission ............... 332 reception ........................................................ 333 transmission ................................................... 331 synchronous slave mode ........................................ 335 associated registers, reception ..................... 337 associated registers, transmission ............... 336 reception ........................................................ 337 transmission ................................................... 335 extended instruction set addfsr .................................................................. 472 addulnk ............................................................... 472 callw .................................................................... 473 movsf .................................................................... 473 movss .................................................................... 474 pushl ..................................................................... 474 subfsr .................................................................. 475 subulnk ................................................................ 475 extended instructions considerations when enabling ................................ 476 external clock input ........................................................... 30 f fail-safe clock monitor ........................................... 411, 425 interrupts in power-managed modes ...................... 427 por or wake-up from sleep .................................. 427 wdt during oscillator failure ................................. 426 fast register stack ........................................................... 73 features overview ............................................................... 1 comparative table ...................................................... 2 firmware instructions ...................................................... 429
pic18f46j50 family ds39931b-page 540 preliminary ? 2009 microchip technology inc. flash program memory ...................................................... 95 associated registers ............................................... 104 control registers ....................................................... 96 eecon1 and eecon2 ..................................... 96 tablat (table latch) register ......................... 98 tblptr (table pointer) register ...................... 98 erase sequence ...................................................... 100 erasing ..................................................................... 100 operation during code-protect ............................... 104 reading ...................................................................... 99 table pointer boundaries based on operation ........................ 98 table pointer boundaries .......................................... 98 table reads and table writes .................................. 95 write sequence ....................................................... 101 writing ...................................................................... 101 unexpected termination .................................. 104 write verify ...................................................... 104 fscm. see fail-safe clock monitor. g goto ............................................................................... 450 h hardware multiplier .......................................................... 105 8 x 8 multiplication algorithms ................................. 105 operation ................................................................. 105 performance comparison (table) ............................. 105 high/low-voltage detect ................................................. 389 applications .............................................................. 393 associated registers ............................................... 394 characteristics ......................................................... 501 current consumption ............................................... 391 effects of a reset ..................................................... 394 operation ................................................................. 390 during sleep .................................................... 394 setup ........................................................................ 391 start-up time ........................................................... 391 typical application ................................................... 393 i i/o ports ........................................................................... 123 open-drain outputs ................................................. 124 pin capabilities ........................................................ 123 ttl input buffer option ........................................... 124 i 2 c mode .......................................................................... 280 i 2 c mode (mssp) acknowledge sequence timing ............................... 308 associated registers ............................................... 314 baud rate generator ............................................... 301 bus collision during a repeated start condition .................. 312 during a stop condition ................................... 313 clock arbitration ....................................................... 303 clock stretching ....................................................... 295 10-bit slave receive mode (sen = 1) ............. 295 10-bit slave transmit mode ............................. 295 7-bit slave receive mode (sen = 1) ............... 295 7-bit slave transmit mode ............................... 295 clock synchronization and ckp bit ......................... 296 effects of a reset ..................................................... 309 general call address support ................................. 299 i 2 c clock rate w/brg ............................................. 302 master mode ............................................................ 299 operation ......................................................... 301 reception ......................................................... 305 repeated start condition timing .................... 304 start condition timing ..................................... 303 transmission ................................................... 305 multi-master communication, bus collision and arbitration ................................................. 309 multi-master mode ................................................... 309 operation ................................................................. 285 read/write bit information (r/w bit) ............... 285, 288 registers ................................................................. 280 serial clock (sclx pin) ........................................... 288 slave mode .............................................................. 285 addressing ....................................................... 285 addressing masking modes 5-bit ......................................................... 286 7-bit ......................................................... 287 reception ........................................................ 288 transmission ................................................... 288 sleep operation ....................................................... 309 stop condition timing ............................................. 308 incf ................................................................................ 450 incfsz ............................................................................ 451 in-circuit debugger .......................................................... 428 in-circuit serial programming (icsp) ...................... 411, 428 indexed literal offset addressing and standard pic18 instructions ............................. 476 indexed literal offset mode ............................................. 476 indirect addressing ............................................................ 90 infsnz ............................................................................ 451 initialization conditions for all registers ............................ 68 instruction cycle ................................................................ 74 clocking scheme ....................................................... 74 flow/pipelining ........................................................... 74 instruction set .................................................................. 429 addlw .................................................................... 435 addwf .................................................................... 435 addwf (indexed literal offset mode) .................... 477 addwfc ................................................................. 436 andlw .................................................................... 436 andwf .................................................................... 437 bc ............................................................................ 437 bcf ......................................................................... 438 bn ............................................................................ 438 bnc ......................................................................... 439 bnn ......................................................................... 439 bnov ...................................................................... 440 bnz ......................................................................... 440 bov ......................................................................... 443 bra ......................................................................... 441 bsf .......................................................................... 441 bsf (indexed literal offset mode) .......................... 477 btfsc ..................................................................... 442 btfss ..................................................................... 442 btg ......................................................................... 443 bz ............................................................................ 444 call ........................................................................ 444 clrf ....................................................................... 445 clrwdt ................................................................. 445 comf ...................................................................... 446 cpfseq .................................................................. 446 cpfsgt .................................................................. 447 cpfslt ................................................................... 447 daw ........................................................................ 448 dcfsnz .................................................................. 449 decf ....................................................................... 448 decfsz .................................................................. 449
? 2009 microchip technology inc. preliminary ds39931b-page 541 pic18f46j50 family extended instructions .............................................. 471 considerations when enabling ........................ 476 syntax .............................................................. 471 use with mplab ide tools ............................. 478 general format ........................................................ 431 goto ...................................................................... 450 incf ......................................................................... 450 incfsz .................................................................... 451 infsnz .................................................................... 451 iorlw ..................................................................... 452 iorwf ..................................................................... 452 lfsr ........................................................................ 453 movf ....................................................................... 453 movff .................................................................... 454 movlb .................................................................... 454 movlw ................................................................... 455 movwf ................................................................... 455 mullw .................................................................... 456 mulwf .................................................................... 456 negf ....................................................................... 457 nop ......................................................................... 457 opcode field descriptions ....................................... 430 pop ......................................................................... 458 push ....................................................................... 458 rcall ..................................................................... 459 reset ..................................................................... 459 retfie .................................................................... 460 retlw .................................................................... 460 return .................................................................. 461 rlcf ........................................................................ 461 rlncf ..................................................................... 462 rrcf ....................................................................... 462 rrncf ................................ .................................... 463 setf ........................................................................ 463 setf (indexed literal offset mode) ........................ 477 sleep ..................................................................... 464 standard instructions ............................................... 429 subfwb .................................................................. 464 sublw .................................................................... 465 subwf .................................................................... 465 subwfb .................................................................. 466 swapf .................................................................... 466 tblrd ..................................................................... 467 tblwt ..................................................................... 468 tstfsz ................................................................... 469 xorlw .................................................................... 469 xorwf .................................................................... 470 intcon ........................................................................... 109 intcon registers ................................................... 109?111 inter-integrated circuit. see i 2 c. internal oscillator frequency drift. see intosc frequency drift. internal oscillator block ..................................................... 30 adjustment ................................................................. 31 osctune register ................................................... 31 internal rc oscillator use with wdt .......................................................... 421 internal voltage reference specific ations ....................... 499 internet address ............................................................... 549 interrupt sources ............................................................. 411 a/d conversion complete ....................................... 343 capture complete (eccp) ...................................... 240 compare complete (eccp) .................................... 241 interrupt-on-change (rb7:rb4) .............................. 130 tmr0 overflow ........................................................ 189 tmr1 overflow ........................................................ 197 tmr3 overflow ................................................ 205, 213 tmr4 to pr4 match ................................................ 216 tmr4 to pr4 match (pwm) .................................... 215 interrupts ......................................................................... 107 control bits .............................................................. 107 control registers. see intcon registers. during, context saving ............................................ 122 intx pin ................................................................... 122 portb, interrupt-on-change .................................. 122 rcon register ........................................................ 121 tmr0 ....................................................................... 122 interrupts, flag bits interrupt-on-change (rb7:rb4) flag (rbif bit) ......................................................... 130 intosc frequency drift .................................................... 31 intosc, intrc. see internal oscillator block. iorlw ............................................................................. 452 iorwf ............................................................................. 452 ipr registers ................................................................... 118 l lfsr ............................................................................... 453 low-power modes ............................................................. 39 clock transitions and status indicators .................... 40 deep sleep mode ...................................................... 46 and rtcc peripheral ........................................ 48 brown-out reset (dsbor) ................................ 48 fault detection .................................................. 48 preparing for ...................................................... 46 registers ........................................................... 49 typical sequence .............................................. 48 wake-up sources .............................................. 47 watchdog timer (dswdt) ................................ 47 exiting idle and sleep modes .................................... 45 by interrupt ........................................................ 45 by reset ............................................................ 45 by wdt time-out .............................................. 45 without an oscillator start-up delay ................. 46 idle modes ................................................................. 44 pri_idle .......................................................... 44 rc_idle ........................................................... 45 sec_idle ......................................................... 44 multiple sleep commands ......................................... 40 run modes ................................................................ 40 pri_run ........................................................... 40 rc_run ............................................................ 42 sec_run ......................................................... 40 sleep mode ............................................................... 43 summary (table) ........................................................ 40 ultra low-power wake-up ......................................... 52 m master clear (mclr ) ......................................................... 57 master synchronous serial port (mssp). see mssp. memory organization ........................................................ 69 data memory ............................................................. 76 program memory ....................................................... 69 return address stack ................................................ 71 memory programming requirements ...................... 498, 499 microchip internet web site ............................................. 549 movf .............................................................................. 453 movff ............................................................................ 454 movlb ............................................................................ 454 movlw ........................................................................... 455 movsf ............................................................................ 473
pic18f46j50 family ds39931b-page 542 preliminary ? 2009 microchip technology inc. movss ............................................................................ 474 movwf ........................................................................... 455 mplab asm30 assembler, linker, librarian .................. 480 mplab icd 2 in-circuit debugger ................................... 481 mplab ice 2000 high-performance universal in-circuit emulator ................................... 481 mplab integrated development environment software .............................................. 479 mplab pm3 device programmer .................................... 481 mplab real ice in-circuit emulator system ................ 481 mplink object linker/mplib object librarian ............... 480 mssp ack pulse ........................................................ 285, 288 i 2 c mode. see i 2 c mode. module overview ..................................................... 261 spi master/slave connection .................................. 266 tmr4 output for clock shift .................................... 216 mullw ............................................................................ 456 mulwf ............................................................................ 456 n negf ............................................................................... 457 nop ................................................................................. 457 o oscillator configuration internal oscillator block ............................................. 30 oscillator control ....................................................... 27 oscillator modes ........................................................ 27 oscillator modes and usb operation ........................ 28 oscillator types ......................................................... 27 oscillator configurations .................................................... 27 oscillator selection .......................................................... 411 oscillator settings for usb ................................................. 32 configuration options ................................................ 33 oscillator start-up timer (ost) ......................................... 37 oscillator switching ............................................................ 34 oscillator transitions .......................................................... 35 oscillator, timer1 ............................................. 191, 196, 209 oscillator, timer3 ............................................................. 205 p p1a/p1b/p1c/p1d. see enhanced capture/compare/pwm (eccp). packaging details ...................................................................... 525 marking .................................................................... 523 parallel master port (pmp) .............................................. 161 application examples ............................................... 183 associated registers ............................................... 185 data registers ......................................................... 168 master port modes ................................................... 175 module registers ..................................................... 162 slave port modes ..................................................... 170 peripheral pin select (pps) ............................................. 141 peripheral pin select registers ............................... 146?159 picstart plus development programmer .................... 482 pie registers ........................................................... 115?117 pin diagrams .................................................................... 3?5 pin functions av dd 1 ........................................................................ 26 av dd 2 ........................................................................ 26 av ss 1 ........................................................................ 26 mclr ................................................................... 14, 20 osc1/clki/ra7 .................................................. 14, 20 osc2/clko/ra6 ................................................ 14, 20 ra0/an0/c1ina/ulpwu/pma6/rp0 ....................... 21 ra0/an0/c1ina/ulpwu/rp0 .................................. 15 ra1/an1/c2ina/pma7/rp1 ..................................... 21 ra1/an1/c2ina/rp1 ................................................ 15 ra2/an2/v ref -/cv ref /c2inb ............................ 15, 21 ra3/an3/v ref +/c1inb ....................................... 15, 21 ra5/an4/ss1 /hlvdin/rcv/rp2 ....................... 15, 21 ra6 ...................................................................... 15, 21 ra7 ...................................................................... 15, 21 rb0/an12/int0/rp3 ........................................... 16, 22 rb1/an10/pmbe/rtccs/rp4 ................................. 22 rb1/an10/rtcc/rp4 ............................................... 16 rb2/an8/ctedg1/pma3/vmo/refo/rp5 ............. 22 rb2/an8/ctedg1/vmo/refo/rp5 ........................ 16 rb3/an9/ctedg2/pma2/vpo/rp6 ......................... 22 rb3/an9/ctedg2/vpo/rp6 .................................... 16 rb4/kbi0/sck1/scl1/rp7 ....................................... 17 rb4/pma1/kbi0/sck1/scl1/rp7 ............................ 23 rb5/kbi1/sdi1/sda1/rp8 ........................................ 17 rb5/pma0/kbi1/sdi1/sda1/rp8 ............................. 23 rb6/kbi2/pgc/rp9 ............................................ 17, 23 rb7/kbi3/pgd/rp10 .......................................... 17, 23 rc0/t1oso/t1cki/rp11 ................................... 18, 24 rc1/t1osi/uoe /rp12 ....................................... 18, 24 rc2/an11/ctpls/rp13 ..................................... 18, 24 rc4/d-/vm .......................................................... 18, 24 rc5/d+/vp .......................................................... 18, 24 rc6/pma5/tx1/ck1/rp17 ....................................... 24 rc6/tx1/ck1/rp17 .................................................. 18 rc7/pma4/rx1/dt1/sdo1/rp18 ............................ 24 rc7/rx1/dt1/sdo1/rp18 ....................................... 18 rd0/pmd0/scl2 ....................................................... 25 rd1/pmd1/sda2 ...................................................... 25 rd2/pmd2/rp19 ....................................................... 25 rd3/pmd3/rp20 ....................................................... 25 rd4/pmd4/rp21 ....................................................... 25 rd5/pmd5/rp22 ....................................................... 25 rd6/pmd6/rp23 ....................................................... 25 rd7/pmd7/rp24 ....................................................... 25 re0/an5/pmrd ........................................................ 26 re1/an6/pmwr ....................................................... 26 re2/an7/pmcs ........................................................ 26 v dd ............................................................................ 19 v dd 1 .......................................................................... 26 v dd 2 .......................................................................... 26 v ddcore /v cap .................................................... 19, 26 v ss 1 .................................................................... 19, 26 v ss 2 .................................................................... 19, 26 v usb .................................................................... 19, 26 pinout i/o descriptions pic18f2xj50 (28-pin) ............................................... 14 pic18f4xj50 (44-pin) ............................................... 20 pir registers ................................................................... 112 pll frequency multiplier ................................................... 30 pop ................................................................................. 458 por. see power-on reset. porta additional pin functions ultra low-power wake-up ................................. 52 associated registers ............................................... 129 lata register ......................................................... 127 porta register ...................................................... 127 trisa register ........................................................ 127
? 2009 microchip technology inc. preliminary ds39931b-page 543 pic18f46j50 family portb associated registers ............................................... 133 latb register .......................................................... 130 portb register ...................................................... 130 rb7:rb4 interrupt-on-change flag (rbif bit) ........ 130 trisb register ........................................................ 130 portc associated registers ............................................... 136 latc register ......................................................... 134 portc register ...................................................... 134 trisc register ........................................................ 134 portd associated registers ............................................... 138 latd register ......................................................... 137 portd register ...................................................... 137 trisd register ........................................................ 137 porte associated registers ............................................... 140 late register .......................................................... 139 porte register ...................................................... 139 trise register ........................................................ 139 power-managed modes and eusart operation ........................................... 319 and pwm operation ................................................ 259 and spi operation ................................................... 270 clock sources ............................................................ 39 entering ...................................................................... 39 selecting .................................................................... 39 power-on reset (por) ...................................................... 57 power-up delays ................................................................ 37 power-up timer (pwrt) ............................................. 37, 58 time-out sequence .................................................... 58 prescaler, timer0 ............................................................. 189 prescaler, timer2 (timer4) .............................................. 243 pri_idle mode ................................................................. 44 pri_run mode ................................................................. 40 product identification system .......................................... 551 program counter ............................................................... 71 pcl, pch and pcu registers ................................... 71 pclath and pclatu registers .............................. 71 program memory alu status ............................................................. 88 extended instruction set ............................................ 91 flash configuration words ........................................ 70 hard memory vectors ................................................ 70 instructions ................................................................. 75 two-word .......................................................... 75 interrupt vector .......................................................... 70 look-up tables .......................................................... 73 memory maps ............................................................ 69 hard vectors and configuration words ............. 70 reset vector .............................................................. 70 program verification and code protection ....................... 427 programming, device instructions ................................... 429 pulse steering .................................................................. 256 push ............................................................................... 458 push and pop instructions .............................................. 72 pushl ............................................................................. 474 pwm (ccp module) associated registers ............................................... 244 duty cycle ................................................................ 242 example frequencies/resolutions .......................... 243 operation setup ....................................................... 243 period ....................................................................... 242 pr2/pr4 registers ................................................. 242 tmr2 (tmr4) to pr2 (pr4) match ........................ 242 tmr4 to pr4 match ................................................ 215 pwm (eccp module) effects of a reset .................................................... 259 operation in power-managed modes ...................... 259 operation with fail-safe clock monitor ................... 259 pulse steering ......................................................... 256 steering synchronization ......................................... 258 pwm mode. see enhanced capture/compare/pwm .......................................... 245 q q clock ............................................................................ 243 r ram. see data memory. rbif bit ........................................................................... 130 rc_idle mode .................................................................. 45 rc_run mode .................................................................. 42 rcall ............................................................................. 459 rcon register bit status during initialization .................................... 60 reader response ............................................................ 550 real-time clock and calendar (rtcc) .......................... 217 operation ................................................................. 229 registers ................................................................. 218 reference clock output .................................................... 36 register file ....................................................................... 78 register file summary .......................................... 81, 81?87 registers adcon0 (a/d control 0) ......................................... 339 adcon1 (a/d control 1) ......................................... 340 alrmcfg (alarm configuration) ............................ 221 alrmday (alarm day value) ................................. 226 alrmhr (alarm hours value) ................................ 227 alrmmin (alarm minutes value) ........................... 228 alrmmnth (alarm month value) .......................... 226 alrmrpt (alarm calibration) ................................ 222 alrmsec (alarm seconds value) ......................... 228 alrmwd (alarm weekday value) .......................... 227 ancon0 (a/d port configuration 2) ....................... 341 ancon1 (a/d port configuration 1) ....................... 341 associated with comparator .................................... 377 associated with program flash memory ................. 104 baudconx (baud rate control) ............................ 318 bdnstat ................................................................ 359 bdnstat (buffer descriptor n status, cpu mode) ...................................................... 360 bdnstat (buffer descriptor n status, sie mode) .. 361 bdnstat (sie mode) ............................................. 361 buffer descriptors, summary .................................. 363 ccpxcon (enhanced capture/compare/pwm x control) .................. 238 cmstat (comparator status) ................................ 379 cmxcon (comparator control x) ........................... 378 config1h (configuration 1 high) .......................... 414 config1l (configuration 1 low) ........................... 413 config2h (configuration 2 high) .......................... 416 config2l (configuration 2 low) ........................... 415 config3h (configuration 3 high) .......................... 418 config3l (configuration 3 low) ........................... 417 config4h (configuration 4 high) .......................... 419 config4l (configuration 4 low) ........................... 418 ctmuconh (ctmu control high) ......................... 407 ctmuconl (ctmu control low) .......................... 408
pic18f46j50 family ds39931b-page 544 preliminary ? 2009 microchip technology inc. ctmuicon (ctmu current control) ...................... 409 cvrcon (comparator voltage reference control) ........................................... 386 day (day value) ...................................................... 224 devid1 (device id 1) .............................................. 419 devid2 (device id 2) .............................................. 420 dmacon1 (dma control 1) .................................... 274 dmacon2 (dma control 2) .................................... 275 dsconh (deep sleep control high byte) ................ 49 dsconl (deep sleep control low byte) ................. 49 dsgpr0 (deep sleep persistent general purpose 0) ............................................ 50 dsgpr1 (deep sleep persistent general purpose 1) ............................................ 50 dswakeh (deep sleep wake high byte) ................ 51 dswakel (deep sleep wake low byte) ................. 51 eccpxas (eccpx auto-shutdown control) ........... 253 eccpxdel (enhanced pwm control) .................... 256 eecon1 (eeprom control 1) .................................. 97 hlvdcon (high/low-voltage detect control) ........ 389 hours (hours value) ............................................. 225 i 2 c mode (mssp) .................................................... 280 intcon (interrupt control) ...................................... 109 intcon2 (interrupt control 2) ................................. 110 intcon3 (interrupt control 3) ................................. 111 ipr1 (peripheral interrupt priority 1) ........................ 118 ipr2 (peripheral interrupt priority 2) ........................ 119 ipr3 (peripheral interrupt priority 3) ........................ 120 minutes (minutes value) ....................................... 225 month (month value) ............................................ 223 odcon1 (peripheral open-drain control 1) ........... 125 odcon2 (peripheral open-drain control 2) ........... 125 odcon3 (peripheral open-drain control 3) ........... 126 osccon (oscillator control) .................................... 35 osctune (oscillator tuning) ................................... 32 padcfg1 (pad configuration control 1) ................ 126 padcfg1 (pad configuration) ................................ 220 parallel master port ................................................. 162 pie1 (peripheral interrupt enable 1) ........................ 115 pie2 (peripheral interrupt enable 2) ........................ 116 pie3 (peripheral interrupt enable 3) ........................ 117 pir1 (peripheral interrupt request (flag) 1) ........... 112 pir2 (peripheral interrupt request (flag) 2) ........... 113 pir3 (peripheral interrupt request (flag) 3) ........... 114 pmaddrh (parallel port address high byte) ......... 169 pmaddrl (parallel port address low byte) .......... 169 pmconh (parallel port control high byte) ............. 162 pmconl (parallel port control low byte) .............. 163 pmeh (parallel port enable high byte) ................... 166 pmel (parallel port enable low byte) .................... 166 pmmodeh (parallel port mode high byte) ............. 164 pmmodel (parallel port mode low byte) .............. 165 pmstath (parallel port status high byte) ............. 167 pmstatl (parallel port status low byte) .............. 167 ppscon (peripheral pin select input 0) ................. 146 pstrxcon (pulse steering control) ...................... 257 rcon (reset control) ....................................... 56, 121 rcstax (receive status and control) .................... 317 ref0con (reference clock output) ........................ 36 reserved .................................................................. 223 rpinr1 (peripheral pin select input 1) ................... 147 rpinr12 (peripheral pin select input 12) ............... 149 rpinr13 (peripheral pin select input 13) ............... 149 rpinr16 (peripheral pin select input 16) ............... 150 rpinr17 (peripheral pin select input 17) ............... 150 rpinr2 (peripheral pin select input 2) ................... 147 rpinr21 (peripheral pin select input 21) ............... 150 rpinr22 (peripheral pin select input 22) ............... 151 rpinr23 (peripheral pin select input 23) ............... 151 rpinr24 (peripheral pin select input 24) ............... 151 rpinr3 (peripheral pin select input 3) ................... 147 rpinr4 (peripheral pin select input 4) ................... 148 rpinr6 (peripheral pin select input 6) ................... 148 rpinr7 (peripheral pin select input 7) ................... 148 rpinr8 (peripheral pin select input 8) ................... 149 rpor0 (peripheral pin select output 0) ................. 152 rpor1 (peripheral pin select output 1) ................. 152 rpor10 (peripheral pin select output 10) ............. 155 rpor11 (peripheral pin select output 11) ............. 155 rpor12 (peripheral pin select output 12) ............. 156 rpor13 (peripheral pin select output 13) ............. 156 rpor17 (peripheral pin select output 17) ............. 156 rpor18 (peripheral pin select output 18) ............. 157 rpor19 (peripheral pin select output 19) ............. 157 rpor2 (peripheral pin select output 2) ................. 152 rpor20 (peripheral pin select output 20) ............. 157 rpor21 (peripheral pin select output 21) ............. 158 rpor22 (peripheral pin select output 22) ............. 158 rpor23 (peripheral pin select output 23) ............. 158 rpor24 (peripheral pin select output 24) ............. 159 rpor3 (peripheral pin select output 3) ................. 153 rpor4 (peripheral pin select output 4) ................. 153 rpor5 (peripheral pin select output 5) ................. 153 rpor6 (peripheral pin select output 6) ................. 154 rpor7 (peripheral pin select output 7) ................. 154 rpor8 (peripheral pin select output 8) ................. 154 rpor9 (peripheral pin select output 9) ................. 155 rtccal (rtcc calibration) ................................... 220 rtccfg (rtcc configuration) .............................. 219 seconds (seconds value) ................................... 225 spi mode (mssp) ................................................... 263 sspxcon1 (msspx control 1, i 2 c mode) .............. 282 sspxcon1 (msspx control 1, spi mode) ............. 264 sspxcon2 (msspx control 2, i 2 c master mode) ............................................ 283 sspxcon2 (msspx control 2, i 2 c slave mode) .............................................. 284 sspxmsk (i 2 c slave address mask) ...................... 284 sspxstat (msspx status, i 2 c mode) ................... 281 sspxstat (msspx status, spi mode) .................. 263 status .................................................................... 88 stkptr (stack pointer) ............................................ 72 t0con (timer0 control) ......................................... 187 t1con (timer1 control) ......................................... 191 t1gcon (timer1 gate control) .............................. 192 t2con (timer2 control) ......................................... 203 t3con (timer3 control) ......................................... 205 t3gcon (timer3 gate control) .............................. 206 t4con (timer4 control) ......................................... 215 tclkcon (timer clock control) .................... 193, 207 txstax (transmit status and control) ................... 316 uaddr .................................................................... 357 ucfg (usb configuration) ..................................... 353 ucon (usb control) ............................................... 351 ueie (usb error interrupt enable) .......................... 369 ueir (usb error interrupt status) ........................... 368 uepn (usb endpoint n control) .............................. 356 ufrmh:ufrml ...................................................... 357 uie (usb interrupt enable) ..................................... 367 uir (usb interrupt status) ...................................... 365
? 2009 microchip technology inc. preliminary ds39931b-page 545 pic18f46j50 family ustat (usb status) ............................................... 355 wdtcon (watchdog timer control) ...................... 422 wkdy (weekday value) .......................................... 224 year (year value) .................................................. 223 reset ............................................................................. 459 reset .................................................................................. 55 brown-out reset ........................................................ 57 brown-out reset (bor) ............................................. 55 configuration mismatch (cm) .................................... 55 configuration mismatch reset ................................... 58 deep sleep ................................................................ 55 fast register stack .................................................... 73 mclr ......................................................................... 57 mclr reset, during power-managed modes ........... 55 mclr reset, normal operation ................................ 55 power-on reset ......................................................... 57 power-on reset (por) .............................................. 55 power-up timer ......................................................... 58 reset instruction ..................................................... 55 stack full reset ......................................................... 55 stack underflow reset .............................................. 55 state of registers ...................................................... 60 watchdog timer (wdt) reset ................................... 55 resets .............................................................................. 411 brown-out reset (bor) ........................................... 411 oscillator start-up timer (ost) ............................... 411 power-on reset (por) ............................................ 411 power-up timer (pwrt) ......................................... 411 retfie ............................................................................ 460 retlw ............................................................................ 460 return .......................................................................... 461 return address stack ........................................................ 71 associated registers ................................................. 71 revision history ............................................................... 535 rlcf ................................................................................ 461 rlncf ............................................................................. 462 rrcf ............................................................................... 462 rrncf ................. ........................................................... 463 rtcc alarm ........................................................................ 233 configuring ...................................................... 233 interrupt ........................................................... 234 mask settings .................................................. 233 alarm value registers (alrmval) ......................... 226 control registers ..................................................... 219 low-power modes ................................................... 234 operation calibration ........................................................ 232 clock source ................................................... 230 digit carry rules .............................................. 230 general functionality ....................................... 231 leap year ........................................................ 231 register mapping ............................................. 231 alrmval ................................................ 232 rtcval ................................................... 232 safety window for register reads and writes .................................... 231 write lock ........................................................ 231 peripheral module disable (pmd) register ............. 235 register interface ..................................................... 229 register maps .......................................................... 235 reset ....................................................................... 234 device ............................................................. 234 power-on reset (por) .................................... 234 value registers (rtcval) ...................................... 223 rtcen bit write .............................................................. 229 s sckx ............................................................................... 262 sdix ................................................................................. 262 sdox ............................................................................... 262 sec_idle mode ............................................................... 44 sec_run mode ................................................................ 40 serial clock, sckx .......................................................... 262 serial data in (sdix) ........................................................ 262 serial data out (sdox) ................................................... 262 serial peripheral interface. see spi mode. setf ............................................................................... 463 shoot-through current .................................................... 255 slave select (ssx ) ........................................................... 262 sleep ............................................................................. 464 software simulator (mplab sim) ................................... 480 special event trigger. see compare (eccp mode). special features of the cpu ........................................... 411 spi mode (mssp) ........................................................... 262 associated registers ............................................... 271 bus mode compatibility ........................................... 270 clock speed, interactions ........................................ 270 effects of a reset .................................................... 270 enabling spi i/o ...................................................... 266 master mode ............................................................ 267 master/slave connection ........................................ 266 operation ................................................................. 265 open-drain output option ............................... 265 operation in power-managed modes ...................... 270 registers ................................................................. 263 serial clock ............................................................. 262 serial data in ........................................................... 262 serial data out ........................................................ 262 slave mode .............................................................. 268 slave select ............................................................. 262 slave select synchronization .................................. 268 spi clock ................................................................. 267 sspxbuf register .................................................. 267 sspxsr register .................................................... 267 typical connection .................................................. 266 sspov ............................................................................ 305 sspov status flag ......................................................... 305 sspxstat register r/w bit ............................................................ 285, 288 ssx .................................................................................. 262 stack full/underflow resets .............................................. 73 subfsr .......................................................................... 475 subfwb ......................................................................... 464 sublw ............................................................................ 465 subulnk ........................................................................ 475 subwf ............................................................................ 465 subwfb ......................................................................... 466 swapf ............................................................................ 466
pic18f46j50 family ds39931b-page 546 preliminary ? 2009 microchip technology inc. t table pointer operations (table) ........................................ 98 table reads/table writes .................................................. 73 t ad ................................................................................... 345 tblrd ............................................................................. 467 tblwt ............................................................................. 468 timer0 .............................................................................. 187 associated registers ............................................... 189 operation ................................................................. 188 overflow interrupt .................................................... 189 prescaler .................................................................. 189 switching assignment ...................................... 189 prescaler assignment (psa bit) .............................. 189 prescaler select (t0ps2:t0ps0 bits) ..................... 189 reads and writes in 16-bit mode ............................ 188 source edge select (t0se bit) ................................ 188 source select (t0cs bit) ......................................... 188 timer1 .............................................................................. 191 16-bit read/write mode ........................................... 196 associated registers ............................................... 202 clock source selection ............................................ 194 gate ......................................................................... 198 interrupt .................................................................... 197 operation ................................................................. 194 oscillator .......................................................... 191, 196 layout considerations ..................................... 197 resetting, using the eccp special event trigger ....................................... 198 tmr1h register ...................................................... 191 tmr1l register ....................................................... 191 use as a clock source ............................................ 197 timer2 .............................................................................. 203 associated registers ............................................... 204 interrupt .................................................................... 204 operation ................................................................. 203 output ...................................................................... 204 timer3 .............................................................................. 205 16-bit read/write mode ........................................... 209 associated registers ............................................... 213 gate ......................................................................... 209 operation ................................................................. 208 oscillator .......................................................... 205, 209 overflow interrupt ............................................ 205, 213 special event trigger (eccp) ................................. 213 tmr3h register ...................................................... 205 tmr3l register ....................................................... 205 timer4 .............................................................................. 215 associated registers ............................................... 216 interrupt .................................................................... 216 mssp clock shift ..................................................... 216 operation ................................................................. 215 output ...................................................................... 216 postscaler. see postscaler, timer4. pr4 register ............................................................ 215 prescaler. see prescaler, timer4. tmr4 register ......................................................... 215 tmr4 to pr4 match interrupt .......................... 215, 216 timing diagrams a/d conversion ........................................................ 520 asynchronous reception ......................................... 328 asynchronous transmission .................................... 326 asynchronous transmission (back-to-back) ........... 326 automatic baud rate calculation ............................ 324 auto-wake-up bit (wue) during normal operation ......................................................... 329 auto-wake-up bit (wue) during sleep ................... 329 baud rate generator with clock arbitration ............ 303 brg overflow sequence ......................................... 324 brg reset due to sdax arbitration during start condition ................................................. 311 bus collision during a repeated start condition (case 1) ........................................... 312 bus collision during a repeated start condition (case 2) ........................................... 312 bus collision during a start condition (sclx = 0) ....................................... 311 bus collision during a stop condition (case 1) ........................................... 313 bus collision during a stop condition (case 2) ........................................... 313 bus collision during start condition (sdax only) .................................... 310 bus collision for transmit and acknowledge .......... 309 clko and i/o .......................................................... 505 clock synchronization ............................................. 296 clock/instruction cycle .............................................. 74 enhanced capture/compare/pwm ......................... 508 eusartx synchronous receive (master/slave) ................................................. 519 eusartx synchronous transmission (master/slave) ................................................. 519 example spi master mode (cke = 0) ..................... 511 example spi master mode (cke = 1) ..................... 512 example spi slave mode (cke = 0) ....................... 513 example spi slave mode (cke = 1) ....................... 514 external clock .......................................................... 503 fail-safe clock monitor ........................................... 426 first start bit ............................................................ 303 full-bridge pwm output .......................................... 250 half-bridge pwm output ................................. 248, 255 high/low-voltage detect characteristics ................ 501 high-voltage detect (vdirmag = 1) ...................... 393 i 2 2c bus data .......................................................... 515 i 2 c acknowledge sequence .................................... 308 i 2 c bus start/stop bits ............................................ 515 i 2 c master mode (7 or 10-bit transmission) ........... 306 i 2 c master mode (7-bit reception) .......................... 307 i 2 c slave mode (10-bit reception, sen = 0, admsk = 01001) ............................................ 292 i 2 c slave mode (10-bit recepti on, sen = 0) .......... 293 i 2 c slave mode (10-bit recepti on, sen = 1) .......... 298 i 2 c slave mode (10-bit transmission) .................... 294 i 2 c slave mode (7-bit reception, sen = 0, admsk = 01011) ............................................ 290 i 2 c slave mode (7-bit reception, sen = 0) ............ 289 i 2 c slave mode (7-bit reception, sen = 1) ............ 297 i 2 c slave mode (7-bit transmission) ...................... 291 i 2 c slave mode general call address sequence (7 or 10-bit a ddressing mode) ....... 299 i 2 c stop condition receive or transmit mode ........ 308 low-voltage detect (vdirmag = 0) ....................... 392 msspx i 2 c bus data ............................................... 517 msspx i 2 c bus start/stop bits ............................... 517 parallel master port read ........................................ 509 parallel master port write ........................................ 510 parallel slave port read .................................. 171, 173 parallel slave port write .................................. 171, 174 pwm auto-shutdown with auto-restart enabled ........................................................... 254 pwm auto-shutdown with firmware restart .......... 254
? 2009 microchip technology inc. preliminary ds39931b-page 547 pic18f46j50 family pwm direction change ........................................... 251 pwm direction change at near 100% duty cycle ............................................. 252 pwm output ............................................................ 242 pwm output (active-high) ....................................... 246 pwm output (active-low) ....................................... 247 read and write, 8-bit data, demultiplexed address ............................................................ 178 read, 16-bit data, demultiplexed address ............. 181 read, 16-bit multiplexed data, fully multiplexed 16-bit address .............................. 182 read, 16-bit multiplexed data, partially multiplexed address ........................................ 181 read, 8-bit data, fully multiplexed 16-bit address ................................................. 180 read, 8-bit data, partially multiplexed address ...... 178 read, 8-bit data, partially multiplexed address, enable strobe ................................... 179 read, 8-bit data, wait states enabled, partially multiplexed address ........................... 178 repeated start condition ......................................... 304 reset, watchdog timer (wdt), oscillator start-up timer (ost) and power-up timer (pwrt) ..... 506 send break character sequence ............................ 330 slave synchronization ............................................. 268 slow rise time (mclr tied to v dd , v dd rise > t pwrt ) ............................................ 59 spi mode (master mode) ......................................... 267 spi mode (slave mode, cke = 0) ........................... 269 spi mode (slave mode, cke = 1) ........................... 269 steering event at beginning of instruction (strsync = 1) ............................................... 258 steering event at end of instruction (strsync = 0) ............................................... 258 synchronous reception (master mode, sren) ...... 333 synchronous transmission ...................................... 331 synchronous transmission (through txen) .......... 332 time-out sequence on power-up (mclr not tied to v dd ), case 1 ................................... 59 time-out sequence on power-up (mclr not tied to v dd ), case 2 ................................... 59 time-out sequence on power-up (mclr tied to v dd , v dd rise < t pwrt ) ........................ 58 timer pulse generation ........................................... 234 timer0 and timer1 external clock .......................... 507 timer1 gate count enable mode ............................ 198 timer1 gate single pulse mode .............................. 201 timer1 gate single pulse/toggle combined mode .............................................. 202 timer1 gate toggle mode ....................................... 200 timer3 gate count enable mode ............................ 209 timer3 gate single pulse mode .............................. 211 timer3 gate single pulse/toggle combined mode .............................................. 212 timer3 gate toggle mode ....................................... 210 transition for entry to idle mode ................................ 44 transition for entry to sec_run mode .................... 41 transition for entry to sleep mode ............................ 43 transition for two-speed start-up (intrc to hspll) ........................................... 425 transition for wake from idle to run mode .............. 45 transition for wake from sleep (hspll) ................. 43 transition from rc_run mode to pri_run mode ................................................. 42 transition from sec_run mode to pri_run mode (hspll) .................................. 41 transition to rc_run mode ..................................... 42 usb signal .............................................................. 521 write, 16-bit data, demultiplexed address ............. 181 write, 16-bit multiplexed data, fully multiplexed 16-bit address .............................. 182 write, 16-bit multiplexed data, partially multiplexed address ........................................ 182 write, 8-bit data, fully multiplexed 16-bit address ................................................. 180 write, 8-bit data, partially multiplexed address ...... 179 write, 8-bit data, partially multiplexed address, enable strobe ................................... 180 write, 8-bit data, wait states enabled, partially multiplexed address .......................... 179 timing diagrams and specifications ac characteristics internal rc accuracy ....................................... 504 clko and i/o requirements ................................... 505 enhanced capture/compare/pwm requirements .................................................. 508 eusartx synchronous receive requirements ..... 519 eusartx synchronous transmission requirements .................................................. 519 example spi mode requirements (master mode, cke = 0) .................................. 511 example spi mode requirements (master mode, cke = 1) .................................. 512 example spi mode requirements (slave mode, cke = 0) .................................... 513 example spi slave mode requirements (cke = 1) ......................................................... 514 external clock requirements .................................. 504 i 2 c bus data requirements (slave mode) .............. 516 i 2 c bus start/stop bits requirements (slave mode) ................................................... 515 msspx i 2 c bus data requirements ....................... 518 msspx i 2 c bus start/stop bits requirements ........ 517 parallel master port read requirements ................ 509 parallel master port write requirements ................ 510 pll clock ................................................................ 504 reset, watchdog timer, oscillator start-up timer, power-up timer and brown-out reset requirements ........................................ 506 timer0 and timer1 external clock requirements .................................................. 507 usb full-speed requirements ............................... 521 usb low-speed requirements ............................... 521 tstfsz ........................................................................... 469 two-speed start-up ................................................. 411, 425 two-word instructions example cases ......................................................... 75 txstax register brgh bit ................................................................. 319
pic18f46j50 family ds39931b-page 548 preliminary ? 2009 microchip technology inc. u ultra low-power wake-up ................................................. 52 universal serial bus ......................................................... 349 address register (uaddr) ..................................... 357 associated registers ............................................... 373 buffer descriptor table ............................................ 358 buffer descriptors .................................................... 358 address validation ........................................... 361 assignment in different buffering modes ......... 363 bdnstat register (cpu mode) ..................... 359 bdnstat register (sie mode) ....................... 361 byte count ....................................................... 361 example ........................................................... 358 memory map .................................................... 362 ownership ........................................................ 358 ping-pong buffering ......................................... 362 register summary ........................................... 363 status and configuration ................................. 358 endpoint control ...................................................... 356 external pull-up resistors ........................................ 354 eye pattern test enable .......................................... 354 firmware and drivers ............................................... 373 frame number registers ......................................... 357 internal pull-up resistors ......................................... 354 internal transceiver ................................................. 352 interrupts .................................................................. 364 and usb transactions ..................................... 364 oscillator requirements ........................................... 373 overview .......................................................... 349, 374 class specifications and drivers ..................... 375 descriptors ....................................................... 375 enumeration ..................................................... 375 frames ............................................................. 374 layered framework ......................................... 374 power ............................................................... 374 speed ............................................................... 375 transfer types ................................................. 374 ping-pong buffer configuration ............................... 354 power modes ........................................................... 370 bus power only ............................................... 370 dual power with self-power dominance ......... 370 self-power only ............................................... 370 transceiver current consumption ................... 371 ram ......................................................................... 357 memory map .................................................... 357 status and control ................................................... 350 ufrmh:ufrml registers ...................................... 357 usb specifications ........................................................... 500 usb. see universal serial bus. v voltage reference specifications .................................... 498 voltage regulator (on-chip) ........................................... 423 operation in sleep mode ......................................... 424 w watchdog timer (wdt) ........................................... 411, 421 associated registers ............................................... 422 control register ....................................................... 421 during oscillator failure .......................................... 426 programming considerations .................................. 421 wcol ...................................................... 303, 304, 305, 308 wcol status flag ................................... 303, 304, 305, 308 www address ................................................................ 549 www, on-line support ........ .............................................. 7 x xorlw ............................................................................ 469 xorwf ........................................................................... 470
? 2009 microchip technology inc. preliminary ds39931b-page 549 pic18f46j50 family the microchip web site microchip provides online support via our www site at www.microchip.com. this web site is used as a means to make files and information easily available to customers. accessible by using your favorite internet browser, the web site contains the following informa- tion: ? product support ? data sheets and errata, appli- cation notes and sample programs, design resources, user?s guides and hardware support documents, latest software releases and archived software ? general technical support ? frequently asked questions (faq), technical support requests, online discussion groups, microchip consultant program member listing ? business of microchip ? product selector and ordering guides, latest microchip press releases, listing of seminars and events, listings of micro- chip sales offices, distributors and factory repre- sentatives customer change notification service microchip?s customer notification service helps keep customers current on microchip products. subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a spec- ified product family or development tool of interest. to register, access the microchip web site at www.microchip.com, click on customer change notifi- cation and follow the registration instructions. customer support users of microchip products can receive assistance through several channels: ? distributor or representative ? local sales office ? field application engineer (fae) ? technical support ? development systems information line customers should contact their distributor, representa- tive or field application engineer (fae) for support. local sales offices are also available to help custom- ers. a listing of sales offices and locations is included in the back of this document. technical support is available through the web site at: http://support.microchip.com
pic18f46j50 family ds39931b-page 550 preliminary ? 2009 microchip technology inc. reader response it is our intention to provide you with the best documentation possible to ensure successful use of your microchip prod- uct. if you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information, and use this outline to provide us with your comments about this document. to : technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds39931b pic18f46j50 family 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document?
? 2009 microchip technology inc. preliminary ds39931b-page 551 pic18f46j50 family product identification system to order or obtain information, e. g., on pricing or delivery, refer to the factory or the listed sales office . part no. x /xx xxx pattern package temperature range device device pic18f24j50 pic18f25j50 pic18f26j50 pic18f44j50 pic18f45j50 pic18f46j50 pic18lf24j50 pic18lf25j50 pic18lf26j50 pic18lf44j50 pic18lf45j50 pic18lf46j50 temperature range i = -40 c to +85 c (industrial) package sp = skinny pdip ss = ssop so = soic ml = qfn pt = tqfp (thin quad flatpack) pattern qtp, sqtp, code or special requirements (blank otherwise) examples: a) pic18f46j50-i/pt 301 = industrial temp., tqfp package, qtp pattern #301. b) pic18f46j50t-i/pt = tape and reel, industrial temp., tqfp package.
ds39931b-page 552 preliminary ? 2009 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: http://support.microchip.com web address: www.microchip.com atlanta duluth, ga tel: 678-957-9614 fax: 678-957-1455 boston westborough, ma tel: 774-760-0087 fax: 774-760-0088 chicago itasca, il tel: 630-285-0071 fax: 630-285-0075 cleveland independence, oh tel: 216-447-0464 fax: 216-447-0643 dallas addison, tx tel: 972-818-7423 fax: 972-818-2924 detroit farmington hills, mi tel: 248-538-2250 fax: 248-538-2260 kokomo kokomo, in tel: 765-864-8360 fax: 765-864-8387 los angeles mission viejo, ca tel: 949-462-9523 fax: 949-462-9608 santa clara santa clara, ca tel: 408-961-6444 fax: 408-961-6445 toronto mississauga, ontario, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific asia pacific office suites 3707-14, 37th floor tower 6, the gateway harbour city, kowloon hong kong tel: 852-2401-1200 fax: 852-2401-3431 australia - sydney tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing tel: 86-10-8528-2100 fax: 86-10-8528-2104 china - chengdu tel: 86-28-8665-5511 fax: 86-28-8665-7889 china - hong kong sar tel: 852-2401-1200 fax: 852-2401-3431 china - nanjing tel: 86-25-8473-2460 fax: 86-25-8473-2470 china - qingdao tel: 86-532-8502-7355 fax: 86-532-8502-7205 china - shanghai tel: 86-21-5407-5533 fax: 86-21-5407-5066 china - shenyang tel: 86-24-2334-2829 fax: 86-24-2334-2393 china - shenzhen tel: 86-755-8203-2660 fax: 86-755-8203-1760 china - wuhan tel: 86-27-5980-5300 fax: 86-27-5980-5118 china - xiamen tel: 86-592-2388138 fax: 86-592-2388130 china - xian tel: 86-29-8833-7252 fax: 86-29-8833-7256 china - zhuhai tel: 86-756-3210040 fax: 86-756-3210049 asia/pacific india - bangalore tel: 91-80-3090-4444 fax: 91-80-3090-4080 india - new delhi tel: 91-11-4160-8631 fax: 91-11-4160-8632 india - pune tel: 91-20-2566-1512 fax: 91-20-2566-1513 japan - yokohama tel: 81-45-471- 6166 fax: 81-45-471-6122 korea - daegu tel: 82-53-744-4301 fax: 82-53-744-4302 korea - seoul tel: 82-2-554-7200 fax: 82-2-558-5932 or 82-2-558-5934 malaysia - kuala lumpur tel: 60-3-6201-9857 fax: 60-3-6201-9859 malaysia - penang tel: 60-4-227-8870 fax: 60-4-227-4068 philippines - manila tel: 63-2-634-9065 fax: 63-2-634-9069 singapore tel: 65-6334-8870 fax: 65-6334-8850 taiwan - hsin chu tel: 886-3-572-9526 fax: 886-3-572-6459 taiwan - kaohsiung tel: 886-7-536-4818 fax: 886-7-536-4803 taiwan - taipei tel: 886-2-2500-6610 fax: 886-2-2508-0102 thailand - bangkok tel: 66-2-694-1351 fax: 66-2-694-1350 europe austria - wels tel: 43-7242-2244-39 fax: 43-7242-2244-393 denmark - copenhagen tel: 45-4450-2828 fax: 45-4485-2829 france - paris tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany - munich tel: 49-89-627-144-0 fax: 49-89-627-144-44 italy - milan tel: 39-0331-742611 fax: 39-0331-466781 netherlands - drunen tel: 31-416-690399 fax: 31-416-690340 spain - madrid tel: 34-91-708-08-90 fax: 34-91-708-08-91 uk - wokingham tel: 44-118-921-5869 fax: 44-118-921-5820 w orldwide s ales and s ervice 02/04/09


▲Up To Search▲   

 
Price & Availability of PIC18LF26J50T-ISO

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X