LED Blink Using CLC JK FlipFlop

 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.

blink_leds.gif

 Materials

Hardware Tools

Tool About Purchase
Xpress-50px.png
MPLAB® Xpress
Development Board

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.

xpress_connected_01.png

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.

4

Step 4

There are three default Project Resources in MCC associated with any MPLAB Xpress project: System Module, Pin Module, and Interrupt Module. For this project, we will leave the settings of these resources in their default state.

project_res.PNG

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.

resources_highlighted%281%29.PNG

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.

tmr0_highlighted.PNG

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.

clc_highlighted_new_01.PNG

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:

pin_diagram_select.PNG

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:

pin_diagram_hightlighted.PNG

8

Step 8

Click the Generate button in MCC to create the appropriate header and source files for this configuration. Upon successful code generation the “Generation Completed” notification should appear. Select “OK” to close the window.

figure.png

9

Step 9

Compile and download the project .hex file by clicking on the Make and Program Device button at the top of the MPLAB Xpress IDE.

Main_Program_Target_Project.png

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.

figure13.png

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.

blink_leds.gif

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.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.