

Controlling The Real World With Computers

::. Control And Embedded Systems .::

Updated August 12, 2016

Click HERE if you are here to download or check for updates of the free multiplication and color code software, then be sure to take a look at the tutorial below.

This site uses hands-on experiments to show the basics of how real things in the real world are controlled with computers. That means it's about most of the computers in the world. Most computers don't sit on desks, but are used to control things that don't look anything like a computer, such as cars (someone pointed out a car to me a while back that has 61 computers in it), planes (especially military fly-by-wire aircraft), factories, spacecraft, toys and appliances. This site provides the opportunity to learn basic control and embedded system concepts while taking advantage of the low cost and conveneince of using a PC as a platform. This site is for anyone who is the least bit curious about monitoring and controlling such things as motors, lights and switches, or recording and playing everything from sound to the arm position on a robot. It's for anyone who likes to learn by doing. You will not only read about controlling motors, lights and sound, you will control real motors, real lights, and really record and play information. It's for anyone who finds intriguing the prospect of controlling a robot or a toy or an appliance by means of a computer embedded in it or, for that matter, a whole factory or space station. It's for anyone who has done little with computers beyond clicking a mouse button, as well as the professional looking for source code. It's for anyone who wants to reach as far as the imagination will take them. This site is for teachers who would like to give their students some interesting, hands-on experience. It's for people who are considering a career change but don't want to suffer the high cost and time of a formal education before knowing for sure that this is the career they would actually look forward to every morning. It's for programmers who would like to know how to read schematics and construct hardware and hardware people who would like to know how to write programs to control their hardware. Please don't think electronics and programming have to be hard. Far from it. Read what others say about this site to get an idea of what the experience is like. Besides, it costs nothing but a little time to go through everything here (well, maybe more than just a little time unless you can read 240 pages really fast). It's not heavy reading, either. It's designed to be accessable by anyone with a knowledge of basic mathematics. You're ready if you can add subtract, multiply and divide. The earlier sections include self-tests that permit checking progress or skipping sections already understood. Please note that the printed circuit board kit mentioned in this site is no longer offered. It has not been offered for some time now. It's ISA and that and the computers that have ISA are out of date. To bring this site up to date, I have written alternate text, which uses an Arduino UNO, a small, inexpensive embedded microcontroller board for experimenters that can and is actually being used in real systems. It's The Arduino Version of the material. See The Arduino Version HERE I have, however, recently found three bare boards which I am offering for $30.00 plus $4.00 shipping, with payment to be made through PayPal (after you sign up): Please note that these boards are not populated and do not include parts. See the parts list Here and parts suppliers Here This offer will end when I have sold all three boards. And my Listening Car provides four channels with a combined DC power control capability up to a little over 1 horspower! The Arduino version of this site will show you how to use it and other power devices. See The Listening Car HERE I have also written free software to help you learn the resistor color code and software to help kids learn multiplication that you can download HERE. There are two versions of the multiplication software you can download, plus a manager that can be used by parents and teachers to help kids with the drill programs. The resistor color code application takes you from the very simple to the point where you can determine the values of resistors by their colors. Let me know what you think about anything on this site.. Much of the example code here is very useful in control and embedded systems, and it is still available in a zip on the order page. The tutorial examples will work on most operating systems that allow direct access to ports (more on ports later). Linux, DOS, Windows 3.x, Windows 95, Windows 98, and Windows Me will work, among others. To use Linux, follow the guidelines at the Linux I/O port programming mini-HOWTO. Direct port access is not permitted by NT, 2000, XP, Windows 7 and above, and some other operating systems. It's still possible to get at the ports however, by using special procedures that add a layer you can go through. Experienced programmers and brave beginners can look in Programmer's Heaven for information on gaining such access. The optional hardware needed to provide an interactive, hands-on experience is available as an inexpensive

Need a computer? Schools and non-profits can get free computers at one of the computer recycling sites. Else, try Ebay. Just be sure the computer you find has an ISA slot available. It might be necessary to email the seller to make sure. Even computers with slots taken up with things such as modems and sound cards can be used. They are not needed and can be removed to make room for the board used in this tutorial.

Some of the computers offered in Ebay have had their hard drives erased. No problem. I have seen DOS there for around $5 -- Ebay search for MS-DOS. Don't worry if you don't know how to use DOS. You will learn enough to get by. Of course there's no need to get DOS if the machine already has an operating system on it that will work.

Table Of Contents

Sections are always being added and/or updated. Please let me know if you would like to get update notices. Please Note: I NEVER release any email addresses!!

Click here to be removed from update notification.

You can also join the LEARN-C discussion group. It permits users of the tutorial and/or board to discuss experiences. There are two ways to join. Click here to subscribe by email, or here to go to the group site to subscribe.

Please let others know about this site. It's easy to do. Just click here to send an e-mail about this website to people on your list who might find the tutorial useful (which, of course, is everyone on your list). The subject and body of the email will already be entered, but you can modify them as you wish.

Data lines, bits, nibbles, bytes, words, binary and HEX

Passing information around in a computer and the hardware.

data lines

bits

nibbles

bytes

words

the numbering systems used in programming

Boolean Logic as it relates to programming as well as the hardware. How to figure out if it's on or off and how to turn it on and off.

Jump To The Self-Test For Boolean Logic AND

OR

NAND

NOR

XOR

NOT

and the C Language expressions used for the above and what happens when they are applied Address Lines and Ports

Using the hardware to make contact with the outside world.

Jump To The Self-Test For Address Lines and Ports Address Lines

Ports

IOR

IOW

AEN

Select Lines How To Read A Schematic

Just a few symbols and you've got it

Jump To The Self-Test For How To Read A Schematic the symbols for connected and unconnected wires

the symbols for power and ground connections

the symbol for switches

the symbol for resistors and the abbreviations showing their values

voltage, current and Ohm's Law

the symbol for capacitors and abbreviations for showing their values

the symbol for diodes

the symbols for integrated circuits, including digital ICs and operational amplifiers

the basic functioning of operational amplifiers The Hardware

Details about portions of the hardware not discussed in the experiments. Putting It All Together - Controlling The Hardware With The Software

The C language fundamentals comments

main()

functions

the concept of void

prototypes

variable declaration

compiler directives such as #include

for() loops

printf() Experiment 1 - Basic Switch Input Detection

Using a device on the board for digital input to get the status of switches. how to use inp()

the use of the #define directive

how to use if() statements

the difference between query and assignment operators

the concept of scope

how to use bit masking

how to use the switch() statement

how to use left and right shift operators

how to use while() loops

how to test functions Experiment 2 - Expanding Switch Input Capacity

Using the 8255 Programmable Peripheral Interface on the board to get an additional 8 inputs. how to set the three modes in the 8255

how to set the three ports as input and/or output

how to use Port B to detect the additional 8 inputs

more opportunities to work with inp(), if() statements, masking,

scope, while() loops, for() loops, falling through decisions,

static and automatic variables and how they can and cannot be used Experiment 3 - The General Purpose Digital Input/Output Module - Part 1

Using two ports of the 8255 PPI on the board to form a switch matrix. file scope and encapsulation, variable protection, testing and OOP

how to use enumerations

problem analysis and solution -- figuring out when to do what kinds of logic

the effect of passing arguments by value to a function

precedence and associativity

external directives

setting up the PPI with values declared in an enumeration so they will be more readable

basic pointers

compiling, linking and testing functions in another module

row driving and column testing in a matrix

combining three discrete inputs with the matrix to get 67 switch inputs

more on masking, shifting, etc.

the most important step in programming is not programming

connecting the headers to see if the thing works Experiment 4 - The Multiple Closure Problem And Basic Outputs With The PPI

More on the matrix, driving higher-current devices using the PPI on the board with current driver circuits. strobing

diode matrix

rail to rail swing

reverse and forward biasing

voltage drop considerations

silicon and germanium

solid state device input and output limitations

open collectors and sinking

electrical layouts vs programming considerations

using the logic suggestions from Experiment 3

avoiding unnecessary complexity

more on pointers and strings

pointer arithmetic and de-referencing

avoiding precedence problems

a new enumeration to achieve maximum flexibility

the contest

long integers

delay loops and problems using them

driving LEDs with the PPI

