-
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
-
>> any ideas?
R-M-W problem? ... post your code and you will get more help
-
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
-
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
-
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
-
Fixed!
That did the trick! Thank you so much!
Hainkm