Beruflich Dokumente
Kultur Dokumente
Lab Manual
v1.08 Page 1
Curiosity Training Lab Manual
v1.08 Page 2
Curiosity Training Lab Manual
Purpose
Demonstrate how to configure a timer interrupt and GPIO with the MPLAB Code Configurator tool
using a PIC16F1619-I/P on a Curiosity Demo Board (DM164137).
Hardware
Procedure
Connect the Curiosity board (DM164137) to the PC.
Depending on your computer, there might be some time needed for driver installation. The
debugger on-board uses HID, and the operating system has a driver for it. (Winodws, Mac,
Linux)
v1.08 Page 3
Curiosity Training Lab Manual
Choose the right HW settings. Select from the list the device on the Curiosity board
(PIC16F1619). Please make sure the PIC16F1619 is selected, and not the LF variant.
We will not use debug header for this lab, please select None, and click Next
v1.08 Page 4
Curiosity Training Lab Manual
Setup your 4MHz internal clock and other fuses in the System resource
From Project resources choose System
From the clock settings, make sure to select INTOSC
Internal Clock should be adjusted to 4MHz_HF
setting.
The debugger on board (PKOB) uses Low Voltage
Program method to program the MCU, therefore
we must enable this fuse setting.
Expand CONFIG2 and Change:
LVP ON
PLLEN OFF
v1.08 Page 5
Curiosity Training Lab Manual
Enabling the Timer Interrupt, a new Project resource Interrupt Manager will appear .
Additional reverse exclamation icon ( ) will appear next to
timer, indicating TMR4 is using interrupts
v1.08 Page 6
Curiosity Training Lab Manual
v1.08 Page 7
Curiosity Training Lab Manual
Your final GPIO settings should look similar to the picture below.
v1.08 Page 8
Curiosity Training Lab Manual
Results
Does the LED D7 appear to flash?
v1.08 Page 9
Curiosity Training Lab Manual
Notes
v1.08 Page 10
Curiosity Training Lab Manual
Purpose
Demonstrate that the Lab 1 code could be improved to blink the LED without an ISR routine. For this
purpose we will use CIP peripherals in standalone mode.
Hardware
Theory of operation
CORE
4MHz
INTOSC
while(1) ;
CLC1
TMR6 RA2
HI J Q
31kHz PRE 8Bit TMR POST
100ms
LF_INTOSC 1:32
period
1:1 D6
K R
LO
v1.07 Page 11
Curiosity Training Lab Manual
Procedure
Connect the Curiosity board (DM164137) to the PC.
Depending on your computer, there might be some time needed for driver installation. The
debugger on-board uses HID, and the operating system has a driver for it. (Winodws, Mac,
Linux)
Choose the right HW settings. Select from the list the device on the Curiosity board
(PIC16F1619). Please make sure the PIC16F1619 is selected, and not the LF variant.
We will not use debug header for this lab, please select None, and click Next
Setup your 4MHz internal clock and other fuses in the System resource
From Project resources choose System
From the clock settings, make sure to select INTOSC
Internal Clock should be adjusted to 4MHz_HF setting.
The debugger on board (PKOB) uses Low Voltage Program method to program the MCU,
therefore we must enable this fuse setting.
Expand CONFIG2 and Change:
Low-Voltage Programming Enable Low-voltage programming enabled <LVP ON>
PLL Enable Bit 4 PLL is enabled when software sets the SPLLEN bit <PLLEN OFF>
v1.07 Page 12
Curiosity Training Lab Manual
v1.07 Page 13
Curiosity Training Lab Manual
Select J-K tab from the logic functions list. Lets connect J and K to high logic level. This is
achieved by making sure GATE 2 and GATE 4 inputs are always low (input tied to LO) and
GATE 2 and GATE 4 output is negated. You can change logic connections and
straight/negated output by clicking on the dashed squares on the wires. The R pin is
kept low with the similar technique.
v1.07 Page 14
Curiosity Training Lab Manual
Results
Does the LED D6 appear to flash?
v1.07 Page 15
Curiosity Training Lab Manual
Notes
v1.07 Page 16
Curiosity Training Lab Manual
Purpose
Configure and use the ADC in auto convert mode and display the result on LEDS.
Hardware
Theory of operation
ISR
CORE
4MHz ADC1_ISR() {
INTOSC r=ADC1_GetConversionResult();
while(1) ; D7 D6 D5 D4
r -> LEDS
}
TMR6
SAMP
FRC RC0
ADC In
ADC
v1.07 Page 17
Curiosity Training Lab Manual
Procedure
Start a new PIC16F1619 project and XC8 compiler with Curiosity board.
Connect the Curiosity board (DM164137) to the PC.
Start a new MPLABX with project PIC16F1619 and Curiosity board.
For the Project Location we will use c:\curiosity_ws
Project name is ADC_ISR and the compiler is XC8.
Setup your 4MHz internal clock and other fuses in the System resource
From Project resources choose System
From the clock settings, make sure to select INTOSC
Internal Clock should be adjusted to 4MHz_HF setting.
The debugger on board (PKOB) uses Low Voltage Program method to program the MCU,
therefore we must enable this fuse setting.
Expand CONFIG2 and Change:
Low-Voltage Programming Enable Low-voltage programming enabled <LVP ON>
PLL Enable Bit 4 PLL is enabled when software sets the SPLLEN bit <PLLEN OFF>
v1.07 Page 18
Curiosity Training Lab Manual
v1.07 Page 19
Curiosity Training Lab Manual
ADC1_StartConversion(channel_Poti);
v1.07 Page 20
Curiosity Training Lab Manual
After the modifications, your main.c should contain the following lines:
Results
Do the LEDs D4D7 display a bar graph proportional to the Poti wiper position?
v1.07 Page 21
Curiosity Training Lab Manual
Notes
v1.07 Page 22
Curiosity Training Lab Manual
Purpose
Configure and use the USART as the standard IO for printf();
Hardware
4MHz TMR2_CallBack() {
prtintf(..);
INTOSC Blink LED
printf(Active\n)
while(1) ;
}
EUSART MCP2200
RB7
9600 bps UART USB
TX
v1.07 Page 23
Curiosity Training Lab Manual
Procedure
Start a new PIC16F1619 project and XC8 compiler with Curiosity board.
Connect the Curiosity board (DM164137) to the PC.
Start a new MPLABX with project PIC16F1619 and Curiosity board.
For the Project Location we will use c:\curiosity_ws
Project name is USART_printf and the compiler is XC8.
Setup your 4MHz internal clock and other fuses in the System resource
From Project resources choose System
From the clock settings, make sure to select INTOSC
Internal Clock should be adjusted to 4MHz_HF setting.
The debugger on board (PKOB) uses Low Voltage Program method to program the MCU,
therefore we must enable this fuse setting.
Expand CONFIG2 and Change:
Low-Voltage Programming Enable Low-voltage programming enabled <LVP ON>
PLL Enable Bit 4 PLL is enabled when software sets the SPLLEN bit <PLLEN OFF>
Enabling the Timer Interrupt, a new Project resource Interrupt Manager will appear .
Additional reverse exclamation icon ( ) will appear next to timer, indicating TMR2 is using
interrupts
v1.07 Page 24
Curiosity Training Lab Manual
v1.07 Page 25
Curiosity Training Lab Manual
Completed IO configuration
v1.07 Page 26
Curiosity Training Lab Manual
Results
Do you read the "Program start. Press button to send messages. help message on your terminal?
Does the LED D7 appear to flash only while S1 is pressed?
Do you receive the text Active over USART every 250ms only while S1 is pressed?
v1.07 Page 27
Curiosity Training Lab Manual
Notes
v1.07 Page 28
Curiosity Training Lab Manual
Purpose
Hardware based button de-bouncing and simple hardware based state machine demo.
Hardware
Theory of operation
TMR2
31kHz CLC1
1 sec period RA5
LF_INTOSC Blinking
reset
blank
RC5
CLC2
TMR0
32 ms
4
period
CLC3 CLC4
RA2
Button Mode
debounce toggle
RC4 VDD
S1
CORE
while(1) ;
v1.07 Page 29
Curiosity Training Lab Manual
Procedure
Start and configure the project as in previous labs.
In System settings, dont forget to set CONFIG2:LVP ON and CONFIG2:PLLEN OFF. Oscillator is
INTOSC 4MHz.
Add all resources as listed in Resources chapter below.
Configure the resources according to CIP configurations chapter below.
Configure IO functions according to the Pin Manager Assignments chapter below.
Generate the configuration code for the design by clicking-on the Generate Code button in the
MPLAB Code Configurator tab.
Make/build the design and program the target device by clicking the Make and Program Device
button , or select Run Run Main Project from the main menu.
Results
Is D4 and D7 alternate blinking at 1sec rate? By pressing S1 blinking mode should go to static on
mode. In static on mode only D6 is on. Pressing S1 again, will revert to blinking mode.
Resources
CIP configurations
TMR2::Timer
v1.07 Page 30
Curiosity Training Lab Manual
TMR0::Timer
CLC1:CLC
The role of CLC1 is to latch the pulse coming from TMR2 rollover and based on this pulse create a
toggling signal on the output. When mode is non-blinking (CLC4 output high) then output should
always be low.
CLC2::CLC
The role of CLC2 is to
invert output of CLC1,
and ensure the output
is low in non-blinking
mode. (CLC4 output
high)
v1.07 Page 31
Curiosity Training Lab Manual
CLC3:CLC
CLC3 is de-bouncing the switch SW1 by sampling and latching the CLCIN0 (SW1 connected here) by
T0 overflow rate. As SW is active low, we invert the signal on the input mux.
CLC4::CLC
CLC4 functions as mode selector. It uses the debounced and latched SW1 state to toggle the output
of the module. If Q is high, that means non-blinking mode. The toggle principle is the same we
learned in Lab 2.
v1.07 Page 32
Curiosity Training Lab Manual
v1.07 Page 33
Curiosity Training Lab Manual
Notes
v1.07 Page 34
Curiosity Training Lab Manual
Purpose
Combine Analog and Digital CIP peripherals and learn how to override MCC generated code.
Hardware
Theory of operation
CORE
4
while(1) ;
TMR0 CLC1
65 ms
period CLC2 RA5
LED
Vdd TMR2 toggle
300 ms
period
RC0 +
CMP2
-
RC5
D7 D4
FVR
2
v1.07 Page 35
Curiosity Training Lab Manual
Procedure
Start and configure the project as in previous labs.
In System settings, dont forget to set CONFIG2:LVP ON and CONFIG2:PLLEN OFF. Oscillator is
INTOSC 4MHz.
Add all resources as listed in Resources chapter below.
Configure the resources according to CIP configurations chapter below.
Configure IO functions according to the Pin Manager Assignments chapter below.
Generate the configuration code for the design by clicking-on the Generate Code button in the
MPLAB Code Configurator tab.
Checking the CMP2::CMP settings we can spot a missing In- FVR setting. After generating the code
we will edit this setting manually, based on the datasheet. The
CMP2::CMP is initialized in the cmp2.c by function void
CMP2_Initialize(void); We can edit any source generated by the
MPLAB Code Configurator. When the Generate Code button is
pressed again a Diff Window is displayed, where we can
carefully apply or reject settings. More on the Diff Window can
be found in MPLABX help. Lets customize the CMP2_Initialize.
Checking the datasheet we reveal that CM2CON1 sets the In-
for CMP2::CMP
Final code:
Make/build the design and program the target device by clicking the Make and Program Device
button , or select Run Run Main Project from the main menu.
Results
Is D7 off approximately at Poti 75%? Is D4 blinking faster if D7 is on?
Resources
v1.07 Page 36
Curiosity Training Lab Manual
CIP configurations
TMR2::Timer
TMR0::Timer
FVR::FVR
CMP2::CMP
v1.07 Page 37
Curiosity Training Lab Manual
CLC1::CLC
CLC2::CLC
v1.07 Page 38
Curiosity Training Lab Manual
Notes
v1.07 Page 39
Curiosity Training Lab Manual
DM164137 Schematics
v1.07 Page 40