Hello, I am new to Arduino and C programming.
I am trying to use the arduino to prototype a device to convert a triac controller lamp string dimmer circuit to PWM control of leds to replace the lamps.
I have 5 lamp strings, to replace with led's.
Of course the 50hz triac dimmer circuits cause noticeable flicker on the LED's.
I have picked up the 5 triac trigger pulses and a zero crossing pulse from the original control board.
The zero crossing pulse is a 5V positive going pulse approx. 2ms wide.
The 5 triac gate pulses are output from a TTL logic ic and are logic low going pulses around 50us wide.
The trigger line goes high(i.e stops pulseing) to turn the lamp string off and goes low to turn the lamp string on at full brightness.
Also the trigger pulses are not very stable, that is there are 8 brightness settings 1 to 8 but in each setting the trigger pulse will actually occur within a 1ms range.
I have used the zero crossing pulse to reset counters and then the gate trigger pulses to read the counter overflow and use that value to select a value from an array to use as the PWM setting.
I see the outputs duty cycle vary with the brightness settings , however the reliability of the outputs become less as I introduce all the trigger pulses. That is with only 1 trigger pulse line input I get predictable and stable results, the PWM duty cycle increases and decrease's as expected.
However when I connect the full 5 trigger pulse lines the results become less reliable, i.e. sometimes a PWM output duty cycle will not change with an input change or change after some delay.
I am guessing its the ATMEGA 328P having trouble with interrupt timing.
Is there a way to improve this with better code.
My complete code is attached
sketch_GI_Lighting_project_rev4.ino (11.5 KB)