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.

Below 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.