Presentation is loading. Please wait.

Presentation is loading. Please wait.

“Low-Pincount Workshop” FLASH Starter Kit PICkitTM 1

Similar presentations


Presentation on theme: "“Low-Pincount Workshop” FLASH Starter Kit PICkitTM 1"— Presentation transcript:

1 “Low-Pincount Workshop” FLASH Starter Kit PICkitTM 1
Uporaba MPLAB® IDE & FLASH Starter Kit PICkitTM 1

2 Izvedba: Elbacomp

3 Urnik: Predstavitev in PC / MPLAB nastavitve 9:00 - 9:20
PICkitTM1 – Start 9: :40 Kaj je MPLAB® 7.xx 9: :00 Več o PicKit :00 -10:45 Praktična uporaba PICkitTM1 11:00-12:30 Arhitektura PIC12F :30-14:00 Primeri programov 14:00-15:45 Pregled razvojnih orodij :45-16:00

4 Predstavitev Elbacomp d.o.o. in Microchip Technology

5 Corporate Overview run rate today Phoenix in Chandler, AZ
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”

6 Worldwide Technical Support Centers & Manufacturing Facilities
Oregon Manufacturing Detroit Chicago Toronto Boston San Jose Los Angeles New York Dallas Atlanta London Paris Milan Munich Shin-Yokohama Bangalore Hong Kong Taipei Seoul Singapore Shenzhen Beijing . Phoenix Kaohsiung Chengdu Fuzhou Sydney Kokomo Copenhagen Qingdao Shanghai Shanghai Test & Assembly Arizona Manufacturing and Corporate HQ Bangkok Test & Assembly 4

7 PICkitTM 1 FLASH Starter Kit Start…...

8

9 PICkitTM 1 FLASH Starter Kit

10 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.

11 PICkitTM 1 Hardware Features The 8/14 pin Evaluation
Supports 8/14 pin Flash devices Programmed via ICSP Includes a button & Potentiometer Shows multiplexing of 12 LED’s (8 provided) I/O pins are attached to an expansion header.

12 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

13 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.

14 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

15 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

16 Directories….. PICkitTM1 Flash Starterkit : use defaults
MPLAB® 6.xxx: use defaults Workshop-files: c:\lessons

17 from the presetation CDROM
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 use the latest version from the presetation CDROM Talk about the benefits of the MPLAB CD, how it is more than just a copy of MPLAB, but also a tool for the engineers to use since it has all of the data sheets, errata's, compiler demos, User guides, the Third Party Guide and Development Tools ordering guide. These are available for free, reference DS51123 DS51123

18 MPLAB® 7.xx Predstavitev kako uporabiti…..

19 Workspace 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

20 MPLAB® IDE Setup Information
Workspace: 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

21 MPLAB® IDE Windows Windows available in a new workspace Project Output
Disassembly Watch Hardware Stack Program memory File Registers EEPROM data Special Function Registers

22 MPLAB® IDE Window Descriptions
Project Project files within a project by file type: Source Files, Header Files, Object Files, Library Files & Linker Scripts Output Tabbed information about program output Disassembly Disassembled code is viewed Breakpoints can be set in code

23 MPLAB® IDE Window Descriptions (cont.)
Watch Program symbols can be monitored and displayed while program is running Hardware stack 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

24 MPLAB® IDE Window Descriptions (cont.)
File registers General purpose registers are displayed EEPROM Data Data memory stored in EEPROM is displayed Special Function Registers (SFR) Symbolic names for SFRs are displayed

25 MPLAB® v6.20 IDE With Sample Code Loaded

26 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

27 MPLAB® IDE: Using Project Wizard
Starting a new project Select: Project-> Project Wizard Select: Next

28 Project Wizard: Select Device
Step 1: Select: PIC12F Select: Next

29 Project Wizard: Select Toolsuite
Step 2: Select: Microchip MPASM™ Toolsuite Select: Next

30 Project Wizard: Select Name
Step 3: Project Directory: C:\ProgramFiles\Microchip\PICkit1\Tutorials Project Name: Workshop In A Box Select: Next

31 Project Wizard: Summary
Step 4: Summary of new project parameters Select: Finish

32 Project Wizard Completed
Project name assigned Next step is to make this project useful Windows are added which display debugging capabilities of MPLAB® IDE

33 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

34 MPLAB® Windows Open With No Code Loaded

35 Select a MPLAB® SIM Debug Tool
Debugger -> Select Tool -> MPLAB SIM MPLAB SIM chosen for this example

36 Adding Symbols to Monitor in Watch Window
View -> Watch enter registers/variables to watch click “Add SFR” or “Add Symbol”

37 Debugging using MPSIM™ Simulator
The MPLAB® IDE Program Project Window Source Code Output Window Watch Window

38 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. Configuration Bits are Important! Read the data sheet for your specific chip!

39 MPLAB® Project With Labels
Status Register: UC=1, LC=0 W Register Program Counter Checksum Word Wrap Device

40 PIC12F675 Arhitektura