increasing current capability with a transistor

making it easier with an open collector inverter

replacing current limiting resistors with a zener

forming a loop to control output with input Experiment 5 - Controlling Motors

Powering higher-current devices using the PPI on the board. darlington transistor

rectifiers

magnets and electromagnets

basic ideas of motor operation

fingers, current, thumbs and North

movement from electricity, and electricity from movement

collapsing magnetic fields and back EMF

turning motors on and off with the PPI

duty cycle

Pulse Width Modulation speed control

using the PPI to control the speed of a motor

a little more on printf

casting Experiment 6 More Precise Control Of Motors

Using the digital I/O on the board with the computer's timer to control devices Greater efficiency through pointers

Structures struct keyword declaration vs instance dot referencing members

Arrays of pointers to structures "->" refererencing members sizeof(..) operator what pointers point to malloc(..) to get some memory, free(..) to free it

typdef

dynamic, multiple-point referencing of a single variable through pointers

interrupts, interrupt service routines, IRQ, ISR

interrupt vector or dispatch table

segment:offset format

the interrupt keyword

getvect(...) and setvect(...)

disable() and enable()

to be reentrant or not to be reentrant

floats and doubles

multiple-point, interrupt-driven pulse width modulation Experiment 7 - Bi-directional Control Of Motors And The H-Bridge

Using the digital I/O on the board with the computer's timer to provide bi-directional motor control H-Bridge basics

turning on the brakes

types of switches used

the MOSFET

enhancement mode

conductivity

the 555 timer/oscillator

RC time constants

logarithms

base e

high current drivers

voltage doublers

blocking capacitor

step response

gate capacitance

impedance and reactance

testing the circuits before connecting them to the computer

smaller h-bridges

the 754410

transistor inverter

voltage dividers for testing h-bridges

the L298

driving the hardware with the software

expanding the control structure

passing by value and through pointers

pointers to pointers Experiment 8 - Digital To Analog Conversion

Using the Digital to Analog Converters on the the board to produce sounds, etc. R 2R ladder

more on Op-Amps

virtual ground

resistor network analysis

port offsets

triangle waves

speaker output

sine waves

trig functions in C

radians

generating sine tables

FILE*, fopen(), fputs(), fprintf(), fflush(), fclose()

acos()

signal offset calculations

step size and distortion Experiment 9 - Analog To Digital Conversion

Using the 8-channel Analog To Digital Converter on the the board to record sound and other analog data. definition

only approximately proportional

numbers and steps

analog vs digital values

the ADC0809

comparator

successive approximation

flow charts

successive approximation example

the ADC clock

ripple counter

D flip-flop

Q and NOT Q

aliasing

decoding read and write select for the ADC0809

multiplexer

Address Latch Enable (ALE), ADC SELECT, BIOW and START

starting a conversion

ADC SELECT

End Of Conversion (EOC)

Output Enable (OE), ADC SELECT and BIOR

Auto port detect

recording and playing back voice

capturing analog information in the timer interrupt service routine

automatic, multiple channel analog to digital data acquisition Experiment 10 - Using Analog Inputs To Control Motors

Modifying the timer system to control PWM in proportion to inputs

from the 8-channel Analog To Digital Converter on the the board The TIP120 revisited

Determination of triggering levels and proportional values for setting up pulse widths from an analog input Experiment 11 - Using Analog Inputs For Bi-directional Control Of Motors

Modifying the timer system to control PWM in proportion to inputs

from the 8-channel Analog To Digital Converter on the the board.

A relay is used this time to control the direction of the motor. Questions, Answers And I Dunno

Questions that have been sent in and my often lame answers.

Have a question about something on the site? -- Email Q, A & I D.

Don't worry if English is not your first language. I'll work with you and we will figure it out together. It's also a good place to make suggestions about what the tutorial should toot -- too much too fast, not fast enough, not the right stuff, just right, etc.?

Let me know what you want and I'll try to provide it. A Special Page The Equilbrium Matrix A pattern recognition circuit designed to help the disabled. Please let anyone you know who might know someone who is working on human-machine interfaces, especially for the disabled. Drag this dot to your desktop to bookmark this site: Search this site powered by FreeFind

