Forward and Reverse MOSFET Switch Design.

Discussion in 'The Projects Forum' started by mattaus, Jan 19, 2013.

  1. mattaus

    Thread Starter New Member

    Jan 18, 2013
    16
    1
    Hi all,

    So I was asking around earlier about how a particular LED driver worked and I figured it out, so now I’m at point number 2 in my little project – the switch.

    I want to get fancy and have drawn up the following circuit:

    [​IMG]

    What it is intended to be is a momentary switch that has both a forward and a reverse momentary action. If I need to explain this a bit more I can happily do so.

    Basically speaking the circuit is intended to function as follows:

    1) The MC2A-1F switch is a double pole momentary switch. It’s similar to what is used in most modern digital cameras – half press for one latch, fully press to activate the second latch. It does not lock in place and releasing the switch fully will return it to no connection.

    2) The MC2A-1F switch connects the 3V coin cell battery to the ATtiny4 micro-controller. When the switch is pressed, depending on how far it is pressed (half or full), the micro-controller reacts accordingly, and activates the MOSFET.

    3) The N-channel MOSFET, now being activated, allows power to flow from the main battery to the LED driver.

    4) Now depending on the code in the micro-controller, the MOSFET will be activated differently based on the previous state:

    • If the load is not running and the MOSFET is off (so the whole system is inactive). Half pressing the switch activates the MOSFET and hence the load, until the switch is released again at which point the MOSFET and load are turned off. (Momentary on).
    • Fully pressing the switch in the above situation activates the MOSFET and turns on the load permanently. So releasing the switch leaves the MOSFET on and the load running. (Permanently on)
    • If the system is in the permanent on state, and the switch is half pressed, the MOSFET is deactivated the load stops running. Releasing the switch during this state returns the MOSFET to the on state and the load begins running again. (Momentary off)
    • If the system is in the permanent on state, and the switch is fully pressed, the MOSFET is deactivated and the load stops running. Releasing the switch after this full press leaves the MOSFET and load off. (Permanently off).

    I actually have a few of these switches with me and there is some bounce in the switch. For example when the switch is fully pressed and then fully released you can feel it switching through the half press state on its way to fully off. This would be corrected in code to prevent it seeing half presses when full presses are intended.

    The microcontroller needs its own battery supply because it can’t get power from the main battery without the load being on and running, which you don’t want when the MOSFET (and hence load) should be off!

    I feel this explanation is important in order to truly grasp what I am trying to do here. If it needs clarification please do not hesitate to ask.

    Anyway – to the point of this post! I’m pretty set on the micro-controller half of the system. What I’m not 100% set on is the MOSFET side. The circuit diagram has been pieced together from various online sources so I’m not exactly sure of the circuit itself, or even the function of some components. I picked the MOSFET as I think it’s appropriate in this situation.

    The diode is intended to provide reverse polarity protection to the micro-controller. Cpower is supposedly to provide the micro-controller with a bit of residual power after the switch is open circuit so the micro-controller can finish doing its business.

    What is this circuit missing, or what does it have that should go? What is the purpose of Rin and the 1M resistors pulling the gate pin on the MOSFET to GND? What are appropriate values to use? Is the MOSFET set up correctly? Hell, is it even and appropriate MOSFET to use!

    I tried working this out on my own (believe it or not) but while I can find plenty of theoretical examples, I can’t seem to find any practical ones that apply to my scenario.

    Any insight or advice would be highly appreciated.

    Thanks,

    - Matt
     
  2. DickCappels

    Moderator

    Aug 21, 2008
    2,653
    632
    For one thing, it is a good idea to connect the VDD pin on the controller to the negative side of the LED battery so that Cpower can have a return path.

    Do you really need a separate battery? If the microcontroller spends most of its time in idle mode at 128 kHz, just waiting for a pin change interrupt, it could idle for somewhere between 10,000 and 20,000 hours on a single CR2032 cell.

    By the way, what programming hardware will program this cute little chip?
     
  3. mattaus

    Thread Starter New Member

    Jan 18, 2013
    16
    1
    Hmmm,

    I can't find the edit button :(

    I realised this morning that the circuit diagram in the original post is wrong. Very wrong. There is a reason the micro-controller cannot use the main battery, and that's because the circuit is actually set up like this:

    [​IMG]

    I was so caught up in copying the MOSFET switch circuits I found on the internet that I forgot to actually apply them to my scenario properly!

    The new circuit changes things around considerably, but now the load-battery-MOSFET arrangement is correct, and the reason the micro-controller can't use the main battery is now hopefully fairly obvious.

    I moved the capacitor as well.

    In regards to how the micro will be programmed....no idea. I'm hoping to find or hire someone to code and flash it for me because I wouldn't have the first idea where to start (well I do, but I don't have the gear or the coding experience).
     
  4. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    C1 is preventing the ground from being common to both batteries, which is required for the MOSFET to switch.

    I'm assuming C1 is a 0.1uF intended to be between V+ and GND on the uC?

    The code for the processor should be fairly straightforward.

    a) Half press is momentary on if light is off.
    b) Full press latches light on if light is off.
    c) Half or Full press turns light off if light is on.

    Is that correct?
     
  5. mattaus

    Thread Starter New Member

    Jan 18, 2013
    16
    1
    Ah yes thanks for the note about C1. I've now connected it from VCC to battery negative on the coin cell (now a common ground to the load). There's also a schottky diode on the Vcc line for reverse polarity protection. The C1 connection is between the diode and the Vcc pin of the uC.

    That code seems like it would work. There needs to be some smarts on part c) to determine if it would stay off from on if it's a half or full press (half press returns on when released, full press stays off when released).

    EDIT: Latest iteration:

    [​IMG]
     
    Last edited: Jan 19, 2013
  6. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    To make it work like a Surefire flashlight tailcap:

    1) While off - Half press - light on for duration of half press.
    2) Full press - "Clicks"/latches on, needs another full click to turn off.
    3) Half press - While latched on - no effect.

    6 state transition possibilities (short on/off, long on/off, short-long on/off since it passes through short to get to long press), 2 states for LED (on or off).

    Need a State Diagram for the different paths from ON to OFF and vice-versa. Then there would be zero confusion for the person writing the code.

    With those details worked out, the programmer could be YOU with BASIC running on an 8 pin PICAXE 08M2. No programmer needed other than serial cable and PC, development software/simulation software is free.
     
  7. mattaus

    Thread Starter New Member

    Jan 18, 2013
    16
    1
    The last state is wrong - a half press while latched on should turn the light off for the duration of the press. The SureFire example is good through - this switch is intended to be used in a C2 host I have with my own custom P60 drop-in sitting up front.

    I'll work on the state diagram tonight hopefully.

    The PICAXE would be wonderful and the idea of having full control over the programming is awesome. Can you clarify a few things for me though?

    The SMD 08M2 is a 150mil SOIC. I'm not sure what 150mil is? Is that .15 inches in which case the 08M2 requires roughly 5mmx6mm (solder pad dimensions) of space on a board? That might just fit. My other concern is I note that the 08M2 has a Vin range of 2.3-5.5V. That 2.3V may be too low as the coin cell will run just above 2V for most of it's life.

    Finally I can see it has sleep and nap commands, but what is the power draw in these states? I'm reading through the documentation and can't see anything. It obviously needs to be very low otherwise my switch will need it's battery replaced too often. The ATtiny4 is in the nA range.
     
  8. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Forgot about the low power sleep. I'm unsure if that is integrated into the 08M2 or not.

    However, playing with it to get it to behave how you would like, then providing the BASIC code that does what you want it to do would save a chunk of money having it translated to C.
     
Loading...