Issue
133 August 2001
MSP430 News Flash:
Recognizing
the Flexibility of Reprogramming
Start
MSP430F1121 Comparatively
Speaking Battery Monitor
Dynamic Inputs RC
To The Rescue E(OR I)IN
It's Only The Beginning
Sources & PDF
RC TO THE RESCUE
Use a single analog input and a single digital input to
set up the circuit in Figure 3. Choose values for the
RC components such that their time constant, R*C, is less
than the time it takes for the micros timer to roll
over. For instance, the DCO can be bumped up to ~3 MHz
from the default of ~750 kHz. The 16-bit timer will roll
over after counting 65536 tics of the 3-MHz clock. Thats
~20 ms. A 10-kW resistor and a 1-µF capacitor has a time
constant of ~10 ms. This is less than the timer overflow
time so you wont need to worry about the timer overflowing.
The digital bit is used to either apply VCC to the resistor
(to charge the capacitor), or ground the resister (to
discharge the capacitor). This can easily be done under
program control.
Software
is written to set the digital output bit high for five
time constants (tc) to assure a full charge (> 99%).
When the digital output is switched to ground, the timer
is cleared and enabled. Because the () input of
the comparator is configured with a relative internal
voltage of 0.25*VCC, the comparator will change states
with the discharging capacitor. At change of state, the
timer is read. The count is the reference count and can
be equated to the reference resistors value. In
simplest terms, if the timer has 10,000 counts and the
reference is a 10k resistor, then 1 count = 1 W.
If youll be using a resistive sensor, make sure
your reference resistors value is higher than the
highest value of your sensor. If youre using a capacitive
sensor, make sure the value of your reference capacitor
is smaller than the smallest value of your sensor. To
improve result accuracy, use a close tolerance reference
device (< 1%), as all calculations are based on this
known value. Note that this will be more of a problem
in selecting a reference capacitor, as finding one with
< 5% tolerance may be difficult.
Now that you have a baseline reference where a count is
equal to so many ohms of a reference, you need a way of
comparing this to a sensor. See Figures 4 and 5 for examples
of how a resistive or a capacitive sensor may be connected
to the original base design from Figure 1. This is accomplished
by using an addition digital I/O pin.
Referring back to the reference circuit (see Figure 3),
the digital I/O pin was used to alternately apply VCC
or Gnd to one end of the reference resistor to allow the
reference capacitor to alternately charge and discharge.
To allow multiple resistive (or capacitive) sensors to
the design, each digital I/O pin must also take on another
state. Multiple sensors connected to VCC and Gnd will
interfere with one another by either being in parallel
with one another or forming a divider. In addition to
the two output states, the pin must be able to be placed
into a high impedance (input) mode. This action will essentially
disconnect them from the circuit.
 |
| Photo 1This
scope shot shows the analog input (P2.3) on the
MSP430F1121 running on the flash memory emulator.
The executing program charges and discharges a capacitor,
first through the reference resistor and then through
a resistive sensor. |
Now each component can become the device being tested.
First, the reference device is connected and goes through
a charge and discharge cycle. The timer count forms a
reference value (counts/ohm). Next the sensor is connected
and goes through an identical charge and discharge cycle.
This time the discharge time (timer count) will be somewhat
less (depending on the sensors value). Because the
reference discharge time (RREF * C = COUNTREF) and sensor
discharge time (RSEN * C = COUNTSEN) both use the same
capacitor, the capacitors value in both equations
cancels out and you have a direct relationship between
RREF, RSEN, and the timer counts.

[1]
Using the values from Figure 1, you get

[2]
If the COUNTSEN value is determined to be 5000, then

[3]
Or
[4]
Actually, the discharge time is from VCC down to 0.25
VCC, which is slightly more than one time constant (63.2%),
but everything here is ratio-metric. As long as VCC stays
constant for a complete cycle (reference and sensor) and
as long as the capacitor used is stable for the same period,
these do not affect the result. You can see that two things
are important to the result, the actual value of the known
reference and the maximum number of counts for the reference
discharge time.
 |
| Figure 4Adding
a second resistive element (in this case, a resistive
sensor) allows the micro to compare how each R interacts
with the C. The R not being tested must be removed
from the circuit by setting its control pin as a
high-impedance input. |
Take a look at Photo 1 for a scope shot of the signal
at the RC junction (comparator input) of the circuit from
Figure 4. The internal RCO was used as the system clock
and was set to ~ 3 MHz. This clock was routed to P1.4
(alternate I/O function of the pin) so I could physically
measure the clock speed with a scope. This was a sanity
(or confidence) check. The specs say 2.73.65 MHz
and I measured 3.4 MHz. The flash memory emulator allows
breakpoints to be set. After halting execution after each
discharge cycle, I was able to check the timer counts
for the reference and the sensor. The reference count
was 0B65Bh (46683). With a 0.1% reference of 10,000 W,
the counts/ohm is

[5]
The sensor count was 5DC3 (24003). This means that the
sensor resistance is
[6]
Referring back to Photo 1, notice that the sensors
discharge time is about twice as long as the reference
discharge time (vertical measurement bars showing ~ 10-ms discharge time).