Machine Design

How to Put the ‘Tronic in Mechatronic Designs

Mechanical products just got easier to convert to mechatronics using a new procedure which highlights block diagrams, flowcharts, and a relatively inexpensive software-development kit.

Dick Fisher
Director of Applications
Microchip Technology Inc.
Chandler, Ariz.

Small electromechanical devices commonly found in homes, factories, and vehicles are prime candidates for conversion to mechatronic products. They traditionally depend on timers, switches, counters, relays, discrete logic, and speed governors for their basic operation. And for many products that require upgrades or new features, and new products intended for high volumes, it’s becoming easier and less expensive to replace mechanical functions with microcontrollers.

Additional benefits gained in going to mechatronics include smaller devices that weigh less and use less power, and because they have fewer moving parts to wear, they last longer. What’s more, the functions are easily changed by reprogramming the device.

A clock with moving figures is used as an example to illustrate how to convert a mechanical design to a mechatronic one using first-time electronics intelligence by creating an embedded control. The intelligence selected for the device is an 8-bit microcontroller with only eight pins, an easily understood device to introduce the design procedure.

First, examine the block diagram of the mechanical clock. It shows a few basic components, including a fixed-frequency source with an elapsed-time-keeping method to provide the basic timer function of an embedded control system. Moreover, the basic timer and elapsed timer functions also provide the alarm. Reporting an alarm or an event is expressed by moving the turntable figures from their resting place and sounding bells. Lastly, the power source could be a pendulum, spring, battery, voltage, steam, or any renewable energy source. In any case, it must generate a stable, steady beat for the embedded control system.

Now the same system designed around a microcontroller should consider the following factors:

• A stable and predictable clock source
• Detecting or planning an event
• Deciding the result and responding; that is, setting an alarm or turning a timer on or off
• Reporting the results or controlling a function

Several components needed to fulfill these requirements are shown in the block diagram of the microcontroller-based clock. It includes components such as a watch crystal for the system clock, a CPU (central processing unit) for the math engine that takes commands stored in memory and uses them as an instruction list to run the tasks, and an ALU (arithmetic logic unit) — a Boolean math engine that operates math functions on binary numbers.

Also needed are standard input and output functions to move data into and out of the CPU, a digital register for holding data, instructions, and addresses, and a digital memory location (timer) that is updated or counted at predetermined times. The controller function for this implementation is the combination of CPU, line I/O, and a timer. Many single MCU or microcontrollers are available that contain all three functions on one chip.

A next step considers the software development. This amounts to programming the microcontroller with code that steps the system through a series of only 33 instructions to make the clock work. Each microcontroller manufacturer defines its own set of instructions or list of commands that the CPU interprets. For example, the simple computer programming instruction to load and move data is MOVLW 5 - MOVE”5” into W.

This instruction moves a literal value represented by 5 from the command word to the W register (working register), a RAM location. Programmers use the remaining 32 instructions to step the controller through a specific sequence that states what it must do next, when, and where within the embedded system.

A variety of standard development tools make it easy to develop and program this code and related system functions. The tools include the software to assist in code development. Emulators, for example, allow testing the code on a sample microcontroller, and programmers download the code into the chip.

A digital timer and a clock source replace the mechanical system’s time-keeping functions. Typically, this is an 8 to 16-bit timer clocked by a 32-kHz crystal. The crystal can emulate a real-time clock because its inherent structure vibrates naturally with the required accuracy. The counter or timer continually runs from this clocked input and maintains precision within the tolerance of the 32-kHz crystal.

An alternative approach develops a program loop that updates or adds a predetermined count to a register or RAM location. The timing is based upon the operating frequency of the microcontroller and its command flow. The code periodically checks for a predetermined value and acts accordingly, that is, branches or jumps to commands that energize the mechanical functions. The method allows implementing more than one timer, a distinct benefit.

Program instructions direct the ALU to help decide when to sound an alarm by comparing the present timer value to the alarm time in a predetermined register or memory location. Now the CPU part of the microprocessor, timer, and crystal combination as illustrated in the flowchart interprets instructions from the program memory of the microcontroller.

The microcontroller can emulate a clock with numerous functions including time of day, multiple alarms, elapsed-time counter, plus day and year. The microcontroller also includes a timer that runs continually off the system clock. This timer may be used to trigger elapsed-time events or generate a time-of-day clock.

The 32-kHz crystal generates the basic reference and the clock to increment the timer. The software monitors the timer and reports a comparison at the minute, hour, and 24-hr periods. One RAM-based register keeps track of timer values. The logic flow reads like this:

• Set the timer to count down from the 60-sec value
• When the timer decrements to zero, add a 1 to minutes value
• Check location (address) 0 for a value of 60 (one hour has passed). If yes, add 1 to the hour value
• Is hour value at 24? If yes, add 1 to day value (day counter)
• Reload the timer and continue decrementing

Microcontrollers also produce sounds. For example, they can generate a PWM (pulse-width-modulated) square-wave signal that sounds like a buzzer when connected to a speaker or horn.

Motion may now be added which includes activating solenoids, ringing bells, or moving figures. In addition, PWM signals can control a motor to rotate fans or a merry-go-round. Motion adds character, intrigue, and novelty to any timed application and at a reasonable price.

A lesson plan for getting an education in mechatronics
Microchip Technology Inc. offers two venues to help engineers grasp the basics of converting mechanical designs to electronic controls and develop them into a final product. The Mechatronics Power Pak kit, for example, includes a Microcontroller Primer which introduces microcontrollers and describes how to convert mechanical designs. The PIC12CXXX Applications Handbook, also in the kit, illustrates hundreds of simple mechanical functions converted into real-world microcontroller-based products.

The Picstart Plus Mechatronics Kit, the second learning tool, steps users through the programming of their first microcontroller with a low-cost software-development system. The company offers microcontroller samples, development tool information, and field application engineering support. For a free copy of the Mechatronics Power Pak and more information on Picstart Plus, visit or call (602) 786-7668.

© 2010 Penton Media, Inc.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.