Microcontroller 12v bulb check - Page 1
Forum section: electronics / projects

author: lolimpol
author_rank: Contributor
timestamp: October 17, 2022, 09:54:41 pm
content: I've been racking my brain over the best way to do this for a few days now, and you guys are a lot smarter than me, here's the situation:Backstory:We converted our car to electric, a 24V Nissan Patrol. We decided to switch to 12V due to ease of sourcing components.Now the harnass is all still the 24v wires which means, double the current through said wires. Eventhough I'm sure the super rugged and overbuilt Nissan could handle it, I think a CAN bus conversion would be fun, and useful for checking the bulbs on our terrible trailers.I came up with:A custom PCB with some microcontroller (probably STM32 or Atmega32u4 or something similar)17 MOSFETs (4 for left, 4 for right and 5 for trailer, I chose 1 per bulb for future flexibility/fun animations etc)And some sort of resistance or current measurement to notify the driver of any broken bulbs.In the spirit of the vehicle being a Patrol, I want to do this as foolproof as possible (I primarily have overvoltage and over current scenario's in my mind), but still as simple as possible (price isn't as big of a concern within reasonable limits). So in the spirit of that I sourced an aluminium ECU type case with some fake ampseal connectors I can use to wire up every light and the trailer plug.(I thought giving as much information as possible would be helpful in case I'm overseeing something huge here)TL;DRI have a MOSFET controlling a lightbulb, and I want to be able to detect if said lightbulb goes out, in the most unbreakable way possible.Thanks!

author: pqass
author_rank: Super Contributor
timestamp: October 17, 2022, 10:29:47 pm
content: Add a 1R or 0R5 sense resistor to each MOSFET source pin. Then measure its voltage drop through a mux to an ADC or comparator. Choose resistor based on load expected. See attachment.Assuming 1.1V Vref for the ADC, a 1R sense resistor will measure up to 1A (using an 8W bulb on a 12V battery). Zener protection assumes 5V MPU.Play with it here:http://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWEAmB0FksgHGAbAOyRHLKR4gKSWXUICmAtGGAFABmIAzGSghQBZ8fCj3Doo0AJyoZCOQtTZWAJxBCKyAsnXCuCHdTYBzXaINnuebFCiruvVJoHUntzJFYAZFC5HgZfyMQdgBDABsAZ3pwak8wXEtkPw1wAQFbZDwBKWhSSC4wWWxsKTACEBsiyUgMmFrWACVLKUFhbNtqP2q4yQRWLiIWtoowdPBO1gB3SmqtHXkdebsAB0pA5cXuCwg41lMt-QXArmtJtVTNue13eAGMgC96ADt6FUYBaC4JsGgCMaOuBkuHgyCYFVcsHg0JhkGwGU+3zYD1mOiOqJQNx0T1e70R+wx6IwaLOexmW2WeH4mMMrAAHiBCEsCBQCH4tFJ1OAbAAVAD2AB1IgBZACqAA16ZQstwxpQ8KJylyEuovgA1KWFKpSGxcAQ2MgQDIq7AAdVYawEHTGCI6yWCZPU1vGqRtdhmVoy9qSfk8QAEDIT: Updated attachment and simulator link for 12V

author: lolimpol
author_rank: Contributor
timestamp: October 17, 2022, 10:39:19 pm
content: So like a shunt? I looked into this, but shunts for 7-10a are far from SMD or even PCB mountable at all, which is why I started thinking more in a resistance measurement while the light is off for example.Also the system is 12v right now, and will stay so.Thanks for the reply!

author: pqass
author_rank: Super Contributor
timestamp: October 17, 2022, 11:16:31 pm
content: @10A, you could go with 0R1/10W or 0R05/5W see below:https://www.digikey.ca/en/products/filter/chip-resistor-surface-mount/52?s=N4IgjCBcoExaBjKAzAhgGwM4FMA0IB7KAbRBgBYBOANgpHxgA4wBmRufAdnM4AZqQAXXwAHAC5QQAZTEAnAJYA7AOYgAvvhbwQSSGix5CJMgFZeW-GGqNy9cKwj5KnAcJDjJMhSvUNejE21dfRx8IkhSMwACAFsAeQALGMw7MF5eWMTkoVEJSBAAVUV5MTjkAFlsVEwAV1lsXxAAWjhoHSg5GsNwyKE1DRABNvkAE0kmtMd3PJA7AEcxAE9JGF47JZEG-OqkfqA

