
Originally Posted by
wdmagic
you can do that easily if you want them all to dim at the same rate using the PICs PWM going into the gate of a seperate FET with its drain tied to all the fets, sources. and its source to ground, this adds a ~.5v voltage drop but you can compensate by adjusting your pots.
I did this on a guys truck, he wanted 2 sets of floorboard lights, operated from a single pushbutton, but he also wanted to control their brightness, it was easy enought to set a 2 bit binary output to 2 FETS, and have them tied to a 3rd FET that was drivin by the PWM pin. and I just used a POT to set the PWM, and a button to select the lights (left, right, both, off).
But did the LEDs blink? It sounds like your LEDs were steady-on with brightness control. For my application, I need to control the brightness of blinking LEDs. You can see the full code file above (created by Darrel) but I think the relevant portion is:
Code:
CCPR1val CON EXT : @CCPR1val = (OSC*1000000/4)/ BLINKYFREQ
;CCPR1 VAR WORD EXT : @CCPR1 = CCPR1L
Timer1 VAR WORD EXT : @Timer1 = TMR1L
CCPIF VAR PIR1.2
;----[Initialize on/off periods & random sequencing (if enabled)]---------------
; (only randomize first 5 blinkies; 6th is strobe which must remaing constant)
; (running lights (7th) are set up separately)
FOR x = 0 to (LEDcount - 2) ; Load the periods from EEPROM
READ OnTimes+x, OnTime(x)
READ OffTimes+x, OffTime(x)
#IFDEF USE_RANDOM_SEQUENCE
IF x < 5 THEN
READ RandPeriods+(x<<1), WORD RandPeriod(x)
ENDIF
#ENDIF
NEXT X
;-- setup CCP1 and Start Timer1 --
CCPR1 = CCPR1val ; set compare value
CCP1CON = %00001011 ; compare mode, special event
Timer1 = 0 ; clear Timer1
T1CON.0 = 1 ; start Timer1
;----[Main Program Loop]----------------------------------------
Main:
' Check if flash mode has changed
IF FlashMode <> Old_FlashMode Then
Old_FlashMode = FlashMode
GOSUB SetNavLtsFlashRates
EndIF
x = (x + 1) // LEDcount
PORTB.1(x) = !!(LoopLED(x) < OnTime(x))
LoopLED(x) = (LoopLED(x) + 1) // (OnTime(x) + OffTime(x))
#IFDEF USE_RANDOM_SEQUENCE
IF x < 5 THEN
RandPeriod(x) = RandPeriod(x) - 1
IF RandPeriod(x) = 0 THEN
READ RandPeriods+(x<<1), WORD RandPeriod(x)
RANDOM RND
OnTime(x) = (MAX_ON - MIN_ON)* RND.HighByte / 255 + MIN_ON
OffTime(x)= (MAX_OFF - MIN_OFF)* RND.LowByte / 255 + MIN_OFF
ENDIF
ENDIF
#ENDIF
IF x != (LEDcount - 1) THEN Main
Waiting: IF !CCPIF THEN Waiting
CCPIF = 0
GOTO Main
Bookmarks