Sie sind auf Seite 1von 40

Curiosity Training Lab Manual

MPLAB Code Configurator &


Core Independent Peripherals

Lab Manual

v1.08 Page 1
Curiosity Training Lab Manual

This page is intentionally left blank

v1.08 Page 2
Curiosity Training Lab Manual

Lab1 LED flashing from ISR

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

Function Pin Setting


IO_LED_D4 RA5 (2) Output
IO_LED_D5 RA1 (18) Output
IO_LED_D6 RA2 (17) Output
IO_LED_D7 RC5 (5) Output

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)

Create a new project using PIC16F1619 on Curiosity Board


Create a new project in the MPLAB X IDE:
Start MPLAB X, then go to File New Project
In New Project dialog navigate to Microchip Embedded Category and select Standalone
Project

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

From the Select Tool list we will select Curiosity

v1.08 Page 4
Curiosity Training Lab Manual

Choosing the compiler


From the Select Compiler list select the latest XC8 compiler. For this lab we use XC8 (1.35)

Saving the project and finalizing the settings


The Project Name for the first lab is LED_ISR.
For the Project Location we will use c:\curiosity_ws
Dismiss the dialog with Finish

Start the MPLAB Code Configurator tool


Select Tools Embedded MPLAB Code Configurator from the main menu.

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

Add TMR4 driver to the Project Resources


Select the MPLAB Code Configurator Resources tab.
In the Device Resources - PIC16F1619 area scroll-down to the Timer entry and expand the
list. (Hint: You may need to click-on the + symbol.)
Now double click-on the TMR4::Timer entry to add it to the Project Resources list.

Configure TMR4 for 9.088ms period


Ensure that TMR4::Timer is highlighted in the Project Resources window.
Tick Enable Timer. Select Clock Source FOSC/4, Postscaler 1:1 Prescaler 1:64
Timer period value is 0x8D for 9.088ms with the current settings.
Control mode setting is Roll over pulse, for continuous timer operation. Make sure
Start/Reset Option is Software Control This will inhibit hardware reset of timer.

Enable TMR4 software interrupt processing


If timer period needs to be extended then software overflows should be used. The overflow
of timer will trigger an interrupt and the ISR will count <Callback Function Rate> events,
before calling a predefined Callback function. This callback should contain the user code.
To configure this feature we will tick the Enable Timer Interrupt checkbox. We would like
to achieve 100ms rate on a fast clock. The closest setting is 119.088ms=99.968ms. We will
enter 11 in Callback Function Rate field

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

Add the GPIO driver to the Project Resources


Select the MPLAB Code Configurator Resources tab.
In the Device Resources - PIC16F1619 area scroll-
down to the GPIO entry and expand the list. (Hint: You
may need to click-on the + symbol.)
Now double click-on the GPIO::GPIO entry to add it to
the Project Resources list.

Configure the GPIO driver settings


Ensure that GPIO::GPIO is highlighted in the Project Resources window.
In the MPLAB Code Configurator window select PDIP20 from the drop-down list for the
Package entry.
Scroll across in the GPIO pin list to PORTA and click-on the open blue padlock below the
symbol for 1.
RA1 should appear in the Selected pins: 1 table, and a locked green padlock symbol
should now appear below pin1.
Please repeat the procedure for pins: (PORTA, 2) (PORTA, 5) (PORTC, 5)
In the selected pins: 4 table you should see RA1, RA2, RA5, RC5 listed.

v1.08 Page 7
Curiosity Training Lab Manual

Rename the I/O pins


In the Selected pins: table, double click-on the entry for IO_RA1 in Custom Name column.
Rename RA1 pin to IO_LED_D5. Please take care to use UPPER case for this lab!
In the Selected pins: 4 table, tick the check box in the column Output.
Please rename all pins according to the table below.

Pin No. Output Custom name


RA5 2 IO_LED_D4
RA1 18 IO_LED_D5
RA2 17 IO_LED_D6
RC5 5 IO_LED_D7

