Stupid simple question.....


Closed Thread
Results 1 to 19 of 19

Hybrid View

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


    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.

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

  3. #3
    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 08:44. Reason: I must RTFM !!!

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


    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 ;-)

  5. #5
    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 08: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 " !!!
    *****************************************

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

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


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Because the variable GPIO isn't defined....

    This is because you're using PBC and it doesn't provide a way to directly write to the registers as you're trying to do - only PBP does that. As I wrote in my previous message you need to do as Darrel showed you earlier in the thread:
    Code:
    SYMBOL GPIO = $05     '$05 is derived from the memory map in the datasheet for 12F683
    SYMBOL TRISIO = $85
    
    Poke TRISIO, 0   'Set all available GPIO pins as outputs
    Poke GPIO, 255  'All availble GPIO pins high.

Similar Threads

  1. Really simple question for you experts :)
    By lew247 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th June 2008, 01:43
  2. SIMPLE question
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th February 2008, 18:27
  3. Stupid question
    By Meriachee in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 20th July 2007, 05:47
  4. really simple, dumb question
    By picster in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd March 2007, 22:02
  5. really simple adcin question
    By kitcat in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 21st April 2006, 09: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