Programmable systems-outcome-34

141
Programmable Systems Gary Plimer 2004 Dave’s Revision Notes

Transcript of Programmable systems-outcome-34

Page 1: Programmable systems-outcome-34

Programmable Systems

Gary Plimer 2004

Dave’s Revision Notes

Page 2: Programmable systems-outcome-34

Programmable Systems Outcome 3

Outcome 3 - Microcontroller Controlled Mechatronic Systems

Section 1 – Introduction

The purpose of this section is to introduce the microcontroller and it's architecture.

When students have completed this unit they should be able to:

Describe the operation and architecture of microcontrollers.

Understand the terms ALU, RAM, ROM, EEPROM and bus. Understand how the Basic Stamp system operates.

Page 3: Programmable systems-outcome-34

Programmable Systems Outcome 3

What is a microcontroller? REVISION

A microcontroller is often described as a 'computer-on-a-chip'. Microcontrollers have memory, processing units, and input/output circuitry all built into a single chip. As they are small and inexpensive they can easily be built into other devices to make these products more intelligent and easier to use.

Page 4: Programmable systems-outcome-34

Programmable Systems Outcome 3

What is a microcontroller? REVISION

Microcontrollers are usually programmed to perform one specific control task for instance, a microwave oven may use a single microcontroller to process information from the keypads, display user information on the seven segment display, and control the output devices (turntable motor, light, bell and magnetron).

Microcontrollers are computers designed to control specific processes or products. The microcontroller is programmed with a specific software program to complete the desired task. By altering this software program the same microcontroller can be used to complete different tasks. Therefore the same device can be used in a range of different products by simply programming it with a different software program.

Page 5: Programmable systems-outcome-34

Programmable Systems Outcome 3

What is a microcontroller? REVISION

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: increased reliability and reduced stock inventory (as one microcontroller replaces several parts), simplified product assembly and smaller end products, greater product flexibility and adaptability since features are programmed into the microcontroller and not built into the electronic hardware rapid product changes or development by changing the program and not the electronic hardware.

Applications that use microcontrollers include household appliances, alarm systems, medical equipment, vehicle subsystems, and electronic instrumentation. Although microprocessor systems (such as those based around the Intel Pentium™ processor) tend to be more widely publicised (mainly via personal computer systems), microcontroller manufacturers actually sell hundreds of microcontrollers for every microprocessor sold.

Page 6: Programmable systems-outcome-34

Programmable Systems Outcome 3

Microcontroller Architecture

DATABUS

PRO G RAMBUS

RO M

PRO G RAMM EM O RY

PRO G RAMC O UNTER RAM

REG ISTERFILES

I/OPO RTS

TIM ERS

ALU

C LO C K

“REAL”WO RLD

SIM PLIFIED PIC M IC RO C O NTRO LLERBLO C K DIAG RAM

Microcontrollers contain all these features within a single package, as opposed to the microprocessor system where each block in the diagram above is normally a separate integrated circuit. In general the only component that needs to be added to a microcontroller is a clock resonator, which sets the operating speed of the microcontroller.

Page 7: Programmable systems-outcome-34

Programmable Systems Outcome 3

Microcontroller Architecture - Terminology

Arithmetic / Logic Unit (ALU) and ClockThe 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 and then carrying out the mathematical operations for each instruction.

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 4MHz, but speeds as high as 20MHz can also be achieved. With a clock frequency of 4MHz the microcontroller completes one million instructions a second!

Page 8: Programmable systems-outcome-34

Programmable Systems Outcome 3

Microcontroller Architecture - Terminology

Microcontrollers contain both ROM (permanent memory) and RAM (temporary memory).

