/pic16f13145-cnano-out-of-box-code-mplab-mcc

This repository contains the project that comes preloaded on the PIC16F13145 Curiosity Nano board. It contains a simple state machine demo of the Configurable Logic Block (CLB).

Primary LanguageCOtherNOASSERTION

MCHP

Curiosity Nano Out-of-the-Box Code Using PIC16F13145 Microcontroller with MCC Melody

This project comes preloaded on the PIC16F13145 Curiosity Nano Evaluation Kit when the user first plugs it in. It consists of a state machine demonstration of the Configurable Logic Block (CLB) peripheral that controls the behavior and/or brightness of the on-board LED.

Related Documentation

Software Used

Hardware Used

Operation

GIF of Demo

The CLB peripheral on the PIC16F13145 acts as a button debouncer and state machine for the LED. On power-up, the LED blinks at (nominally) 7.8 Hz. All other states of the state machine change the brightness of the LED via Pulse Width Modulation (PWM) dimming, which is synthesized inside the CLB as well. The pushbutton, SW0, on the Curiosity Nano is debounced within the CLB and used to advance the state machine. The table below shows the behavior for each button press.

State LED Behavior
0 The LED blinks at (nominally) 7.8 Hz.
1 Brightness Level 1 (12.5%)
2 Brightness Level 2 (25%)
3 Brightness Level 3 (37.5%)
4 Brightness Level 4 (50%)
5 Brightness Level 5 (62.5%)
6 Brightness Level 6 (75%)
7 Brightness Level 7 (87.5%)

Note: Percentages are with respect to active LOW.

Setup

All necessary hardware is integrated on the Curiosity Nano. No external components are required.

MCC Setup

  • Configuration Bits
    • CONFIG1
      • External Oscillator mode selection bits: Oscillator not enabled
      • Power-up default value for COSC bits: HFINTOSC (1 MHz)
      • VDD Range Analog Calibration Selection bit: Internal analog systems are calibrated for operation between VDD = 1.8V - 3.6V

Image of CONFIG1

  • CLB Settings _ CLB Settings _ Clock Selection: MFINTOSC-32 _ Clock Divider: Divide clock source by 64
    Image of the CLB Settings
    _ Load Configuration _ CLB Synthesizer → Load... _ Select CnanoCLBdemo.clb inside of the source code folder
    Image of the CLB Synthesizer
    _ Tip: Click on these buttons in the CLB Synthesizer tab toolbar to hide the sidebars for more working space!
    CLB Window Controls
    _ You can also maximize the current window in MPLAB X IDE by double-clicking on the tab of the desired window to maximize. Double-clicking on this again will return it to normal size. _ Window → Reset Windows can be used to reset all of the window positions and sizes in the IDE, if issues occur. _ Synthesize the Design * Click on the Synthesize button in the bottom left corner to generate the output bitstream.
    CLB Synthesize Button

Note: Synthesizing the design is required for the utilized CLB I/O to appear in the pin grid!

  • Pin Grid View

    • Set CLBPPSOUT0 to RC2
    • Set CLBIN0PPS to RC3

Pin Grid View

  • Pins

    • Name RC2 to LED0
    • Name RC3 to SW0
    • Enable Weak Pullup for RC3

Pin Settings

Pin Assignments

Pin Name Function
RC2 LED0 Output (Active LOW)
RC3 SW0 Pushbutton Input (Active LOW, requires pullup)

How to Program the Curiosity Nano

  1. Connect the Curiosity Nano to the computer with a USB Type-C Cable.
  2. Open the project folder in MPLAB X IDE.
  3. Press the Programming Button (arrow into the microcontroller) on the top toolbar.
    Programming Button
  4. Select the Curiosity Nano from the list.
    Selecting a tool
  5. Wait for the code to compile and programming to complete.

Summary

This example has shown how to get started with the CLB on the PIC16F13145 family of microcontrollers.