Skip to content

This MPLAB X Melody code example shows how to make an LED blink using the Configurable Custom Logic (CCL) found in the AVR® DB. The CCL is configured as a toggling J-K flip-flop. The toggling is a result of a timer event.

License

microchip-pic-avr-examples/avr128db48-blink-led-ccl-mplab-mcc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCHP

Blink Using Integrated Logic

This MPLAB X Melody code example shows how to make an LED blink using the Configurable Custom Logic (CCL) found in the AVR® DB.

The CCL is configured as a toggling J-K flip-flop, also known as a T flip-flop. While a regular J-K flip-flop has two inputs and a clock signal that toggles the output on rising edges, the T flip-flop only uses a clock signal to toggle and has no other inputs. To achieve this, the J and K input needs to be set to constant logical '1'.

Flip flop

An internal clock signal can be used for the toggling, but it will toggle the output so fast that the blinking of an LED will appear as an LED that is always on. To get a more reasonable time between blinks, an alternative is to use the AVR event system. The event system needs a generator to generate the event, and a peripheral to make use of the event. In this example, a timer will trigger an event each time the timer overflows. The event will then be used as the clock input for the T flip-flop. This way makes it easier to set a specific time between each blink.

Timing Diagram

Related Documentation

Software Used

Hardware Used

Setup

MCC with the Melody library was used to implement this example, once downloaded and opened in MPLAB X, it only requires the project to be built and flashed to an AVR DB Curiosity nano device.

Build and Flash

To change configurations in MCC, simply push the MCC icon in MPLAB X, and wait for MCC to start.

MCC

Operation

The configurations in MCC for this example, are demonstrated and explained below. In this example, the three peripherals CCL, TCA timer, and the Event System are added and configured.

Overview

Peripherals

Setting up the CCL:

  1. Add CCL from “Drivers” in the Device Resources list by pressing the corresponding green cross.

    CCL MCC

  2. Enable the CCL.

    CCL Enable

  3. Go into the CCL GUI and choose the LUTs to use. Each LUT can be configured by pressing the related cogwheel.

    CCL LUT

  4. In this example, we want to use a JK flip-flop as a T flip-flop.

  5. We need two LUTs for the J and K input.

  6. The two inputs need to be constant 1 so we use a custom logic set to 0xFF.

    CCL LUT

  7. We want the T flip-flop to be triggered by an event instead of a clock.

  8. To get an event as an input for the clock, one of the logic inputs needs to be set as the new clock signal.

  9. We here set it to be IN2.

  10. In the logic gate, we choose IN2 to be one of the event channels, EVENTA.

    CCL LUT Config

  11. Enable LUT and LUT output in the two chosen LUTs.

  12. We want the toggling to happen to a specific pin. This pin will be used to toggle an LED. This will affect the LUTs you use. In our case, the PB3 pin is preferable because it has an LED connected to it for the CNANO. We therefore use LUT4 and LUT5.

  13. Connect the output of the JK flip flop to the output pin. To connect an output in MCC, press the output and drag it to the selected output pin.

Setting up the TCA timer:

  1. Add the TCA0 from the Timer list, found under “Drivers” in the Device Resources list.

    TCA MCC

  2. Open the TCA tab.

    TCA Overview

  3. Enable TCA.

  4. Choose a clock selection. Bigger divisions of the System clock give a slower clock which allows for longer delays. We have chosen "System Clock / 16".

  5. Choose count direction. We have chosen UP count.

  6. Choose the Waveform generation mode. We have chosen the default, "Normal Mode".

  7. Choose the desired clock time between each overflow. We have chosen 0.25 seconds, this is the time between overflows, meaning an event will trigger every 0.25s. The T flip flop will therefore toggle the LED every 0.25s.

Setting up the Event system:

  1. Open the Resource management tab.

    EVSYS MCC

  2. Add the EVSYS initializer from “Peripherals” in the Device Resources list.

  3. Open the EVSYS initializer tab.

    EVSYS overview

  4. Set the generator. We use the TCA to generate an event on each overflow. We choose this in MCC by setting one of the channels, CHANNEL0 to TCA0_OVF_LUNF .

    EVSYS Channel 0

  5. Set the user. When configuring the CCL, event channel A (EVENTA) was used as an input for LUT4. To set LUT4 as the user of the event, select USERCCLLUT4A, and set it to the same channel as the generator, CHANNEL0.

    EVSYS Channel 0 User

Once all configurations are complete the code needs to be generated. Go to the Resource Management [MCC] tab, and click on the Generate button to generate the code.

Generate MCC Code

Build the code and flash your device.

Build and Flash

If build and flashing were successful the LED on the board should start blinking with 0.25s intervals.

CNANO Blink

Conclusion

After going through this example you should be able to make an LED blink, and be more familiar with how to:

  • Configure the Timer to generate an overflow event
  • Configure the Event System to route a Timer overflow event to CCL
  • Configure the CCL JK flip-flop with constant inputs, and an overflow event as the clock

About

This MPLAB X Melody code example shows how to make an LED blink using the Configurable Custom Logic (CCL) found in the AVR® DB. The CCL is configured as a toggling J-K flip-flop. The toggling is a result of a timer event.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published