vin “Low-Pincount Workshop” Uporaba MPLAB® IDE & FLASH Starter Kit PICkitTM 1 © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 1 vin Izvedba: Elbacomp © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 2 vin Urnik: Predstavitev in PC / MPLAB nastavitve PICkitTM1 – Start Kaj je MPLAB® 7.xx Več o PicKit-1 Praktična uporaba PICkitTM1 Arhitektura PIC12F675 Primeri programov Pregled razvojnih orodij © 2003 Microchip Technology Incorporated. All Rights Reserved. 9:00 - 9:20 9:20 -9:40 9:40 -10:00 10:00 -10:45 11:00-12:30 13:30-14:00 14:00-15:45 15:45-16:00 Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 3 vin Predstavitev Elbacomp d.o.o. in Microchip Technology © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 4 vin Corporate Overview Leading semiconductor manufacturer: of high-performance, field-programmable, 8-bit & 16-bit RISC Microcontrollers of Analog & Interface products of related Memory products for high-volume embedded control applications $572M in product sales in FY02, $700M run rate today Almost 3,000 employees Headquartered near Phoenix in Chandler, AZ “The Silicon Desert” © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 5 vin Worldwide Technical Support Centers & Manufacturing Facilities Oregon Manufacturing •. Toronto Chicago Detroit Boston Kokomo New York San Jose Los Angeles Phoenix Dallas Atlanta •. London Copenhagen Paris Munich Milan Shanghai Test & Assembly •.•. Seoul Beijing Shin-Yokohama Qingdao Shanghai Chengdu Fuzhou Taipei Bangalore Shenzhen Kaohsiung Hong Kong Singapore Arizona Manufacturing and Corporate HQ Bangkok Test & Assembly Sydney © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 6 vin TM PICkit 1 FLASH Starter Kit Start…... © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 7 vin © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 8 vin PICkitTM 1 FLASH Starter Kit © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 9 vin PICkitTM 1 Hardware Features The Programmer •Uses PIC16C745 •CCP Driven Charge pump for Vpp voltage. •USB Powered. •Can write 1k words in 8 seconds. •Minimum parts count for minimum cost. © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 10 vin PICkitTM 1 Hardware Features •Supports 8/14 pin Flash devices •Programmed via ICSP •Includes a button & Potentiometer © 2003 Microchip Technology Incorporated. All Rights Reserved. The 8/14 pin Evaluation •Shows multiplexing of 12 LED’s (8 provided) •I/O pins are attached to an expansion header. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 11 vin PICkitTM 1 Hardware Prototyping Area Innovative Snap-off Prototyping area Patterns placed for RS-232 interface & 5v power supply. Pattern also placed for 14 pin DIP & decoupling capacitor © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 12 vin PICkitTM 1 GUI GUI runs independently from MPLAB. GUI gives access to all PICkitTM 1 features. Read/write/erase/verify Source code for GUI is provided. © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 13 vin PICkitTM 1 Package Features •PICkitTM 1 Hardware Kit •USB cable •Quickstart Guide •Tips n’ Tricks •MPLAB® CDROM •PICkitTM 1 CDROM Users Manual Example Software PICkitTM 1 Programmer GUI © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 14 vin Getting Started Install PICkitTM1 CD-ROM Select Quick Start / Install PICkitTM1 Software from menu Connect USB cable to PC and PICkitTM1 Demonstration software has already been downloaded to the PICmicro in the PICkitTM1 For proper operation LEDs will sequentially blink ON and OFF Press switch SW1 to reverse blinking sequence © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 15 vin Directories….. PICkitTM1 Flash Starterkit : use defaults MPLAB® 6.xxx: Workshop-files: c:\lessons © 2003 Microchip Technology Incorporated. All Rights Reserved. use defaults Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 16 vin ® MPLAB IDE CD It’s Free! User Guides Dev Tools Guide 3rd Party Guide Data sheets w/ errata’s Free Demo Compilers Quarterly Product Line Card © 2003 Microchip Technology Incorporated. All Rights Reserved. DS51123 Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 17 vin ® MPLAB 7.xx Predstavitev kako uporabiti….. © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 18 vin MPLAB® 7.xx Layout Tool Bar Buttons are added to the Toolbar as features are enabled Project Window Workspace Output Window (tabs are added as tools are enabled) Status Bar © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 19 vin Workspace: MPLAB® IDE Setup Information Contains setup information which includes: – Selected device from menu – Debug tool and/or programmer – Open windows used and their location – IDE configuration settings Project: Contains source files needed to build and test an application © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 20 vin MPLAB® IDE Windows Windows available in a new workspace Project Output Disassembly Watch Hardware Stack Program memory File Registers EEPROM data Special Function Registers © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 21 vin Project Project files within a project by file type: – Source Files, Header Files, Object Files, Library Files & Linker Scripts Output MPLAB® IDE Window Descriptions Tabbed information about program output Disassembly Disassembled code is viewed – Breakpoints can be set in code © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 22 vin Watch Program symbols can be monitored and displayed while program is running Hardware stack MPLAB® IDE Window Descriptions (cont.) Stack data is displayed in 3 columns – Top of Stack, Stack level & return address Program memory Opcodes are displayed 5 different ways – Opcode Hex, Machine & Symbolic © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 23 vin File registers General purpose registers are displayed EEPROM Data MPLAB® IDE Window Descriptions (cont.) Data memory stored in EEPROM is displayed Special Function Registers (SFR) Symbolic names for SFRs are displayed © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 24 vin MPLAB® v6.20 IDE With Sample Code Loaded DSC Division Review October 2002 © 2003 Microchip Technology Incorporated. All Rights Reserved. Microchip Confidential Slide 6 Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 25 vin Creating a Project Objectives Using the Project Wizard in MPLAB® IDE Creating simple MPASM™ code written in MPLAB® IDE (nop.asm) Building code in MPLAB® IDE Introduce the Output Window and Program Memory Window Selecting Build Options © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 26 vin MPLAB® IDE: Using Project Wizard Starting a new project Select: Project-> Project Wizard Select: Next © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 27 vin Project Wizard: Select Device Step 1: Select: PIC12F675 Select: Next © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 28 vin Project Wizard: Select Toolsuite Step 2: Select: Microchip MPASM™ Toolsuite Select: Next © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 29 vin Project Wizard: Select Name Step 3: Project Directory: C:\ProgramFiles\Microchip\PICkit1\Tutorials Project Name: Select: © 2003 Microchip Technology Incorporated. All Rights Reserved. Workshop In A Box Next Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 30 vin Project Wizard: Summary Step 4: Summary of new project parameters Select: Finish © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 31 vin Project Wizard Completed Project name assigned Next step is to make this project useful Windows are added which display debugging capabilities of MPLAB® IDE © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 32 vin How to Open Windows in MPLAB® IDE MPLAB® Workspace configured for use Select View -> Output View -> Dissasembly View -> Watch View -> Hardware Stk View -> Pgm Memory View -> File Registers View -> EEPROM View -> SFRs © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 33 vin MPLAB® Windows Open With No Code Loaded © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 34 vin Select a MPLAB® SIM Debug Tool Debugger -> Select Tool -> MPLAB SIM MPLAB SIM chosen for this example © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 35 vin Adding Symbols to Monitor in Watch Window View -> Watch enter registers/variables to watch click “Add SFR” or “Add Symbol” © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 36 vin Debugging using MPSIM™ Simulator The MPLAB® IDE Program Project Window Source Code Output Window Watch Window © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 37 vin Setup Configuration Bits in PICmicro® MCUs PIC® MCUs have Configuration Bits Configuration bits are setup at program or debug time. Set the Configuration Bits first, with Configure -> Configuration Bits, then program the device. © 2003 Microchip Technology Incorporated. All Rights Reserved. Configuration Bits are Important! Read the data sheet for your specific chip! Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 38 vin MPLAB® Project With Labels W Register Status Register: UC=1, LC=0 Program Counter Checksum Device © 2003 Microchip Technology Incorporated. All Rights Reserved. Word Wrap Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 39 vin PIC12F675 Arhitektura © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 40 vin PIC12F629/675 Block Diagram © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 41 vin 8-Pin & 14-Pin Features PIC12F629/ PIC12F675 1.8K Bytes Flash Program (1Kw) 64 Bytes Data RAM 128 Bytes Data EEPROM 1 Comparator 1x8, 1x16 bit counters Precision Internal OSC Brown-Out Reset (BOR) Watchdog Timer (WDT) PDIP, SOIC, DFN 4 x 10-bit A/D (12F675) © 2003 Microchip Technology Incorporated. All Rights Reserved. PIC16F630/ PIC16F676 1.8K Bytes Flash Program (1Kw) 64 Bytes Data RAM 128 Bytes Data EEPROM 1 Comparator 1x8, 1x16 bit counters Precision Internal OSC Brown-Out Reset (BOR) Watchdog Timer (WDT) PDIP, SOIC, TSSOP 8 x 10-bit A/D (16F676) Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 42 vin PIC12F6xx <-> PIC16F630/676 8 x 10-bit A/D PIC16F630 PIC16F676 4 x 10-bit A/D PIC12F629 © 2003 Microchip Technology Incorporated. All Rights Reserved. PIC12F675 Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 43 VDD GP5/T1CKI/OSC1/CLKIN GP4/AN3/T1G/OSC2/CLKOUT VDDGP3/MCLR/VPP 14 - Pin 8-pin and 14-pin Compatibility 8 - Pin vin VSS GP0/AN0/CIN+/ICSPDAT GP1/AN1/CIN-/ICSPCLK GP2/AN2/T0CKI/INT/COUT RC5 RC0/AN4 RC4 RC1/AN5 RC3/AN7 RC2/AN6 © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 44 A/D vin 8-18 Pin Migration PIC12F675 PIC16F676 PIC16F818/9 PIC16C71x Digital/ Comparator PIC12C671/2 Flash OTP PIC12F629 PIC12C50xA 8 Pin PIC16F630 PIC16C505 14 Pin PIC16F627/8 PIC16C62xA 18 Pin Enh Flash © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 45 vin Low Pin Count Migration Paths More I/O, More A/D channels PIC12F629 PIC12F675 Flash, 10-bit A/D, EEPROM, Comparator, Better Intosc, 2V Operation, x14 Core More I/O and memory, Serial comms, CCP PIC16F630 PIC16F676 Lower cost Flash, 10-bit A/D, Better Intosc, more I/O, 2V Operation, Comparator, EEPROM, x14 Core Flash, A/D, EEPROM, Comparator, Better Intosc 2V Operation, x14 Core More I/O PIC12C50x PIC12C67x Lower cost 8-pin © 2003 Microchip Technology Incorporated. All Rights Reserved. PIC16F62x PIC16F81x Lower cost, more A/D Flash, EEPROM, 10-bit A/D, Lower cost, Better Intosc, 2V Operation Flash, 10-bit A/D, EEPROM, Better Intosc, 2V Operation, More Memory, USART More I/O PIC16C505 Lower cost PIC16C62x PIC16C71x 14-pin Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit 18-pin Slide 46 vin Flash - Quality !!!! © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 47 vin Strength - PEEC Flash Program Memory So What: Best in the Industry Endurance Prove it: Endurance - From Datasheet Spec * 100,000 Erase/Write Cycles Program Memory 1,000,000 Erase/Write Cycles Data EEPROM How important is quality and reliability in the application? © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 48 vin Provide Non-Volatile Storage for: Strength - Data EEPROM Calibration values Serial numbers After Production modification/customization Storing custom settings during power down Data EEPROM is Separate from Program Memory More Read/Write cycles than Program Memory Microcontroller can continue executing code while writing to Data EEPROM © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 49 vin ADC 10 Bit versus 8 Bit © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 50 vin Advantages of a 10-bit A/D To get 8-bit Resolution with an 8-bit A/D, the signal must be full scale IN Adjust 5V Amp 5V 8-bit A/D Digital MCU 5V 10100100 00100101 10001110 10001001 00101001 11111010 3V 1V 0V © 2003 Microchip Technology Incorporated. All Rights Reserved. 2V 0V 0V Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 51 vin Advantages of a 10-bit A/D PIC12F675 IN Signal can be measured directly ADC 5V 3V 1V 0V © 2003 Microchip Technology Incorporated. All Rights Reserved. 10-bits means 1024 steps 2V/5V*1024 = 409steps more than 8-bit resolution No more scaling required No more adjustments required Less components Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 52 vin When is a Comparator helpful ? 1.) Software ADC -> PIC16F630 2.) fast hardware shutdown © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 53 vin Good General Purpose Comparator Standard on all products Internal Voltage Divider (Vref) available Strength - Comparator Up to 32 Software Programmable levels available Eight different operating modes Programmable input multiplexing Output is externally available (Use as a standalone analog component) Switched off if not used to save power © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 54 vin Comparator Features: Eight Operating Modes CIN - - CIN + + CIN - - CIN + + Cout Cout Default CIN - - CIN + + Cout Internal Out © 2003 Microchip Technology Incorporated. All Rights Reserved. External/Internal Out HW-shutdown possible CIN - - CIN + + Cout Vref External/Internal Out with Internal Reference Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 55 vin Comparator Features: Eight Operating Modes (cont.) CIS CIN CIN - - CIN + + CIN + + Cout Cout Off (Lowest Power) CIN CIN + Cout - Vref Input Multiplexing with Internal Reference CIS CIN - - CIN + + + Cout Vref Internal Out with Internal Reference © 2003 Microchip Technology Incorporated. All Rights Reserved. Vref Input Multiplexing with Internal Reference Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 56 vin Comparator uses for 10Bit SW-ADC PIC12F6xx , PIC16F630, PIC16F/C62x © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 57 vin Temperature Measurement Circuit Using a Diode CMCON := 0000 0011 VRCON := 1110 1100 VDD = 5V VDD PIC16F676 R3 R1 43kW MCP601 VDD R2 RA3 CINT ~0.1mA PortA.3 RA0 R1 = 24kW R2 =31.5kW R3 =196kW CINT =100nF High Input Impedance Low Output Impedance Input Range 200mV to 800mV RA2 + VDD / 2 Comparator CMCON.6 AN700-”Make a Delta-Sigma Converter Using a Microcontroller’s Analog Comparator Module” © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 58 vin What is the wake-up time of a controller after SLEEP mode ? © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 59 vin Why is a quick startup important? 1mA Idd 1uA Device wakes up (8 Tcycle-int. RC), tests a condition and go back to sleep A quick startup time reduces ‘on’ time © 2003 Microchip Technology Incorporated. All Rights Reserved. For battery applications: Minimize ‘On’ time Minimum sleep current Result: Longer battery life Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 60 vin Simplify the Power Supply © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 61 vin Strength: Wide Operating Voltage So What: Flexibility to select best available/low cost device to interface to PIC12F6xx Does not require additional components to translate voltage levels so that different components can interface © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 62 vin Wide Operating Voltage doesn’t need a LDO... Voltage 2,0/2,2V Time Operating voltage range with LDO Wider operating voltage means easier Power-supply © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 63 vin 8-Pin Strength - Packaging SN package (150mil SOIC) DFN (Flatter) package 14-Pin 12 I/O Pins 150 mil SOIC TSSOP package available © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 64 vin QFN Package Cross Section Die Mold Compound Cu Leadframe Gold Wire Lands © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 65 vin MPLAB® Integrated Development Environment Simulator, Assembler, Linker Programming support Development Tool Support PRO MATE® II programmer PICSTART® Plus programmer (low-cost) PICKit 1 Flash Starterkit MPLAB® In-Circuit Debugger (ICD 2) MPLAB® ICE 2000 Emulator © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 66 vin ICD for 8/14 Pin Devices ICD Device (PIC12F675/ICD) ICD2 (DV164005, DV164006,DV164007) ICD2 Header (AC162050) Target Board To PC © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 67 vin Summary Features Flash Program Memory Real Data EE2 Wide Operating Voltage 2.0-5.5V 10-bit resolution on the A/D (12F675/16F676 only) Analog Comparator Module + programmable Vref Precision Internal 4MHz Oscillator +-2% Operating Speed up to 20MHz In-Circuit Debug Capability Packaging - DFN-S,TSSOP Brown-out Reset © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 68 vin Technical Literature PIC12F629/675 Data Sheet - DS41190C Programming Spec. - DS41173B PIC16F630/676 Data Sheet DS40039C PIC16F630/676 Programming Spec. DS41191B Tips n’ Tricks Brochure Please check Microchip’s Web Site for the latest Versions of the Data Sheet and possible Errata-sheets © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 69 vin Workshop Lessons using TM PICkit 1 © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 70 vin Overview Lesson 1: Blinking LED 200ms Lesson 2: read a button -> LED on/off Lesson 3: Constant Main-loops Lesson 4: SW-PWM standard via IRQ Lesson 5: SW- PWM easy way © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 71 vin Lesson #1 In Lesson #1 a very basic program is downloaded to the PIC12F675, which drives LED D0 ON/OFF at a 200 millisecond rate. The Flowchart for Lesson #1 shows the basic operation of the source code The block diagram shows a typical circuit used to drive an LED. – 2 different methods of driving an LED using an I/O port are shown Source code description includes Assembler directives and initialization of PICmicro © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 72 vin Lesson #1 Flowchart & LED Drive Circuit VCC S t a r t LED LED1 ON LED1 OFF I n i t i a l i z e P I C 1 2 F 6 7 5 LED2 ON LED2 OFF OUT1 OUT2 LO X HI or Z X X X HI LO or Z LED1 T u r n o n L E D OUT1 D e l a y OUT2 PIC12F675 LED2 T u r n O f f L E D D e l a y © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 73 vin Assembly Code Description Assembler directives are used at the beginning of the program to select additional library functions and set initial conditions. #Include – Assembler directive to load Libraries _Config – Assembler directive to assign the initial conditions of the microcontroller #Define – Defines variables and assigns initial values © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 74 vin Lesson #1 Source Code Assembler Directives list p=12F675 #include <p12f675.inc> __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF…... #define DELAYCONSTANT #define TRISIO_INIT #define LED cblock 0x20 INNER OUTER endc © 2003 Microchip Technology Incorporated. All Rights Reserved. .255 b'11111110' GPIO,0 ;GP0 - Output Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 75 vin Assembly Code Description (continued) Microcontrollers require initialization after they come out of their Power On Reset (POR) condition. Initialize function – Located at the beginning of a program – Memory, registers and I/O ports should be initialized to specific values for a more robust design © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 76 vin © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 77 vin Lesson #1 Source Code Initialization of PICmicro org 0x00 Initialize banksel GPIO movlw .7 movwf CMCON clrf banksel movlw movwf clrf banksel ;Bank 0 ;Comparator Off, Pins Set ;For Digital GPIO TRISIO TRISIO_INIT TRISIO ANSEL GPIO © 2003 Microchip Technology Incorporated. All Rights Reserved. ;Bank 1 ;Pins Set For Digital ;Bank 0 Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 78 vin © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 79 vin © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 80 vin Assembly Code Description (continued) A main program is used to control the overall operation of any microcontroller. MAIN function – Usually located after the Initialize section – Will call other subroutine functions for steps that are repeated throughout the operation Delay – Subroutine function with a programmable delay to control LED ON/OFF timing © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 81 vin Lesson #1 Source Code Main Function Main bsf LED movlw DELAYCONSTANT call Delay bcf LED movlw DELAYCONSTANT call Delay goto Main © 2003 Microchip Technology Incorporated. All Rights Reserved. ;Turn on LED ;Delay ;Turn off LED ;Delay ;Start All Over Again Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 82 vin Assembly Code Description (continued) A subroutine or function is used to support the Main function of a microcontroller. Delay function – This function is called by the Main function when a programmable delay is required – The delay in this function is used to control the rate that the LED cycles ON and OFF © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 83 vin Lesson #1 Source Code Delay Subroutine ; Delay(W) - DelayTime = [ (1)+(2)+(2)+(W*768-W)+(W*3-1)+(2)]* (OSC/4)cycles (This includes the movlw,call,and return) ; - Max Time When W=0xFF, [ 196356 Cycles * (OSC/4) ] ; - Must Declare INNER & OUTER AS GPR'S ;****************************************************** Delay movwf OUTER clrf INNER D1 decfsz INNER,f goto D1 D2 decfsz OUTER,f goto D1 return END © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 84 vin Lesson #1 Step 1: Create a project under MPLAB Step 2: Enter the code , assemble Step 3: Simulate it under MPLAB Step 4: Begin communication with PICkit 1 Start->Programs->PICKit 1 FLASH Start Kit Screenshots are shown on next slide © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 85 vin It starts Here… “Ready for launch...” Simulate and Debug Edit & Build Project Management Design Process Emulate Program Device © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 86 vin MPLAB ® Integrated Development Environment Built-in Editor Language Products Low-cost Debugging MPASM MPLAB SIM MPASM™ + MPLINK Sofware Assembler Simulator + MPLIB MPLINK™HEX File MPLIB™ MPLAB C17 MPLAB C18 MPLAB C30 Source Level Debugger Project Manager Emulation and Analyis MPLAB ICE 2000 MPLAB ICE 4000 MPLAB ICD MPLAB ICD 2 © 2003 Microchip Technology Incorporated. All Rights Reserved. Device Programmers ® PICSTART Plus Third Party Tools C Compilers IAR Hi-Tech CCS PRO MATE® II Real-time Operating Systems CMX, Vector, Realogy PRO MATE 3 Libraried Routines Live Devices, CMX, Momentum Data Systems Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 87 vin Now bring it to PICKIT1 hardware…. LED D0 is on when: =============== RA4 -> Output High (1) RA5 -> Output Low (0) © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 88 vin Programming Interface for Steps 1 & 2 © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 89 vin Step 3: Download data to PICmicro Lesson #1 (continued) Programmer-> Write Device Or Press Write Device Button Status window shows ‘Write Successful’ LED D0 should now blink at a 200 msec rate © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 90 vin Programming Interface for Step 3 © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 91 vin The new code in Lesson 2 will turn LED D1 ON at startup and D0 will be OFF. Lesson #2 While pressing switch SW1, D1 will turn OFF & D0 turns ON Releasing SW1 turns D1 ON & turns D0 OFF Flowchart / LED & Switch schematic shown Basic flowchart of Lesson 2 LED and switch circuit used in PICkitTM 1 © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 92 vin Lesson #2 Flowchart and LED Truth Table PIN D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 D10 D11 t GP4 r a t S HI LOW HI LOW Z Z Z Z Z Z HI LOW GP5 LOW HI Z Z HI LOW Z Z HI LOW Z Z GP2 Z Z LOW HI LOW HI HI LOW Z Z Z Z GP1 Z Z Z Z Z Z LOW HI LOW HI LOW HI e z i l a i t i n I PICkit™ 1 LED Truth Table 5 7 6 F 2 1 C I P (HI => Logic 1, LOW => Logic 0, and Z => TRISIO = 1) s e Y n o t t u B s I ? d e h s u P n O n r u T o N 1 D E L n O n r u T 2 D E L © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 93 vin Lesson #2 LED Circuit in PICkitTM 1 © 2003 Microchip Technology Incorporated. All Rights Reserved. PICmicro can selectively drive up to 12 different LEDs using 4 I/O ports See TB029 Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 94 vin Step 1: Locate Lesson2.hex and load buffer File->Import HEX – Path: xxx Step 2: Download data to PICmicro Lesson #2 Programmer-> Write Device Or Press Write Device Button – Status window shows ‘Write Successful’ LED D1 will turn ON Pressing SW1 will turn D1 OFF and turn D0 ON Releasing SW1 will go back to initial setup © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 95 vin Lesson #3 Have a predictable timing and avoid asynchronus interupts. A Task Manager enhances readability of the software and the debug capabilities ... ... ... ... Taskmanager n 1 © 2003 Microchip Technology Incorporated. All Rights Reserved. 2 Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 96 vin Mainloop Every Task gets a number -> task_count this task# has to be checked for value and has to be limited. Every task could have the same timing Out of constant tasks you can count up for seconds, minutes, hours,... © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 97 vin Using TMR0 / RTCC 8-bit Timer / Counter Readable and writable 8-bit software programmable prescaler Internal or external clock select Interrupt on overflow from FFh to 00h Edge select for external clock External Clock Input 8-bit Data Bus Fosc/4 8-bit Programmable Prescaler T0SE T0CS 3 PS2, PS1, PS0 © 2003 Microchip Technology Incorporated. All Rights Reserved. Sync with internal clocks TMR0 (2 cycle delay) PSA Set T0IF interrupt flag on Overflow Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 98 vin © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 99 vin “Task Manager” - in General Initialize TMR0 Task# as offset in W-Reg Goto Task0 Task0 Goto Task1 ..... Goto Taskn Taskn Increment Task# constant time Add offset on PCL-REG and limit value Wait for TMR0 has it´s final value © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 100 vin ;********** MAIN - LOOP************************** ;********** create 10 tasks , each 1ms long ;********** use tmr0 for it: ;********** micro running at 4MHz-> 1 us per instruction ;********** 1ms = 1000us, prescaler-vale = ":4" Start_Main movlw 0x00 movwf TMR0 movf task_count,w andlw b’00000111’ addwf PCL,f goto task0 goto task1 goto task2 goto task3 goto task4 goto task5 goto task6 goto task7 continue incf task_count,f movlw 0x06 xorwf task_count,w btfsc STATUS,Z goto task_limit goto wait_end_task task_limit movlw 0x00 movwf task_count wait_end_task movlw 0xF7 ; is 1ms over ?? subwf TMR0,W btfsc STATUS,C goto Start_Main ; yes goto wait_end_task ; no Limiting table jump Jump-table Prepare the next task Fill rest of task with waiting for a constant time © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 101 vin Lesson #4 Read upper 8 Bit of ADC Channel 0 and create a standard SW-PWM via IRQ Period D.C. © 2003 Microchip Technology Incorporated. All Rights Reserved. Period D.C. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 102 vin Lesson #4 How it works…. Period D.C. Period D.C. Demo will give you approx. 124Hz © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 103 vin PWM-Generation PWM-Output © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 104 vin Main-Loop ;---------------------------------------------------------------Main call Read_ADC call SetPWM goto Main ;Start All Over Again ;---------------------------------------------------------------- © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 105 vin 10-Bit A/D Module: Left/Right Justification of A/D Result 10-Bit Result ADFM = 1 ADFM = 0 076 5 7 00 0000 ADRESH ADRESL 10-Bit Result Left Justified © 2003 Microchip Technology Incorporated. All Rights Reserved. 0 2 107 7 0 0000 00 ADRESH ADRESL 10-Bit Result Right Justified Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 106 vin A/D Conversion Timing BSF ADCON0, GO 1/2 Tcy 134 131 Q4 130 A/D CLK 9 A/D D ATA 8 7 6 3 OLD_DATA ADRES 2 1 0 NEW_DATA ADIF GO SAMPLE DONE 132 SAMPLING STOPPED If the A/D clock source is selected as RC, a time of TC Y is added before the A/D clock starts. This allows the SLEEP instruction to be executed. © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 107 vin 10-Bit A/D: Acquisition, Conversion and Sampling Time A/D Sample Time Acquisition Time Conversion Time Go bit set A/D Channel Selected; A/D Turned ON © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 108 vin © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 109 vin Input Impedance : Looking in from the outside Vdd Analog Input Rs Switch Resistance CPIN Leakage current R = 1..8kW Sample Cap C = 25pF(12Bit) Vss Analog channel input impedance is relatively low Source output impedance Interacts with switch resistance and sample caps A high impedance source will increase sample cap charging time © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 110 vin © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 111 vin © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 112 vin ADC-setup banksel movlw ADCON0 B'00000001' movwf banksel movlw ADCON0 ANSEL B'00110001' movwf ANSEL ; left adjustified, Vdd as Vref, Channel 0, ; ADC is on ; Poti of PICKIT 1 is connected to GP0 ; driven by int. RC ADC-subroutine Read_ADC bsf ADCON0,GO ; ADC starten btfsc goto movf return ADCON0,GO wait_ADC ADRESH,W ;...............result is now in ADRESH wait_ADC © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 113 vin ;********************************************************************* ; Interrupt Vector and Service Routine ; This interrupt routine is entered via an overflow of TMR0 from ; 0xFF to 0x00. A test of RB1 determines if the next time state ; is a high or low cycle. The next interrupt will occur based the ; TMR0 reload value (OUTLOW or OUTHIGH). ; ; The interrupt routine was designed to use a minimial number of ; instruction cycles. This was done to maximise the PWM duty cycle ; range (ie. a 5 % to 95 % range is achievable with this ISR). Note ; that 'swapf' instructions are used to perform register moves without ; effecting the STATUS flags (this saves instruction cycles by ; eliminating the need to temporarily save the STATUS register). ; ;********************************************************************* © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 114 vin © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 115 vin org 0x004 ; Interupt vector location IntVector movwf btfsc goto TEMPW PWM PWMLow ; Temporarily save W ; Was this a Low cycle ? ; No ... swapf bsf nop movwf bcf swapf swapf OUTHIGH,W PWM ; Yes... Load high time without affecting STATUS flags PWMHigh TMR0 INTCON,T0IF TEMPW,F TEMPW,W ; Delay to equalise high/low TMR0 load cycles ; Load next edge interrupt time ; Clear TMR0 overflow flag ; Swap saved W ; Restore W IntEndHi retfie ; Return from Interrupt PWMLow bcf swapf movwf bcf swapf swapf PWM OUTLOW,W TMR0 INTCON,T0IF TEMPW,F TEMPW,W ; Load low time ; Load next edge interrupt time ; Clear TMR0 overflow flag ; Swap saved W ; Restore W IntEndLo retfie ; Return from Interrupt ;---------------------- end of IRQ ------------------------- © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 116 vin ;********************************************************************* ; Set PWM Subroutine ; The following calculates the next low and high PWM time values. ; The two time values, OUTLOW and OUTHIGH, will be passed to the ; interrupt service routine. ;********************************************************************* SetPWM bcf INTCON,GIE ; Disable interrupts to prevent ISR from... ; corrupting OUTLOW & OUTHIGH values movwf OUTLOW ; Set PWM Duty Cycle comf OUTLOW,W ; ; addlw movwf movf addlw movwf IntEndHi-IntVector ; Adjust for Int Service time OUTHIGH OUTLOW,W IntEndHi-IntVector ; Adjust for Int Service time OUTLOW swapf swapf bsf return OUTLOW,F OUTHIGH,F INTCON,GIE © 2003 Microchip Technology Incorporated. All Rights Reserved. ; Swap nibbles so that interrupt service... ; will not corrupt STATUS ; Re-enable interrupts Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 117 vin Lesson #5 Read upper 8 Bit of ADC Channel 0 and create a easy SW-”PWM” without IRQ Period D.C. Period D.C. Goes from 0Hz(0%) …200Hz ….8,8Khz © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 118 vin •Now, please exchange the Set_PWM-SW with the following new one. •Delete the IRQ-SW. •Disable all IRQ’s. •READ_ADC as before.. © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 119 vin Easy_PWM bcf PWM addwf ACCU,F btfsc STATUS,C GOTO TOGGLE return TOGGLE clrf ACCU bsf PWM return © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 120 vin Microchip Product -Update © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 121 vin Overview Analog PICmicro Low-pin count #1 Pin-migration family high-quality Flash Self programming Memory Interface Low-Power OPAMP Reliable Partner Second source SOT23 High-performance small package -> Sole source (SC70-LDO/OPAMP/RESET) high-quality Flash mostly +125°C possible (SEEVAL Tool) (Endurance Disk) int. E²prom ….. Perfect match © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 122 vin Int. RC PIC16F874A int. Reset (BOR) int. E²prom int. Comparator Int. RC 16F74/16F77 int. Vref int. Reset (BOR) int. E²prom PIC16F873A HW-PWM 16F72/16F73 int. Comparator int. Vref PIC16F819 int. 10Bit ADC 16C62xA 16F876A 16C712/716/771 18F252 (1,5KRAM) (8/10/12 Bit ADC) PIC12F675 16C505 12C50xA 12F629 12F675 16F630 16F676 16F818/819 (12Bit ADC) 16F877A 16C773 (12Bit ADC) PIC16F676 16C774 int. 10Bit ADC 18F452 (1,5KRAM) 18F458 (CAN) 18F4320 (Low-power) 18F258 (CAN) 18F2320 (Nano-power) 16F628A (USART) 16F648A (4KW) 16F88/87 (4KW) 18F1220/1320 (Nano-power + LIN UART) © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 123 vin 14-Pin upgrades... 2kWords, 256Bytes Eeprom 8Mhz int. RC !!! New Low current WDT upto 268 sec. !!! Enhanced CCP-Modul !!! PIC16F630 PIC12F629 © 2003 Microchip Technology Incorporated. All Rights Reserved. PIC16F684 PIC16F676 PIC12F675 Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 124 vin Benefits….. 1mA Idd Use 32kHz crystal (lowest cost) for timing 1uA Device wakes up (8 clocks), tests a condition and go back to sleep PIC12F675 For battery applications: Minimize ‘On’ time Minimum sleep current A quick startup time reduces ‘on’ time Result: Longer battery life Execute code running internal oscillator PIC12F675 Voltage 10Bit ADC IN CIS CIN - 2,0V Operating voltage range translates into battery life Time Wider operating voltage means longer battery life © 2003 Microchip Technology Incorporated. All Rights Reserved. CIN + + Cout Vref Input Multiplexing with Internal Reference Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 125 vin 18 Pin with Comparator + Vref 4KW PIC16F648A PEEC Technology PIC16F628 2 Comp. + Vref. PIC16F628A BOR PIC16C621A/622A int. Dual speed RC USART 2 Comp. + Vref PIC16CR620A BOR HW PWM Capture/Compare more memory 2 Comp. + Vref BOR © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 126 vin 18/20 Pin with ADC PIC16F88/87 4KW, ICD2, 10Bit ADC, int. Osc., Comp. Low-power-Modi PIC16F819 Flash PIC16C770 / C771 12Bit ADC progr. BOR PIC16C717 progr. LVD 10Bit ADC enh. HW PWM progr. BOR progr. LVD PIC16C712/716 enh. HW PWM 16Bit timer Caoture/compare int. Dulspedd RC 16Bit timer PIC16C711 8Bit ADC Caoture/compare BOR int. Dulspedd RC HW PWM int. Vref int. Vref more Memory 16Bit timer 8Bit ADC Capture/compare BOR © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 127 vin PWM Quad Output Mode Example VHIGH TC4428 PA PB PC A FET DRIVER PD TC4428 C FET DRIVER MOTOR B D PIC16F684 PIC16C717 PIC16C770 PIC16C771 PIC18F1220 PIC18F1320 © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 128 vin Dead time control on enhanced PWM TD TDC TP TD = Dead Time [Dual Output Mode Only] TDC = Duty Cycle Time TP = Period Time © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 129 vin PICmicro® goes….. PIC18F2220/2320 PIC18F1320 PIC18F1220 PIC16F88/87 •More flexible Oscillators PIC16F819 PIC16F648A PIC16F628A Lowest Cost © 2003 Microchip Technology Incorporated. All Rights Reserved. •Lower current Timer1 •faster Startup , (8clocks) after power-up •more Power-down-modi Highest feature Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 130 vin © 2003 Microchip Technology Incorporated. All Rights Reserved. Want to try ? Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 131 vin Get info’s automatical !! Change / Errata via email http://cn.microchip.com/sales/product_change.nsf/mainframeset?openframeset © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 132 vin Microchip delivers…….. Risk free development Lower total system cost Faster time to market © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 133 vin Tips and Tricks © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 134 vin Overview Tip’s & Tricks RC- Osc. Switching Easy charge-pumps Self-latching circuits Reading a sensor with higher resolution High Frequency messurement HW-PWM using comparators Low-Power Several SW Tips © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 135 vin Dual Speed RC Oscillator resistor switching © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 136 vin Dual Speed RC Oscillator After reset, GP2 pin is High - Z Frequency is determined by R1 and C3 Changing GP2 state to output high Frequency is determined by R1||R2 and C3 Looks fine, any possible problems? © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 137 vin Dual Speed RC Oscillator While in the low frequency mode, GP2 sees the oscillators voltage swing, which causes additional current drawn through the digital input buffer. Tip: On some devices, the digital input buffer can be turned of by configuring the pin as analog input. Switching GP2 to ground will certainly hold the oscillator, without an active watchdog somebody needs to remove the battery. © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 138 vin Dual Speed RC Oscillator Switching a capacitor instead of a resistor Situation changes , GP2 sees the signal while in high speed mode, where the increased current consumption may be tolerated. It doesn‘t matter if you set GP2 high or low, important is the change input/output GP2=input High frequency GP2=output Low frequency © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 139 vin Dual Speed RC Oscillator capacitor switching © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 140 vin Connecting C3 to Vdd © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 141 vin Works also for Xtal © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 142 vin Charge pumps •Can be driven with an I/O-pin •For higher output currents, parallel I/Os •Or, use a push-pull stage •This can be a discrete one or a FET-driver •Don‘t forget the current limiting resistors •Clock out may also be used •Attention, higher source impedance © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 143 vin Doubling charge pump © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 144 vin Inverting charge pump © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 145 vin Bad circuit! © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 146 vin Inverting charge pump with higher current © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 147 vin Self latching circuits •The micro has control over Vdd •Allows the watchdog to be running •Allows brown out detection •A dynamic circuit can serve as an additional watchdog © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 148 vin Self latching circuits Standard I/O © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 149 vin Self latching circuits Open Drain I/O © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 150 vin Self latching circuits Dynamic drive © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 151 vin Self latching circuits Dynamic drive simplified © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 152 vin Self latching circuits •The simplified circuit requires an asymetric drive •Clock out may be used to drive the charge pump •PNP instead of NPN may be used •Using MOSFET may cause problems with lower battery voltages © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 153 vin Reading a Sensor with Higher Resolution 1. RC timing method with reference resistor 2. Charge balancing method 3. A/D method © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 154 vin I. Reading a Sensor with Higher Resolution 1. RC Timing Method: Vc(t) R1 R2 Simple RC step response Vth Vc(t) = VDD * (1 - e -t/(RC)) t = -RC ln(1 - Vth/VDD) t=0 Vth/VDD is constant R2 = (t2/t1) * R1 © 2003 Microchip Technology Incorporated. All Rights Reserved. t = t1 t = t2 Time AN512 Implementing Ohmmeter/Temperature Sensor AN611 Resistance and Capacitance Meter Using a PIC16C622 Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 155 vin I. Reading a Sensor with Higher Resolution RC Timing Method PIC12F629 Rref GP2 Rsen GP1 GP0 1. Set GP1 and GP2 to inputs, and GP0 to a low output to discharge C. 2. Set GP0 to an input and GP1 to a high output. 3. Measure tRsen (GP0 changes to 1). 4. Repeat step 1. 5. Set GP0 to an input and GP2 to a high output. 6. Measure tRref (GP0 changes to 1). 7. Use film polypropylene capacitor. 8. Rth = tRsen x Rref tRref Other alternatives: Voltage comparator in the PIC12F6XX © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 156 vin II. Charge Balancing Method 1. Sensor charges a capacitor 2. Reference resistor discharges the capacitor 3. Modulate reference resistor to maintain constant average charge in the capacitor 4. Use comparator to determine modulation © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 157 vin II. Reading a Sensor with Higher Resolution 2. Charge Balancing Method: VDD PIC12F6XX CVref Rsen COUT GP1 Rref T1G GP2 © 2003 Microchip Technology Incorporated. All Rights Reserved. 1. GP1 average voltage = CVref 2. Time base as sampling rate. 3. At the end of each time base period: - If GP1 > CVref, then GP2 Output Low - If GP1 < CVref, then GP2 Input mode 4. Accumulate the GP2 lows over many samples. 5. Number of samples determines resolution. 6. Number of GP2 lows determine effective duty cycle of Rref. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 158 vin II. Delta Sigma Converter 1. GP1 average voltage = CVref 2. Time base as sampling rate. 3. At the end of each time base period: - If GP1 > CVref, then GP2 Output Low. - If GP1 < CVref, then GP2 Output High. PIC12F6XX CVref Software closes loop COUT GP1 Vin GP2 4. Accumulate the GP2 lows over many samples. 5. Number of samples determines resolution. © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 159 vin III. Reading a Sensor w/ Higher Resolution A/D method: PIC12F675 100K GP2 10K GP1 AN0 (A/D input) Rsen © 2003 Microchip Technology Incorporated. All Rights Reserved. 1. 10K and 100K resistors are used to set the range. 2. Vref for A/D = VDD. 3. Rth calculation is independent of VDD. 4. Count = Rsen/(Rsen+Rref) x 255 5. Don’t forget to allow acquisition time for the A/D Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 160 vin High Frequency Signal Measurement TMR0: Readable and writable Generates interrupt on overflow from FFh to 00h Prescaler is programmable In timer mode: fastest increment rate is OSC/4 (5 MHz @ 20 MHz oscillator frequency) In counter mode: configurable to increment on either edge External counter mode has Max. input = 50 MHz (using prescaler) Interrupt on overflow Ext clock input 8-bit prescaler 8-bit timer/counter Internal clock © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 161 vin High Frequency Signal Measurement If Prescaler set to max. divide value of 256 Max. input frequency = 1/1.6 nS However Min. input rise/fall time = 10 nS So Max frequency = 1/20nS = 50Mhz. © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 162 vin High Frequency Signal Measurement CNTL1=1, stops additional pulses from getting clocked into the prescaler To get low 8 bits from prescaler, pulse CNTL2 N times, till TMR0 = TMR0+1; Low 8 bit value = (256 - N). © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 163 vin High Frequency Signal Measurement Q1 replaces the NAND gates to reduce system cost. © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 164 vin Hardware PWM using comparators Vin Vout Vref Vin Vin = Ramp input If Vin > Vref, Vout = 0 If Vin < Vref, Vout = 1 If Vref is variable, then the PWM duty cycle will vary with the Vref level. Vref Vout © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 165 vin Hardware PWM using comparators Generating a Ramp OSC1 PIC16C62X Vout OSC2 Vramp R C Vout OSC1 is connected to as an RC oscillator. OSC2 output is connected to a RC to generate a ramp Selection of RC is important to maximize the triangulation in the ramp voltage. Vramp © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 166 vin Hardware PWM using comparators Vref outputs for 62x Vdd = 5V Vr<3:0> VRR = 1 VRR = 0 0 0 1.25 1 0.21 1.41 2 0.42 1.56 3 0.63 1.72 4 0.83 1.88 5 1.04 2.03 6 1.25 2.19 7 1.46 2.34 8 1.67 2.50 9 1.88 2.66 10 2.08 2.81 11 2.29 2.97 12 2.50 3.13 13 2.71 3.28 14 2.92 3.44 15 3.13 3.59 © 2003 Microchip Technology Incorporated. All Rights Reserved. Vref Values For Vdd = 5V a total of 32 voltage outputs are available as Vref. Values sometimes overlap for VRR = 0 and VRR = 1. In order to get an ascending order of Vref, a lookup table is the best approach to set VRCON. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 167 vin Hardware PWM using comparators Lookup table for Ascending Vref values Voltage VRCON Voltage VRCON 1.04 229 2.34 199 1.25 230 2.50 200 1.41 193 2.66 201 1.56 194 2.71 237 1.67 232 2.81 202 1.72 195 2.92 238 1.88 196 2.97 203 2.03 197 3.13 204 2.08 234 3.28 205 2.19 198 3.44 206 2.29 235 3.59 207 © 2003 Microchip Technology Incorporated. All Rights Reserved. For each value of voltage, a corresponding VRCON value can be selected. A look-up table can be used to select an ascending order of Vref voltages. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 168 vin Hardware PWM using comparators C Code for varying PWM Duty Cycle const unsigned char VrefTable[] = { 229,230,193,194,232,195,196,197,234,198,235, 199,200,201,237,202,238,203,204,205,206,207,0}; void main(void){ Init(); Delay_Ms_4MHz(250); while(1) { if(!PORTB.UP) { VrefIndex++; if (VrefIndex == MAXVREFS) VrefIndex = 0; VRCON = VrefTable[VrefIndex]; PORTB = VrefIndex; } while (!PORTB.UP) Delay_Ms_4MHz(20); } } © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 169 vin Hardware PWM using comparators PIC16C62X Implementation PIC16C62X RA4 RA3 OSC1 RA2 Vref CM<2:0> = 110 Vout OSC2 Vramp R © 2003 Microchip Technology Incorporated. All Rights Reserved. Vramp = RC square wave after filter RA3 and RA4 are PWM outputs pins. Vref output on RA2 RA2 connected to NonInverting terminals of both comparators. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 170 vin Keyboard scanning using a ADC © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 171 vin What is Nanowatt Technology ? Reduction of the Power Consumption of an Electronic Circuit to Values < 1 uW Is this possible and how can we achieve it ? © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 172 vin Keep maximum current consumption at all times low Low Performance Application like Real Time Clocks, Timers Keep average current consumption low, allowing short peaks of higher currents Methods to implement Nanowatt Technology Remote Controls, RKE systems Remote Sensors Combination of both – Data Logger © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 173 vin Key Elements for Nanowatt Applications Supply Voltage Clock Frequency Operating Temperature Component Selection Relation of Stand-By Times vs. Active Times Other H/W and S/W Design Techniques © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 174 vin Key Elements for Nanowatt Applications Controller Architecture Efficient Throughput Rate Static Design Flexible Power Management – Low Power Modes – Variable Clock Frequency – Power Control for on-chip Peripherals – Fast Wake-up from Stand-By Mode © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 175 vin Wake-up from Stand-By Mode Crystal Waking-Up(~8.5msec) © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 176 vin Wake-up from Stand-By Mode Resonator Waking-Up (~390usec.) © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 177 vin Wake-up from Stand-By Mode RC oscillator Waking-Up(~1.15usec) © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 178 vin Int. RC of PIC12F675 © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 179 vin Wake-up from Stand-By Mode Conclusions Internal RC oscillator is optimum solution for many Nanowatt applications – low current consumption – fast wake-up from Stand-by Immediate Start of Oscillation OST is disabled on PICmicro Devices – fast stop when entering Stand-by © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 180 vin Example for nW Components PIC12F629/12F675 0.4 Micron CMOS process High reliable, high endurance, ultra low leakage current proprietary FLASH Cell (PEEC) Harvard Architecture (RISC like, 0.25 MIPS per MHz) with internal RC oscillator and power controlled peripherals (BOR, Comparator, ADC, EEPROM ….etc.) Supply Voltage Range 2.0V - 5.5 V typ. Leakage current on any I/O pin < +-0.1 uA (max. +-1 uA) max. standby current @3.0V = 770 nA typ. Standby current @ 3.0V = 1.2 nA typ. Operating current @32kHz, 3.0 V = 18 uA for further details see data sheet DS41190C © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 181 vin Example for nW Components MCP604x/MCP614x Low Power Operational Amplifiers CMOS process Rail-to-rail I/O CS input for power control (MCP6x43) 14kHz/100kHz GBWP Typical quiescent current Iq = 600 nA Standby Current (MCP6x43) typ. 20 pA Supply voltage range 1.4 V … 5.5 V for further details see data sheet DS21669B © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 182 vin Example for nW Components TC54 Voltage Detector CMOS process Generates an “Active Low” output signal if Supply Voltage drops below “reset voltage” Reset Voltage selectable between 1.5V and 6.0 V with +-1% Tolerance Quiescent Current @ 3V : typ. 1.3 uA, max. 3.4 uA for further details see data sheet DS21669B © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 183 vin Active to Standby Times Iavg = ( Idd*T1+ Ipd*T2 ) / (T1+T2) Active (T1) Idd Standby (T2) Ipd © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 184 vin Active to Standby Times Example for PICmicro Controllers Max Idd = 0.7 mA (int. 4MHz, 3V, -40 ….+85 ) Max Ipd = 770 nA (“SLEEP”, 3V, -40 …+85 ) T1 …. 1 ms T2 …. 2.5 sec Iavg = (0.7 * 0.001+ 0.00077*2.5) / 2.501= 1.05 uA max. Typical Average Power Consumption @25 deg C 201 nA * 3 V = 603 nanoWatt © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 185 vin Active to Standby Times Conclusions Nanowatt Applications are possible ! Fast Oscillator Start-up after Wake-up has major impact on Iavg (shorter Duty Cycle) Take normal Operating Temperature of Application into Consideration © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 186 vin Other H/W and S/W Design Techniques Switch off power to external peripherals when not used Switch off power to internal peripherals when not used I/O Port Management Dual Clock Systems Power Budgeting © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 187 vin Switch off power to external Peripherals Serial EEPROMs, RS232 Drivers Connect Vdd of Peripheral to PICmicro I/O pin instead of Vbat Turn on the Pin only when Peripheral is needed (e.g. when reading or writing EEPROM) - saves up to 5 uA stand-by current © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 188 vin Switch off internal Peripherals Consider disabling of Watchdog Timer (saves up to 3.5 uA) Brown-Out Detection ( up to 70 uA) ADC (up to 1 uA) Comparators (up to 8.5 uA) Real Time Clock (Timer1) - up to 7 uA © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 189 vin Pull Input Pins as close to Vdd or Vss as possible I/O Port Management pull-up or pull-down resistors – may cause up to 1 uA leakage current Define as Outputs – optimal for unused Pins Define Input Pins as “analog inputs” “ANSEL” register in PICmicro especially useful if voltage Vss<Vin<Vdd © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 190 vin Many PICmicro Controllers have a 32kHz clock driver for Timer1 Dual Clock Systems Connect 32KHz crystal to TMR1 Real Time Clock, also running during “SLEEP” Use RC Oscillator as System Clock TMR1 clock provides accurate time basis to calculate compensation values for Frequency Variation of RC oscillator Fast Start-up Time from SLEEP mode © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 191 vin Dual Clock Systems TMR1 as a Real Time Clock +5V PICmicro® R C T1OSI Y OSC1 C T1OSO C See Application Note AN580 for more information © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 192 vin Multiple Clock Systems Newest PIC Microcontrollers have very flexible on-chip Clock Generation Calibrated internal RC oscillator FLL with Frequency divider S/W controlled switching between clock sources Fail Save Clock Monitor Dual Speed Start-up © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 193 vin PIC16 Oscillator Sources OSCCON To Timer 1 Timer1 Oscillator (~2 uA) Internal RC OSC (31.25kHz, ~2 uA) FLL (x256) 16-bit Postscaler WDT (~30 uA) X TMR0 Clock Monitor WDT Time-out 8-bit Postscaler Main Oscillator (LP, XT, HS) © 2003 Microchip Technology Incorporated. All Rights Reserved. Post- 1:2 scaler 1:4 1:8 1:16 1:32 1:64 System Clock Bias Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 194 vin Oscillator Sources PIC18F4320 Timer1 Oscillator Timer 1 Enable Prescaler To Timer 1 External Interrupt Event Switch Internal Interrupts Primary Oscillator (LP, XT, HS, HSPLL) Wakeup from sleep To Peripherals Bias To CPU Clock IDLE Mode Internal RC OSC (31.25kHz) FLL (8MHz out) Postscaler 1:2 1:4 1:8 1:16 1:32 1:64 FS Clock Monitor WDT (4ms) © 2003 Microchip Technology Incorporated. All Rights Reserved. Postscaler 1:1 to 1:32768 Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 195 vin Increments and Decrements PIC12Fxxx/PIC16Fxxx 16-Bit Increment incfsz goto incf 16-Bit Decrement decf incfsz goto decf LO $+2 HI LO LO,W $+2 HI 8-Bit Decrement to 0xFF NOT_AT_FF : decf incfsz goto AT_FF: REG REG,W NOT_AT_FF © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 196 vin Comparisons 8-Bit Range Test Enter with value to be tested in W. Exits with Carry set if W is in the range [LOVAL to HIVAL], inclusive. addlw 255-HIVAL addlw (HIVAL-LOVAL)+1 Compare and Swap Compare the values in registers X and Y. If Y < X, swap them. movf subwf bc addwf subwf X,W Y,W $+3 X Y ;GRAB X. ;Y >= X? ;IF SO, JUMP AHEAD. ;OTHERWISE, X = X + (Y-X) = Y, ; AND Y = Y - (Y-X) = X. © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 197 vin Comparisons Minimum Enter with three values stored in registers N1, N2, and N3. Exit with min(N1,N2,N3) in MIN, N1-3 unchanged, W scrambled. movf subwf N1,w N2,W movf skpc movf N1,W movwf MIN subwf skpc addwf N3,W N2,W MIN © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 198 vin Miscellaneous "Switch" Statement ; ENTER WITH VALUE TO BE TESTED IN W. XORLW VAL1 BZ CASE1 ;IF W = VAL1, GOTO CASE1. ; XORLW VAL2^VAL1 BZ CASE2 ; ;IF W = VAL2, GOTO CASE2. XORLW VAL3^VAL2 BZ CASE3 ; ;IF W = VAL3, GOTO CASE3. XORLW VAL4^VAL3 BZ CASE4 ; ;IF W = VAL4, GOTO CASE4. etc... © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 199 vin Recommendations Use WDT, but serve it not inside a condition-loop or IRQ or sub-routine, check for min. and max. values (18ms is only for 5V @25 degreeC) Refresh the TRIS-register from time to time Use a debounce-time for reading the I/O´s If cap. Load on I/O´s is higher than spec., then use shadows register for the I/O-Ports to avoid a read-modify-write-problem Fill unused Program- Area: for example: FILL (GOTO wdtreset), (400h-$) © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 200 vin “Do You Have the Tools to Do the Job?” © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 201 vin MPLAB ® Integrated Development Environment Built-in Editor Language Products MPASM™ Assembler Low-cost Debugging MPLAB SIM Sofware Simulator MPLINK™ MPLIB™ MPLAB C17 MPLAB C18 MPLAB C30 Source Level Debugger Project Manager Emulation and Analyis MPLAB ICE 2000 MPLAB ICE 4000 MPLAB ICD MPLAB ICD 2 © 2003 Microchip Technology Incorporated. All Rights Reserved. Device Programmers ® PICSTART Plus PRO MATE® II PRO MATE 3 MPLAB PM3 Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Third Party Tools C Compilers IAR Hi-Tech CCS Real-time Operating Systems CMX, Vector, Realogy Libraried Routines Live Devices, CMX, Momentum Data Systems Slide 202 vin Microchip Universal Macro Assembler Product called MPASM™ Assembler Creates object files for use by MPLINK™ Linker or MPLIB™ Librarian Microchip Object Linker Assembly Language Products Product called MPLINK™ Linker Create executable files from object files May use libraries stored by MPLIB™ Librarian Microchip Object Librarian Product called MPLIB™ Librarian Groups relocatable objects created by MPASM™ Assembler © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 203 vin MPLAB® C17/C18 - $495 each C Compilers Microchip custom ‘C’ compilers ANSI Compatible Reliable Code Generators Free 30 day copies available on the web Third Party Compilers Hi-Tech PICC™ C Compiler - $895, $500 Cross license – Recommended Compiler – Complete offering for all PICmicro® MCUs IAR - $895 - $2000 – High-end compiler CCS - $99 - $395 – Entry level C Compiler © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 204 vin MPLAB® SIM Supports all PICmicro® MCUs Discrete event simulator instruction based MPLAB® compatible Unlimited break points Unlimited trace points Examine/modify registers Watch variables Time stamp Stimulus injection Have you investigated MPLAB® SIM? Available electronically FREE © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 205 vin In-Circuit Debugger - ICD 2 DV164005 ICD 2 Module DV164006 ICD 2 Evaluation Kit DV164007 ICD 2 Module w/supply MPLAB® IDE compatible Firmware upgrade Debugger/Programmer Single step/breakpoint USB connect and powered or RS-232 © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 206 vin To Host PC An MPLAB® ICE System... Emulator Pod Processor Module Device Adapter Transition Socket To Target Board © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 207 vin Development Programmer PICSTART® Plus RS-232 Serial Interface 9V DC Input PICSTART Plus DEVELOPMENT PROGRAMMER Pin-1 POWER ACTIVE Power ON Programmer Active Low-cost Development Programmer Upgrades done in MPLAB® software. Firmware upgrades occasionally required for new PICmicro® sub-families Uses serial programming algorithms for all ICSP capable devices Windows NT® drivers available 40-Pin ZIF Socket to accommodate PICmicro® MCUs from 8- to 40-pins. 68-pin PLCC can be programmed with an adapter © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 208 vin Programmer - PRO MATE® II Runs under MPLAB® software Field upgradable firmware DOS Command Line interface for production Operating modes: Host, Safe, and Stand-Alone Automatic downloading of object file to PRO MATE® II SQTP serialization adds unique serial number to each device programmed Windows NT® driver available In-Circuit Serial Programming™ Kit (sold separately) Interchangeable socket modules supports all package options (sold separately) © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 209 vin Special Features In-Circuit Serial Programming™ How do I connect to ICSP™? Only two I/O pins used for programming – – VPP is program voltage – I/O 1 is clock input I/O 2 is data input/output MCLR/VPP VDD VPP VDD VSS VSS I/O 1 Clock I/O 2 Data I/O PIC16CXX PIC14CXXX PIC12CXXX Driven to +13V VDD is device operating voltage – – Driven to +5V during programming Driven to VDD(max) and VDD(min) for verify © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 210 vin ICSP™ System VDD/VPP VDD PIC12/16/18xxx MCLR/VPP Programming Connector VDD VSS Data Clock System Connection © 2003 Microchip Technology Incorporated. All Rights Reserved. Isolation Circuits Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 211 vin Third Party Tools Beyond Microchip’s own tools, there are over 100 third-party companies supporting Microchip products. DS00104 © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 212 vin © 2003 Microchip Technology Incorporated. All Rights Reserved. Lowpincount Tips& Tricks using PICkitTM1 Flash Starter Kit Slide 213