Menu

CCP1 and Pull Up Conflict on PIC 18F1220

Help
Capaction
2011-01-06
2013-05-30
  • Capaction

    Capaction - 2011-01-06

    I have a Hall Sensor on Pin 18 CCP1/RB3.
    Can I use the internal PullUp on Port B ?
    It worked fine on the PIC 16F628-A but does not on the PIC 18F1220 ! Why ?

     
  • gcha44

    gcha44 - 2011-01-07

    Capture mode uses either Timer1 or Timer3 on 18F1220 . You must verify this :

    "15.3.2 TIMER1/TIMER3 MODE SELECTION
    The timers that are to be used with the capture feature
    (either Timer1 and/or Timer3) must be running in Timer
    mode or Synchronized Counter mode. In Asynchronous
    Counter mode, the capture operation may not
    work. The timer to be used with each CCP module is
    selected in the T3CON register."

    But if does not work ,can you post your PIC configurations and your pieces of code on 16F628 and 18F1220 ?
    Regards
    GC

     
  • Capaction

    Capaction - 2011-01-07

    The following code works very well,  vith a 5V pull up on all pins port B:
    'PCB shematic =>  http://capaction.free.fr/Schem110912.jpg
    #chip 16f628A,4 '4MHz
    #config osc = intosc 'otherwise GCB chooses the external OSC !
    #config MCLRE = off '?

    DIR PortB IN
    Set NOT_RBPU OFF 'enable PullUps PortB
    Dir PortA.1 OUT
    #Define LED PortA.1
    Dir PortA.2 OUT 'PIN 1
    Dir PortA.3 OUT 'PIN 2
    #Define COIL1 PortA.2 'PIN 1 First  COIL
    #Define COIL2 PortA.3 'PIN 2 Second COIL

    Main:
    Repeat 3
    Set Led Off
    wait 1 s
    Set Led On
    wait 1 s
    End Repeat

    'PIN9 SENSOR 5V latched in front of south pole
    #Define SENSORon  PortB.3 = off'OV released in front of north pole
    #Define SENSORoff PortB.3 = on '5V latched in front of south pole

    Ignition:
    DO while SENSORon
    wait 11000 us '1/2 turn 2000 RPM
    set  COIL1 on 'Start loading COIL 1
    wait 4000 us 'Loading Time
    set  COIL1 off 'Ignition COIL 1
    wait 11000 us '1/2 turn 2000 RPM
    set  COIL2 on 'Start loading COIL 2
    wait 4000 us 'Loading Time
    set  COIL2 off 'Ignition COIL 2
    LOOP
    Goto Main
    The same code modified for the PIC18F1220 also works but there is no pull up on B0, B1, B4  ? ? ?
    'PCB shematic =>  http://capaction.free.fr/Schem110107.jpg
    #chip 18f1220,8   
    #Config LVP = OFF, MCLRE = On, PWRT = On, WDT = off, BOR = Off, OSC = INTIO1
    DIR PortB IN
    Set NOT_RBPU OFF 'do not enable PullUps PortB0, B1 B4 ? ?
    Dir PortA.4 OUT
    #Define LED PortA.4
    Dir PortA.0 OUT 'PIN 1
    Dir PortA.1 OUT 'PIN 2
    #Define COIL1 PortA.0 'PIN 1 First  COIL
    #Define COIL2 PortA.1 'PIN 2 Second COIL

    Main:
    Repeat 3
    Set Led Off
    wait 1 s
    Set Led On
    wait 1 s
    End Repeat

    'PIN18 SENSOR 5V latched in front of south pole
    #Define SENSORon  PortB.3 = off 'OV released in front of north pole
    #Define SENSORoff PortB.3 = on  '5V latched in front of south pole

    Ignition:
    DO while SENSORon
    wait 11000 us '1/2 turn 2000 RPM
    set  COIL1 on 'Start loading COIL 1
    wait 4000 us 'Loading Time
    set  COIL1 off 'Ignition COIL 1
    wait 11000 us '1/2 turn 2000 RPM
    set  COIL2 on 'Start loading COIL 2
    wait 4000 us 'Loading Time
    set  COIL2 off 'Ignition COIL 2
    LOOP
    Goto Main

     
  • gcha44

    gcha44 - 2011-01-07

    Your code seems correct for 18F1220 , except PortB0 , 1 and 4  which are configured as analog inputs (AN4 , 5 and 6) after reset and read as "0" . You must configure them as digital input by manually setting bits 4,5 and 6 of  ADCON1 register

    Because in 18F1220 datasheet chapter 10.0 I/O ports , you read :

    "Each of the PORTB pins has a weak internal pull-up. A
    single control bit can turn on all the pull-ups. This is performed
    by clearing bit RBPU (INTCON2<7>). The
    weak pull-up is automatically turned off when the port
    pin is configured as an output. The pull-ups are
    disabled on a Power-on Reset."
    and a very important Note:
    " On a Power-on Reset, RB4:RB0 are configured
    as analog inputs by default, and
    read as ‘0’; RB7:RB5 are configured as
    digital inputs."

    So , to  configure PortB0 , B1,B4 as digital inputs you must set  bits 4 , 5 and 6  of ADCON1 register
    ( see 17-2 of datasheet ADCON1 register , 10-2 PORTB  and example 10-2 "initializing PortB")

    Regards
    GC

     
  • Nobody/Anonymous

    Looks like GCBasic gets tripped up with the 18f1220, and does a clrf ADCON1 in the INITSYS sub of the compiled.asm file.  Tried compiling the very same code with a 18f1330 (and most others AFAIK), and it successfully sets the PCFG0-3 bits of ADCON1 in the INITSYS sub

    Kent.

     
  • Capaction

    Capaction - 2011-01-09

    Thank you  GC
    This code on both 18F1220 and 18F1320 gives the Pull Up on all  PortB pins

    Set PCFG4 = 1 'pin  8  configured as digital port B0
    Set PCFG5 = 1 'pin  9  configured as digital port B1
    Set PCFG6 = 1 'pin 10 configured as digital port B4
    DIR PortB IN
    Set NOT_RBPU OFF 'enable PullUps all PortB digital input (OK with scope)

    Kent  I don't know if it is correct ?
    Program compiled by Great Cow BASIC (0.9 10/9/2010) gives with PIC18F1220 and PIC1320 the same result

    INITSYS
    movlw 112
    iorwf OSCCON,F,ACCESS
    clrf BSR,ACCESS
    clrf TBLPTRU,ACCESS
    bcf ADCON0,ADON,ACCESS
    bcf ADCON2,ADFM,ACCESS
    clrf ADCON1,ACCESS
    clrf PORTA,ACCESS
    clrf PORTB,ACCESS
    return

     
  • kent_twt4

    kent_twt4 - 2011-06-23

    Our friendly spamster nobody is at it again, with over 300+ posts.  So this thread is closed.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.