The ROM (Read Only Memory) contains the operating instructions (i.e. 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. Most microcontrollers are one-time-programmable types, which means the ROM can only be programmed once. If you make a mistake, and have to change the program, the chip has to be thrown away and a new chip programmed with the revised program. To overcome this problem some microcontrollers now use FLASH EEPROM memory instead. This type of 'erasable-permanent' memory allows the ROM to be re-programmed if a mistake is made.

Page 9: Programmable systems-outcome-34

Programmable Systems Outcome 3

Microcontroller Architecture - Terminology

RAM

Random Access Memory, 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 is lost. Buses

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.The size of the data bus provides a description for the microcontroller. Therefore an '8 bit microcontroller' has a data bus '8-bits' wide. Microcontrollers with 16-bit and 32-bit data buses are also available.

Page 10: Programmable systems-outcome-34

Programmable Systems Outcome 3

Microcontroller Architecture - Terminology

Input/Output Circuitry (I/O Ports)

Microcontrollers communicate with the outside world via pins which are grouped together in 'ports', with up to eight pins in each port. Smaller microcontrollers may only have one port, whilst larger devices may have five or more. Generally each pin within the port can be configured as an output or as an input, or can even be multiplexed to change functions as the program is run!Timers

Most microcontrollers have one or more 'timers' built into the system. The 'watchdog timer' is the most common type of timer. This is a special timer that 'resets' the microcontroller if it stops processing for any reason (e.g. a 'bug' in the program). This ensures that the microcontroller continues working at all times - which is essential in some applications, for instance medical monitoring equipment.

Page 11: Programmable systems-outcome-34

Programmable Systems Outcome 3

The Basic Stamp

DO WNLO AD C ABLEHO ST C O M PUTER

RUNNINGSTAM P SO FTWARE

BASICINTERPRETER

C LO C K

EEPRO M

INPUT/O UTPUT

PINS

The program instructions are written on a host computer in the simple PBASIC language. The download cable is then connected from the computer to the module, and the program is downloaded into the EEPROM memory chip. The download cable is then removed, and the program (now stored in the memory chip) is carried out sequentially by the microcontroller 'interpreter' chip.

Page 12: Programmable systems-outcome-34

Programmable Systems Outcome 3

Programming Procedure

• Write the program on a host computer using the Stamp software.

• Connect the download cable from the computer to the Stamp Controller.

• Connect the power supply to the Stamp Controller.

• Use the Stamp software to download the

program. The download cable can be removed (if desired) after the download.

Page 13: Programmable systems-outcome-34

Programmable Systems Outcome 3

Pupil Assignment no.1

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

• Describe the input sensors and output transducers that may be linked to a microcontroller in the following common household

appliances:- microwave oven- washing machine- electronic bicycle speedometer

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

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

Page 14: Programmable systems-outcome-34

Programmable Systems Outcome 1

Section 2 - Number Systems

The purpose of this section is to introduce the main number systems used within programmable systems for the processing of information.

When students have completed this unit they should be able to:

Use the following terms correctly: decimal, binary, hexadecimal.

Describe contexts when it is appropriate to use the three different number systems.

Convert between decimal, binary and hexadecimal number systems.

Outcome 3 - Microcontroller Controlled Mechatronic Systems

Page 15: Programmable systems-outcome-34

Programmable Systems Outcome 3

Number Systems

Microcontrollers only recognises the two electronic states high and low.

This number system uses just two digits 0 and 1.

An electrical signal which is low is represented by 'logic 0', and a signal which is high is represented by a 'logic 1'.

Write down the first sixteen numbers in the decimal and binary system

Page 16: Programmable systems-outcome-34

Programmable Systems Outcome 3

Number Systems Notation

Before we introduce different number systems, we need to help the Stamp Controller to differentiate between them.

When using a number of different counting systems it is important to distinguish which counting system you are using. For instance the number '10' means three different values in the three different counting systems!

Therefore the following notations are used within PBASIC programs:

Decimal values are written as usual:10 ( = 10 in decimal)

Binary values are preceded by a % symbol: %10 ( = 2 in decimal)

Hexadecimal values are preceded by an & symbol: &10 ( = 16 in decimal)

Page 17: Programmable systems-outcome-34

Programmable Systems Outcome 3

Number Systems

Bits and Bytes

Eight bits grouped together are described as a byte. The decimal value of a byte is calculated by adding together the corresponding decimal value of each of the individual bits. The eight bits in a byte are labelled bits 0 to 7, from right to left. The right most bit is called the Least Significant Bit (LSB) and the left most bit is called the Most Significant Bit (MSB). The decimal value of each bit is given in the table below:

bit number 7 6 5 4 3 2 1 0

decimal value

128 64 32 16 8 4 2 1

Page 18: Programmable systems-outcome-34

Programmable Systems Outcome 3

Pupil Assignment No.2

bit number 7 6 5 4 3 2 1 0

decimal value

128 64 32 16 8 4 2 1

Convert each of the following binary numbers into decimal:

11110000110000110101010110101010

Page 19: Programmable systems-outcome-34

Programmable Systems Outcome 3

Pupil Assignment No.2

bit number 7 6 5 4 3 2 1 0

decimal value

128 64 32 16 8 4 2 1

Convert each of these decimal numbers into binary:

1723113833

Page 20: Programmable systems-outcome-34

Programmable Systems Outcome 3

Hexadecimal Number System

Writing binary numbers in groups of eight bits is quite time consuming, although on some occasions binary numbers are very useful to clearly illustrate the condition of each bit in a byte.

However a more user-friendly system of writing numbers is the hexadecimal system. The hexadecimal system uses 16 different digits - 0 to 9 and A to F. The 'digits' A to F correspond to the decimal numbers 10 to 15.

Decimal Hexadecimal

10 A

11 B

12 C

13 D

14 E

15 F

Page 21: Programmable systems-outcome-34

Programmable Systems Outcome 3

Decimal Binary Hexadecimal

0 0000 0

1 0001 1

2 0010 2

3 0011 3

4 0100 4

5 0101 5

6 0110 6

7 0111 7

8 1000 8

9 1001 9

10 1010 A

11 1011 B

12 1100 C

13 1101 D

14 1110 E

15 1111 F

Page 22: Programmable systems-outcome-34

Programmable Systems Outcome 3

Converting Binary to Hexadecimal

Divide the binary number into groups of nibbles (four bits) Convert the nibbles into decimal

Convert the decimal nibbles into hexadecimal (i.e. convert any decimal values greater than 9 into the hexadecimal letter 'digits')

Example:

Convert %01101010 into hexadecimal

Divide into nibbles 0110-1010Convert into decimal 6-10Convert into hexadecimal 6-A

Therefore %01101010 = &6A

Page 23: Programmable systems-outcome-34

Programmable Systems Outcome 3

Pupil Assignment No.2

Convert the following binary numbers to hexadecimal:

%11011101%11111001%01010101%10101010%11001010

Page 24: Programmable systems-outcome-34

Programmable Systems Outcome 3

Converting Hexadecimal to Binary

Convert &AF into binary

Divide into separate digits A-FConvert to decimal 10-15Convert to binary 1010-1111Join the two four bit numbers 10101111

Therefore &AF = %10101111

Page 25: Programmable systems-outcome-34

Programmable Systems Outcome 3

Converting Decimal to Hex

Convert 450 to Hex

Think about base 16,

163 162 161 160

4097 256 16 1

For 450 we need x1 x12 x2

In Hex 1 C 2

&1C2

Page 26: Programmable systems-outcome-34

Programmable Systems Outcome 1

Outcome 3 - Microcontroller Controlled Mechatronic Systems

Section 3 - Simple Control Routines

The purpose of this section is to introduce the PBASIC commands used in developing control program listings.

When students have completed this unit they should be able to:

Understand the use of flowcharts. Develop flowcharts from a brief. Understand the most common PBASIC

commands. Write PBASIC programs that involve loops, if

statements and sub-procedures.

Page 27: Programmable systems-outcome-34

Programmable Systems Outcome 3

Port Addressing and the Data Direction Register

Microcontrollers communicate with the outside world by input/output pins which are grouped together in 'ports'.

The Stamp Controller has one input/output port, which contains eight input/output pins.

Each pin can be addressed individually, or all eight pins in the port can be addressed simultaneously.

In the PBASIC language the pins are labelled 0 to 7, and the whole port address is allocated the label 'pins'.

For example, to switch pin 3 'high' individually the command would be:high 3To switch pin 3 'low' individually the command would be: low 3

Page 28: Programmable systems-outcome-34

Programmable Systems Outcome 3

input/output pin 7 6 5 4 3 2 1 0

bit of address 'pins' 7 6 5 4 3 2 1 0

decimal value 128 64 32 16 8 4 2 1

Port Addressing and the Data Direction Register

To switch all pins 'high' the command would be let pins = 255

To switch all pins 'low' the command would be let pins = 0

To switch pins 0-2 'high' and pins 3-7 'low' the command would belet pins = %00000111

Note how the use of the binary number system can be used on this occasion to clearly illustrate which pins are switched high (=1) or low (=0).

Page 29: Programmable systems-outcome-34

Programmable Systems Outcome 3

The Data Direction Register (DDR)

Each pin can be configured to be an output (to send digital signals) or an input (to receive digital signals).

The Data Direction Register (DDR) is used to configure the port, and in the PBASIC language the DDR is allocated the label 'dirs'.

If all the bits in the DDR are set high then all the pins will be set as outputs. If all the bits are set low each pin will be set as an input.

For example,let dirs = 255 ' set all pins as outputslet dirs = 0 ' set all pins as inputslet dirs = %11110000 ' set 0-3 inputs, 4-7 outputs

Every PBASIC program listing should always begin with a 'let dirs =' statement to correctly setup the DDR.

Page 30: Programmable systems-outcome-34

Programmable Systems Outcome 3

Beginning Programming

START

SWITC H PIN 7HIG H

SWITC H PIN 6HIG H

SWITC H PINS 4 5HIG H

&

WAIT 2 SEC O NDS

SWITC H ALLO FF

WAIT 3 SEC O NDS

STO P

WAIT 1 SEC O ND

Consider the simple Flowchart shown opposite.

The Flowchart helps us plan our programming.

Now have a look at the next slide which shows a possible solution to this Flowchart

Page 31: Programmable systems-outcome-34

Programmable Systems Outcome 3

Beginning Programming

A PBASIC program which would achieve this control operation is:

let dirs = %11110000 ' set pins 0-3 inputs, 4-7 outputshigh 7 ' set pin 7 highpause 2000 ' wait for 2 seconds (= 2000 ms)high 6 ' set pin 6 highpause 1000 ' wait for 1 secondlet pins = %11110000 ' set pins 4-7 highpause 3000 ' wait for 3 secondslet pins = 0 ' switch all pins lowend ' end the program

Page 32: Programmable systems-outcome-34

Programmable Systems Outcome 3

Labels and Addressing

START

SWITC H PIN 7HIG H

SWITC H PIN 6HIG H

SWITC H PINS 4 5HIG H

&

WAIT 2 SEC O NDS

SWITC H ALLO FF

WAIT 3 SEC O NDS

WAIT 1 SEC O ND

WAIT 1 SEC O ND

Sometimes it is necessary to create programs that loop 'forever', as shown by the flowchart. In this case it is necessary to add labels to the program, and to use the 'goto' command to jump to the line marked by the label.

Study the Flowchart then look at the solution on the next slide.

Page 33: Programmable systems-outcome-34

Programmable Systems Outcome 3

Labels and Addressing (Continued)

START

SWITC H PIN 7HIG H

SWITC H PIN 6HIG H

SWITC H PINS 4 5HIG H

&

WAIT 2 SEC O NDS

SWITC H ALLO FF

WAIT 3 SEC O NDS

WAIT 1 SEC O ND

WAIT 1 SEC O ND

A PBASIC program which would achieve this control operation is listed below.

init: let dirs = %11110000 ' set pins 4-7 as outputs

main: high 7 ' set pin 7 highpause 2000 ' wait for 2 secondshigh 6 ' set pin 6 highpause 1000 ' wait for 1 secondlet pins = %11110000 ' set pins 4-7 highpause 3000 ' wait for 3 secondslet pins = 0 ' switch all pins lowpause 1000 ' wait for 1 secondgoto main ' loop forever

Page 34: Programmable systems-outcome-34

Programmable Systems Outcome 3

Labels and Addressing (Continued)

Activity 1

Key in, download and run the program listed above.

After the first line (which simply sets up the DDR), a label called 'main' has been added to the listing.

Note that all address labels must end with a colon (:) when they are first defined.

It is also a good programming technique to use tabs (or spaces) at the start of lines without labels so that all the commands are neatly aligned.

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.

The last line 'goto main' causes program flow to 'jump back' to the line labelled main'. This means that this program will loop 'forever'.

Page 35: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 1

What is the function of the Data Direction Register (DDR)?

What is meant by the term "white-space"?

Why is it important to use white-space and comments when writing programs?

Page 36: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 2

A set of temporary traffic lights are required for a system of road-works.

red 10 sec

red and amber 2 sec

green 10 sec

amber 2 sec

Draw a flowchart for the lights sequence shown by one set of the traffic lights.

Use the times shown in the table for each stage.

Write a PBASIC program to achieve this operation. Use the following pin configuration - red (7), amber (6) and green (5).

Page 37: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 3

START

STO P

M O VE FO RWAR D

W AIT 3 SEC .

W AIT 3 SEC .

TU R N LEFT

W AIT 1 SEC .

M O VE FO RWAR D

Write a high level program in PBASIC to control the movement of the buggy as shown by the flowchart opposite.

Page 38: Programmable systems-outcome-34

Programmable Systems Outcome 3

For...Next Loops

Y

N

START

SWITC H PIN 7HIG H

SWITC H PIN 7LO W

WAIT 1 SEC O ND

STO P

WAIT 1 SEC O ND

SET C O UNTER= 5

HAVE WELO O PED 5

TIM ES?

A for...next loop is used when you wish to repeat a section of code a number of times.

The number of times the program runs for is set by a variable.

A variable is a number that is stored in the RAM memory of the Stamp Controller.

There are 14 memory locations that byte variables can be stored in.

These locations are labelled b0 to b13, but can also be 'renamed' to more appropriate names by use of the 'symbol' command.

Page 39: Programmable systems-outcome-34

Programmable Systems Outcome 3

For...Next Loops

Activity

Study the following program. In your own words, write down what you expect the program to do. Now, key in, download and run the following program to check your answer.

symbol counter = b0 ' define the variable "counter"symbol red = 7 ' define pin 7 with the name "red“

init: let dirs = %10000000 ' set up pin 7 as an outputmain: for counter = 1 to 5 ' start a for...next loop

high red ' switch pin 7 highpause 1000 ' wait for 1 secondlow red ' switch pin 7 lowpause 1000 ' wait for 1 secondnext counter ' end of for...next loopend ' end program

Page 40: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 4 3

3

33

A buggy is to follow the path shown opposite.

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. (Assume it takes 1.5 seconds to turn 90 degrees).

Page 41: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 5

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

Input Connection

Pin Output Connection

7

6 Yellow Light

5 Purple Light

4

3 Blue Light

2 Green Light

1

0 Red Light

The red and green lights should come on together and stay on for 5 seconds. Then they both go off and the yellow and blue lights should come on together for 8 seconds. They then go off and the purple light flashes on and off 6 times (the 'on' and 'off' times being 0.5 seconds each). The sequence then repeats itself continuously.

Draw a flowchart and write a PBASIC program for this sequence.

Page 42: Programmable systems-outcome-34

Programmable Systems Outcome 3

If...Then... command

SWITC H ALLLO W

Y

N

START

SWITC H PIN 7HIG H

STO P

IS PIN 3HIG H?

The if...then programming structure allows the computer to make a decision based on information received from an input pin.

Note the symbol used in the flowchart

Give an example of where this type of control might be used

Page 43: Programmable systems-outcome-34

Programmable Systems Outcome 3

If...Then... Command

Activity

Key in, download and run the program listed below. init: let dirs = %10000000 ' setup the DDRmain: let pins = %10000000 ' switch pin 7 high

if pin3 = 1 then skip ' jump to 'skip' if input 3 is highgoto main ' loop

skip: let pins = 0 ' switch all pins offend ' end the program

To test the program you will need to connect the sensors module to the Stamp Controller, and connect a micro-switch to sensor 3 on the sensor module.

Note: The then command can only be followed by a label to jump to.

Page 44: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 6

WAIT 0.5 SEC O NDS

WAIT 0.5 SEC O NDS

SWITC H ALLPINS LO W

SWITC H ALLPINS LO W

START

SWITC H ALLPINS HIG H

SWITC H ALLPINS HIG H

STO P

Y

NHAS THIS BEENDO NE 10 TIM ES?

WAIT 5 SEC O NDS

Develop a PBASIC program that will carry out the instructions shown in the flowchart opposite.

Page 45: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 7

A motor, connected to pin 7, is to run when a 'start' switch (connected to pin 2) is momentarily pressed.

The motor continues to run until another 'stop' switch (connected to pin 3) is pressed - at which point the motor switches off.

The system should then reset to wait for another 'start' signal.

Draw a flowchart and write a PBASIC program for this sequence.

Page 46: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 8

STAM PC O N TR O LLER

O U TPU TD R IVER

M O D U LE

Connect 2 motors to the output driver module (or MFA movement module) as shown in the diagram. Connect micro-switch 'bumpers' to pins 0 and 1 on the Stamp Controller via the screw terminals as shown below.

V+

0

1

2

3

0V

SHOWS HOW TO WIRE 2 SWITCHES TOTHE SCREW TERMINALS ON THE

STAMP CONTROLLER

The motors should run in a forward direction until either of the two micro-switch bumpers are activated. At this point the motors should reverse for 3 seconds, then stop. One motor should then switch on for 2 seconds, then stop. Both motors should then switch on.Draw a flowchart and write a PBASIC program to control the movement of the buggy as described above.

Page 47: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 9

START

G R EEN LED O N

SW ITC HPU SH ED ?

N O

YES

G R EEN LED O FFAM BER LED O N

W AIT 3 sec.

AM BER LED O FFR ED LED O N

W AIT 4 sec.

AM BER LED O N

W AIT 2 sec..

R ED /AM BER LED O FFG R EEN LED O N

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

Input Connection

Pin Output Connection

7 Red Light

6 Amber Light

5 Green Light

4

Start Switch

3

Page 48: Programmable systems-outcome-34

Programmable Systems Outcome 3

Sub-Procedures

STO P

START

B1 = 5

FLASH

FLASH

FLASH

B1 = 20

B1 = 10

FLASH

H IG H 7

W AIT 0.1s

LO W 7

W AIT 0.1s

H AS TH ISBEEN DO N EB1 TIM ES? N O

YES

R ETU RN

It is often useful to be able to re-use sections of code within a program. A sub-procedure is a small section of code that can be 'called' from a different part of the program.

After the sub-procedure is finished program flow moves back to the original section of the program.

To 'call' a sub-procedure the gosub (go-to-sub-procedure) command is used.

The last line of the sub-procedure must be return, which means 'return to the original position'.

Page 49: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity

Key in, download and run the following program.

init: let dirs = %10000000 ' setup the DDRmain: let pins = %10000000 ' switch pin 7 high

let b1 = 5 ' give variable b1 the value 5gosub flash ' call sub-procedurepause 2000 ' wait two secondslet b1 = 20 ' give variable b1 the value 20gosub flash ' call sub-procedurepause 2000 ' wait two secondslet b1 = 10 ' give variable b1 the value 10gosub flash ' call sub-procedurepause 2000 ' wait two secondsend ' end the main program

' Sub-procedures start here.

Continued on next page

Page 50: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity Continued

flash:for b2 = 1 to b1 ' setup a for...next loop using b2 high 7 ' output pin on pause 100 ' wait 100ms low 7 ' output pin off pause 100 ' wait 100msnext b2 ' next loopreturn ' return form sub-procedure

In this example the flash sub-procedure is used to actually flash the LED on and off. The number of times the LED flashes is set by variable b1, which is set before the sub-procedure is called. Therefore by changing the value of b1 the number of flashes can be changed.

Note the end command between the main program and the sub-procedure. This is essential because it stops the Stamp Controller accidentally 'running into' the sub-procedure after the main program has been completed.

Page 51: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity Continued

One further advantage of sub-procedures is that they are easily copied from one program to another. Therefore a 'standard' sub-procedure can be created to carry out a specific task. This task can then be carried out in a number of different programs by simply copying the sub-procedure from program to program.

Page 52: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 10

As part of a shop display, 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 Orange Light

3

switch 2 2

switch 1 1

0

Page 53: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 10 continued

If switch 1 is pressed, each light should flash on and off in sequence i.e. orange then green then yellow then red (each 'on' and 'off' time should be 0.5 seconds), this should be repeated 5 times. The system then resets for the next switch push.

If switch 2 is pressed all lights should flash simultaneously 3 times. There should then be a 2 second pause, before all lights should flash simultaneously 6 times (each 'on' and 'off' time should be 0.5 seconds). The system then resets for the next switch push.

Draw a flowchart and write a PBASIC program for this sequence (use a sub-procedure for the flash routines).

Page 54: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 11

A sequence of events for the operation of the washing machine is given in the table below:

Step 1 Wait until the door switch is closed.

Step 2 Wait until the start switch is pushed.

Step 3 Rotate the drum clockwise for 10 seconds.

Step 4 Rotate the drum anti-clockwise for 10 seconds

Repeat steps 3 and 4 10 times

Step 5 Rotate the drum clockwise for 5 seconds.

Step 6 Rotate the drum anti-clockwise for 5 seconds

Repeat steps 5 and 6 5 times

Draw a Flow Chart, write, and test, a PBASIC program for the control sequence described above.

Page 55: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 12

INLET VALVE

M AINS WATER

HEAD STO RAG E TANK

DUM P PUM P M O TO RAG ITATO RM O TO R

C O NVEYO RM O TO R

The diagram shows the layout of a pulper machine used in a paper mill.A batch of pulp and fillers, i.e. 5 x 20 kg bales of pulp and 2 x 50 kg bags of fillers, is mixed during the pulping process with 1600 litres of water.

The operation of the pulping process is controlled by a microcontroller. The microcontroller connections are as shown on the next slide.:

Page 56: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 12 continued

Input Connection

Pin Output Connection

7 Agitator motor

6 Dump Pump

5 Conveyer

4 Inlet valve

3

2

1

Start switch 0

Page 57: Programmable systems-outcome-34

Programmable Systems Outcome 3

Event Operator Action Control Activity

1 Load conveyer with batch

2 Press start button Sequence commences.

3 Open inlet valve. Close valve after 10 minutes.

4 1 minute after inlet valve opens, start agitator motor. run agitator motor for 11 minutes.

5 Start conveyer 2 minutes after inlet valve opens. Run conveyer for 3 minutes.

6 1 minute after agitator motor stops, start dump pump. run dump pump for 3 minutes.

7 Reset and wait for next start command.

Page 58: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 12 continued

(a) Based on the instructions given in the table, draw up a flow chart which shows the control sequence for the pulping sequence.

(b) With reference to your flow chart, write a high level program in PBASIC to control the operation of the pulper.

Assume use of a pre-written time delay sub-procedure called 'delay' which will produce a time delay in multiples of one minute, according to the value set in the variable 'mins' before the sub-procedure is called.

Example - To wait five minutes: let mins = 5gosub delay

Page 59: Programmable systems-outcome-34

Programmable Systems Outcome 3

Specialised Commands

The PBASIC language also contains some specialised commands dedicated for use with microcontrollers.

One of the most useful commands is serout.

The serout command can be used to send serial ASCII text strings out of a single pin. This can be used to send information to a host computer via a serial link, or to another device, such as the serial LCD module, which can interpret ASCII text strings.

Page 60: Programmable systems-outcome-34

Programmable Systems Outcome 3

Specialised Commands

For example, to send the word "Hello" out of pin 7, the PBASIC command would be

serout 7, T2400, (254,128)serout 7,T2400,("Hello")

Connect the serial LCD module to the Stamp Controller and try the above command.

Page 61: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity

init: let dirs = %10000000 ' make pin 7 an outputlet pins = %10000000 ' switch pin 7 high

main: pause 5 ' short pauseserout 7,T2400,(254,1) ' send 'clear LCD' commandpause 500 ' wait 0.5 secondserout 7,T2400,(254,128) ' send 'line 1' commandserout 7,T2400,("Hello!") ' send message

pause 1000 ' wait 1 secondserout 7,T2400,(254,192) ' send 'line 2' commandserout 7,T2400,("Goodbye!") ' send message

pause 1000 ' wait 1 secondgoto main ' loop

Enter and run the following program

Page 62: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity

symbol counter = b0 ' define the variableinit: let dirs = %10000000 ' make pin 7 an output

let pins = %10000000 ' switch pin 7 high

pause 5 ' short pauseserout 7,T2400,(254,1) ' send 'clear LCD' commandpause 30 ' wait 30 ms

main: for counter = 0 to 20 ' start a for...next loop serout 7,T2400,(254,128) ' send 'line 1' command serout 7,T2400,("Count = ") ' send message serout 7,T2400,(#counter," ") ' send counter value pause 500 ' wait 0.5 secondnext counter ' next loopend

Enter and run the following program

Page 63: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 13

Connect two switches to the input module, and the serial LCD module, to the Stamp Controller.

When the switch connected to pin '0' is pressed the Stamp Controller should add 1 to the current total, and then display the new value on the LCD.

When the switch connected to pin '1' is pressed the Stamp Controller should subtract 1 from the current total, and then display the new value on the LCD.

Draw a flowchart and write a PBASIC program to control the operation described above.

Page 64: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 13 solution

START

PIN 0H IG H ?

PIN 1H IG H / LET b0 = b0 - 1

LET b0 = b0 + 1 U PDATE LCD

WAIT 1 Sec.

Page 65: Programmable systems-outcome-34

Programmable Systems Outcome 3

symbol counter = b0 ' define the variableinit: let dirs = %10000000 ' make pin 7 an output

let pins = %10000000 ' switch pin 7 high

pause 5 ' short pauseserout 7,T2400,(254,1) ' send 'clear LCD' commandpause 30 ' wait 30 ms

main: serout 7,T2400,(254,128) ' send 'line 1' commandserout 7,T2400,("Value = ") ' send messageserout 7,T2400,(#counter," ") ' send counter valuepause 1000 ' wait 1 sec

loop: if pin0 = 1 then add1 ' test switch 0if pin1 = 1 then take1 ' test switch 1goto loop

add1: let counter = counter + 1 ' add 1goto main ' refresh display

take1:let counter = counter - 1 ' take 1goto main ' refresh display

Page 66: Programmable systems-outcome-34

Programmable Systems Outcome 1

Outcome 3 - Microcontroller Controlled Mechatronic Systems

Section 4 - Mechatronic System Interfacing Circuits

The purpose of this section is to understand the need for interfacing input and output devices when building mechatronic systems that are controlled by a microcontroller.

When students have completed this unit they should be able to:

Explain why interfacing circuits are required within mechatronic systems.

Select appropriate interfacing techniques for common output devices.

Understand the different operation of common switch types. Understand how unipolar stepper motors are controlled. Understand the need for D-A conversion. Understand how push-pull drivers are used to control dc

motors. Understand pulse-width modulated control of dc motors. Understand the term 'soft-start' when applied to dc motor Write PBASIC programs to control stepper motors Write PBASIC programs to control

Page 67: Programmable systems-outcome-34

Programmable Systems Outcome 3

Mechatronic System Interfacing Circuits

The microcontroller input/output pin can only provide a small drive current when configured as an output. Therefore most output devices require an interfacing circuit.

The simplest interfacing circuit uses a bipolar transistor, and the Darlington pair configuration is often used to increase the drive current capabilities.

Vt

0V

Page 68: Programmable systems-outcome-34

Programmable Systems Outcome 3

Mechatronic System Interfacing Circuits

The ULN2803A integrated circuit can be very useful because it contains eight 'Darlington transistor pairs' in a convenient 18 pin DIL package. For added convenience the back emf protection diodes are also included on the integrated circuit.

The Stamp Controller output driver uses this type of integrated circuit.

Page 69: Programmable systems-outcome-34

Programmable Systems Outcome 3

Mechatronic System Interfacing Circuits

For devices which use larger currents (e.g. a solenoid), or a separate power supply (e.g. mains electricity) , a relay can be used. The relay is usually driven by a transistor as shown in the diagram.

+ 5V

0V

RELAY+ 12V

0V

SO LENO ID

Page 70: Programmable systems-outcome-34

Programmable Systems Outcome 3

Connecting Digital Switches

10K

+ 5V

0V

SWITC H O PEN = LO WSWITC H C LO SED = HIG H

NO RM ALLY O PEN SWITC H

Digital switches are available in two main 'families'. Normally-open switches are the most common. As the name suggests, the contacts on these switches are normally open, so the switch is electrically 'off'. When the switch is activated the contacts close and so the switch is electrically 'on'.

Note: Your Teacher will discuss pull up & Pull down resistors.

Page 71: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 14

Draw appropriate interfacing circuit diagrams for the following output devices.

Clearly explain your choice of circuit in each case.

a) LED b) Buzzerc) 6V DC motord) 12V DC solenoide) 24V pneumatic solenoid valve

