Lecture8 - 3c - Interrupt Example - Core Timer
Lecture8 - 3c - Interrupt Example - Core Timer
●
Interrupt Example – Core Timer
Core Timer Example
Illustrate interrupts with an example that uses the
core timer to blink an LED
●
Using XC32
●
Configuring the PIC32MX470
●
Coding interrupts with XC32
●
Accessing CP0 registers
Implement this on a Microchip PIC32MX470
Curiosity Board (DM320103)
The PIC32 Oscillator
●
The PIC32MX470 can be operated at speeds
up to 120 MHz
●
Configure the example to run at 80 MHz
●
Oscillator is discussed in section 8 of the data
sheet
Oscillator Configuration
●
Use the the 20 MHz crystal onboard and the PLL in oscillator
●
Oscillator Configuration
POSCMOD and FNOSC in DEVCFG1
FPLLIDIV, FPLLMUL, and FPLLODIV in DEVCFG2
USB PLL(5)
USB Clock (48 MHz)
UFIN
div x PLL x24 div 2
UFRCEN
UFIN 4 MHz UPLLEN
UPLLIDIV<2:0> USBPLL (96 MHz)
REFCLKI ROTRIM<8:0>
POSC (M) OE
FRC
LPRC
SOSC REFCLKO
FPLLI (i.e., FIN)
System PLL PBCLK 2 N + ---------
M
512
-
4 MHz FIN 5 MHz SYSCLK
FVCO System PLL
div x PLL RODIV<14:0> To SPI
(N)
FPLLIDIV<2:0> ROSEL<3:0>
FRCDIV<2:0>
TUN<5:0>
LPRC
Oscillator 31.25 kHz typical LPRC
NOSC<2:0>
COSC<2:0>
FSCMEN<1:0> OSWEN
WDT, PWRT
Timer1, RTCC
Notes: 1. A series resistor, RS, may be required for AT strip cut crystals or eliminate clipping. Alternately, to increase oscillator circuit gain,
add a parallel resistor, RP, with a value of 1 M
2. The internal feedback resistor, RF, is typically in the range of 2 M to 10 M
3. Refer to Section 6. “Oscillator Configuration” (DS60001112) in the “PIC32 Family Reference Manual” for help in determining the
best oscillator components.
4. PBCLK out is available on the OSC2 pin in certain clock modes.
5. USB PLL is available on PIC32MX4XX devices only.
●
To generate an 80 MHz SYSCLK
#pragma config FPLLIDIV=DIV_4, FPLLMUL=MUL_16, FPLLODIV=DIV_1
( Note the input to the PLL must be between 4 MHz and 5MHz )
Check this...
1
20 MHz× ×16×1=80 MHz
4
PIC32MX330/350/370/430/450/470
Virtual Address
Bits
All Resets
Bit Range
(BFC0_#)
Register
Name
31/15 30/14 29/13 28/12 27/11 26/10 25/9 24/8 23/7 22/6 21/5 20/4 19/3 18/2 17/1 16/0
Bits
All Resets
Bit Range
(BF80_#)
Register
Name
31/15 30/14 29/13 28/12 27/11 26/10 25/9 24/8 23/7 22/6 21/5 20/4 19/3 18/2 17/1 16/0
31:16 — — — — — — — — — — — — — — — — 0000
F200 CFGCON
15:0 — — IOLOCK PMDLOCK — — — — — — — — JTAGEN TROEN — TDOEN 000B
31:16 VER<3:0> DEVID<27:16> xxxx(1)
F220 DEVID
15:0 DEVID<15:0> xxxx(1)
31:16 0000
F230 SYSKEY SYSKEY<31:0>
15:0 0000
2012-2019 Microchip Technology Inc.
Legend: x = unknown value on Reset; — = unimplemented, read as ‘0’. Reset values are shown in hexadecimal.
Note 1: Reset values are dependent on the device variant.
Where are the configuration bit
settings?
●
Configuration settings are in
/opt/microchip/xc32/v4.00/docs/config_docs/
[Link]
Installed with the XC32 compiler and has a file for
every PIC32 device ([Link] is
shown)
32-Bit Language Tools Master Index file:///opt/microchip/xc32/v2.10/docs/[Link]
Documentation for these language tools is described below. Documentation is available in several
formats:
1 of 1 1/31/21, 12:18 PM
Config-Bit Settings for PIC32MX470F512H file:///opt/microchip/xc32/v2.10/docs/config_docs/32mx4...
Usage:
#pragma config SETTING = VALUE
USERID
USERID = 00000000 Range is from 0 to 0xffff
1 of 9 1/31/21, 12:21 PM
Config-Bit Settings for PIC32MX470F512H file:///opt/microchip/xc32/v2.10/docs/config_docs/32mx4...
2 of 9 1/31/21, 12:21 PM
Config-Bit Settings for PIC32MX470F512H file:///opt/microchip/xc32/v2.10/docs/config_docs/32mx4...
3 of 9 1/31/21, 12:21 PM
LED
Choose the Red LED to blink, initialize as digital
output
Code the ISR
●
The core timer increments every 2 SYSCLKs, or
with frequency of 40 MHz
●
Blink the LED with a 1.0 second period which is
40,000,000 SYSCLKs
●
Toggle every 0.5 seconds or 20,000,000 SYSCLKs
=> Interrupt every 20,000,000 timer increments
Use compiler built ins to read and right the CP0
registers associated with the Core Timer
●
Section 15.2 and 15.3 in that chapter discuss,
and gives examples, for coding an ISR with the
XC32 compiler
Initialize the ISR
●
Use the sys/attribs header file for macros
●
Set the priority to 2 and subpriority to 0
●
Relevant registers and bit fields for the Core
Timer interrupt are found in table 7-1 in the
datasheet
Where are the interrupt names and
macros?
●
Interrupt vector macros (such as _ISR) are in the header file
/opt/microchip/xc32/v4.00/pic32mx/include/sys/attribs.h
●
Interrupt Vector definitions (such as _CORE_TIMER_VECTOR)
are in the header file
/opt/microchip/xc32/v4.00/pic32mx/include/proc/PIC32MX/
p32mx470f512.h
/* Vector Numbers */
#define _CORE_TIMER_VECTOR 0
#define _CORE_SOFTWARE_0_VECTOR 1
#define _CORE_SOFTWARE_1_VECTOR 2
#define _EXTERNAL_0_VECTOR 3
#define _TIMER_1_VECTOR 4
#define _INPUT_CAPTURE_1_VECTOR 5
#define _OUTPUT_COMPARE_1_VECTOR 6
#define _EXTERNAL_1_VECTOR 7
#define _TIMER_2_VECTOR 8
#define _INPUT_CAPTURE_2_VECTOR 9
#define _OUTPUT_COMPARE_2_VECTOR 10
#define _EXTERNAL_2_VECTOR 11
#define _TIMER_3_VECTOR 12
#define _INPUT_CAPTURE_3_VECTOR 13
#define _OUTPUT_COMPARE_3_VECTOR 14
#define _EXTERNAL_3_VECTOR 15
#define _TIMER_4_VECTOR 16
#define _INPUT_CAPTURE_4_VECTOR 17
#define _OUTPUT_COMPARE_4_VECTOR 18
#define _EXTERNAL_4_VECTOR 19
#define _TIMER_5_VECTOR 20
#define _INPUT_CAPTURE_5_VECTOR 21
#define _OUTPUT_COMPARE_5_VECTOR 22
#define _ADC_VECTOR 23
#define _FAIL_SAFE_MONITOR_VECTOR 24
#define _RTCC_VECTOR 25
#define _FCE_VECTOR 26
#define _COMPARATOR_1_VECTOR 27
#define _COMPARATOR_2_VECTOR 28
#define _USB_1_VECTOR 29
#define _SPI_1_VECTOR 30
#define _UART_1_VECTOR 31
#define _I2C_1_VECTOR 32
#define _CHANGE_NOTICE_VECTOR 33
#define _PMP_VECTOR 34
#define _SPI_2_VECTOR 35
#define _UART_2_VECTOR 36
#define _I2C_2_VECTOR 37
#define _UART_3_VECTOR 38
#define _UART_4_VECTOR 39
#define _CTMU_VECTOR 41
#define _DMA_0_VECTOR 42
#define _DMA_1_VECTOR 43
#define _DMA_2_VECTOR 44
#define _DMA_3_VECTOR 45
●
Complete the rest of the code
●
Use a “forever” loop to wait for interrupts
Build the Project
●
Use MPLAB X and the XC32 compiler and
download the hex file to the demo board, or
●
Use the XC32 compiler with the command line
and download the hex file with IPE
Demo the Project