Programmable Control Teachers Notes



Teacher’s Notes

Contents

|Introduction |75 |

|Assignments and activities |75 |

|Assignments |75 |

|Practical activities |75 |

|Project assignments |75 |

|General Notes on Using the Stamp Controller |76 |

|Hardware |76 |

|Software |76 |

|Software installation – Acorn |76 |

|Software installation – Windows |76 |

|Serial Port Information for PC Users |78 |

|Identifying the serial ports |78 |

|Two or more ports |78 |

|Only one port? No problem |78 |

|Additional serial ports and modem cards |79 |

|Software |79 |

|Other equipment |79 |

|Standard Programming Format |80 |

|PBASIC Commands |81 |

|Input/output |81 |

|Time |81 |

|Looping |81 |

|Program flow |81 |

|Subroutines |81 |

|Miscellaneous |81 |

|Equipment List |82 |

|Stamp Controller equipment required |82 |

|Other equipment |82 |

|Control models |83 |

|MOD-001 buggy model |83 |

|MOD-002 washing machine model |83 |

|MOD-003 bank safe model |83 |

|Electronic toy |84 |

|Software and Minimum Computer Specifications |86 |

|PC: 16-bit Windows |86 |

|PC: 32-bit Windows |86 |

|Acorn |86 |

|Mac |86 |

|Upgrading computer systems |86 |

|Contact Addresses |87 |

|Answers to Assignments |88 |

Introduction

Assignments and activities

The students’ notes are broken down into a number of sections for clarity. The sections should be completed in sequence, as knowledge of the software techniques introduced in previous sections is assumed in the latter sections.

Assignments

Each section involves a number of assignments. The earlier assignments in each section are simpler questions/activities that cover important teaching points, and the later assignments build up to longer examination-style questions. It is therefore important that students complete all the assignments within a section.

Practical activities

Practical activities differ slightly from assignments in that there is no assessment requirement for the activity. Practical activities are used mainly as ‘tutorials’ to demonstrate different software techniques. Students are expected to complete each activity.

Students should not be allowed simply to open and download ‘pre-saved’ files when completing activities. It is through the process of keying in the program that an understanding of the program operation will be gained. Each activity program is kept deliberately short so that this keying-in time is not too great.

Project assignments

It is through practical problem-solving exercises that students develop the key skills of identifying systems, selecting input and output transducers, drawing flowcharts and developing PBASIC programs.

The project assignments at the rear of the student materials provide 20 suggested activities for problem-solving exercises. Further suitable project briefs may be set by the teacher/lecturer at his/her discretion.

General Notes on Using the Stamp Controller

Hardware

1. The stamp controller has 8 input/output pins. Within the Standard Grade course, pins 0 to 3 are used as inputs, 4 to 7 as outputs.

2. The stamp controller provides digital (logic-level) outputs. To drive high current loads, such as motors, an interfacing circuit (for example the Outputs Driver module) must be used.

Software

3. The student assignments do not explain how to perform software procedures such as saving programs, downloading, editing, etc. This is because these techniques vary according to the computer platform being used. These techniques are explained for the Windows version of the software in Section 2 of the student notes.

4. Students are expected to add comments and correctly use ‘white-space’ within each of their PBASIC programs.

5. PBASIC programs use labels (rather than line numbers) for addressing purposes.

6. Schools may distribute the Basic Stamp software to students for home use if desired. There is no charge for the software when distributed in this manner.

