Trouble with P.W.M


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2008
    Posts
    12

    Unhappy Trouble with P.W.M

    I had my code working on a pic16F, then I tried to merge to a more powerful 18f. The problem is that my P.W.M part isn't working now. My code is running because I added some lines to flash an LED and it did work, but once it comes to the P.W.M it does nothing. I've read the datasheet over and over, but I can't spot the mistake. Perhaps someone here can help me.

    I'm using the following:
    Pic18f2520
    10 Mhz Crystal

    My code is:

    asm
    __CONFIG _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    __CONFIG _CONFIG2L, _BOREN_OFF_2L & _PWRT_ON_2L
    __CONFIG _CONFIG2H, _WDT_ON_2H
    __CONFIG _CONFIG3H, _MCLRE_OFF_3H & _CCP2MX_PORTBE_3H
    __CONFIG _CONFIG4L, _LVP_OFF_4L & _DEBUG_OFF_4L
    __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
    __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
    __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
    __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
    __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
    __CONFIG _CONFIG7H, _EBTRB_OFF_7H
    endasm
    '************************************************* **********************




    Define OSC 10
    cmcon = 7


    '
    'P.W.M
    '
    ccp1con = %1100
    pr2 = 155 '1Khz
    t2con = %110 ' T2 On Prescaler 1:16
    '************************************************* **********************

    '
    'I/O
    '
    Trisb = 0
    Trisa = %11
    portb = 0
    button var porta.1
    '-----------------------------------------------------------------------------------

    '
    'Vars
    '
    duty var word
    duty = 0

    '-----------------------------------------------------------------------------------





    Main:



    if button = 0 then
    pause 33

    if duty = 625 then duty = 0

    duty = duty + 5
    CCPR1L=DUTY>>2
    CCP1CON.5=DUTY.1
    CCP1CON.4=DUTY.0
    CCP1CON = %1100
    endif
    pause 1
    goto main

  2. #2
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    only thing missing that I can see is:

    TRISC.2=0
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    CCPR1L=DUTY>>2
    CCP1CON.5=DUTY.1
    CCP1CON.4=DUTY.0
    CCP1CON = %1100 <---- this one will overwrite previous CCP1CON<5:4>

    Also you haven't disable the multiplexed ADCs (refer to ADCON1).

    Maybe you wanted a PWM signal on PORTB? must change to CCP2CON & CCPR2L

    Not a bad idea to make sure the extended instruction set bit is disable...
    Code:
    __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    Last edited by mister_e; - 8th April 2008 at 21:03.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Apr 2008
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    That should be it.. Sorry..

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    HEY! No need to be sorry Don't worry!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. trouble with microcode loader
    By meho in forum mel PIC BASIC
    Replies: 4
    Last Post: - 9th August 2012, 14:39
  2. Replies: 10
    Last Post: - 2nd May 2009, 07:42
  3. Trouble with PIC12F683 - GP0 GP1 as inputs
    By erice1984 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 30th March 2009, 04:32
  4. Trouble using int. osc. On 18f2455
    By KPDes in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th June 2007, 10:35
  5. 12F629 Trouble
    By shahidali55 in forum General
    Replies: 26
    Last Post: - 18th May 2007, 09:22

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