Atmega32 delay function doubles it value seldom,probably due to noise

Go To Last Post
81 posts / 0 new

Pages

Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear all,
I have a code that control ice maker machine. Most of the time it works fine and randomly(I think I noticed faut is triggered by defrost solenoid operation) it just double all of delays:- the freezing , defrost and hinge movement but still it keeps the sequence of operation. In another project I faced noise problem and guys told me to add snubber and it solved the problem. But here I want to exercise defensive programming. I want to know how delay doubled due to noise or discussion of noise effect on the code. To solve the problem I creat safeDelay function which takes three identical arguments and using two timer and loop delay to make accurate delay but it doesn't work. I have attached the codes please help

Attachment(s): 

Last Edited: Wed. Feb 19, 2020 - 05:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Tinsae wrote:

But here I want to exercise defensive programming.

 

Wrong approach. You need to get your hardware right before you start thinking about the software. A hardware design with 'issues' will come back and haunt you days/weeks/months/years down the line.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tinsae wrote:
I think I noticed fault is triggered by defrost solenoid operation

Ha!

 

I once had a project where 50 or so coffee machines were installed across the country, and we were getting "random" failures after a few weeks operation.

 

It eventually turned out that there was a clean cycle run every week or so, and that could cause some "glitch" which messed stuff up.

 

Tinsae wrote:
I want to know how delay doubled due to noise or

Sounds like the delay did something which caused the code to run at half speed? Or maybe just the timers to run at half speed.

 

eg, I think it's possible for a crystal to get "knocked" into working on a different harmonic ...

 

Tinsae wrote:
noise effect on the code

It's unlikely that noise affects the code - it's a hardware thing!

 

But it could corrupt memory, or corrupt comms, or give false readings to the code, or false triggering of interrupts, or ...

 

Tinsae wrote:
I creat safeDelay function which takes three identical arguments and using two timer and loop delay

You need to beware of "single points of failure"

 

eg, if the 2 timers and CPU clock share a common source, then any error on that source will cause them all to change together - so your "safeDelay" function will never notice!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tinsae wrote:
Most of the time it works fine and randomly

Can you post a picture of your board, or your a PDF of your CAD drawing?

Some one may spot where it can be improved.

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to the Forum.

 

Is your board a retro-fit for a commercial ice maker, or a new design?

 

Likely the solenoid is either generating a back-EMF spike, that can be coupled into the circuit either by RF or directly through its wiring; or it is putting a high current demand on a weak power supply, and the power supply voltage is dipping low when the solenoid fires.

 

So it would be reasonable to put a snubber on the solenoid, and put an O'scope on the power bus and on the solenoid wiring and see what they look like.

 

Know that the water control valve and any other electromechanical components can also generate problems as above and may also need attention.

 

JC 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear Brian, I believe putting snubber across the coil will solve the problem because I did it before for another project and believe me I will put snubber. But I want to know before putting the snubber what is going on, like the suggested hypothesis-cpu running at half or something else because after the hardware I believe it is good to make the code also robust so I want to learn defensive programing

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tinsae wrote:
I want to know before putting the snubber what is going on

Then instrument your system so that you can see what's going on!

 

Set up a few examples with "non-snubbered" coils and watch what's happening

 

If you can't then get them to fail, that suggests that you haven't really found the root cause yet ...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:
Likely the solenoid is either generating a back-EMF spike, that can be coupled into the circuit either by RF or directly through its wiring; or it is putting a high current demand on a weak power supply, and the power supply voltage is dipping low when the solenoid fires.

Indeed.

 

All of which should be fairly easy to see on an oscilloscope scope ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes awneil, I am trying to find the common source of error, like cpu running at half speed. Btw I am using the internal clock not external crystal.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have attached the pic

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you DocJC, both my board and ice maker are new design.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So that's very much a prototype, then?

 

Not a PCB; no ground planes, etc, etc.

 

