Testing battery powered devices

Battery powered devices present unique test challenges. During development, a circuit may be powered from a fixed power supply to eliminate the variability and hassle of debugging with a battery. However, this does not reflect the real environment the circuit will operate in. As a battery discharges its voltage decreases following a battery specific curve until at some point the battery is exhausted and its output voltage collapses. Eventually the device will have to be tested in its real-world environment.

Testing a devices behavior as the battery discharges can be time consuming and make reproduction of any failures difficult. A better approach would be to simulate the battery discharge curve over a shorter time period, sufficiently long to allow the device to experience and react to the shifting voltage and short enough that the test can be completed in a reasonable time frame. This allows repeated tests if any failure occurs.

To help with these kinds of problems, Five Wire includes the Waveform Source which is capable of acting as a power supply. Its output can drive voltages between 0 – 5 V with load currents up to 100 mA. It can be configured to generate a fixed output such as +3.3V DC but also includes standard waveforms that simulate battery types such as  Alkaline, Ni-Cad, Li-ion, Ni-MH, and LiPo. The discharge time can be adjusted to 60 seconds, 300 seconds (5 minutes), or longer. Simulating battery operation of your device using the Five Wire Waveform Source allows you to quickly test and debug issues related to battery operation. Here is an example of a LiPo discharge over a 5 minute period using the Waveform Source.

If the battery type or discharge curve you want to test is not directly supported in the menus, you can create your own custom waveform for testing. The Five Wire Waveform Source is an arbitrary waveform generator (AWG). It has 10 bits of vertical resolution, 0 – 5 V output, and each waveform can include up to 1020 points. The time duration of each point is settable with a range from 10 microseconds to 20 seconds for a maximum waveform duration of 20,400 seconds (more than 5 hours). The waveform can be developed using a spreadsheet or using MBScript, a ‘C’ like scripting language included in the Five Wire application software.

Creating custom analog waveforms

The five Wire Waveform Source is an arbitrary waveform generator (AWG). To simplify the user experience the GUI includes standard waveforms such as sine, square,  triangle, RC, battery, and DC with settable parameters such as frequency/period, duty cycle, amplitude, etc. The standard waveforms are easy to use but do not show the full power of the Waveform Source.

The Waveform Source generates 0 – 5 V output with 10 bits of resolution. Up to 1020 points can be defined each having a duration from 1 us to hundreds of seconds each. Just like the Logic Source, the Waveform source includes 3 jump controllers providing branch and counted loop control. You can easily generate a custom waveform using the MBScript scripting language. In our first example we will write a script which creates a square wave by combing the fundamental, 3rd, 5th, 7th, and 9th harmonics of a 1KHz sine wave.

The script defines a function waveValue() to calculate the signal magnitude at each point. This includes a 2.5 V offset to center the waveform and the fundamental sine wave and its odd harmonics scaled according to the Fourier series. The pattern includes 630 points with factors of 2 x 3 x 3 x 5 x 7 ensuring that complete integral cycles of each harmonic can be created. A for() loop sets the first 659 points by calling the function setPoint(). The last point is created with a jumpA command which is configured to branch back to the beginning of the waveform in an infinite loop. Here is the complete script.


// Include the WS_Lib.mbs library
addLibrary scriptDirectory + “WS_Lib.mbs”;

// Waveform parameters
fundamental = 1e3; // fundamental frequency is 1KHz

points = 630; // 2*3*3*5*7 = number of waveform points to use
dt = 1/(fundamental*points); // Period of eaach point

// Calculate the magnitude of the waveform at a specific phase
function waveValue(deg)
{
return 2.5 + sin(deg) + ((1/3)*sin(3*deg)) + ((1/5)*sin(5*deg)) + ((1/7)*sin(7*deg)) + ((1/9)*sin(9*deg));
}

SY(“openWindow waveformSource”);

// Generate and load the waveform
for(i=0;i<points;i++)
{
d = i*360/points;
setPoint(i, waveValue(d), dt, “next”);
}

// Create the last point with a jumpA mode
i–;
d = i*360/points;
setPoint(i, waveValue(d), dt, “jumpA”);

// Configure jumpA to always jump to the first point
configJump(“jumpA”, “always”, 0, 1);

// Update the waveform display
update(dt*points);

// Run the waveform
WS(“run”);


Running the script opens the Waveform Source window, loads the waveform, updates the Waveform Display to show its shape in the GUI, and runs the pattern on the Waveform source. Here is a partial screen capture of the Waveform Display view.

Here is a cell phone pic of an oscilloscope display.This shows that it is fairly straight forward to create your own waveforms by replacing the waveValue() function. For example you may want to step between two frequencies inside and outside of a filter pass band. Here is a waveValue() function that toggles between 1KHz and 3KHz

function waveValue(deg)
{
if(deg < 360)
return 2.5 + sin(deg);
else
return 2.5 + sin(3*deg);
}

We configure the A and B jump controllers to repeat each frequency for 100 cycles and the C jump controller branches back to the beginning of the waveform forming an infinite loop. Here is a cell phone scope capture of the frequency transition.

The Waveform Source provides quick easy to use standard waveforms. By writing a little MBScript code you can take full advantage of its AWG features.

Creating custom digital waveforms

