Professional Documents
Culture Documents
Slide
Slide
Agenda
Presentation: 1 hr
Hardware Tips and Tricks Software Tips and Tricks
Class
Slide
Class
Slide
Class
Slide
Class
Slide
Class
Slide
Input/Output: Multiplexing
Example - Six LEDs on 3 I/O pins
# LEDs = # I/Os * (# I/Os - 1) (1)
3V GPIO 0 1 2 0 0 1 Z Z 0 1 0 0 0 1 1 1 1 0 1 0 0 1 Z Z 0 1 1 0 0 1 1 0 Z Z 1 0 1 0 1 0 1 0 1 0 1 LEDs 1 2 3 4 5 6 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0
GP0
5 1 2 6
Note 1: #LEDs also limited by pin IOL, IOH and max device current.
2005 Microchip Technology Incorporated. All Rights Reserved. Class
Slide
To check state 0
Read 0 on pin
To check state 1
Read 1 on pin
2005 Microchip Technology Incorporated. All Rights Reserved. Class
0 1 Z
PIC12F6XX
GP0/AN0
Class
Slide
10
When GP4=1 and no keys pressed, read ID setting When GP4=0, read switch buttons
VDD
Class
Slide
11
PIC16F630
COUT
CVref
Class
Slide
12
1 Pin Power/Data
Single direction data Transistor pulls data line low via Sender GPIO Capacitor stabilizes VDD while data line low
VDD - 0.7V VDD VDD
Receiver GP0
Sender
GP0
Class
Slide
13
Class
Slide
14
VDD
Class
Slide
15
Class
Slide
16
Class
Slide
17
Class
Slide
18
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
2005 Microchip Technology Incorporated. All Rights Reserved. Class
R1
R2
Vth
t=0
t = t1
t = t2
Time
Slide
19
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. Rsen = tRsen x Rref
tRref
Slide
20
1. 10K and 100K resistors are used to set the range. 2. Set port pins for desired resistors to output 1, others to inputs. 3. Vref for A/D = VDD. 4. Rsen calculation is independent of VDD. 5. Count = Rsen/(Rsen+Rref) x 255 6. Dont forget to allow acquisition time for the A/D
Class
Slide
21
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.
GP1 Vin
PIC12F6XX
CVref COUT Software closes loop
GP2
4. Accumulate the GP2 lows over many samples. 5. Number of samples determines resolution.
Class
Slide
22
Delta-Sigma Converter
Pros:
Cons: Requires some F/W High resolution overhead Good noise immunity Slow conversion Easy to scale and offset More bits = longer the signal, even far conversion time above VDD and below VSS Absolute accuracy requires stable power Inherently linear and supply monotonic Requires minimal external components (2 Rs & 1 C)
Class
Slide
23
Class
Slide
24
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). NOP NOP GOTO$+1 CALL Rtrn ... RETURN
Rtrn
Class
Slide
25
Optimizing Destinations
Destination bit determines W or F for result Look at data movement and re-structure
Example: A + B => A MOVF ADDWF MOVWF 3 instructions A,W B,W A MOVF ADDWF B,W A,F
2 instructions
Class
Slide
26
; 2 instructions, 4 cycles
4 instructions
3 instructions
Note : When controlling ports, a two cycle zero pulse can occur
2005 Microchip Technology Incorporated. All Rights Reserved. Class
Slide
28
Class
Slide
30
1st Rotate
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 0 0 0 0 0 0 0
Class
Slide
31
Conclusion
Use of existing features wisely
TRIS states on I/Os CLKOUT output Destination locations
Class
Slide
32
References
AN512 - Implementing Ohmmeter/Temperature Sensor AN611 - Resistance and Capacitance Meter Using a PIC16C622 AN683 - A Comparator Based Slope ADC AN700 Make a Delta-Sigma Converter Using a Microcontroller's Analog Comparator Module Tips and Tricks Booklet LCD PICmicro MCU Tips 'n Tricks
2005 Microchip Technology Incorporated. All Rights Reserved. Class
Slide
33
BREAK
Slide
34
Hands-on Material
Hardware
MPLAB ICD2 Programmer / Emulator Demonstration board
Software
MPLAB IDE Project template
Documentation
Hand-out with schematic Tips n Tricks booklet
Class
Slide
35
1. Multiplexing LEDs 2. Multiplexing buttons 3. Reading a sensor with higher accuracy 4. BONUS: Implement a Delta-Sigma A/D converter
Class
Slide
36
Class
Slide
37