thanks for your quick reply Ray . I REALLY APPRECIATE IT & YOUR EFFORT TO HELP !! i,ve answered your questions & the full code is below i was using variable width before which i think is the prob. let me know if it isn't ========================================== Ray Gardiner wrote: > Hi Glen, > I can't follow your code, It wraps around and the formatting > makes it hard to read. But what little I can decipher I don't > understand what you are trying to do with the "xorwf chksw" > > what you have looks like.... > > caltab > CALL table ; use look up table > MOVWF strttmr ; move value from table to strttmr > XORWF chksw ; compare chksw value (switch value) > GOTO caltab ==============================with xorwf i was trying to get the switch value into chksw ( get switch value)& the corresponding table value into strttmr ( start timer) compare if correct and use that correct value in strttmr for the timer ============================ > table > ADDWF PCL,f ; sw value : time : > RETLW d'25' ; 00 : 250ms (switch > RETLW d'50' ; 01 : 500ms (switch > RETLW d'75' ; 10 : 750ms (switch > RETLW d'100' ; 11 : 1000ms (switch > > What this will do is as follows, first time correct > lookup value will be returned, and the table will > be re-entered with the return value instead of the > switch value, this will result in a jump past the > end of the table with unpredictable results! :-( > ============================== if i remove everything from caltab to table ( all above ) & put in movlf d'25' :counter value movwf strttmr the program works ' believe it or not ' ! ========================== > I would suggest the following. > > 1. Get the hardware working correctly first, you > might have to put a pull down on RB3. > ===================================== ** this code works with a single value in "strttmr" "believe it or not "tested on simstick" - dontronics ** i turn the pullups on to get the switch settings then off again at powerup because once i get that setting i don't need the switch anymore =============================== i didn't know how to do it ! ============================== > 2. Constrain W as follows > table ANDLW 0x03 ; > ADDWF PCL,f ; sw value : time : > RETLW d'25' ; 00 : 250ms (switch > RETLW d'50' ; 01 : 500ms (switch > RETLW d'75' ; 10 : 750ms (switch > RETLW d'100' ; 11 : 1000ms (switch > > 3. Check for TMR0 overflow flag rather than looking > at the timer value directly. Better yet handle the > TMR0 overflow in an interrupt. ************************i don't know how to do interupts . i haven't been doing this for very long ! ****************************** HERE'S THE FULL CODE > ;********************************************************************** > ; 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 ; > chksw equ 0x12 ; > strttmr equ 0x13 ; no of counts > 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 ===pullups enabled=========== > > movlw b'00000111' ;scale 1:256 , pullups enabled > OPTION > ; ============= counter setup ============== > ===================for a single timer value================== > movlf d'25' :counter value > movwf strttmr > ======================================= > ;code below is used for 2 switches > ; init strttmr from input pins > > movf PORTB,w ;get values of RB0 & RB1 > andlw 0x03 ; extract bits 0,1 PORTB (strttmr sw value) > movwf chksw ;put rb0 & rb1 values in register chksw > > > caltab CALL table ; use look up table > movwf strttmr ;move selected value from table to strttmr > xorwf chksw ;compare strttmr with chksw value > btfsc STATUS,Z ;if yes,skip next instruction > GOTO caltab > > ;********************************************************************** > ; ============== program start ============= > > movlw 0x00 ;move 00 hex to register w > movwf PORTB ;move reg w to PORTB (clear PORTB) > > ;============= prescaler setup ===pullups disabled=========== > > movlw b'10000111' ;scale 1:256 , pullups disabled > OPTION > ; ============= 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 > 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) > > ; ================= > ;============= check start cycle / check finish cycle ============= > > chcycs btfsc PORTB,3 ;check AC input at port b pin 2 for 0 > GOTO chcycs ;check again if still high > lw btfss PORTB,3 ;check AC input at port b pin 2 for 1 > GOTO lw ;check again if still low > RETURN ;found zero crossing - rising edge > > ;********************* delay sub-routines ******************************* > ; > ; ============== start timer ============= > > sttimer movlw 0x10 ;move 00 hex to register w > movwf souter ;move register w to "outer" > sout movlw 0x10 ;move 00 hex to register w > movwf sinner ;move register w to "inner" > sinn decfsz sinner,f ;decrement "inner" each scan, scan for 0 > GOTO sinn ;loop "inner" until it = 0 > decfsz souter,f ;decrement "outer" each scan, scan for 0 > GOTO sout ;loop "outer" until it = 0 > RETURN > > ; ==============toggle outputs ============= > > tog bsf PORTB,4 ;set PORTB bit 4 high } > bsf PORTB,5 ;set PORTB bit 5 high } > CALL togs ;CALLs toggle sub-routine } Toggle 4/5 > bcf PORTB,4 ;set PORTB bit 4 low } > bcf PORTB,5 ;set PORTB bit 5 low } > CALL togf ;CALL the delay sub-routine > btfsc PORTB,3 ;skip next if 0 > GOTO tog > RETURN > > ; ============== ontime delay ============= > > togs movlw 0x2 ;move 00 hex to register w > movwf outers ;move register w to "outer" > outs movlw 0x2 ;move 00 hex to register w > movwf inners ;move register w to "inner" > inns decfsz inners,f ;decrement "inner" each scan, scan for 0 > GOTO inns ;loop "inner" until it = 0 > decfsz outers,f ;decrement "outer" each scan, scan for 0 > GOTO outs ;loop "outer" until it = 0 > RETURN > > ; ============== offtime delay ============= > > togf movlw 0x1 ;move 00 hex to register w > movwf outerf ;move register w to "outer" > outf movlw 0x1 ;move 00 hex to register w > movwf innerf ;move register w to "inner" > innf decfsz innerf,f ;decrement "inner" each scan, scan for 0 > GOTO innf ;loop "inner" until it = 0 > decfsz outerf,f ;decrement "outer" each scan, scan for 0 > GOTO outf ;loop "outer" until it = 0 > RETURN > ;********************************************************************** > END ; directive 'end of program' > > THANKS FOR YOUR PATIENCE & TIME > glen > ps i'm just about to try your suggestion , i'll let you know