Analogue to digital converters

Analogue input is fed to the converter through any one of 14 channels. For this discussion we will refer only to channel AN0, which is at pin 19. At power-on, all the PIC's output channels are automatically set as analogue inputs. The analogue selection register ANSEL, which is in Bank 2, is used to define which are to be reset as digital inputs. If bit < 0> is '1' this makes AN0 (pin 19), an analogue input. At the same time it disables the weak pull-up and the interrupt-on-change function....

Avoiding obstacles

The LEDs are mounted on the body of the robot and directed on a single central point about 100 mm ahead of the robot. If an object is present at this point, and assuming the object is large enough and fairly reflective, the amount of light received by the LDR will be significantly greater than normal. The robot detects this situation and takes avoiding action. The robot will respond also when it approaches a wall or furniture, so it is able to scoot about the room indefinitely, though it may...

Building the wheel system

We chose a typical food storage box, with a snap-on lid. The corners are rounded (see photo). The best way to use this type of box is upside down. The lid (now underneath) has the motor, the drive wheels and the castor mounted on it. The circuit boards and parts of the robot are housed in the box. An electric motor spins too fast to drive the wheels directly. Use a motor with a built-in gearbox. We chose a 6 V (nominal) DC motor which included a kit of plastic gear wheels. These are assembled...

Camera

This is a one-pixel digital camera It has a single LDR as its sensor. Its output is an analogue voltage ranging between a few millivolts when focussed on a black object and several volts when aimed at brightly lit white objects. Because it has a lens to focus a life-size image of the object on to the sensor, the camera has high sensitivity and a narrow field of view. These features are important when the Gantry is playing a board game or when registering the layout of a drawn maze. But,...

Companion website

This website carries downloadable files of the MPASM versions of all the programs and subroutines listed in the book. In addition there are files of programs for the Quester and the Gantry that are too long to be included in the book. All downloads are free of charge. The site also carries the same programs in the form of hexadecimal files. What sort 2 Getting down to detail 4 Controlling the robot 5 Programming a PIC 6 Simulating the PIC 8

Comparators

The 16F690 has two voltage comparators, each of which has its own control and register. For comparator 1 (C1), this register is called CM1C0N0, at address 119h in Bank 2. We will look at programming C1. Programming C2 is similar. The comparator has the usual properties of a comparator circuit. It has two inputs, C1VP (positive, or non-inverting input) and C1VN (negative, or inverting input). The non-inverting input is supplied either through the RA0 pin (pin 19) or from an internal voltage...

Connections between boards

See the drawings on p. 264 and p. 268, and the table below. The photo on the previous page illustrates the way the 0 V and +6 V lines are daisy-chained from board to board. The PIC is not in its socket, and will not be there until the whole system has been tested. No. of wires From connector To connector Light sensor LDR Light sensor Processor * Pin 0.9 mm pin on the board, socket on the lead. t 2-way and 3-way polarising header plug on the board, socket on the lead. Begin testing by checking...

Connectors

This book is based on the idea of circuit modules. These modules can be put together in many different ways to build a variety of robots. Modules also have the advantage that their circuit boards are small and so will fit more easily into that small space in the cramped interior of the robot. A modular system can be improved, added to and revised without having to re-build the whole system. There are several types of connectors suitable for robot circuits. The cheapest are the 0.9 mm or 1 mm...

Controller board

This is the same as the controller board of the Scooter (p. 174) but has three pull-up resistors added to it. These are 10 kQ resistors soldered between E2 and F2, between E3 and G3, and between E4 and H4. The controller board is bolted to the shelf on the right and close to the front (see photo overleaf) where it is easy to remove and replace the PIC. Before wiring up the board, the programming of the stepper motor of the arm was developed and tested. The motor is on the right-hand wall, with...

Controlling the robot

The first robots (they were called automatons in those days) were purely mechanical, driven by clockwork or steam power. The arrival of electronics greatly increased the scope of what robots could be made to do. Modern concepts of robotics began to emerge. The big advances came when engineers started putting complex digitial circuitry on a single chip. These were microprocessors, capable of millions of operations per second. Microprocessors are widely used in computers, robots, and many other...

Cutting tools

