Stupid simple question.....


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    Jun 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    So I tried driving it with two pins but something else is screwy now....

    This is what I have:

    Code:
    OUTPUT Pin1
    output Pin2
    
    Startup:
    
    for startupalarm = 1 to 4
    high 2 
    high 1 
    pause 5000
    low 2 
    low 1 
    pause 5000
    next startupalarm
    It seems that "high 2" does not actually switch the pin high, but just ticks it high for a split second. "high 1" switches the pin high and it is held high for 5 seconds until it is switched low...

    This is the same regardless of which pins I use. The line of code immediately preceding the pause command works, all others do not. Nothing else is connected to the chip, it's all by itself on a breadboard.............
    www.theLanguageBear.com - Multi-Lingual books for kids and adults of all skill levels.

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


    Did you find this post helpful? Yes | No

    Default

    Hi,
    You're suffering from what is called a RMW problem (read-modify-write). The way the PIC works when setting a single bit in a register, like the GPIO-port in this case, is to first read the whole register, then set the bit in question and finally writing the whole register "back".

    Because your motor presents a large a load to the pin (especially at startup) the voltage on the pin will sag or be low. So what is happening is this:
    First you have the High 2. This reads the port (as a byte), sets bit 2 and writes the whole byte back to the port.
    Now you have High 1 which does the same thing but because pin2 is heavily loaded it will read as 0 when the port is read, the PIC then sets bit1 and write back to the port resulting in bit 2 now being reset to 0.

    The best bet is to use a transistor to drive the motor. If that's not an option then write to the port directly, setting both pins at the same time. You do this in the same way as Darrel showed you how to write to CMCON etc - look up the physical adress of GPIO and use POKE to write to it.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Remember also, you must treat your Motor as an INDUCTOR or RELAY. The back emf could destroy your PIC pin or Transistor switching it. Put that all important Diode reverse-biased across the Motor.

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Post

    +1 .....

    Good answer from Henrik ...
    Last edited by Acetronics2; - 23rd February 2010 at 09:44. Reason: I must RTFM !!!

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


    Did you find this post helpful? Yes | No

    Default

    Nah, if you look at section 9.1 of the mid-range manual you'll find the following:
    All write operations (such as BSF and BCF instructions) are read-modify-write operations. Therefore a write to a port implies that the port pins are read, this value is modified, and then written to the port data latch.
    So I'll stick to my theory ;-)

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Talking

    Ok Henrik ...

    One red tomato for me ... ( was the question ...)

    this also explains why it acts the same whith heavy capacitive loads ... driving directly Big Mosfets gates i.e.

    Alain

    PS: but what an Idea µChip had to proceed like that ???
    Last edited by Acetronics2; - 23rd February 2010 at 09:46.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Jun 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    Why is it that when I enter:

    GPIO = %11111111

    Picbasic says "Undefined variable"?
    www.theLanguageBear.com - Multi-Lingual books for kids and adults of all skill levels.

Similar Threads

  1. Really simple question for you experts :)
    By lew247 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th June 2008, 02:43
  2. SIMPLE question
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th February 2008, 19:27
  3. Stupid question
    By Meriachee in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 20th July 2007, 06:47
  4. really simple, dumb question
    By picster in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd March 2007, 23:02
  5. really simple adcin question
    By kitcat in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 21st April 2006, 10:06

Members who have read this thread : 0

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