Such a construction would be expected to be rather susceptible to interference!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Feb 11, 2020 - 08:43 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Can you confirm the following...

 

 

I *think* that the blue highlighted wiring is your 0V net, and the red is +5V.

 

 

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please also post the full schematic

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes you are correct

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1


Consider the following...

 

 

Point A is where your power enters, point D is where your relays return their current to the 0V rail, and point C is the 0V reference to your micro.

 

Now we need to remember that in the real world wires, PCB tracks, solder joints, and even chip pins have a resistance.

 

So, what happens when one or more of your relays operates? A current will flow between points A and D and because there is resistance between those points a voltage will develop between those points.

 

Bonus question...what happens to the voltage at point C?

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Unfortunately, that board has ‘death’ written all over it. Don’t ever have mains voltages on dot board like that. Scrap that board for your own safety and rethink how you can build your prototype in a much safer form. Use relays like the omron g2r series so it is easy to maintain adequate separation between mains and elv circuits. Remove the copper dots where there is mains present.

Last Edited: Tue. Feb 11, 2020 - 11:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear all, my trouble is not why my circuit affected by noise since it has no ground plane, opto isolator and etc. But let me take this as an opportunity such that it is prone to noise and try as much as possible with the code. For example I included a code that put the current position to memory which in case of reset the mcu will continue and also included reduendent reading. These two codes saved me from two noise related issues. Now came delay doubling is it possible to know how and why it doubles to make the case more easy once delay double ocurs it continues untill reset it doubles every following delays

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I understand that hardware comes first but what I am doing is make the harware prone to noise and try as much possible to make code defensive and come back to harware as recommended. If I make the hardware bulletproof then how could I make a test for defensive code?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tinsae wrote:
is it possible to know how and why it doubles

As previously noted, you are going to have to investigate that on your board.

 

It is almost certainly not any "normal" operating mode - but some result of all the noise & interference that you are bound to be getting on such a board.

 

For a start, as suggested back in #8, have you used an oscilloscope to actually see the effects that Brian described?

 

Any system is going to do weird things if you abuse it sufficiently - there has to be a tradeoff between getting the design right so that the abuse can't happen, and just tolerating the abuse ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've built a few boards like that over the years...

 

Please be very careful having 220V Mains on your board along with the other circuitry.

 

Put some hot glue over all of the 220 V Mains connections to help keep you from accidentally touching them.

 

Your Mega32 NEEDS two by-pass capacitors for reliable operation.

These are 0.1 uF caps.

One goes from Vcc to Ground.

One goes from AVcc to Ground.

Put these as close to the pins on the micro as you can get them.

 

The large electrolytic caps do NOT serve the same purpose as the by-pass caps.

 

Next:

You need to add the snubber circuits to all of the relays, water control valves, and perhaps to the heater coil.

You need them for reliable operation of the circuit, or the reverse EMF spikes can damage the circuitry.

Adding them will also improve other aspects of your circuit.

 

You can work on making your software reliable and fault tolerant, but start with good hardware.

Otherwise you are wasting your time.

 

You obviously do not want a fault where the water valve turns on and stays on, flooding the building.

You obviously do not want a fault where the heater coil turns on and stays on, overheating the system, and causing a fire.

There are likely other faults that you will not want, also, and you need to make a list of all of them.

 

For your fault protection you can only do so much with software within the micro that is controlling the device.

 

You might well consider adding a second micro as a fault detection and mitigation supervisor micro.

It can monitor the state of the system and watch for any states that should never occur, and if they do occur it can shut off power to the system.

It might time how long the water valve is on and know that it should only ever be on for X minutes.

If it is on for ___ minutes longer then there is a problem and it turns on an alarm and resets the system.

It might have a thermistor to measure the temperature of the ice maker frame.

If it ever reaches > X degrees, then the system is overheating...

 

Obviously, adding a supervisor circuit adds additional complexity, and code, and possible failure points to the project.

So engineering is based on trade-offs.

 

