Objective
The Configurable Logic Cell (CLC) is a hardware peripheral inside many of the latest PIC® microcontrollers. Using the CLC is quite easy as there is a graphical user interface built into MPLAB® Code Configurator (MCC) that will generate code required to setup the CLC. This project takes you step by step through setting up the CLC and Timer0 to toggle all four LEDs every 500 ms on the Xpress Evaluation Board featuring PIC16F18855 microcontroller.
Materials
Hardware Tools
Tool | About | Purchase |
---|---|---|
| |
Software Tools
Tool | About | Installers |
Installation
Instructions |
||
---|---|---|---|---|---|
Windows | Linux | Mac OSX | |||
MPLAB® Xpress
Cloud Integrated Development Environment |
| |
Exercise Files
File | Download |
Installation
Instructions |
||
---|---|---|---|---|
Windows | Linux | Mac OSX | ||
Project and Source Files
|
| | | |
Procedure
1
Step 1
The MPLAB Xpress Evaluation Board should be connected to an available USB port on the host computer through a USB cable to the micro B connector on the board. Drivers should install successfully the first time the board is connected and may take a minute or so. The connection is shown in the picture. No other components are required.
2
Step 2
Create a new project in MPLAB Xpress for a PIC16F18855 using the MPLAB Xpress Evaluation Board.
3
Step 3
Open MCC from the MPLAB Spress IDE menu: Tools > Embedded > MPLAB Xpress Code Configurator.
5
Step 5
The Timer 0 (TMR0) peripheral needs to be setup. From the Device Resources panel, double click on TMR0 module under Timer to add it to the project.
space
Once TMR0 is added to the project and selected, the easy setup interface appears. Change the Clock Prescalar to 1:512, Clock Source to FOSC/4, and Timer Period to 500 ms (see image). All other options remain as default.
6
Step 6
Using a similar procedure to that used in step 5, CLC1 module is added to the project resource. CLC1 has different modes of operation and we are using the JK flip-flop mode to toggle the output. According to the properties of the JK flip-flop, if both J and K inputs are high, the output toggles on every rising edge of the clock signal. Select T0_overflow from the dropdown menu as clock input and connect the wire to the first NOR gate by simply clicking on it. To set J and K input high, invert the second and fourth NOR gates' output by simply clicking the output side. Changes are highlighted in the image.
7
Step 7
The MPLAB Xpress Evaluation Board has four LEDs and from the schematic, we can see they are connected to the Pins: RA0, RA1, RA2 and RA3. Since we want all four LEDs to toggle, connect the output of the CLC1 to the LEDs by simply clicking those four ports using the pin layout interface as shown:
space
Notice in the previous image, port RA0 and RA1 are showing a link symbol instead of lock symbol as port RA2 and RA3. In order to get the CLC to work, CLCIN0 and CLCIN1 input pins need to be assigned and RA0 and RA1 are selected as default. Using the Peripheral Pin Select (PPS) feature of the PIC16F18855, these ports can be used as CLC output without changing the input pins but for the simplicity of this tutorial, we are moving these input pins to RA4 and RA5 by simply clicking those two ports as shown:
10
Step 10
Program the MPLAB Xpress Evaluation Board by dragging the project .hex file from the downloads section of the browser and dropping the file onto to the Xpress drive.
The Programmer LED on the Xpress board should quickly flash from green to red and then back to green indicating that the .hex file was successfully programmed to the PIC16F18855.
The Red LEDs will begin flashing on the Xpress board.
Summary
This simple project showed how to setup a CLC to control output pins. Notice that the project never required any code changes as the MCC handled all the setup. The CLC then runs in hardware in the background. The main.c file could be modified to perform some software functions in parallel with the CLC if the user wanted to expand the capabilities of this project. This project then becomes the basis for future CLC controlled applications.