News:

Let's find out together what makes a PIC Tick!

Main Menu

CIP peripherals

Started by Giuseppe MPO, May 01, 2021, 11:35 PM

Previous topic - Next topic

Giuseppe MPO

I hope it's not OT.
I had never used CIPs.
It took a little time to understand how it works but once I learn they are really interesting.
An AC dimmer that works virtually without a program line.
Maybe it won't be the best of optimization, surely it could have been done better,
I used ZCD, 2 Timers and 2 CLCs.
            Device = 16F1619

            Xtal = 4

            All_Digital = Off
            Declare Optimiser_Level = 0

            Config1 FOSC_INTOSC, PWRTE_OFF, MCLRE_On, Cp_OFF, BOREN_On, CLKOUTEN_OFF, IESO_On, FCMEN_On
            Config2 WRT_OFF, PPS1WAY_On, ZCD_OFF, PLLEN_OFF, STVREN_On, BORV_LO, LPBOR_OFF, LVP_On
            Config3 WDTCPS_WDTCPS1F, WDTE_OFF, WDTCWS_WDTCWSSW, WDTCCS_SWC

            OSCCON  = 0x68
            OSCTUNE = 0x00
            BORCON  = 0x00

            OPTION_REG.7 = 0            ' All weak pull-ups are disabled (except MCLR, if it is enabled)
'-----------------------------------------------
            ZCD1CON = 0x81
            WPUA.2 = 0
            ANSELA.2 = 0
'------------------------------- ' CLC1 CONFIGURABLE LOGIC CELL
            CLC1CON  = 0x86
            CLC1GLS0 = 0x02
            CLC1GLS1 = 0x00
            CLC1GLS2 = 0x00
            CLC1GLS3 = 0x00
            CLC1POL  = 0x0A
            CLC1SEL0 = 0x15
            CLC1SEL1 = 0x1A
            CLC1SEL2 = 0x10
            CLC1SEL3 = 0x10
'------------------------------- ' CLC2 CONFIGURABLE LOGIC CELL
            CLC2CON  = 0x80
            CLC2GLS0 = 0x02
            CLC2GLS1 = 0x00
            CLC2GLS2 = 0x00
            CLC2GLS3 = 0x00
            CLC2POL  = 0x02
            CLC2SEL0 = 0x1A
            CLC2SEL1 = 0x15
            CLC2SEL2 = 0x15
            CLC2SEL3 = 0x15
'------------------------------- ' TIMER 2
            t2clkcon = 0x00
            t2con    = 0xA0
            t2hlt    = 0x33
            t2pr     = 0xC7
            t2rst    = 0x09
            t2tmr    = 0x00
'------------------------------- ' TIMER 4
            t4clkcon = 0x00
            t4con    = 0xF0
            t4hlt    = 0x12
            t4pr     = 0x97
            t4rst    = 0x05
            t4tmr    = 0x00
'-------------------------------
            RC0PPS = 0x05
'-------------------------------


            TRISA = 0x04
            TRISB = 0x00
            TRISC = 0x08

            Dim Impulso As byte

init:       While

            for impulso = 1 to 154
            t4pr = impulso
            DelayMS 10
            next

            Wend


            End

Giuseppe

Thanks MPO for sharing your code it could be of help for others.
To date I have never experimented on these Configurable Logic Cells.
In the future I hope to do some tests on them