PDA

View Full Version : Can't get RC2 to go high with PORTC.2 = 1



jellis00
- 9th September 2009, 03:46
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?



'--------------------{ 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

Acetronics2
- 9th September 2009, 10:41
Hi, Jellis


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

Alain

jellis00
- 9th September 2009, 18:41
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?


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.

jrudd
- 10th September 2009, 02:04
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.

jellis00
- 13th September 2009, 06:47
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?

mackrackit
- 13th September 2009, 07:26
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.