Announcement

Collapse
No announcement yet.

Running a microcontroller in car - power supply aspects

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Running a microcontroller in car - power supply aspects

    Good day folks. Some of you may know that a while back I was messing around with a little Arduino Mini and made up a little circuit to automatically roll my car windows up and down and all that jazz...not important right now. The project is built and runs as it should on a breadboard on the bench, so I thought before transferring it to a perfboard and shrinking it down, I should go over the power supply section and how I'm going to power this thing, since the electrical environment of a car is not the same thing as on the bench with a wall wart and there could be some problems down the line which I may have overlooked. I may have actually gone overboard with the power section and wanting to make it as bulletproof as possible, it probably had the opposite effect and I gravitated away from electronics industry standards and made it more complicated and inefficient if anything. This apparent complexity may not necessarily result in a better electrical environment for the micro itself...

    There's a diagram attached and it's a bit of a mess, so please bare with us

    1) it's powered all the time, so I'll wire it straight off the battery.

    2) the top branch which goes through F1 is straight off the car's system - no regulation at all - so it can be anywhere between 11v and 14v (and probably more due to inductive spikes ! !). The reason for this is because those switches (S1-S4) are actually the rocker switches for the power windows and they're already wired in to the car, so I want to keep this as PnP as possible and not alter the existing harness, so rather than implementing my own step-down circuit here as well, I'm doing it this way: the voltage present at those switches goes through R1-R4 when the switch is pressed, to the 5.1v zeners Z1-Z4 (just noticed ZD would be the correct notation for those, but anyway) and to the anodes of optoisolators PC1-PC4 respectively. This pulls the collector low which in turns pulls pins A-D low and the micro know what button was pressed. There's two windows and 2 directions (UP/DOWN), so 4 sets of each. Hope this makes sense. I only drew 2 of the pins, and added "tags" for the other two. Also, the H-bridge which will be used to actually drive the motors is not pictured ! This setup is perfectly functional on the breadboard right now as it is.

    3) to power the micro itself I send "V-BAT", let's call it, though a DC-DC step-down buck converter which drops it to around 6v and then did something which you probably shouldn't/don't need to do and send that through a resistor+zener combo AFTER the buck converter itself, the thinking behind this being that if the buck converter overshoots or shorts out for any reason, the linear zener regulator would still prevent V-BAT from shooting straight into the micro and killing it...THIS is probably the most "incorrect" part of this whole setup, despite being functional. It's worth mentioning that I'm powering the Arduino Mini straight via the VCC pin and not using the on-board regulator via the RAW pin. In fact, I removed the regulator from the board entirely. Maximum energy conservation is also important.

    4) values for the components:
    • C1-C4 are 100nF ceramic caps
    • C5 is a 10uF tantalum
    • R1-R4 are 1k
    • R5-R8 are 10k pull-up resistors
    • R9 is 82R
    • D1 and D2 are UF5408 Schotkkys


    That's it for now Let me know what you think and what should be improved. Thanks.
    Attached Files
    Wattevah...

    #2
    Re: Running a microcontroller in car - power supply aspects

    Honestly, what you are planning sounds pretty good. If you were worried about power spikes, you could probably improve things by putting in some additional filtering at the source, like a 25v 100uf and then an inductor, but that would probably REALLY overkill. (Especially if the MCU is a mini, which can already handle up to 12v.)

    Probably, if it were me, I'd just go with what you've written out and then add additional filtering later if it becomes a problem. Though, I'm just a hobbyist too, so a pro might come by and make me feel quite foolish. lol

    ---

    A question on the Schematic. On those optocouplers, were you meaning to draw this (or I might be misreading) with the "transistor" side bypassing the switch? Then were you thinking of turning on the optocopular using the io from your mcu? At the moment I'm reading the schematic like you are wanting to be able to send an output to the mcu when you press the switches on your car's panel. I could be understanding things a bit wrong though.
    Last edited by Retro-Hipster; 05-01-2019, 01:20 PM. Reason: I misread something on the schematic..


    “Men always seem to think about their
    past before they die, as though they were
    frantically searching for proof that they
    truly lived.”
    – Jet (Cowboy Bebop) -

    Comment


      #3
      Re: Running a microcontroller in car - power supply aspects

      Originally posted by Retro-Hipster View Post
      A question on the Schematic. On those optocouplers, were you meaning to draw this (or I might be misreading) with the "transistor" side bypassing the switch? Then were you thinking of turning on the optocopular using the io from your mcu? At the moment I'm reading the schematic like you are wanting to be able to send an output to the mcu when you press the switches on your car's panel.
      Correct: those switches are just a schematic representation of the 2 switches for the windows. Each has two possible states: UP and DOWN, obviously. Let's say S1 is UP for the left window and S2 is DOWN for the left window. When the switch is closed, the linear zener regulator becomes active and the LED in the optoisolator is turned on. The transistor is thus turned on and the I/O pin is pulled low. When the switch is released, the LED "dies", the C-E junction becomes resistive and the pin is pulled back to a HIGH state via the 10k resistor. Hope that clears it.

      Yes, some caps on the input would be advisable, though I'm a bit nervous about placing them directly across the car's battery, since that's essentially where power is coming from - nothing between.

      Inductors: don't know too much about these TBH, so I don't know what parameters they have or what I should look out for. I know they have an inductance rating, but do they also have voltage/current ratings ? Is there a rule of thumb for the inductors like "bigger is better" or are certain values better suited for specific applications ?
      Wattevah...

      Comment


        #4
        Re: Running a microcontroller in car - power supply aspects

        Oh, you could definitely place the caps I meantioned after the fuse and such. I just meant you could put a fairly beefy cap on the input to help with voltage spikes since capacitors resist changes to voltage. In terms of filter inductors, that really probably be a waste of inductors unless you wanted to smooth out the current capabilities of your power source. You would likely want to put a snubber diode across the inductor if you did put one in as well. without one you could fry the buck converter when you unplugged it from it's power source.

        In reality, most of the time it is better in DC circuits to just use a capacitor for smoothing and then a zener after to clamp down any voltage spikes that may get through (ie: a 16v zener), if I am not mistaken. You could put those two things after the fuse and just place an appropriately rated NTC Thermistor between the fuse and the capacitor. That way you wouldn't blow the fuse/damage anything when you plugged things in.

        So you could do something like...

        12-15v in > fuse > thermistor > Capacitor> Zener> Buck Converter>etc..
        Last edited by Retro-Hipster; 05-01-2019, 05:11 PM.


        “Men always seem to think about their
        past before they die, as though they were
        frantically searching for proof that they
        truly lived.”
        – Jet (Cowboy Bebop) -

        Comment


          #5
          Re: Running a microcontroller in car - power supply aspects

          TVS:https://cdn.badcaps-static.com/pdfs/...325913767f.pdf

          Inductor in Automotive system:
          https://industrial.panasonic.com/kr/...tive-inductors
          https://industrial.panasonic.com/kr/...rs/application

          You may need LC filter so your DC-DC converter will not dump the switching noise into the car system.
          Last edited by budm; 05-01-2019, 11:52 PM.
          Never stop learning
          Basic LCD TV and Monitor troubleshooting guides.
          http://www.badcaps.net/forum/showthr...956#post305956

          Voltage Regulator (LDO) testing:
          http://www.badcaps.net/forum/showthr...999#post300999

          Inverter testing using old CFL:
          http://www.badcaps.net/forum/showthr...er+testing+cfl

          Tear down pictures : Hit the ">" Show Albums and stories" on the left side
          http://s807.photobucket.com/user/budm/library/

          TV Factory reset codes listing:
          http://www.badcaps.net/forum/showthread.php?t=24809

          Comment


            #6
            Re: Running a microcontroller in car - power supply aspects

            Just realized I made a little f-up in my diagram and should also explain in more detail how those switches actually work, since it may be confusing to some: the 4 switches in my diagram are just schematic representations of the actual rocker switches on the dash. Notice I added L and R for the two sets. In reality, there's 2 rocker switches (one for each window) and each of them has two "poles" which are pulled to either VCC or GND depending in which position they're "rocked".

            This diagram explains it: when "resting", both poles (1 and 2) are grounded. When rocked to either side, one is pulled to VCC while the other one continues to stay grounded. In my case, imagine pole 1 of the switch in the diagram goes to the linear regulator formed by R1 and ZD1 and pole 2 goes to R2+ZD2. What happens is when the switch is pushed in the "down" position, R2+ZD2+PC2 become active and the micro's A pin is pulled low, telling it to do.....something, doesn't matter. Likewise, when pushed into the "up" postion, R1+ZD1+PC1 become active and pin B is pulled low. I don't think there's any problem with the linear regulator staying grounded when not in use, since (if you had your thinking cap on) you'll notice all 4 resistors remain grounded when the switch is resting, or at least one of the poles will always be at GND.

            The way I tap into this is I cut the two wires currently going from the switch to the motor (from pins 1 and 2) and I'll solder matching male-female XT60 connectors to both the switch side and the motor side of the resulting wires. The "control" input of my control box will also get an XT60 connector that accepts the one coming from the rocker. The output of the H-bridge will get one that matches the one going to the motor. The reason I'm doing it like this is to allow me to quickly revert back to the stock setup if something goes wrong, by removing the box entirely and plugging the switches right back into the motors as they were, since the XT60 connectors will not only match the box but each other as well.

            Now, F1 and D1 will not be there, since that part (before the rockers) is already present in the car and will not be messed with. What I have access to is the "outputs" of those rocker switches, so I'll only be able to tap into where the "poles" of the switches are. The correct diagram would look like THIS then (can't get the damn lighting to look any better ).


            Also, you're saying I should drop choke L1 in series with the buck converter like that ? Also remembered what you said about the caps on the input of the buck converter, but I had already snapped the pictures, so let's assume there's a cap after L1
            Attached Files
            Last edited by Dannyx; 05-02-2019, 10:38 AM.
            Wattevah...

            Comment


              #7
              Re: Running a microcontroller in car - power supply aspects

              Consider this for the window switches. You do not need protection zeners or diodes because one opto protects the other against reverse spikes, and +ve spikes get current-limited by the resistor. Even a 100V spike is about 50mA for the LED- which it can take.

              What is the 5V DC-DC converter, how many volts is max. input?
              I use a 27V TVS (1,500W to 6,600W) at the input to limit +ve spikes to ~40V like 1.5KE27A or larger. I would have it for D1 instead of UF5408.
              Attached Files

              Comment


                #8
                Re: Running a microcontroller in car - power supply aspects

                Originally posted by redwire View Post
                Consider this for the window switches. You do not need protection zeners or diodes because one opto protects the other against reverse spikes, and +ve spikes get current-limited by the resistor. Even a 100V spike is about 50mA for the LED- which it can take.

                What is the 5V DC-DC converter, how many volts is max. input?
                I use a 27V TVS (1,500W to 6,600W) at the input to limit +ve spikes to ~40V like 1.5KE27A or larger. I would have it for D1 instead of UF5408.
                That's the sort of stuff which I may have overdid like I said. I COULD'VE probably got away with a single resistor in series with the LED of the optoisolators just like you suggested and I actually went with that for quite some time, but just to make sure I later added a zener in there as well. I suppose to cut down on the space and part count, I could go down your route too.

                Also, slight error in the layout of the switch there - the dotted line connecting the two contact plates should not be there, as only ONE pole moves at a time, whereas the line would indicate both move at once...probably a limitation of the software you used to make the diagram....which I find very nice actually and I'd like to know what it is, so I'd stop using pen and paper
                Wattevah...

                Comment


                  #9
                  Re: Running a microcontroller in car - power supply aspects

                  This is what I use in cars. For me it's quicker to draw it in KiCad or Altium we use at work. A pencil is more powerful but taking pictures of paper sucks.

                  If you use an large inductor to filter out ignition and fuel pump EMI, it can add to a spike sometimes and make them worse. So you have to be careful. If I have room I add 100uH-1mH with a diode across it, instead of ferrite bead.

                  Your 5V regulator needs to take ~30-40V input max. and 6V min. or else the Arduino will reboot when you start the car, cranking gives low voltage.
                  I think an Arduino Nano needs around 20mA. I use an LDO LP2950 to power it and a sleep command to go down to a few mA.

                  I can explain each part if you want to make sense of it.
                  Attached Files

                  Comment


                    #10
                    Re: Running a microcontroller in car - power supply aspects

                    Originally posted by redwire View Post
                    If I have room I add 100uH-1mH with a diode across it, instead of ferrite bead.
                    So I should have the diode reverse-biased across the coil and place this setup in series with the input to the regulator ? What diode should this be ? A regular 1n4007 or an UF one ?

                    The DC-DC converter can take 32v max apparently.
                    Last edited by Dannyx; 05-02-2019, 12:25 PM.
                    Wattevah...

                    Comment


                      #11
                      Re: Running a microcontroller in car - power supply aspects

                      I know adding a filter inductor is a good idea but it added new problems.
                      The inductor back-emf can make a spike worse, so they add a diode across it. This is the circuit I remember. I will check with the people I know that design automotive ECU's.

                      Are you sure the LM2596 can run off your car battery? I thought it uses a lot of current, and more with an Arduino running. You should measure it, or run it off IGN power.
                      Attached Files

                      Comment


                        #12
                        Re: Running a microcontroller in car - power supply aspects

                        Originally posted by redwire View Post
                        Are you sure the LM2596 can run off your car battery? I thought it uses a lot of current, and more with an Arduino running. You should measure it, or run it off IGN power.
                        I did measure the overall power consumption since it IS important indeed - don't want to wake up to a flat battery one day, but I can't remember precisely what this was. I THINK like 30mA or something total...

                        Can't run off accessory power, since the thing needs to be on standby all the time - I added a feature to roll up the windows when the car is locked with the key fob, so the ignition would be off at that point.
                        Wattevah...

                        Comment


                          #13
                          Re: Running a microcontroller in car - power supply aspects

                          Also, why 470uH on the coil there ? Forgot to ask. How would one determine the value of the inductor in such a circuit ?
                          Wattevah...

                          Comment


                            #14
                            Re: Running a microcontroller in car - power supply aspects

                            I might be wrong but, in a fairly clean dc to dc source, you are mainly going to be choosing an inductor based on the dc resistance the inductor poses and the potential peak current spikes from the source. Essentially, if you don't have visible/measurable switching noise on the dc output on the car, then doing frequency calculations doesn't really work. With that, the main focus would be "how much current will it take to drive the core into saturation?" and "how hot will this inductor get due to it's dc resistance"? You can get both of these statistics from Datasheets and, in this case, would want an inductor with a higher saturation current than what your circuit is going to be using and to know that the total watts that the inductor dissipates would be within tolerable range for the inductor.

                            I THINK I'm right on this, but I really really need to brush up on inductors/the math needed to do calculations.
                            Last edited by Retro-Hipster; 05-10-2019, 12:15 PM.


                            “Men always seem to think about their
                            past before they die, as though they were
                            frantically searching for proof that they
                            truly lived.”
                            – Jet (Cowboy Bebop) -

                            Comment


                              #15
                              Re: Running a microcontroller in car - power supply aspects

                              Not sure how much ripple/noise a car has on its battery when running. I plan to run wires straight from the battery terminals to run this thing (quite a lot of current required for the power windows), so there's going to be no filtering whatsoever there - what's present at the battery will immediately show up at the input to my circuit exactly.
                              Wattevah...

                              Comment


                                #16
                                Re: Running a microcontroller in car - power supply aspects

                                Originally posted by Dannyx View Post
                                Not sure how much ripple/noise a car has on its battery when running. I plan to run wires straight from the battery terminals to run this thing (quite a lot of current required for the power windows), so there's going to be no filtering whatsoever there - what's present at the battery will immediately show up at the input to my circuit exactly.
                                You're assuming your circuit represents a high enough impedance that it doesn't factor into the distribution characteristics of the "signal" from the battery.

                                You're also assuming that the battery's output impedance is low enough that "loads" (yours and others) won't affect what you see on it's terminals.

                                Note that even the resistance between the binding post and the cable clamp can be "significant" in terms of other aspects of the "system" (assuming you aren't drilling into the binding post to secure "your" connection, upstream of the cable clamp).

                                [I.e., all resistances between the battery and the loads in question appear as parts of the battery's output impedance]

                                Comment


                                  #17
                                  Re: Running a microcontroller in car - power supply aspects

                                  Another idea came to mind, which I've seen on wires and circuits before but don't know for sure how to correctly choose it or IF it should be used at all in my scenario at all: how about a common-mode choke ? Two things come to MY mind when I hear the term: a ferrite ring which has the + and - wires going to the circuit wrapped through it AND the more "advanced" version which already has copper wires properly arranged on it and comes as a standalone device which all SMPSs have on their AC mains inputs. How's that ?
                                  Wattevah...

                                  Comment


                                    #18
                                    Re: Running a microcontroller in car - power supply aspects

                                    If you put a scope on a car's 12V power, there is a lot of low frequency noise from the ignition system, fuel injectors, fuel pump motor, alternator ripple etc. It is a few hundred to a few kHz, and over a volt pp.
                                    It is worse if you have an old battery or old wiring connections like rusty grounds and battery terminals.

                                    The noise is differential (not common-mode) so it is between 12V and GND. A mains SMPS makes lots of common-mode noise (between LV secondary and earth GND). Rare to see a CM choke in a car.

                                    If it's an old car with a distributor, which makes a lot of RF interference and is one reason car makers went to coil-on-plug. It's hard to read an O2 sensor when you have many kV arcs in the distributor nearby.


                                    An inductor on 12V input helps with noise in either direction (coming in from ignition, or going back from 5V SMPS to car). For analog car stereos it used to be big iron-core mH's and now 22-470uH choke or whatever fits is still enough.

                                    The minimum is a ferrite bead and TVS+reverse diode. The ferrite bead is to stop high frequency >1MHz noise from affecting AM radio of the ECU.

                                    Comment


                                      #19
                                      Re: Running a microcontroller in car - power supply aspects

                                      Originally posted by redwire View Post
                                      The minimum is a ferrite bead and TVS+reverse diode. The ferrite bead is to stop high frequency >1MHz noise from affecting AM radio of the ECU.
                                      Ok, so no CM choke then. Your last schematic seems to be what I should go for - the one with the 470uH coil and diode across it.
                                      Wattevah...

                                      Comment


                                        #20
                                        Re: Running a microcontroller in car - power supply aspects

                                        I got myself THESE for the inductor....pretty overkill at 3a, but it's better to have more there than not enough.
                                        Wattevah...

                                        Comment

                                        Working...
                                        X