A junior hacksaw, with a 150 mm long blade is good enough for most jobs, such as cutting wood or plastic, and for circuit boards. For cutting aluminium or brass stock a regular hacksaw is faster and gives a straighter cut. If you have problems with cutting things square or if you need to cut at a particular angle, a mitre saw is a great help. It keeps the saw blade vertical and perpendicular to the length of the workpiece. It has gauges to help cut pieces to equal lengths. The frame that...

Data transmission with the USART

The 690 has an Enhanced Universal Synchronous Asynchronous Receiver Transmitter, or USART for short. We use this to take a byte of data and transmit it serially (that is, one bit at a time) to the USART of another PIC. The second USART receives the serial data bit by bit and assembles it into a byte that can be read from a register. Transmission can be by a single wire (if the 0V line is common to both PICs) or by a radio link. The output from the USART is at RB7 (pin 10) and the input at RB5...

Developing the Quester

There is plenty of scope for combining some of the routines in this specification to make longer and more complex programs the PIC16F690 still has plenty of program memory to spare. Consider building some of the other sensors described in Part 3. Add them to this robot. For instance, the sound sensor has several applications ranging from responding to a hand-clap (everyone in the room has to keep very quiet when this is running) to allowing a pair of robots to communicate by using sound...

Dry run

No matter what ingenious programming software is available, there are times when the only practicable way to debug a program is to do a dry run. All you need are a pencil and paper. In a dry run you set out a table of all the registers and variables that are involved. You then go through the listing line-by-line and work out the values that are in each register. Enter these in the table and confirm that they are the right values. As an example, here is a segment of the listing for part of the...

Gear wheels

Gear wheels are often needed for drive transmission and for moving arms and grippers. They are available as packeted kits of plastic gear wheels of a range of diameters from various manufacturers. Tamiya produce sets of gears, including motors, that can be assembled into gearboxes of many different ratios. Meccano and Lego produce gear wheels too, and the kinds of mechanism that can be built from them are shown in the photos overleaf. Gear wheels transmit turning force by engaging their teeth....

Hello World

The program of the PICBASIC version is listed opposite. It is clear when we compare this listing with the assembler listing on pp. 184-185, that the BASIC listing is much shorter. This is generally true of all BASIC versions of assembler programs. BASIC has built-in routines for complicated tasks, while assembler has to be told what to do, one small step at a time. But the assembled program in machine code is probably always shorter than the version generated by BASIC compiler. A noticable...

Highlevel languages

Assembler instructs the controller step by step. High-level languages, such as BASIC and C, provide the programmer with commands each of which takes the controller through many steps. This makes programming quicker and easier to follow. A good example is the WRITE command in PICBASIC. A single program line, 'WRITE 3, count', puts the value of the count variable into byte 3 of the PIC's EEPROM. Doing the same thing in assembler takes many more program lines. A program written in a high-level...

Infrared sensor board

The infrared sensors in this robot are mounted below the lower deck, just behind each bumper, and directed downward. The rims of the shields are about 20 mm above ground level. The probes are built on small squares of stripboard (overleaf). The IR LED (D1) is a 5 mm type able to pass a maximum current of 50 mA. The IR photodiode (D2) is a BP104, which fits conveniently close to the circuit board, but other types can be used. When soldering in the diodes, note that they are mounted with opposite...

Inputs and outputs

Programs usually begin by clearing the ports and setting each channel as either an input or an output. We also need to think about which input channels are to be digital and which analogue. If a channel is a digital input, is it to have weak pull-ups Now we step warily through the various banks of Special Function registers. Incidentally, even though a linker file may have eliminated the need to type the equates, the list of registers on p. 135 is handy as a reminder of which bank each register...

Interference

The Gantry has several connecting wires that are 10 cm long or longer. These wires are liable to pick up spikes and other signals radiated from other connecting wires. For example, the wires from the Hall effect sensors to the PIC1 board are about 70 cm long, and this may lead to unreliable counting of the marker magnets. This problem may not arise but, if it does, the x- and y-frames do not move the correct distances. The effect is cumulative. The sensible solution would be to use screened...

Location sensors