Your final GPIO settings should look similar to the picture below.

Generate the configuration code for the design


Click-on the Generate Code button in the MPLAB Code Configurator tab. Click Yes in the
appearing dialog.

Enable Global and Peripheral interrupts in main.c.


Select the Projects tab. If necessary expand the Source Files section of the list (Hint: Click-on
the + symbol.), then double click-on the entry for main.c
Remove line comment from lines
//INTERRUPT_GlobalInterruptEnable();
//INTERRUPT_PeripheralInterruptEnable();
This will include a call to the predefined macros and enable interrupts.
After uncommenting, your main.c should contain the following lines:

v1.08 Page 8
Curiosity Training Lab Manual

To use GPIO definitions, include pin_manager.h or mcc.h


Customized pin names in GPIO::GPIO can be used only if the related header file is included in
the source.
The GPIO definitions are located in the pin_manager.h. We need to add this file to the
includes section of the tmr4.c file.
Select the Projects tab. If necessary expand the Source Files section of the list (Hint: Click-on
the + symbol.), then double click-on the entry for MCC Generated Files\tmr4.c.
Scroll to the beginning of tmr4.c and add the
#include "pin_manager.h"
Resulting code snippet:

Add the source code for the design to tmr4.c.


Select the Projects tab. If necessary expand the Source Files section of the list (Hint: Click-on
the + symbol.), then double click-on the entry for MCC Generated Files\tmr4.c.
Scroll to the bottom of the file tmr4.c.
If not already present, modify void TMR4_CallBack(void) function and add
IO_LED_D7_Toggle();
Resulting code snippet:

Make/build the design and program the target device


Select the Make and Program Device button , or select Run Run Main Project
from the main menu.
Note: If you receive a warning message about the selection of a 5V programmable voltage,
simply click on the OK button.

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

Lab 2 LED flashing with CIPs

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

Function Pin Setting


IO_LED_D4 RA5 (2) Output
IO_LED_D5 RA1 (18) Output
IO_LED_D6 RA2 (17) Output
IO_LED_D7 RC5 (5) Output

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)

Create a new project using PIC16F1619 on Curiosity Board (screenshots in Lab 1)


Create a new project in the MPLAB X IDE:
Start MPLAB X, then go to File New Project
In New Project dialog navigate to Microchip Embedded Category and select Standalone
Project

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

From the Select Tool list we will select Curiosity

Choosing the compiler


From the Select Compiler list select the latest XC8 compiler. For this lab we use XC8 (1.35)

Saving the project and finalizing the settings


The Project Name for the second lab is LED_CIP.
For the Project Location we will use c:\curiosity_ws
Dismiss the dialog with Finish

Start the MPLAB Code Configurator tool


Select Tools Embedded MPLAB Code Configurator from the main menu.

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

Add the TMR6 driver to the Project Resources


Select the MPLAB Code Configurator Resources tab.
In the Device Resources - PIC16F1619 area scroll-down to the Timer entry and expand the
list. (Hint: You may need to click-on the + symbol.)
Now double click-on the TMR6::Timer entry to add it to the Project Resources list.

Configure TMR6 for 100.129ms period


Ensure that TMR6::Timer is highlighted in the Project Resources window.
Tick Enable Timer. Select Clock Source LFINTOSC, Postscaler 1:1 Prescaler 1:32
Timer period value is 0x60 for 100.129ms with the current settings.
Control mode setting is Roll over pulse, for continuous timer operation. Make sure
Start/Reset Option is Software Control This will inhibit hardware reset of timer.

Add the CLC1 driver to the Project Resources


Select the MPLAB Code Configurator Resources tab.
In the Device Resources - PIC16F1619 area scroll-down to the CLC entry and expand the list.
(Hint: You may need to click-on the + symbol.)
Now double click-on the CLC1::CLC entry to add it to the Project Resources list.

Configure CLC1 to realize the required JK Flip-flop function


Ensure that CLC1::CLC is highlighted in the Project Resources window.

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.

