• PicŪ Basic


  • NCO and CLC on 16F1509 to implement a XOR between external signal and a reference (NCO)

    This article was originally published in forum thread: NCO to forum started by Oldhack View original post

    An example can be made from code that was used in connection with the thread in http://www.protonbasic.co.uk/showthr...l=1#post503884
    It uses NCO and CLC on 16F1509 to implement a XOR between external signal and a reference (NCO).

    Code:
    Device = 16F1509
    Config1 FOSC_HS, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, BOREN_OFF, CLKOUTEN_OFF, IESO_ON, FCMEN_ON           
    Config2 WRT_OFF, STVREN_ON, BORV_LO, LPBOR_OFF, LVP_OFF
    '
    Xtal = 12                    
    '
    OSCCON = 111000          
    APFCON = 000000           
    '
    ANSELA = 0
    ANSELB = 0
    ANSELC = 0
    '
    TRISA = 000000                               
    TRISB = 000000
    TRISC = 000000           ' RC7 is CLC1IN1 for external signal XOR with NCO
    '
    CLC1_config:                ' configured as XOR with the NCO
    Symbol LC1EN = CLC1CON.7
    Symbol LC1OE = CLC1CON.6
    Symbol LC1OUT = CLC1CON.5
    
    
    CLC1CON  = 0x01             ' OR-XOR
    CLC1POL  = 0x00
    '
    CLC1SEL0 = 0x01             ' LC1_IN[1] is lc1d1    - Signal on pin RC7
    CLC1SEL1 = 0x00             ' LC1_IN[12] is lc1d4   - NCO out
    '
    CLC1GLS0 = 0x02             ' lc1d1T is gated into lc1g1
    CLC1GLS1 = 0x00             ' not gated
    CLC1GLS2 = 0x00             ' not gated
    CLC1GLS3 = 0x80             ' lc1d4T is gated into lc1g4
    '
    NCO_config:
    NCO1CON = 000000
    Symbol N1EN   = NCO1CON.7
    Symbol N1OE   = NCO1CON.6
    Symbol N1OUT  = NCO1CON.5
    Symbol N1POL  = NCO1CON.4
    Symbol N1PFM  = NCO1CON.0
    '
    NCO1CLK = 000001         ' FIXED DUTY CYCLE, clock source FOSC
    '
    Dim tempword As Word     
    '
    main:    
        DelayMS 250             
        '
        LC1OE = 1               
        LC1EN = 1
        '
        tempword = 34602        ' Increment for close to 180KHz -> ((12000000 * 34602)/2^20)/2 = 197,994.23 Hz
        NCO1INCH = tempword.HighByte
        NCO1INCL = tempword.LowByte
        '
        N1OE   = 1
        N1OUT  = 1
        N1POL  = 0
        N1PFM  = 0
        N1EN   = 1
        '
        '---------------
        While 1 = 1             ' NCO output on RC1, output of NCO XOR with CLC1IN (RC7) is on RA2    
            DelayMS 100
            PORTC.3 = ~PORTC.3  ' do something in a loop the NCO and CLC are running in hardware
        Wend
        '---------------
    This article was originally published in forum thread: NCO to forum started by Oldhack View original post