41 PIC12F629/675 Block Diagram

42 8-Pin & 14-Pin Features PIC12F629/ PIC12F675 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, DFN 4 x 10-bit A/D (12F675) 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)

43 PIC12F6xx <-> PIC16F630/676
8 x 10-bit A/D PIC16F630 PIC16F676 4 x 10-bit A/D PIC12F675 PIC12F629

44 8-pin and 14-pin Compatibility
VDD VSS 8 - Pin 14 - Pin GP5/T1CKI/OSC1/CLKIN GP0/AN0/CIN+/ICSPDAT GP4/AN3/T1G/OSC2/CLKOUT GP1/AN1/CIN-/ICSPCLK VDDGP3/MCLR/VPP GP2/AN2/T0CKI/INT/COUT RC5 RC0/AN4 RC4 RC1/AN5 RC3/AN7 RC2/AN6

45 8-18 Pin Migration A/D Comparator Digital/ 8 Pin 14 Pin 18 Pin
PIC16F818/9 PIC16F676 PIC12F675 A/D PIC16C71x PIC12C671/2 PIC16F627/8 PIC16F630 Comparator Digital/ PIC12F629 PIC16C62xA PIC16C505 PIC12C50xA 8 Pin 14 Pin 18 Pin Flash OTP Enh Flash

46 Low Pin Count Migration Paths
More I/O, More A/D channels More I/O and memory, Serial comms, CCP PIC12F629 PIC12F675 PIC16F630 PIC16F676 PIC16F62x PIC16F81x Lower cost, more A/D Lower cost Flash, 10-bit A/D, EEPROM, Better Intosc, 2V Operation, More Memory, USART Flash, 10-bit A/D, EEPROM, Comparator, Better Intosc, 2V Operation, x14 Core Flash, 10-bit A/D, Better Intosc, more I/O, 2V Operation, Comparator, EEPROM, x14 Core Flash, EEPROM, 10-bit A/D, Lower cost, Better Intosc, 2V Operation Flash, A/D, EEPROM, Comparator, Better Intosc 2V Operation, x14 Core PIC12C50x PIC12C67x More I/O PIC16C505 More I/O PIC16C62x PIC16C71x Lower cost Lower cost 8-pin 14-pin 18-pin

47 Flash - Quality !!!!

48 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? This shows quality, reliability, confidence

49 Strength - Data EEPROM Provide Non-Volatile Storage for:
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

50 ADC 10 Bit versus 8 Bit

51 Advantages of a 10-bit A/D
To get 8-bit Resolution with an 8-bit A/D, the signal must be full scale Digital MCU 8-bit A/D 0V 5V 2V Adjust 0V 5V Amp 0V 5V 3V 1V IN

52 Advantages of a 10-bit A/D
Signal can be measured directly 10-bits means 1024 steps 2V/5V*1024 = 409steps more than 8-bit resolution No more scaling required No more adjustments required Less components PIC12F675 ADC IN 0V 5V 3V 1V

53 When is a Comparator helpful ?
1.) Software ADC -> PIC16F630 2.) fast hardware shutdown

54 Strength - Comparator Good General Purpose Comparator Standard on all products Internal Voltage Divider (Vref) available Up to 32 Software Programmable levels available Eight different operating modes Programmable input multiplexing Output is externally available (Use as a stand-alone analog component) Switched off if not used to save power

55 Comparator Features: Eight Operating Modes
- + CIN - CIN + Cout - + CIN - CIN + Cout Default External/Internal Out HW-shutdown possible - + CIN - CIN + Cout Vref - + CIN - CIN + Cout Internal Out External/Internal Out with Internal Reference

56 Comparator Features: Eight Operating Modes (cont.)
- + CIN - CIN + Cout Vref CIS - + CIN - CIN + Cout Off (Lowest Power) Input Multiplexing with Internal Reference - + CIN - CIN + Cout Vref CIS - + CIN - CIN + Cout Vref Internal Out with Internal Reference Input Multiplexing with Internal Reference

57 Comparator uses for 10Bit SW-ADC PIC12F6xx , PIC16F630, PIC16F/C62x
AN700 as A/D - Converter Comparator uses for 10Bit SW-ADC PIC12F6xx , PIC16F630, PIC16F/C62x

58 Temperature Measurement Circuit Using a Diode
CMCON := VRCON := VDD = 5V VDD PIC16F676 R3 VDD R1 R2 43kW MCP601 RA3 CINT ~0.1mA PortA.3 RA0 - High Input Impedance Input Range 200mV to 800mV RA2 R1 = 24kW R2 =31.5kW R3 =196kW CINT =100nF + CMCON.6 VDD / 2 Comparator Low Output Impedance AN700-”Make a Delta-Sigma Converter Using a Microcontroller’s Analog Comparator Module”

59 What is the wake-up time of a controller after SLEEP mode ?

60 Why is a quick startup important?
1mA Idd 1uA Device wakes up (8 Tcycle-int. RC), tests a condition and go back to sleep For battery applications: Minimize ‘On’ time Minimum sleep current A quick startup time reduces ‘on’ time Result: Longer battery life

