Steve Addison writes: >I am trying to generate a 77Khz signal from a surface mount pic in 10ms bursts. >The way I have attempted to do it at the moment I require the program >counter to increment every 0.5uS which means I need a resonator speed of >8MHz - as the PC is incremented at a quarter of the pic clock speed. > >All the SMD pics in the (Farnell) catalog are 4MHz devices - and here's the >stupid question - will I be able to use an 8MHz resonator? Probably. You won't have any recourse if it doesn't work, of course. >If anyone has any sugestions on how to achieve a 77KHz output (in 10mS >bursts) for an SMD 4MHz pic I would love to hear them! OK, I'll take a stab at it: 77KHz = approx 13 cycles at 4 MHz X1 (actual freq will be 1E6/13 = 76.9231 KHz. 10 ms = 770 cycles of 77 KHz signal. Since the rate is 13 cycles, it's tough to make a square wave using exactly a 4 MHz clock. In the program below, the signal will be high for 6 instruction cycles and low for 7. Since there is some extra time in the routine, slower PIC clocks may be used and then the waveform made symmetrical by removing some NOPs. I'll leave this for the programmer. It appears that a 77K*12*4 = 3.696 MHz clock would be ideal for making square waves, by removing the NOP after burstsl below. burst movlw .2 ;2 byte cycle counter - initialize to 770 dec. movwf ccntl ;Need 2 RAM variables. movlw .3 movwf ccnth burstfl nop ;Equalize loop time if only low byte dec. nop burstsl nop ;May be removed for slower clocks. bsf PORT_B,0 ;Set output high. (can use any port here) goto $+1 ;2- cycle NOPs. goto $+1 nop bcf PORT_B,0 ;Output was high for 6 cycles, now low. ; From here, always 5 cycles back to burstsl. decfsz ccntl goto burstfl decfsz ccnth goto burstsl ;Fall thru to here when burst is done. This code is not tested or guaranteed. Use at your own risk. -Mike