16 bit PWM using CCP1


Closed Thread
Results 1 to 40 of 61

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    .... Pulses will be continuous at ~40hz ....
    How do you get ~40-Hz?

    <added>

    Oops! Sorry! I see it. Timer 1 rollover every 26.2144 msecs (38.14697265625 Hz)... I need another cup o' coffee (grin)...
    Last edited by Mike, K8LH; - 28th October 2010 at 16:13.

  2. #2
    Join Date
    Nov 2009
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    Hi Everyone,
    Talat from Istanbul here. Please help wıth my PWM problem.
    My code is runnıng BUT I get only 1 or 2 output pulses from port B3 on startup then no output after that.
    What am ı doıng wrong?
    Thanks ın advance fo you help.
    Talat

    '************************************************* ***************
    '* Name : *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 09.08.2014 *
    '* Version : 1.0 *
    '* Notes : 16F1827 *
    '* : *
    '************************************************* ***************
    ' DEVİCE 16F1827

    ASM
    __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
    __config _CONFIG2, _PLLEN_ON & _LVP_OFF & _LVP_OFF & _STVREN_OFF; & _VCAPEN_OFF
    ENDASM
    CLEAR
    DEFINE OSC 32
    OSCCON=%01110000 '32

    DEFINE INTHAND PWM_INT

    PWM_VAL VAR WORD BANK0 SYSTEM
    VALUE VAR WORD

    INIT:
    APFCON0 = 0 'SET PORTB.3 TO CCP1
    T1CON = %00100000 'Prescaler 1:4

    PIE1.0 = 1 'TMR1IE TMR1 Interrupt Enable
    PIR1.0 = 0 'TMR1IF TMR1 Interrupt Flag
    INTCON.7 = 1 'GIE Global Interrupt Enable
    INTCON.6 = 1 'PEIE Peripheral Interrupt Enable
    CCP1CON = 9 'compare mode
    OUTPUT PORTB.3 'CCP PIN


    T1CON.0 = 1 'TMR1ON SET TMR1
    PAUSE 1000
    VALUE=1000

    MLOOP:
    VALUE=VALUE+1
    PWM_VAL = VALUE
    Goto MLOOP


    Asm
    PWM_INT
    movlw 9 ; compare mode
    clrf CCP1CON ; clear reg
    movwf CCP1CON ; Set reg
    movf PWM_VAL+1,W ; hb
    movwf CCPR1H ; put
    movf PWM_VAL,W ; lb
    movwf CCPR1L ; put
    bsf INTCON,7 ;GIE = 1
    bsf INTCON,6 ;PEIE = 1 Enable peripheral interrupts
    bsf PIE1,0 ; TMR1IE= 1 Enable TMR1
    bcf PIR1,0 ; TMR1IF = 0 Clear Timer1 Int Flag

    RETFIE ; Return from Interrupt
    EndAsm

    END

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