Software installation ( Acorn

Computer requirements:

• RISC-OS 3.0 or greater

• 1 MB RAM or greater

• mouse

• serial port.

Note that the A3000 and earlier models may require an RISC-OS upgrade, and the A3000 requires the optional ‘serial port upgrade’ to be fitted. For further details on these upgrades contact your usual Acorn dealer, or Castle Technology, telephone (01728) 621622. The software does not operate with RISC-OS 3.0.

The software will run directly from the floppy disc. However, if your computer has a hard disc, the software will run more efficiently if you copy it to the hard disc.

1. Insert the !AStamp disc into the floppy disc drive.

2. Create a new directory called ‘Stamp’ on the hard disc.

3. Open the floppy disc file directory and drag all the icons into the new directory on the hard disc.

Software installation ( Windows

Computer requirements

• 486 processor (or greater)

• 4 MB RAM (or greater)

• available serial port

• Windows 95/98/NT (or greater)

Note that if you are running Windows 3.x you must use the 16-bit Stamp Editor (order code BAS-201) instead of the 32-bit version.

The software is compatible with all network types.

To install the software:

1. insert Stamp Editor Disc 1 into the floppy disc drive

1. click ‘Start’ and select ‘Run’

1. type a:\setup (enter)

1. follow the on-screen instructions

1. after installation is complete, run the software by clicking ‘Start>Programs>Stamp Editor’

1. select the correct serial port (COM1 to 4) by selecting ‘Options’ from the ‘File’ menu.

Serial Port Information for PC Users

This information sheet is designed to provide answers to the most common enquiries that Revolution technical support staff receive about the installation of equipment and software using the serial port.

Please read the sheet carefully before calling ( your answer may well be here!

Identifying the serial ports

Most computers have one or two serial ports. On the rear of the computer look for either a 9-way male D-connector or a 25-way male D-connector (male connectors have visible ‘pins’ rather than ‘holes’). If the port is labelled, it may be marked ‘Serial’, ‘RS232’, ‘101010’, ‘COM1’ or ‘COM2’.

Two or more ports

Most modern computers have two 9-pin D-connectors, called COM1 and COM2. In this case, either port can be used. Older computers also usually have two serial ports, but sometimes have one of each size. The first port, COM1, is often used for the mouse, leaving COM2 for connecting external equipment. If COM2 is a 25-way connector you will require a 9(25-way adapter, as the cable supplied with our equipment is the more common 9-way type. This type of adapter is commonly known as a ‘mouse adapter’ and may be purchased from Revolution (ADA-010) or from any high street computer store. Or you may have one lying around already ( they are sometimes supplied with a new mouse!

Only one port? No problem

Some modern computers are equipped with just one 9-way serial port. Unfortunately some manufacturers still supply a mouse that uses this port, which leaves no serial port available for connecting external equipment! Fortunately these machines also have a ‘PS/2’ port available for the mouse (6-pin mini-DIN socket, normally beside the keyboard socket, marked with a ‘mouse’ symbol), and so it is possible to free up the serial port by using a PS/2 mouse instead.

To do this, carry out the following procedure.

1. Purchase a PS/2 mouse (from any high-street computer store). Unfortunately you cannot normally ‘adapt’ the existing mouse ( you must buy a new one. New PS/2 mouses are available for under £10.

1. Turn the computer off.

1. Remove the old mouse and connect the new one.

1. Restart the computer. Windows 95/98/NT should automatically notice the change and prompt you with instructions. With older versions of Windows it will be necessary to reinstall the mouse driver (use the disc supplied with the new mouse and follow the instructions provided with the mouse).

1. Restart the computer again. The new mouse should operate correctly, and the serial port should now be available for use.

Do not try to ‘cheat’ by repeatedly swapping the mouse and equipment cables ( yes, people do try it! This will not work: the mouse driver will always be running, even if the mouse is not connected, and so the software application will not operate correctly. This process could also cause damage to the computer and/or equipment.

Additional serial ports and modem cards

You may purchase additional ‘slot-in’ PC cards that provide one or two extra serial ports, often labelled COM3 and COM4. Internal modem cards also require use of one of the serial ports. It is important to realise that you cannot generally use COM1 and COM3 (or COM2 and COM4) simultaneously, as they ‘share’ interrupts. Therefore, for instance, you cannot use external equipment on COM3 if you have a mouse on COM1, as an interrupt conflict will occur. The setup of PC cards often requires setting base addresses and interrupts through jumper settings. Revolution cannot provide any technical support for this: contact your PC manufacturer if you require help.

Software

All Revolution Windows software applications automatically identify which serial ports are currently available when the application loads. If a particular serial port is not available it will appear ‘greyed out’ on the selection panel, so that it is not possible to select it. If this problem is caused by another Windows application already using the port (for example fax or internet software), this can be corrected by exiting from the Revolution application, exiting from the other application and then restarting the application.

Other equipment

The stamp controller cable is a pin-to-pin, straight-wired cable. Therefore, it may be left permanently attached to the serial port at the rear of the computer. If you wish to use other serial equipment on the same computer, the cable from the other equipment may be safely connected directly to the stamp controller cable. This removes the need for students to add/remove cables at the rear of the computer.

Standard Programming Format

All students are expected to use a common format when solving problems. All flowcharts are to use the symbols as explained in the students’ notes, and all PBASIC programs are to follow the standard format.

main: high 7 ' set pin 7 high

pause 5000 ' wait for 5 seconds

low 7 ' set pin 7 low

goto main ' loop forever

All programs start with a ‘main’ label. The tab key is used to align commands, with only labels appearing at the start of a line. Every program line has a comment included behind an apostrophe (') symbol.

PBASIC Commands

The PBASIC commands to be used in the Standard Grade course are listed below. These commands are also listed at the rear of the student notes. Note that the software must be configured to ‘Extended PBASIC’ mode when using the ‘sensor’ command.

Input/output

low switch an output pin off (low)

high switch an output pin on (high)

sensor reads an analogue input (A or B) and gives a scaled value 1–240

Time

pause pause for between 1 and 65,535 milliseconds

Looping

for ( next create a for ( next loop

Program flow

if ( then test an input and jump to label

goto jump to address label

Subroutines

gosub jump to sub-procedure

return return from sub-procedure

Miscellaneous

end end the main program

debug send variables to computer for viewing (not examinable)

symbol allocate a symbol for a variable or value

Equipment List

Stamp controller equipment required

7. BAS-110 Stamp controller

8. BAS-119 Output driver

9. BAS-121 Input module + sensors

10. PWR-010 9 V d.c. power supply

• EW2-001 buzzer

• EW2-007 d.c. motor

CP2-001 propeller

All of the above modules and equipment are included in the economical stamp controller starter pack. This pack, which is supplied in a high-quality plastic storage tray to store all items, also includes a perspex cover to protect the stamp controller and software discs.

• BAS-900 Stamp controller starter pack

Other equipment

The PWM control activity requires a small d.c. motor. It is strongly recommended that a solar motor EW2-011 is used, as this can be run at much slower speeds than standard ‘toy’ d.c. motors. A propeller mounted on the shaft makes the movement much more visible.

• EW2-011 solar motor

• CP2-001 propeller

The stepper motor activity requires a stepper motor.

• EW2-017 stepper motor

Control models (see the ‘Control models’ section for further details)

• MOD-001 buggy

• MOD-002 washing machine

• MOD-003 bank safe

All modules and models are produced by Revolution Education and are available from:

Business Information Centre

Innova Park

Mollison Avenue

Enfield EN3 7XU

Tel: 020 83501315

E-mail: info@rev-ed.co.uk

Web: rev-ed.co.uk

Control models

A very important aspect of the course is the control of ‘real’ mechatronic systems. It is therefore expected that students have access to three-dimensional models for control exercises. These models may be purchased in kit-form from Revolution Education Ltd, fabricated from constructional sets (such as LEGO or Fishertechnik) or manufactured from discrete materials. Many schools may already possess a number of these types of models.

The course describes the use of three models. However, schools may develop further models for extension exercises.

MOD-001 buggy model

This model is a simple buggy that can be used to demonstrate simple programming techniques.

This apparatus should consist of a small buggy with two motors driving a wheel on each side. Two microswitches should be mounted to the front of the buggy to act as ‘collision bumpers’.

|Input connection |Pin |Output connection |

| |7 |motor B reverse |

| |6 |motor B forward |

| |5 |motor A reverse |

| |4 |motor A forward |

| |3 | |

| |2 | |

|switch 1 |1 | |

|switch 0 |0 | |

The outputs are connected to the output driver module. The microswitches are connected to the input module.

MOD-002 washing machine model

This piece of apparatus should represent a washing machine.

|Input connection |Pin |Output connection |

| |7 |motor reverse |

| |6 |motor forward |

| |5 |solenoid bolt |

| |4 |LED |

| |3 | |

| |2 | |

|door microswitch |1 | |

|start switch |0 | |

The outputs are connected to the output driver module. The switches are connected to the input module.

MOD-003 bank safe model

This model should represent a bank safe.

|Input connection |Pin |Output connection |

| |7 |buzzer |

| |6 | |

| |5 |solenoid/red LED |

| |4 |green LED |

|lock switch 3 |3 | |

|lock switch 2 |2 | |

|lock switch 1 |1 | |

|door microswitch |0 | |

The outputs are connected to the output driver module. The microswitches are connected to the input module.

Electronic toy

The electronic toy looked at as a case study in the first section is a Furby™ from Tiger Electronics Ltd. This toy is an ideal example, as it is a complex mechatronic device to which students can easily relate. If available, an actual working toy will help stimulate the students.

If desired, the outer fur of the Furby™ can be removed so that the mechanisms are clearly visible. If carried out carefully, this will not affect the operation of the toy, although it should be noted that it will not be possible to reattach the fur once it is removed.

Tools required: small screwdriver, side-cutters, craft knife.

1. Remove the batteries from the base.

2. Feel along the bottom of the ear for the plastic actuator. Gently ease this out of the ear and cut the stitch securing it to the top of the ear. Repeat for the second ear.

3. The fur is held around the base of the toy by a standard plastic cable-tie. Cut this tie at the rear with a pair of side cutters.

4. It will now be possible to pull the fur up and over the toy, so that it is only attached in the faceplate area. The fur is stuck with glue around the ears, but this can be easily pulled off.

5. The fur is sewn to the faceplate. Remove the two screws holding the faceplate in position. Remove the faceplate. If necessary, the stitches holding the fur to the faceplate can be cut to increase access.

6. Remove the six screws holding the outer casing in place. Remove the outer casing, taking care not to pull the microphone out of its location in the casing.

7. Replace the batteries.

Points of interest

• A single motor is used for all movements. A gear train drives a worm gear that then drives the cam mechanisms. The cams, rack and pinion, etc., are all readily visible. The central cam hits a microswitch at the central position, which provides positioning feedback. Holding this switch open when the toy is operating will show how the feedback signal is needed for accurate repetitive use. An infra-red LED and sensor are located on either side of one of the gears (behind the speaker) to count revolutions.

• An LDR, infrared LED and infrared sensor are clearly visible between the two eyes. The infrared signals are used to enable two or more toys to communicate with each other.

• Decoupling capacitors are clearly visible across the motor contacts.

• The tilt switch uses a ball-bearing rather than the hazardous ‘mercury’ types.

Software and Minimum Computer Specifications

The stamp controller is programmed using a computer. Three versions of the Stamp software are available for different computer platforms/operating system combinations. The following information provides the minimum system requirements to run each version of the software.

PC: 16-bit Windows

winstamp.exe – 386 processor, 4 MB RAM, Windows 3.x, serial port

PC: 32-bit Windows

winstamp32.exe – 486 processor, 8 MB RAM, Windows 95/98/NT 3.51, serial port

The Windows applications are fully compatible with all network types.

Acorn

!AStamp – RISC-OS 3.0, 1 MB RAM, mouse, serial port

Note that some older Archimedes machines (for example the A3000) may require an operating system upgrade and/or serial port upgrade. Chips required for serial port upgrade: 65C51 (28 pin) and LT1133 (24 pin). These chips are available from Farnell Electronics.

Mac

There is no ‘native’ Mac version of the software and so the Windows emulator SoftWindows must be used with the Windows version of the Stamp software. Owing to the relatively high purchase cost of the PC emulator software, some schools have collected old ‘386/486’ PCs for dedicated Stamp use.

Upgrading computer systems

The same stamp controller module is used for all computer platforms. The same programming ‘language’ syntax is also used for all systems. Therefore, changing computer systems at a later date simply involves buying new cables (if required) and obtaining the alternative software. This software can be downloaded free of charge from the internet or can be provided on disc.

Contact Addresses

Revolution Education Ltd

Business Information Centre

Innova Science Park

Mollison Avenue

Enfield

EN3 7XU

Tel: 020 8350 1315

Fax: 020 8350 1351

Web: rev-ed.co.uk

Middlesex University Teaching Resources

Teaching Resources

Middlesex University

Trent Park

Bramley Road

London

N14 4YZ

Tel: 0181 447 0342

Fax: 0181 447 0340

Answers to Assignments

Assignment 1.1

List three electronic devices.

• Gameboy toy

• Television remote control

• Calculator

List three mechatronic devices. Explain the ‘mechanism’ in each of the three mechatronic devices listed.

Computer CD-ROM drive: the eject mechanism is a mechanism that is controlled by an electronic system.

Microwave oven: the turntable is a mechanism controlled by an electronic system.

• Remote door lock in a car: the lock and movement of the handle, etc., are mechanisms controlled by an electronic system.

Assignment 1.2

Draw a systems diagram for the electronic toy described above.

[pic]

Assignment 1.3

List the input and output transducers for the following devices.

|Device |Inputs |Outputs |

|(a) washing machine |door switch |motor |

| |cam/selection switches |solenoid valves |

| |temperature sensor |heater |

|(b) personal stereo |switches |motor |

| |variable resistors |speaker |

| | |LED |

|(c) vending machine |coin sensor |motors |

| |keypad |LED display |

|(d) hairdryer |switches |motor |

| | |heater |

Assignment 1.4

List the advantages of using a microcontroller within a product design.

One microcontroller can often replace a number of separate parts, or even a complete electronic circuit. Some of the advantages of using microcontrollers in a product design are:

11. increased reliability and reduced stock inventory (as one microcontroller replaces several parts)

12. simplified product assembly and smaller end products

13. greater product flexibility and adaptability since features are programmed into the microcontroller and not built into the electronic hardware

14. rapid product changes or development can be made by changing the program and not the electronic hardware.

Assignment 1.5

List three devices that may contain a microcontroller. Explain why you think it would be useful to have a microcontroller in these devices.

• Burglar alarm

A burglar alarm may contain a microcontroller because all buildings are different and, therefore, require different numbers and types of sensors. A microcontroller can easily be programmed with different programs for each building.

• ‘One-touch’ style TV remote control

A TV remote control that works with all types of television may use a microcontroller. All the control codes for hundreds of types of television can be stored in the microcontroller, so that users can select the type of television they want to use with the remote control.

• Christmas-tree lights controller

Many people like their Christmas-tree lights to show various patterns. However, the lights are only used for a short part of the year and so most people would not pay a lot of money for the control system. Microcontrollers are cheap and can contain a number of different light sequences, and so are ideal for this application.

Activity 2.b

Remove the serial cable and power supply from the stamp controller. Reconnect the power supply and see if the program restarts. How else can you restart the program?

By pressing the reset switch on the stamp controller.

Assignment 2.1

Explain how the stamp controller system operates.

The stamp controller ‘runs’ programs that have been downloaded to it. It has indicator LEDs to show which outputs and inputs are on or off, and has connectors for the input and output modules.

Assignment 2.2

Explain why the stamp controller can run a program when the serial cable is not connected to the computer.

The ‘brain’ of the stamp controller board is the 18-pin microcontroller chip in the centre of the board. The program is stored in the 8-pin EEPROM memory chip. This type of memory can be reprogrammed when desired, but also keeps the program when the power supply is removed. This means the stamp controller will start to run the program currently in memory whenever the power supply is connected – the serial cable has to be connected only when downloading a new program.

Assignment 2.3

[pic]

A set of temporary traffic lights is required for a system of roadworks.

|red |10 s |

|red and amber | 2 s |

|green |10 s |

|amber | 2 s |

Draw a flowchart for the lights sequence shown by one of the sets of traffic lights. Use the times shown in the table for each stage.

[pic]

Assignment 2.4

A microwave oven operates with the following sequence. Draw a flowchart for this sequence.

1) Light on

2) Turntable on

3) Magnetron on

4) Wait 30 seconds

5) Magnetron off

6) Wait 10 seconds

7) Turntable off

8) Buzzer on

9) Wait 0.5 second

10) Buzzer off

11) Light off

