
Originally Posted by
richard
maybe malcom could refresh us on the issue , but as I understand it
1.the external pwm chip has 4096 steps
2.the loop update time is in 1 sec intervals
3. the desired fade in /out period divided by the loop time yields too few "pwm" steps for a smooth looking transition if you simply divide 4096 by the number of available steps
my theory is that if the steps are chosen well the effect may be smoother
Close 
With a friends help I've implemented a routine using the internal timers to get timings under a second.
Code:
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ToggleLED1, ASM, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
T1CON = %00000001 ; free-running, 1:1 prescaler
TMR1H = %11111111
TMR1L = %11111011
@ INT_ENABLE TMR1_INT ; enable Timer1 interrupts
And
Code:
ToggleLED1:
TMR1H = %11111111
TMR1L = %11111011
pcaPwmValue0=pcaPwmValue0+1
pcaPwmValue1=pcaPwmValue1+1
@ INT_RETURN
I can go from 0 - 4095 in less than two minutes, which helps in test runs.
The ramp up is controlled by the case statement
Code:
case DAWN
lcdout $FE,$80+15,"DAWN "
if pcaPwmValue0 => blue_delay_in then
B_PWM=B_PWM+1
pcaPwmValue0 = 0
endif
if B_PWM => B_MAX then
Blue_Day_Cycle = DAY
endif
The value for the pulse width is then written to the PCA chip in the main loop
Code:
pcaChannel = 0 ;Set a PWM channel
lcdout $FE,$80,"CH1"
i2cControl = $6 + 4*pcaChannel ;LED0_ON_L $6
I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[0,0,0,B_PWM ]
I have everything working fine, when using pre-set values for the fade in times and brightness and can do a full dawn, day, dusk, night cycle in five minutes, I just need to be able to sort out the manual settings for adjusting the the brightness so I can enter 0-100% rather than 0 - 4095 on the LCD
Hope this additional information helps
Bookmarks