1
\$\begingroup\$

I have a PCB that is getting powered from mains and is connected to a Hi Link component (HLK-5M05 with 5V output). At the moment it is connected to an extensions with a button, a little bit like this one. When I power it on and start measuring I get the 5V output, 3v3 output, I can see that some components are working accordingly (voltage monitor) and then I went to load my firmware into the st microcontroller.

I disconnected eveything since I don't want to accidentally get shocked, I connect all the pins (gnd to gnd, 3v3 to Vapp, TMS -> TMS, etc). After I connected this I connected the board to the extension and turned on the button. Immediately I heard a loud noise and I noticed the st link wasn't ON anymore (a capacitor exploded) and the circuit breaker activated. Then I went to measure the board and I notice that there is a3v3 short to ground.

I have revised my entire layout and there is no connection between mains and GND in my circuit. The closest to it is the analog circuitry for measuring the voltage, but still, they are not connected. From what I can see everything is connected as it should be according to datasheets, but it still didn't work.

After that I tried connecting and programming my board via the bootloader. I did the required connections and tested my board and everything was working properly. Again I disconnected everything and connected the USB-serial board to my board (GND, TX and RX ... very simple and straight forward). When I connected everything the circuit breaker still activated but fortunately this time it didn't destroy my PCB.

Very distraught I turned off the button and went to disconnect the USB-serial board and got shocked. After that I measured the voltage between the USB connector and my PCB ground and there was 220Vac ... when the extension was turned off and the extension is not grounded (not USA .. incompatibility between different types of plugs ... old everything), but there is 0V when I measure the voltage between them when the extension is powered on.

What could I be doing wrong? I measured other devices (USB chargers and similar) and they all had the same behaviour ... 0V when ON and 220V when OFF. I have compared my schematic to others, such as open energy monitor and many other projects you can find online and I'm not doing anything crazy here (in terms of schematics and connections). Could there be something wrong with my installation? Or is it a PEBKAC (more like between PCB and chair [PEBPAC])?

EDIT: Adding schematics, just the important part, the rest is all decoupling capacitors, oscillators, etc. enter image description here

\$\endgroup\$
  • 1
    \$\begingroup\$ Use a lab power supply when programming. And get an isolation transformer before you kill yourself. \$\endgroup\$ – alex.forencich Jan 11 '18 at 22:59
  • \$\begingroup\$ And you're not going to get any useful advice from anyone until you post pictures and schematics. \$\endgroup\$ – alex.forencich Jan 11 '18 at 23:00
  • \$\begingroup\$ Also, you could have a hot/neutral mix-up somewhere causing your plug strip to only interrupt the neutral connection. \$\endgroup\$ – alex.forencich Jan 11 '18 at 23:16
  • \$\begingroup\$ You say the extension is not grounded. That means it has a reversible plug on it, right? When you plug it in there's a 50% chance that hot goes to neutral and neutral goes to hot. The switch will be in one of those wires but you don't know which. (I sure hope the extension has ungrounded sockets because otherwise that is a disaster waiting to happen when you plug in a grounded device!) \$\endgroup\$ – immibis Jan 12 '18 at 0:14
  • \$\begingroup\$ @alex.forencich Thank you for your advice, but I'm not afraid of death (just kidding .. very afraid (it's just difficult for me to get many tools), that's why I was disconnecting everything before even touching the board, the problem is that I got shocked when the extension was OFF ... and for some reason the JTAG got destroyed when I joined both GNDs) \$\endgroup\$ – morcillo Jan 12 '18 at 0:19
2
\$\begingroup\$

The accidental mains-earth short. Don't we all make those one day.

  1. You switched extension cord probably only switches one line.
    That way you do not know whether it switched Line of Neutral unless you explicitly measure it relative to mains earth.
    I'd recommend getting an isolator switch, an appropriate contactor, or just unplug.
    Relays don't have enough distance and might get stuck on faults.

  2. Your circuit does have a path from mains to earth when you connect the programmer. But we don't know the impedance of this connection.
    Inside your PC the USB GND is connected to mains earth, and that's what has blown your ST Link.

enter image description here

The slightest current this way may upset power supplies. Or blow inputs if you do not connect ground first. Which is why typical connectors always connect ground first. eg: USB, HDMI, VGA, DVI, SATA, PCI. Except audio, which you've probably noticed one day will create a loud humm when not inserted correctly yet.

I'd recommend getting an ST-LINK/V2-ISOL if you plan to work with circuit like this further. But beware, your oscilloscope has the same problem! You can use a differential probe with your scope.

Or buy an isolation transformer, that would remove the sparks on a fault. But can still result in strange behavior and shock hazards with a fault.

In the future, be aware of what potentials you connect.


In a comment you state that resistors r4, r5 and r6 are 200k and r7, r8, r9 are 820 Ohm. This means there was a short trough r7,r8 and r9 to earth.
I'd recommend making these two resistor strings identical:

schematic

simulate this circuit – Schematic created using CircuitLab

But you will have to take common mode noise into account.

\$\endgroup\$
  • \$\begingroup\$ @ Yeap ... it was inverted. The tools I have to work with are ... rudimentary at best. After a night of sleep I noticed that I might be connecting to live instead of neutral. I switched the plug today (literally turned it 180° and connected it again) and the 220V AC disappeared. My problem now is that there is a DC voltage between the USB ground and my ground, which does not let me program mi microcontroller since it has 1V signals (measuring from the PCB gnd to the signal). Also resistors r4, r5 and r6 are 200k and r7, r8, r9 are 820 \$\endgroup\$ – morcillo Jan 12 '18 at 16:01
  • \$\begingroup\$ I also connected a 60v capacitor from N to 0V, because my signal wasn't good enough and after that it got much better, a very pretty sine wave \$\endgroup\$ – morcillo Jan 12 '18 at 16:03
  • \$\begingroup\$ @morcillo I don't get what you're doing with the 1Vdc GND-EARTH. That is normal. Also the capacitor I do not follow. You need to take a step away and draw up the full schematics of what you're hooking up before continuing. \$\endgroup\$ – Jeroen3 Jan 13 '18 at 16:41
  • \$\begingroup\$ I ended up removing it, so what I have is what you can see in the schematic I provided. And I meant to say 3V instead of one .. it was a typo. I'm afraid I won't be able to program my microcontroller because the JTAG signals will be different to what the microcontroller is seing and then not being able to load my firmware \$\endgroup\$ – morcillo Jan 13 '18 at 17:03
  • \$\begingroup\$ I was hoping that this could have a simpler solution, but apparently I'll have to cut a lot of wires in my board in order to have a usable board. At the moment I wired up 5Vdc to my board and am now able to remove the 3Vdc GND-EARTH, so I think I'll be able to program my board (hopefully .. waiting for the new st link I bought). The way that it is now, I can connect my board to mains and get a pretty good AC signal for my ADC ... I was really hoping that I could fix this with just few mods, but apparently a redesign is in order?? \$\endgroup\$ – morcillo Jan 13 '18 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.