One of the advantages of the gantry type of robot is that it is easy to keep the robot informed of the exact location of the x-frame. This is done by placing regularly spaced markers on one of the x-rails and one of the y-rails. The markers work like this. At the start of a session the x-frame is returned to its base location (front right). From then on, it keeps a count of how many markers it has passed, and the direction it is moving. From this data it can calculate its position in an...

Machinegun sound effect

This routine generates a burst of white noise which sounds reasonably like a burst of machine-gun fire. It makes a good addition to the repertoire of a military toy robot. The sound is variable so it could have other applications. The random number generator (pp. 161-163) is made to run in a loop, generating a sequence of values of randval at high speed. As each new number is generated, its bit< 7> is read (by ANDing randval with 080h,) and channel RC7 of port C is set to the same value....

Magnetic probe circuits

Each probe (p. 317) is connected to the controller board by three leads positive supply, 0 V and output. The positive supply and 0 V are connected to pins at the top of the PIC2 board. The output leads run direct to pins 15 (RC1) and 14 (RC2) of PIC1. These are the comparator input pins. The motor control board mounted on the front panel of the Gantry. The y-winch motor Ml can just be seen on the right of the board.

Mode 1 Wanderer

In this mode, the robot bleeps once, then runs across the floor, bumping into furniture, walls and obstacles. Every time it bumps it switches on the LED on the side that it bumped, reverses a short distance, turns away from the side it bumped, switches off the LED and then continues on its way, flashing the LEDs and emitting bleeps as it does so. It repeats this sequence indefinitely. The Quester needs the two bumpers for this mode, but no other sensors. It is a good program for your first...

Mode 2 Light seeker

This program is best run with the robot in a curtained or low-lit room. It works most effectively if there is only one source of light. There should not be any obstacles on the floor. The robot needs the light sensor and the pair of bumpers. The Quester is made to detect the direction of the source by spinning round while continually reading the input from the light sensor. The tube on the light sensor restricts the angle of view to about 10 degrees ahead. As soon as the sensor detects light...

Mode 3 Line follower

The Quester follows a line marked on the floor or other surface. For this task, it needs the pair of infrared sensors. The ultra-bright LEDs on the front panel are not essential, but they add to the visual appeal of the robot, especially when it is operating in low light. It can, of course, operate in darkness or in bright room lighting. There is also the practical point that when the robot is spinning left or right to keep on a curving line, the LED on the side to which it is spinning comes...

Mode select routine

The memory of a PIC is large enough to accommodate several different programs unless they happen to be blockbusters. For this reason it is convenient to have a number of programs in a single PIC chip and to be able to select any one of these at run time. The first program lines after the 'start' label usually initialise the ports and set any options that are in force for the whole program. Immediately after this comes the mode select routine. Leave it out if there is only one program on the...

More mods

For a toy vehicle, an amusing addition to the sensors is a downwardly-directed light sensor underneath, at the front. It could have its own light source, preferably infrared, or rely on ambient light. When the robot is running on a table there will be a change of light level as the front of the vehicle reaches the edge of the table. Program it to respond immediately by backing and turning before going forward again. A sensor that detects the Earth's magnetic field is unusual but inexpensive....

Motor direction control

There are two ways of doing this with a transistor H-bridge, and by a relay. The H-bridge circuit is used in most of the projects in this book. It can be based on BJTs or MOSFETS. The circuit (see opposite) comprises four transistors for controlling one motor. Two of the transistors are npn (Q1 and Q3) and two are pnp (Q2 and Q4). There are two control inputs, A and B, which supply current to the bases of the npn transistors and turn them on when the input voltage is high. They sink current...

Mounting the boards and offboard items

The three boards are each supported on two M3 bolts. The exact positioning depends on the size and shape of the box. Remember to place the Controller board so that it is easy to remove and replace the PIC when debugging the program. Check that the motor and other items on the lid will not come into contact with the boards when the lid is on the box. Leave enough room for the wiring. Drill 3 mm holes in the box for the bolts that support the boards. Drill a hole in the bottom of the box for the...

Moving from C to D

The AtoB program is a useful one for positioning the x-frame at the beginning of a session. It assumes that it is at (0, 0) and takes it to some other location to perform its tasks. Suppose the x-frame now has to go to another position. One way of doing this is to repeat the routines for moving it to base, then to (0, 0), and eventually to the new location. This takes time and it is quicker to go directly from one location to the next, without visiting base and (0, 0). This is the function of...

Moving the xframe

One of the advantages of a gantry is that the processor always knows where the x-frame is. So one of the important programming tasks is to put it where it should be. As explained earlier, the Gantry locates the x-frame on a square grid. In the prototype there are 6 rows of 6 columns, making a total of 36 locations. There are four core subroutines for moving the x-frame. They move it one step in each direction left, right, back, forward. Here is the listing of left, the subroutine that moves the...

Offboard connections

The boards are connected by single-stranded PVC insulated connecting wires. The insulation is stripped from the ends of each wire for about 5 mm. The table below lists the connections needed. Cut the wires as short as conveniently possible. In a few cases, indicated by * in the socket columns of the table, the wires are soldered to the terminals. The positive supply also goes to the off-board LEDs and LDRs. For neatness, this line and the connections returning from the components are best...

Other tools for electronics

A wire and cable stripper removes the insulation from the end of the connecting wire in a single action. It saves a lot of time. But most wire strippers are designed for use by electricians. They will strip the insulation from hefty mains cable, or TV antenna cables, but not from the thin wires such as we use in electronic hobby projects. Choose with care. Wire cutters of the side cutter type trim the component leads short after they have been soldered to the board or terminal. They give a neat...

Pic Io

For later reference, the table below lists I O connections to the PIC. A photocopy of this table mounted on card is handy to have on the workbench while assembling and testing For later reference, the table below lists I O connections to the PIC. A photocopy of this table mounted on card is handy to have on the workbench while assembling and testing The entries are grouped by I O port and list all the channels available on the PIC16F690. In the fourth column, the I or O indicates whether the...

Pic Io Stepper steering

For later reference, the table below lists I O connections to the PIC. A photocopy of this table mounted on card is handy to have on the workbench while assembling and testing the circuit modules. Reference voltage, Comparator 1(C1IN+) Forward light sensor, Comparator 1 (C12IN-) The entries are grouped by I O port and list all the channels available on the PIC16F690. In the fourth column, the I or O indicates whether the channel is to be configured as an input or an output. AnI is an analogue...

PIC Programming

Branching instructions 141 Mathematical operations 1S7 Steering a mobile robot 144 Random numbers 161 As you can see if you look at the programming examples of the projects, there are program routines that we use over and over again. Some may differ in detail but essentially they are repeats. It makes more sense to save these as separate text files, so that you can load them and put them into your current project. They may need a little editing here and there but this is nothing compared with...

PICs and robots

The robot projects in this book are based on the PIC16F690 microcontroller, made by Microchip Technology Inc. But all PICs have a common basic architecture and electrical properties so the circuits described in this book can usually be made to work with several other types of PIC. Programming a PIC wwwwwwwwwwwwwwwvwwwwwB The PIC16F690 is especially suitable for hobby robotics because It uses the latest nanoWatt Technology. The standby current is only 1 nA when operating on a 2 V supply. At the...

Pins and ports

The F690 version that we describe here has a 20-pin double-in-line package (opposite). Other packages are obtainable, such as surface-mount devices, for example. All pins except 1 and 20 are available for use as input output pins. Those of Ports A and B can be individually set to have built-in pull-ups when configured as inputs. Also, as inputs, they can be programmed to cause interrupts when the input signal changes. Certain of the pins, though usable for simple input or output, can be...

Programming

Unfortunately, their precision is low but they are fun to experiment with. The most practical solution is a gantry, described in the next section. A gantry robot operates over a clearly defined rectangular area. It picks up objects from any point in the area and sets them down at another point in the area. The tool (often a gripper) is suspended from a small trolley-like frame, and can be lowered and raised. The frame has wheels and runs on a pair of rails so that it can travel from one side of...

Programming a PIC

A controller operates according to a program. This is stored digitally in the controller's memory in the form of a code, called machine code. This code is very difficult to write by hand but, fortunately, a computer can help. Using special software, the program is typed in as a sequence of understandable instructions (or mnemonics) for the controller to execute. The software assembles the machine code from these instructions. A PIC (top centre) being programmed in a programming deck. This is...

Programming the gripper

The gripper is raised and lowered by the same mechanism as the hook, so the programming if up down actions is the same, including the feedback from the two limit switches. In addition, the gripper motor has to be controlled by on off and open close signals, and there is a limit switch that closes when the jaws close. One way of treating the programming is to make this an example of distributed processing. PIC1 controls the three winch motors and the sequencing of the operation. We use a second...

Pulley wheels

A pulley is a wheel with a grove around its rim, known as a race. Pulley wheels are mainly used for the transfer of force. In the Gantry, for example, they transfer the force of gravity to the chassis to pull it along the tracks when the winch unwinds. They are also used in the pulley system that raises and lowers the hook and some other tools. Another way in which force is transferred is by a belt drive between two pulleys. A pair of pulleys of equal diameter simply transfer force over a...

Scissors Paper Stone

For scissors, the hand is flat with the second and third fingers spread apart. For paper, the hand is flat with fingers together. For stone, the hand is clenched in a fist. On a given signal, the players swing their hands forward and upward to reveal their choice of scissors, paper or stone. If they have both chosen the same, the result is a draw but, if they have chosen differently, the winner is decided like this Scissors wins against paper because scissors cut paper. Paper wins against stone...

Seeking the light

In this program, the Scooter is set down in a room which has fairly subdued lighting. There is one brighter souce of light which may be either a table-lamp on the floor or (in daytime) a window with a low sill. The robot's task is to locate this source and to move toward it. The program is also an example of how to use the PIC's comparators. Before going on to the light-seeking program, here is a program intended for running while setting the variable resistor VR1 (p. 176). A diagnostic program...

Shopping list electronic

Ci polyester capacitor, 100 nf IC1 PIC16F690 20-way d.i.l. turned pin ic socket socket strip 2 x 12 sockets stripboard 17 strips x 12 holes Q1, Q3 BC639 npn transistor (2 off) Q2, Q4 BC640 pnp transistor (2 off) socket strip, 2, 3, and 6 sockets stripboard 8 strips x 21 holes VR1, VR2 horiz. trimmers 100K (2 off), optional socket strip, 3, 4, 5, and 8 sockets - D3 5 mm light emitting diodes, ultra bright (3 off) LDR1m LDR2 light dependent resistors (ORP12 or similar) S1 spst mini toggle switch...

Shopping list electronic 1

Ci polyester capacitor, ioon. C2 polyester capacitor, ion. 20-way d.i.l. turned pin socket. 2-way screw terminal. 0.9 mm PCB terminal pins (17 off). Stripboard 13 strips x 20 holes. Q1, Q3, Q5, Q7 BC639 npn transistor (4 off). Q2, Q4, Q6, Q8 BC640 pnp transistor (4 off). PCB plugs 4-way (2 off). 2-way screw terminal. Stripboard 16 strips x 21 holes. 53 miniature 3-pole, 4-way rotary switch. 0.9 mm PCB terminal pins (19 off). Stripboard 11 strips x 14 holes. R1 light dependent...

Shopping list electronic 2

IC sockets (14-pin 3 off, 16-pin 1 off). PL2, PL3 PCB plugs and sockets 4-way (2 off). VR1 miniature preset potentiometer, 470 k. 0.9 mm terminal pins (5 off). Stripboard 5 strips holes. LDR1 light dependent resistor (ORP12 or similar). UGN3503U Hall effect magnetic sensors (2 off). Laser pointer. Ferrite magnets 10 mm X 10mm X 4 mm (12 off or more). Battery holder, 8 x AAA or 8 x AA, with wire or stud terminals. Battery holder, 4 x AAA or 4 x AA, with wire or stud terminals. PP3 type...

Shopping list mechanical

Box, squarish, made of non-brittle plastic, possibly transparent. DC motor and gearbox with output shaft on both sides. Pair of wheels, with tyres, about 60 mm diam. Metal tubing to fit into wheels and fit over drive shaft of motor. Pulley wheel(s) about 25 mm diam for castor, with shaft about 40 mm long. Material for making castor wheel bearings. Nuts and bolts, mainly M3, bolts 6 mm and 10 mm long. The robot is controlled by a PIC16F690 microcontroller. Several other types of PIC could be...

Simulating the PIC

