last day (15 days later) » 

16:29
0
Q: Thunderstorm reseting my micro-controller

JoeyI think this is a follow up from my previous question. If not then please ignore it. I have created a very basic (crude) alarm system that uses a reed switch. Luckily there was a thunderstorm and some lighting to test out the system. Below is a schematic of the system. The works as expected, when...

You mean Lightning , not thunder and the dI/dt couples into current loops which may be attenuated with ferrite sleeves or shunt 0.1 Caps and twisted pair or gnd'd STP cable.
Schematic and PCB layout for the board that houses the microcontroller?
@Unimportant the schematic is shown above. I am using Veroboard since the FR-4 PCB design is a bit expensive and this is for personal use not commercial.
@Joey Poor board layout/decoupling and not conditioning external current loops going trough long wires as mentioned before would certainly be a plausible cause.
Unfortunately, the schematic doesn’t make much sense. What is a ‘gds’? The wiring to the reed switch is acting like an antenna. When lightning hits nearby a large magnetic field is created and your wiring picks it up. Use a varistor or TVS diode to limit the voltage then have a filter with a 10k resistor in series and 100nF capacitor from the port pin to gnd. Your code also need to debounce/filter the input to ignore short pulses. A valid signal is >100ms.
16:29
@Unimportant I see what you meant by schematic and layout. I have updated the post. "not conditioning external current loops" what is this?
@Joey As mentioned by Tony and Kartman, long external wires acts as antennas and signals coming in trough these need to be filtered. That AVR has multiple ground and VCC pins, you should connect them all! There's also completely no decoupling capacitors on your microcontroller board.
@Unimportant okay I see now, so between trig+ and trig- (reed switch inputs), I should put a capacitor? The buck converter thus has a decoupling capacitor at the output, do I still need to add one at the micro Vcc and Gnd?
@TonyStewartSunnyskyguyEE75 where is the best place to put a ferrite sleeve on a cable?
@Joey A simple RC filter and TVS diode might suffice, perhaps this post can give some inspiration. Yes, you still need decoupling caps, right on the supply pins of the AVR, all the supply pins (connect the ones you've left unconnected also)
Without a better cable schematic it's hard to tell. But ferrite can reduce current in low impedance circuits at 1MHz otherwise the circuit resistance with a shunt cap will more effectively reduce voltage, ideally > 40dB at 1MHz or a breakpoint < 10kHz ie. 1k reed inputs with T=RC>350us or C > 350 nF but 0.1uF may be enough. or change 1k to 10k and insert 100R with 0.1uF to limit reed current
@Unimportant I have updated the capacitor part, still working on the RC filter, will update that shortly. However is the capacitors now okay?
16:29
Where is your ground plane and decoupling capacitors?
@winny the circuit is not that complex so a ground plane was not needed. The decoupling capacitors are the blueish, purple cylinders in the pics above.
@Joey - of course you need a groundplane. You’re experiencing EMC issues and you’re breaking the rules! What you think is a simple circuit is way more complex than you realise. AVCC and all the ground pins of the micro NEED to be connected. Single sided boards have the tracks on the bottom.
@Kartman All the Vcc and ground pins of the micro are connected to its respective voltage levels. This is a single sided PCB with the copper traces on the bottom. I have updated the PCB pic and make the FR-4 transparent so you can see the copper traces. The second picture is an inverted image.
@Joey "All the Vcc and ground pins of the micro are connected to its respective voltage levels." - No, they're not, I already mentioned this multiple times. Look at the datasheet for the Atmega 328. Pin 20 (AVCC) & 22 (GND).
And no pullup resistor on the reset pin. Follow the recommendations in the Atmel datasheet.
16:29
@Unimportant "AVCC is the supply voltage pin for the A/D converter, PC3:0, and ADC7:6. It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter. Note that PC6..4 use digital supply voltage, VCC." I shall stop making you angry :)!
@Kartman "A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running. " I shall stop making you angry as well :) thanks for the info!
@Joey - why would you think I'm angry? I'm just pointing out the errors as are the others - and there's quite a few of them.
Au contraire! Your circuit not being DC or audio only is complex enough so you do need ground plane and decoupling. Electrolytics are no good here. You need ceramics or film capacitors very close to the Vcc and directly to your ground plane.
@winny by ground plane you mean the entire bottom surface of the PCB needs to be the ground? What I have done is gound the components where needed using a ground trace only, so you say just a ground trace on the PCB is not good enough.
@winny I have updated the PCB, still working on the LPF part but is your part now correct? I will bridge the Vcc with the AVcc with a wire.
Yes, save for perhaps a few shorts tracks to help out your top side. There is no reason to use a single layer design in 2020 unless you produce in the millions of units. Also, wire = inductance. Local decoupling for every Vcc pin is what you should strive for. If you again are producing in the millions, you can think about reducing them after your initial design.
@Unimportant I have made the final design and included what you said. Is this design now up to par?
@Kartman I have made the final design and included what you said. Is this design now up to par?
@winny I think the PCB manufacture here charges extra for double-sided PCB (need to verify when they open) hence I design using single-sided. I have made the final design and included what you said. Is this design now up to par?
16:29
@Joey Looking much better, yes. You could turn C4 around so it's ground pin is closer to pin 22 of the microcontroller, making the loop smaller still. C2 should probably be electrolytic bulk capacitance, 100μF or so rather then small ceramic.
@Unimportant Thank you, can you explain what you mean by making the loop smaller?
Sure they are charging for it, but how many are you making and how much engineering effort in terms of EMI problems which you are experiencing are you willing to invest in instead? Par for me in the year 2020 would be an all SMD design, two layers minimum and all surplus space removed.
@Joey When the microcontroller demands a sudden surge in current, the power supply cannot deliver it immediately because of the inductance in the traces leading from the power supply to the microcontroller. It's the capacitor's job to supply this surge. Current flows from the capacitor into the microcontroller supply pin, and out again to the capacitor trough the ground pin. You want this loop to be as small as possible, otherwise there'll be inductance introduced again.
@Unimportant "0.1 uF in parallel with 10 uF", will a single 0.1uF suffice for the decoupling capacitor giving my application or do I need to add an addition 10uF in parallel?
@Joey For C1 and C4? 100n ceramic should suffice.
16:29
@Unimportant yes for c1 and c4, thank you for assisting during your holidays.

last day (15 days later) »