MUX1 shall be T6_postscaled_out, and GATE 1 connected to MUX1.

Assign CLC1 output to drive LED D6


CLC is internal logic function capable of generating interrupts if needed. To drive external
pins, we need to map the CLC output to an external pin. Go to MPLAB Code configurator
Pin Manager. Find CLC1OUT function and map the function to PORTA,2

v1.07 Page 14
Curiosity Training Lab Manual

Generate the configuration code for the design


Click-on the Generate Code button in the MPLAB Code Configurator tab. Click Yes in the
appearing dialog.

Make/build the design and program the target device


Select the Make and Program Device button , or select Run Run Main Project
from the main menu.
Note: If you receive a warning message about the selection of a 5V programmable voltage,
simply click on the OK button.

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

Lab 3 ADC with MCC

Purpose
Configure and use the ADC in auto convert mode and display the result on LEDS.

Hardware

Function Pin Setting


IO_LED_D4 RA5 (2) Output
IO_LED_D5 RA1 (18) Output
IO_LED_D6 RA2 (17) Output
IO_LED_D7 RC5 (5) Output
channel_Poti RC0 (16) Analog in

Theory of operation

ISR
CORE
4MHz ADC1_ISR() {
INTOSC r=ADC1_GetConversionResult();
while(1) ; D7 D6 D5 D4
r -> LEDS
}

TMR6

31kHz PRE 8Bit TMR POST


100ms
LF_INTOSC 1:8 1:10
period Vref+ Vdd

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.

Start the MPLAB Code Configurator tool


Select Tools Embedded MPLAB Code Configurator from the main menu.

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>

Add the TMR6 driver to the Project Resources


Select the MPLAB Code Configurator Resources tab.
In the Device Resources - PIC16F1619 area scroll-down to the Timer entry and expand the
list. (Hint: You may need to click-on the + symbol.)
Now double click-on the TMR6::Timer entry to add it to the Project Resources list.

Configure TMR6 for 100.129ms period


Ensure that TMR6::Timer is highlighted in the Project Resources window.
Tick Enable Timer. Select Clock Source LFINTOSC, Postscaler 1:1 Prescaler 1:32
Timer period value is 0x60 for 100.129ms with the current settings.
Control mode setting is Roll over pulse, for continuous timer operation. Make sure
Start/Reset Option is Software Control This will inhibit hardware reset of timer.

v1.07 Page 18
Curiosity Training Lab Manual

Add and configure the GPIO driver


Please find the instructions in Lab 1.
The port assignments are the same as for Lab1, according to the table below.
Pin No. Output Custom name
RA5 2 IO_LED_D4
RA1 18 IO_LED_D5
RA2 17 IO_LED_D6
RC5 5 IO_LED_D7

Add the ADC1 driver to the Project Resources


Select the MPLAB Code Configurator Resources tab.
In the Device Resources - PIC16F1619 area scroll-down to the ADC entry and expand the list.
(Hint: You may need to click-on the + symbol.)
Now double click-on the ADC1::ADC entry to add it to the Project Resources list.

Assign ADC channel to MCU pin


Poti is connected to RC0 pin. Lets go to MPLAB Code Configurator Pin Manager tab to
assign RC0 to ADC1 input.
In the MPLAB Pin Manager window select PDIP20 from the drop-down list for the Package
entry.
Scroll across in the ADC1 ANx pin list to PORTC and click-on the open blue padlock
below the symbol for 0.
RC0 should appear in the Selected pins: 1 table, and a locked green padlock symbol
should now appear below pin1.

Configure ADC1 for T6 based auto conversion and interrupt


Ensure that ADC1::ADC is highlighted in the Project Resources window.
Tick Enable ADC. Select Clock FRC. Postitive Vref is VDD and we align the result to right.
Right aligned results are best if used with full 10bit result in a C program. Left aligned result
is most efficient if 8bit measurement is sufficient.
For Auto-Conversion Trigger we use TMR6_postscaled as source.
We will show the conversion result on the LEDs from ISR, therefore we will tick Enable
ADC Intrerrupt. Customize analog input name of the channel, by clicking the custom name
column in RC0 row and typing channel_Poti

