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




Bookmarks