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


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2009
    Posts
    33

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

    Hello.
    Yes I have been reading the data sheet and trying to understand how to do this but I don't really understand datasheets. Maybe if I can get this right I will help me understand them better.
    Anyway. For now my hpwm 3,127,1000 command is appearing on port rb5. According to the data sheet it should default to RC6 but it isn't. I don't know why and I can't figure out how to change it.

    Thanks

  2. #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

  3. #3
    Join Date
    Jul 2009
    Posts
    33


    Did you find this post helpful? Yes | No

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

    Thanks for that. Actually I couldn't get your version to work but this does:
    asm
    config FOSC = INTIO67 , CCP2MX = PORTC1, CCP3MX = PORTC6
    endasm

    I think I have learned something and I am almost in danger of being able to understand data sheets. It's all in the mpasm pic inc file isn't it?

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

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

    Yup!

    PICs, CONFIGS and Oscillator Settings for Beginners:
    http://www.picbasic.co.uk/forum/showthread.php?t=15982

    Robert

  5. #5
    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

    Don't know what happend to the code i posted earlier in the thread, it seems to have been reformatted missing bits so would never work.

    Here it is as an attachment

    HPWM.txt

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

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

    Quote Originally Posted by BH_epuk View Post
    Don't know what happend to the code i posted earlier in the thread, it seems to have been reformatted missing bits so would never work...

    The top left icon above the post box has two As; click on it to get SOURCE mode. That will leave your code intact.

    To have your post box in SOURCE mode by default:
    - click on SETTINGS at top right.
    - click on General Settings on left side.
    - scroll down to Miscellaneous Options.
    - click on Standard Editor - Extra formatting controls

    Robert

    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 = %01100010          ' Set internal 8Mhz OSC
    OSCCON2 = %00001100
    while OSCCON.2 = 0 : WEND   ' Wait for stable flag
    
    clear
    
    
    PORTA = %00100000       ' Setup ports
    PORTB = %00000000
    PORTC = %00000000
    
    ANSELA = %00000000
    ANSELB = %00000000
    ANSELC = %00000000      ' Config A2d
    
    ADCON2 = %10101101
    ADCON1 = %00001000
    ADCON0 = %00011000
    
    VREFCON0 = %10100000    ' Enable voltage referance 2.048V
    
    TRISA = %00000000       ' Setup TRIS
    TRISB = %10000110
    TRISC = %10011000
    
        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

  7. #7
    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

    Cheers Robert, It was going to be something simple.

Members who have read this thread : 1

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