[pic]

Assignment 2.5

The flowchart for the movement of a robot buggy is shown below.

[pic]

Draw the path you would expect the robot buggy to take. How long is the robot buggy moving for?

The path would be as follows.

[pic]

The robot buggy is moving for 7 (3 + 1 + 3) seconds.

Assignment 2.6

[pic]

A set of temporary traffic lights is required for a system of roadworks.

|red |10 s |

|red and amber | 2 s |

|green |10 s |

|amber | 2 s |

Draw a flowchart for the lights sequence shown by one of the sets of traffic lights. Use the times shown in the table for each stage.

Write a PBASIC program, using switch on and switch off commands, to achieve this operation. Use the following pin configuration: red (7), amber (6) and green (5).

[pic]

main: high 7 ' set pin 7 high

pause 10000 ' wait for 10 seconds

high 6 ' set pin 6 high

pause 2000 ' wait for 2 seconds

low 7 ' set pin 7 low

low 6 ' set pin 6 low

high 5 ' set pin 5 high

pause 10000 ' wait for 10 seconds

low 5 ' set pin 5 low

high 6 ' set pin 6 high

pause 2000 ' wait for 2 seconds

low 6 ' pin 6 low

goto main ' loop forever

Assignment 2.7

What is meant by the term ‘white-space’? Why is it important to use white-space and comments when writing programs? Why is it important to add comments to programs?

The term: ‘white-space’ is used by programmers to define tabs, spaces and blank lines, and the correct use of white-space can make the program listing much easier to read and understand.

A comment starts after an apostrophe (') and continues to the end of the line. Although the comments are not needed to make the program work, they are an essential part of the program as they explain in ‘plain language’ what the program is doing. Comments are particularly important if the program is to be studied by someone else at a later date.

Assignment 2.8

A fountain in a garden centre is to be used to attract visitors to a new range of plastic ponds. The garden centre owner wishes to develop a microcontroller-based system that can be programmed to switch the fountain pump, and an external lighting system, on and off at regular intervals.

The following PBASIC program will switch the pump on and off every 60 seconds. The lights turn on 10 seconds after the pump has started, and turn off 10 seconds before the pump is stopped.

Draw a flowchart for the control sequence and add the missing comments to the program listing.

[pic]

main: high 7 ' switch the pump on

pause 10000 ' wait 10 seconds

high 6 ' switch the lights on

pause 4000 ' wait 4 seconds

low 6 ' switch the lights off

pause 10000 ' wait 10 seconds

low 7 ' switch the pump off

pause 6000 ' wait 6 seconds

goto main ' loop

Assignment 2.9

A toy shop has a train set in the window. The train set has an electric train, a set of red/green signals, and a set of moving track points that allows the train to move around two different loops of track.

|Input connection |Pin |Output connection |

| |7 |train motor |

| |6 |points |

| |5 |green signal |

| |4 |red signal |

| |3 | |

| |2 | |

| |1 | |

| |0 | |

The toy-shop owner wants to develop a program that will carry out the following sequence.

1) Switch the green signal on