Page 72: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 14START

R ED LED O NBO LT O UT

SW ITC H 3PRESSED ?

SW ITC H 2PRESSED ?

SW ITC H 1PRESSED ?

R ED LED O FFG REEN LED O N

BO LT IN

W AIT 3s

YES

YES

YES

N O

N O

N OBUZZER O N

W AIT 2s

BUZZER O FFWrite, and test, a PBASIC program for the control sequence shown in the diagram opposite.

Input Connection

Pin Output Connection

7 Bolt

6 Buzzer

5 Green LED

4 Red LED

Switch 3 3

Switch 2 2

Switch 1 1

0

Page 73: Programmable systems-outcome-34

Programmable Systems Outcome 3

Stepper Motors

Stepper motors are very accurate motors that are commonly used in computer disk drives, printers, XY plotters and clocks. Unlike dc motors, which spin round freely when power is applied, stepper motors require that their power supply be continuously pulsed in specific patterns. For each pulse, the stepper motor moves around one 'step', typically 7.5 degrees (giving 48 steps in a full revolution).

Stepper motors do have some limitations. First, the power consumption is greatest when the stepper motor is stopped (as all coils are still energised). Secondly the output torque is not very high, and so some type of gearbox is normally required. Unless this gearbox is very carefully designed the 'backlash' of the gears can disrupt the accuracy of the final system. Finally the speed of revolution is limited to around 100 steps per second, which provides a rotational speed of 2 rev / s or 120 rev / min.

Page 74: Programmable systems-outcome-34

Programmable Systems Outcome 3

Stepper Motors

There are two main types of stepper motors - unipolar and bipolar. Unipolar motors usually have four coils which are switched on and off in a particular sequence. Bipolar motors have two coils in which the current flow is reversed in a similar sequence. It is the unipolar type which is described in this section.

The stepper motor contains magnets which are fixed to the central armature. Four electronic coils are located around the casing. When a current is passed through these coils they generate a magnetic field, which attract/repels the permanent magnets on the armature, and so the armature spins one 'step' until the magnetic fields align. The coils are then energised in a different pattern to create a different magnetic field, and the armature spins another step.

Page 75: Programmable systems-outcome-34

Programmable Systems Outcome 3

Stepper Motors 1

2

3

4

5

6

7

8

9

18

17

16

15

14

13

12

11

10

ULN

2803

A

STEPPER

7

6

5

4

+ 12V

0V0V

To make the armature rotate continuously the four coils must be switched on and off in a certain order.

Many microcontroller systems use four output lines to control the stepper motor, each output line controlling the power to one of the coils.

Page 76: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 15

Describe three products which may contain stepper motors.

Describe how the motor is used in each case.

A toy manufacturer is designing a new programmable robot toy. Describe the advantages and disadvantages of using stepper

