ChipCenter Questlink
SEARCH CHIPCENTER
Search Type:
Search for:




Knowledge Centers
Product Reviews
Data Sheets
Guides & Experts
News
International
Ask Us
Circuit Cellar Online
App Notes
NetSeminars
Careers
Resources
FAQ
EE Times Network
Electronics Group Sites

RC SERVO CONTROL VIA TPU


Circuit Cellar Online
THE MAGAZINE FOR COMPUTER APPLICATIONS
Circuit Cellar Online offers articles illustrating creative solutions
and unique applications through complete projects, practical
tutorials, and useful design techniques.

RC SERVO CONTROL VIA TPU

Lessons from the Trenches by Jeff Loeliger

Start ý The Answer Isý ý Designing Functions ý Demonstration ý Youýre in Control ý Sources and PDF

DESIGNING FUNCTIONS

Figure 3ýThe main flow is for normal operation of the function and state 1 is used for immediate updates.

 

The best way to design TPU functions is through state diagrams. The TPU is event driven, which correlates well to the states. This function has five states that initialize and control the output of the servo control signal. The state diagram and associated control waveform is given in Figures 3 and 4. Table 1 outlines the actions of each state.

Figure 4ýHere you can see the relationship of the parameters and states to the output waveform.

 

State 0 is the first state executed. Itýs responsible for initializing the whole function and scheduling the rising edge match. After the parameter RAM in the TPU is set up, the host CPU issues a host service request (HSR%11) to the TPU, which causes state 0 to be executed. State 2 generates the rising edge of the output control signal and calculates when the falling edge should happen. State 3 is entered when the falling edge is generated. It starts the long delay that is held by state 4 until the next control signal is generated.

In addition to the basic control states, there is an Immediate Update state (state 1). Normally the output signal is only updated every 20ý30 ms. State 1 gives the option of updating it sooner as long as the control waveform is still high. If the TPU is currently generating the active portion of the output signal, updating the POSITION parameter and issuing a host service request (HSR%01) will cause the function to change the output signal value immediately.

State 2 must perform a multiply-and-divide calculation to determine the output signal. Because the TPU does not have a multiply instruction, hardware is used to help perform a shift-and-add multiply algorithm. To calculate the output signal, a 16 x 8 bit multiply is required, giving a 24-bit answer. The most significant 16 bits of the answer are then stored in the A register while the least significant eight bits are stored in the Shift Register (SR).

Because there are 256 output positions, a divide-by-256 would be required on the A register and Shift Register to give the final answer. This would be equivalent to eight successive right shifts so the A register can be considered to hold the final answer and the data in the Shift Register can be ignored and used merely for rounding. This method allows complex multiply-and-divide calculations to be executed in only three instructions and 10 TPU cycles. The multiply-and-divide operation, in the middle of state 2, is shown in Listing 1.

The key to creating a fast TPU function is mapping the function states to the TPU entry table efficiently. By doing this, the TPU is able to determine what state to execute without using any code. All of the states (except state 1) map directly to the TPU entry table. State 1 is instead divided into two substates (state 1a and state 1b) that are mapped directly to the entry table. States 0, 1a, and 1b are entered when a host service request (HSR) is issued.

When a match between the TPU channelýs compare register and the selected TPU timebase occurs, states 2, 3, and 4 can be entered. State 2 is entered if the output pin is high after the match, with states 3 and 4 being entered if the pin is low. An internal software flag in the TPU (flag 0) then determines whether state 3 or state 4 should be entered. The TPU defines what level the output should be when a match occurs to ensure that the flow follows the state diagram.

The servo function was written for the TPU3 on the Motorola MPC555 but will work on any version of the TPU. The complete code for the servo function can be obtained from the Circuit Cellar website.

PREVIOUSNEXT


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.
Click here to get your listing up.

Copyright © 2003 ChipCenter-QuestLink
About ChipCenter-Questlink  Contact Us  Privacy Statement   Advertising Information  FAQ