18F6680 and portd problems.


Closed Thread
Results 1 to 11 of 11
  1. #1
    jkbh's Avatar
    jkbh Guest

    Default 18F6680 and portd problems.

    Hi,
    I have problems with portd.

    This program should make the bit3 output pin on portd go on and off at 1 hz.
    But it stays on all the time and sometimes other port pins on portd goes on.
    Why??

    My test program:

    '--- SETUP SECTION -----------------------------------------
    TRISA = %11001111 ' Set PORTA direction 1= input 0= output
    TRISB = %00000000 ' Set PortB Direction
    TRISC = %11000000 ' Set PortC Direction
    TRISD = %00000011 ' Set PortD Direction
    TRISE = %11111111 ' Set PortE Direction
    TRISF = %11111111 ' Set PortF Direction
    TRISG = %11111100 ' Set PortG Direction
    CMCON = 7
    ADCON1 = %00001011 ' AN0-AN3 used as analog inputs.Rest is digital.

    ' Defines.
    DEFINE ADC_BITS 8 'Number of bits in ADCIN result
    DEFINE HSER_RCSTA 90h ' Set receive register to receiver enabled
    DEFINE HSER_TXSTA 20h 'Set transmit register to transmitter enabled
    DEFINE HSER_BAUD 115200 ' Set baud rate
    DEFINE OSC 40 'Uses 40 MHz clock
    DEFINE ADC_SAMPLEUS 50 'ADC sampling time in microseconds
    'DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)

    '*Port Alias
    X1 var porte.6
    X2 var porte.7
    X3 var portd.0
    X4 var portd.1
    X5 var porte.5
    X6 var porte.4
    X7 var porte.2
    X8 var porte.3
    X9 var porte.1
    X10 var porte.0
    X11 var portg.3
    X12 var portg.4
    X13 var portf.7
    X14 var portf.6
    X15 var portf.5
    X16 var portf.4
    X17 var portf.2
    X18 var portf.3
    X19 var portf.1
    X20 var portf.0
    Y1 var lata.5
    Y2 var latc.2
    Y3 var latd.3
    Y4 var latd.7
    Y5 var latc.1
    Y6 var latc.5
    Y7 var latd.2
    Y8 var latb.1
    Y9 var lata.4
    Y10 var latc.4
    Y11 var latd.5
    Y12 var latb.2
    Y13 var latc.0
    Y14 var latb.5
    Y15 var latd.4
    Y16 var latb.3
    Y17 var latc.3
    Y18 var latb.4
    Y19 var latd.6
    Y20 var latb.0

    '* Variables
    AN1 var byte
    AN2 var byte
    AN3 var byte
    AN4 var byte
    T1 var word
    T2 var word
    T3 var word
    T4 var word
    T5 var word
    T6 var word
    T7 var word
    T8 var word
    T9 var word
    T10 var word
    C1 var word
    C2 var word
    C3 var word
    C4 var word
    C5 var word
    C6 var word
    C7 var word
    C8 var word
    C9 var word
    C10 var word
    SP1 var bit
    SP2 var bit
    SP3 var bit
    SP4 Var bit

    '----------------------------------------------------------------

    '--- Main Program begin -----------------------------------------
    Startup:
    HIGH Y3
    pause 500
    LOW Y3
    Pause 500
    goto Startup

    end

  2. #2
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Default

    Hi jkbh,

    I didn't take the time to look up the data sheet on this micro but:

    "Y3 var latd.3" At what point did you declare Portd.3 = latd.3?

    All of your X variables have been assigned to a port pin but none of the Y variables have a specific port assignment. I'm still a beginner at programming but this stood out to me.

    BobK

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


    Did you find this post helpful? Yes | No

    Default

    What are your config fuse settings?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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


    Did you find this post helpful? Yes | No

    Default

    Just recall that: why using Y3 var latd.3 instead of Y3 VAR PORTD.3?

    Just out of curiosity!!!
    Steve

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

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    On the 18F series, when you have a mixture of inputs & outputs on the
    same port, writing to the LAT register VS the port bit directly avoids the
    read-modify-write problem.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Thanks Bruce,

    I'll put that note in my handbook! That's what I like about this site. You always learn something!

    BobK

  7. #7
    jkbh's Avatar
    jkbh Guest


    Did you find this post helpful? Yes | No

    Default

    I´m gonna check my config bits tomorrow,but I think I have got it right.
    I know I have set:
    HS PLL mode.
    Power on timer enabled.
    Turned off watchdog.

    What config bits shall I use if I just want to use PORTD as Digital I/Os.
    /Jimmy

  8. #8
    jkbh's Avatar
    jkbh Guest


    Did you find this post helpful? Yes | No

    Default

    Hers my current Configuration Bits.

    I have put these in the 18F6680.INC file in the PBP directory.
    Is this the right way to do it?

    __CONFIG _CONFIG1H, _OSC_HSPLL_1H
    __CONFIG _CONFIG2L, _PWRT_ON_2L
    __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H
    __CONFIG _CONFIG4L, _LVP_OFF_4L & _STVR_OFF_4L
    __CONFIG _CONFIG5H, _CPD_OFF_5H
    __CONFIG _CONFIG6H, _WRTD_OFF_6H

    /Jimmy

  9. #9
    jkbh's Avatar
    jkbh Guest


    Did you find this post helpful? Yes | No

    Default

    I have now tested with a 18F6585 chip and it is same problem with this chip.
    The current drawn from each pin on portD is 0.2mA.Total of 1.6mA on portD so there is not to high load on the port.
    So I guess that there is something that I have forgotten to turn off or something.
    Now guys..Please help me!!

    /Jimmy

  10. #10
    jkbh's Avatar
    jkbh Guest


    Did you find this post helpful? Yes | No

    Default

    If I use ASM code in Picbasic it works.
    I did like this!!

    Startup:
    asm
    bsf LATD,5
    endasm

    pause 500


    asm
    bcf LATD,5
    endasm

    pause 500

    adcin 1,AN1
    adcin 2,AN2
    adcin 3,AN3
    ADCIN 5,AN4

    goto startup


    end


    WHY does it not work if I simple use HIGH and LOW LATD.5
    Is it a bug in PBP 2.44???

    /Jimmy

  11. #11
    jkbh's Avatar
    jkbh Guest


    Did you find this post helpful? Yes | No

    Default

    I solved the problem!

    I had bad through plating holes on my PCB.Almost all PortD bits had bad connection on the second layer.Hav fix it now and the portD works great.

    Thanks anyway!!
    /Jimmy

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