v1.07 Page 19
Curiosity Training Lab Manual

Finalized pin assignments

Generate the configuration code for the design


Click-on the Generate Code button in the MPLAB Code Configurator tab. Click Yes in the
appearing dialog.

Enable Global and Peripheral interrupts in main.c.


Select the Projects tab. If necessary expand the Source Files section of the list (Hint: Click-on
the + symbol.), then double click-on the entry for main.c
Remove line comment from lines
//INTERRUPT_GlobalInterruptEnable();
//INTERRUPT_PeripheralInterruptEnable();
This will include a call to the predefined macros and enable interrupts.

Select the Poti ADC channel and start a conversion


The default conversion channel is set to CH0 on reset. This is not the channel we want read.
Therefore we have to select the channel where the poti is connected. In MCC we were
naming the AN4 channel to channel_Poti and we will use this symbolic notation to select
our ADC channel. Add the

ADC1_StartConversion(channel_Poti);

line before the endless loop in main.c

v1.07 Page 20
Curiosity Training Lab Manual

After the modifications, your main.c should contain the following lines:

Add the source code for the design to adc1.c.


Select the Projects tab. If necessary expand the Source Files section of the list (Hint: Click-on
the + symbol.), then double click-on the entry for MCC Generated Files\adc1.c.
Scroll to the bottom of the file adc1.c.
If not already present, modify void ADC1_ISR (void) function and add
adc_result_t adval = ADC1_GetConversionResult();
IO_LED_D4_LAT = (adval > (1024*1)/5); // LEDD4 on if adval>204
IO_LED_D5_LAT = (adval > (1024*2)/5); // LEDD5 on if adval>409
IO_LED_D6_LAT = (adval > (1024*3)/5); // LEDD6 on if adval>614
IO_LED_D7_LAT = (adval > (1024*4)/5); // LEDD7 on if adval>819
Resulting code snippet:

Make/build the design and program the target device


Select the Make and Program Device button , or select Run Run Main Project
from the main menu.
Note: If you receive a warning message about the selection of a 5V programmable voltage,
simply click on the OK button.

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

Lab 4 printf to USART

Purpose
Configure and use the USART as the standard IO for printf();

Hardware

Function Pin Setting


IO_LED_D4 RA5 (2) Output
IO_LED_D5 RA1 (18) Output
IO_LED_D6 RA2 (17) Output
IO_LED_D7 RC5 (5) Output
T2 dedicated RC4 (6) Input
TX dedicated RB7 (10) Output
RX dedicated RB5 (12) Input

VDD Theory of operation


TMR2
Reset T2 S1
31kHz PRE 8Bit TMR POST
250ms RC4
LF_INTOSC 1:8 1:5
period

CORE ISR RC5 D7

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.

Start the MPLAB Code Configurator tool


Select Tools Embedded MPLAB Code Configurator from the main menu.

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>

Add TMR2 driver to the Project Resources


Select the MPLAB Code Configurator Resources tab.
In the Device Resources - PIC16F1619 area scroll-down to the Timer entry and expand the
list. (Hint: You may need to click-on the + symbol.)
Now double click-on the TMR2::Timer entry to add it to the Project Resources list.

Configure TMR2 for 250.323ms period


Ensure that TMR2::Timer is highlighted in the Project Resources window.
Make sure Enable Timer is ticked.
Select Clock Source LFINTOSC, Postscaler 1:5 Prescaler 1:8
Timer period value is 0xC1 for 250.323ms with the current settings.
Control mode setting is Roll over pulse, for continuous timer operation. Make sure
Start/Reset Option is Resets at TMR2_ers = 1
This will inhibit the timer if the S1 is not pressed.

Enable TMR2 software interrupt processing


Tick Enable Timer Interrupt checkbox and enter 1 in Callback Function Rate field

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

