Listing 1—The PBasic pseudo
code shows how an approximate 30-MHz signal is measured using a relatively low-power
4-MHz microprocessor. The design uses the PIC16F877A’s internal Timer0 with a
built-in prescaler.
fhilo var word //Contains RF frequency after measurement
measrf:
High PORTE.1 //Enable RF oscillator gate
Low PORTA.5 //Disable t0ckl gate
LowPORTE.0 //Force local oscillator gate output high
TMR0=0 //Clear TIMER0
PULSOUT PORTA.5,100 //Enable tockl gate for 1 ms
Low PORTE.1 //Disable RF oscillator gate
fhilo.byte1=TMR0 //Extract upper 8 bits of Timer0
call extract //Extract value in prescaler
RETURN
extract:
For I=1 to 255 //Pulse Timer0 until prescaler overflows
PULSOUT PORTA.5,1
If TMR0-fhilo.byte1=1 then goto done //Is there overflow?
Next I //No
done: fhilo.byte0=256-I //Yes. 256 – number of loop cycles = prescaler value
Return