That has got to be one of the finest, most detailed, accurate and complete answers to an open ended newbie question that I have ever seen. --- James Newton: PICList webmaster/Admin mailto:jamesnewton@piclist.com 1-619-652-0593 phone http://www.piclist.com/member/JMN-EFP-786 PIC/PICList FAQ: http://www.piclist.com > -----Original Message----- > From: piclist-bounces@mit.edu > [mailto:piclist-bounces@mit.edu] On Behalf Of Maarten Hofman > Sent: 2005 Nov 28, Mon 12:08 > To: Microcontroller discussion list - Public. > Subject: Re: [PIC] newbie question on timing > > > Using a basic compiled program using a for-next loop, a > flash PICchip. > > can I expect toget a pulse every 55 ms. or about 18pulses > per second? > > > > I know a lot of it will depend on what speed I am running > the chip at. > > Yes, and on the BASIC compiler. > > Let me see, hypothetically (non working code, just counting a bit): > > FOR A = 0 TO 255 > PORTC = PORTC & 254 > PORTC = PORTC | 1 > NEXT A > > ; FOR A = 0 TO 255 > movlw 0 > movwf A > goto NEXT1002 > NEXT1001 > movlw 255 > xorwf A,w > btfsc STATUS,Z > goto NEXT1003 > incf A,f > NEXT1002 > ; PORTC = PORTC & 254 > movlw 254 > andwf PORTC,f > ; PORTC = PORTC | 1 > movlw 1 > iorwf PORTC,f > ; NEXT A > goto NEXT1001 > NEXT1003 > > Which indicates there are 4 cycles of setup and 11 cycles per loop. > Given a not unreasonable clock frequency of 4 MHz, that means > you get a pulse every 11us, so about 90909 pulses per second. > > As said, this highly depends on the clock frequency, but also > on the BASIC compiler (the code could be further optimized > using incfsz/decfsz, which would make it faster. Or the BASIC > compiler outputs more generic code, allowing values greater > than 255, which would make things slower... Also if it would > allow full expressions in the FOR loop this might add > superfluous dummy variables, slowing things down). > > But 90909 pulses per second seems a lot closer to reality > than 18. If you DO want 18 pulses per second, you might need > to add a suitable PAUSE command, of known duration. > > Greetings, > Maarten Hofman. > > -- > 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