Yesterday I wrote: > > Steve Smith wrote: > > > start BSF porta,0 > > NOP > > NOP > > BCF porta,0 > > GOTO start > > Makes a square wave of 6 instruction cycles eg 1mhz / 6 not very useful as it > > does nothing else. > > Well, it does Pulse Infinite Cycles. But with a Programmer's Insightful > Change it can Pulse In Chunks: > > MOVLW CYCLES_TIMES_2 > MOVWF cycle_count > start BSF porta,0 ;Pulse Initial Cycle > DECF cycle_count,F ; > NOP ;oPerate it Can't > BCF porta,0 > goto $+1 ;Phased Instruction Count > BSF porta,0 > SKPZ > goto stop ;Properly Indented Code > BCF porta,0 > goto start ;Proceed if conscious > > stop BCF porta,0 > > Giving a maximum of 256*2 pulses. There is a way to Possibly Increase > the Counts to 65536*2. And since there were no takers on the 64k version, here it is (actually, it is the 17-bit cycle count version): MOVLW LOW(CYCLE_TIMES_2) MOVWF cycle_count_lo MOVLW -(LOW(CYCLE_TIMES_2)+HIGH(CYCLE_TIMES_2)) MOVWF cycle_count_hi start BSF porta,0 DECFSZ cycle_count_lo,F INCF cycle_count_hi,F BCF porta,0 MOVF cycle_count_lo,W IORWF cycle_count_hi,W BSF porta,0 SKPZ goto stop BCF porta,0 goto start stop BCF porta,0 ;And if you want the capability to produce an odd number of ;cycles to: BTFSS cycle_an_odd_number_of_times,0 goto really_stop BSF porta,0 goto $+1 BCF porta,0 really_stop The frequency is f_CPU/4/6 = f_CPU/24. The minimum pulse length is 2 cycles and the maximum is (2^17)+1 (when the initial cycle_count is 0x0000 and cycle_an_odd_number_of_times is odd). Of course it hasn't been tested, so Probably It'll Crash. Scott -- __o I buy pizza instead of gas. \< (*)/(*)