Hi, I am new on this forum so here's my problem.
I wrote a program in my pic because I want to build a home made desklight. I'm using leds which are adjustable in intensity, this using PWM ofcourse.
Now there are 2 kind of leds, one with high brightness leds, and one with large angle leds. The intensity is set for the both. Not independant. THe program works. S2 switches between only the first set of leds, or the second set of leds, or both. The first 2 options work perfect with the PWM commando. Now with the third option doesn't work well with the pwm commando. This is because the PIC pwms the first set of leds, then leaves them black, and then pwms the second set of leds. I want them both at the same time, with the same intensity ofcourse. Now what I actually need is a replacement commando for PWM. Something with for next loops perhaps?
Thanks already for your help.
Greetings
Robin
I wrote a program in my pic because I want to build a home made desklight. I'm using leds which are adjustable in intensity, this using PWM ofcourse.
Now there are 2 kind of leds, one with high brightness leds, and one with large angle leds. The intensity is set for the both. Not independant. THe program works. S2 switches between only the first set of leds, or the second set of leds, or both. The first 2 options work perfect with the PWM commando. Now with the third option doesn't work well with the pwm commando. This is because the PIC pwms the first set of leds, then leaves them black, and then pwms the second set of leds. I want them both at the same time, with the same intensity ofcourse. Now what I actually need is a replacement commando for PWM. Something with for next loops perhaps?
Thanks already for your help.
Greetings
Robin
Code:
DEVICE 16F628A ;Using the 16F628A
CONFIG INTRC_OSC_NOCLKOUT, WDT_OFF, PWRTE_ON, LVP_OFF, MCLRE_OFF ;Fuses instellen
ALL_DIGITAL TRUE ;All info is digital
Dim Duty as byte
Dim main_switch as byte
SYMBOL LED0 = PORTA.0
SYMBOL LED1 = PORTA.1
SYMBOL LED2 = PORTA.2
SYMBOL LED3 = PORTA.3
SYMBOL S0 = PORTB.0
SYMBOL S1 = PORTB.1
SYMBOL S2 = PORTB.2
;76543210
PORTA = %00000000 ;Port A low
PORTB = %00000000 ;Port B low
TRISA = %00000000 ;All output
TRISB = %00000111 ;ports 0-2 input
PORTB_PULLUPS ON
LED3 = 1
Duty = 255
main_switch = 1
Loop: ;start mainloop
While 1 = 1
Select case main_switch
Case 1
PWM LED0, Duty, 10
Call readaction
Case 2
PWM LED1, Duty, 10
Call readaction
Case 3
PWM LED0, Duty, 10
PWM LED1, Duty, 10
Call readaction
End Select
Wend ;End mainloop
readaction:
Select Case 0
Case S0
If Duty = 30 then
Duty = 30
else
Duty = Duty - 25
End if
while S0 = 0 : wend
Case S1
If Duty = 255 then
Duty = 255
else
Duty = Duty + 25
End if
while S1 = 0 : wend
Case S2
If main_switch = 3 then
main_switch = 1
Else
main_switch = main_switch + 1
End if
while S2 = 0 : wend
End select
return
END ;End program