61 Simplify the Power Supply

62 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

63 Wide Operating Voltage - doesn’t need a LDO...
Wider operating voltage means easier Power-supply Operating voltage range with LDO 2,0/2,2V Time

64 Strength - Packaging 8-Pin 14-Pin SN package (150mil SOIC)
DFN (Flatter) package 14-Pin 12 I/O Pins 150 mil SOIC TSSOP package available PIC12F629 PIC12F675 PIC16F630 PIC16F676

65 QFN Package Cross Section
Die Mold Compound Cu Leadframe Gold Wire Lands

66 Development Tool Support
MPLAB® Integrated Development Environment Simulator, Assembler, Linker Programming support PRO MATE® II programmer PICSTART® Plus programmer (low-cost) PICKit 1 Flash Starterkit MPLAB® In-Circuit Debugger (ICD 2) MPLAB® ICE 2000 Emulator

67 ICD for 8/14 Pin Devices ICD Device ICD2 (DV164005, (PIC12F675/ICD)
DV164006,DV164007) ICD2 Header (AC162050) Target Board To PC

68 Summary Features Flash Program Memory Real Data EE2
Wide Operating Voltage V 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

69 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 Emphasize the revisions of the data sheets as there are major differences in the contents. The latest versions are only available from the web.

70 Workshop Lessons using PICkitTM 1

71 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

72 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

73 Lesson #1 Flowchart & LED Drive Circuit

74 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

75 Lesson #1 Source Code Assembler Directives
list p=12F675 #include <p12f675.inc> __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF…... #define DELAYCONSTANT .255 #define TRISIO_INIT b' ' ;GP0 - Output #define LED GPIO,0 cblock 0x20 INNER OUTER endc

76 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

77

78 Lesson #1 Source Code Initialization of PICmicro
org 0x00 Initialize banksel GPIO ;Bank 0 movlw .7 movwf CMCON ;Comparator Off, Pins Set ;For Digital clrf GPIO banksel TRISIO ;Bank 1 movlw TRISIO_INIT movwf TRISIO clrf ANSEL ;Pins Set For Digital banksel GPIO ;Bank 0

79

80

81 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

82 Lesson #1 Source Code Main Function
bsf LED ;Turn on LED movlw DELAYCONSTANT call Delay ;Delay bcf LED ;Turn off LED movlw DELAYCONSTANT ;Delay call Delay goto Main ;Start All Over Again

83 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

84 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, [ 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 return END

85 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

86 It starts Here… “Ready for launch...”
Edit & Build Project Management Simulate and Debug Design Process Emulate Program Device

87 MPASM + MPLINK + MPLIB HEX File

88 Now bring it to PICKIT1 hardware….
LED D0 is on when: =============== RA4 -> Output High (1) RA5 -> Output Low (0)

89 Programming Interface for Steps 1 & 2

90 Lesson #1 (continued) Step 3: Download data to PICmicro
Programmer-> Write Device Or Press Write Device Button Status window shows ‘Write Successful’ LED D0 should now blink at a 200 msec rate

91 Programming Interface for Step 3

92 Lesson #2 The new code in Lesson 2 will turn LED D1 ON at startup and D0 will be OFF. 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

93 Lesson #2 Flowchart and LED Truth Table

94 Lesson #2 LED Circuit in PICkitTM 1
PICmicro can selectively drive up to 12 different LEDs using 4 I/O ports See TB029

95 Lesson #2 Step 1: Locate Lesson2.hex and load buffer
File->Import HEX Path: xxx Step 2: Download data to PICmicro 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

96 Have a predictable timing and avoid asynchronus interupts.
Lesson #3 Have a predictable timing and avoid asynchronus interupts. Taskmanager 1 2 n ... A Task Manager enhances readability of the software and the debug capabilities see also AN514,AN777

97 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,...

98 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 8-bit Data Bus External Clock Input Fosc/4 Sync with internal clocks TMR0 8-bit Programmable Prescaler T0SE (2 cycle delay) T0CS 3 Set T0IF interrupt flag on Overflow PSA PS2, PS1, PS0

99

100 “Task Manager” - in General
Initialize TMR0 Task# as offset in W-Reg Add offset on PCL-REG Goto Task0 Goto Task1 ..... Goto Taskn Task0 constant time Taskn Increment Task# and limit value Wait for TMR0 has it´s final value

101 Fill rest of task with waiting
;********** 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’ ’ 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 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 Alternative waiting: ; here you can use IRQ or TMR0 overflow-flag.... ; to do this you should preload TMR0 with the correct value ; otherwise this technic also works for the 12-Bit Core ; from Microchip like 12C509A Fill rest of task with waiting for a constant time

102 Read upper 8 Bit of ADC Channel 0 and create a standard SW-PWM via IRQ
Lesson #4 Read upper 8 Bit of ADC Channel 0 and create a standard SW-PWM via IRQ Period D.C.

103 Lesson #4 How it works…. Demo will give you approx. 124Hz Period
D.C. D.C. Initialyze IRQ IRQ: look if pin is low then make it high, then load the high-time into TMR0 IRQ: look if pin is high then make it low, then load the low-time into TMR0 Demo will give you approx. 124Hz

104 PWM-Generation PWM-Output

105 Main-Loop ; Main call Read_ADC call SetPWM goto Main ;Start All Over Again

106 10-Bit A/D Module: Left/Right Justification of A/D Result
10-Bit Result ADFM = 1 ADFM = 0 7 7 ADRESH ADRESL ADRESH ADRESL 10-Bit Result 10-Bit Result Left Justified Right Justified

107 A/D Conversion Timing

108 10-Bit A/D: Acquisition, Conversion and Sampling Time
A/D Sample Time Acquisition Time Conversion Time Terminology: The Acquisition time is the time required for the internal sampling cap to charge up to the analog input voltage. In systems terms, it starts when the channel is selected and the ADON bit is set and ends On Tad after the GO bit is set (conversion is started). The Conversion time is the time from when the GO bit is set to the time where the GO bit = 0, indicating a conversion completion. For the 10 bit A/D this is anywhere from 11 to 12 Tad. Sample Time = acquisition + conversion time. Since Conversion time is essentially known, the only design consideration is to reduce the acquisition time. Since the charging of of the internal 120pf cap is dependant on the source impedance, the lower the source impedance the faster the cap would charge. To reduce input impedance, use a voltage follower circuit just before the input to the A/D pin. Go bit set A/D Channel Selected; A/D Turned ON

109

110 Input Impedance : Looking in from the outside
Analog Input Vdd Switch Resistance R = 1..8kW Sample Cap CPIN Rs Leakage current 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

111

112

113 ADC-setup ADC-subroutine banksel ADCON0
movlw B' ' ; left adjustified, Vdd as Vref, Channel 0, ; ADC is on movwf ADCON0 banksel ANSEL movlw B' ' ; Poti of PICKIT 1 is connected to GP0 ; driven by int. RC movwf ANSEL ADC-subroutine Read_ADC bsf ADCON0,GO ; ADC starten wait_ADC btfsc ADCON0,GO goto wait_ADC movf ADRESH,W ; result is now in ADRESH return

114 ;*********************************************************************
; 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).

