12F683 - basic code not working


Closed Thread
Results 1 to 40 of 57

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Hi,
    Regarding your first schematic, generally you need to put the transistor on the low side. Otherwise you need a higher voltage on the base than you've got on the collector. Put the relay "on top", then on to the motor and finally the transistor at the bottom, emitter to ground. Yes, the motor is biderectional but the current thru the transistor is always the same so put the diode back across is, cathode facing "up" of course.

    /Henrik.

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Quick questions guys, I've been developing the hardware further and need to swap the 2930 transistor for something more powerful for driving the 540 type motor. I have a TIP126 PNP darlington, which works, but with reverse logic on the base. IE instead of turning on when the base is high it's high when the pic pin is low. I could change the code so that the output is constantly high and goes low when the conditions are met, but was wondering if there was a simple way of making the transistor fire with a positive voltage on its base ?

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    If you don't want to change your code, what if you add a small NPN transistor to the base of the PNP?

    Connect the NPN to GND instead of VDD (all sounds plausible in my head).

    Robert

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Yeah, there's no way to change the actual transistor (obviously) so what you need to do is invert the signal which you can do by adding a NPN transistor "in front" of the PNP like Robert says.

    Previously I said to put the transistor on the low side but that was when you used a NPN transistor. Now, with a PNP "serviced" by a NPN you'll be better of putting on the high side. It will work with the PNP on the low side as well but only as long the voltage feeding the motor isn't higher than the voltage used to drive the transistors (ie the voltage feeding the PIC) + around 1V for a Darlington. Also, remember that the voltage drop across a Darlington transistor is higher than across a "normal" BJT.

    You need to remember that ordinary transistors (BJTs or Bipolar Junction Transistor) are operating on current. Ie, for a NPN transistor we push a certain current into the base which gets "amplified" by the gain of the transistor and "pulled down into" the collector. The base basically behaves as diode connected to the emitter so there will be a voltage drop across it of ~0.6V (for a silicon device) as with any diode. So, IF you put a NPN transistor on the high side of the load with the collector connected to, say 12V, you basically need a voltage of 12.6V in order to be able to "push" current into the base. If you try to push current into the base using 5V the transistor will only partly open (ie it'll operate in its linear region) and it'll disipate a lot of heat. This is what's done in linear amplifiers etc but not what you want when using the transistor as a switch.

    OK, so what if we put that NPN on the low side of the load (motor). Now, the emitter is connected to ground so there's plenty of headroom in using 5V to push current into the base and it'll work just fine provided you use a sensible value for the base resistor.

    Then you decide to change to a PNP transistor.....
    The PNP transistor is "operated" by "pulling" a current out thru the base (as oposed to driving current into the base for a NPN). So, if you put the PNP on the low side of the load its emitter (which is now connected to the load) will "see" the full supply voltage when the transistor is OFF. So, in order to keep the transistor OFF no current can be allowed to flow down thru its emitter and out of the base, right? In order to prevent that from happening the voltage at the base needs to be atleast the same as the voltage feeding the load less one diode drop (or two for a Darlington). If the powersupply voltage is 12V and you're driving that low side PNP with 5V from a PIC it will never turn off completely.

    Putting your Darlington PNP on the high side of the load with a small NPN to "pull" current thru the Darlingtons base to ground (thru a resistor of course) is the right way to do it given those particular circumstances.

    /Henrik.

  5. #5
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Henrik,

    Thanks for the explanation. And yes I did find the motor would not actually stop running, it would shut off, then slowly start up again, gradually increasing in speed.

    If I've followed your post correctly, and followed the schematic provided by Pedja, would the attached work (using say a 2n3904 and a 1K base resistor) - Note that the motor supply is using 6v with the PIC running at 5v (and I've noticed I've omitted the diode across the relay -Doh !)
    Attached Images Attached Images  

  6. #6
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Wow. Great explanation Henrik. It answered a few questions I'd been having with a project. Thanks for taking the time.

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Scampy,
    You have the Darlington PNP upside down, the emitter needs to go to the positive rail. And you need a resistor in the Darlingtons base as well. If you don't put a resistor there you'll basically short out the supply with the base emitter diode(s) in the Darlington - not good. Use 1k or whatever.

    EDIT: Oh, and the emitter of the small NPN must go to ground - not to the collector of the Darlington.

    AvionicsMaster1,

    Thanks, and you're welcome! Perhaps not the best explaination from a purely technical standpoint but never the less.... :-)

    /Henrik.

  8. #8
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Please delete this post

  9. #9
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Rob,

    I'll opt for changing the code... it's only a matter of changing half a dozen lines from how to high

    But thanks for the input

Similar Threads

  1. 12F683 - Pin1 not working
    By ruijc in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th February 2014, 17:38
  2. 12F683 Maths and code genius reqd.
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 1st January 2014, 08:44
  3. please help with 12f683 pwm code
    By haidar in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 22nd May 2013, 21:25
  4. Problem converting 12F683 code to 12F1840
    By RossWaddell in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 14th March 2013, 01:55
  5. Working code but my layman approach uses too much code space
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 14th December 2012, 20:44

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts