Battery Analyzer for RC Power
The simplicity of the interface program makes it
a little boring, but is an important part of the system.
The program starts with its typical initializations,
with the most important being the activation of the
ADC. The “Config Adc” statement makes this
process easy. Once the ADC is started with the
“Start Adc” command, you only have to call the
“Getadc()” routine to snatch a measurement from
the converter.
After everything has been initialized, the program waits for the PC to send a control word via the
serial connection to start the battery testing. The
program will loop using the “loop until good=1”
statement until it is satisfied. The program will fall
through when the interface board receives a control
word from the PC. The “Relay_con” routine will execute when a character is received in the serial buffer.
The “input” statement is used to capture the control
word and store it in the variable “Relcon.” The control word “Go1” will start the process by connecting
the ADC to the load and turning ON the FETs with
a sample rate of five seconds, while “Go2” will use a
sample rate of 10 seconds.
If a “Stop” control word is received, the program
will do just that by disconnecting the ADC and turning OFF the FETs. The program will then just wait
for something to do. After getting the go-ahead from
the PC, the program will continue to get an ADC
value and send it the computer at the selected sample time until a “Stop” command is received. Two
LEDs on the board give a quick visual of what is
going on; RED stopped, GREEN plotting.
The automated connection of the ADC is needed to prevent device damage by excessive V-input.
The ADC is connected to the load via a mini
relay AFTER the power resistors begin dividing the
voltage into a safe level. The ADC must also be
disconnected BEFORE the load circuit is open to
prevent device damage. Even though the routine is
simple, it is a great building block for more complex
control applications.
The Computer Program
The computer program was written using
Microsoft’s Visual Basic 6.0 programming environment for Windows. A tutorial on VB is way beyond
the scope of this article, but the easy-to-understand
syntax usually provides enough information for even
non-programmers to gain a good understanding of
what is going on. The entire program is too lengthy
to publish, but the complete program listing can be
found at the Nuts & Volts website ( www.nuts
volts.com) in their FTP library.
Listing 2 is really the heart of the program and
deserves recognition because most of the process-
JULY 2005
Listing 1. Interface board program.
$crystal = 10000000
Dim W As Word
Dim Relcon As String * 5
Dim Deltm As Byte
Dim Good As Bit
Good = 0
Config Pinc.0 = Output
Config Pinc.1 = Output
Config Pinc.5 = Output
Config Pinb.0 = Output
Portb.0 = 0
Portc.0 = 1
Portc.1 = 0
Portc.5 = 0
‘loop control
‘green LED
‘red LED
‘FET control
‘ADC control
‘ADC disconnect
‘green LED off
‘red LED on
‘load off
On Urxc Relay_con
Enable Urxc
Enable Interrupts
‘ interrupt routine set
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
Redo:
Do
Loop Until Good = 1
‘wait for a control word
Do
W = Getadc(0)
Print W;
If Deltm = 5 Then
Wait 5
End If
If Deltm = 10 Then
Wait 10
End If
Loop Until Good = 0
‘send data until stop is sent
Goto Redo
End
Relay_con:
Input Relcon Noecho
If Relcon = “Go1” Then
Deltm = 5
Portc.5 = 1
Waitms 500
Portb.0 = 1
Waitms 500
Portc.0 = 0
Portc.1 = 1
Good = 1
End If
If Relcon = “Go2” Then
Deltm = 10
Portc.5 = 1
Waitms 500
Portb.0 = 1
Waitms 500
Portc.0 = 0
Portc.1 = 1
Good = 1
End If
If Relcon = “Stop” Then
Portb.0 = 0
Waitms 500
Portc.5 = 0
Portc.0 = 1
Portc.1 = 0
Good = 0
End If
Return
‘get control word
‘use 5sec delay
‘Connect load
‘connect ADC
‘wait for relay to close
‘toggle LEDs
‘fall through do-nothing loop
‘use 10sec delay
‘stop analyzing
‘disconnect ADC
‘wait for relay to open
‘disconnect load
‘return to loop
45