115

116 org 0x004 ; Interupt vector location
IntVector movwf TEMPW ; Temporarily save W btfsc PWM ; Was this a Low cycle ? goto PWMLow ; No ... PWMHigh swapf OUTHIGH,W ; Yes... Load high time without affecting STATUS flags bsf PWM nop ; Delay to equalise high/low TMR0 load cycles movwf TMR0 ; Load next edge interrupt time bcf INTCON,T0IF ; Clear TMR0 overflow flag swapf TEMPW,F ; Swap saved W swapf TEMPW,W ; Restore W IntEndHi retfie ; Return from Interrupt PWMLow bcf PWM swapf OUTLOW,W ; Load low time IntEndLo retfie ; Return from Interrupt ; end of IRQ

117 ;*********************************************************************
; 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 IntEndHi-IntVector ; Adjust for Int Service time movwf OUTHIGH movf OUTLOW,W ; addlw IntEndHi-IntVector ; Adjust for Int Service time movwf OUTLOW swapf OUTLOW,F ; Swap nibbles so that interrupt service... swapf OUTHIGH,F ; will not corrupt STATUS bsf INTCON,GIE ; Re-enable interrupts return

118 Lesson #5 Read upper 8 Bit of ADC Channel 0 and create a easy SW-”PWM” without IRQ Period D.C. Goes from 0Hz(0%) …200Hz ….8,8Khz

119 Now, please exchange the Set_PWM-SW with the following new one.
Delete the IRQ-SW. Disable all IRQ’s. READ_ADC as before..

120 Easy_PWM bcf PWM addwf ACCU,F btfsc STATUS,C GOTO TOGGLE return TOGGLE clrf ACCU bsf PWM

121 Microchip Product -Update

122 Overview Memory PICmicro Perfect match
Analog Interface Memory PICmicro Low-Power OPAMP Second source High-performance small package (SC70-LDO/OPAMP/RESET) mostly +125°C possible Reliable Partner SOT23 -> Sole source high-quality Flash (SEEVAL Tool) (Endurance Disk) Low-pin count #1 Pin-migration family high-quality Flash Self programming int. E²prom ….. Wie sollte man Microchip kennen. : …… Auf jeder Platine findet man immer eines dieser Produkte. Damit entwickelt sich Microchip zu einem immer wichtiger werdenden Partner aus einer Hand. Mit gleichem Support-Niveau , Liefertreue und Qualität für alle Produkte. Microchip macht nicht mehr nur PICmicro’s…aber dieses sind nach wie vor die wichtigsten Produkte. Perfect match

