In this chapter, we will go through the complete process of application design and development, based on a simple motor drive system, to illustrate the principles outlined in the preceding sections. At each step, basic design techniques will be explained and a suitable implementation developed.
Before designing hardware or writing a program, we have to describe as clearly as possible what an application is required to do; this means a specification is needed which defines the user’s requirement. Once the specification has been written, a prototype hardware design can be attempted; a useful starting point for hardware design is a block diagram. We have already seen some examples in previous chapters. It should represent the main parts of a system and the signal/data flow between them, in a simplified form.
This can later be converted to circuit diagrams and the hardware connections laid out and constructed on a printed circuit board (PCB). In a similar way, software can be designed using techniques that allow the application program to be outlined, and then the details progressively filled in. Flowcharts have been used already, and this chapter will explain in more detail the basic principles of using flowcharts to help with program design.
Pseudocode is another useful method for designing software. This is a program outline in text form that can be entered directly into the source code editor as a set of general statements that describe each major block, which would be defined as functions and procedures in a high-level language, and subroutines and macros in a low-level language. Detail is then added under each heading until the pseudocode is suitable for conversion into source code statements for the assembler or compiler for the target processor or programming language.
At this stage, we will concentrate on flowcharts, as their pictorial nature makes them a useful learning tool. The first step in the software design process is to establish a suitable algorithm for the program; that is, a processing method that will achieve the specification using the features of an available programming language. This obviously requires some knowledge of the range of languages that might be suitable, and experience in the selected language. Formal software design techniques cannot be properly applied until the software developer is reasonably familiar with the relevant language syntax. However, when learning programming we have to develop both skills together, so some trial and error is unavoidable. When learning, it is useful to apply these design techniques retrospectively, that is, as an analytical tool or as part of the application documentation. For instance, a final version of a flowchart might be drawn after the program has been written and tested, when the suitability of the design algorithm has been proven.
Real software products will generally be far more complex than the simple examples considered here, but the same basic design principles may be applied. If the design brief is not specific about the hardware, considerable experience and detailed knowledge of the options available is required to select the most appropriate hardware and software combination. The relative costs in the planning, development, implementation, testing, commissioning and
support of the product should also be estimated to obtain the most cost-effective solution. Naturally, the example used here to illustrate the software development process has been chosen as suitable for PIC® implementation.
Design Specification
The application program will be required to generate a pulse width modulated (PWM) output to drive a small, brushed direct current (dc) motor. This can be generated by a specially designed hardware interface in many microcontrollers (MCUs), including PICs, as it is
a common requirement. The software implementation will help us to understand the operation of the hardware-based PWM interface, which will be described later.
Under PWM control, the motor runs at a speed that is determined by the average level of a pulsed signal, which in turn is dependent on the ratio of the on (mark) to off (space) time, or ‘duty cycle’. This method provides an efficient method of using a single digital output to control output power from a motor, heater, lamp or similar power output transducer. PWM is also used to control small digital position (hobby) servo units, as used in radio-controlled models. The basic drive waveform is shown in Figure 8.1.
A variable mark/space ratio (MSR) of 0e100%, with a resolution of 1%, is required.
The frequency is not critical, but should be high enough to allow the motor to run without any significant speed variation over each cycle (> 10 Hz). It is desirable to operate at a frequency above the audible range (> 15 kHz) because some of the signal energy can radiate as sound from the windings of the motor, which can be quite irritating! A higher frequency of operation also ensures full averaging of the current. However, it is more practical to implement this using the dedicated (hardware) PWM interface, so we will aim for lower frequency of operation just to demonstrate the principles involved. The interfacing hardware is also simplified; a single field effect transistor (FET) drive transistor is used to drive the motor in one direction only, such as
would be required in a ventilation fan. A full bridge driver with four FETs is normally used to provide bidirectional motor control, which would be needed in a position controller, for example.
The motor speed will be controlled by two active low inputs, which will increment or decrement the PWM output. An active low enable signal is also required to switch the drive on and off, while preserving the existing setting of the MSR. The system should start on reset or power up at 50% MSR, that is, with equal mark and space, and a reset input should be provided to return the output to the default 50% MSR at any time. The increment and decrement operations must stop at the maximum and minimum values; in particular, 0% must not roll over to 100%, causing a zero to maximum motor speed transition in a single step. The inputs and outputs must be TTL (transistoretransistor logic) compatible (þ5 V nominal signals) for interfacing purposes, allowing PWM control from a separate master controller. A programmed device (i.e. PIC) allows the control parameters to be modified to suit different motors and to enable future enhancement of the controller options and performance. A performance specification and a control logic table (Table 8.1) define the operational characteristics required.