Ray Gardiner wrote: > > > > > >where am i going wrong please ? > > > >thanks very much for your help > >i appreciate it > >glen > > Hi Glen, > I assume that your code does something after the "movwf strttmr" > and doesn't just run off into the "table" subroutine. .. :-) yes ray , "movwf strttmr" does continue on in the program. > the "weak-pullups" enabled in the OPTION register. yes they are enabled > And another thing, why have you got the 10k resistor there anyway? > it is not needed for switches. (assuming the weak-pull-ups are enabled). > i have removed the 10k res.& checked the following vdd= 5v low= 0v high= 1.75v i have tried the different switch settings but still no change ! " stop press " i think i've found the problem. the circuit works when the single strttmr value & no pullups are used. i am using rb3 to sense the ac line i/p.& synchronise (i am testing with 16vac till i get the code to work correctly) but when i get to using the 240v line voltage the same problem would arise, can't read zero crossing due to pullups! when i use pullups the prog won't work , because the ac i/p (rb3) doesn't go down to read a zero goes no lower than 1.8v ***************** with this modification using selectable switch values via lookup table & since i need pullups to work the two switches. is their a way to code other than to enable pullups to get the switch values & then disable rb3 pullup so rb3 can sense line & synchronise(able to read zero crossing) heres the code (lookup table only included in sub routines) ; vars PORTA equ 0x05 ;CPU equates (program memory map) PORTB equ 0x06 ;CPU equates (program memory map) souter equ 0x0c ; sinner equ 0x0d ; inners equ 0x0e ; outers equ 0x0f ; innerf equ 0x10 ; outerf equ 0x11 ; chkcnt equ 0x12 ; strttmr equ 0x13 ; no of counts switch equ 0x14 ; STATUS equ 0x03 ;CPU equates (program memory map) w equ 0 ; destination designators f equ 1 ; destination designators ;********************************************************************** ; porta set-up org 0x000 ;address 000 program start start movlw 0xff ;ff hex moved to w register tris PORTA ;porta set as inputs ; ;********************************************************************** ; PORTB set-up movlw 0x0f ;00001111 hex moved to w register tris PORTB ;PORTB set o/p's 4,5,6,7,inputs 0,1,2,3 ; ;********************************************************************** clrf STATUS ; ============= prescaler setup ============== movlw b'01000111' ;scale 1:256 , pullups enabled OPTION ; ============= counter setup ============== ;code below is used for 2 switches ; init strttmr from input pins movf PORTB,w ;get values of RB0 & RB1 andlw 0x03 ; extract out bits 0,1 of PORTB (strttmr value) CALL table ; use look up table movwf strttmr ;move selected value from table to strttmr ;********************************************************************** ; ============== program start ============= movlw 0x00 ;move 00 hex to register w movwf PORTB ;move register w to PORTB (clear PORTB) ; ============= initialise timer setup ============== initmr movlw .215 ;40 * .000256 = 10 ms movwf TMR0 loop CALL chcycs ;check for zero crossing CALL sttimer CALL tog ; ============= check timer ============== movf TMR0,w ;move f reg to w btfsc STATUS,Z ;if !0 ,GOTO loop GOTO loop decfsz strttmr,f ;decrement strttmr by 1 GOTO initmr ;go around for next delay ;drop thru to stop stop GOTO stop ;======================================================================= ; delay sub-routine table addwf PCL,f retlw d'25' ; 00 : 250ms (switch position 1) retlw d'50' ; 01 : 500ms (switch position 2) retlw d'75' ; 10 : 750ms (switch position 3) retlw d'100' ; 11 : 1000ms (switch position 4) thanks for your help ray it's very kind of you glen