2) Switch the train on for 30 seconds

3) Stop the train

4) Switch the green signal off and the red signal on

5) Switch the points on

6) Switch the train on for 30 seconds

7) Stop the train

8) Switch the points off

9) Switch the red signal off and the green signal on

10) Jump back to step 1

Draw a flowchart for the control sequence and then use the flowchart to write a PBASIC program.

[pic]

symbol red = 4

symbol green = 5

symbol points = 6

symbol train = 7

main: high green ' set green on

high train ' set train on

pause 30000 ' wait for 30 seconds

low train ' set train off

low green ' set green off

high red ' set red on

high points ' set points on

high train ' set train on

pause 30000 ' wait for 30 seconds

low train ' set train off

low points ' set train off

low red ' set red off

high green ' set green on

goto main ' loop forever

Assignment 3.1

Explain the following microcontroller terms: ALU, bus, clock.

The processing unit (full name ‘arithmetic and logic unit’ [ALU] is the ‘brain’ of the microcontroller. It operates by reading instructions from the ‘read only memory’ (ROM) ( the permanent program memory ( and then carrying out the mathematical operations for each instruction. The speed at which these operations occurs is controlled by the clock circuit.

The clock circuit within the microcontroller ‘synchronises’ all the internal blocks (ALU, ROM, RAM, etc.) so that the system remains stable. The clock circuit is built into the microcontroller, but an external crystal or resonator is required to set the clock frequency. A typical clock frequency for use with a microcontroller is 4 MHz, but speeds as high as 20 MHz can also be achieved. With a clock frequency of 4 MHz the microcontroller completes one million instructions a second!

Information is carried between the various blocks of the microcontroller along ‘groups’ of wires called buses. The ‘data bus’ carries the 8-bit data between the ALU and RAM/input(output registers, and the ‘program bus’ carries the 13-bit program instructions from the ROM.

Assignment 3.2

Explain the differences between the following types of memory: RAM, ROM, EEPROM.

RAM Random Access Memory

ROM Read Only Memory

EEPROM Electronically Erasable Programmable Read Only Memory

The ROM contains the operating instructions (that is the ‘program’) for the microcontroller. The ROM is ‘programmed’ before the microcontroller is installed in the target system, and the memory retains the information even when the power is removed.

The RAM is ‘temporary’ memory used for storing information whilst the program is running. This memory is ‘volatile’, which means that as soon as the power is disconnected, the contents of the memory are lost.

The EEPROM memory is the external, reuseable memory used to store the program. It retains the program when the power is removed, but can be overwritten at any time.

Assignment 3.3

[pic]

Connect a buggy to the output driver module as shown in the diagram.

[pic]

Write a program to control the movement of the buggy as shown by the flowchart above.

main: high 5 ' forward

high 7 ' forward

pause 3000 ' wait for 3 seconds

low 7 ' left

high 6 ' left

pause 1000 ' wait for 1 second

low 6 ' forward

high 7 ' forward

pause 3000 ' wait for 3 seconds

low 7 ' halt

low 5 ' halt

end ' stop

Assignment 3.4

Build a maze on the table out of books. Write a PBASIC program to steer the buggy through the maze. Add comments to each line of your program to explain how it works.

Answer as appropriate.

Assignment 3.5

Explain the terms ‘mark’ and ‘space’ in relation to PWM speed control of a d.c. motor.

With pulse-width modulation (PWM) the time that the power supply is switched on is called the mark time, and the time that the motor is switched off is called the space time. By varying the on (mark)-to-off (space) ratio, the speed of the motor can be varied.

[pic]

Assignment 3.6

Describe the advantages and disadvantages of using PWM speed control.

The advantage of PWM is that the torque remains quite high even when the motor is turning at low speed. The disadvantage of PWM control is that a pulsing signal is required, and so a device such as a microcontroller must be used. Therefore, a drill without PWM control would be cheaper than a drill with PWM speed control as it requires less electronics. However, it would not provide as much power at low speeds.

Assignment 3.7

[pic]

Connect the washing machine model to the output driver module. The motor on the washing machine is controlled by outputs 6 and 7 (motor ‘b’). Switching output 6 on will make the motor turn one way; switching output 7 on will make the motor turn the other way.

a) Write a PBASIC program that will make the motor rotate at full speed in each direction for five seconds.

main: high 7 ' forward

pause 5000 ' wait for 5 seconds

low 7 ' backward

high 6 ' backward

pause 5000 ' wait for 5 seconds

low 6 ' halt

end ' stop

b) Write a second PBASIC program that will make the motor rotate at half speed in each direction for five seconds. Use PWM speed control for the motor.

Five seconds = 5000 ms. If each loop takes 30 ms, we require 5000/30 = 167 loops.

Note! A common mistake is to try to use a number bigger than 255 for the counter!

symbol counter = b0

main: for counter = 1 to 167 ' start a loop

high 7 ' forward

pause 10 ' pause for 5 ms

low 7 ' halt

pause 20 ' pause for 20 ms

next counter ' next loop

for counter = 1 to 167 ' start a loop

high 6 ' backward

pause 10 ' pause for 5 ms

low 6 ' halt

pause 20 ' pause for 20 ms

next counter ' next loop

end ' stop

Assignment 3.8

[pic]

The following PBASIC program will carry out the instructions shown in the flowchart above. Add the missing comments to complete the program listing.

symbol counter = b0 ' define the variable ‘counter’

main: high 7 ' switch on output 7

high 6 ' switch on output 6

high 5 ' switch on output 5

high 4 ' switch on output 4

pause 5000 ' wait 5 seconds

for counter = 1 to 10 ' set-up a for ( next loop

low 7 ' switch off output 7

low 6 ' switch off output 6

low 5 ' switch off output 5

low 4 ' switch off output 4

pause 500 ' wait 0.5 second

high 7 ' switch on output 7

high 6 ' switch on output 6

high 5 ' switch on output 5

high 4 ' switch on output 4

pause 500 ' wait 0.5 second

next counter ' next loop

low 7 ' switch off output 7

low 6 ' switch off output 6

low 5 ' switch off output 5

low 4 ' switch off output 4

end ' stop the program

Assignment 3.9

[pic]

Connect a buggy to the output driver module as shown in the diagram.

[pic]

The buggy should follow the movement path as shown in the diagram above, moving in each direction for three seconds.

Draw a flowchart for the movement of the buggy, making use of a ‘for ( next’ command structure.

Write a high-level program in PBASIC to control the movement of the buggy as shown by your flowchart. (It will be necessary to experiment with time delays to establish how quickly your buggy turns 90 degrees to the left.)

[pic]

symbol counter = b0 ' define the variable ‘counter’

main: for counter = 1 to 4 ' start a for ( next loop

high 5 ' forward

high 7 ' forward

pause 3000 ' wait for 3 seconds

low 5 ' left

high 4 ' left

pause 1000 ' wait for 1 second

low 4 ' forward

next counter ' end of for ( next loop

low 5 ' halt

low 7 ' halt

end ' end program

Assignment 3.10

[pic]

A washing machine has both wash and spin cycles. Add the missing comments to this PBASIC program, which will control the washing machine.

symbol motor = 7 ' rename pin 7 ‘motor’

symbol counter = b0 ' name a counter variable

main: ' make a label called ‘main’

gosub wash ' call sub-procedure wash

gosub spin ' call sub-procedure spin

gosub wash ' call sub-procedure wash

gosub spin ' call sub-procedure spin

gosub wash ' call sub-procedure wash

gosub spin ' call sub-procedure spin

end ' end the program

wash: ' make a label called wash

for counter = 1 to 250 ' start a for ( next loop

high motor ' switch on the motor

pause 10 ' wait 0.01 seconds

low motor ' switch off the motor

pause 5 ' wait 0.005 seconds

next counter ' loop back until count = 250

return ' return from sub-procedure

spin:

high motor ' switch on the motor

pause 5000 ' wait 5 seconds

low motor ' switch off the motor

return ' return from sub-procedure

Assignment 4.1

List four different kinds of switches. Give an example of where each type of switch may be used.

• microswitch: in a fridge door

• reed switch: across a door in a burglar alarm

• rocker switch: in a conventional light switch

• tilt switch: in a car alarm

Assignment 4.2

A burglar alarm must sound a buzzer and light a warning signal for 20 seconds when any of the four windows in a house is opened. Each window contains a reed switch that is connected to the alarm.

Draw a flowchart and write a PBASIC program that will operate the burglar alarm correctly. Use the following input and output connections.

|Input connection |Pin |Output connection |

| |7 |red light |

| |6 |buzzer |

| |5 | |

| |4 | |

|switch 3 |3 | |

|switch 2 |2 | |

|switch 1 |1 | |

|switch 0 |0 | |

[pic]

main: if pin0 =1 then flash ' test input switch

if pin1 =1 then flash ' test input switch

if pin2 =1 then flash ' test input switch

if pin3 =1 then flash ' test input switch

goto main ' loop

flash:

high 7 ' switch on light

high 6 ' switch on buzzer

pause 20000 ' wait 20 second

low 7 ' switch off light

low 6 ' switch off buzzer

goto main ' loop back to start

Assignment 4.3

As part of a Christmas decoration in a shop, a lighting sequence is to be controlled by a microcontroller. The output connections are shown below.

|Input connection |Pin |Output connection |

| |7 |red light |

| |6 |yellow light |

| |5 |green light |

| |4 | |

| |3 | |

| |2 | |

| |1 | |

|pressure mat |0 | |

When a visitor treads on a pressure mat under the carpet, the lights should flash on and off in sequence three times.

The following PBASIC program will carry out the instructions shown in the table above.

Add the missing comments to complete the program listing.

symbol counter = b0 ' define a variable

symbol red = 7 ' define an output light

symbol yellow = 6 ' define an output light

symbol green = 5 ' define an output light

main: if pin0 =1 then flash ' test input switch

goto main ' off so loop

flash: for counter = 1 to 3 ' start a for ( next loop

high red ' switch on light

low green ' switch off light

pause 500 ' wait 0.5 second

high yellow ' switch on light

low red ' switch off light

pause 500 ' wait 0.5 second

high green ' switch on light

low yellow ' switch off light

pause 500 ' wait 0.5 second

next counter ' next loop

low green ' switch off light

goto main ' loop back to start

Assignment 4.4

[pic]

Connect a buggy to the output driver module (or MFA movement module) as shown in the diagram. Connect the microswitch ‘bumpers’ to pins 0 and 1 on the input module.

The buggy should continue going forwards until either of the two microswitch bumpers is activated. At this point, the buggy should reverse for three seconds, rotate 90 degrees clockwise, and then continue forwards.

Draw a flowchart and write a PBASIC program to control the movement of the buggy as described above.

[pic]

main: high 5 ' forward

high 7 ' forward

loop: if pin0 =1 then bump ' test switch 0

if pin1 =1 then bump ' test switch 1

goto loop ' else loop

bump: low 5 ' reverse

low 7 ' reverse

high 4 ' reverse

high 6 ' reverse

pause 3000 ' wait for 3 seconds

low 4 ' left

high 5 ' left

pause 2000 ' turn for 2 seconds

low 5 ' halt

low 6 ' halt

goto main ' back to start

Assignment 4.5

[pic]

Develop a PBASIC program that will carry out the instructions shown in the flowchart above. Use the following pin configuration.

|Input connection |Pin |Output connection |

| |7 |red light |

| |6 |amber light |

| |5 |green light |

| |4 | |

| |3 | |

| |2 | |

| |1 | |

|start switch |0 | |

main: high 5 ' green on

loop: if pin0 =1 then lite ' test start switch

goto loop ' else loop

lite: low 5 ' green off

high 6 ' amber on

pause 3000 ' wait for 3 seconds

low 6 ' amber off

high 7 ' red on

pause 4000 ' turn for 4 seconds

high 6 ' amber on

pause 2000 ' wait for 2 seconds

low 6 ' amber off

low 7 ' red off

goto main ' back to start

Assignment 4.6

[pic]

Connect the washing machine model to the input module and output driver module. The washing machine model has the following connections.

|Input connection |Pin |Output connection |

| |7 |motor reverse |

| |6 |motor forward |

| |5 |solenoid bolt |

| |4 |LED |

| |3 | |

| |2 | |

|door microswitch |1 | |

|start switch |0 | |

The washing machine operates as follows.

1) Wait until the start switch is on.

2) Wait until the door switch is on.

3) Switch on the LED.