123 (Nano-power + LIN UART) Und…alles Neue ist FLASH -
Highrunner PIC16F874A Int. RC int. Reset (BOR) int. E²prom int. Comparator int. Vref int. 10Bit ADC HW-PWM 16F74/16F77 16C774 (12Bit ADC) 16F877A 18F452 (1,5KRAM) 18F458 (CAN) 18F4320 (Low-power) Int. RC int. Reset (BOR) int. E²prom int. Comparator int. Vref int. 10Bit ADC PIC16F873A 16F72/16F73 16C773 (12Bit ADC) 16F876A 18F252 (1,5KRAM) 18F258 (CAN) 18F2320 (Nano-power) PIC16F819 16C62xA 16C712/716/771 (8/10/12 Bit ADC) 16F818/819 16F628A (USART) 16F648A (4KW) 16F88/87 (4KW) 18F1220/1320 (Nano-power + LIN UART) PIC16F676 Aufgeführt sind die Highrunner von Microchip. Hier erkennt man die PICmicro-Bandbreite, Peripherien zu jedem Thema wie CAN,LIN, 12Bit ADC von 8 Pin bis 84 Pins, von 2KByte bis 128KByte. Auch die neuesten Nano-power Derivate wie ein 18F1220 ist bereits aufgeführt. Und…alles Neue ist FLASH - 1Mio. re-writes im int. EEprom, Programmspeicher bis 100K bei einer Dataretention von 40 Jahren. PIC12F675 16C505 16F630 16F676 128KByte Flash 12C50xA 12F629 12F675

124 14-Pin upgrades... ca. Sept. 2003 2kWords, 256Bytes Eeprom 8Mhz int. RC !!! New Low current WDT upto 268 sec. !!! Enhanced CCP-Modul !!! PIC16F684 PIC16F676 PIC16F630 Hier sehen Sie die Übersicht über die neusten Low-end Flash PICmicro’s. Alle besitzen einen Comparator und eine programmierbare Spannungsreferenz, zusätzlich auf der rechten Seite stehen bis zu 8x 10Bit ADC zur Verfügung. PIC12F675 PIC12F629

125 with Internal Reference
Benefits….. 1uA 1mA Device wakes up (8 clocks), tests a condition and go back to sleep Idd For battery applications: Minimize ‘On’ time Minimum sleep current A quick startup time reduces ‘on’ time Result: Longer battery life PIC12F675 Use 32kHz crystal (lowest cost) for timing Execute code running internal oscillator PIC12F675 IN 10Bit ADC Time Voltage Wider operating voltage means longer battery life Operating voltage range translates into battery life 2,0V Hier sind die Vorteile der PICmicro-Flash Bauteile: 10Bit ADC +- 1LSB bis runter zu 2,2V RTC (real-time-clock) möglich arbeiten bis 2,0V selbst wenn “Brown out reset” aktiv ist. Der interne Comparator hat eine Vref und kann auch den Ausgang auf einen Pin legen. Schnelles Start-up in 8clocks (4µs). Neuste PEEC Flashzelle, mit 40 Jahren Dataretention, echtes EEprom mit bis zu 1 Mio. Mal wiederbeschreibbar! Input Multiplexing with Internal Reference - + CIN - CIN + Cout Vref CIS real E² rewrites

126 18 Pin with Comparator + Vref
ca. June 2003 PIC16F648A 4KW PEEC Technology PIC16F628 PIC16F628A 2 Comp. + Vref. BOR int. Dual speed RC USART HW PWM Capture/Compare 18 Pin mit 2 Comparatoren und einer programmierbaren Vref.(Spannungsreferenz). Seit der Flash-Version wurde auch ein echter UART und ein echtes PWM integriert. Der int. RC arbeitet bei 4 MHz und 37KHz. Samples vom 16F628A sind bereits verfügbar. PEEC = pmos eeprom erasable cell (das ist die neuste Microchip eigene Flash Zelle) PIC16C621A/622A ca. June 2003 2 Comp. + Vref BOR more memory PIC16CR620A 2 Comp. + Vref BOR

127 18/20 Pin with ADC ca. Juni 2003 NOW ! Flash
PIC16F88/87 4KW, ICD2, 10Bit ADC, int. Osc., Comp. Low-power-Modi PIC16F819 NOW ! PIC16C770 / C771 Flash 12Bit ADC progr. BOR progr. LVD enh. HW PWM 16Bit timer Caoture/compare int. Dulspedd RC int. Vref more Memory PIC16C717 10Bit ADC progr. BOR progr. LVD enh. HW PWM 16Bit timer Caoture/compare int. Dulspedd RC int. Vref Die Geschichte hier hat mal mit dem 16C71 angefangen. Heute wird auch hier alles auf Flash umgestellt. Spannend zu bemerken ist, dass der 16F819/16F88/87 einen 8 MHZ int. Osc. haben und mit dem ICD2 arbeiten können und “Bootloader”-fähig sind (d.h. “selfprogramming” möglich über eine beliebige Schnittstelle) Samples vom 16F88 sind möglich. PIC16C712/716 8Bit ADC BOR HW PWM 16Bit timer Capture/compare PIC16C711 8Bit ADC BOR

