Stupid simple question.....


Closed Thread
Results 1 to 19 of 19
  1. #1
    Join Date
    Jun 2008
    Posts
    16

    Default Stupid simple question.....

    I'm trying to make a button work...
    here is my test code:

    Code:
    input Pin4
    
    loop:
    
    if Pin4 = 1 then cycle
    
    goto loop
    
    
    cycle:
    
    if Pin4 = 0 then loop
    
    high 0 : pause 100
    high 1 : pause 100
    high 2 : pause 100
    low 0 : pause 100
    low 1 : pause 100
    low 2 : pause 100
    
    
    goto cycle
    
    
    end
    When I connect pin4 to high nothing happens... Do I need to pull the pin high or low or something? Should I have something other than the "input Pin4" command?

    This seems like it should be super fricking simple, but it just doesn't work... I feel like I'm taking crazy pills!! Someone please help.
    www.theLanguageBear.com - Multi-Lingual books for kids and adults of all skill levels.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Pin4 is usually PORTB.4, and not actually Pin4 on the chip.

    Which chip are you using?
    <br>
    DT

  3. #3
    Join Date
    Jun 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    I'm using a 12F683, GP4 (which I believe is the same as PORTB.4?) is Pin3.
    www.theLanguageBear.com - Multi-Lingual books for kids and adults of all skill levels.

  4. #4
    Join Date
    Jun 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    I could use some help here... I am completely at a loss. I can't get any input to work at all, am I going crazy?
    www.theLanguageBear.com - Multi-Lingual books for kids and adults of all skill levels.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    For a 12F683, you need to turn off the Analog inputs and Comparator.

    SYMBOL ANSEL = $9F
    SYMBOL CMCON0 = $19

    POKE ANSEL, 0
    POKE CMCON0, 7

    hth,
    DT

  6. #6
    Join Date
    Jun 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    I cannot express enough gratitude. It works! Thank you so much kind sir. Now where might one learn a bit of information like that? That seems fairly basic, but I don't recall coming across that in any of my "pic'n" books or the 12F datasheet...
    www.theLanguageBear.com - Multi-Lingual books for kids and adults of all skill levels.

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


    Did you find this post helpful? Yes | No

    Default

    Hi,
    If you look at section 4 in the datasheet you'll see a note there saying:
    Note: The ANSEL and CMCON0 registers must be initialized to configure an analog channel as a digital input. Pins configured as analog inputs will read ‘0’.
    There's also an example showing how to do it but it's in ASM so it's not that easy to understand.

    If you then look at figure 8.4 you'll see the various configurations for the comparator module and in the bottom right hand corner it shows that you should write 7 (the three lower bits are set) to CMCON0 in order to disable the comparator.

    If you then look at the bottom of table 2.2 it'll show you that ANSEL "comes up" with the lower 4 bits set and if you look at register 4-3 (page 33) you'll see that when bit 0-3 is set it means that the pin is in "analog mode".

    As for the rest, $9F is the adress for ANSEL register and $19 is the adress for the CMCON0 register and that can be found if you look at figure 2.2 in the same datasheet. PBP makes it a lot easier as it allows you to write directly the the registers without having to look up the actual adress of it "manually".


    It's a very common thing to overlook untill you've been bitten by it, next time a pin doesn't work as you think it should it'll be the first thing you'll think of checking ;-)

    /Henrik.

  8. #8
    Join Date
    Jun 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    oy...
    Thanks guys, you rock..
    How I wish I could be using my Arduino for this project..
    www.theLanguageBear.com - Multi-Lingual books for kids and adults of all skill levels.

  9. #9
    Join Date
    Jun 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Another dumb ass problem

    I really hate this stuff.... it makes me want to stab myself in the eyeball with a fork.

    I'm measuring 3v from Pin1 (GP1) on my 12F683.
    I'm using a 3v coin cell. It measures 3v.
    I connect a LED to Pin1, it lights.
    YAY! Next frickin challenge....

    I connect a small vibe motor to my 3v battery, it vibrates like crazy. Yay.
    I connect my small vibe motor to Pin1 (measuring 3v) It does absolutely nothing.
    I connect the LED to Pin1.. it lights..
    I connect the motor to Pin1 ... it does nothing
    I punch stuff... that doesn't help.

    I don't know what else to try...
    The vibe motor draws about 35-40mA

    I see that the IO pins supply 25 mA but the GPIO can supply 90mA...
    What's the difference?
    www.theLanguageBear.com - Multi-Lingual books for kids and adults of all skill levels.

  10. #10
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by chien_fu View Post
    The vibe motor draws about 35-40mA

    I see that the IO pins supply 25 mA but the GPIO can supply 90mA...
    What's the difference?
    A single pin can put out a max of 25mA, but the entire GPIO (all output pins) can put out a max of 90mA. You could use a transistor, or you could have two pins control the motor (and hope start current would not be too high).

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

  12. #12
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    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.

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

  14. #14
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    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 !!!

  15. #15
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


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

  16. #16
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    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 " !!!
    *****************************************

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

  18. #18
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    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.

  19. #19
    Join Date
    Jun 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    Cool, thanks.
    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, 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 : 1

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