4) Switch on the solenoid bolt.

5) Wash cycle: repeated 20 times – motor forwards for five seconds, motor backwards for five seconds.

6) Spin cycle: repeated 10 times – motor forwards for two seconds, motor backwards for two seconds.

7) Switch off the solenoid bolt.

8) Switch off the LED.

Draw a flowchart and write a PBASIC program to control the movement of the washing machine as described above.

[pic] symbol counter = b0

symbol LED = 4

symbol bolt = 5

main: if pin0 =0 then main ' wait for switch

door: if pin1 =0 then door ' wait for switch

high LED ' switch on the LED

high bolt ' switch on the solenoid

for counter = 1 to 20 ' start a loop

high 6 ' motor forwards

pause 5000 ' wait for 5 seconds

low 6 ' motor backwards

high 7 ' motor backwards

pause 5000 ' wait for 5 seconds

low 7 ' motor off

next counter ' next loop

for counter = 1 to 10 ' start a loop

high 6 ' motor forwards

pause 2000 ' wait for 2 seconds

low 6 ' motor backwards

high 7 ' motor backwards

pause 2000 ' wait for 2 seconds

low 7 ' motor off

next counter ' next loop

low bolt ' switch off the solenoid

low LED ' switch off the LED

end

Assignment 4.7

[pic]