128 PWM Quad Output Mode Example
VHIGH TC4428 TC4428 PA PB PC PD A C FET DRIVER MOTOR FET DRIVER B D Hier sieht man, dass es bereits verschiedene PICmicros gibt die direkt Halb-und Vollbrücken ansteuern können. PIC16F684 PIC16C717 PIC16C770 PIC16C771 PIC18F1220 PIC18F1320

129 Dead time control on enhanced PWM
TD TP TDC Hier ist zu sehen, wie man mit einem PICmicro direkt gegenphasige Signale erzeugen kann mit Totzeitprogrammierung. TD = Dead Time [Dual Output Mode Only] TDC = Duty Cycle Time TP = Period Time

130 PICmicro® goes….. Nanopower PIC18F2220/2320 More flexible Oscillators
Lower current Timer1 faster Startup , (8clocks) after power-up more Power-down-modi PIC16F819 PIC16F648A PIC16F628A Highest feature Lowest Cost

131 Want to try ? 4 mal im Monat 5 Positionen mit je 3 Stück
direkt ins Haus liefern lassen

132 Get info’s automatical !! Change / Errata via email
Immer auf dem neuesten Informationsstand mit einer direkt von Microchip zum Thema, Tools, Change-notification, Errata’s,….

133 Microchip delivers…….. Risk free development Lower total system cost
Faster time to market

134 Tips and Tricks

135 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

136 Dual Speed RC Oscillator resistor switching
I/O = 0: Slow speed for low current. I/O = 1: High speed for quick math.

137 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? I/O = 0: Slow speed for low current. I/O = 1: High speed for quick math.

138 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. I/O = 0: Slow speed for low current. I/O = 1: High speed for quick math.

139 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 I/O = 0: Slow speed for low current. I/O = 1: High speed for quick math.

140 Dual Speed RC Oscillator capacitor switching
I/O = 0: Slow speed for low current. I/O = 1: High speed for quick math.

141 Connecting C3 to Vdd I/O = 0: Slow speed for low current.
I/O = 1: High speed for quick math.

142 Works also for Xtal I/O = 0: Slow speed for low current.
I/O = 1: High speed for quick math.

143 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 I/O = 0: Slow speed for low current. I/O = 1: High speed for quick math.

144 Doubling charge pump I/O = 0: Slow speed for low current.
I/O = 1: High speed for quick math.

145 Inverting charge pump I/O = 0: Slow speed for low current.
I/O = 1: High speed for quick math.

146 Bad circuit! I/O = 0: Slow speed for low current.
I/O = 1: High speed for quick math.

147 Inverting charge pump with higher current
I/O = 0: Slow speed for low current. I/O = 1: High speed for quick math.

148 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 I/O = 0: Slow speed for low current. I/O = 1: High speed for quick math.

149 Self latching circuits Standard I/O
I/O = 0: Slow speed for low current. I/O = 1: High speed for quick math.

150 Self latching circuits Open Drain I/O
I/O = 0: Slow speed for low current. I/O = 1: High speed for quick math.

151 Self latching circuits Dynamic drive
I/O = 0: Slow speed for low current. I/O = 1: High speed for quick math.

152 Self latching circuits Dynamic drive simplified
I/O = 0: Slow speed for low current. I/O = 1: High speed for quick math.

153 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 I/O = 0: Slow speed for low current. I/O = 1: High speed for quick math.

154 Reading a Sensor with Higher Resolution
1. RC timing method with reference resistor 2. Charge balancing method 3. A/D method

155 I. Reading a Sensor with Higher Resolution
1. RC Timing Method: Simple RC step response Vc(t) = VDD * (1 - e -t/(RC)) t = -RC ln(1 - Vth/VDD) Vth/VDD is constant R2 = (t2/t1) * R1 t = 0 t = t1 Vth Vc(t) Time t = t2 R1 R2 AN512 Implementing Ohmmeter/Temperature Sensor AN611 Resistance and Capacitance Meter Using a PIC16C622

156 I. Reading a Sensor with Higher Resolution
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 6. Measure tRref (GP0 changes to 1). 7. Use film polypropylene capacitor. 8. Rth = x Rref RC Timing Method Rref Rsen GP2 GP1 GP0 PIC12F629 Lower leakage, ESR (Effective Serial Resistance More stable tRsen tRref Other alternatives: Voltage comparator in the PIC12F6XX

157 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

158 II. Reading a Sensor with Higher Resolution
2. Charge Balancing Method: 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. VDD Rsen PIC12F6XX Rref CVref GP1 GP2 T1G COUT Sensor resistance determines comparator high/low time. Periodic samples. More accurate, slower, noise insensitive.

159 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. 4. Accumulate the GP2 lows over many samples. 5. Number of samples determines resolution. PIC12F6XX Vin CVref GP2 GP1 COUT Software closes loop Two counters: Track time and number of ones/zeroes.

160 III. Reading a Sensor w/ Higher Resolution
A/D method: 10K Rsen GP2 GP1 AN0 (A/D input) PIC12F675 100K 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 Needs flow chart.

161 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 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

162 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.

163 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).

