Logic AND Gate

The CCL module can be used to implement a logic gate with up to three inputs. The following example shows how to configure and use CCL LUT1 to implement an AND gate.

Figure 1. Using CCL as Logic AND Gate
On the first step, the I/O pins are selected as inputs using the INSELx[3:0] bits from the LUT control registers (LUTnCTRLB and LUTnCTRLC):
Figure 2. LUTn Control B Register
Figure 3. LUTn Control C Register

The table below summarizes the INSEL[3:0] options for all inputs.

Figure 4. CCL Input Selection Options

This translates to the following code:

CCL.LUT1CTRLB = CCL_INSEL0_IO_gc | CCL_INSEL1_IO_gc;

CCL.LUT1CTRLC = CCL_INSEL2_IO_gc;

The next step is to configure the Truth tables for LUT1 to generate the right combinational logic to implement an AND gate on the selected pins. Thus, the Truth table will have a value of 0x80.

CCL.TRUTH1 = 0x80;

The next step is to configure the output of decoder, specifically, the I/O Port pin (PC3) in this example. This is done by setting the OUTEN bit on the LUT0CTRLA register.

Figure 5. LUTn Control A Register

This translates to the following code:

CCL.LUT1CTRLA = CCL_OUTEN_bm;

By enabling the LUTn output on the I/O pin, the settings for the corresponding pin are overwritten. To enable the decoding of the input sequence, the CCL and the used LUTs need to be enabled. That is done using the ENABLE bit from the LUTnCTRLA register.

CCL.LUT1CTRLA |= CCL_ENABLE_bm;

To complete the setup, the CCL module should also be enabled using a CCL global Enable bit from the CTRLA register.

Figure 6. CCL Control A register
CCL.CTRLA = CCL_ENABLE_bm;
Tip: The full code example is also available in the Appendix section.