» Home

» Products

» Interfaces

» Lab

» Downloads

» Buy It

» Contact

» Links

|
» Lab » Frequency Counter via IrTx
|
| Project: | Frequency Counter via IrTx |
| Source Code: | PIC Assembler |
| PIC: | 16F628 |
| Interface: | IrTx |
| Author: | Ravi Deo |
| Last Updated: | 7th April 2005 |
|
Project Description:
This sample PIC project demonstrates how to use a PIC 16F628 with SirPic, to implement
the core functionality of a frequency counter.
Display output from the PIC is transmitted via the IrTx interface to SirPic running on the Palm.
SirPic displays the calculated frequency as the decimal value "f=<frequency> Hz".
Frequency counter via IR
: Zip file containing ASM and HEX files (approx 4KB).
Hardware Schematic:
With this PIC project an external 4MHz external clock oscillator is used to drive both the PIC, and also
as a convenient test signal for counting the frequency (test signal feeding pin 12 of the PIC). The Infra-red bit-stream
output from the PIC (pin 8) feeds the SirPic IrTx Infra-red transmitter unit .

This project makes use of the 16F628's 16 bit TIMER1 as an asynchronous counter, counting the number of rising pulse edges
over a duration of 1/X of a second. The pre-scaler is set to 1:1, so multiplying the count
by X, gives the frequency count in Hertz. Using values of X as 2^N (eg X=1,2,4,8,16...) helps
simplify the multiplication operation (double the number by shifting bits left 1 bit).
The code comprises of the following subroutines:
InitPic: Initialises the PIC device
MainLoop: Main loop which counts and displays frequency
FreqDelay: Interval X over which frequency is counted
DoubleFreq: Multiplies 1 32-bit frequency count by two
TxChIr: Standard SirPic subroutine to transmit char via Infra-Red
WaitDelay: Standard SirPic delay routine used by above
SkipZero: Skips leading zero digits
ShowDigit: Displays the frequency digit
bcd2a: Converts BCD to ASCII
b2bcd: Converts 32-bit Binary to BCD
SirPic Communication and Options settings should be configured as shown below (Note Text mode):

On starting the SirPic log session, you should see the following data being captured.

Try disconnecting the input signal to pin 12 and watch the frequency drop to zero.
|
|