PWM problem with PIC16F777


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Mar 2011
    Location
    cape town, south africa
    Posts
    19

    Default PWM problem with PIC16F777

    Would really appreciate some help on getting the 3rd PWM to work on my PIC16F777.

    I'm using the three PWM's to control R G B led strips. My PortB.5 will not light!

    The code I'm using - primarily from this forum is below. I know that the circuit is fine, as all three colours work when I manually switch the pins high and low.

    I've stripped the code down - for simplicity - to just flash through the three colours... but alas only ever get two!

    Code:
    '-- Setup ---------------------------------------------------------------------
    @ DEVICE PIC16F777, INTRC_OSC_NOCLKOUT
    
    DEFINE  OSC 8
    
    OSCCON = %01110010 'see data sheet for INTRC speed setting
    
    ' Word vars for 10-bit value of each PWM duty cycle
    DutyR VAR WORD ' Channel #1
    DutyG VAR WORD ' #2
    DutyB VAR WORD ' #3
    
    ' Set CCPx pins to outputs
    TRISC.2=0 ' CCP1 output
    TRISC.1=0 ' CCP2 output (could also be assigned to RB3)
    TRISB.5=0 ' CCP3 output
    
    ' Set CCP modules to PWM mode
    CCP1CON = %00001100 ' Mode select = PWM
    CCP2CON = %00001100 ' Mode select = PWM
    CCP3CON = %00001100 ' Mode select = PWM
    
    ' Set period up for 1.22kHz PWM freq
    PR2 = $FF
    
    ' Set TMR2 up for 1:16 prescale & turn it on
    T2CON = %00000110 ' TMR2 ON 1:16 prescale
    
    
    '-- Program ---------------------------------------------------------------------
    MainRoutine:
    
    dutyR = 719
    dutyg = 0
    dutyb = 0
    gosub colourset
    PAUSE 1000
    
    dutyR = 0
    dutyg = 719
    dutyb = 0
    gosub colourset
    PAUSE 1000
     
    dutyR = 0
    dutyg = 0
    dutyb = 719
    gosub colourset
    PAUSE 1000
    
    goto MainRoutine
    
    '-------------------------------------------------------------------------------
    
    colourset:
    CCP1CON.4 = Dutyr.0 ' Setup 10-bit duty cycle as
    CCP1CON.5 = Dutyr.1 ' a 10-bit word
    CCPR1L = Dutyr >> 2
                  
    CCP2CON.4 = Dutyg.0 
    CCP2CON.5 = Dutyg.1 
    CCPR2L = Dutyg >> 2
            
    CCP3CON.4 = Dutyb.0 
    CCP3CON.5 = Dutyb.1 
    CCPR3L = Dutyb >> 2
    return
    Many thanks in advance,
    orjon.

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


    Did you find this post helpful? Yes | No

    Default Re: PWM problem with PIC16F777

    Rule #1: Always check the pinout.

    What's on PORTB.5?
    Yeah right AN13... Now check the datasheet page 155 (ADCON1 register) to see how to disable the ADC on this pin.
    Steve

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

  3. #3
    Join Date
    Mar 2011
    Location
    cape town, south africa
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: PWM problem with PIC16F777

    Hi Steve,

    Thank you for the prompt reply.

    I've been looking through the datasheet in the A/D section, but it's quite over my head! I have done some searches and see that setting the ADCON1 to %00000001 for instance would set AN0 to A/D. But see not reference to AN13 (portb.5) in the table...

    Another clue ... please?!

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: PWM problem with PIC16F777

    ADCON1 = 15 ' All I/O pins digital
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Mar 2011
    Location
    cape town, south africa
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: PWM problem with PIC16F777

    Thanks!

    Phew - that wasn't fun...

    It is possible to set them individually?

    Thank you both very much - you have just completed the spectrum for me!

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: PWM problem with PIC16F777

    Yes, goto the table Steve mentioned and take a look.
    1111 = 15
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Dec 2012
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: PWM problem with PIC16F777

    hey.... i am working on application note AN889...... open loop v/f control of pic16f777....... getting error as follows.......... ' Error - section '.udata_shr' can not fit the section. Section '.udata_shr' length=0x00000010' plz some one help with this error....Thanks

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default Re: PWM problem with PIC16F777

    Quote Originally Posted by oswalam View Post
    hey.... i am working on application note AN889...... open loop v/f control of pic16f777....... getting error as follows.......... ' Error - section '.udata_shr' can not fit the section. Section '.udata_shr' length=0x00000010' plz some one help with this error....Thanks
    looks you are asking questions about Microchip assembler aboard a Picbasic pro forum ...
    sorry but you've hit the wrong door ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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