Microchip 16-Bit MCU PIC24F
Microchip 16-Bit MCU PIC24F
MCU3121
16 Accumulators Address
(Working Registers) Generation
DSP Units
Engine dsPICs
(MAC) only
Multiply Accumulate
FOSC FOSC
External Clock
FCY FCY
Internal
Instruction Clock
PIC24 and dsPIC33 dsPIC30
Programmer/Debuggers
MPLAB® IDE
www.microchip.com/mplab
Defines SFR
bit-field names
Defines SFR
bit names
Defines SFR bit
name shortcuts
Defines useful
macros
Peripheral
Pin Select
Data Direction
TRISx 0 1 0 1 0 0 1 1 (1 = IN, 0 = OUT)
PORTx
Device Pins
PORTx
The GPIO pins are
Device Pins the PORT Register
© 2012 Microchip Technology Incorporated. All Rights Reserved. Slide 22
Steps for working with I/O Ports
Output
Configured with
Open Drain
ADC
Analog Digital
Input Output
© 2012 Microchip Technology Incorporated. All Rights Reserved. Slide 27
Simplified ADC Block Diagram
Channel Select One of many channel
CHS4:CHS0 select options
AN32
Configurable 16
AN31
Word Result Buffer
1 or 4 (SFRs found in DM)
• Sample Caps
•
•
32:1 Analog Mux
•
•
AN7
AN6
AN5
ADC ADCxBUF0
ADCxBUF1
AN4 •
VREFL •
AN3 VREFH VREFL •
AN2 ADCxBUFF
AVDD
AN1
AN0
VREF+
VREF-
AVSS
See device data sheet Multiple Voltage
for # of ADC channels Reference options
VCFG2:VCFG0
© 2012 Microchip Technology Incorporated. All Rights Reserved. Slide 28
ADC Sample Time
time
SOURCE
RS < 10k
ADC
+ Sample Time allows V
CHOLD VC Hold Capacitor to
- fully charge to VIN
VREFL
© 2012 Microchip Technology Incorporated. All Rights Reserved. Slide 29
ADC Conversion Time
Total Acquisition Time
Sample Time Conversion Time
TAD configured to be
time
minimum time to convert TAD
one bit in SAR ADC cycle
VC
VIN
time
Conversion auto-starts
when sampling stops
+
CHOLD VC
-
VREFL
© 2012 Microchip Technology Incorporated. All Rights Reserved. Slide 30
Generating the ADC clock period (TAD)
ADCS<7:0>
Configure TAD to be close to,
8
but not less than the
TCY ADC Clock minimum TAD
Postscaler TAD min is in the 35nS to 133nS
÷ by 1 to 256 TAD range (see data sheet)
Internal
instruction RCAD The minimum TAD time
rate
comes from the minimum
ADRC
Internal ADC RC time to convert one bit in
oscillator (4MHz Typ)
the SAR ADC process
ADC Control Register #3 (AD1CON3)
15 14 13 12 11 10 9 8
If the ADC RC
ADRC SAMC4 SAMC3 SAMC2 SAMC1 SAMC0 oscillator is used,
7 6 5 4 3 2 1 0 TAD = 250ns
ADCS7 ADCS6 ADCS5 ADCS4 ADCS3 ADCS2 ADCS1 ADCS0
VREF
ADC Control Register #1 (AD1CON1)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SSRC2 SSRC1 SSRC0 ASAM SAMP
SSRC<2:0>
VREF
ADC Control Register #1 (AD1CON1)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SSRC2 SSRC1 SSRC0 ASAM SAMP
MUX A
bits in AD1CON2 •
VCFG2:VCFG0
AN0
VREFL VREFL ADC
AN1
VREFH
AVSS
MUX B
VREF- Devices with 4
VREFL sample and holds
CH0NA/B have 4 channels
CH0 Negative
Input Select CH0SB3:CH0SB0 Channel 0 Select (Mux A):
• AN1 #2
•
AN7 AN5 #2
AN7 #2
AN6
AN5 ADC AN0 #3
AN4 AN1 #3
AN3 VREF AN5 #3
AN2 AN7 #3
AN1 AN0 #4
AN0 Enable Channel AN1 #4
Scanning # Samples per AN5 #4
Interrupt (1 to 32) AN7 #4
ADC Control Register #2 (AD1CON2) ADC Result Buffer
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
0
CSNA SMPL4 SMPL3 SMPL2 SMPL1 SMPL0
• AN1 #2
•
AN7 AN1 #3
AN1 #4
AN6
AN5 ADC DMA AN5 #1
AN4 AN5 #2
AN3 VREF AN5 #3
AN2 AN5 #4
AN1 Peripheral Indirect AN7 #1
AN0 Address (PIA) AN7 #2
AN7 #3
AN7 #4
Data Memory
DMA uses info from ADC to
generate Data Memory addresses
Each channel has it’s own
buffer in Data Memory
Temperature Operating
Coefficient Temperature (°C)
Maximum temps:
Industrial: 85°C
Extended: 125°C
What it is…
Pin multiplexing that allows user to select
the pin out of digital functions
Allows optimal usage of on-board
peripherals
Allows Pin Redefinition via software
What it is not …
Not a method to achieve pin compatibility
Analog and special pad pins (e.g., PMP &
I2C™) are still fixed
RP1 Pad
Logic
Input to Peripheral
Pad
RP2
Logic
Pad
RPn
Logic
efine the location of each function used by modifying xxxxR bits in RPINRn registers
Peripheral Output
Select Bits
Peripheral 1 Output
Peripheral 2 Output
Peripheral 3 Output
Pad
RP0
Logic
Peripheral N Output
RPOR0bits.RP1R = 3
efine the output functionality on each pin by modifying RPnR bits in RPORn registers
© 2012 Microchip Technology Incorporated. All Rights Reserved. Slide 54
PPS Register Protection
HW integrity checking
Bit flip will cause device reset
I/O lock feature
RPINRn/RPORn can only be written to, while
the IOLOCK bit in the OSCCON register = 0;
once the IOLOCK is set, the registers cannot be
written.
IOLOCK Protection
The state of the IOLOCK bit can only be
changed with an unlocking sequence
Protection selectable by configuration bit
Peripheral priorities:
1. Analog Functions ANx, Vref+/-
2. PPS Outputs UART TX, SDO, OC
3. PPS Inputs UART RX, SDI, IC
4. Fixed Digital Peripheral Outputs I2C, PMP
5. Fixed Digital Peripheral Inputs I2C, PMP
Pad
Logic
RP2
Pad
Logic
RP3
Input to Peripheral #2
e.g. INT1
Output to Peripheral
e.g. SDO
Application
64 KB Flash, 8 KB RAM
2 ch A/D, Ext. VREF
2 Comparators
UART x 2, I2C, SPI x 2
4 Digital I/O
3 Spare Pins
PR2
PR2
Period
Register ADC Event Trigger
TCY TMR3
TMR3 TMR2
TMR2
TCS Reset
Timer2 & Timer3 and
Timer4 & Timer5 can be TGATE 32
32 bit
bit Comparator
Comparator
combined to work like Equal
Event
Event and
and
Set Input Capture
Interrupt
Interrupt Logic
Logic
Interrupt Flag
4-Level
Input Capture Interrupt Modes FIFO ICxBUF
ICxBUF
11: Interrupt on every fourth capture event
10: Interrupt on every third capture event
01: Interrupt on every second capture event
00: Interrupt on every capture event
Fixed Frequency
© 2012 Microchip Technology Incorporated. All Rights Reserved. Slide 72
Output Compare
Block Diagram (one of several types)
Output Compare Output Compare Output
Set Output Compare
Register Register Secondary Compare Pin
Interrupt Flag
OCxR
OCxR OCxRS
OCxRS
S
S Q
Q OCx
Output
Output
Comparator
Comparator R
R
Compare
Compare Logic
Logic
OCTSEL
OCFA or OCFB
OCM<2:0>
PWM Fault Pins
TMR2
TMR2 TMR3
TMR3
Output Compare Modes:
Comparator
Comparator Comparator
Comparator 11x: PWM
Period Register 10x: Single or continuous pulse
PR2
PR2 PR3
PR3 0xx: Set, Clear, or Toggle OCx Pin
Timer3 Output Compare
Timer2 See data sheet for details
Timer Select
OCTSEL
OCM<2:0>
TMR2
TMR2 TMR3
TMR3
Comparator Comparator
PR2/3
PR2/3
Comparator Comparator
OCxR
OCxR OCxRS
OCxRS
PR2
PR2 PR3
PR3
Timer2 Timer3
OCx
TMR2/3 reset to 0
on period match TMR2/3
OCTSEL
OCFA or OCFB
OCM<2:0>
PWM Fault Pins
TMR2
TMR2 TMR3
TMR3
At start of period:
Comparator Comparator OCxRS
OCxRS
Comparator Comparator OCxRS copied
into OCxR
PR2
PR2 PR3
PR3 OCx set high OCxR
OCxR PR2/3
PR2/3
Timer2 Timer3
# of Stop Parity
STSEL Parity UxTX
bits select Baud
Baud Rate
Rate Parity Generator
Generator
High Baud Generator
Generator Start
BRGH 0
Rate select UART TX Pin
Stop
1
UARTx Mode Register (UxMODE)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
0
UARTEN LPBACK BRGH PDSEL1 PDSEL0 STSEL
UxBRG
UxBRG Baud Rate
Register
UART Baud Rate Generator
BRGH = 0 FCY
(standard Baud Rate =
16 x (UxBRG + 1)
speed)
See the UART section in
BRGH = 1 FCY the Family Reference
(high speed) Baud Rate = Manual for tables of baud
4 x (UxBRG + 1)
rates and BRGH settings
UARTx Mode Register (UxMODE)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
UARTEN BRGH PDSEL1 PDSEL0 STSEL
© 2012 Microchip Technology Incorporated. All Rights Reserved. Slide 81
Lab 5:
Working with the UART
Questions?