-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doesn't work with Robotdyn AC Dimmer #11
Comments
I added
now the compare match interrupt fires on time, but the light still doesn't dimm. I left the interrupt on for the second match to print the micros(), and it run and the time is somehow OK (not 20 half-micros, but I had Serial.print there)
this doesn't look right in compare match interrupt
TCCR1A is set in capture interrupt as
with
it started fading but randomly gets out of sync and flickers.
in capture interrupt (clear I give up with your library. Additionally I use pin 10 as slave select for Ethernet shield and your library doesn't have an option to use only one pin of Timer1. |
Probably the easiest solution is to add a small RC filter to debounce the pin. Put a small 220 Ω resistor between the zero crossing pin between Sync and arduino pin 8, and wire a 1 µF capacitor from pin 8 to ground; that should be enough to fix the issue entirely without introducing too large of a timing error. These values were determined with this handy debounce calculator and give a debounce time of 142 µs (a little over 1% of the half-wave period), but if you are able to measure the debounce time with an oscilloscope you can calculate your own component values if you want the timing to be tighter than that. Note that your debug code may actually be causing additional problems. Try switching to a higher baud rate (like 115200) to give yourself some more breathing room. Even at 115200 you still only get 115 characters per half-wave, but as long as you're not using the serial for anything else alongside it that should be enough to prevent the debug code from interfering with the interrupt timing.
After looking at it I believe you are in fact correct. This is actually a pretty huge error, I have no idea why it even works at all for me. I'll fix this ASAP. TriacDimmer.cpp:100 should read: TCCR1A &=~ _BV(COM1A0); //clear OC1x on compare match and likewise TriacDimmer.cpp:112 should read: TCCR1A &=~ _BV(COM1B0); //clear OC1x on compare match I've split this off as issue #12. If you want to PR this yourself to take credit for the fix I'd be glad to accept it, although I may get to it first.
Actually that's a good suggestion. I'll take a look at updating the library to support using only a single pin. I've split this off as issue #13. |
and |
Thanks, you're correct there too. The changes are in PR #14. Can you comment there if those changes work before I merge it to master? |
Are you using it with an LED or CF bulb? Triac dimmers don't work with those kinds of loads, they only really work with resistive loads like incandescent bulbs or heaters. Otherwise, the instability is likely due to the fact that the triac isn't capable of holding itself on for a small portion of the phase near 0 volts, and if the 20 µs pulse occurs in that window it won't latch on. There is a solution for this, it's just not implemented yet. Give me a bit and I'll add it. I've split this issue off as issue #15. |
Ok, I've just merged the fixes for #12 and #15 (PRs #14 and #16) into the development branch. Can you test whether these changes fix the issue for you and let me know so I can make a new release and push the updated library to the arduino library list? |
I use incandescent light bulb for test. In the project I control a heater. |
Can you test if the version in the development branch works? I've added the fixes for the issues with the compare match behavior and changed the behavior so an early pulse stays high until a minimum amount of time from the zero cross (enough to ensure triggering but without saturating the gate). |
|
Oh you're right; I've added the Can you elaborate on the flickering you're seeing? I don't actually have access to real hardware to test against at the moment, so I'm going to need you to describe what you're seeing in more detail. What dimmer values result in flickering? And what do you mean by "fade-out is nice, but it still flickers on fade-in"? That makes it sound like the flickering is only happening while gradually increasing the dimmer value, but that decreasing it - even through the same dimming percentage - doesn't cause flickering, which seems unlikely (and if that is the case, I definately need to see the code you're using that causes this). Do you have an oscilloscope you can use to probe the circuit? |
the brightness increases, but on every change it flickers. |
Huh. I think what's happening is that the |
Ok, just added code to the dev branch that should buffer the negative edge offset to prevent this flickering. (Commit 8a1be9c) Can you test it and report if this change fixes the flickering issue? |
I also just made another small change in dev to eliminate one other possible but unlikely source of issues due to non-atomic writes to the variables that control ISR behavior. |
@JAndrassy Does the code in the dev branch now work correctly on your hardware? |
you should really compile before commit now the fading is smooth. brightness values less then 0.02 don't work. the light is on and flickers. at 0.0 too |
You're right, I should be compiling this before committing; the reason I haven't is mostly that I've been doing this from my phone. I'm back home now though so I should be able to work faster. I'll work on implementing the channel disable functionality and minimum brightness threshold. |
Ok, I've implemented the channel disable functionality (by default each channel is disabled until you enable it by setting its brightness) and added parameters for the upper and lower thresholds outside which the pin will be either always on or always off. There's also been a handful of other tweaks to the code that should make it just a little bit more stable and/or performant (ensuring both edge offsets for a channel get updated atomically, basing the falling edge in the compare interrupts on last_icr in case the input capture is somehow retriggered, etc.). |
now it fades nice (with off_thresh 0.03) . triac is on pin 9 and a 5 mm LED blinks on pin 10. |
Yes, yes it is. Thanks for the help finding and solving these issues. |
There we are, just packaged and released v1.1.0 incorporating all of the changes. Thanks again for bringing up these issues and helping fix them. |
5 minutes after release the new version is in Library Manager. thank you for your effort |
With Robotdyn AC Dimmer (schematics) and basic_example.ino the light is full on and sometimes flickers.
I test with Arduino Nano.
I added some debug prints in ISR(TIMER1_CAPT_vect) after last_icr = ICR1:
output is
sorry I rewrote this issue twice until I debugged the problem.
the problem is, there are some phantom zero crossings resulting in period 0 and brightness is calculated with this value
The text was updated successfully, but these errors were encountered: