Joe, Wow, that is a big difference in code. I just ran the numbers=20 because I wanted to see what would happen using this code with a 20MHz=20 clock and the error is almost 2 percent. But I could use that until I=20 receive the other crystal. Hum, I'll trying coding these later on today=20 or sometime tomorrow. Thanks, rich! On 7/18/2014 5:40 AM, IVP wrote: >> Could you please send me the code to do it the other way? > E&OE > > PS best practice is to save and restore W and STATUS, as they will > probably be altered by the ISR. This could affect operation when you > return to the main code > > Here's how to, from the 628 datasheet. Although note that BCF > STATUS,RP0 does not guarantee Bank0. banksel status_temp > is much better, if indeed Bank0 is where you assigned the temporary > storage to be in > > So, have a couple of registers w_temp and status_temp in Bank0 > RAM. Microchip's comments below are not clear or complete. You > may be in Bank1 when the ISR is entered, and so W may be stored > in completely the wrong RAM. Make sure W and STATUS are > being saved and recalled from the correct bank. Any bank, as long > as it's the right one and W and STATUS are as they were when > the main code was left > > MOVWF W_TEMP ;copy W to temp register, > ;could be in either bank > SWAPF STATUS,W ;swap status to be saved into W > BCF STATUS,RP0 ;change to bank 0 regardless > ;of current bank > MOVWF STATUS_TEMP ;save status to bank 0 > ;register > : > : (ISR) > : > SWAPF STATUS_TEMP,W ;swap STATUS_TEMP register > ;into W, sets bank to original > ;state > MOVWF STATUS ;move W into STATUS register > SWAPF W_TEMP,F ;swap W_TEMP > SWAPF W_TEMP,W ;swap W_TEMP into W > > Joe > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > ;iinitialise IRQ counter > > movlw -.75 > movwf irqs > > ;ISR > > irq bcf pir1,tmr1if ;clear irq flag > > incfsz irqs ;increment, skip after 75 interrupts > retfie ;exit > > movlw -.75 ;re-initialise counter > movwf irqs > > movf portb,w ;read portb > xorlw b'00000001' ;toggle portb,0 > movwf portb ;write portb > > retfie ;exit --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .