Yesterday 23:49
Forum: Proton Plus Compiler v3
Starter: xldaedalus
Views: 0
Replies: 11
Go to last post By: tumbleweed
Yesterday 19:54
Forum: Proton Plus Compiler v3
Starter: joesaliba
Views: 0
Replies: 4
Yesterday 18:02
Forum: Proton Studio
Starter: GAMBOA
Views: 0
Replies: 1
Yesterday 14:28
Forum: Timer Modules
Starter: See_Mos
Views: 0
Replies: 1
Yesterday 14:23
Forum: The Lounge
Starter: craig
Views: 0
Replies: 24
+ Reply to Thread
Results 1 to 7 of 7

Thread: PIC16F18877 - no PWM output22 days old

  1. #1
    Junior Member kuhrig's Avatar
    Join Date
    Aug 2005
    Posts
    60
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    2.98 GB

    0 Not allowed!

    Default PIC16F18877 - no PWM output

    I need your help please. There is no PWM output signal on PWM1 - RC2 - pin.
    compiler 3.6.2.3
    I can drive port RC2 high or low, no problem. Just no PWM signal.
    What is missing or wrong?

    code:
    Code:
         Device = 16F18877
    
        Declare Reminders Off
        @ CONFIG_REQ = 0 ; Override Compiler's configuration settings
        Asm-
            __Config _Config1, 0x179F ;FEXTOSC_ECH & RSTOSC_HFINTPLL & CLKOUTEN_OFF & CSWEN_OFF & FCMEN_OFF
            __Config _Config2, 0x3FFE ;MCLRE_OFF & PWRTE_OFF & LPBOREN_OFF & BOREN_ON & BORV_LO & ZCD_OFF & ZCDDIS_OFF & PPS1WAY_ON & STVREN_ON & DEBUG_OFF
            __Config _Config3, 0x07FF ;WDTCPS_WDTCPS_31 & WDTE_ON & WDTCWS_WDTCWS_7 & WDTCCS_LFINTOSC
            __Config _Config4, 0x0FFF ;WRT_OFF & SCANE_not_available & LVP_OFF
            __Config _Config5, 0x3FFF ;CP_OFF & CPD_OFF
        Endasm-
        Declare Reminders On
    
    ;**** End of Fuse Configurator Settings ****
    ;-------------------------------------------------------------------------------
        Declare Xtal = 16
        OSCCON1 = %00010001      '  HFINTOSC WITH 2x PLL /  CLOCK DIVIDER 2
        OSCCON2 = %00010001      '  HFINTOSC WITH 2x PLL /  CLOCK DIVIDER 2
        OSCFRQ = %00000011      ' SET AT 8 MHZ
     
        Declare Float_Rounding = On
        Declare Float_Display_Type = Fast
        Declare Watchdog = On
        Declare Dead_Code_Remove On
        Declare MemWrite_Int_Control = 1
    'Pre start
    'Set port directions -
    'Initialize Ports
        ccdcon = 0          ' DISABLE CURRENT_CONTROLLED DRIVE
    
        trisa   = 0
        ansela  = 0
        wpua    = 0     ' PORT WEAK PULL-UP
        odcona  = 0     ' PORT OPEN DRAIN CONTROL
        slrcona = 0     ' PORT SLEW RATE CONTROL
        inlvla  = 0     ' PORT INPUT LEVEL CONTROL CMOS / TTL
        ccdpa   = 0     ' CURRENT-CONTROLLED DRIVE POSITIVE
        ccdna   = 0     ' CURRENT-CONTROLLED DRIVE NEGATIVE
    
        trisb   = 0
        anselb  = 0
        wpub    = 0     ' PORT WEAK PULL-UP
        odconb  = 0     ' PORT OPEN DRAIN CONTROL
        slrconb = 0     ' PORT SLEW RATE CONTROL
        inlvlb  = 0     ' PORT INPUT LEVEL CONTROL CMOS / TTL
        ccdpb   = 0     ' CURRENT-CONTROLLED DRIVE POSITIVE
        ccdnb   = 0     ' CURRENT-CONTROLLED DRIVE NEGATIVE
    
        trisc   = 0
        anselc  = 0
        wpuc    = 0     ' PORT WEAK PULL-UP
        odconc  = 0     ' PORT OPEN DRAIN CONTROL
        slrconc = 0     ' PORT SLEW RATE CONTROL
        inlvlc  = 0     ' PORT INPUT LEVEL CONTROL CMOS / TTL
        ccdpc   = 0     ' CURRENT-CONTROLLED DRIVE POSITIVE
        ccdnc   = 0     ' CURRENT-CONTROLLED DRIVE NEGATIVE
    
        trisd   = 0
        anseld  = 0
        wpud    = 0     ' PORT WEAK PULL-UP
        odcond  = 0     ' PORT OPEN DRAIN CONTROL
        slrcond = 0     ' PORT SLEW RATE CONTROL
        inlvld  = 0     ' PORT INPUT LEVEL CONTROL CMOS / TTL
        ccdpd   = 0     ' CURRENT-CONTROLLED DRIVE POSITIVE
        ccdnd   = 0     ' CURRENT-CONTROLLED DRIVE NEGATIVE
    
        trise   = 0
        ansele  = 0
        wpue    = 0     ' PORT WEAK PULL-UP
        odcone  = 0     ' PORT OPEN DRAIN CONTROL
        slrcone = 0     ' PORT SLEW RATE CONTROL
        inlvle  = 0     ' PORT INPUT LEVEL CONTROL CMOS / TTL
        ccdpe   = 0     ' CURRENT-CONTROLLED DRIVE POSITIVE
        ccdne   = 0     ' CURRENT-CONTROLLED DRIVE NEGATIVE
    
    '-------------------------------------------------------------------------------------------------
        porta = 0
        portb = 0
        portc = 0
        portd = 0
        porte = 0
        clear
        delayms 500
    ' SET PWMs
        Set TRISC.2     ' MAKE INPUT TO SET CCP/ PWM OUTPUT
    
        T2clkcon = %00000011    ' TIMER 2 CLOCK SELECTION   = HFINTOSC 16MHz
        CCPTMRS0 = %01100101    ' CCP4 = Timer2, CCP3 = Timer4, CCP2 = Timer2, CCP1 = Timer2
        PR2         = 255       ' 10 bit resolution     255 = 10 bit, 127 = 9 bit, 63 = 8 bit, 31 = 7 bit
        CCP1CON     = %10001111 ' CCP1 ENABLE - PWM MODE
        clear pir4.1            ' CLEAR TMR2IF
        T2CON       = %10000000 ' TIMER2 ON with Prescaler 1 and Postscaler 1
    
        ccp1pps = 0x12      ' SET CCP1 TO RC2 (by default anyway)
        Clear TRISC.2     ' MAKE OUTPUT
        ' LOAD VALUE 512
        ccpr1H = %10
        ccpr1l = 0

  2. #2
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,549
    Thumbs Up
    Received: 60
    Given: 89
    Total Downloaded
    895.24 MB

    0 Not allowed!

    Default Re: PIC16F18877 - no PWM output

    Hi,

    Some starters

    1 Make sure you can flash the led eg that the pic runs at the right speed
    2 In your code the reg and port set up seems to extensive and you may have set something wrong. The only thing you generally need to do is get the pic running at the right speed with oscon that links in with point 1. Also the analogue / comparator is right
    3 Just use high or low to set up the port

    When setting up a PWM I just go online to get the reg setting. This is for 16mhz 1000hz pwm at 50%

    PR2 = %11111001 ;
    T2CON = %00000111 ;
    CCPR1L = %01111100 ;
    CCP1CON = %00111100 ;

    How it helps
    Tim

  3. #3
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    1,786
    Thumbs Up
    Received: 158
    Given: 153
    Total Downloaded
    3.04 GB

    0 Not allowed!

    Default Re: PIC16F18877 - no PWM output

    Just from a quick look at your code I see that you have not used the fuse configurator plug in. Unless you're absolutly certain about your fuse setting, I strongly recommend that you install that plugin and use it.

    Is there a reason why you have turned reminders off for the fuse settings, then back on?
    George

  4. #4
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,346
    Thumbs Up
    Received: 83
    Given: 23
    Total Downloaded
    3.86 GB

    0 Not allowed!

    Default Re: PIC16F18877 - no PWM output

    Quote Originally Posted by towlerg View Post
    Is there a reason why you have turned reminders off for the fuse settings, then back on?
    George,

    That is something that Fuse Configurator do.
    Regards

    Joseph

  5. #5
    Junior Member kuhrig's Avatar
    Join Date
    Aug 2005
    Posts
    60
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    2.98 GB

    0 Not allowed!

    Default Re: PIC16F18877 - no PWM output

    Thanks to your replies:
    @Tim: An LED flashes correctly with these settings. I had to set xtal=16 (even the osccon is set to 8) to get the right flash frequence. I also tried to remove the extensive port settings with no difference in result.
    @Towlerg: Yes, I have used the fuse configurator plug-in

  6. #6
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    1,786
    Thumbs Up
    Received: 158
    Given: 153
    Total Downloaded
    3.04 GB

    0 Not allowed!

    Default Re: PIC16F18877 - no PWM output

    My bad, I didn't relaize FC could use old school mode. Sorry for muddying water.
    George

  7. #7
    Junior Member kuhrig's Avatar
    Join Date
    Aug 2005
    Posts
    60
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    2.98 GB

    2 Not allowed!

    Default Re: PIC16F18877 - no PWM output

    Solved!
    1. You have to set register RxyPPS. Seems like there is no default routing to the default port even it says default location at POR for CCP1 = RC2.
    2. There is a mistake in the datasheet. Page 241, Register RxyPPS, bit 5-0. It says "see Table 13-2". That seems to be wrong. You must use Table 13-3. (document DS40001825D)
    If I use the values of Table 13-3 it works and CCP1 will be routed to RC2.
    Hope that helps if somebody wants to use PWM with an 16F18877.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Pic16f18877
    By teo in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 4th December 2016, 15:47
  2. PIC16F1575 - PWM Output with Variabe Duty Cycle
    By gdesantis in forum Capture Compare / PWM Modules and Enhanced versions
    Replies: 0
    Last Post: 25th April 2016, 02:08
  3. Replies: 5
    Last Post: 30th March 2011, 07:06
  4. [SOLVED !] PWM frequency output and options
    By Brent Warp in forum Proton Plus Compiler v3
    Replies: 4
    Last Post: 14th August 2006, 20:20
  5. 16F88 glitch in hardware PWM output
    By rcurl in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 29th March 2006, 21:56

Members who have read this thread : 33

Actions :  (Set Date)

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts