You're right - the only way out is with a reset. Thanks for the bsf/bcf suggestion - I will do that. I didn't realize there was a potential problem with repetitive incf's. Ron > > From: Jose Da Silva > Date: 2004/11/29 Mon PM 08:21:18 EST > To: "Microcontroller discussion list - Public." > Subject: Re: [PIC]:Do I REALLY have a 2MHz square wave here? > > On Monday 29 November 2004 03:59 pm, Ron Hackett wrote: > > I need to produce a 2MHz square wave on an output pin of a PIC16F876 > > running at 16MHz. I have written a program that seems to do the job (my > > PC scope shows the 2MHz square wave on PB0, but just in case I'm missing > > something here, I thought I would ask. > > > > My program takes advantage of the fact that, within any given memory page, > > the PC counter wraps around from the end of the page (PCL = 0xFF) to the > > beginning of the page (PCL = 0x00) if PCLATH is not incremented. > > Essentially, it's a "brute-force approach to the problem: page 1 is > > completely filled with 2048 "incf PORTB, F" instructons and a small setup > > routine in page 0 jumps to page 1. The output of RB0 appears to be a > > free-running 2MHz square wave on my scope, but I just want to be sure I'm > > not overlooking a small timing delay when the PC wraps around in page1. > > from your description, yes, you do have a 2mhz square wave, but it seems your > chip has no room to exit this loop without causing a glitch since you have > to devote 1 cycle per bit flip on the port (therefore leaving no room to > make a decision). > > I'm guessing that once triggered, the only way you are going to turn this > 2mhz off is by some external chip reset. > > > Any comments or suggestions are welcome! > > You should "force" the pin to flip by using: > bsf PORTB,0 > bcf PORTB.0 > bsf PORTB,0 > bcf PORTB.0 > bsf PORTB,0 > bcf PORTB.0 > etc... > > You may find problems with incf, decf or xorf because they rely on the port > having flipped to the correct "next" state before you incf, decf, or xorf > again. > > If your port is heavily loaded with too much capacitance and/or small > resistance, the port pin may not swing to the correct state in time to be > read correctly because the value incremented is read is at the pins (which > may not have reached the correct voltage), not at your output registers.... > therefore your 2mhz may "stutter" now-n-then.... since you may still be > reading a zero at the port pin when the port register is outputting a one. > _______________________________________________ > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > _______________________________________________ http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist