eblc1388 said:Mega AVR series already have internal pullup resistor on the RESET pin, so adding external reset resistor serve no good purpose.
On recent AVRs, the RESET pin is used also as "DebugWire" to communicate with the host software for debugging purposes and this preclude any connection of capacitor on this pin.
The OP's problem is most certainly not caused by "floating" reset pin, but more like software problem. Have the watchdog timer disabled or configured correctly? Is the main program looping correctly?
On most LCD modules I have used, the backlight LED(s) would draw more current(>100mA) than the AVR port pin can comfortably source/sink so it is better to use a transistor as a buffer.
// Defines
#define STOP_TIMER TCCR0 &= ~((1<<CS02) | (1<<CS01) | (1<<CS00))
// timer prescaler of 256
#define START_TIMER TCCR0 |= (1<<CS02)
// Timer 0 Overflow Interrupt handler, counts seconds
ISR(TIMER0_OVF_vect)
{
// 256 ticks have gone by
Ticks256++;
// 1 second per 150 counts with timer prescaler of 256 and clock of 1
if (Ticks256 == 150)
{
Ticks256 = 0;
count_seconds--;
// wait for run out
if (count_seconds == 0)
{
// my counting down and switching on and off happens here
}
}
}
// Main function
int main(void)
{
// Configure device
cli(); // disable interrupts just in case
TCNT0 = 0x00; // clear Timer/Counter
START_TIMER;
// enable interrupts on timer 0 overflow
TIMSK |= _BV(TOIE0);
// Set MCU control register
MCUCR |= (1<<ISC11) | (0<<ISC10) | (1<<ISC01) | (0<<ISC00);
sei(); // enable interrupts
// Loop forever; the interrupts will take it from here
while(1)
{
}
}
Chris_P said:Thanks for your advice. I was worried it may be a software problem. I have had no training at all in programing and have pieced the code together myself, so I am rather embarrassed about how poor most of my coding is. My code is very long so I will try and post the parts relevant to the timer here and hopefully you may see some obvious problem.
I don't think I have done anything with the Watchdog timer, will this cause a problem?
With regards to the backlight, I will look at including a transistor in my circuit. What damage could be caused by me using the AVR port to sink the current? Will I damage the AVR?PHP:// Defines #define STOP_TIMER TCCR0 &= ~((1<<CS02) | (1<<CS01) | (1<<CS00)) // timer prescaler of 256 #define START_TIMER TCCR0 |= (1<<CS02) // Timer 0 Overflow Interrupt handler, counts seconds ISR(TIMER0_OVF_vect) { // 256 ticks have gone by Ticks256++; // 1 second per 150 counts with timer prescaler of 256 and clock of 1 if (Ticks256 == 150) { Ticks256 = 0; count_seconds--; // wait for run out if (count_seconds == 0) { // my counting down and switching on and off happens here } } } // Main function int main(void) { // Configure device cli(); // disable interrupts just in case TCNT0 = 0x00; // clear Timer/Counter START_TIMER; // enable interrupts on timer 0 overflow TIMSK |= _BV(TOIE0); // Set MCU control register MCUCR |= (1<<ISC11) | (0<<ISC10) | (1<<ISC01) | (0<<ISC00); sei(); // enable interrupts // Loop forever; the interrupts will take it from here while(1) { } }
Chris_P said:My code is very long so I will try and post the parts relevant to the timer here and hopefully you may see some obvious problem.
Chris_P said:I don't think I have done anything with the Watchdog timer, will this cause a problem?
I'll do as you suggest. I am self taught and don't really know the best ways to do a lot of these things.eblc1388 said:I can't see anything abnormal in the code posted but it seems you have placed all the timing values testing and handling inside the interrupt routine.
I would advise to try to place the testing of timing variable inside the main routine "while loop" so that the only job of the interrupt is to decrement the timing count variable. Wouldn't it be better to decrement a single variable which represent the total time required inside the interrupt handling routine, instead of working on two variables. Only in case of ASM programming, you'll need to do just that because of the 256 size limitation on each entity. In C, your variable can have very large value.
I put in a bit of extra code to disable it anyway.eblc1388 said:The watchdog timer is most probably disabled but you'll need to double check your compiler documentation.
I have a feeling this is probably the problem. A friend of mine first had the problem when he was switching a solenoid. I got the problem switching a fan, but I just ran it for about 20 hours switching a low powered light with no problem. I have probably put components in bad places. I tried to minimise the board size and just put things wherever I could fit them. This is my board at the moment. I was thinking of putting an MOV on the main supply to the transformer and the relay. Would this help? Is there something else I can do to minimise interference on this board? I really appreciate the help with this.eblc1388 said:If your present program can work for hours but sometime failed, it is possible that the AC load that you are switching has somehow induced interference to the AVR. Try driving the relay without any AC load to see if the program runs properly.
In a noisy environment, 'helping' the weak internal pullup has often been recommended. I recommend it. It certainly does no harm.Mega AVR series already have internal pullup resistor on the RESET pin, so adding external reset resistor serve no good purpose.
I am using ATMEGA16-16PU being clocked by a 9.8304Mhz oscillator.ikalogic said:the ATMEGA16L-8PU only goes to 8 Mhz....
Don't think there is much I can do about that on my existing boards but I will widen it on my new ones.eblc1388 said:If this is the first time you have tried to actually layout a PCB, I must say you have done surprisingly well. There are some minor suggestions for you to consider.
1. the 0V trace is too thin and too little and it is not good for overall stability. Usually the 0V common occupied quite some space on the board and they also acts as ground plane. Your AVR can go up to 16MHz clock and it is in effect an RF circuit.
As eblc1388 suggested in a PM I cut this trace as close to the relay as I could and soldered the wire directly to the relay.eblc1388 said:2. one of the AC connections from the relay is too close to the AVR pin (IDC connector pin16) and electrical leakage could be a problem. I would suggest you rotate the 7805 counterclockwise to get some board space and move the AVR and LCD IDC connector up a bit so that you have larger separation between AC connection and the IDC pin16. Since you are using both PCB sides for load current carrying, the trace width can also be made a tiny bit smaller to help separation.
I found the peak DC voltage was high but when the relay was switched it dropped a bit to be just inside the specs of the relay. So hopefully this doesn't cause a problem. I will use a zener diode on my next design.eblc1388 said:3. the rectified 12.6V AC would give some 17.6V DC peak voltage to the 7805 input and also the relay coil. This might be too high for the relay. Measure actual voltage and check relay spec.
I added one to the main supply just to be safe.eblc1388 said:4. the addition of a MOV might or might not help and I cannot say for sure. It would not hurt for sure.
I am pretty sure it is switching inductive loads that is causing the problem. It works fine when switching no load or very small loads but I need it to be able to switch anything that can be plugged into a 10A 240V socket including AC units, pump motors etc.eblc1388 said:5. if switching inductive load cause problems, then you would need to look into better electrical shielding using metal enclosure or in extreme cases optical isolation between relay circuit and AVR.
I made changes to the code and configured all unused pins as OUTPUT and set them HIGH. On the existing boards I couldn't find a way of putting a resistor to VCC but I have soldered a 0.1uF cap from the reset pin to 0V.eblc1388 said:6. look into unused AVR pins and make sure that they are configured as OUTPUT if possible. Usually I would set them to HIGH. In your case, an extra 10K to VCC and 0.1uF capacitor to 0V on the AVR reset pin might also help.
Chris_P said:Thought I'd post about my progress, maybe someone else will learn something from my mistakes too. I stupidly built quite a few of these before I discovered the problem so I am attempting to fix these ones without having to rebuild them completely.
Don't think there is much I can do about that on my existing boards but I will widen it on my new ones.
As eblc1388 suggested in a PM I cut this trace as close to the relay as I could and soldered the wire directly to the relay.
I found the peak DC voltage was high but when the relay was switched it dropped a bit to be just inside the specs of the relay. So hopefully this doesn't cause a problem. I will use a zener diode on my next design.
I added one to the main supply just to be safe.
I am pretty sure it is switching inductive loads that is causing the problem. It works fine when switching no load or very small loads but I need it to be able to switch anything that can be plugged into a 10A 240V socket including AC units, pump motors etc.
I made changes to the code and configured all unused pins as OUTPUT and set them HIGH. On the existing boards I couldn't find a way of putting a resistor to VCC but I have soldered a 0.1uF cap from the reset pin to 0V.
A couple are being trialed again now on high loads. Fingers crossed.
Chris_P said:Well I have had some advice about my schematic, and a list of mistakes I have possibly made. One was about the opto having a common ground with the rest of the circuit and effectively bypassing the isolation. Do I need to have 2 completely seperate power supplies to use an optoisolator properly?
Chris_P said:I need to get some new boards made up just in case my quick fixes don't work so I thought I'd post my changes and see if anyone can find fault, BEFORE I go and have them made.
Chris_P said:1/ I put in a 2N2222A transistor to switch the LCD backlight on and off.
Chris_P said:3/ I put a 1W 12V zener diode in the unregulated 12V DC supply to switch the relay. Not sure if I put this around the right way.
Chris_P said:4/ I took the relay completely off the board and have put a 4N28 optoisolator instead. I have some of these already so I might as well use them. Not sure about my wiring of these though. Yet to test it. EDIT: I had to add a transistor to get it working.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?