Connect with us

need help with simple 3v to 34v transistor relay/switch

Discussion in 'General Electronics Discussion' started by sideburn, Jun 14, 2013.

Scroll to continue with content
  1. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,271
    Nov 28, 2011
    OK. Thanks for the link.

    There's not much information on it, is there. I noticed it needs a 5V supply. Are you using a separate battery for that?

    I see, RI is only available on pin 4 of the SIM900 IC itself. That's a good reason to use serial data instead.

    No, MOSFETs and bipolar transistors operate in different ways.

    You just need to understand that the MOSFET is interested in the gate voltage RELATIVE TO THE SOURCE. In that design, the source is connected to the +3.7V rail, so it's always at +3.7V relative to the circuit's 0V rail. So when the PIC's output goes low, i.e. it goes to 0V, from the MOSFET's point of view the gate is 3.7V negative relative to the source.

    In this arrangement, current flows from the source to the drain. That's conventional current, which flows from positive to negative.

    Actually it flows from the positive terminal of the battery, to the +3.7V rail on the board, to the source of the MOSFET, through the MOSFET to the drain, then out to the positive supply input of the DC-DC converter.

    The MOSFET's source is always at the same potential as the +3.7V rail. They're connected together.

    When the PIC's output is high, it is equal to the +3.7V rail, so there is no voltage difference between the MOSFET's gate and source. So it's turned OFF and no current flows out the drain and to the converter.

    When the PIC's output is low, it is equal to the 0V rail, which is 3.7V negative with respect to the +3.7V rail. So there is 3.7V on the MOSFET's source, and 0V on its gate, so from the MOSFET's point of view, Vgs is -3.7V. So it's turned ON, and current flows in the source, through the MOSFET, out the drain, and to the converter.

    No problem. I hope you understand that last description because it's about as clear as I can make it. Re-read it until it really sinks in. And remind yourself about which pin is the source, and which is the drain. It's not hard to get them confused.
     
  2. sideburn

    sideburn

    75
    2
    Jun 14, 2013
    I know.. There's no manual.. Not a seperate battery, and so far I am ok. It has been running all day on the 3.6v lipo. But not sure how well it will go with the PIC when I'm done and not sure what will happen once the HV ringer kicks in.. But I have a 5V step up/charger circuit I was panning on using..

    This--> http://www.ebay.com/itm/2-x-PCB-Li-...DC-/140791768382?ssPageName=ADME:L:OC:US:3160

    Right. I was initially planning on soldering a jumper wire to it and then connecting it to the pic.

    Yes. This is great. And I will be re-reading it.. But the point you made the gate being relative to the source helped clear things up a lot. I was thinking of the source as being similar to the emitter on a transistor.
    I've got a pretty good general understanding of how electronics work, current flows neg to pos vs conventional, etc. but I've got a lot to learn.
     
    Last edited: Jun 24, 2013
  3. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,271
    Nov 28, 2011
    I don't see any output current rating given for those boards. It needs to be able to supply 2A peak for the GSM board.

    Also, looking at the schematic (which has multiple errors anyway), I see that the negative connections on the input and output are not common; they're interrupted by two MOSFETs. You should check that there's continuity between the negative side of the 3.7V input, and the negative side of the 5V output.
     
  4. sideburn

    sideburn

    75
    2
    Jun 14, 2013
    Oh great... I just bought them a long time ago and have never tried them out yet.
    I thought they would work well as a charging circuit for the lipos.
    Maybe I won't even need a charging circuit actually.. I think the lipos have built in LVC and as long as my dc charger is at a lower mAH, I guess I would be alright. So maybe, if I'm lucky I wont need to step it up to 5V anyway.

    I'm also hoping I can charge the batteries WHILE the circuit is running. The battery is 2000mah FYI.. I'm hoping thats going to be enough to run the PIC + GSM board + BOOSTER/BELL (which is only on when ringing of course) for at least a day.. Hopefully more.

    I made an edit above about MOSFETS--- I was thinking of the source as being similar to the emitter on a transistor. Is that not the case?
     
    Last edited: Jun 24, 2013
  5. sideburn

    sideburn

    75
    2
    Jun 14, 2013
    That GSM pulls 2A peak? When is that happening when you connected on a call?
    Thats the size of my lipo.. Yikes. I hope it doesn't drain that battery too fast when connected to a call.

    I wonder how many amps I'm going to be pulling when the pic is idling in my event loop, and the GSM is on stand by.

    And while we are on the subject of current flow.. Is it possible to drive a small speaker if I connected it directly to an output pin on the pic? To generate a beep sound?
    I was thinking I could pulse the output of a pin at certain frequency to drive a speaker. Or am I going to need another MOSFET for that?
     
    Last edited: Jun 24, 2013
  6. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,271
    Nov 28, 2011
    If you want to run the circuit while the battery is charging, it's best to power the circuit from a power supply and charge the battery through a separate path. If you don't do it that way, and a call comes in while the battery is being charged, your circuit will draw current from the charger, which will confuse it - it's designed to supply current to the battery only.

    Have you decided how you want to charge the battery? Do you have a charger IC in mind?
    Yes, that is the case. The source, and the emitter, are the reference connection for the control electrode (gate, or base). They are also one of the electrodes for the main conduction path (drain-source or collector-emitter). A MOSFET responds to the voltage difference between the gate and the source. A transistor responds to the current flow in the base-emitter junction.
    The 2A current specification is just the peak current. The GSM system transmits in bursts (hence the "dig-a-dig, dig-a-dig" sound you hear if you put a transmitting cellphone near a sensitive piece of audio equipment). So it won't draw 2A continuously. The average current will be quite a bit lower - the specification says 0.5A average, and that will be while a call is in progress.
    I think you'll be OK. You'll waste significant power in the 3.7V-to-5V converter though, so a 0.5A current into the GSM device will correspond to a load on the battery of around 0.75A or more.

    The GSM module claims a standby current of only 2 mA. You should read the documentation!

    The PIC will only draw a few mA as well, so you should get several days between charges if the GSM device doesn't transmit.
    Yes, but you need to use a series resistor to limit the current, and it won't be very loud. Try a 330 ohm resistor; that will limit the current to a bit over 10 mA. Different speakers will behave differently. Often, piezo transducers are used instead of speakers in these applications. For example, http://www.digikey.com/product-detail/en/PKM13EPYH4000-A0/490-4698-ND/1219329
     
  7. sideburn

    sideburn

    75
    2
    Jun 14, 2013
     
    Last edited: Jun 24, 2013
  8. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,271
    Nov 28, 2011
    Protection circuitry is for protection. You're not supposed to use it to control the normal charging process. Chargers use carefully determined algorithms and voltage, current and temperature sensing to charge the battery to optimise safety, performance and battery lifetime. Several manufacturers make battery charging ICs - try Maxim (http://www.maxim-ic.com), Texas Instruments (http://www.ti.com), Microchip (http://ww.microchip.com) and Linear Technology (http://www.linear.com) to start with.

    True, MOSFETs are most often switched, but transistors can also be used with PWM.

    Major advantages of MOSFETs are: (a) the drain-source path is resistive (assuming sufficient gate bias) and its resistance can be extremely low - less than 1/1000th of an ohm, and (b) The MOSFET's gate does not draw any steady current, although MOSFETs have significant gate-source capacitance. These characteristics make them good for switching heavy DC currents, and at low switching speeds, the energy required to switch them ON and OFF can be very low.

    For example, you could switch a 100A current ON and OFF with a single high-current MOSFET, controlled by a tiny little switch, with the switch controlling the voltage from a stack of four 3V lithium coin cells, and the coin cells would last practically their whole shelf life.

    Transistors are quite different to drive. To keep a transistor conducting, you have to feed a steady current into the base. (This current comes out the emitter.) A transistor has a limited current gain (normally less than 1000, often around 200), so the amount of current it can control is determined by the amount of base current that the driving circuit is forcing into it, and at high collector current, the current gain can get very low - less than 10 for a big transistor at 10A upwards.

    Some characteristics of transistors may make them more suited to certain circuit positions than MOSFETs. The base-emitter forward voltage of around 0.7V (at low currents, at least) is less variable than the gate-source threshold voltage of a MOSFET, which can differ by as much as 2V between different devices with the same part number. On the other hand, MOSFETs have advantages in some circuit positions too. In some circuits, either will work.

    The fact that transistors will turn OFF unless actively biased by a base current can be useful; if you leave a MOSFET's gate unconnected, its voltage will float, because of the extremely high gate resistance. Even an extremely weak (high-resistance) leakage path from the gate to some other voltage in the circuit will pull the gate to that potential.

    Because of their extremely high gate resistance, MOSFETs can be damaged by electrostatic discharge (ESD) to the gate, which damages the thin gate insulation. This will also happen if the limited gate voltage range (no more than +/- 30V relative to the source) is exceeded. You should use antistatic precautions when handling MOSFETs (and ICs which contain them) to prevent ESD damage.

    Transistors can be damaged by reverse base-emitter voltages greater than about 5V. The base-emitter junction acts as a zener and breaks down at a reverse voltage of around 7V and even a small reverse current causes both a short-term and a long-term reduction in current gain, while a larger reverse current makes the transistor unusable.

    That's not a complete summary of the differences but it covers some of the main ones.

    I'm not sure what that specification means. Sleep mode isn't described anywhere. Is this its default mode when it's not communicating on the GSM network? Is it always ready to receive an incoming call or message in this mode?

    The only other current consumption figures are 0.5A continuous and 2A peak, which I assume only apply when the module is transmitting. So when it's idle but ready to receive, how much current does it draw? Is this the 1.5 mA Sleep mode current? Or does it draw more than 1.5 mA when it's idle but ready?

    That depends on how you're handling the serial data reception. If your code is making a half-second beep sound using instruction loops and delays, and the GSM unit sends a string like "NO CARRIER", the first nine characters are going to be lost, because the PIC wasn't checking the USART's receive ready flag during the time they came in. The USART can only store one character plus the one it's currently receiving. So you'll lose data.

    There are various approaches you can take to deal with this. As I explained in an earlier post, you can use the USART's received character interrupt to force the PIC core to deal with characters as they arrive; this will cause tiny disruptions to the sound which may or may not be noticeable. Or depending on the capabilities of the timer modules in the particular PIC you're using, you may be able to time the edges of the tone using on-chip hardware, so the PIC core can do other things while it's waiting. You could even avoid using interrupts and timer features altogether if you use cycle counting!

    I'll have a look at the data sheet for the PIC16F628A and suggest something.

    I think it's probably a good idea. The booster will draw significant current even if the bell isn't being used. You're looking at a normal operating current budget in the milliamp range, and the booster's idle current could easily be 10 mA.
     
  9. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,271
    Nov 28, 2011
    I've had a look at the PIC16F628A data sheet. I think you can do it all without interrupts. Here's the architecture I suggest.

    Have a loop that runs constantly and calls separate functions for the various functions required:
    - Serial reception - poll RCIF bit to detect new data; store into a buffer; compare a complete string to known strings and set control flags accordingly.
    - Beep generation - poll for CCP1IF set; if so, update CCP1M3~0 to appropriate new state for speaker pin according to beep enable and beep frequency
    - Timing update - detect elapsed time through either CCP1IF or TMR1IF; count down timers for beep and bell control; update bell control output (relatively slow).
    - Overall control logic: detect the "RING" and "NO CARRIER" flags from the serial receive function and update control and timing variables that control the tone and bell control output signal generation.

    The tones can be accurately generated using the capture/compare module, which operates in conjunction with Timer 1. When the Timer1 count register matches the output compare register, the output will be set high, set low, or unchanged, according to the CCP1M3~0 bits in the CCP1CON register. The output is available on RB3/CCP1 (pin 9 on the DIP version).
     
  10. sideburn

    sideburn

    75
    2
    Jun 14, 2013
    Thanks,

    I'll have to read through your posts in more detail later when I get some free time again.
    Got hung up with work stuff that I have to get out of the way. I did get a chance to try out that 5v charger/regulator board and you are right, I don't think its going to be able to provide enough current.. the pic keeps rebooting when the gsm module is receiving calls.. I also don't really need the 5v I don't think. I'll know for sure when I hook the bell up.
    I received the MOSFETs today and I can't wait to give them a try. I also tried my circuit out today on a breadboard instead of my development board and it was going bonkers on the outputs. misbehaving badly. I don't have andy pull up or pull down resistors hooked up. I set the weak pull-ups flag in my code and that fixed it. The pic was talking back and forth to the GSM module. Cool stuff.

    I looked at the Microchip MCP73871 lipo management controller chip. That looks like it might be what I need. It seems like it is pretty simple to set up.
     
    Last edited: Jun 25, 2013
  11. sideburn

    sideburn

    75
    2
    Jun 14, 2013
    I also hooked a speaker up to the GSM and its a little too tinnie sounding. I'd like to add some more midrange/bass to it if I could easily. If not I might have to just lower the volume level. it's a bit ear piercing at the moment.
     
  12. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,271
    Nov 28, 2011
    The specifications for that GSM module are very clear: 4.5~5.5V supply required...
    You should have actual pull-up and pull-down resistors on the board. The PIC's pins probably go high-impedance while it's resetting.
    Good! You've written a fair bit of code then?
    That's a nice little chip. It's only rated for 1.8A maximum input current though. You might be able to get away with that if you add some BIG decoupling capacitance to absorb the 2A peak transmit current drawn by the GSM module. Ideally it would be best if the charging could be suspended while the GSM module is transmitting, but the MCP73871 doesn't support charging suspension, and I don't think there's any way to tell when the GSM module is transmitting, so that's a lost opportunity.

    Are you going to be able to deal with the MCP73871's package? It's a no-lead device that needs to be surface-mounted using solder paste.

    Yeah, just lower the volume level.
     
  13. sideburn

    sideburn

    75
    2
    Jun 14, 2013
    Yeah.. I know.. But its working fine at 3.7v when I connect the battery directly to the PIC circuit and the module. I'll let it run overnight and see how it performs tomorow.

    I'll add the pull-up and pull-downs when I get down to actually soldering up the board. I think I can disable some inputs and outputs too in the firmware which I think will help conserve the battery as well.

    Yeah, about 500 lines or so.. I'm using 4 inputs and 5 outputs. But I think I will be able to eliminate 2 outputs now. This is the first time i've messed with microcontrollers and I am starting to like it a lot. So cool writing software for your own hardware! And I'm impressed how low cost and powerful they are. They're like a complete computer from the 80's (minus the graphics and sound).

    I'm about at the point where this battery management is the only thing left...
    I know, I hate that its SMD.. I've done a little of that before and I have some solder paste.
    And I use a hot plate.


    I still have to finish designing the board in eagle and get some boards made.

    The first one will probably just be on a breadboard which will also make that MCP73871 even more of a pain to deal with.
    I just cut the volume in half and that helped a lot. This GSM board is actually pretty nice.
    Its got a 300 page manual of AT commands you can do with it. I just found out it has tone generators too so I may not have to do that with the pic (which will elimate the need for 2 of the outputs).
     
    Last edited: Jun 25, 2013
  14. sideburn

    sideburn

    75
    2
    Jun 14, 2013
  15. sideburn

    sideburn

    75
    2
    Jun 14, 2013
    Ha! I just maxxed the chip out with my code and got:

    :0: error: can't find 0xB words (0xb withtotal) for psect "text643" in class "CODE" (largest unused contiguous range 0x8)

    I had to remove a few lines of debug code to get it to build... I could use a little more memory. I got to tighten things up some more if I want to use the USART to capture the RING indicator..
     
  16. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,271
    Nov 28, 2011
    I'm not sure how much your code is doing, but 500 lines sounds like a lot for the functionality you've been talking about so far. You're probably doing things the long way; there are probably lots of techniques you can use to make your code shorter and tidier.

    Please feel free to post your code here, and I (and possibly others) will suggest improvements.
     
  17. sideburn

    sideburn

    75
    2
    Jun 14, 2013
    I'm turning a rotary phone into a mobile phone.
    So I am detecting when the phone is on or off the hook, decoding the number being dialed and then sending the number off to the gsm. Then with the ring indicator I'm making the bell ring. Theres also some special commands.. dialing 1,1 redials last number, 1,2 calls back a missed call..

    so theres 4 inputs:

    incoming call
    handset off the hook or not
    rotary not in the resting position-- (dial complete)
    rotory dialing bounce switch

    and theres 5 outputs:

    ring booster power
    GSM power up (during startup)
    bell ringer signal
    dialtone - i am scrapping this though, the gsm has one already that I can turn on through the usart

    I'm down to about 200/300 lines now.. and theres a lot fo things commented out and debug strings.. because I'm experimenting, and yeah I know its just a bunch of while loops. I can make it much more tight and efficient.. but im ok with it for now. I scrapped the idea of using the USART to detect the RING and NO CARRIER. it was becoming a nightmmare with all of my loops and delays.. I know I could do it with interupts and the way you suggested and I might later when I go into the streamlining phase but for now I just want to get everything working. So I soldered a wire to the RI pin on the GSM pin.

    Ive got everything working now on a couple breadboards. I just have to do a little more optimiizing.

    One thing thats annoying is the PIC programmer keeps randomly failing to program when I try to program it in circuit. If I use my dev board it programs everytime but Its a pain to have to keep pulling the chip out to try things. Sometimies it works like a charm and then it decides to quit working entirely.

    Keeps doing this:

    Programming...
    program memory
    Address: f Expected Value: 2d78 Received Value: 2d84
    Failed to program device
     
    Last edited: Jun 26, 2013
  18. sideburn

    sideburn

    75
    2
    Jun 14, 2013
    i got it all working..
    had a hell of a time with the rotary dial. it was randomly adding number to some of the numbers i dialed.. I played with bounce back delays forever until i realized the problem was the bouncing of the leave switch while you were spooling it up before you let go and let it dial. so i put code in to not read the switch for a few milliseconds after you turn the dial away from its resting position. theres 2 switches on the dial.. a "done filing" switch and the one that does the pulses.


    Anyway. all thats left is the FET to turn the booster on and off. I measured that its pulling 50 milliamps idle.. the rest of the circuit pulls about 20 to 30.

    Ao 80.. not sure how long that would take to drain a 2000mah battery though. I don't know the math for that but 50 is a lot compared to the rest of it. I guess its a bad idea to not use a mosfet and conect it directly to the output. I guess I'll tackle that next..

    Heres a pic of the circuit so far.. You can see the little white wire I soldered to the pin of the sim900 for the ring indicator.. I'm pretty happy with it. When you power it up, it sends an output to the power input on the GSM board and turns it on, waits for it to boot up and then sends a bunch of AT commands to configure it and then an led blinks to indicate everything is ready. when you pick up the hook, you get a dial tone. rings the bell on and incoming call.. its all pretty solid now.. you can dial 1,1 to redial last number and 1,2 calls 1800-free-411

    I want to finish the schematic in eagle and get a board made. The hardest part with that is finding some connectors for everything.
    And then finding a place that will make the boards.I was thinking http://oshpark.com but i'd like a fast turn around so any suggestions if you've got them would be great...
     

    Attached Files:

    Last edited: Jun 27, 2013
  19. sideburn

    sideburn

    75
    2
    Jun 14, 2013
    After getting the MOSFET controlling power ot the boost converter I checked the load and the PIC is pulling 3ma and the gsm is pulling 25ma..

    Does this mean in idle, with a 2000mah battery, it should run for about 70 hours?
     
  20. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,271
    Nov 28, 2011
    GSM modem idle current 25 mA? That's a reasonable figure.

    Yes, a 2000 mAh battery should give about 70 hours at that current.

    Have you confirmed that the GSM modem will work properly at 3.7V? The specification is very clear that its input range is 4.5~5.5V. If you need to add a boost converter, expect an increase of about 50% in the current, and a reduction in operating time down to about 50 hours.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-