164 High Frequency Signal Measurement
Q1 replaces the NAND gates to reduce system cost.

165 Hardware PWM using comparators
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.

166 Hardware PWM using comparators Generating a Ramp
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.

167 Hardware PWM using comparators 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.

168 Hardware PWM using comparators Lookup table for Ascending Vref values
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.

169 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); }

170 Hardware PWM using comparators PIC16C62X Implementation
Vramp = RC square wave after filter RA3 and RA4 are PWM outputs pins. Vref output on RA2 RA2 connected to Non-Inverting terminals of both comparators.

171 Keyboard scanning using a ADC

172 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 ?

173 Methods to implement Nanowatt Technology
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 Remote Controls, RKE systems Remote Sensors Combination of both Data Logger

174 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

175 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

176 Wake-up from Stand-By Mode
Crystal Waking-Up(~8.5msec)

177 Wake-up from Stand-By Mode
Resonator Waking-Up (~390usec.)

178 Wake-up from Stand-By Mode
RC oscillator Waking-Up(~1.15usec)

179 Int. RC of PIC12F675

180 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

181 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 V typ. Leakage current on any I/O pin < uA (max. +-1 uA) max. standby = 770 nA typ. Standby 3.0V = 1.2 nA typ. Operating 3.0 V = 18 uA for further details see data sheet DS41190C

182 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

183 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

184 Active to Standby Times
Iavg = ( Idd*T1+ Ipd*T2 ) / (T1+T2) Active (T1) Idd Standby (T2) Ipd

185 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 * *2.5) / 2.501= 1.05 uA max. Typical Average Power deg C 201 nA * 3 V = 603 nanoWatt

186 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

187 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

188 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

189 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

190 I/O Port Management Pull Input Pins as close to Vdd or Vss as possible
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

191 Dual Clock Systems Many PICmicro Controllers have a 32kHz clock driver for Timer1 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

192 Dual Clock Systems TMR1 as a Real Time Clock
+5V PICmicro® C R T1OSI OSC1 Y C T1OSO C As mentioned before, we want to implement a real time clock to provide time stamping of measurements as well as other events such as upload times. We may also want to be able to synchronize the clock on an upload. A RTC can be implemented on the PICmicro MCU with the addition of a low cost 32KHz crystal and two capacitors. Two I/O pins from the MCU are used to connect to the crystal and the Timer1 module can be configured to run independently of the main oscillator. Timer1 is a 16-bit timer providing counts. Since the crystal has a 32KHz frequency this relates to a maximum 2 second overflow. By preloading Timer1, any rate that is a division of 2 from the 2 second rate can be achieved such as: 1 second, preload TMR1H with 80h ½ second, preload TMR1H with C0h etc. The source code to implement the RTC functions has very little impact to the overall code size for the application. See Application Note AN580 for more information

193 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

194 PIC16 Oscillator Sources
OSCCON To Timer 1 Timer1 Oscillator (~2 uA) Post- 1:2 scaler 1:4 1:8 1:16 1:32 1:64 FLL (x256) Internal RC OSC (31.25kHz, ~2 uA) 16-bit Postscaler Clock Monitor WDT (~30 uA) WDT Time-out For PIC16 devices, the temperature compensated and calibrated Internal RC oscillator, the FLL and its postscaler are taken from the PIC18F4320. The Internal RC oscillator can be adjusted using the OSCTUNE register. The FLL can select either the internal RC oscillator or the Timer1 oscillator as its reference frequency input and multiplies this by 256 for use as the system clock. A lower frequency can be selected under firmware control. A new postscaler driven by the Internal RC oscillator replaces the existing watch dog timer circuit with the same accuracy as the internal RC oscillator. The reset state of this postscaler will produce a watch dog timer period of 16ms. Both longer and shorter watch dog timer periods are available from this postscaler. The existing watch dog timer circuit is disconnected but not removed. The 8-bit postscaler shared by Timer0 and the watch dog timer remains, and its use is unaffected. However, it is now possible to assign this postscaler to Timer0, and still have a longer watch dog timer period using the new 16-bit postscaler. The clock monitor is also taken from the PIC18F4320. It will monitor the system clock for a failure. If a failure is detected, the internal RC oscillator will be selected as the system clock source. X 8-bit Postscaler TMR0 System Clock Bias Main Oscillator (LP, XT, HS)

195 Oscillator Sources PIC18F4320
Timer1 Oscillator Timer 1 Enable Prescaler To Timer 1 External Interrupt Internal Interrupts Event Switch Wakeup from sleep Bias Primary Oscillator (LP, XT, HS, HSPLL) To Peripherals To CPU Clock IDLE Mode Here is the oscillator system. We will be discussing the Primary oscillator, the Secondary oscillator, and the Internal RC oscillator and Frequency locked loop, and the means to select various clocks. Any of these oscillators can be used depending on the low power mode selected. In addition, some low power modes do not clock the CPU. In particular, we will be examining the INTRC oscillator, the FLL, and the postscaler, and how to select a different frequency output from the INTRC clock source. FLL (8MHz out) Internal RC OSC (31.25kHz) Post :2 scaler 1:4 1:8 1:16 1:32 1:64 FS Clock Monitor Postscaler 1:1 to 1:32768 WDT (4ms)

