915 Tat
-
Upload
vivek-vats -
Category
Documents
-
view
218 -
download
0
Transcript of 915 Tat
-
8/6/2019 915 Tat
1/37
2005 Microchip Technology Incorporated. All Rights Reserved. Slide 1
915 TAT
Tips & Tricks on Designingwith Microchips
6/8/14-pin Devices
-
8/6/2019 915 Tat
2/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 2
What this class is...
TricksTricks
IdeasIdeas
TipsTips
HintsHints
-
8/6/2019 915 Tat
3/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 3
Agenda
Presentation: 1 hr
Hardware Tips and Tricks Software Tips and Tricks
Break: 10 min
Hands-on session: 3 hours
-
8/6/2019 915 Tat
4/37 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 4
8- and 14-pin Flash Devices
High Performance MCU DC to 20 MHz operating speed
8-level deep stack
FLASH Program Memory
Re-programmable In-Circuit Serial Programming (ICSP) capability
Low Power Consumption Low Voltage operation with EEPROM write capability
over whole voltage range (2V-5.5V)
-
8/6/2019 915 Tat
5/37 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 5
Tips and Trickswith Hardware
-
8/6/2019 915 Tat
6/37 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 6
Dual Speed RC Oscillator
PIC12F6XX
GP0OSC1
+5V
R1 R2
C
1. After reset I/O pin is High1. After reset I/O pin is High ImpedenceImpedence
(running at low frequency)(running at low frequency)
2. Output a high on I/O pin2. Output a high on I/O pin
3. R1, R2 and C determine Osc Frequency3. R1, R2 and C determine Osc Frequency
4. Works also with additional capacitors4. Works also with additional capacitors
-
8/6/2019 915 Tat
7/37 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 7
Screen Captures using Hewlett-Packard Mixed Signal Oscilloscope 54645
Dual Speed RC Oscillator
Freq = 2.1 MHz
Duty Cycle = 91%
Freq = 4.3 MHz
Duty Cycle = 90%
-
8/6/2019 915 Tat
8/37 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 8
Input/Output: Multiplexing
1 2
3 4
3V
GP0
GP1
GP2
PIC12F6XX
5 6
GPIO LEDs0 1 2 1 2 3 4 5 6
0 0 0 0 0 0 0 0 00 1 Z 1 0 0 0 0 01 0 Z 0 1 0 0 0 0Z 0 1 0 0 1 0 0 0
Z 1 0 0 0 0 1 0 00 Z 1 0 0 0 0 1 01 Z 0 0 0 0 0 0 10 0 1 0 0 1 0 1 00 1 0 1 0 0 1 0 0
0 1 1 1 0 0 0 1 01 0 0 0 1 0 0 0 1
1 0 1 0 1 1 0 0 01 1 0 0 0 0 1 0 11 1 1 0 0 0 0 0 0
Example - Six LEDs on 3 I/O pins
# LEDs = # I/Os * (# I/Os - 1) (1)
Note 1: #LEDs also limited by pin IOL, IOH and max device current.
-
8/6/2019 915 Tat
9/37 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 9
PICMCUI/O
Read 3 States from 1 Pin
To check state Z Drive output pin high
Set to input
Read 1
Drive output pin low
Set to input
Read 0
To check state 0 Read 0 on pin
To check state 1 Read 1 on pin
State Pin 0 Pin 1
0 closed open1 open closedZ open open
5v
0v
Pin 1
Pin 0
-
8/6/2019 915 Tat
10/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 10
4x4 Keyboard with 1 Input
GP0/AN0
PIC12F6XX
VDDResistors chosen for unique voltages
Use A/D to measure button voltage
-
8/6/2019 915 Tat
11/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 11
Decode Keys and ID SettingsDecode Keys and ID Settings
When GP4=1and no keyspressed, readID setting
When GP4=0,read switch
buttons
GP0
GP4
GP1
GP2
GP3
VDD
-
8/6/2019 915 Tat
12/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 12
Reading four switches with
one Comparator and two pins Set CVref to check for each valid level
Toggle input select to check second pair
Switches pull up to optimize range of CVref
CVref
PIC16F630
COUT
VDD
-
8/6/2019 915 Tat
13/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 13
1 Pin Power/Data
Single direction data Transistor pulls data line low via Sender GPIO Capacitor stabilizes VDD while data line low
GP0 GP0
SenderReceiver
VDD
VDD
VDD - 0.7V
-
8/6/2019 915 Tat
14/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 14
Generating High VoltagesGenerating High Voltages
CLKOUT generates frequency for charge pumpCLKOUT generates frequency for charge pump
Low costLow cost Minimal part countMinimal part count
PIC12F6XXw/ RCCLKOUT
CLKOUTVout max = (2 * VDD) - (2 * Vdiode)
CpumpCfilter
VDD
-
8/6/2019 915 Tat
15/37
-
8/6/2019 915 Tat
16/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 16
Smart Current Limiter
Using A/D Motor control and power supplies often need
current limiter
Intelligent control can be done for: In-rush current
Current limiting
Over-current recovery
Smart circuit breaker
-
8/6/2019 915 Tat
17/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 17
Using PICmicroMCU A/D
for Smart Current Limiter
Detect current throughlow side sense resistor
Optional peak filter
capacitor Varying levels of
overcurrent response
can be realized insoftware
Rsense
10KLoad or Motor
PIC12F6XX
AN0
-
8/6/2019 915 Tat
18/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 18
1. RC timing method with reference resistor
2. Creating a Delta-Sigma ADC
Reading an Analog Sensor
Without an ADC Peripheral
-
8/6/2019 915 Tat
19/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 19
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
R1R2
Reading an Analog Sensor
Without an ADC Peripheral
-
8/6/2019 915 Tat
20/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 20
Other alternatives: Voltage comparator in the PIC12F6XX
1. Set GP1 and GP2 to inputs, andGP0 to a low output to discharge C.
2. Set GP0 to an input and GP1 to ahigh 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. Rsen = x RreftRsen
tRref
Rref
Rsen
GP2
GP1
GP0
PIC12F6XX
1. RC Timing Method
Reading an Analog Sensor
Without an ADC Peripheral
-
8/6/2019 915 Tat
21/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 21
10K
Rsen
GP2
GP1
AN0 (A/D input)
PIC12F6XX100K
1. 10K and 100K resistors areused to set the range.
2. Set port pins for desired resistorsto output 1, others to inputs.
3. Vref for A/D = VDD.4. Rsen calculation is independent
of VDD.5. Count = Rsen/(Rsen+Rref) x 2556. Dont forget to allow acquisition
time for the A/D
Used to dynamically adjust the range as needed.
Reading a Sensor w/ Higher
Resolution
-
8/6/2019 915 Tat
22/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 22
1. GP1 average voltage = CVref2. 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 overmany samples.
5. Number of samples determines resolution.
PIC12F6XX
Vin
CVref
GP2
GP1
COUT
Softwarecloses loop
Delta-Sigma Converter
-
8/6/2019 915 Tat
23/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 23
Delta-Sigma Converter
Pros:
High resolution
Good noise immunity Easy to scale and offset
the signal, even far
above VDD and belowVSS
Inherently linear andmonotonic
Requires minimalexternal components(2 Rs & 1 C)
Cons:
Requires some F/W
overhead Slow conversion
More bits = longer
conversion time Absolute accuracy
requires stable powersupply
-
8/6/2019 915 Tat
24/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 24
Tips and Trickswith Software
-
8/6/2019 915 Tat
25/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 25
NOP
NOP ;2 instructions, 2 cycles
CALL Rtrn ;1 instruction, 4 cycles. . .
Rtrn RETURN
GOTO$+1 ;1 instruction, 2 cycles
Delay Techniques
Use GOTO next instruction instead of two NOPs.
Use CALL Rtrn as quad, 1 instruction NOP (where Rtrn
is the exit label from an existing subroutine).
-
8/6/2019 915 Tat
26/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 26
Optimizing Destinations
Destination bit determines W or F for result
Look at data movement and re-structureExample: A + B => A
MOVF B,WADDWF A,F
2 instructions
MOVF A,WADDWF B,WMOVWF A
3 instructions
-
8/6/2019 915 Tat
27/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 27
Optimizing Function Calls
Subroutine . . . ; Do something
RETURN
. . .CALL Subroutine ; 2 instructions, 4 cycles
RETURN
. . .
GOTO Subroutine ; 1 instruction, 2 cycles
Replace a CALL instruction that is immediately followed
by a RETURN instruction by a GOTO instruction
-
8/6/2019 915 Tat
28/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 28
Conditional Bit Set/Clear
To move single bit of data from REGA to REGB:
Precondition REGB bit
Test REGA bit and fix REGB if necessary
BTFSS REGA,2BCF REGB,5BTFSC REGA,2BSF REGB,5
4 instructions
BCF REGB,5BTFSC REGA,2BSF REGB,5
3 instructions
Note : When controlling ports, a two cycle zero pulsecan occur
-
8/6/2019 915 Tat
29/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 29
Swap File Register with W
The following macro swaps the contents of W and
REG without using a second register
SWAP MACRO REG
XORWF REG,FXORWF REG,WXORWF REG,FENDM
Needs: 0 TEMP Registers3 Instructions
3 Tcy
W = 0xaa, REG = 0x55
1010 1010
0101 01011111 1111 (REG)
1010 1010
0101 0101 (W)
1111 1111
1010 1010 (REG)
-
8/6/2019 915 Tat
30/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 30
Rotate a byte through carry without using RAM
variable for loop count:
Easily adapted to serial protocol routines.
Carry bit is cleared (except last cycle) and the
cycle repeats until the zero bit sets indicating
the end.
Bit Shifting using Carry Bit
-
8/6/2019 915 Tat
31/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 31
Bit Shifting using Carry Bit
1
C
Z = 1
2nd Rotate
1st Rotate
Final Rotate
1 0 1 0 1 0 1 0
7 0
1 0 1 0 1 0 1 0
10 0 1 0 1 0 1 0
01 0 0 0 0 0 0 0
1
-
8/6/2019 915 Tat
32/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 32
Conclusion
Use of existing features wisely
TRIS states on I/Os
CLKOUT output
Destination locations
Simple external circuits
RC circuits Resistor ladders / dividers
-
8/6/2019 915 Tat
33/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 33
References
AN512 - ImplementingOhmmeter/Temperature Sensor
AN611 - Resistance and Capacitance MeterUsing a PIC16C622
AN683 - A Comparator Based Slope ADC
AN700 Make a Delta-Sigma ConverterUsing a Microcontroller's Analog
Comparator Module Tips and Tricks Booklet
LCD PICmicro MCU Tips 'n Tricks
-
8/6/2019 915 Tat
34/37
2005 Microchip Technology Incorporated. All Rights Reserved. Slide 34
BREAK
-
8/6/2019 915 Tat
35/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 35
Hands-on Material
HardwareHardware
MPLABMPLAB
ICD2 Programmer / EmulatorICD2 Programmer / Emulator Demonstration boardDemonstration board
SoftwareSoftware MPLAB IDEMPLAB IDE Project templateProject template
DocumentationDocumentation HandHand--out with schematicout with schematic TipsTips n Tricks bookletn Tricks booklet
-
8/6/2019 915 Tat
36/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 36
Lets Write Some Code!
1. Multiplexing LEDs1. Multiplexing LEDs
2. Multiplexing buttons2. Multiplexing buttons
3. Reading a sensor with higher accuracy3. Reading a sensor with higher accuracy
4. BONUS: Implement a Delta4. BONUS: Implement a Delta--Sigma A/D converterSigma A/D converter
-
8/6/2019 915 Tat
37/37
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 37