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,624


    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.

  2. #2
    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  

  3. #3
    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.

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


    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.

  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 info.

    I was browsing through my old posts as I recall I did something similar for a model train controller... only this time I used two transistors in a darlington pair. I'll use this as a basis for the output to the motor - via the relay contacts
    Attached Images Attached Images  

  6. #6
    Join Date
    Jan 2007
    Posts
    78


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    I have ever used a DPDT relay as a motor direction control instead of an H bridge device.
    In some cases the relay takes care of a lot of H-bridge current limitation issues since there is negligible resistance in relay contacts. A 2n7000 mosfet can a drive large number of different relay types nicely.

    And the relay only requires one control pin from the PIC.
    If speed control is needed, I use a mosfet to pulse current to the motor.

    Fun stuff!! :-]

  7. #7
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    I've just transferred the project from the development board to stripboard. The circuit is running fine in that the RTC is being read and serial comms are working, however the PIC is not driving the relays hard enough to move the contacts (although they can be heard clicking slightly). I've changed the base resistor as I'm now using 5v DIL relays with contacts rated at 2A 30v which should be OK for driving a 6v motor that draws 700mA under load. In the attached circuit R1 is 100 ohm, Q1 is a BC639 NPN and the relay coil has a resistance of 63 ohms. I've also found that when the PIC makes the pin high it's reaching 2.84v and not 5v or near as dammit. Any suggestions ?
    Attached Images Attached Images  

Similar Threads

  1. 12F683 - Pin1 not working
    By ruijc in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th February 2014, 18:38
  2. 12F683 Maths and code genius reqd.
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 1st January 2014, 09:44
  3. please help with 12f683 pwm code
    By haidar in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 22nd May 2013, 22:25
  4. Problem converting 12F683 code to 12F1840
    By RossWaddell in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 14th March 2013, 02: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, 21: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