Thanks, my code is as follows. I need to produce a steady voltage between 1-10V to dim the ballast according to my "moon" position (ie. my lamp). Sort of a sunriser with gradual rise/set controlled by PWM.
The ballast is at best an EVG 2x24W T5 dimmable, with a max current rating of 0.2mA. I cant find any datasheets unfortunately.
void setmoonparam () {
if (hrs>=uphr) {
if (min>=upmin) {
if (updown==0) {
setup_ccp2(CCP_PWM); // Configure CCP2 to PWM on pin C1
setup_timer_2(T2_DIV_BY_1, 255, 1); // Tosc/((PR2+1)*4*prescale)
// 20000000/((255+1)*4*1) = 19,5kHz, 51,2us
updown = 1;
moonintensity = intensitet[abs(fullmoon-day)];
set_pwm2_duty(255*moonintensity/100);
}
}
else {
if (updown==1) {
setup_ccp2(CCP_OFF);
setup_timer_2(T2_DISABLED,0,1);
}
updown = 0;
moonintensity = 0;
}
}