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.
- MPLAB® X IDE v6.20.0 or newer
- MPLAB XC8 v2.46.0 or newer compiler
- MPLAB Code Configurator (MCC)
- PIC16F1xxxx_DFP v1.25.389 or newer
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.
All necessary hardware is integrated on the Curiosity Nano. No external components are required.
- 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
- CONFIG1
- CLB Settings
_ CLB Settings
_ Clock Selection: MFINTOSC-32
_ Clock Divider: Divide clock source by 64
_ Load Configuration _ CLB Synthesizer → Load... _ SelectCnanoCLBdemo.clb
inside of the source code folder
_ Tip: Click on these buttons in the CLB Synthesizer tab toolbar to hide the sidebars for more working space!
_ 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.
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
-
Pins
- Name RC2 to LED0
- Name RC3 to SW0
- Enable Weak Pullup for RC3
Pin Name | Function |
---|---|
RC2 | LED0 Output (Active LOW) |
RC3 | SW0 Pushbutton Input (Active LOW, requires pullup) |
- Connect the Curiosity Nano to the computer with a USB Type-C Cable.
- Open the project folder in MPLAB X IDE.
- Press the Programming Button (arrow into the microcontroller) on the top toolbar.
- Select the Curiosity Nano from the list.
- Wait for the code to compile and programming to complete.
This example has shown how to get started with the CLB on the PIC16F13145 family of microcontrollers.