Problems with RC2 and RC3


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425

    Default Problems with RC2 and RC3

    Hi,

    I am using a program on a 16F870 where all pins are outputs with the exception of portc.7. I can activate each output one by one and turn them off with no problems. When I try to activate portc.2 and portc.3 with all other outputs active, they only turn others off and I can't understand why. Said differntly, they work fine by themselves but when combined with other outputs, the operation is not what was expected. Can anyone shed some light on this?

  2. #2
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Code Please

    Hi,

    Please post the code otherwise it is difficult to understand your exact problem.
    Regards

    Sougata

  3. #3
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default

    Ok, I don't like to post the code because it's not written very well and I am not an expert but maybe someone can help me. Here is the code:

    @ DEVICE PIC16F870, HS_OSC, WDT_OFF, PWRT_ON, BOD_ON, LVP_OFF , DEBUG_OFF, PROTECT_OFF

    DEFINE OSC 20
    DEFINE HSER_BAUD 2400
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_CLROERR 1
    ADCON1=7
    b1 var WORD 'first of 4 vars to store verified good data
    b2 var WORD
    b3 var WORD
    b4 var WORD
    in1 var WORD 'first of 4 vars to store incoming data
    in2 var WORD
    in3 var WORD
    in4 var WORD
    start var byte 'first incoming byte - should be zero
    sum var WORD 'incoming checksum from the sending PIC
    datasum var WORD 'used to add values of 4 incoming data bytes
    errorflag var bit 'flag to indicate bad data (1 = bad or untested data)


    TRISA = %00000000
    TRISC = %10000000
    TRISB = %00000000
    TRISD = %00000000
    pause 100

    PORTB.0=0
    PORTB.1=0
    PORTB.2=0
    PORTB.3=0
    PORTB.4=0
    PORTB.5=0
    PORTB.6=0
    PORTB.7=0
    PORTA.0=0
    PORTA.1=0
    PORTA.2=0
    PORTA.3=0
    PORTA.4=0
    PORTA.5=0
    PORTA.6=0
    PORTA.7=0
    PORTC.0=0
    PORTC.1=0
    PORTC.2=0
    PORTC.3=0
    PORTC.4=0
    PORTC.5=0
    PORTC.6=0






    mainloop:
    IF RCSTA.1 = 1 THEN 'if USART overrun error flag OERR is set...
    RCSTA.4 = 0 'clear and then set CREN bit to recover
    RCSTA.4 = 1
    in1 = RCREG 'read data to clear out RCREG
    IF PIR1.5 = 1 THEN in1 = RCREG 'clear possible 2nd byte in RCREG
    ENDIF

    WHILE PIR1.5 = 0 'stay here until USART receives data

    'LOW portc.3 'portc.3 has diagnostic LED
    WEND


    'HIGH portc.3 'data in RCREG; turn on diagnostic LED

    errorflag = 1
    GOSUB getdata

    IF errorflag = 0 THEN 'only updates relays if data judged to be good


    if b1=0 and b2=1 and b3=11 THEN GOSUB ONN1
    if b1=0 and b2=1 and b3=12 THEN GOSUB OFF1
    if b1=0 and b2=2 and b3=11 THEN GOSUB ONN2
    if b1=0 and b2=2 and b3=12 THEN GOSUB OFF2
    if b1=0 and b2=3 and b3=11 THEN GOSUB ONN4
    if b1=0 and b2=3 and b3=12 THEN GOSUB OFF4
    if b1=0 and b2=4 and b3=11 THEN GOSUB ONN3
    if b1=0 and b2=4 and b3=12 THEN GOSUB OFF3
    if b1=0 and b2=5 and b3=11 THEN GOSUB ONN5
    if b1=0 and b2=5 and b3=12 THEN GOSUB OFF5
    if b1=0 and b2=6 and b3=11 THEN GOSUB ONN6
    if b1=0 and b2=6 and b3=12 THEN GOSUB OFF6
    if b1=0 and b2=7 and b3=11 THEN GOSUB ONN7
    if b1=0 and b2=7 and b3=12 THEN GOSUB OFF7
    if b1=0 and b2=8 and b3=11 THEN GOSUB ONN8
    if b1=0 and b2=8 and b3=12 THEN GOSUB OFF8
    if b1=0 and b2=9 and b3=11 THEN GOSUB ONN0
    if b1=0 and b2=9 and b3=12 THEN GOSUB OFF0
    if b1=1 and b2=0 and b3=11 THEN GOSUB ONN9
    if b1=1 and b2=0 and b3=12 THEN GOSUB OFF9
    if b1=1 and b2=1 and b3=11 THEN GOSUB ONN11
    if b1=1 and b2=1 and b3=12 THEN GOSUB OFF11
    if b1=1 and b2=2 and b3=11 THEN GOSUB ONN13
    if b1=1 and b2=2 and b3=12 THEN GOSUB OFF13
    if b1=1 and b2=3 and b3=11 THEN GOSUB ONN12
    if b1=1 and b2=3 and b3=12 THEN GOSUB OFF12
    if b1=1 and b2=4 and b3=11 THEN GOSUB ONN14
    if b1=1 and b2=4 and b3=12 THEN GOSUB OFF14
    if b1=1 and b2=5 and b3=11 THEN GOSUB ONN16
    if b1=1 and b2=5 and b3=12 THEN GOSUB OFF16
    if b1=1 and b2=6 and b3=11 THEN GOSUB ONN15
    if b1=1 and b2=6 and b3=12 THEN GOSUB OFF15
    if b1=9 and b2=9 and b3=11 then gosub allon
    if b1=9 and b2=9 and b3=12 then gosub alloff
    ENDIF

    goto mainloop:


    getdata:
    IF RCSTA.1 = 1 THEN xfer 'USART overflow error - bad data
    HSERIN 40, xfer, [start, in1, in2, in3, sum]
    IF start <> 0 THEN xfer 'if first byte isn't 0 assume bad data
    datasum = in1 + in2 + in3 'add the 4 bytes and compare to sum
    IF datasum = sum THEN errorflag = 0 'if compare is good, assume good data
    xfer:
    IF errorflag = 0 THEN
    B1 = in1
    b2 = in2
    b3 = in3


    ENDIF
    RETURN

    ONN1:
    HIGH PORTB.7
    goto mainloop
    OFF1:
    LOW PORTB.7
    GOTO MAINLOOP

    ONN2:
    HIGH PORTB.3
    goto mainloop
    OFF2:
    LOW PORTB.3
    GOTO MAINLOOP

    ONN3:
    HIGH PORTB.4
    goto mainloop
    OFF3:
    LOW PORTB.4
    GOTO MAINLOOP

    ONN4:
    HIGH PORTA.3
    goto mainloop
    OFF4:
    LOW PORTA.3
    GOTO MAINLOOP

    ONN5:
    HIGH PORTB.5
    goto mainloop
    OFF5:
    LOW PORTB.5
    GOTO MAINLOOP

    ONN6:
    HIGH PORTA.2
    goto mainloop
    OFF6:
    LOW PORTA.2
    GOTO MAINLOOP

    ONN7:
    HIGH PORTC.2
    goto mainloop
    OFF7:
    LOW PORTC.2
    GOTO MAINLOOP

    ONN8:
    HIGH PORTC.3
    goto mainloop
    OFF8:
    LOW PORTC.3
    GOTO MAINLOOP:

    ONN9:
    HIGH PORTC.1
    GOTO MAINLOOP
    OFF9:
    LOW PORTC.1
    goto mainloop

    ONN0:
    HIGH PORTC.0
    GOTO MAINLOOP
    OFF0:
    LOW PORTC.0
    goto mainloop

    ONN11:
    HIGH PORTA.5
    GOTO MAINLOOP
    OFF11:
    LOW PORTA.5
    goto mainloop

    ONN12:
    HIGH PORTB.1
    GOTO MAINLOOP
    OFF12:
    LOW PORTB.1
    goto mainloop

    ONN13:
    HIGH PORTB.0
    GOTO MAINLOOP
    OFF13:
    LOW PORTB.0
    goto mainloop

    ONN14:
    HIGH PORTC.5
    GOTO MAINLOOP
    OFF14:
    LOW PORTC.5
    goto mainloop

    ONN15:
    HIGH PORTB.2
    GOTO MAINLOOP
    OFF15:
    LOW PORTB.2
    goto mainloop

    ONN16:
    HIGH PORTC.4
    GOTO MAINLOOP
    OFF16:
    LOW PORTC.4
    goto mainloop

    alloff:
    LOW PORTA.2
    LOW portc.4
    LOW portb.2
    LOW portc.5
    LOW portb.0
    LOW portb.1
    LOW PORTB.5
    LOW porta.5
    LOW portc.0
    LOW portc.1
    LOW portc.2
    LOW portc.3
    LOW porta.3
    LOW portb.3
    LOW portb.4
    LOW portb.7
    goto mainloop

    allon:

    PORTB.0=1
    PORTB.1=1
    PORTB.2=1
    PORTB.3=1
    PORTB.4=1
    PORTB.5=1
    PORTB.6=1
    PORTB.7=1
    PORTA.0=1
    PORTA.1=1
    PORTA.2=1
    PORTA.3=1
    PORTA.4=1
    PORTA.5=1
    PORTA.6=1
    PORTA.7=1
    PORTC.0=1
    PORTC.1=1
    PORTC.2=1
    PORTC.3=1
    PORTC.4=1
    PORTC.5=1
    PORTC.6=1

    goto mainloop

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


    Did you find this post helpful? Yes | No

    Default

    O.k, there's few thing to be removed first..
    Code:
    mainloop:
        IF RCSTA.1 = 1 THEN 'if USART overrun error flag OERR is set...
           RCSTA.4 = 0 'clear and then set CREN bit to recover
           RCSTA.4 = 1
           in1 = RCREG 'read data to clear out RCREG
           IF PIR1.5 = 1 THEN in1 = RCREG 'clear possible 2nd byte in RCREG
           ENDIF
    DEFINE HSER_CLROERR 1 do this for you. Remove those line.

    Code:
        WHILE PIR1.5 = 0 'stay here until USART receives data
              'LOW portc.3 'portc.3 has diagnostic LED
              WEND
    
        'HIGH portc.3 'data in RCREG; turn on diagnostic LED
    While your program do nothing usefull there, simply remove those line and replace it simply for HSERIN.

    Code:
    if b1=0 and b2=1 and b3=11 THEN GOSUB ONN1
    .
    .
    .
    Should be writen like..
    Code:
    if (b1=0) and (b2=1) and (b3=11) THEN GOSUB ONN1
    Code:
    ONN1:
    HIGH PORTB.7
    goto mainloop
    You jump to ONN1 with a gosub, it must be terminated with a RETURN to avoid stack overflow. Replace GOTO MAINLOOP by a simple RETURN.

    Multiple PORTA.0=0, PORTA.1=0, ... can be replace with a single line. In your example you set all PORTA bit to zero. It's working sure, but you can still use PORTA=0. Same for all PORTx to 1. Can be replace with PORTx=%11111111, PORTx=$FF or PORTx=255.

    Personnaly i would change it to something different..., let's try something.
    Code:
        TRISA  = %00000000
        TRISB  = %00000000
        TRISC  = %10000000
        ADCON1 = 7
    
        PORTx    var byte
        PORTbit  var byte
        BitState var byte    
    
        PORTA = 0
        PORTB = 0
        PORTC = 0
    
    mainloop:
        hserin 500,mainloop,[PORTx,DEC1 portbit, DEC1 bitstate]
        select case portx
               case "A"
                    PORTA.0(PORTBIT)=BITSTATE
               CASE "B"
                    PORTB.0(PORTBIT)=BITSTATE
               CASE "C"
                    PORTC.0(PORTBIT)=BITSTATE     
               END SELECT
        GOTO MAINLOOP
    With few chunk around it may be something to play with

    EDIT: also, there's no PORTD on the F870.. no warning or error using PM? I don't know how it's handle by PM but for sure, this will return you an error message when using MPASM...

    @Darrel,
    Yet another reason
    Last edited by mister_e; - 23rd May 2006 at 14:16.
    Steve

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

  5. #5
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Port C issues

    I have experimented more with trying to have all outputs on at the same time. Configured different ways, I have problems with portc.0, portc.1, portc.2 and portc.3. Has anyone ever tried to activate all ports on a 16F870, 876, 876A and been able to do it. Like I said, one by one they work fine but when I turn on all ports, I have difficulties with the ones mentioned above. I have tried 10 different PIC's so I am pretty sure it's not a hardware problem, there must be something in the software that needs to be changed.

    Chris

  6. #6
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile R-M-W Issues?

    What do you have connected to your port pins (e.g., LEDs, floating, etc.)?

    Have you tried something like this to test PORTC?

    For X = 0 to 255
    PORTC = X
    Pause 500
    NEXT X

    Paul Borgmeier
    Salt Lake City, Utah
    USA
    Last edited by paul borgmeier; - 29th May 2006 at 13:28.

  7. #7
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default

    That works. The problem is when you have all ports activated (porta, portb, portc), there are issues with only portc. Like I said before, all outputs work on portc by themselves but when combines with other outputs, portc.0 through portc.3 has problems. Any more suggestions? Can someone else try to activate all ports on a 16F870, 876, 876A and see if it works?

    Thanks,

    Chris

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


    Did you find this post helpful? Yes | No

    Default

    maybe you reach the maximum current source of your PIC. How about if you trade your LEDs to 1-10K resistors???
    Steve

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

  9. #9
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default

    The outputs are going to a ULN2003A and while I haven't measured it, the datasheet for the ULN2003A says it requires 1.2mA per pin.....this is well below the 200mA maximum by the PIC. The PIC is supplying roughly 19.2mA to activate the outputs.

  10. #10
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by Christopher4187
    ...Like I said before, all outputs work on portc by themselves but when combines with other outputs, portc.0 through portc.3 has problems.
    Call me slow, but I still do not understand. My suggested code in post #6 does activate combined pins of PORTC. If that worked, then I would try this:

    PORTA = 255
    pause 1000
    PORTB = 255
    pause
    For X = 0 to 15
    PORTC = X
    Pause 100
    NEXT X
    Pause 10000
    end

    and see if it is still weird.

    I was suspecting R-M-W issues as hinted in my subject line of post #6. Your code is full of R-M-W opportunity where the code above is not. If you still get weird results, you can rule out R-M-W issues. If your problem goes away, then it could be R-M-W.

    My question about what you had connected was exactly where Steve went – possibly to much current but it seems you have ruled that out.

    Paul Borgmeier
    Salt Lake City, Utah
    USA

  11. #11
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default

    Paul,

    I have located something abnormal. I took off all of the ULN2003A's from the board and I can get all of the outputs activated at the same time. Maybe current is the issue but it will require further investigation to determine where the problem exactly is.

    Thanks,

    Chris

  12. #12
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Success!

    I have located the problem. On the ULN2003A (the one for PORTC), the negative pin was not soldered.....I must have overlooked it. When the ULN was trying to draw more current, it wasn't able to because of the high resistance between ground and the negative pin. Thanks to all who helped.

    Chris

Similar Threads

  1. Can't get RC2 to go high with PORTC.2 = 1
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 13th September 2009, 07:26

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