Connect the bank safe model to the input module and output driver module. The bank safe model has the following connections.

|Input connection |Pin |Output connection |

| |7 |buzzer |

| |6 | |

| |5 |solenoid/red LED |

| |4 |green LED |

|code switch 3 |3 | |

|code switch 2 |2 | |

|code switch 1 |1 | |

|door microswitch |0 | |

The bank safe operates as follows.

1) Switch on the red LED.

2) Switch on the solenoid bolt.

3) Wait until code switch 1 is pushed.

4) Wait until code switch 2 is pushed.

5) Wait until code switch 3 is pushed.

6) Switch off the solenoid bolt.

7) Switch off the red LED.

8) Wait until the door is opened (microswitch off).

9) Switch on the green LED.

10) Wait 10 seconds.

11) Switch off the green LED.

12) Switch on the buzzer.

13) Wait until the door is closed (microswitch on).

14) Switch off the buzzer.

15) Loop back to step 1.

Draw a flowchart and write a PBASIC program to control the movement of the washing machine as described above.

[pic]

symbol bolt = 7 ' define the outputs

symbol buzzer = 6

symbol green = 5

symbol red = 4

main: high red ' red on

high bolt ' bolt on

loop1: if pin1 =0 then loop1 ' wait for switch 1

loop2: if pin2 =0 then loop2 ' wait for switch 2

