|
by
Duane Perkins
Start ý The
Circuit ý Construction ý Testing
ý Program Code ý Sources
and PDF
PROGRAM CODE
calibrat.asm and vom.asm
are the same except that calibrat.asm displays the ADC count
for calibration purposes. The main loop executes about once per second
and updates the display. The secondary loop is executed 256 times.
It generates a ramp of 13,312 cycles of the 8-MHz oscillator (1664
ýs). As shown in Figure 3, this allows the ramp to reach its maximum
voltage well after the highest possible count has been captured.
Using RA1AN1 requires programming the
ADC function to shift the input voltage upward by about 0.5 V, thus
avoiding inaccuracy that could result in a low count. First, a count
for the input voltage plus the shift voltage is captured, then a count
for the shift voltage alone is calculated. The latter is subtracted
from the former so as to make the adjusted count relative to zero.
If the absolute difference between the adjusted count and NSHIFT is
found to exceed NRANGE, "Out of Range" is displayed and
the main loop is executed. Otherwise, the mean count from the previous
main loop execution is subtracted from the current count to cancel
out the DC component and the result is squared.
The adjusted count and the squared result
are summed in two accumulatorsýa 24-bit accumulator for the counts
and a 40-bit accumulator for the squares. After 256 iterations, the
mean of the sums is contained in the accumulators, disregarding the
low-order byte (effectively a divide by 256). The square root of the
mean of the sum of the squares is calculated. NSHIFT is subtracted
from the mean count (making it relative to NSHIFT) and the result
is multiplied by the slope to convert it to DC voltage.
NSLOPE is used if the count is greater
than NSHIFT, otherwise PSLOPE is used. The root of the sum of the
squares is always multiplied by PSLOPE to obtain the AC voltage. When
measuring resistance, the DC voltage is converted to ohms. The results
are displayed and the main loop begins again.
PIC14000.INC provides the basic
definitions for the PIC14000. vom.inc provides additional definitions
and function for the VOM. Other .inc files provide code for
various functions used by vom.asm. You can experiment with
programming the PIC14000 by using these files.
PREVIOUS NEXT
Circuit Cellar provides up-to-date information for engineers. Visit
www.circuitcellar.com for
more information and additional articles.
For subscription information, call (860) 875-2199, subscribe@circuitcellar.com
or subscribe online.
ýCircuit Cellar, the Magazine for Computer Applications. Posted with
permission. |