Your next steps should be:

1)  Add the by-pass caps to the micro.

2)  Add the snubber circuits, you need them for a reliable board that will work long term without a hardware failure.

3)  Get an O'scope to look at the power rails, and the signal lines in/out of the micro, as the circuit operates.

4)  Write a test program that simulates normal operation, but much faster, (i.e. not waiting for ice to be made, or the defroster to work, etc.)

It should cycle through turning everything on and off every few seconds, so you can see hardware induced faults much faster, and so you can watch the circuitry with your O'scope for many, many operations, (turning no/off relays, valves, heaters, etc.).

5)  Post a schematic diagram of your circuit.

 

JC  

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What's going on here?  Is that wire supposed to connect to the copper?  If yes, it should be soldered otherwise you may have an intermittent connection.  If no, you should route it through a different hole.

 

Letting the smoke out since 1978

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry Tinsae if I'm sounding harsh - unfortunately you've broken many rules of electrical safety and embedded software. We all make mistakes but we should learn from them.

 

1. Understand creepage/clearance distance between 220VAC and elv circuits This serves two purposes - electrical safety and coupling of transients.

2. Understand wire 'ampacity' and fusing. Don't feed 10 Amps into a circuit with wiring that can only cope with 2Amps - fire risk.

3. Your relays probably aren't safety rated for 220VAC and most likely not mounted on your dot board.

 

Now we get onto your code.

You've got delays, timers, interrupts and many flags and values sprinkled through your code. You call functions with shared variable from timer isrs with no atomic protection. Basically it is near impossible to predict the output in all conditions.

How do we fix that?

 

1. You only need one timer - usually 10ms. All your timing is derived from that.

2. The usual control loop consists of:

  read the inputs

 validate the inputs

 process the control logic

 update the outputs

 

this control loop runs every 10ms.

 

Technically, you don't even need an interrupt for the timer - you can poll the compare flag. Use the CTC mode for the timer.

 

 

Here's an example of how you might implement your alarm flashing:


#define TICK_TIME 10        //in milliseconds
#define ALARM_TIME (1000 / TICK_TIME)   //1 second on,1 second off
bool alarmFlash(bool active)
{
    static uint16_t alarmTimer = 0;
    static bool output = false;
    
    if (active == true)
        {
            if (alarmTimer)
                {
                    alarmTimer--;
                }
            else
                {
                    alarmTimer = ALARM_TIME;    //load up the timer
                    output != output;           //flip the output state
                }
        }
    else        //turn alarm off
        {
            output = false;
            alarmTimer = 0;
        }
    
    return output;
}

Note how it does not manipulate the port bit directly - this means you can test this code on your PC or online using online C compiler tools. You should be able to write your whole control code in a similar way so you can simulate it. Also note how the function does not rely on anything outside of itself.

 

If you have a zillion flags and conditionla tests, this suggests you need to look at using a 'finite state machine' - you sort of have this already but it could be implemented better.

 

with a little bit of thought and some work you should be able to restructure your code so it is a lot simpler and easier to understand. When something goes wrong it will be easier to pinpoint the problem.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The main is electrically isolated using relay. What kind of safety danger can come beside malfunction?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Unfortunately I don't have oscilloscope and in cercuit debugger. The only trouble shooting I use is flashing led when the code enter somewhere.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, if you want to do a thorough analysis of this - those are the tools you're going to need.

 

Otherwise, as already suggested, just design the hardware properly so that you don't have this stuff to contend with!

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Inadequate clearance. The mains is full of transients which far exceed 220vac. Given the right conditions a spark will form and transfer dangerous voltages to your extra low voltage circuitry, potentially electrocuting someone or form an arc and cause a fire. If you look at any properley designed board using that style of relay, there will be slots in the pcb to ensure adequate clearance and creepage distances.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Okay thank you I understood.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Your relays probably aren't safety rated for 220VAC and most likely not mounted on your dot board.

