Portc.3 latching?


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2006
    Posts
    21

    Default Portc.3 latching?

    Hi guys,

    I'm having a problem with Portc.3 (Pin 18 PIC16F877A). I have it tied to a 4.7k ohm resistor to +5V.
    When I pull it (pin 18) to ground and hold it there for more than a few seconds, the pin seems to latch up and stay there (at 0v) when I remove the ground.
    Here is the bit of code.
    I have re-read the data sheets and I don't see anything special about portc.3 except SPI? Am I missing something?

    DEFINE OSC 8' USE 8MHZ CRYSTAL OSC.
    DEFINE ADC_BITS 10' Number of bits in Adcin result
    ' +VREF= 2 VOLTs SO 1 = .00195V OR ~ 2MV
    DEFINE CCP1_REG PORTC' Hpwm channel 1 pin port
    DEFINE CCP1_BIT 2' Hpwm channel 1 pin bit
    DEFINE CCP2_REG PORTC' Hpwm channel 2 pin port
    DEFINE CCP2_BIT 1' Hpwm channel 2 pin bit
    DEFINE HSER_RCSTA 90h' Set RECIEVE Enabled
    DEFINE HSER_TXSTA 24h' Set XMIT Enabled HS
    DEFINE HSER_BAUD 4800' BAUD RATE
    DEFINE HSER_CLROERR 1' CLEAR OVER RUN ERRORS
    DEFINE CHAR_PACING 1000' CHAR PACING(uSEC) TO 1MS
    '
    '**************** SET UP I/O PORTS ****************************
    '
    TRISA=%00001111' SET UP PORTA I/O (1=IN,0=OUT)
    TRISB=%11001000' SET UP PORTB I/O
    TRISC=%10001000' SET UP PORTC I/O
    ADCON1=%10100101' USE PORTA.3 PIN5 AS VREF+ @ 2.0VDC
    ADCON0=%01000000' A/D OFF -- RIGHT JUSTIFY. 6MSB=0 ADRESH
    '
    '************* ALLOCATE VARIABLES *******************
    '
    SWDN VAR PORTC.0' ~SWDN ZEROS INTEGRATE REGISTER'
    HIGH SWDN' NOT YET
    ZERO VAR PORTB.4' ~ZERO PORT
    HIGH ZERO' NOT YET
    INTEG VAR PORTC.4' ~INTERGRATE PORT
    HIGH INTEG' NOT YET
    VACPMP VAR PORTB.5' VACUUM PUMP PORT
    LOW VACPMP ' TURN IT OFF
    RTS VAR PORTA.5' REQ TO SEND IL1700
    BLEDOUT VAR PORTD.1' BLUE LED ENABLE ICD
    HIGH BLEDOUT' ENSURE BLUE LED IS OFF
    RLEDOUT VAR PORTD.2' RED LED ENABLE ICD
    HIGH RLEDOUT' ENSURE RED LED IS OFF
    BLUELVL VAR WORD' BLUE LED LEVEL (0-100%)
    DISTALCNT VAR BYTE' NUMBER OF TESTS RUN ON BUNDLE
    REDLVL VAR WORD' RED LED LEVEL (0-100%)
    FLASHED VAR BYTE' USE FOR COUNTING
    X VAR BYTE' USE FOR LOOP COUNTING
    REDCUR VAR WORD' RED LED DRIVE CURRENT
    BLUCUR VAR WORD' BLUE LED DRIVE CURRENT
    REDSNS VAR WORD' RED LED SENSE CURRENT
    BLUSNS VAR WORD' BLUE LED SENSE CURRENT
    BLUPRCNT VAR WORD' ALIAS TO DISPLAY ROUGH PERCENTAGE
    REDPRCNT VAR WORD' ""
    PROX_IN VAR BIT
    REDDONE VAR BIT
    BLUEDONE VAR BIT
    SERLOOP VAR BYTE
    INCOM VAR WORD' SERIAL DATA
    '-=-=-=-=-=-=-=-=-=-=-=-=-=-=- MAIN -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    CLEAR' SET ALL VARIABLE LOW
    BLUCUR = 242'
    REDCUR = 153'
    HSERIN [WAIT("*"),INCOM]' COULD BE ANYTHING HERE... USE *START
    BLUPRCNT = (BLUCUR-50)/2
    REDPRCNT = (REDCUR-50)/2
    HSEROUT ["RUNNING",13,10]
    HSEROUT ["CURRENT SETTINGS ARE:",13,10]
    HSEROUT ["RED IS SET TO:",dec REDPRCNT,"%",13,10]
    HSEROUT ["BLUE IS SET TO:",dec BLUPRCNT,"%",13,10]
    PAUSE 1000
    HSEROUT ["---------------------------------------------------",13,10]
    GOSUB BEGIN'
    BEGIN:
    BLEDOUT = 0' TURN BLUE LED ON
    HPWM 2, BLUCUR, 5000' AND SET CURRENT
    PAUSE 200' SETTLE 200MS
    ADCON0 = %01001101' BLUE ADC
    ADCIN 1, BLUELVL' READ IT
    PAUSE 10' A/D FOR 10MS
    BLEDOUT = 1' TURN BLUE OFF
    RLEDOUT = 0' TURN RED ON
    HPWM 1, REDCUR, 5000
    PAUSE 200' SETTLE 200MS
    ADCON0=%01000001' RED A/D
    ADCIN 0, REDLVL
    PAUSE 10' A/D FOR 10MS
    RLEDOUT = 1' TURN RED OFF
    hpwm 1, 0, 0' STOP WHINING
    HPWM 2, 0, 0
    REDLVL=REDLVL/2
    BLUELVL=BLUELVL/2
    PAUSE 10'
    HSEROUT [13,10]'
    HSEROUT ["RED LED SETTING =",DEC REDCUR,32,13,10]
    HSEROUT ["RED MEASURES: ",dec REDLVL,"MA.",13,10]
    HSEROUT ["BLUE LED SETTING =",DEC BLUCUR,32,13,10]
    HSEROUT ["BLUE MEASURE: ",DEC BLUELVL,"MA.",13,10]
    HSEROUT [13,10]' CR LF *
    HSEROUT ["CHANGE LED SETTINGS? (Y/N)"]' PC ADD PREFIX "*"
    HSERIN [WAIT("*"),INCOM]'
    IF INCOM == "Y" THEN GOSUB RS232LOOP
    IF INCOM == "N" THEN
    HSEROUT [13,10,"INSERT DISTAL END",13,10]'
    GOTO WAIT_PROX
    ENDIF
    GOTO BEGIN
    RETURN
    WAIT_PROX:
    BLUELVL = BLUCUR '
    REDLVL = REDCUR '
    HPWM 1, 0,0' NO NEED TO WHINE
    HPWM 2, 0,0' TURN BOTH OFF
    IF PORTC.3 == 0 THEN GOTO PROX_DET' CHECKing
    GOTO WAIT_PROX' TIGHT LOOP
    '---------------------------PROX DET---------------------------
    PROX_DET:
    HSEROUT["DISTAL END DETECTED. TURNING ON PUMP",13,10]
    DISTALCNT = DISTALCNT+1'
    HSEROUT["TESTING DISTAL END ",DEC DISTALCNT,32,13,10,13,10]
    HPWM 1, BLUELVL, 5000' SET BLUE CURRENT LEVEL 5KHZ
    HPWM 2, REDLVL, 5000' SET RED CURRENT LEVEL 5KHZ
    VACPMP = 1' TURN ON VACUUM PUMP
    PAUSE 100' WAIT 100 MSEC
    GOTO DO_TESTING
    DO_TESTING:
    IF REDDONE==0 THEN GOTO RED_LED_LOOP
    IF ((REDDONE==1) AND (BLUEDONE ==0)) THEN
    GOTO BLUE_LED_LOOP
    ELSE
    IF ((REDDONE ==1) AND (BLUEDONE==1)) THEN GOTO FINISH
    GOTO DO_TESTING
    ENDIF
    FINISH:
    LOW VACPMP' ----- TURN VACUUM PUMP OFF -----------------------
    HSEROUT["TURNING PUMP OFF",13,10]
    REDDONE=0' GET READY FOR ANOTHER TEST
    BLUEDONE=0
    HPWM 1,0,0
    HPWM 2,0,0
    FLASHED = 0
    PAUSE 10'
    IF PORTC.3 == 1 THEN
    HSEROUT [13,10,"INSERT NEXT DISTAL END",13,10]'
    GOTO WAIT_PROX
    ELSE
    HSEROUT ["PLEASE REMOVE DISTAL END ",DEC DISTALCNT,32,13,10]
    GOTO FINISH
    ENDIF
    END

    Everything works as it should except for the latching problem of the PORTC.3.
    I am using LAB-X1 for the hardware.
    Thanks!
    Last edited by Bronurstomp; - 6th November 2008 at 19:38.
    The less you expect, the more you get.

  2. #2
    Join Date
    Feb 2006
    Posts
    21


    Did you find this post helpful? Yes | No

    Talking NVM Is it Friday yet?

    Sigh... I had PortC.0 shorted to PortC.3 on the LAB-X1 U7 pin 2-3 after putting in R11. So all I had to do was change SWDN to another port... Namely PORTD.3.

    Anyway, the code above is working very well, for any of those interested in using HSERIN to start and stop your PIC via RS-232.

    So, I fixed my own problem. By the way, if anyone is thinking of buying a developers bundle I highly recommend getting Codestudio PLUS... the added support for the ICD is extrememly helpful when debugging these PICs.
    The LAB-X1 board is very nice, after the initial intimidation wears off and you understand it... like most things.
    Cheers!
    The less you expect, the more you get.

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


    Did you find this post helpful? Yes | No

    Default

    With all of your code crammed together, and no code tags, it's really hard to read it all, but you might want to look for more instances of things like this;

    GOSUB BEGIN'
    BEGIN:
    Regards,

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

  4. #4
    Join Date
    Feb 2006
    Posts
    21


    Did you find this post helpful? Yes | No

    Default Where to begin

    1st, I crammed everything to gether for this post. My code looks much nicer than that.
    But it does bring up a question I had: Where does the PIC start excecuting? If I don't tell it where to start?
    And right I changed
    GOSUB BEGIN
    BEGIN:
    to
    GOTO BEGIN
    BEGIN:
    Is that better? If I didn't put that there where would the PIC have begun running? Right after the BEGIN: label? ie

    BLEDOUT = 0' TURN BLUE LED ON ??
    The less you expect, the more you get.

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


    Did you find this post helpful? Yes | No

    Default

    The program will start at the very top of your code, and will execute each following lines. You don't need the GOTO BEGIN.
    Steve

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

Similar Threads

  1. A logic gate chip with 1 ea XOR and 2 ea AND gates?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 5th August 2009, 05:29
  2. Serin2 - All I Need Is 8 Numbers....
    By SOMRU in forum Serial
    Replies: 4
    Last Post: - 14th December 2006, 13:50
  3. Serout2/serin2 Pbp Problem
    By SOMRU in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th December 2006, 19:55
  4. Newbie - 16F628A and switch latching
    By malc-c in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 19th May 2006, 02:35
  5. flip flop for driving latching solenoids
    By kitcat in forum Schematics
    Replies: 3
    Last Post: - 4th February 2006, 22:34

Members who have read this thread : 0

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