I am building a dimmer for 3 10 W g4 halogen lamps using:
attiny84
5V voltage regulator
Mosfet driver
Mosfet
Power supply 12 V dc 3.75 A
I first built the circuit on breadboard and used my Arduino to get it going. Then I ported the program to the attiny84 (almost ripping my hair off before that worked smoothly).
#define dimdelay 15
#define dimdelay2 500
#define min_output 30
const int lampPin = 5;
const int buttonPin = 1;
boolean lampOn = false;
boolean lastLamp = false;
int output=min_output;
int dimdir=1;
// the setup routine runs once when you press reset:
void setup() {
pinMode(lampPin,OUTPUT);
pinMode(buttonPin,INPUT);
//set frequency of PWM to a value that generates no humming
TCCR1B = TCCR1B & 0b11111000 | 0x04;
}
void loop() {
boolean buttonState ;
if ((digitalRead(buttonPin)==HIGH))
{
delay(400);
buttonState=digitalRead(buttonPin);
if (buttonState==LOW)
{
if(lampOn)
{
lampOn=false;
}
else
{
lampOn=true;
}
if(lampOn)
{
analogWrite(lampPin,output);
}
else
{
analogWrite(lampPin,0);
}
}
else
{
while (digitalRead(buttonPin)==HIGH)
{
output+=dimdir;
if(output==255)
{
analogWrite(lampPin,output);
delay(dimdelay2);
dimdir=-1;
if (digitalRead(buttonPin)==LOW)break;
}
if (output<min_output)
{
delay(dimdelay2);
dimdir=1;
if (digitalRead(buttonPin)==LOW)break;
}
analogWrite(lampPin,output);
delay(dimdelay);
}
}
}
}
Then I transfered the circuit to a breadboard type PCB and had some soldering issues which I think I have taken care of.
Now for my problem: The circuit is very unstable. It works fine when I don't connect the lamps(signal from mosfet driver is OK) but when I plug them in it works "sporadically". I.e. It may work as intended for a minute and then just die. A faint clicking sound can be heard (about one click per second) though when the "button" is depressed. Then suddenly it may start working again for a while.
Hi, can you post a copy of your circuit, it sounds like a layout problem, but their may be some loading concerns with the components used.
A pic of a hand drawn circuit would be okay.
Have you measured the 12V supply when this happens, 12V at 10W, = 0.833A times 3 = 2.5A so you are within supply specs.
Can you measure the supply current as it is starting to make sure your load is only 2.5A at full load?
Is the click coming from the supply? This is common from a switch mode supply going into current limit.
I can see that you only have a digital in, so you are basically not using it as a dimmer but as a soft start, and soft stop.
Hope to help with your probem, Tom.....
Electrically speaking, halogen lamps aren't great for being dimmed, you need the lamp to make temperature or the halogen doesn't envelope the filament which leads to shorter life expectancy.
Halogens also destroy diac (or is it triac?) based dimmers after a while.
Hi. halogens have a hit inrush current, which I think your are trying to minimise, this is because the cold filament resistance is very low.
How quick are you going from start to full brightness?
Also have you got significantly bigger conductors for the high current paths on your board? If not you may be dropping voltage that is causing the attiny to reset.
If all your wiring is done using the wire that we see on top, then definitly not heavy enough if used for the lamp current.
The board tracks are also too light in guage if you have lamp current flowing through them.
The connection from MOSFET source to the neg input terminal should be a separate heavier wire.
Your MOSFET should be as close to the 12V input terminals as possible and the positive 12V to the lamps should be taken directly from the positive 12V input terminal on your board.
Have you tried using only one lamp, then 2, then 3 to see if it works with lower load?
Thanks for all input.
I have had time to make some more tests and the project works with one lamp. With two lamps it does not.
It seems like it is the power sourse that is clicking indicating that there is a too great powersurge starting up. As mentioned above the resistances of the lamps when cold is very small and the mosfet driver is capable of putting out about 2 A momentarily but i am unsure whether this is drawn from the power source directli or if it is stored internally in some capacitors.
That the circuit was sporadically working earlier was probably due to bad solders which I now have improved.
So now the question is if I should look for a better power source or if some larger capacitors could solve the problem...
I broke out the mosfet from the original board and put it on a separate board using the power supply described earlier. The positive goes directly to the lamps and the return goes to the board and the drainpin on the mosfet. The original board is now powered by a separate 12 v DC supply. The two boards are only connected in a common ground and the signal from the mosfet driver.