motors (rather than dc motors) to manoeuvre the robot.

Page 77: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 16

STAM PC O N TR O LLER

O U TPU TD R IVER

STEPPERM O TO R

12V D CSU PPLY

Connect a stepper motor to the output driver module as shown.Develop a PBASIC program that will rotate the stepper motor 48 steps in one direction, and then 48 steps in the other direction.

Page 78: Programmable systems-outcome-34

Programmable Systems Outcome 3

Step Coil 4(output 7)

Coil 3(output 6)

Coil 2(output 5)

Coil 1(output 4)

1 1 0 1 0

2 1 0 0 1

3 0 1 0 1

4 0 1 1 0

1 1 0 1 0

The table below shows the four different steps required to make the motor turn. Copy the table into your workbook

Page 79: Programmable systems-outcome-34

Programmable Systems Outcome 3

Stepper Motor Driver IC

Q 1

Q 2

Q 33

Q 4

15

STEPPER

+ 12V

0V0V

100K 1K

2 13 14 4

C

M

R VC C 2

VEE1 VEE2

VC C 1 RX

5 12

C LO C K

DIREC TIO N

SAA1027

The use of four output pins to drive a stepper motor can be an inefficient way to use the microcontroller input/output pins.

A dedicated integrated circuit, called the SAA1027 stepper motor driver, has been designed to overcome this problem by building the logic step generator, and the transistor switches, into one package.

Page 80: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity, key in the following program

symbol direct = 5 ' pin 5 is direction pinsymbol clock = 4 ' pin 4 is clock pinsymbol counter = b0 ' variable b0 is loop counterinit: let dirs = %00110000 ' pin 4 & 5 outputsmain: high direct ' set dir pin high

for counter = 1 to 48' setup a for...next loop high clock ' clock pin high pause 10 ' wait 10ms low clock ' clock pin low pause 10 ' wait 10msnext counter ' next looplow direct ' set dir pin highfor counter = 1 to 48' setup a for...next loop high clock ' clock pin high pause 10 ' wait 10ms low clock ' clock pin low pause 10 ' wait 10msnext counter ' next loopgoto main ' loop forever Continued

Page 81: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity, connect the MFA boards to the Stamp as shown. Run the program.

STAM PC O N TR O LLER

12V D CSU PPLY

M FASTEPPER

M O TO RD R IVER

M FAAD APTER

STEPPERM O TO R

Page 82: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 17

Crystal glassware is decorated by cutting grooves on to the outside surface. The process leaves the untouched parts of the glass clear and reflective, whereas the cut grooves are dull and rough and require to be polished.

The diagram shows the layout of a prototype system, developed by a student, to polish crystal glasses with eight parallel grooves cut along the length of the glass.

4-PHASESTEPPER M O TO R

G RO O VE SENSO R

G RO O VES

C RYSTALG LASS

PO LISHING BRUSHDRIVEN BY DC M O TO R

PNEUM ATIC C YLINDERSM O VE BRUSH M O TO R

INTO /O UT FRO M THE G LASS

Page 83: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 17 continued

4-PHASESTEPPER M O TO R

G RO O VE SENSO R

G RO O VES

C RYSTALG LASS

PO LISHING BRUSHDRIVEN BY DC M O TO R

PNEUM ATIC C YLINDERSM O VE BRUSH M O TO R

INTO /O UT FRO M THE G LASS

The system is to be controlled by a microcontroller. With a glass in place, the start button is pressed to cause the cutting disk to switch on and move into the cutting position. The first groove is cut for five seconds. The cutter is then withdrawn. The stepper motor rotates the glass through 90 degrees into position for the next groove. The process continues until all four grooves have been cut. The stepper motor used by the student has a step angle of 7.5 degrees. It is controlled by means of an SAA1027 driver IC signalled from the microcontroller.

Page 84: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 17 continued

Input Connection Pin Output Connection

7 Pneumatic Cylinder(1 = outstroke, 0 = instroke)

6 DC Motor(1 = on, 0 = off)

5 Stepper Pulse(0 to 1 pulse = 1 step)

4 Stepper Direction(1 = clockwise, 0 = anticlockwise)

3

2

1

Start button(logic 1 when pressed)

0

Page 85: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 17 continued

Calculate the number of steps the stepper motor must rotate to rotate the glass through 90 degrees.

Draw up a flow chart which shows the control sequence for the polishing process.

With reference to your flow chart, write a high level program in PBASIC to control the polishing process.

Page 86: Programmable systems-outcome-34

Programmable Systems Outcome 3

Push-Pull Motor Drivers

The L293D IC is a push-pull driver and is included on the Output Driver module.

The table shows the pin combinations to drive the motor forward or backward.

pin 4 pin 5 motor A pin 6 pin 7 motor B

0 0 halt 0 0 halt

0 1 forward 0 1 forward

1 0 reverse 1 0 reverse

1 1 halt 1 1 halt

Page 87: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity, key in and run the following program

STAM PC O N TR O LLER

O U TPU TD R IVER

M O D U LE

init: let dirs = %11110000 ' make pins 4-7 outputs

main: let pins = %01010000 ' motors forwardpause 3000 ' pause for 3 seclet pins = %00000000 ' motors haltpause 3000 ' pause for 3 seclet pins = %10100000 ' motors reversepause 3000 ' pause for 3 seclet pins = %11110000 ' motors haltpause 3000 ' pause for 3 secgoto main ' loop forever

Page 88: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 18

A single block of material is to be moved continuously back and forth along a conveyer belt without falling off either end.

Draw a flowchart that will control the movement as described. Write, and test, a PBASIC program for the control sequence as drawn in your flowchart.

Page 89: Programmable systems-outcome-34

Programmable Systems Outcome 3

DC Motor Speed Control

The speed of a dc motor varies directly with the voltage applied across it.

Microcontroller do not normally have an analogue output, and so they cannot be used to vary the voltage to a motor in this manner.

However there are two main methods by which a microcontroller can control the speed of a DC motor:

Digital to Analogue Conversion (DAC)

Pulse Width Modulation

Page 90: Programmable systems-outcome-34

Programmable Systems Outcome 3

Digital to Analogue Conversion

The simplest way to control the speed of a DC motor is to vary the voltage applied to the motor coils - the higher the voltage the faster the motor will spin (within the motor operating limits).

However the digital output from a microcontroller is at a fixed voltage, and the microcontroller cannot supply enough current to drive the motor. Therefore an interfacing circuit is required to boost the supply current for the motor and to provide different voltage levels.

2

1

0

DIG ITALANALO G UE

DAC

Page 91: Programmable systems-outcome-34

Programmable Systems Outcome 3

Digital to Analogue Conversion

A Digital to Analogue Converter (DAC) is an integrated circuit that decodes binary information and generates an analogue voltage proportional to the binary information provided.A three bit DAC, with an output range of 0-5V, may produce a voltage output according to the table shown opposite.:

binary input

analogue output (V)

000 0.00

001 0.71

010 1.42

011 2.13

100 2.84

101 3.55

110 4.26

111 4.97

Page 92: Programmable systems-outcome-34

Programmable Systems Outcome 3

Digital to Analogue Conversion

Each increase in the binary input produces a step increase of 0.71V (5V ÷ 7 steps) in the analogue output. In most practical applications the DAC cannot supply the full output voltage (e.g. 5V) due to the technical operating limitations of the device.

+5V

-5V

0V

10K

10K

22K

39K

2

1

0

The simplest form of DAC is made from a summing amplifier, as shown in the diagram below

Page 93: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity, key in a run the program

STAMPCONTROLLER

15VDCSUPPLY

MFAPOWERD TO A

CONVERTER

MFAADAPTER

MOTOR

symbol counter = b0 ' variable b0 is loop counterinit: let dirs = %11110000 ' pin 4-7 outputs

let pins = %00010000 ' starting speedmain: ' set dir pin high

for counter = 0 to 7 let pins = pins + 16 ' next speed pause 5000 ' wait 5 secondsnext counter ' next loop

end ' end

This program drives the motor at eight different speeds for five seconds each speed.

Page 94: Programmable systems-outcome-34

Programmable Systems Outcome 3

Pulse Width Modulation

With DAC, the voltage applied to the motor is directly varied. As the voltage is decreased the motor turns more slowly. However the current flowing through the motor coils also decreases, and so the output torque (turning moment) of the motor also falls.

Therefore this solution is often unsatisfactory for controlling DC motors due to the undesirable loss of motor torque. Pulse Width Modulation (PWM) is a digital method which can be used to vary the motor speed. In this method the full voltage is applied to the motor, but it is rapidly pulsed on and off. By varying the on and off ratio of the pulses the speed of the motor can be varied. As the full voltage is applied to the motor during the 'on' pulses the torque of the motor remains high.

Page 95: Programmable systems-outcome-34

Programmable Systems Outcome 3

Pulse Width Modulation

V

tSPAC E

M ARKThe graph shows how the technique is applied. The 'on' time for the motor is called the mark, the 'off' time is called the space. When the voltage is applied to the motor it accelerates to top speed. However before the top speed is reached the motor is switched off, thus slowing it down. By increasing the frequency of the pulses this acceleration/deceleration becomes negligible, and the motor rotates constantly at a slower speed.

Page 96: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity

Build the circuit as shown. This is most simply achieved by connecting the dc motor across the 'V+' and '7' Darlington Driver terminals on the Output Driver module.

Key in, download and run the program listed below. This program drives the motor at approximately half speed, as the space is twice the length of the mark.

symbol mark = b1symbol space = b2symbol motor = 7init: let dirs = %11110000 ' pin 4-7 outputs

let mark = 10 ' set mark to 10mslet space = 20 ' set space to 20ms

main: high motor ' output highpause mark ' pause for mark timelow motor ' output lowpause space ' pause for low time goto main ' loop

Page 97: Programmable systems-outcome-34

Programmable Systems Outcome 3

Soft Start of DC Motors V

t

In some devices, such as electric drills, it is desirable for the motor to start rotating slowly and then build up speed, rather than rapidly 'accelerating' up to full speed. This is called 'soft starting' the motor, and the use of PWM is often appropriate in these situations. The motor is started at a low speed and then gradually accelerated by varying the mark to space ratio over a period of time.

Page 98: Programmable systems-outcome-34

Programmable Systems Outcome 3

Soft Start of DC Motors

Key in, download and run the program listed below. This program gradually increases the speed by increasing the length of the mark time over a period of time.

symbol counter = b0 ' variable b0 is loop countersymbol mark = b1symbol space = b2 symbol motor = 7init: let dirs = %11110000 ' pin 4-7 outputs

let mark = 10 ' set mark to 10mslet space = 20 ' set space to 20ms

main: gosub puls ' call sub-procedurelet mark = mark + 2 ' increase mark time goto main ' loop

' sub-procedurepuls: for counter = 0 to 50 ' start a for...next loop

high motor ' output high pause mark ' pause for mark time low motor ' output low pause space ' pause for low time next counter ' loopreturn ' return from sub-procedure

Page 99: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 19

+5V

-5V

0V

10K

10K

22K

39K

2

1

0

Details of a speed control unit for a dc motor are shown.

Name the configuration of operational amplifier being used.

Name the method of dc motor speed control being used.

Explain clearly how the system operates.

State what the output voltage supplied to the motor will be when the following values are applied to the input pins (presume the feedback resistor is at it's maximum value of 10K).

i) 1ii) 3iii) 4

Page 100: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 20

A small dc motor, which is used to drive a model conveyer belt, is to be controlled by a microcontroller. The microcontroller gives out a 6V signal when an output bit is switched to logic 1. The speed of the motor must be varied according to the loads which are being carried. for convenience, the speed is to be reduced using pulse-width modulated control.

Develop a short PBASIC procedure which could be used to drive the motor in a clockwise direction with a mark-to-space ratio of 2:1. Explain how you could alter the procedure to make the motor rotate in an anti-clockwise direction, with the same mark-to-space ratio.

Pin allocations are shown on the next slide

Page 101: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 20

Input Connection

Pin Output Connection

7

6

5 Motor Anticlockwise

4 Motor Clockwise

3

2

1

0

Page 102: Programmable systems-outcome-34

Programmable Systems Outcome 3

Analogue to Digital Conversion

The microcontroller can only process digital (high/low) signals.

However in many practical applications analogue quantities, such as light intensity or temperature, need to be tested.

An Analogue-to-Digital Converter (ADC) is a device which can convert analogue quantities into digital signals.

An 8-bit ADC can generate a digital signal in the range 0 to 255 (i.e. one byte).

ADC's are available as separate integrated circuits, or may even be 'built into' the microcontroller to give it 'on-board' ADC capabilities.

With the Stamp Controller system an external 8-bit ADC integrated circuit is used.

Page 103: Programmable systems-outcome-34

Programmable Systems Outcome 3

Voltage Reference

V = 2.5VREF

1K

2.5VREF

DIO DE

5V

0V

ADCs are designed to process analogue signals within a certain range.

The maximum voltage signal that can be processed by an ADC is called its reference voltage.

A common reference voltage for an 8-bit ADC is 2.55V, so the ADC can measure signals in the range 0 to 2.55V.

Therefore the 8-bit ADC device will generate an 8-bit value directly equivalent to the voltage signal applied.

Page 104: Programmable systems-outcome-34

Programmable Systems Outcome 3

Signal Conditioning

SIG NALAM PLIFIER

Analogue sensors, such as the thermistor (temperature sensor), may not directly produce a suitable signal for use with the ADC. Therefore it is often necessary to use a signal amplifier circuit so that the input signal can be 'conditioned' to the input range of the ADC (0 to 2.5V). An operational amplifier, configured as a voltage amplifier, is commonly used for this task.

Page 105: Programmable systems-outcome-34

Programmable Systems Outcome 3

Example

The following example shows how the gain of the operational circuit is typically calculated.

A temperature sensor is to be used to monitor the temperature of a factory furnace. Experimentation has shown that the temperature sensor produces a linear output signal, reading 0V at 0º Celsius and 1.53V at a temperature of 200º Celsius. The maximum operating temperature of the furnace is 1000º Celsius. The maximum voltage that may be fed into the ADC is 2.55V

Draw a circuit diagram of a suitable signal conditioning system based on operational amplifiers.

Continued

Page 106: Programmable systems-outcome-34

Programmable Systems Outcome 3

Example

1) Calculate the maximum input signal, which is at 1000º Celsius.

Signal at 200º = 1.53V1000º is equal to 5 x 200ºTherefore maximum signal is 5 x 1.53V = 7.65V

2) Calculate the gain required from the op-amp circuit.

Input Signal = 7.65VRequired output signal =

2.55VTherefore Gain = output /

input = 2.55 / 7.65 = 0.33

Your Task

Draw a suitable circuit to achieve a gain of 0.33

Page 107: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 1

A microcontroller based monitoring system is used to monitor sound signals over a period of time. It is found that the maximum voltage generated from the sound signals is 6V. However the maximum voltage that may be fed into the microcontroller system is 1.8V

a) Draw a circuit diagram of a suitable signal conditioning system, based on operational amplifiers, which will allow the signals to be monitored without damaging the microcontroller system. Indicate the values of any components used in your circuit.

b) If the sound signal is fed into the microcontroller through an ADC which has a voltage reference of 1.8V, write down the 8-bit binary pattern you would expect from the ADC when the sound signal generates a voltage of 4.8V.

Clearly identify the least significant bit (LSB).

Page 108: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 1(b) Solution

Two ways to consider this problem

1st If the ADC is 8 bit, then there are 255 steps from 0V to 6V

This means each step is worth 0.023529V approx.

If we are trying to find what 4.8V would give, then if we divide 4.8 by 0.023529, we get 204 steps.

Converting 204 into binary we get 11001100

OR

2nd A neater way is to use (4.8/6) x 255 = 204

Same answer, but a bit quicker. Can you work out how I arrived at this method?

Page 109: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 2

The signal from a temperature sensing sub-system is processed by an ADC before being read by a microcontroller. The ADC has a voltage reference of 1.8 volts which produces a binary word of %11111111

a) What is an ADC and why is it required before processing by the microcontroller?

b) Calculate the binary word produced by the ADC at 200ºC, if the voltage signal from the temperature sensing sub-system at this temperature is 1.2V.

Clearly identify the least significant bit (LSB).

Page 110: Programmable systems-outcome-34

Programmable Systems Outcome 3

Interfacing to the ADC

PIN 0

PIN 1

PIN 2

2.5V

1

2

3

4

V IN

+ 5V

0V

VIN(+ )

V IN(-)

G ND

C S

VREF

VC C

C LK

DATA

ADC0831

The ADC used with the Stamp Controller is a 'serial' type device. This means that the analogue reading is transmitted as a series of eight consecutive bits via a single 'data' pin. However it is obviously necessary that the Stamp Controller and the ADC are synchronised for this communication, and this is achieved by the Stamp Controller sending a number of 'clock' pulses down a second 'clock' pin.

Page 111: Programmable systems-outcome-34

Programmable Systems Outcome 3