196 Increments and Decrements PIC12Fxxx/PIC16Fxxx
16-Bit Increment incfsz LO goto $+2 incf HI 16-Bit Decrement decf LO incfsz LO,W goto $+2 decf HI 8-Bit Decrement to 0xFF NOT_AT_FF : decf REG incfsz REG,W goto NOT_AT_FF AT_FF: Mention example1 and gloss over 2 and 3 as they operate on FF as opposed to zero. 1. Uses $ in the goto instruction to eliminate labels, shows smallest code for a 16 bit increment without a skip if non zero instruction 2. Could use only 3 instructions if transition was at 00 as opposed to FF 3. Only useful if FF transition mandatory

197 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 X,W ;GRAB X. subwf Y,W ;Y >= X? bc $+3 ;IF SO, JUMP AHEAD. addwf X ;OTHERWISE, X = X + (Y-X) = Y, subwf Y ; AND Y = Y - (Y-X) = X. 4. Note parameter passed W. Good general routine to test if register is within a certain range. Good to use to asses if a temperature measurement is within a predefined range. 5. Compares two numbers and puts them in ascending order. Can be useful when sorting numbers into order for further analysis. Note the use of the ‘bc’ instruction which is a two word instruction, atest of the carry bit followed by a goto.

198 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 N1,w subwf N2,W movf N1,W skpc movf N2,W movwf MIN subwf N3,W addwf MIN 6. Neat way of storing the smallest value in MIN without disturbing any of the three variables.

199 Miscellaneous "Switch" Statement ; ENTER WITH VALUE TO BE TESTED IN W.
XORLW VAL ;IF W = VAL1, GOTO CASE1. BZ CASE ; XORLW VAL2^VAL ;IF W = VAL2, GOTO CASE2. BZ CASE ; XORLW VAL3^VAL ;IF W = VAL3, GOTO CASE3. BZ CASE ; XORLW VAL4^VAL ;IF W = VAL4, GOTO CASE4. BZ CASE ; etc...

200 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 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-$)

201 “Do You Have the Tools to Do the Job?”

202 AVAILABILITY: MCHP has tools for every stage of the product development cycle: creating project, editing and debugging code, simulating and emulating, programming, etc... INTEGRATION: All these tools are INTEGRATED within MPLAB. MPLAB PM3

203 Assembly Language Products
It's all Free!! Microchip Universal Macro Assembler Product called MPASM™ Assembler Creates object files for use by MPLINK™ Linker or MPLIB™ Librarian Microchip Object Linker 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

204 C Compilers MPLAB® C17/C18 - $495 each Third Party 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

205 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 Available electronically FREE Have you investigated MPLAB® SIM?

206 In-Circuit Debugger - ICD 2
DV ICD 2 Module DV ICD 2 Evaluation Kit DV ICD 2 Module w/supply MPLAB® IDE compatible Firmware upgrade Debugger/Programmer Single step/breakpoint USB connect and powered or RS-232 This is one of our #1 selling tools. It offers a low-cost development tool that features both a debugger and a programmer. With MPLAB 6.10 it will support all Flash mid-range and PIC18F microcontrollers. In the future, we plan to offer device support (debugging, programming) first on this product.

207 An MPLAB® ICE System... It's Simple! Emulator Pod Processor Module
To Host PC Emulator Pod Processor Module Device Adapter Transition Socket It's Simple! To Target Board

208 Development Programmer PICSTART® Plus
RS-232 Serial Interface 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 9V DC Input PICSTART Plus DEVELOPMENT PROGRAMMER Power ON POWER Pin-1 ACTIVE Programmer Active 40-Pin ZIF Socket to accommodate PICmicro® MCUs from 8- to 40-pins. 68-pin PLCC can be programmed with an adapter

209 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)

210 Special Features In-Circuit Serial Programming™
How do I connect to ICSP™? Only two I/O pins used for programming I/O 1 is clock input I/O 2 is data input/output VPP is program voltage Driven to +13V VDD is device operating voltage Driven to +5V during programming Driven to VDD(max) and VDD(min) for verify VPP MCLR/VPP VDD VDD VSS VSS I/O 1 Clock I/O 2 Data I/O PIC16CXX PIC14CXXX PIC12CXXX

211 ICSP™ System VDD/VPP VDD PIC12/16/18xxx Programming Connector System
MCLR/VPP VDD VSS Data Clock System Connection Isolation Circuits

212 Third Party Tools Beyond Microchip’s own tools, there are over 100 third-party companies supporting Microchip products. DS00104

213 Thank You


Download ppt "“Low-Pincount Workshop” FLASH Starter Kit PICkitTM 1"

Similar presentations


Ads by Google