The relay spec is for 220vac why it is not safe? And I dont get you what you mean by not mounted on your board. I have also issue on english language not only c language lol. Execuse me if I dont understand some sentence.

Kartman wrote:
You call functions with shared variable from timer isrs with no atomic protection.

I made every variables that is used in interrupt volatile. Is this acceptable?

Kartman wrote:
You only need one timer

Initially I was using one timer untill the problem appear. Then to correct the problem I used more timers assuming if one failed the other two may not. But as noted above the root cause is where all timers share that is probably the cpu clock.
Kartman wrote:
this means you can test this code on your PC

The codes run many cycle before it doubles the timer. If I test it, it run without error because no noise here or is there any means to inject noise in the simulation?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The relay spec is only one part of the puzzle. Different countries have different laws and requirements. What is acceptable in China may not be acceptable in Korea, USA, Europe etc.

Once you put that relay (or any other part) onto your board you are affecting the part's operation. Because your board does not have adequate insulation, you have compromised the relay specifications - the relay is no longer good for use at 220V.

 

 

'volatile' only forces the compiler to read/write the variable - it does not ensure atomicity. Remember - the timer isr can hit anywhere in your code. Whilst I have not looked extensively at your code, I see enough potential for problems.

 

You cannot simulate noise problems on a PC. You can simulate noise problems with with the actual hardware and instruments that generate ESD and fast transients.

 

Noise causes random faults with your AVR. As was suggested in #2, solve your hardware problems. There's a number of problems with your code. Get the basics correct first, then move forward. Trying to find the problems(s) in your existing code is a waste of time.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A few questions...

 

1) You appear to feed your incoming 5V to a pair of electrolytic capacitors and then to pin 10 (VCC) of the M32 via a diode?

 

2) You don't appear to have a connection to pin 31 (GND)?

 

I *could* sit here and try to draw a schematic of your board but that's really your job if you want help.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


On the subject of safety...

 

 

I think that the yellow highlight is your 12V rail and the red your mains.

 

There's not much gap between the two when you take into account the islands of copper.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The thing is a death trap........

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


To give the OP some idea of what a safe design looks like, here is a board I did a coupe of months ago. It too has mains relays on it. I've measured the clearance from the pads at mains potential to my 0V ground plane...

 

 

...and here's the whole of one side of the board. Note the 0V ground plane to keep ground currents where they should be.

 

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear Brian Fairchild and all I am so sorry and ashamed of myself for being late for my owm help. But I have reason 1. Me and my device are not fast on social media eg I was not able to use TAG and most importantly weak internet netwok. Anyways I have attached hand made schematics I dont have cad or pdf

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Answer for question#
1. The first big cap is intended for stablizing voltage dip that will be create by heavy dc hinge motor. The second 0.1uf is for filtering. The diode is to make sure the voltage is below 5v since 5v is the max for the mcu.
2. May be it is not vissible but the gnd of the mcu is connected to the supply and caps

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So the copper dot spacing is not enough to separate main from low voltage?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
volatile' only forces the compiler to read/write the variable - it does not ensure atomicity.

Can please give furthe explanation?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is amazing I will chake it physically

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

This thread worries me deeply. No one should be messing with mains design without formal training in the safety requirements. Googling around I see IEC-60950-1 mentioned a lot for example. 

 

While the IEC standards are charged for documents (which seems counter intuitive as common sense says they should be free for all who need their guidance) you can find interesting documents that summarise some aspects of safe design such as:

 

https://www.infineon.com/dgdl/Infineon-ApplicationNote_MOSFET_CoolMOS_Electrical_safety_and_Isolation-AN-v01_00-EN.pdf?fileId=db3a30433d1d0bbe013d20e0cbf017fe

 

While that is talking about how the safety standards impact the use of one manufactures specific devices I imagine there are many other application notes like this.

 

