How to Create a Divide-By-Three Circuit Using MPLAB® Melody

Last modified by Microchip on 2024/11/04 14:32

To achieve a divide by three with a duty cycle of 50 percent of an input signal, a common sequential logic implementation is done using three x D-type Flip-Flops (DFF) connected in sequence. The first two DFFs are clocked using a positive edge clock while the last DFF is clocked with a negative edge clock.

The sequential logic in the Configurable Logic Block (CLB) on some devices can only be clocked by a single source without the ability to invert the clock signal. However, many MCUs with CLB peripheral will also feature additional logic peripherals like the Configurable Logic Cell (CLC) which also contain their own DFF. This tip demonstrates how the CLB can be used with two CLCs to implement the divide by three with a 50 percent duty cycle.

Support Files

The MPLAB® X IDE project for this training can be downloaded from GitHub. It is based on the PIC16F13145 Curiosity Nano Demonstration Board.

Requirements

  • MPLAB X IDE (includes MPLAB® Code Configurator (MCC) Melody)
  • Demonstration board using a Microchip MCU with Configurable Logic Block (CLB) peripheral
  • Compatible debugger (if demonstration board doesn't provide one)
  • Oscilloscope or logic analyzer
Information

Note: For access to Microchip's Parametric Search Tool, where all devices with the required peripherals can be found, see the "Microcontroller and Processor Productspage. 


Procedure

Create a project in MPLAB X IDE and launch MCC Melody MPLAB Melody Icon.

Add CLB peripheral to the MCC Melody project.

Configure CLB to use two DFF cascaded with the output of each inverted and then routed as inputs to a 2-input AND gate whose output is connected to the first DFF input.  Clock input to CLB is the signal to be divided and the output of the last DFF connected to an output pin.

MPLAB Melody Divide by 3 CLB Schematic

Back to Top


Add CLC1 peripheral to the MCC Melody project.

Back to Top


Configure CLC1 as 1-input DFF with S and R. Connect the clock signal to be divided to the first OR gate and invert the output. Connect the second OR gate input to the input pin connected to the pin-configured CLB output.
MPLAB Melody Divide by 3 CLC1 Schematic

Back to Top


Add CLC2 peripheral to the MCC Melody project.

Back to Top


Configure CLC2 to OR-XOR connecting the output of CLC1 to one input of the top OR gate. Connect another input of the same OR gate to the CLCIN1 pin that is connected to the pin configured as CLB output.
MPLAB Melody Divide by 3 CLC2 Schematic

Back to Top


Update pin assignments in Pin Grid View pane, as shown:

MPLAB Melody Divide by 3 Pin Grid View

Results

MPLAB Melody Divide by 3 Results

Learn More

Back to Top