16f876a Pwm


Closed Thread
Results 1 to 6 of 6

Thread: 16f876a Pwm

Hybrid View

  1. #1
    Join Date
    Dec 2006
    Posts
    6

    Question 16f876a Pwm

    Ok, I've done PWM a bunch of times on other PICs, but for some reason I can't get the 16F876A do what I want...

    I want to use software PWM, basically doing an RGBW LED Fade (4 channels)

    Right now, using either PORTA or PORTB, I fade up an LED, then set it HIGH. I go to fade up the 2nd channel and the first channel (set high, not using PWM anymore) goes dead.

    I have my pins set to outputs, a/d is off, etc.

    Any ideas?

    Thanks!
    Hainkm

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    >> any ideas?

    R-M-W problem? ... post your code and you will get more help
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default

    Paul is right. If you are modifying the outputs like this

    PORTB = PORTB + $2

    You can be sure that bit corresponding to $2 will come on, but the bits which are supposed to stay where they are may not. This is the Read-Modify-Write issue Paul is talking about. Read more about it in the datasheets

    JF

  4. #4
    Join Date
    Dec 2006
    Posts
    6


    Did you find this post helpful? Yes | No

    Thumbs up The Code...

    Here's some code. Thanks for the help!!

    @ device PIC16F876A, hs_osc, wdt_off, pwrt_off, bod_off, lvp_on, cpd_off

    TRISA=%00000000
    TRISB=%00000000
    ADCON0=7
    ADCON1=7

    W VAR BYTE

    TheLoop:

    FOR W=1 TO 255
    PWM PORTB.0,W,1
    NEXT W

    HIGH PORTB.0

    PAUSE 1000

    ' As soon as I start this PWM on PORTB.1, PORTB.0 goes LOW...this is what I need to fix.

    FOR W=1 TO 255
    PWM PORTB.1,W,1
    NEXT W

    HIGH PORTB.1

    PAUSE 1000

    GOTO TheLoop

  5. #5
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default

    You don't seem to have the RBPU enabled in your code (OPTION_REG) and also you may not be having external pull ups on the PWM output pins. So, when the PWM code executes, it does the RMW routine and PortB.0 goes low. You could check on this.

    JF

  6. #6
    Join Date
    Dec 2006
    Posts
    6


    Did you find this post helpful? Yes | No

    Smile Fixed!

    That did the trick! Thank you so much!

    Hainkm

Similar Threads

  1. Half-bridge PWM with a 16F684 ?
    By Byte_Butcher in forum General
    Replies: 7
    Last Post: - 17th January 2010, 22:18
  2. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  3. PWM setting PIC16F887
    By Gevo in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th June 2008, 07:24
  4. Pwm 16f876a
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 19th September 2006, 06:35
  5. Tidying Up PWM Routine
    By Tissy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st February 2005, 00:26

Members who have read this thread : 0

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