No one should be allowed near a design/implementation until they have at least a cursory understanding of such things. What you should never do is have an open sea of copper with mains connected to even a small part of it without it at least being encapsulated in a clear plastic enclosure. Suppose a colleague (or worse a child) happened to touch the "hot" parts of that while it was live !

 

This isn't a subject where you can have a cavalier attitude of "oh, it'll be all right - I know what I'm doing" (when you clearly don't).

 

In previous days there were organisations such as BEAB who would not allow a product to be sold without certification to show that the design adhered to all such mandated safety standards. These days there is CE testing/marking for the same kind of thing which harmonizes the safety concerns of all European regulatory authorities.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
These days there is CE testing/marking

trouble is, there is no requirement for testing these days.

 

sad surprise

 

Counterfeit electrical goods which clearly have never been anywhere near a test lab - or even a competent design review - are a big problem nowadays.

Especially on places like Amazon, ebay, Ali Express, etc ...

 

sad

 

eg, just the very first of a huge list on google:  https://www.electricalsafetyfirst.org.uk/media-centre/press-releases/2018/06/conline-18-million-brits-fall-victim-to-counterfeit-electrical-goods-online/

 

https://www.theguardian.com/technology/2018/jun/06/dangerous-fake-electrical-goods-sold-amazon-ebay-investigation

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

...Googling around I see IEC-60950-1 mentioned a lot for example. 

 

And if you search for "60950 pdf" who knows what you might find. wink

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Kartman wrote:

volatile' only forces the compiler to read/write the variable - it does not ensure atomicity.

Indeed.

 

 

Tinsae wrote:
Can please give furthe explanation?

Further explanation of what, exactly?

 

Recent discussion of 'volatile': 

 

https://www.avrfreaks.net/forum/why-volatile-variable-used-interrupt-service-routine - be sure to follow the link to clawson's tutorial!

 

Meaning of 'atomic':

 

https://preshing.com/20130618/atomic-vs-non-atomic-operations/

 

Importance of atomic operations:

 

https://en.wikipedia.org/wiki/Linearizability

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Fri. Feb 14, 2020 - 03:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That board was out of its cover to take pic. So it will be safe

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You haven't been paying attention, then!

 

Many of the concerns raised sill apply when it's in the box.

 

And it's going to have to come out of the box for programming, testing, debugging, etc - so it should still have a safety cover for those situations.

 

Again, if you look inside properly designed mains gear, you will see such "secondary" protection ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To re-iterate Andy - your board is not safe. Putting it in a box makes no difference. Stop and recognise the danger signs.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Concerning relays. I though them an isolation device but depending on their quality, okay they may not provide the intended isolation. Most of the time I check with mega ohms range if there is reading. So far I didnt found. I am not defending bad design but i want to know and feel the reasons if there is some one who can tell me what kind of relay failure/bad quality brings lethal electric shock to some one touching the DRIVE CIRCUIT(I dont mean shock like the one you receive when you touch tv antena or pc usb) which is supposed to be isolated.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tinsae wrote:
Concerning relays. I though them an isolation device

In themselves, they can be.

 

The concern here is not the relays themselves - it's how you've designed your PCB around them.

 

 

Most of the time I check with mega ohms range if there is reading. So far I didnt found.

Google the terms "creepage" and "clearance".

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you want to see a good quality design then look back at post #34 where I showed an example of one.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just replaced the control board in my stove, since the old control board had no core value, I took it apart to see if I could identify the root cause.  The control mpu was a pic 18f(something)!

What I found were several burnt bodyies (ants) between the two hot phases near the relays, and more between the relay contact points (HV 220v ac) and one of the relay coil pins (5vdc), this most likely was the cause of the LED display failures leading to the need for the replacement.  I wish I had known this before I replaced the module so I could have sprayed the board with some conformal coating to provide some insulation between the HV points and the LV coils.  I'll know next time it happens.   The clearance was enough to prevent flash over but not a short via ant body(s) as they tend to march in a line, the pcb had no solder mask or conformal coating.

 

Jim

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

Pages