Input problems with 12F629?


Closed Thread
Results 1 to 14 of 14
  1. #1
    achilles03's Avatar
    achilles03 Guest

    Default Input problems with 12F629?

    I'm relatively new to PBP, and am still in the learning stages. I'm using a 12F629 to control a servo based on two inputs via pins 1 and 2. Pin 0 is the output pin. For some reason, the 12F629 doesn't recognize any inputs on pins 1 and 2. I've checked to make sure there's no port/pin type conflicts, but I'm sure I'm missing something. Does anyone know what I'm missing?

    Thanks in advance,
    Dave
    (see program below)

    -------------------------------------------------
    i VAR BYTE

    output 0
    input 1
    input 2

    Define OSCCAL_1K 1

    low 0

    pause 100

    loop:
    if GPIO.1=1 then turn1
    if GPIO.2=1 then turn2
    goto loop

    turn1:

    for i=0 to 5
    pulsout 0, 147
    pause 20
    next i
    goto loop

    turn2:
    for i=0 to 5
    pulsout 0, 152
    pause 20
    next i
    goto loop
    -------------------------------------------------

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default CMCON... Again :o)

    What about
    Code:
    Define OSCCAL_1K 1 
    CMCON=7 ' disable analog comparator
    
    TRISIO=%11111110 ' set GPIO as output
                     ' others as input
    i VAR BYTE
    
    low 0
    
    pause 100
    
    loop:
        if GPIO.1=1 then turn1
        if GPIO.2=1 then turn2
        goto loop
    
    turn1:
        for i=0 to 5
            pulsout 0, 147
            pause 20
            next i
        goto loop
    
    turn2:
        for i=0 to 5
            pulsout 0, 152
            pause 20
            next i
        goto loop
    Also, make sure you set MCLR pin to +5V OR you disable it at programming time.

    Same for internal OSC.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Feb 2013
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: Input problems with 12F629?

    hi there

    can you tell me from where you got the syntax " PAUSE ..." in your pgm !

    I am using C language and dont know such a syntax

  4. #4
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Input problems with 12F629?

    Loop is one of those reserved words in PBP3 and I'm pretty sure in earlier versions. It really fouls things up.

    If your inputs and outputs are either high or low you want to set all your pins to digital with analog select register. i.e ansel=0. Otherwise the pins get sensed in the middle and often never toggle.

    if you want gpio.0 to be low then I think you need low gpio.0 not just low 0.

    I've never used PULSOUT before but I'm certain you need to spell out gpio.0 and not just 0

    Most people recommend a CLEAR at beginning and a END at end.

    I'd also recommend you turn on capitalization of commands in PBP. It helps me recognize some of the reserved words and commands.

    If you'll post schematic I'll run it on simulator if you like.

    Code:
    clear 
    Define OSCCAL_1K 1 
    CMCON=7 ' disable analog comparator
    ansel=0
    TRISIO=111110 ' set GPIO as output
                     ' others as input
    i VAR BYTE
    
    ' commented out low 0
    low gpio.0
    
    pause 100
    
    ' commented outloop:
    main:
        if GPIO.1=1 then turn1
        if GPIO.2=1 then turn2
    '  commented out   goto loop
    goto main
    
    turn1:
        for i=0 to 5
    ' comment out        pulsout 0, 147
    pulsout gpio.0, 147
            pause 20
            next i
    ' commented out    goto loop
    goto main
    
    turn2:
        for i=0 to 5
    ' comment out        pulsout 0, 152
    pulsout gpio.0, 152       
            pause 20
            next i
    'commented out    goto loop
    goto main
    
    end

  5. #5
    Join Date
    Feb 2013
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re:syntax for loop delay with 12F629?

    thanks avionics master.

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


    Did you find this post helpful? Yes | No

    Default Re: syntax for loop delay with 12F629?

    This one should work ... ( ISIS tells so ... )

    Code:
    '****************************************************************
    '*  Name    : SERVOTEST0                                        *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 10/02/2013                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : 12F629 @4 Mhz internal                            *
    '*          :                                                   *
    '****************************************************************
    
    #CONFIG
       __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _CP_OFF & _MCLRE_OFF
    #ENDCONFIG
    
    Servo   var GPIO.0
    Right   var GPIO.1
    Left    var GPIO.2
    
    Define OSCCAL_1K 1 
    CMCON   =7 ' disable analog comparator
    ' ansel=0  NO ANSEL with the '629 !!!...
    TRISIO  = %11111110 ' set GPIO as output
                     ' others as input
    i VAR BYTE
    clear 
    
    low Servo
    pause 100
    
    ' commented outloop:
    main:
    
    while 1
        IF Right THEN
            pulsout Servo, 147
        ELSEIF Left THEN
            PULSOUT Servo, 152
        ELSE
            PULSOUT Servo, 150  ' Center/stop ( ? ) if no button pushed ...   
        ENDIF
        
        Pause 19
        
    WEND
           
    end
    Alain
    Last edited by Acetronics2; - 10th February 2013 at 16:12.
    ************************************************** ***********************
    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
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Input problems with 12F629?

    you can use Loop in PBP 2.6 and lower, but I agree it should have been a reserved word back then.
    I've see some samples of code online that use it. Those sites will need to update their code when 3.0 becomes the standard

  8. #8
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Input problems with 12F629?

    Just sayin' according to page 19 of http://ww1.microchip.com/downloads/e...doc/41190c.pdf you need to configure ansel and cmcon to get digital ports. Page 44 tells you how to set up the ANSEL register.

    Shouldn't the clear be the first line of the program?

    I'd also add a goto main after the WEND or it will only do the movement once.

    Just curious, why pause 19? Is that the minimum time for all the stuff to settle out?

  9. #9
    Join Date
    May 2009
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Re: Input problems with 12F629?

    ANSEL and CMCON are only required for a 12f675 that has analog input capability. A12f629 does not have analog inputs so these commands are not required for the 12f629.
    The clear command is not required and the variable "I" is also not needed as there are no for/ next loops in the program. A While 1 / wend forms a continuous forever loop so the goto command after the wend is not required. The pause 19 is in the loop so that the pulses are send every 19 milliseconds which is the repeat rate required by the servo decoder.

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: Input problems with 12F629?

    Hi, Graham

    Good !

    1) I wanted to wipe line about " I var " ... but timeout for editing post caught me !!! - seriously - that doesn't change anything to the produced Hex , as it's just a compiler directive ...

    2) I also wanted to add
    Code:
    LOW Servo
    just before each PULSOUT Command ... BTW ... could you tell us why ?
    to understand the "why" ... just plug and unplug the servo plug for 5 or 6 times in a row ... with power ON

    and 3) ... CLEAR might much better be after declaring the variables ... no ???

    and ... 4) BINARY numbers must be written %01010101 ... for
    Code:
    TRISIO =
    Everything told now !

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

  11. #11
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Input problems with 12F629?

    Thanks for straightening me out. You learn something new every day.

  12. #12
    Join Date
    Mar 2008
    Posts
    59


    Did you find this post helpful? Yes | No

    Default Re: Input problems with 12F629?

    I have read this thread several times and looked at the datasheet several time as well. I am having problems with code that has worked fine in the past and suddenly I can not make GPIO.0 and GPIO.3 function as inputs. This is the code I have used in the past. I have added a TRISIO statement and this does not seem to help either. “TRISIO = %11001011”
    This code works on GPIO.1 but not on GPIO.0 and GPIO.3. I have used three ICs and continue to have no luck?

    #IF __PROCESSOR__ = "12F629"
    #DEFINE MCU_FOUND 1
    #CONFIG
    cfg = _INTRC_OSC_NOCLKOUT ; INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN
    cfg&= _WDT_ON ; WDT enabled
    cfg&= _PWRTE_OFF ; PWRT disabled
    cfg&= _MCLRE_OFF ; GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD
    cfg&= _BODEN_ON ; BOD enabled
    cfg&= _CP_ON ; Program Memory code protection is enabled
    cfg&= _CPD_OFF ; Data memory code protection is disabled
    __CONFIG cfg
    #ENDCONFIG
    #ENDIF
    #IFNDEF MCU_FOUND
    #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
    #ENDIF

    CMCON = 7
    SYMBOL LTIN = GPIO.0 'input
    SYMBOL RTIN = GPIO.1 'input
    SYMBOL LTOUT = GPIO.2 'output
    SYMBOL FOURIN = GPIO.3 'input
    SYMBOL RTOUT = GPIO.4 'output
    SYMBOL PEIZO = GPIO.5 'output

    Over:
    IF LTIN = 1 THEN HIGH PEIZO
    IF LTIN = 0 THEN LOW PEIZO
    IF RTIN = 1 THEN HIGH PEIZO
    IF RTIN = 0 THEN LOW PEIZO
    IF FOURIN = 1 THEN HIGH PEIZO
    IF FOURIN = 0 THEN LOW PEIZO

    GOTO OVER

  13. #13
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    574


    Did you find this post helpful? Yes | No

    Default Re: Input problems with 12F629?

    See this post : http://www.picbasic.co.uk/forum/show...=7072#post7072
    Maybe is useful !

  14. #14
    Join Date
    Mar 2008
    Posts
    59


    Did you find this post helpful? Yes | No

    Default Re: Input problems with 12F629?

    I just found my problem. It was these two lines

    SYMBOL RTOUT = GPIO.4

    SYMBOL PEIZO = GPIO.5

    I had changed my board on the last run and forgot to change the pin numbers in the code. The input was working fine it was the output the whole time.My silly mistake

    SYMBOL RTOUT = GPIO.5

    SYMBOL PEIZO = GPIO.4

    I am back up and running thank You for your reply!

Similar Threads

  1. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 02:50
  2. Input problems
    By ALFRED in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd July 2006, 22:02
  3. Using GPIO.3 as input on 12F629
    By Sharky in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th May 2006, 20:41
  4. Input on 12F629
    By BGreen in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th March 2005, 12:14
  5. 12F629 I2C problems
    By AIW128ProGuy in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 12th November 2004, 00:41

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