Can't get RC2 to go high with PORTC.2 = 1


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378

    Question Can't get RC2 to go high with PORTC.2 = 1

    As I continued my debugging I found another problem in my below code that I initially thought was also a read-modify-write problem that Charles Leo at meLabs previously corrected me on. But on closer inspection I don't think so. I am including my current ISR code below and would appreciate any help from anyone in looking at it to see if you can see why RC2 (sol_valve) never goes high during the execution of this ISR, even though the code is setting it high. As you can see, I made sure that ANSEL = 0 and ANSELH = 0 at beginning of the ISR to make all PORTC digital and to be sure I don't have another "read-modify-write" problem as was previously pointed out to me by Charles Leo. Can't see why RC2 (sol_valve) will never go high even when the code directs it to. RC2 is connected to the + coil terminal of a DPDT single side stable non-latching relay and therefore the relay is never being triggered from the non-energized to energized state because RC2 is not going HIGH. Any ideas would be greatly appreciated?

    Code:
    '--------------------{ Begin Interrupt Handler }--------------------------
    DISABLE                 ' Disable interrupts during interrupt handler
    Int_handler:
     'Initialize registers/ports upon Interrupt wakeup from Sleep
        OPTION_REG.7 = 0    ' Enable PortA/PortB Pullups                   
        WDTCON = %0001000   ' Turn WDT on for ops
      ' A/D & Comparators disabled
        ANSEL=0             ' Set ports to digital I/O
        ANSELH=0            ' Analog module disabled
        CM1CON0=0           ' Disable comparators
        CM2CON0=0
      ' PORT Settings
        TRISA = %11111111   ' All PORTA pins to inputs...RA2& RA3 are used..
                            ' RA2 as input clock to TMR0 overflow interrupt
                            ' RA3 as input for sensing Flush switch closure
        TRISB = %00000000   ' All PORTB pins to outputs..RB5 is used.
        TRISC = %11100000   ' Set lower 5 pins of PortC as outputs....RC0,
                            ' RC1, RC2, RC3 & RC4 are used.
        PORTA = %00000000   ' PortA pins all set to Low
        PORTC = %00000000   ' LEDs (RC0 and RC1) set to low
      ' Initialization of inputs/outputs
        flush = 1           ' Init RA3 (flush) @ High value as flush interrupt
        HS1 = 1             ' Init RA2 (HS1) at High for METER pulse overflow
                            ' TMR0 clock input (RA2) for meter pulse inputs
        ext_pwr = 0         ' Init RC3 at low value to turn off external power
        sol_valve = 0       ' Init RC2 (sol_valve) at Low value 
    
     ' Interrupts Settings
        TMR0_Enable VAR INTCON.5    'Alias for On_Off switch of TMR0 counter
        FLUSH_INT_FLAG VAR INTCON.0 'Alias RA3(FLUSH) On-change-inter. flag
        TMR0_INT_FLAG VAR INTCON.2  'Alias Timer0 overflow flag bit
        
     ' Process this Interrupt   
        DEFINE WRITE_INT 1
        IF FLUSH_INT_FLAG = 1 Then  ' Interrupt was from RA3 on change
           REPEAT
                ' Wait till the external Flush interrupt is at high level..
                ' this limits interrupt to switch closure only & not also  
                ' for switch opening.
           Until flush = 1
           ext_Pwr = 1     ' Power on RL1 & external power during the       
                           ' Interrupt Service Routine (ISR).  This puts
                           ' power to RL1 & opens valve at same time.
           Pause 40        ' Delay for 40 millisecs
           ext_pwr = 0     ' Turn off power to RL1 & external power circuit.
           PULSOUT LED_Red,2000*4   ' Blink RED LED 40 msec for valve open.
           'Write  7, flush ' Write FLUSH value..remove comment for test only
        Endif
        
     ' Valve is open and water is flowing...Measure flow meter output
        TRISC.4 = 0          ' Make RC4 an output for HS_Pwr.
        HS_Pwr = 1           ' Turn on power to HS1 & HS2 sensors.
        TMR0_Enable = 1   	 ' Enable the TMR0 pulse counter for overflow interrupt
        ' Set registers for using A/D converter
          ' Set ADCON registers for A/D converter
            ADCON0 = %10110101  
                ' ADCON0.7 = ADFM = 1       ' 10-bit result is right justified
                ' ADCON0.6 = VCFG = 0       ' Set VREF+ to Vdd 
                ' CHS<3:0> = 1101           ' Select 0.6V Ref channel                                                    
            ADCON1 = %00110000    ' Select FRC as A/D conversion clock source
          ' Set FOSC=1MHz to stay inside recommended TAD range when not in SLEEP
            OSCCON = %01000001
        DEFine ADC_BITS 10            
        REPEAT  ' Execute this loop while waiting for flow to reach 1.6 gallons. 
          ' Flash Green flow light while water flowing till pulse counter overflow
            LED_Grn = 1
            Pause 125
            LED_Grn = 0
            Pause 500
          ' If Battery is low..flash battery monitor RED LED while water flowing
            VRCON.4 = 1        ' Turn 0.6V reference ON
            PAUSEUS 100        ' Allow VP6 to settle
            ADCIN 13,ADINPUT   ' Get VP6 analog reading (10-bit)
            VRCON.4 = 0        ' Turn 0.6V reference OFF
            'WRITE 11,ADINPUT
            'A/D scale for 0.6 volts is 0.6 * 1024 Full Scale = 6138
            VDD = 6138/ADINPUT ' convert input reading to Vdd voltage
            ' Vdd now holds the measured Vdd voltage * 10 (i.e., 3.4V = 34)
            '   The formula is the same for any Vdd voltage.  Assume normal 
            '   Vdd = +3.95vdc direct from fully charged battery pack input.
            'WRITE 13,b0  ' Remove comments on Write statements for test only
            'WRITE 14,b1
            'Write 17,Vthr      
            IF Vdd <= Vthr THEN ' If Vdd less than or equal to 3.2v, blink the
                LED_Red = 1     ' RED LED for warning to replace batteries.   
                PAUSE 125        
                LED_Red = 0
                Pause 500       
            EndIF                                     
        Until TMR0_INT_FLAG = 1  ' Loop ends when pulse counter overflows
        HS_Pwr = 0               ' Turn off power to HS1 & HS2 sensors.
        ext_pwr = 1              ' Turn on power to RL1 & external power circuit.  
        HIGH sol_valve           ' Generate 5 sec pulse on RC2 to RL1..close
        Pause 5000
        Low sol_valve
        ext_pwr = 0              ' Turn off power to RL1 & external power circuit. 
        PULSOUT LED_Red,2000*4   ' Blink RED LED 40 msec for valve closed command   
        'WRITE 19, TMR0_INT_FLAG  ' Write TMR0 value..remove comment for test   
        dummy = flush            ' Clear mismatch condition                   
        FLUSH_INT_FLAG = 0       ' Clear interrupt flag & enable RA3 on interr.
        TMR0_INT_FLAG = 0        ' Clear overflow flag
        TMR0 = 256 - k           ' Reload TMR0 to overflow after k counts
      RESUME                      ' Resume Main Program                 
      ENABLE
      '------------------{ End of Interrupt Handler }-------------------------
        ' If the user program ends by getting to the last statement of the
        ' program at an END instruction, the MCU will SLEEP and await a wakeup.
    END

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Question

    Hi, Jellis


    I'd appreciate A look to this part of the scheme !

    Alain
    Last edited by Acetronics2; - 9th September 2009 at 10:47.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  3. #3
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Schematic enclosed

    Alain, thanks for the reply. I tested the code again watching closely for the 5 sec pause and notice strangely that it never does pause for 5 secs. This really puzzles me. Any ideas why this would happen?

    Quote Originally Posted by Acetronics View Post
    Hi, Jellis
    I'd appreciate A look to this part of the scheme !
    Alain
    Am enclosing a partial schematic that shows how RC3 is interfaced to a SPST relay that controls power from the battery to another single stable DPDT relay, which switches the power between two polarity switched outputs, to SOL_RED when RC2 is not energized and to SOL_BLK when RC2 is energized. My problem is that RC2 is never going high by the code so the DPDT relay never energizes into the SOL_BLK output state.
    Attached Images Attached Images  

  4. #4
    Join Date
    Feb 2005
    Location
    Indiana
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Rc2

    I think that RC2 is trying to go high but can't because the coil of the relay is pulling too much current for the output. Might have to use a transistor as a switch.
    JRudd

  5. #5
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Thanks for reply

    I thought of interfacing the RC2 pin to a NPN transistor with the relay in the collector path to insure enough current to trigger the relay. However, according to the spec on the relay, it has a high enough coil resistance that the RC2 pin when set high (5.0 vdc) it will only draw 25 mAmps. And since the spec on my 16F690 MCU chip says it will provide 25 mAmps on any pin, I thought I could save the cost and board space by eliminating the transistor. Do you think I should still try the transitor?

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Have you tried a LED in place of the relay to see if the pin is working properly? If it is the suggestion jrudd made is the way to go. That would be the safe way.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Free Project - 245 LED Display
    By T.Jackson in forum Code Examples
    Replies: 221
    Last Post: - 16th August 2009, 04:59
  2. Using Sleep
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th August 2008, 04:05
  3. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  4. code conversion
    By saturnX in forum mel PIC BASIC
    Replies: 19
    Last Post: - 3rd October 2005, 17:17
  5. New member
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 28th February 2004, 22:44

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