Joe, I check and mouser stocks 19.6608MHz crystals. They are 0.39 each.=20 I can do that. I could place an order with them for the crystal and a=20 few other things so as to spread out the cost of shipping. But I could=20 use this for right now with the 20MHz crystal. Could you please send me=20 the code to do it the other way? Thanks, rich! On 7/18/2014 4:57 AM, IVP wrote: >> This is what I don't know how to do > Using TMR1 is very simple (when you know how to do it) > > Here are some jottings. E&OE. Watch the banking, I didn't look > any up for this so you may need more or fewer banksels. The aim > is for the IRQ system to be reset after the 76th interrupt. As I > mentioned, the '19264' will need to be decreased by the number > of cycles needed to do the load. TMR1 can be stopped during > the load and restarted after, remember to take those instruction > cycles into account as well > > Note that if a 19.6608MHz had been used the ISR would have > been quite a bit simpler, just a 75 count > > The timing system could be done quite a different way. For example > load TMR1 with 50,000 (-ish) every time and count 100 interrupts > to get the 5,000,000. This does give you some consistency of > execution in the ISR as there's no clean-up 77th interrupt > > Joe > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > ;make a flag in a RAM location > > #define last_irq flags,0 > > ;configure TMR1 > > banksel t1con > movlw b'00000000' > ; - > ; 0 not T1osc > ; 00 pre-scaler =3D 1:1 > ; 0 T1osc off > ; 0 internal source > ; 0 internal source > ; 0 T1 off > movwf t1con > > ;initialise interrupt counter to - 76 > > banksel irqs > movlw -.76 > movwf irqs > bcf last_irq ;initialise "last interrupt" flag > > ;enable TMR1 interrupts > > banksel pie1 > bsf pie1,tmr1ie > bsf intcon,peie > bsf intcon,gie > > clrf tmr1l > clrf tmr1h > > bsf t1con,tmr1on ;start TMR1 > > here goto here > > ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > ;ISR > > irq bcf pir1,tmr1if ;clear irq flag > btfsc last_irq ;test if last interrupt > goto last ;yes > > incfsz irqs ;increment, skip after 76 interrupts > retfie ;exit > > banksel tmr1l > movlw low(.19264) ;load TMR1 for last interrupt period > movwf tmr1l > banksel tmr1h > movlw high(.19264) > movwf tmr1h > > banksel flags > bsf last ;set "last interrupt" flag > retfie ;exit > > last banksel irqs > movlw -.76 ;re-initialise counter > movwf irqs > bcf last_irq ;and "last interrupt" flag > > movf portb,w ;read portb > xorlw b'00000001' ;toggle portb,0 > movwf portb ;write portb > =20 > 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 .