16 bit PWM using CCP1


Results 1 to 40 of 61

Threaded View

  1. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,

    Pretty cool stuff. Have you tested this on other 18F parts? I don't have a 4520 to test
    with, but I couldn't get this to work without clearing CCP1CON before moving 9 to it on
    a 452 or 4431.

    Had to do this;
    Code:
    ASM
    MyInt                    
        clrf CCP1CON         ; 18F452 & 18F4431 require this before it changes CCP1 output
        movlw 9
        movwf CCP1CON
        bcf PIR1,TMR1IF      ; clear TMR1 int flag
        retfie FAST          ; use RETFIE FAST to restore WREG, STATUS & BSR
    ENDASM
    On an 18F452 or 18F4431, the above works fine, but only if I clear CCP1CON first.

    This works on a 452 & 4431 with CCP1 & TMR1 ints enabled on any output pin;
    Code:
    ASM
    MyInt                    
        btfss PIR1,TMR1IF    ; TMR1 interrupt?
        bra CCP              ; no - service CCP interrupt
        bcf PIR1,TMR1IF      ; yes - clear TMR1 int flag
        bsf LATB,0           ; set RB0 on TMR1 interrupt
        retfie FAST          ; return
    CCP
        bcf PIR1,CCP1IF      ; clear CCP1 int flag
        bcf LATB,0           ; clear RB0 on compare interrupt
        retfie FAST          ; use RETFIE FAST to restore WREG, STATUS & BSR
    ENDASM
    I was just wondering if this might be a fluke with the 4520 part - since none of the other
    18F parts I've tested will toggle CCP1 with just the movlw 9, movwf CCP1CON?
    Last edited by Bruce; - 14th December 2009 at 02:34. Reason: 2nd version uses CCP1CON = %00001010
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Half-bridge PWM with a 16F684 ?
    By Byte_Butcher in forum General
    Replies: 7
    Last Post: - 17th January 2010, 22:18
  3. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  4. How to tell which PICs can handle 16 bit variables?
    By MikeTamu in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st August 2005, 08:44
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 2

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