Merge pull request #17201 from stefanbode/patch-1

Bugfix for Zero-Cross Power correction
This commit is contained in:
Theo Arends 2022-11-27 18:39:27 +01:00 committed by GitHub
commit a1ffd88819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 14 deletions

View File

@ -32,15 +32,15 @@ typedef struct gamma_table_t {
} gamma_table_t;
const gamma_table_t ac_dimmer_table[] = { // don't put in PROGMEM for performance reasons
{ 0, 0 },
{ 1, 64 },
{ 5, 144 },
{ 10, 205 },
{ 50, 500 },
{ 90, 795 },
{ 95, 866 },
{ 99, 936 },
{ 100, 1000 },
{ 0, 0 },
{ 10, 64 },
{ 50, 144 },
{ 100, 205 },
{ 500, 500 },
{ 900, 795 },
{ 950, 866 },
{ 990, 936 },
{ 1024, 1024 },
{ 0xFFFF, 0xFFFF } // fail-safe if out of range
};
@ -333,7 +333,7 @@ uint16_t ledGammaReverse_internal(uint16_t vg, const struct gamma_table_t *gt_pt
// 10 bits power select to 10 bits timing based on sinus curve
uint16_t ac_zero_cross_power(uint16_t v) {
return ledGamma_internal(v, ac_dimmer_table)/10;
return ledGamma_internal(v, ac_dimmer_table);
}
// 10 bits in, 10 bits out

View File

@ -277,7 +277,7 @@ void SyncACDimmer(void)
// reset trigger for PWM sync
ac_zero_cross_dimmer.startReSync = false;
// calculate timeoffset to fire PWM based on Dimmer
phaseStart_ToBeClockCycles = (ac_zero_cross_dimmer.tobe_cycle_timeClockCycles * (1024 - (Light.fade_running ? Light.fade_cur_10[i] : Light.fade_start_10[i]))) / 1024;
phaseStart_ToBeClockCycles = (ac_zero_cross_dimmer.tobe_cycle_timeClockCycles * (1024 - ac_zero_cross_power(Light.fade_running ? Light.fade_cur_10[i] : Light.fade_start_10[i]))) / 1024;
// Limit range to avoid overshoot and undershoot
phaseStart_ToBeClockCycles = tmin(tmax(phaseStart_ToBeClockCycles, 160000), 0.95* ac_zero_cross_dimmer.tobe_cycle_timeClockCycles);
@ -322,9 +322,8 @@ void SyncACDimmer(void)
#endif // ESP32
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("CNT: [%d], shift: %d, dimm_time_CCs %d, phaseShift_CCs %d, currentPWMcylce: %lu, current_cycle_CC: %lu, lastcc %lu, currentSteps %lu, currDIM %lu, last delta:%lu"),
i, ac_zero_cross_dimmer.currentShiftClockCycle[i], phaseStart_ToBeClockCycles,phaseShift_ClockCycles,ac_zero_cross_dimmer.currentPWMCycleCount[i],ac_zero_cross_dimmer.current_cycle_ClockCycles , ac_zero_cross_dimmer.lastCycleCount, ac_zero_cross_dimmer.currentSteps, Light.fade_cur_10[i],phaseStart_ActualClockCycles);
// Light fading
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("CNT: [%d], shift: %d, dimm_time_CCs %d, phaseShift_CCs %d, currentPWMcylce: %lu, current_cycle_CC: %lu, lastcc %lu, currentSteps %lu, currDIM %lu, last delta:%lu"),
i, ac_zero_cross_dimmer.currentShiftClockCycle[i], phaseStart_ToBeClockCycles,phaseShift_ClockCycles,ac_zero_cross_dimmer.currentPWMCycleCount[i],ac_zero_cross_dimmer.current_cycle_ClockCycles , ac_zero_cross_dimmer.lastCycleCount, ac_zero_cross_dimmer.currentSteps, Light.fade_cur_10[i],phaseStart_ActualClockCycles); // Light fading
//AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("CNT: [%d], curr: %d, final: %d, fading: %d, phase-shift: %d, ON/OFF: %d"),i, Light.fade_cur_10[i], Light.fade_start_10[i], Light.fade_running, phaseStart_ToBeClockCycles,ac_zero_cross_dimmer.PWM_ON[i]);
} // do sync onchannel