Hello, sorry for my bad English. I am using the dimmer module from robotdyn.
I drive it with the dimmer.h library. When I extend the length of the power cables of the lamps, the dimmer feature disappears, only on/off. I think the library is set for 60hz, I need to set it to 50hz. Can someone help? I can upload the library, can you edit it? I think it will be fixed at 50hz.
I believe that is a setting in the library. Can you post a sketch explaining what you are doing when extending the power cables. A sketch would be worth a thousand words.
The frequency is set in the constructor of the Dimmer object.
/**
* Constructor.
*
* @param pin pin that activates the triac.
* @param mode operating mode.
* Possible modes:
* NORMAL_MODE: Uses timer to apply only a percentage of the AC power to the lamp every half cycle.
* RAMP_MODE: Same as in normal mode, but it applies a ramp effect when changing levels. @see rampTime
* COUNT_MODE: Counts AC waves and applies full half cycles from time to time.
* @param rampTime time it takes for the value to rise from 0% to 100% in RAMP_MODE, in seconds. Default 1.5. @see setRampTime().
* @param freq AC frequency, in Hz. Supported values are 60Hz and 50Hz, use others at your own risk.
*
* @see begin()
*/
Dimmer(uint8_t pin, uint8_t mode = DIMMER_NORMAL, double rampTime = 1.5, uint8_t freq = 60);
The Fade.ino example at 50Hz would have a constructor like this if the triac is on pin3
Dimmer dimmer(3, DIMMER_RAMP, 1.5, 50);
You could also edit (using any basic text editor to open the library file) the default code for the constructor in the library and then save the modifid library copy on your computer but it will be overwritten if you download a new version of the library.
Dimmer(uint8_t pin, uint8_t mode = DIMMER_NORMAL, double rampTime = 1.5, uint8_t freq = 50);
I have deleted your other cross-post @fehu1973.
Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.
Repeated cross-posting can result in a suspension from the forum.
In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.
For example, it can dimmer without any problems with a 30 cm cable.
The dimmer disappears when the cable length is between +5 and 10 meters. It only works on/off.
I tried but it didn't work. My cable length from the module to my lamps is approximately 10-15 meters. When I connect the lamps with a short cable, it works, but the long cable does not dimmer.
Dimmer dimmer1(5, DIMMER_RAMP, 1.5, 50);
Dimmer dimmer2(6, DIMMER_RAMP, 1.5, 50);
Dimmer(uint8_t pin, uint8_t mode = DIMMER_NORMAL, double rampTime = 1.5, uint8_t freq = 50);
Please explain more about your hardware setup.
What AC voltage is being switched?
Are you using a commercial SSR or a circuit you have put together?
What type of light is being dimmed? Incandescent? LED?
Please post a hand drawn circuit diagram.
The module I use is the 4 channel triac module of the robotdyn company. I use 50 hz home electricity. My lamps are 220v LED, the library I use is dimmer.h. My problem is exactly like this, when I connect my lamps to the module with a 10-20cm cable, everything works fine. But for example, the lamps are in another room, there is a length in between, when the cable meter increases from 5 meters to 10 meters, the dimmer feature does not work, the triac only works on and off, the dimmer cannot be turned on and remains unresponsive. I thought this might be a 60hz 50hz problem. Frequency may decrease due to cable length.
The problem only works in the library when I use it with a different library, but I need to use dimmer.h in my project. I can't change my library. What I want to do is to change the frequency and try that way.
Your image shows incandescent lights. Dimming LED's may have unique issues. There is much to be found on line. This is a hardware issue which is not an area I know much about.
No, frequency will not change.
Have you tried with incandescent bulbs?
I discovered something, when I set it to 50 Hz, it started to work in certain number ranges, but once I set it to 0, when a dim value is sent again, it turns on full, but if I don't change the PWM value (0-100) from 0 to full, it works in the range, but once I set it to zero, it breaks. This is ridiculous. It's gotten better. I have to use LED bulbs.
Let me explain the subject from the beginning, I have an Arduino Uno, a Robotdyn 4 channel dimmer card and LED bulbs.
I send the PWM value from the computer to the Arduino with an interface I made with C#, for example, I send the number range command from a slider from the computer and set it on the Arduino. My purpose is to dim and turn on the lamps from my computer interface. I can do this without any problems when I keep the cable going to the lamps short. However, when the length of the cable becomes longer, it does not have a dimmer feature, it is ridiculous and works poorly, just like on/off. My goal is to set the 0-100 number range that I sent from my windows interface to triac on Arduino.
Are you referring to the cable that connects the Arduino to the dimmer module, or the cable that connects the LED bulbs to the dimmer?
220v load output connecting LED bulbs to dimmer
Please post your code
How can I change this line of code to 50hz? Can you fix it?
// Setup timer to fire every 50us @ 60Hz
TCNT(DIMMER_TIMER) = 0; // Clear timer
TCCRxA(DIMMER_TIMER) = TCCRxA_VALUE; // Timer config byte A
TCCRxB(DIMMER_TIMER) = TCCRxB_VALUE; // Timer config byte B
TIMSKx(DIMMER_TIMER) = 0x02; // Timer Compare Match Interrupt Enable
OCRxA(DIMMER_TIMER) = 100 * 60 / acFreq - 1; // Compare value (frequency adjusted)
started = true;
I don't think that you need to to anything.
acFreq will pick up the value of 50 or 60 from the constructor.
If acFreq = 50 instead of 60, then the OCRxA value will be 6000/50 -1 or 119 instead of 99.
The timer will fire every 60us at 50 Hz. That is each timer tick is longer at 50 HZ than 60 Hz.
OCRxA(DIMMER_TIMER) = 100 * 60 / acFreq - 1; // Compare value (frequency adjusted)
I don't understand where I should write. What should I write instead of 100 * 60 / acFreq - 1? Is it wrong to organize and give the sections? let me try.
That line is inside the library and you do not need to write anything special.
Please post your code so that I can see if you have the constructor correct.