=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Date: Sat, 06 May 2000 10:41:11 From: Nikolai Golovchenko <golovchenko-at-mail.ru> To: pic microcontroller discussion list <PICLIST-at-MITVMA.MIT.EDU> Subject: Re: Window Detection -------------------------------------------------------------------------------- On Friday, May 05, 2000 Kevin Blain wrote: > I am having trouble with window detection - using the subwf function. It > looks to me very much like the following code section should work, but then > again, have I just been staring at it too long? Looks like you did it right. > I am using interrupts - Yes, I am preserving all the right registers, but > could the C flag be getting corrupted is teh interrupt occurs during the > skpc instruction??? Interrupt can't occur during skpc execution. Two cycle instructions are executed actually in one cycle, the other cycle is dummy, during which the next instruction is fetched. So even if C flag gets corrupted by interrupt, it can happen only between instructions. Just make the registers saving/restoring in interrupt by the book and you must be safe. > For reference, device PIC16C72 > entry to routine is with ADRES freshly captured. That bit seems okay. BTW, you can make the program a bit shorter: Radix = DEC movf ADRES, w ;w = ADRES addlw -176 ;w = ADRES - 176 = ADRES + (256 - 176) = ADRES + 80 skpc goto SECTION_C ;ADRES < 176 ;numbers 176-255 now start from 0 addlw -(198-176) ;w = w - 22 = w + 234 skpc goto SECTION_B ;176 <= ADRES < 198 ;numbers 198-255 now start from 0 addlw -(221-198) skpc goto SECTION_A ;198 <= ADRES < 221 Hint: ready to pack into a macro :) <snip> Nikolai http://techref.massmind.org/member/NG--944 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Date: Fri, 05 May 2000 19:03:16 From: Kevin Blain <kevinb-at-WOODANDDOUGLAS.CO.UK> To: PICLIST-at-MITVMA.MIT.EDU Subject: Window Detection -------------------------------------------------------------------------------- I am having trouble with window detection - using the subwf function. It looks to me very much like the following code section should work, but then again, have I just been staring at it too long? I am using interrupts - Yes, I am preserving all the right registers, but could the C flag be getting corrupted is teh interrupt occurs during the skpc instruction??? For reference, device PIC16C72 entry to routine is with ADRES freshly captured. That bit seems okay. movlw .176 ; threshold subwf ADRES,w skpc goto SECTION_C ; = below decimal 176 movlw .198 ; threshold subwf ADRES,w skpc goto SECTION_B ; = between 176 and 198 decimal movlw .221 ; threshold subwf ADRES,w skpc goto SECTION_A ; = between 198 and 221 decimal ... it must be above 221 decimal then subroutines... SECTION_A: stuff SECTION_B: stuff SECTION_C: stuff