Can someone show me how to set ccp3 to RC6 on pic 18f24k22


Results 1 to 7 of 7

Threaded View

  1. #2
    Join Date
    Nov 2008
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Re: Can someone show me how to set ccp3 to RC6 on pic 18f24k22

    Hi,

    Sorry I've been meaning to post the code I had for this, but have problems with the computer that has the file on.

    The CCP3 output is set in the configuration bits, I'll have a look at the datasheet in a bit and give a better pointer.

    EDIT: the joy of USB disks, found it!

    Code:
    '************************************************************************************
    '*   HPWM Demo Code for PIC18F24K22                                            *
    '*                                                                                  *
    '*                                                                                  *
    '*                                                                                  *
    '************************************************************************************
    
    
    
    asm
            __CONFIG    _CONFIG1H, _FOSC_INTIO67_1H & _PLLCFG_OFF_1H & _PRICLKEN_ON_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
            __CONFIG    _CONFIG2L, _PWRTEN_ON_2L & _BOREN_OFF_2L & _BORV_285_2L
            __CONFIG    _CONFIG2H, _WDTEN_NOSLP_2H & _WDTPS_512_2H
            __CONFIG    _CONFIG3H, _CCP2MX_PORTB3_3H & _PBADEN_OFF_3H & _CCP3MX_PORTB5_3H & _HFOFST_OFF_3H & _T3CMX_PORTB5_3H & _P2BMX_PORTB5_3H & _MCLRE_EXTMCLR_3H
            __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
            __CONFIG    _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L 
            __CONFIG    _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
            __CONFIG    _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L 
            __CONFIG    _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H  
            __CONFIG    _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L 
            __CONFIG    _CONFIG7H, _EBTRB_OFF_7H       
    
    ENDASM
    
    Define OSC 8
    
    
    
    LED2    var PORTA.0     ' Status LED
    LED1    var PORTA.1     ' Status LED 
    RA2     var PORTA.2     '     
    RA3     var PORTA.3     '   
    RA4     var PORTA.4     '    
    RA5     var PORTA.5     ' 
    RA6     VAR PORTA.6     ' Xtal
    RA7     var PORTA.7     ' Xtal
    
    PWM1    VAR PORTB.0     ' CH1 PWM Output
    RB1     VAR PORTB.1     ' 
    RB2     VAR PORTB.2     ' 
    PWM2    VAR PORTB.3     ' CH2 PWM Output
    RB4     VAR PORTB.4     ' Spare
    PWM3    VAR PORTB.5     ' CH3 PWm Output
    RB6     VAR PORTB.6     ' PGC / TX2
    RB7     VAR PORTB.7     ' PGD / RX2
    
    RC0     var PORTC.0     '  
    RC1     var PORTC.1     '    
    RC2     var PORTC.2     '      
    RC3     var PORTC.3     '    
    RC4     var PORTC.4     '    
    RC5     var PORTC.5     ' 
    TXD1    var PORTC.6     ' TX1
    RXD1    var PORTC.7     ' RX1
    
    RE0     VAR PORTE.0     ' VPP/nMCLR
                         
    ch1     var byte
    ch2     var byte
    ch3     var byte
    
    update  var bit
    
    
    OSCCON = 100010          ' Set internal 8Mhz OSC
    OSCCON2 = 001100
    while OSCCON.2 = 0 : WEND   ' Wait for stable flag
    
    clear
    
    
    PORTA = 100000       ' Setup ports
    PORTB = 000000
    PORTC = 000000
    
    ANSELA = 000000
    ANSELB = 000000
    ANSELC = 000000      ' Config A2d
    
    ADCON2 = 101101
    ADCON1 = 001000
    ADCON0 = 011000
    
    VREFCON0 = 100000    ' Enable voltage referance 2.048V
    
    TRISA = 000000       ' Setup TRIS
    TRISB = 000110
    TRISC = 011000
    
        GOTO start
        
    '-------------------------------------------------------------------------------
    ' Main program starts here
    '-------------------------------------------------------------------------------
    
    
    start:
    
        ch1 = 64            ' load some levels for the outputs
        ch2 = 128
        ch3 = 192            
        update = 1            ' set flag to update PWM outputs
        
    
    '-------------------------------------------------------------------------------
    ' Main Loop 
    '-------------------------------------------------------------------------------
        
        
    main:   
    
        if update then        ' If the flag is set to update then
            hpwm 4,ch1,500        ' load the PWM outputs with new values
            hpwm 3,ch2,500
            hpwm 2,ch3,500    
            update = 0        ' clear update flag
        endif
        
        
        goto main
         
             
     
        end
    Last edited by BH_epuk; - 22nd March 2012 at 20:28. Reason: Found the code

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts