Author Topic: Multiplexing the CCP output  (Read 1637 times)

Offline kronosslayer

  • ½ Pint
  • *
  • Posts: 36
  • Post quality +6/-0
  • Gender: Male
  • Acidmods User
Multiplexing the CCP output
« on: December 11, 2011, 07:11:41 PM »
After many weeks, i was able to make a simple PWM signal on GP2 which fades in and out. I want to change the pin it outputs on but i'm a little lost.

The datasheet says that the CCP1 output is multiplexed with the PORT data latch? I've tried changing TRISIO to a different pin in different places but got no result from it. Plus the order the datasheet says to setup the PWM, i didn't really follow and was still able to get output on GP2 only.

If someone could explain how i could modify my code to make CCP1 to output on other pins such as GP1,GP0, or GP5, please let me know.

Here's my code:

Code: [Select]
list p=12f683
include <p12f683.inc>

__config _INTOSCIO & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _CP_ON & _CPD_OFF & _BOD_NSLEEP & _IESO_OFF & _FCMEN_OFF

errorlevel -302

Inner EQU 0x70
Outer EQU 0x71
Final EQU 0x72

ORG 0x0000
GOTO Declarations

Declarations
BANKSEL GPIO
CLRF GPIO
MOVLW 0x07
MOVWF CMCON0

BANKSEL ANSEL
CLRF ANSEL
MOVLW   b'111000'     ; Define inputs & outputs.
    MOVWF   TRISIO
    MOVLW   b'11000011'     ; Disable pull-ups, Prescaler -> TMR0
    MOVWF   OPTION_REG      ;  (TMR0 prescaler = 16)

BANKSEL GPIO
Pwm_start
CLRF GPIO

;Setup GPIO
;MOVLW 0xFF
;MOVWF GPIO
;Set up CCP1 Module
MOVLW b'00001101' ;Active High
MOVWF CCP1CON ;Lsb aren't used
;Setup resolution
BANKSEL PR2
MOVLW 0xFF
MOVWF PR2 ;10 bit resolution, but only 256 cycles used
;Timer 2 setup
BANKSEL T2CON
MOVLW b'00000010'
MOVWF T2CON ;T2 off, prescale 16
;Setup up duty cycle
CLRF CCPR1L
;Start Timer
BSF T2CON, TMR2ON
;Begin visuals
Fadein
CALL Delay_5
INCF CCPR1L,f
MOVLW b'11111111'
XORWF CCPR1L,w
SKPZ
GOTO Fadein

CALL Delay_1s
 
 Fadeout
CALL Delay_5
DECFSZ CCPR1L,f
GOTO Fadeout

;Turn things Off
CLRF GPIO
BCF T2CON, TMR2ON
CLRF CCPR1L
CALL Delay_1s

CLRF TRISIO
GOTO Pwm_start

Delay_5
CLRF Inner
MOVLW 0x05
MOVWF Outer
subloop
NOP
DECFSZ Inner,f
GOTO subloop
DECFSZ Outer,f
GOTO subloop
RETURN

Delay_1s
CLRF Inner
CLRF Outer
MOVLW 0x04
MOVWF Final
subloop1
NOP
DECFSZ Inner,f
GOTO subloop1
DECFSZ Outer,f
GOTO subloop1
DECFSZ Final,f
GOTO subloop1
RETURN


END
I'm a java developer, Graphic Designer, and an a**hole.

 

SMF spam blocked by CleanTalk
SimplePortal 2.3.5 © 2008-2012, SimplePortal