12F683 - basic code not working


Closed Thread
Results 1 to 40 of 57

Hybrid View

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

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

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    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.

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

  5. #5
    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!! :-]

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

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


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Hi,

    In the datasheet I looked at the current gain for the BC639 is stated as minimum 40. Your relay coil needs 5V/63ohm=80mA at 5V, with a gain of 40 you need to push 80/40=2mA into the base of the transistor.

    There's a drop of 0.6V across the base-emitter junction so if the PIC is powered with 5V you're left with ~4.4V to do it. The base resistor then needs to be 4.4/0.002=2200ohm, I'd go with half that or ~1k.

    With a 100ohm base resistor you're overloading the output drivers in the PIC, trying to pull ~44mA from an output rated at 20mA. This is probably why the voltage is clamped to way less than 5V.

    Fit a 1k-2k resistor then verify the operation in steps.
    1) Measure the voltage at the PIC output, it should be either 0 or 5V (or close to it). If it's not then something is wrong.
    2) Measure the voltage at the base of transistor, it should be either 0 or 0.6V (or close to it). If it's not something is wrong.
    3) Measure the voltage at the collector of the transistor, it should be 5V when the transitor is OFF and close to 0 when the transitor is ON.

    If it doesn't work please do the above measurments and report the results.

    /Henrik.

  8. #8
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    The output drive is current limited to 25mA meaning an internal resistance of about 200 Ohms at 5V. That's why you see the 2.84V at the pin and nothing close to 5V.
    Name:  Port output.JPG
Views: 576
Size:  14.3 KB


    Also, I would think you only need about a 2K Ohm resistor to drive the NPN that has a min. gain of 40 to drive the 80mA relay load.
    Louie

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