I'm trying to drive a Mosfet to dimm the light. All is driven on AC voltage.
The only problem I have is how to set in the software interrupt signal ( zero crossing signal) to drive a Mosfet by PWM.
This is not the same as Triac it is definitely different way.
Please anyone can help?
That's a pretty advanced use of a timer. I've never tried to do it myself but I expect the hardware supports it.
You need to find which registers control the timer and use them to reset the timer to zero in the interrupt. The datasheet has all the details you need.
I want to drive this mosfet by opto. See attached 2 photos. First is Zero crossing circuit and second is a mosfet driver with resistor sensing for interrupt. That interrupt I use to switch Mosfet ON and OFF if AC output will short for any reason so will not blow the circuit.
Now I want to synchronise pwm signal with zero cross detector.
This is temperature sensor which reading a room temp and when it is reached ( set temperature minus 2degC ) then pwm from 255 to 130 to set temperature.
Set temperature is set by 2 buttons up and down or potentiometer.
I need only the sketch to synchro ZC circuit with PWM.
It sounds like you want to do temperature control:
danio40:
This is temperature sensor which reading a room temp and when it is reached ( set temperature minus 2degC ) then pwm from 255 to 130 to set temperature.
When all this started, you wanted to
danio40:
... dimm the light.
What are you really trying to do?
Where did these schematics come from, and where can we find the missing parts of them? The images are hard to read; they might be easier to interpret in their native format.
Schematic I have already working as a mosfet dimmer and it is working fine. In my case I want to dimm the light when temp is between +/-2degC. For example:
If you set temp to 25C and room temp is 18C then:
Light is fully ON (255) up to 23C. When it is reached the 23C then light starting to dimm from 255 to 130 until sensor reach temp = 27C. Also there are 2 cases:
When temp is below set temp -2 ( in that case below 23C) then light is fully ON - PWM 255.
When temp is above set temp +2 ( in that case above 27 ) then light is 50% ON - PWM 130.
Also one more case when set temp is above 30C light is OFF - PWM 0.
That is the case. As you can see ZC circuit is very simple and give a nice signal for interrupt signal for arduino pin 2. Second circuit is a 1channel shown ( originally is 2 channel circuit) so The driver is MIC5020. If you see a spec is used in nice mode. Usually people use 1 mosfet and the bridge to drive a lamp. In that case instead of to use a bridge ( drop voltage is too high and get hot really hot) I use second mosfet and another MIC driver. Both are sensing resistors just for one case. When the bulb at the output is short ( in any reason - I mean short main) then the MIC switches off Mosfet before they blow and sending a FAULT signal by opto to an led to show there is a short. This circuit is trying to restart until the short will remove (change a bulb). All is separated from mains so there is opto to drive a MIC chip ( then mosfet) and Fault signal also goes by opto for led. and at the end EN signal to switch ON/OFF power supply for MIC driver to restart completely the circuit.
At the moment this circuit works without any problem if you send PWM you can dimm the light but I want use this ZC circuit for synchronize with PWM. When PWM is going to an opto the MIC driver I want to do that when main is in zero not when it is 50 or 100%. Same what you do in TRIAC but mosfet is different. Also this should work with 120VAC and 60HZ.
Any thoughts?
LM35 as sensor is used so it is pretty obvious and set temp is set by 2 switches up and down between 18 and 33C. Everything is shown on LCD.