On Wed, 5 Jun 2002, Bob Ammerman wrote: > Gordon, > > You can do this with a 1-bit output direct-digital synthesis technique. > > > Given the following variables: > > unsigned long increment_value; > unsigned long phase_accumulator; > > for (some number of iterations) > { > phase_accumulator += increment_value; > > // copy hi bit of phase_accumulator to output pin > // code could look something like: > movf output_port,W ; get existing port bit > andlw ~(1 << output_bit) ; turn off current value > btfsc phase_accumulator; ; is high bit on? > iorlw 1 << output_bit ; yes: turn the bit on > movwf output_port ; send it back to the hardware > } > > The output frequency is directly proportional to 'increment_value'. A simpler way is to toggle the output everytime the phase accumulator rolls over: movf increment_value,w addwf phase_accumulator,f ; or better, a 16-bit phase acc. movlw 1<