loop3: if pin3 =0 then loop3 ' wait for switch 3

low red ' red off

low bolt ' bolt off

loop4: if pin0 =1 then loop4 ' wait for door switch

high green ' green on

pause 10000 ' wait 10 seconds

low green ' green off

high buzzer ' buzzer on

loop5: if pin0 =0 then loop5 ' wait for door switch

low buzzer ' buzzer off

goto main ' back to start

Assignment 5.1

Convert each of the following binary numbers into decimal.

(a) %11110000

240

(b) %11000011

195

(c) %01010101

85

(d) %10101010

170

Assignment 5.2

Convert each of these decimal numbers into binary.

(a) 17

00010001

(b) 23

00010111

(c) 11

00001011

(d) 38

00100110

(e) 33

00100001

Assignment 6.1

Explain the main differences between d.c. motors and stepper motors.

Stepper motors require a switching supply to their four coils to make them rotate; d.c. motors just need to be connected to a power supply. Stepper motors can be accurately moved to a position; d.c. motors cannot. Stepper motors will provide more torque than equivalent-sized d.c. motors. Stepper motors are more expensive than d.c. motors. Stepper motors draw current when stationary and so will drain batteries quickly. D.c. motors can achieve higher speeds than stepper motors.

Assignment 6.2

Describe three products that may contain stepper motors. Describe how the motor is used in each case.

Printer: to move the printing head back and forth

XY Plotter: to move the pen back and forth

Clock: to move the second hand

One-arm bandit,

etc.: to rotate the wheels so that they land on particular symbols

Assignment 7.1

[pic]

A street lamp must turn on when the light level is below the level ‘100’ and turn off when the level is above ‘100’. The lamp is connected to output 7 and the LDR light sensor is connected to sensor A.

Draw a flowchart and write a PBASIC program that will make the street lamp work correctly.

[pic]

main: ' make a label called ‘main’

if sensorA < 100 then swon ' jump if the value < 100

goto swoff ' value is > 100 so jump

swon: ' make a label called ‘red’

high 7 ' switch output 7 on

goto main ' jump back to start

swoff: ' make a label called ‘green’

low 7 ' switch output 7 off

goto main ' jump back to start

Assignment 7.2

State whether each of the input transducers below is an analogue or digital sensor.

(a) LDR analogue

(b) reed switch digital

(c) microswitch digital

(d) thermistor analogue

(e) variable resistor analogue

(f) tilt switch digital

(g) push switch digital

(h) rocker switch digital

Assignment 7.3

For each of the input transducers listed in assignment 7.2 give an example of an electronic product that may use that transducer. Explain how the transducer would be used within the product.

Answer as appropriate.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download