author: james_s
author_rank: Super Contributor
timestamp: October 18, 2022, 12:42:53 am
content: You could use a Hall based current sense IC, they're a lot more efficient for measuring currents in that range and will result in less drop and a lot less heat.

author: pqass
author_rank: Super Contributor
timestamp: October 18, 2022, 01:04:15 am
content: I forgot about the  nature of auto electrics - everything is grounded directly to the chassis at the load. So you're probably going to have to go with P-MOSFETs and high-side current sensing instead.See attachment.Note: I tried to scale down (by a third; or 4k7/(4k7+10k)) all sensed voltages through the MUX and opamps (to keep them below 5V) but not sure why scaling up in the diff-amp was it neccessary to use a different factor (3k3/(3k3+10k)). Oh well, software will smooth all the rough edges.http://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWEAmB0FksgHGAbAOyRHLKR4gKSWXUICmAtGGAFABOIAzHtiMzm69+AFj7U2AcyF8wgnrJEioUDigLJ+XTWACcmxtpWZIrADIg8y5hXz87EkADMAhgBsAzvRqmwuGeDywkbUyHgIXNC6kNgiOFxYkFwiXCCymjCQypkirABKAQJ8CvZ41OUgIhIZKjAIrFxEhXYlRhDlrAAOlXZFPRSMYuC1rADulggDQxrUg+KsAB4gBEaDSNhwoprKfiAAKgD2ADoeALIAqgAai+rU2BQJd7qV4HzYAOpd-dzbdnKyI3GIhamlaGTG33+AShpic6gMRhKhlBqTA6CgUVQ+gQ2Nxaj0CJ0+nsggk8FM4wJJOKwj6pgALoE+DZwMSWY4YHhtLoNkocVy5MhUpyECk9LxsNE9LoRM8TCAACb0VwAVzc9NY0ipEmJDlUnChLKspWM8AhwKmNOZQwp3z6SJhN10ED+K1ZL125zMADkyEkblx-CyIqlmKkdnwAGqSDwnAC2LgWRwAjkdOgB6RhkSNqC2iPg4gw28DktSF-OUYkhSpEUzSctGcvF23hS2VovzJYrCDIAjKbDIZS9ggevgAMXYBzjJwu1yBvShousjvGS+plCUKGw804a5wBc3JTJZt3h+Ea6U4hrcE1G+Ul7vlWNHXG++4CE0b+0L4mbdb8NUbpdAeLIQGA7hYmGDppHAwNlHAqoKlMTg31QWwCAoNDTTNFwt2KUCwAw7hQILbDyRQaBtxEAgCHwMRyDwXQEiQZBKNiAgP2wGi9BYZ0dnJW1UMmPCRNtQjMOE8TiOyVhcIwUEP0qTYuEU0jj3IyJsB4DQwG0PB9LibAkE07TkkYwMaIQDBUQE81lMUxDpNUIFlNA+SnNtdyEmULyeGcyg5ACNcjwhdze00f9wv8sKYgCz8qn8xyyALQLksSzYsKS2LTDk1LhKS4S1JLATuGgAU-AwZ0uDAYFZVK8rgKoar9PIUhipPJTQmEoSKGoLhHlzezP23d8an6m8UJGlSdCI6ayLrcBZsUqSj382CCNm0CW26jRljIADTCWKykEYLjf34LlRxAABlABjdx6BOBUDlGAA7I4jlepwDnYGcrhufSKCaDYRxYJAIxAd4AEt2EejxYc6WGvFe+lY0+26Dle176Fu+kocxj6UYAC0nFVJCJv7riWPwR1qgIUj4CGAHlXrcABPE5MbhhUoacJxGBcONOkJlwnHpehfrOK4Tih2MPGx+glQVG4cWeaqICMhSKGZ1mOY8DwodeyQ3DhhBIxOToXolk4PBVTpOnZwmPCJg41QVE4ACM4YVpWTm+yXZxF173Y8A5OkFzoPFYIA

