Rpbasic-52 programming guide, Freq – Remote Processing BASIC 52 User Manual

Page 60

Advertising
background image

RPBASIC-52 PROGRAMMING GUIDE

2-41

FREQ

(Function)

Syntax:

F R E Q (channel)
Where : channel = 0 or 1, depending upon card.

Function:

Returns a counter value

Mode:

Comm and, run

Use:

PRINT FR EQ(0)

Cards:

RPC-210, RPC-320, RPC-330 (RPC-210 and -320 are channel 0 only)

D E S C R IP T I ON

This command returns a frequency, or number of pulses over a period of time. FREQ returns the latest value
from the hardware counter. FREQ does not actually read from the counter. The operating system reads the
counter at set interva ls defined by C ONF IG FRE Q and stores th em for retrieval by this function. This
function is used to read analog input modules made by Greyhill, Dutec, and others. Equivalent 15+ bit analog
input readings are theoretically possible.

F R E Q f un c ti o n r e tu r ns 0 un t il s et u p b y C O N F IG F R E Q .

The latest FR EQ valu e remains in mem ory until updated b y the RPB ASIC-5 2 operating system . The update
interva l is dete rmine d by the CO NFIG FRE Q com man d.

Avoid using COUNT (n) when using this command. It is possible values returned by COUN T(n) could be
wrong.

Hardware counters (LSI 7166) are used to count pulses. CONFIG FRE Q defines the time interval between
readings. The operating system reads and resets the counters every time interval. Thus, you can measure a
frequency in 1/10 second. The result is multiplied by 10 to obtain the "true" frequency. Errors in this case
are also multiplied by 10. The best rule is to set the time interval in CONFIG FREQ for as long of a period as
possible (up to 1.275 s econds) to get the most stable a nd accurate re adings. Shorter interva ls make co unts
appear less stable.

Best resolution is below 80 Khz at a measurement interval of 1/2 second. Between 80 Khz and about 190
Khz counts can easily vary by ±2. From 190 Khz to about 1 Mhz, counts vary by up to ±10. Above 1 Mhz,
counts vary much more. Counting to 20 Mhz is possible.

You will ha ve to p lay w ith the m easure men t interv al, base d on the input fre quenc y and d esired stabilit y.
Averaging the counts helps stabilize the readings.

There are several sources of errors and instability. The time interval between counter readings is based on the
system tick tim er, which is base d on the crystal. Ac curacy is usually better than 0.01% . The error is very
noticeable at higher (> 200Khz) frequencies. Another potential source of error is the program or functions
you may be executing. Some functions, such as AIN, turn off all interrupts for a "short" period of time (50
micro-seconds). What this means is, if it is time for the operating system to read the counters, the reading
w i l l b e d el a ye d b y u p to 5 0 m ic r o- s ec o n ds . I f th e fr e qu e n cy i s v e ry h ig h , a d d it i on a l c o u nt s ar e re a d . N o
counts are missed, so averaging readings helps to reduce errors.

Counts are missed when the frequency is above 1 Mhz (500 Khz on the RPC-210). This is because of CPU
p ro c es si ng ti m e b e tw e e n l at c hi ng a nd re s et in g th e co u nt e r ( ab o ut 1 - 2 m i cr o- se c on d s) . I nc r ea s in g th e ti m e
i nt e rv a l b e tw e e n r ea d in g s h e lp s to re d uc e er ro rs b ut do e s n o t e li m in a te th e m .

RELATED

CONFIG FREQ

E R R O R

Advertising