Author Topic: Pi 3D printer low side switch -- protecting IO?  (Read 1127 times)

0 Members and 1 Guest are viewing this topic.

Offline microbugTopic starter

  • Frequent Contributor
  • **
  • Posts: 568
  • Country: gb
  • Electronics Enthusiast
Pi 3D printer low side switch -- protecting IO?
« on: August 29, 2020, 07:49:36 pm »
I'm using an N-channel MOSFET (IRL40B209) to turn my 3D printer on and off with a Raspberry Pi running Octoprint. The printer runs on 24V at up to 15A and the MOSFET switches the low side of the input to the printer mainboard (SKR Mini E3 V1.2 -- schematic. I'm connecting to RX2 and TX2.). The MOSFET gate is controlled by a GPIO pin that goes through a 3.3V to 5V logic shifter:

(BJT is a 2N3904).

This was all working fine, but when I connected the UART pins from the Pi to the printer board, the Pi got quite hot and died (red light but no green activity light, and nothing on HDMI). It's worth noting that Octoprint initialises the GPIO on startup so the UART pins were probably actively pulled low by the Pi.

My guess for the reason is that there are rail protection diodes inside the Pi's GPIO block and somehow the UART pins on the printer mainboard were connected to 24V when the board was off. The mainboard UART input goes straight into an STM32F103 on the mainboard (no external pull-ups). 3.3V is provided by an AS1117 powered from an AOZ1282 buck converter, which has a P-channel MOSFET inside it. Maybe the STM32F103 was sourcing 24V from its GPIO protection diodes and the Pi was getting it?

TLDR:
My Pi is dead. I have ordered two more. Is it worth persisting with this (e.g. putting 10k resistors on the UART lines to try and limit current, or any other suggestions you have) or is it just a bad idea all round to connect push pull GPIO to something powered from 24V while it's switched off low side?
 

Offline microbugTopic starter

  • Frequent Contributor
  • **
  • Posts: 568
  • Country: gb
  • Electronics Enthusiast
Re: Pi 3D printer low side switch -- protecting IO?
« Reply #1 on: August 29, 2020, 08:40:34 pm »
Doing some googling, perhaps I should just use a P-channel FET and switch it high side. I can use a resistor divider to keep Vgs from going too low.
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4857
  • Country: dk
Re: Pi 3D printer low side switch -- protecting IO?
« Reply #2 on: August 29, 2020, 10:14:16 pm »
use a relay on the high side instead
 

Offline MarkR42

  • Regular Contributor
  • *
  • Posts: 139
  • Country: gb
Re: Pi 3D printer low side switch -- protecting IO?
« Reply #3 on: August 29, 2020, 10:23:31 pm »
Yes, Raspberry Pi IO pins are not very tolerant of too many volts or other problems, you will probably kill the chip if anything isn't quite right.

Suggestions: I like the idea of a relay on the high side, but you will probably need a mosfet to drive the relay (switch the low side of that, of course)

Also remember (I've been got by this before) that there are a few IO pins on the Pi which pull high at boot, which can't be overridden, so don't use those.

As another option, consider a usb serial dongle instead of the Pi's built-in UART, it's more hardware but will probably be more electrically robust.
 

Offline Renate

  • Super Contributor
  • ***
  • Posts: 1460
  • Country: us
Re: Pi 3D printer low side switch -- protecting IO?
« Reply #4 on: August 29, 2020, 10:27:01 pm »
Yow! |O Switching low side!
If the power supply is grounded then when the low side switch is open then the "ground" (and various connections) out of the 3DP will be at +24V !
 

Offline microbugTopic starter

  • Frequent Contributor
  • **
  • Posts: 568
  • Country: gb
  • Electronics Enthusiast
Re: Pi 3D printer low side switch -- protecting IO?
« Reply #5 on: August 29, 2020, 11:34:02 pm »
Yow! |O Switching low side!
If the power supply is grounded then when the low side switch is open then the "ground" (and various connections) out of the 3DP will be at +24V !

Hmm. Yeah I didn't really think this through too well. The printer frame isn't actually grounded (anodised extrusions) but that's no excuse for leaving the board 0V at earth + 24V.

...
Also remember (I've been got by this before) that there are a few IO pins on the Pi which pull high at boot, which can't be overridden, so don't use those.
...

Wow, what kind of SoC pulls GPIO at boot rather than making them floating?! Thanks for telling me this, I did have the input connected to one that was high at boot so will now swap it. It's quite important for the system to fail safe as it's an additional layer of protection against the printer catching fire (as well as a convenient way to turn it on).

use a relay on the high side instead
I've now switched the circuit to a P-channel FET and NPN BJT that can pull it to Vin/2 through some resistors (I don't have a relay that can handle 15A max on hand, but I do have FETs). Tested ok with a dummy load, I'll see what it's like with a new Pi tomorrow but hopefully there shouldn't be any surprises.
 

Offline microbugTopic starter

  • Frequent Contributor
  • **
  • Posts: 568
  • Country: gb
  • Electronics Enthusiast
Re: Pi 3D printer low side switch -- protecting IO?
« Reply #6 on: August 30, 2020, 06:14:45 pm »
Update: all working nicely with the high side P-channel MOSFET. Luckily the printer's STM32 is not completely fried, just the serial port -- I can connect to it over USB instead.
 

Offline MarkR42

  • Regular Contributor
  • *
  • Posts: 139
  • Country: gb
Re: Pi 3D printer low side switch -- protecting IO?
« Reply #7 on: September 02, 2020, 08:39:24 am »
Wow, what kind of SoC pulls GPIO at boot rather than making them floating?!

The RaspberryPI SoC.

As I understood it, those pins are used for some signals which can be optionally used to boot the chip, SPI or something, they have to pull high to work correctly at boot time. Because they are set at boot time inside the hardware itself, nothing in the software can change them, even setting low inside the bootloader (a config.txt command can set the pin low) will cause the pin to stay high for ~ 1 second after power on.

Only some of the pins pull high at boot (most do not), they are documented but it is not widely known. All of them are configurable to stop the "pull high"; you could also use a resistor to pull them low more strongly (e.g. 10k would be ok I think), as the pull is not very "strong".

The document "BCM2835 Peripherals" contains a table which shows which gpios pull low/high at boot.

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf