nickelflippr
Member
I've been fooling around with the 18f26k22 chip for short while, and have run into a mental block. In the example code posted below I try to set three standard PWM's using three different clocks and period register settings.
The CCP1 PWM works fine and responds to PR2 values and set/clr of the TMR2ON bit. The CCP2 PWM works, but is just a mirror of CCP1, and only responds to PR2 and TMR2. Getting zilch from CCP3. Have tried setting the CCPTMRS0 register bits (CCP2) and the CCPTMRS0 register (CCP3) to use TMR4 and TMR6 respectively. Also have different pre/post scale settings, to no effect.
Since this is a new chip for me, I learned about needing to set the PBADEN=OFF in config. Also have played with the CCP2MX and CCP3MX in config too. Hopefully will learn some other gotchas with this chip through someones experience or suggestions.
Here's the assembler file from GCBasic.
The CCP1 PWM works fine and responds to PR2 values and set/clr of the TMR2ON bit. The CCP2 PWM works, but is just a mirror of CCP1, and only responds to PR2 and TMR2. Getting zilch from CCP3. Have tried setting the CCPTMRS0 register bits (CCP2) and the CCPTMRS0 register (CCP3) to use TMR4 and TMR6 respectively. Also have different pre/post scale settings, to no effect.
Since this is a new chip for me, I learned about needing to set the PBADEN=OFF in config. Also have played with the CCP2MX and CCP3MX in config too. Hopefully will learn some other gotchas with this chip through someones experience or suggestions.
Here's the assembler file from GCBasic.
Code:
;Set up the assembler options (Chip type, clock source, other bits and pieces)
LIST p=18F26K22, r=DEC
#include <P18F26K22.inc>
CONFIG LVP = OFF, MCLRE = INTMCLR, PBADEN = OFF, CCP2MX = PORTB3, WDTEN = OFF, BOREN = OFF, FOSC = INTIO67
;********************************************************************************
;Vectors
ORG 0
goto BASPROGRAMSTART
ORG 8
retfie
;********************************************************************************
;Start of program memory page 0
ORG 12
BASPROGRAMSTART
;Call initialisation routines
rcall INITSYS
;Start of the main program
bsf TRISC,0,ACCESS
bcf TRISC,7,ACCESS
bcf TRISA,5,ACCESS
bcf TRISC,2,ACCESS
bcf TRISB,3,ACCESS
bcf TRISC,1,ACCESS
bcf TRISB,5,ACCESS
bcf TRISC,6,ACCESS
movlw 112
movwf OSCCON,ACCESS
bsf OSCTUNE,PLLEN,ACCESS
movlw 12
movwf CCP1CON,ACCESS
movlw 10
movwf PR2,ACCESS
movlw 1
movwf CCPR1L,ACCESS
bsf CCP1CON,DC1B1,ACCESS
bcf CCP1CON,DC1B0,ACCESS
movlw 240
movwf T4CON,ACCESS
movlw 12
movwf CCP2CON,ACCESS
bcf CCPTMRS0,C2TSEL1,ACCESS
bsf CCPTMRS0,C2TSEL0,ACCESS
movlw 20
movwf PR4,ACCESS
movlw 1
movwf CCPR2L,ACCESS
bsf CCP2CON,DC2B1,ACCESS
bcf CCP2CON,DC2B0,ACCESS
movlw 3
movwf T6CON,ACCESS
movlw 12
movwf CCP3CON,ACCESS
movlw 128
movwf CCPTMRS0,ACCESS
movlw 30
movwf PR6,ACCESS
movlw 1
movwf CCPR3L,ACCESS
bsf CCP3CON,DC3B1,ACCESS
bcf CCP3CON,DC3B0,ACCESS
bsf T2CON,TMR2ON,ACCESS
clrf TRISA,ACCESS
movlw 223
movwf LATA,ACCESS
START
bra START
BASPROGRAMEND
sleep
bra BASPROGRAMEND
;********************************************************************************
INITSYS
clrf BSR,ACCESS
clrf TBLPTRU,ACCESS
bcf ADCON0,ADON,ACCESS
bcf ADCON2,ADFM,ACCESS
clrf ANSELA,ACCESS
clrf ANSELB,ACCESS
bcf CM2CON0,C2ON,ACCESS
bcf CM1CON0,C1ON,ACCESS
clrf PORTA,ACCESS
clrf PORTB,ACCESS
clrf PORTC,ACCESS
clrf PORTE,ACCESS
return
;********************************************************************************
END