کد زیر برای دیمرac با اردینو و ترایاک و اپتوکپر هست.
میخوام در بارش توضیح بدی مخصوص درون تابع zero_cross. چرا فقط 10 میکروثانیه روشن است؟
int LAMP = 4;
Sure, I'd be happy to explain how this code works, particularly the zero_cross function and why the pulse to the triac (via LAMP pin) is only 10 microseconds long.
Overview of the Code:
Firstly, let's understand the purpose of the code. This code is used to control the brightness of an AC lamp (or any other resistive load) using a method called phase angle control. It uses an Arduino, a triac, and an opto-isolator to achieve this.
Key Components:
Triac: A semiconductor device that can control AC power to a load. Once triggered, it conducts current until the next zero crossing of the AC waveform.
Opto-isolator (Opto-coupler): An electronic component that transfers electrical signals between two isolated circuits by using light. In this case, it safely triggers the triac without direct electrical connection.
How Phase Angle Control Works:
In AC power control, phase angle control involves delaying the firing angle of the triac after each zero crossing of the AC waveform. By adjusting this delay, we control how much of the AC waveform is allowed to pass to the load, thus controlling the power and brightness.
Sets LAMP (pin 4) as an output to control the opto-isolator (and thus the triac).
Attaches an interrupt to pin 2 (digitalPinToInterrupt(2)), triggering on any change (CHANGE) in signal. This interrupt will call the zero_cross function whenever a zero crossing of the AC waveform is detected.
Main Loop:
cpp
void loop()
{
int data = analogRead(A0);
int data1 = map(data, 0, 1023, 10, 49);
dim_val = data1;
}
Reads an analog value from pin A0 (presumably from a potentiometer or other input device).
Maps this value to a range between 10 and 49, which corresponds to delay values used for dimming. This determines the firing angle delay.
digitalWrite(LAMP, HIGH); sends a voltage to the opto-isolator LED, which triggers the triac.
The pulse is held high for 10 microseconds.
After that, it turns off (LOW), waiting for the next zero crossing interrupt.
Why Only 10 Microseconds High Pulse?
Triac Triggering Requirements:
A triac requires a gate pulse to start conducting. Once it starts conducting, it remains on until the current through it drops to zero (which happens at the next zero crossing in an AC circuit).
The gate pulse does not need to be held for the entire half-cycle. It only needs to be long enough to reliably trigger the triac.
Sufficient Gate Pulse Duration:
A pulse of 10 microseconds is generally sufficient to trigger the triac.
This minimal pulse ensures that the triac switches on without wasting power or risking overheating the gate circuitry.
Efficiency and Safety:
Keeping the gate pulse short reduces power consumption in the control circuitry (opto-isolator and microcontroller).
It also minimizes the risk of damage to the opto-isolator or triac due to prolonged gate current.
Avoiding Unintended Behavior:
A longer pulse might not improve performance and could potentially interfere with the operation of the triac or opto-isolator.
It ensures that any residual charge or delays in turning off the gate drive do not affect the next half-cycle.
Summary:
The 10-microsecond pulse is a deliberate design choice to provide a quick, sufficient gate trigger to the triac.
It ensures efficient operation by:
Providing reliable triac triggering.
Minimizing power usage in the control circuit.
Protecting the components from unnecessary stress.
Visualization:
Imagine the AC sine wave crossing zero volts twice every cycle.
At each zero crossing, the interrupt triggers zero_cross().
The program waits (dimming_time) before triggering the triac, controlling the phase angle.
After the delay, a brief 10-microsecond pulse turns on the triac.
The triac conducts for the remainder of the half-cycle until the next zero crossing.
Conclusion:
The short 10-microsecond HIGH pulse in the zero_cross function is designed to efficiently and effectively trigger the triac without unnecessary power consumption or component stress. It's a standard practice in AC phase control circuits to use such brief pulses for triac triggering.
Note: When working with AC mains electricity, always ensure safety and compliance with local regulations. Improper handling can be dangerous.
Answer:
The code you've provided controls an AC dimmer using phase angle control by triggering a triac through an opto-isolator. In the zero_cross function, the key steps are:
Calculating the Delay: The dimming_time variable determines how long the program waits after the AC zero crossing before triggering the triac. This delay controls the phase angle, effectively adjusting the power delivered to the load (lamp).
Triggering the Triac: After the delay, the code sends a short 10-microsecond pulse to the LAMP pin, which is connected to the opto-isolator's input. This pulse triggers the opto-isolator, which in turn triggers the triac to start conducting.
Why Only 10 Microseconds?
Sufficient to Trigger the Triac: A triac requires only a brief gate pulse to start conducting. Once conducting, it continues until the current falls to zero at the next AC zero crossing. A 10-microsecond pulse is typically sufficient to ensure reliable triggering without overdriving the gate.
Efficiency and Component Protection: Keeping the pulse short minimizes power consumption in the opto-isolator and prevents potential overheating or damage to the components due to prolonged current flow.
Avoiding Unintended Effects: Longer pulses are unnecessary and could introduce complications, such as increased electromagnetic interference or unintended interactions with the AC waveform.
By sending only a 10-microsecond pulse, the code efficiently triggers the triac at the desired point in each AC half-cycle without wasting energy or risking component damage. This precise control allows for smooth dimming of the lamp.
So, in the zero_cross function, the lamp is turned on for only 10 microseconds because that's all the time needed to trigger the triac, ensuring efficient and safe operation of the dimmer circuit.
یک پالس ۱۰ میکروثانیهای برای تریاک کافی است تا شروع به رسانش کند. پس از آن، تریاک تا عبور بعدی از صفر به رسانش ادامه میدهد. پالس طولانیتر ضروری نیست و میتواند باعث مصرف توان اضافی یا آسیب به قطعات شود. بنابراین، در تابع zero_cross، پین LAMP فقط به مدت ۱۰ میکروثانیه روشن میشود تا تریاک را بهدرستی و بهصورت کارآمد تریگر کند.