author: pcprogrammer
author_rank: Super Contributor
timestamp: October 18, 2022, 06:03:30 am
content: Don't forget that in a car with a combustion engine 12V is not a steady 12V. When the motor is running the alternator will ramp up the voltage to possibly over 14V.QuoteBut if the above means you turned the car into an electrically propelled vehicle using an electric motor then it might be a different story

author: james_s
author_rank: Super Contributor
timestamp: October 18, 2022, 06:18:48 am
content: You can do all of this easily with a single IC per channel. Isolated so it doesn't matter if it's high side or low side, very low resistance so it runs cool and drops very little voltage, robust and easy to work with, works over a wide range of voltage, just hook it up and get an analog output proportional to the current flowing through. Here's the sort of thing I'm talking about.https://docs.broadcom.com/doc/ACHS-712x-DS

author: lolimpol
author_rank: Contributor
timestamp: October 18, 2022, 07:53:15 am
content: This is a lot more like it, but very complicated, some others mentioned the hall effect current sensors, they seem a lot simpler

author: lolimpol
author_rank: Contributor
timestamp: October 18, 2022, 07:54:58 am
content: This is true, and yes we have a DC-DC converter which essentially provides 14v ish when running, this is why I said I want it to be as foolproof as possible.If we ever sell this thing, it is guaranteed to go to some hillbilly offroad fan, and I KNOW that he is not going to take care to protect any sensitive circuitry lol

author: lolimpol
author_rank: Contributor
timestamp: October 18, 2022, 07:56:32 am
content: I think this is the ticket, I'll just have to look at some magnetic field protection for them. Seeing as they can handle a lot more current and voltage, someone could really screw up bad in the electrical system, and all would be well with the board

author: pqass
author_rank: Super Contributor
timestamp: October 18, 2022, 01:09:00 pm
content: Don't forget about price...Shunt: 0R1/10W (WSHP2818R1000FEA) is €1.3648 (qty25)Hall-effect sensor: 100mV/A (ACHS-7122-000E) is €3.118 (qty25) but no stock at digikey.nlHall-effect sensor: 100mV/A (TMCS1108A2BQDR) is €1.9696 (qty25)The only additional parts for the shunt implementation is a single Instrumentation amp (likeINA350CDSIDDFR €0.68MCP6N11-100E/SN €1.84; replacing buffer-amps+diff-amp+resistors) and shunt scale-down resistors (4k7+10k). Both implementations need the P-MOSFETs, their drivers (ULN2003ADR2G €0.78), and MUXes (74HC4051D,653 €0.50)All parts+prices are for eaches at digikey.nl

author: james_s
author_rank: Super Contributor
timestamp: October 18, 2022, 03:32:47 pm
content: Who cares about price? This is a one-off project, and you're not factoring in the time required to build some other solution. If the sensor ICs cost $50 instead of $5 I might try to find something else, but in this case it's cheap.

author: lolimpol
author_rank: Contributor
timestamp: October 18, 2022, 04:20:28 pm
content: Exactly this, the whole restauration + electrification was €40k so I simply just want the best available. Also I could potentially multiplex it to use one current ic maybe?

author: pcprogrammer
author_rank: Super Contributor
timestamp: October 18, 2022, 04:44:04 pm
content: Pictures of the conversion would be interestingMultiplexing the lamp driving signals would mean time multiplexing them being on and off to be able to use just a single current sensing IC. Most likely easier to get the 17 you need and either use a MCU with sufficient analog inputs or get a couple of 4051's to multiplex the analog signals before the MCU.

author: Zero999
author_rank: Super Contributor
timestamp: October 18, 2022, 04:59:34 pm
content: Measure the voltage across the MOSFET. It should be equal to 12V, when off and close to, but not quire zero, when on. An estimate of the voltage when on can be gained by multiplying the bulb current, by the drain resistance.Why not use LEDs anyway?