Interfacing to the ADC

THEREFORE, IT IS NOT NECESSARY TO LEARN THESE ‘SUB-PROCEDURES.

THE SUB-PROCEDURES WILL ALWAYS BE PROVIDED, IF NECESSARY, IN EXAMINATIONS.

WHEN CREATING NEW PBASIC PROGRAMS THE TEMPLATE FILE ‘TEMPLATE.BAS’ SHOULD BE USED.

THIS TEMPLATE FILE CONTAINS ALL THE STANDARD SUB-PROCEDURES REQUIRED, SO THAT IT IS ONLY NECESSARY TO KEY IN THE MAIN PROGRAM.

Although the procedure for using the ADC is the same in every case, it is never the less very complex.

Page 112: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity STAM P

CO NTRO LLERSERIAL

ADCM O DULE

TEM PERATUREPRO BE

Build the circuit as shown above.

In the case of the serial ADC module the sub-procedure to take a reading is called 'adcread'.

This sub-procedure performs a read of the ADC and then stores the reading in a variable named 'data'.

CONTINUED

Page 113: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity

Therefore a sample program to take an analogue reading, and then transmit it to the computer for viewing (using the debug command), would be:

main: gosub adcread 'Get the ADC readingdebug data 'Transmit data to computerpause 1000 'Pause for 1 secondgoto main 'Loop forever

Note that this is not the whole program listing, as the actual sub-procedure 'adcread' and the symbol definitions are not included. However they are not needed to understand how the main program operates, and so can be left out for clarity.

Open the file ‘template.bas’, key in the main program above in the correct section of the template and run the program.

Page 114: Programmable systems-outcome-34

Programmable Systems Outcome 3

Multiplexers

ADC integrated circuits are relatively expensive to construct. When it is necessary to record more than one analogue signal a 'multiplexer' can be used to prevent the need for multiple ADC circuits. The multiplexer can be physically 'built into' the ADC integrated circuit, or can be provided by a completely separate integrated circuit.

Vs1

Vs2

TO ADC

M ULTIPLEXER

The multiplexer functions in a similar manner to a rotary switch connecting each of the analogue channels in turn to the ADC. Therefore the multiplexer 'selects' which sensor is connected to the ADC at any one time. As only one sensor is connected to the ADC at any one time the whole system is slower than using a separate ADC for each sensor. However modern microcontrollers operate very quickly, and so the cost saving usually outweighs the increased processing time.

Page 115: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity

STAM PC O N TR O LLER

SE R IALAD C

M O D U LE

TE M PER ATU R EPR O BE

SER IALLC D M O D U LE

LIG H TSEN SO R

M U LTIPLEX ER

Build the circuit as shown. Note that a 2mm lead is used to connect the MFA Analogue Multiplexer to the Serial ADC Module (pin 3).

Key in, download and run the program listed on the next slide. This program reads each of the two sensors every second, and displays the reading on the LCD.

Page 116: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity STAM PC O N TR O LLER

SE R IALAD C

M O D U LE

TE M PER ATU R EPR O BE

SER IALLC D M O D U LE

LIG H TSEN SO R

M U LTIPLEX ER

let pins = %11110111pause 5 'Short pauseserout 7,T2400,(254,1) 'Clear LCD commandpause 30 'Short pause

main: low ADC_MPX 'Select sensor 1gosub adcread 'Get the ADC readingserout 7,T2400,(254,128) 'Print on LCD line 1serout 7,T2400,("Sensor 1= ",#data," ")high ADC_MPX 'Select sensor 2gosub adcread 'Get the ADC reading serout 7,T2400,(254,192) 'Print on LCD line 2serout 7,T2400,("Sensor 2= ",#data," ")pause 1000 'Wait 1 secondgoto main 'Loop

Page 117: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 3

TEM PERATU R EPRO BE

STAM PCO NTR O LLER

SERIALADC

M O DU LE

SERIALLCD M O DU LE

DATALO G G ERM O DU LE

Build the circuit as shown in the diagram above. (The datalogging module is optional at this point)

a) Write a high level program in PBASIC that will continually monitor and display the temperature of the water on the LCD.

b) The temperature of the water should not be allowed to drop below 45 degrees Celsius. Modify your PBASIC program so that the immersion heater (connected to pin3) is automatically switched on when the water cools below the critical temperature.

Page 118: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 3 solutions

main: gosub adcread 'Get the ADC readingserout 7,T2400,(254,128) 'Print on LCD line 1serout 7,T2400,("Temp = ",#data," ")pause 1000 'Wait 1 secondgoto main 'Loop

main: gosub adcread 'Get the ADC readingserout 7,T2400,(254,128) 'Print on LCD line 1serout 7,T2400,("Temp = ",#data," ")if data < 45 then doon 'Jump if temp lowlow 3 'Heater offgoto main 'Loop

doon: high 3 'Heater ongoto main 'Loop

Page 119: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 4

A local council has issued standard size "wheely bins" to all households so that the dust carts can empty them automatically. The dustman simply clamps the wheely bin onto a platform and then presses a switch. the platform then rotates through 130 degrees as shown in the diagram. The platform stays in the emptying position for 5 seconds and then returns to it's original position, where it triggers a micro switch on the rear of the dustcart. Platform movement is controlled by a dc motor and gearbox.

START SWITC H

M IC RO -SWITC HPLATFO RM

WHEELYBIN

130 0

Continued

Page 120: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 4

The process is controlled by a microcontroller. the angle of rotation of the platform is sensed by a rotary potentiometer. The potentiometer is capable of rotating 360 degrees from the starting position, and rotation between 0 and 360 degrees sends a proportional reading of between 0 and 255 via an ADC module connected to the microcontroller.

Input Connection

Pin Output Connection

Start switch

0

1

2

Micro-switch

3

4 Motor clockwise (Raises bin)

5 Motor anti-clockwise (Lowers bin)

Continued

Page 121: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 4

(a) Calculate the analogue reading when the platform is 130 degrees from the original position.

(b) Draw up a flow chart which shows the control sequence for the emptying of the wheely bin.

(c) With reference to your flow chart, write a high level program in PBASIC to control sequence for the emptying of the wheely bin.

Assume use of a pre-written sub-procedure called 'adcread' which will return the analogue reading in a variable called 'data'.

Page 122: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 4 solutions

(a) Calculate the analogue reading when the platform is 130 degrees from the original position.

360 degrees gives a reading of 255Therefore 130 degrees gives a reading of 130/360 * 255 = 92

(b) Draw up a flow chart which shows the control sequence for the emptying of the wheely bin.

STA

RT

NO NO NO

YES

YES

YES

STAR

TSW

ITCH

MO

TOR

CLO

CKW

ISE

MO

TOR

ANTI

CLO

CKW

ISE

ANG

LE=1

30O

ANG

LE=0

O

MO

TOR

OFF

MO

TOR

OFF

WAI

T 5

Sec.

Page 123: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 4 solutions

(c) With reference to your flow chart, write a high level program in PBASIC to control sequence for the emptying of the wheely bin.Assume use of a pre-written time delay sub-procedure called 'adcread' which will return the analogue reading in a variable called 'data'.

main: let pins = %00000000if pin0 = 1 then loop 'Test start switchgoto main 'Else loop

loop: high 4 'Lift bingosub adcread 'Read analogue valueif data > 92 then up 'Test for topgoto loop 'Else continue

up: low 4 'Motor offpause 5000 'wait for 4 secondshigh 5 'Lower bin

lp2: gosub adcread 'Read analogue valueif data = 0 then main 'Test for downgoto lp2 'Else continue

Page 124: Programmable systems-outcome-34

Programmable Systems Outcome 3

Data-Logging

Microcontroller systems are ideal for data logging tasks. A data logger is a device which is capable of remotely capturing and recording information, often analogue signals such as temperature and light level (via an Analogue to Digital Converter).

Data loggers are used in a wide range of applications from flight recorders on aircraft to life support systems in incubators for premature babies.

The frequency at which signals are recorded is called the sample frequency. A high frequency rate would be used to record a very fast changing signal over a small period of time - for instance when measuring the electrical activity of the human heart. A low frequency rate would be used when a slow changing signal is measured over a long period of time - for instance monitoring the temperature of a green house over a week period.

Page 125: Programmable systems-outcome-34

Programmable Systems Outcome 3

Data-Logging

As data loggers are generally small, portable and battery operated, the data is often stored electronically in EEPROM integrated circuits. This means the data is retained when the batteries are removed, but can also be updated easily when required.

Data loggers can be left unattended for long periods of time, and are ideal for hostile or remote environments measuring variations in industrial and weather monitoring situations.

Once a data logging experiment is complete, it is obviously necessary to be able to retrieve the data for analysis. In more basic systems the data may just be printed out directly as a simple table, but in more advanced systems it is common to 'upload' the data to a personal computer for mathematical analysis and/or graph generation in a spreadsheet application

Page 126: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 5

Suggest a suitable sampling frequency for each of the following monitoring systems.

In each case clearly explain why your sample frequency is appropriate.

a) Monitoring the temperature in a greenhouse.b) Monitoring the speed of an aeroplane.c) Monitoring the heart rate of a premature baby in an incubator.d) Monitoring the temperature in a restaurant cold store.