The software supplied with a programming deck usually includes its own assembler and, as already mentioned, may have a BASIC or C compiler built in to it. On the computer screen, type in the program (or part of it) using a text editor. This is usually supplied as part of the programming software, or use Notepad, which comes in the Windows package. Next comes the simulator. The simulator is another item which is provided with the programming software. It runs on the PC but behaves just like a...

Soldering tools

A soldering iron is an essential item. A soldering station with thermostatic control is nice to have but a simple electrically heated iron will do. The main points are that it should be low power, about 15 W, and the bit should be no more than 2 mm in diameter. If you have several models of iron to choose from, select the one with the above features and with a light-duty power lead. Some makes of iron are spoilt by having a heavy duty power lead capable of supplying a 1 kW device. The thick...

Song and Dance

A routine for producing a square-wave tone is described on pp. 150-155. This produces a single burst of sound at a given frequency and of a given duration. But before it can do this it needs three values to work on. It also needs editing to produce the sound signal at the specified pin. In the Android, the speaker is driven from Port B, channel RB5. Edit the listing to read portb instead of portc, trisb instead of trisc, and portb, 5 instead of portc, 0. To obtain the pitch of...

Stepper motor control board

This interfaces the controller with the stepper motor inputs and consists of four transistor switches. The schematic of one switch is on p. 99. The circuit board layout is below. This board is run on the same supply as the controller (6 V), or its supply could be at higher voltage if the motor needs it. Top to bottom A2, B2, B3, -, Al, -, Bl, A3 The stepper motor (M3) control board. The board is most conveniently located at the back right of the shelf, next to the controller board.

Stepper motors

As their name suggests, stepper motors turn step by step. The commonest type has a step size of 7.5 , so that it takes 24 steps to make one revolution. This produces a slightly jerky motion but it is satisfactory for most purposes and the programming is simple. This description refers to unipolar stepper motors which have permanent magnets and 7.5 steps. The motor generally has six wires, which are connected to the windings as shown in the drawing opposite. The two windings of the stepper motor...

Stepper steering

Alternatively, the off-board connections and the I O table for this are on pp. 232-234. For later reference, the table below lists I O connections to the PIC. A photocopy of this table mounted on card is handy to have on the workbench while assembling and testing the circuit modules. Reference voltage, Comparator 1(C1IN+) Forward light sensor, Comparator 1 (C12IN-) The entries are grouped by I O port and list all the channels available on the PIC16F690. In the fourth column, the I or O...

Varible speed control

The idea is that power is supplied to a motor as a stream of pulses. The pulses are at the full supply voltage (or the voltage available from an H-bridge) but the ratio between the length of a pulse and the interval between pulses can be varied by programming. The shorter the pulse and, therefore, the longer the interval, the lesser the power delivered to the motor and the slower it turns. This way of controlling speed is preferable to varying the voltage. It...

What sort

The first question is 'What sort of robot do we want to make '. When they hear the word 'robot', many people immediately think of the R2-D2 or the robots of the film I, Robot. These are robots similar to humans in some ways, but not in all. There are many kinds of robot, one major group being the mobile robots, sometimes called mobile platforms. Examples of mobile robots include the human-like robots mentioned above and a wide range that mimic animals. Some walk about on six legs, like insects,...

Software for programming

The most direct way of programming a PIC is first to write the program in assembler, using a simple text editing program such as Notepad. This, or something similar, is provided as part of the Windows package. The top photo opposite shows a screen-shot of an assembler listing in Notepad. When the file is saved, Notepad creates a file in text file format .txt . When asked for the file name to save it under, type the name with the extension '.asm' not '.txt', and not without an extension . It is...

The Intcon register

Pin Layout Pick 16f88

This register controls the processing of interrupts. The bits of interest are lt 7 gt GIE 1 interrupts enabled, 0 interrupts disabled. This bit is used to switch all interrupts on or off with a single command. lt 6 gt PEIE 1 enable peripheral interrupts, 0 disable these interrupts. lt 5 gt TOIE 1 enable timer TR0 overflow interrupts, 0 disable. lt 4 gt INT 1 enable INT interrupt, 0 disable. The INT interrupt is an external interrupt occurring when RA2 changes. The direction of change that...