Embedded systems often take external real world inputs from sensors evaluating their characteristics to produce a desired control function. For example, a micro-controller might accept a quadrature hall sensor input that indicates motor rotation. This input is used to determine motor RPM as part of a closed loop feedback system that controls motor drive via a PWM output to a full bridge driver. However, the real physical motor to be controlled may not be available for initial code development or may be impractical to have sitting on the developers bench. It is also difficult to get repeatable results using physical devices making it difficult to evaluate performance characteristics of the feedback loop. For these cases it can be advantageous to simulate the motor input or PWM output during early development of the system.

The Five Wire Logic Source tool is a digital pattern generator which provides a simple user interface for creating custom digital signals to stimulate the inputs of your circuits. It provides up to 1020 digital values with each value having a unique duration from 30 ns to 40 ms. The sequential output of vectors can be modified by up to three loop controllers branching execution to form loops, counted repeats, or conditional branching. In this post we will explore how these features can be used to create simulations of real world signals that can be used to evaluate embedded system performance.

We can generate the motor sensor quadrature output using two digital output signals. The pattern only requires 4 vectors, one for each 90 degrees of rotation – 00, 01, 11, 10. This pattern is continuously repeated.The period of each vector should be 1/4 of the motor rotation period. For example, if the motor is rotating at 600 RPM then the motor is rotating 600 / 60 = 10 times per second so the full period is 100 ms. The duration of each of the vectors should be 25 ms. The pattern should then repeat so an unconditional loop branching to the pattern start should be placed on the 4th vector. Here is a partial screen shot of the Logic source pattern editor screen to produce this signal.

This will provide a fixed RPM signal to help development of input timers and RPM calculation algorithms.

Once the input structure is functional it can be handy to evaluate the dynamic performance of the feedback algorithms. This can be accomplished by generating a motor RPM step to see how the algorithm reacts. The motor RPM is set to one value for a number of rotations and then changes to a second value for a set of rotations. For example, we can generate a step from 600 RPM to 900 RPM. The motor will make 100 rotations at each speed. Then the process will repeat.

To create this pattern we will use counting repeat loops. Each loop will repeat 99 times followed by one rotation outside of the loop. The 600 RPM vector period was calculated above. The 900 RPM period is as follows. 900 / 60 = 15 rotations per second making the rotation period 66.67 ms. Each vector period must be 16.67 ms for 1/4 of a rotation.

To fully control the pattern sequence we place the Logic Source in Custom pattern mode. We change the A loop control to type Inner Loop with a jump target of 0 and a loop count of 99. This will replace our original infinite loop. We repeat the vector pattern one more time following the repeat loop. So the 600 RPM pattern is implemented in vectors 0 through 7.

We use vectors 8 through 15 to implement the 900 RPM section. The pattern is the same but the vector duration is 16.67 ms. We use the B loop to repeat the 900 RPM pattern 99 times followed by one more rotation. On vector 15 the C loop branch is used to return to vector 0 repeating the overall pattern. Here is the partial screen capture of the pattern.

Here is a screen capture using the Logic Analyzer showing the step from 600 to 900 RPM.

For additional analysis it may be desirable to generate signals that are a linear function of time. For example, you may want to sweep over a range of RPM or create an RPM which includes noise or a sinusoidal oscillation to verify the operation of the feedback loop. Although these kind of patterns could be entered manually it is much simpler to create them using the scripting language MBScript.

Here is a script that generates 256 vectors (n) resulting in 64 motor rotations with a starting  speed of 600 RPM speeding up on each rotation and ending at 1200 RPM. Each iteration of the for loop creates 4 vectors or 1 rotation of the motor.


addLibrary scriptDirectory + “LS_lib.mbs”;

// Stop in case we are running and configure jump controller A to jump to sequence zero
cmd(“stop”);
configJump(“jumpA”, “always”, 0);

// Sweep from 25ms to 12.5ms phase period
t = 25e-3;
n = 256;
dt = (25e-3 – 12.5e-3) / n;

// Load the pattern
for(i=0; i<n; i+=4)
{

d = t – ( i * dt );
vector(i, 1, d);
vector(i+1, 3, d);
vector(i+2, 2, d);
vector(i+3, 0, d);

}

// Set the loop jump and event out
configMode(i-1, “jumpA”);
configMode(0, “event”);

// Update the GUI display and run the pattern
cmd(“updatePatternDisplay”);
cmd(“run”);


Running this script will open the Logic Source tool, program the series of vectors calculating the duration for each rotation, and set a branch loop to vector 0 at the end of the pattern. Here is a partial screen shot of the start of the pattern. You can see that the vector duration decreases on each set of 4 vectors.

Capturing the digital output with the Logic Analyzer tool shows the effect of the sweep pattern.

Other linear functions can be used to control the motor RPM by replacing the function
d = t – ( i * dt );

with another function such as
d = t + (5e-3*sin( i * 360 / n ));

This would impose a sine variation on the waveform.

The same approach can be used to generate reference PWM signals to control the full wave bridge driver and motor. Using a step function the dynamic performance of the motor can be determined by capturing its quadrature output signal with the Logic Analyzer tool. The captured data can be exported to a spreadsheet or processed with MBScript or Python. Five Wire provides the ability to better evaluate and test these dynamic systems.