Page 127: Programmable systems-outcome-34

Programmable Systems Outcome 3

The Data Logger Module

C S

C LK

DI

DO

1

2

3

4

VC C8

NC7

O RG6

VSS593

LC66

+ 5V

C S

C LO C K

DATA

2K2

The data logger module contains a 512 byte EEPROM integrated circuit. In practical terms this means that up to 512 8-bit ADC readings can be stored in the EEPROM.

The EEPROM integrated circuit is a serial device, and operates in a very similar manner to the serial ADC, using the same three data, clock and chip select signals. However in this case the data signal is bi-directional, as it is necessary to write to, and read from, the EEPROM memory.The 512 byte memory is divided into two pages, each page containing 256 bytes. Therefore to correctly locate a memory cell you must specify both its page number (0 or 1) and its address (0 to 255).

Page 128: Programmable systems-outcome-34

Programmable Systems Outcome 3

The Data Logger Module

Like the ADC, the EEPROM makes use of two 'standard' sub-procedures to carry out the serial communication. These sub-procedures can be copied directly from the datasheets. Sub-procedure 'eewrite' is used to write data to the EEPROM, and 'eeread' is used to read data back from the EEPROM

The 512 byte memory is divided into two pages, each page containing 256 bytes. Therefore to correctly locate a memory cell you must specify both its page number (0 or 1) and its address (0 to 255).

Continued

Page 129: Programmable systems-outcome-34

Programmable Systems Outcome 3

The Data Logger Module

Therefore to write the value '85' to EEPROM address '23' on page '1' the program would be

let data = 85 'Set the data.let address = 23 'Set the address.let page = 1 'Set the page.gosub eewrite 'Write the data to the EEPROM.

To retrieve the data and show it on the computer screen (via the debug command) the program would be

let address = 23 'Set the address.let page = 1 'Set the page.gosub eeread 'Read the data from the EEPROM.debug data 'Send data to the computer screen.

Page 130: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity TEM PERATU R EPRO BE

STAM PCO NTR O LLER

SERIALADC

M O DU LE

SERIALLCD M O DU LE

DATALO G G ERM O DU LE

main: for b10 = 0 to 30 ' Start a for...next loop let page = 0 ' set EEPROM page let address = b10 ' set EEPROM address gosub adcread ' get analogue reading gosub eewrite ' write to EEPROM serout 7,T2400,(254,128) ' Line 1 serout 7,T2400,("Address = ",#address," ") serout 7,T2400,(254,192) ' Line 2 serout 7,T2400,("Data = ",#data," ")

pause 1000 ' wait 1 secondnext b10 ' next loopend

Build the modules as shown, download and run the following program.

Page 131: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity

TEM PERATUREPRO BE

STAM PCO NTR O LLER

SERIALADC

M O DULE

SERIALLCD M O DU LE

DATALO G G ERM O DULE

Describe in your own words what the previous program was doing

The program records thirty readings of the analogue sensor. For ease of understanding the readings are also shown simultaneously on the LCD.

Page 132: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity TEM PERATU R EPRO BE

STAM PCO NTR O LLER

SERIALADC

M O DU LE

SERIALLCD M O DU LE

DATALO G G ERM O DU LE

Build the modules as shown, download and run the following program.

Let dirs = %11110111 ‘pin 3 as an input

main: for b10 = 0 to 30 ' Start a for...next loop let page = 0 ' set EEPROM page let address = b10 ' set EEPROM address gosub eeread ' read data from EEPROM serout 7,T2400,(254,128) ' line 1 serout 7,T2400,("Address = ",#address," ") serout 7,T2400,(254,192) ' line 2 serout 7,T2400,("Data = ",#data," ") pause 1000 next b0 end

Page 133: Programmable systems-outcome-34

Programmable Systems Outcome 3

Activity

TEM PERATU R EPRO BE

STAM PCO NTR O LLER

SERIALADC

M O DU LE

SERIALLCD M O DU LE

DATALO G G ERM O DU LE

This program retrieves the data from the EEPROM one address at a time. To get the next reading the digital input switch on the Serial

ADC module should be briefly pressed.

Page 134: Programmable systems-outcome-34

Programmable Systems Outcome 3

Analysing Data

In most situations it will be necessary to tabulate the readings collected, for analysis. The serial printer module allows the readings to be printed directly, without the need for a host computer.

STAM PCO NTRO LLER

SERIALPRINTERM O DULE

PRINTERDATALO G G ERM O DULE

Unfortunately, because of the school system, we do not have stand alone printers where we can show this process. However, program to achieve this is shown on the next slide.

Page 135: Programmable systems-outcome-34

Programmable Systems Outcome 3

Printing Data

pause 5 ' Short pausestart: serout 7,T2400,(STX) ' Start printing command

'Print titlesserout 7,T2400,(TAB,"Address",TAB,TAB,"Sensor")serout 7,T2400,(CR,LF,LF)'Next line.

main: for b10 = 0 to 30 'Start a for..next loop. let page = 0 'Set page let address = b10 'Set address gosub eeread 'Read data from EEPROM. serout 7,T2400,(TAB,#address,TAB,TAB,#data)

serout 7,T2400,(CR,LF) 'Next linenext b10 'Next loop.

serout 7,T2400,(FF) 'Print form-feedserout 7,T2400,(ETX) 'Send printer module to sleepend 'end

Page 136: Programmable systems-outcome-34

Programmable Systems Outcome 3

Analysing Data with a Spread-sheet

M ULTIPLEXER ADC M IC RO -C O NTRO LLER

HO ST C O M PUTER

SERIAL LINK

EEPRO MANALO G UESENSO RS

After a data-logging experiment it is usual to 'upload' the data to a host computer so that the readings can be analysed via a spread-sheet application. This enables mathematical calculations to be made, and also allows the generation of graphs.

The 'upload' procedure requires serial communication between the Stamp Controller and the host computer. This is achieved via a serial cable connected to the Datalogger Module.

Page 137: Programmable systems-outcome-34

Programmable Systems Outcome 3

Analysing Data with a Spread-sheet

The procedure is as follows:

Download the standard file ‘datalink.bas’ to the Stamp Controller. Move the serial cable from the Stamp Controller to the Datalogger

module. Start up the ‘Datalink’ utility software on the computer. Click ‘New’ with the ‘Datalink’ utility to start the upload. Once the upload is complete. save the uploaded data into a CSV

format data file. Exit the ‘Datalink’ utility. Start up the spreadsheet application. Open the CSV format data file previously saved. Analyse and draw graphs of the data using the standard

spreadsheet functions.

Page 138: Programmable systems-outcome-34

Programmable Systems Outcome 3

Analysing Data with a Spread-sheet

Activity

Open the standard PBASIC file ‘datalink.bas’.

Follow the procedure detailed on the last slide to upload the data from the datalogger module.

Once the upload is complete, save the CSV file and then exit from the datalink utility.

Start up the spread sheet application, import the CSV file, and generate a graph from the data.

Page 139: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 6

A data logging system is to be used to record the temperature and light level in a greenhouse over a period of 1 day.

STAM PC O N TR O LLER

SER IALAD C

M O D U LE

TEM PER ATU R EPR O BE D ATALO G G ER

M O D U LE

LIG H TSEN SO R

M U LTIPLEXER

Build the apparatus as shown in the diagram above.

a) Explain why it is necessary to use a multiplexer in this situation.b) Write a 'test' program in PBASIC that will record the temperature

and light levels over a 5 minute period.c) Use the datalink program to retrieve the data from the datalogger

module. Using a spreadsheet draw a line graph to show the data recorded.

Page 140: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 7

A pet shop owner requires a data logging system that will allow him to monitor the temperature of one of the large display aquariums in the shop.

The datalogger should record the temperature every ten minutes over a 24 hour period. At the end of the period the owner wants to be able to print out a table of results from the datalogger without having to use a host computer to analyse the data.

(a) Draw a block diagram of the system.(b) Draw up a flow chart which shows the control sequence for the data logging experiment.(c) With reference to your flow chart, write a high level program in PBASIC to perform the experiment.

Page 141: Programmable systems-outcome-34

Programmable Systems Outcome 3

Assignment 8

In a maternity hospital premature babies are cared for in incubators. The temperature inside each incubator is continuously monitored.

A microcontroller based data logging system is used to monitor the temperature from four separate incubators by means of a 4-bit multiplexer.

a) With the aid of sketches, explain the function of a 4-bit multiplexer and suggest why it is useful in this application.

b) Suggest a suitable way of presenting the output from the datalogging system for use by the nursing staff. Explain your answer.