I tried the suggested PWM built in PBP and it works pretty good.
Here is the code I used to get a nice ramp up and down even with
high brightness LEDs which are harder to control linearly.
led VAR PORTB.5
steps VAR WORD
cycles CON 2
' Change limits for steps to play around 0 or 100% brightness
' Change steps for different duration of ramps
' Works good even with high brightness LEDs, harder to control linearly
fade:
up:
For steps=0 TO 255
PWM led,steps,cycles
Next
High led
Pause 2500
down:
For steps=255 TO 1 STEP -1
PWM led,steps,cycles
Next
Low led
Pause 2500
GoTo fade
End
Bookmarks