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 the 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.
|Tool|| About|| Purchase|
| Windows|| Linux|| Mac OSX|
Cloud Integrated Development Environment
| Windows|| Linux|| Mac OSX|
Project and Source Files
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 below. No other components are required.
Create a new project in MPLAB Xpress for a PIC16F18855 using the MPLAB Xpress Evaluation Board. Instructions are below if this is your first project.
Open the MPLAB Code Configurator (MCC) under the Tools > Embedded > MPLAB Xpress Code Configurator menu of MPLAB Xpress IDE. Instructions are below if this is your first project.
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.
Once TMR0 is added to the project and selected, the easy setup interface appears. Change the Clock Prescaler to 1:512, Clock Source to FOSC/4 and Timer Period to 500 ms as highlighted in the following picture. All other options remain as default.
Using a similar procedure to that used in task 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 drop down 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 gate's output by simply clicking the output side. Changes are highlighted in the image below.
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 below.
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 below.
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.
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.