Add Async mode EUSART driver to the Project Resources


Select the MPLAB Code Configurator Resources tab.
In the Device Resources - PIC16F1619 area scroll-down to the EUSART entry and expand the
list. (Hint: You may need to click-on the + symbol.)
In the EUSART entry expand the list. (Hint: You may need to click-on the + symbol.)
Now double click-on the EUSART
Asynchronous (NRZ) entry to add it to
the Project Resources list.

Configure USART for 9600bps and enable STDIO redirection


Ensure that EUSART::EUSART Asynchronous (NRZ) is highlighted in the Project Resources
window. Make sure Enable USART is ticked.
Choose the desired Baud-Rate from the list of standard rates or enter the desired value
manually. For tis lab we will use 9600bps
Enable TX functionality by ticking Enable Transmit. printf() and scanf() are working on
STDIN and STDOUT. With MCC we can comfortably redirect STDIO to USART by selecting the
corresponding Redirect STDIO to USART checkbox.

Add and configure the GPIO driver


Please find the instructions in Lab 1.
The port assignments are the same as for Lab1, according to the table below.
Pin No. Output Custom name
RA5 2 IO_LED_D4
RA1 18 IO_LED_D5
RA2 17 IO_LED_D6
RC5 5 IO_LED_D7

v1.07 Page 25
Curiosity Training Lab Manual

Configure TX and RX pins for EUSART


In MPLAB Code Configurator Pin Manager assign pin 12 (PORTB, 5) to EUSART RX and pin
10 (PORTB, 7) to EUSART TX.

Completed IO configuration

Generate the configuration code for the design


Click-on the Generate Code button in the MPLAB Code Configurator tab. Click Yes in the
appearing dialog.

Enable Global and Peripheral interrupts in main.c.


Enable Global and Peripheral interrupts and printf a short help to the user:
printf("Program start. Press button to send messages.\n");
After editing, your main.c should contain the following lines:

v1.07 Page 26
Curiosity Training Lab Manual

To use GPIO definitions in timer call-back, include pin_manager.h or mcc.h


Customized pin names in GPIO::GPIO can be used only if the related header file is included in
the source. The GPIO definitions are located in the pin_manager.h. We need to add this file
to the includes section of the tmr2.c file.
Scroll to the beginning of tmr2.c and add the
#include "pin_manager.h"
Resulting code snippet:

Add the source code for the design to tmr2.c.


Open and scroll to the bottom of the file tmr2.c.
If not already present, modify void TMR2_CallBack(void) function and add
IO_LED_D7_Toggle();
printf("Active\n");
Resulting code snippet:

Make/build the design and program the target device


Select the Make and Program Device button , or select Run Run Main Project
from the main menu.
Note: If you receive a warning message about the selection of a 5V programmable voltage,
simply click on the OK button.

Start your favourite terminal on the PC


Setup 9600,8N1 communications parameters for the terminal

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

Lab 5 The railway crossing

Purpose
Hardware based button de-bouncing and simple hardware based state machine demo.

Hardware

Function Pin Setting


CLC1OUT dedicated RA5 (2) Output
CLC4OUT dedicated RA2 (17) Output
CLC2OUT dedicated RC5 (5) Output
CLCIN0 dedicated RC4 (6) Input

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

Pin Manager Assignments

v1.07 Page 33
Curiosity Training Lab Manual

Notes

v1.07 Page 34
Curiosity Training Lab Manual

Lab 6 ZEN master

Purpose
Combine Analog and Digital CIP peripherals and learn how to override MCC generated code.

Hardware

Function Pin Setting


CLC2OUT dedicated RA5 (2) Output
C2OUT dedicated RC5 (5) Output
C2IN+ dedicated RC0 (16) Analog in

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

Pin Manager Assignments

Notes

v1.07 Page 39
Curiosity Training Lab Manual
DM164137 Schematics

v1.07 Page 40

Das könnte Ihnen auch gefallen