Saturday, March 13, 2010
Keys to Successful Medical Practice Design
It was not regarded as appropriate to ask him to quote for the work in advance and I remember causing considerable offence on one occasion when I asked for a price in advance of preparing the conveyance work on my house sale and purchase.
In like manner, Hospitals and Medical Practices have only relatively recently had to take account of their patients as "Customers", where the customer experience is regarded as an important factor in their overall service.
One significant consequence of this has been an attention to the detail involved in the design of Hospitals and Surgeries which have developed and become much more "customer" focussed. New hospital developments have come to look more like a high class shopping mall and progressively the areas of patient interaction in hospitals and surgeries have endeavoured to become more friendly in appearance.
Much of this move has been really positive as it seeks to establish a more respectful and egalitarian approach between professional and patient/client.
The challenge for the Medical Practitioner or Hospital Developer in this current climate is how to both establish this ambiance within the design of any development, whether minor or more major, and also account for the future - for one thing is certain: change is here with us to stay.
Trends in all areas of business and the professions are developing. If someone develops symptoms then a search on the internet is quite likely to be the first port of call. Likewise with an anticipated purchase. It is an easy first stage to carry out some on line research.
Ultimately, however, if the symptoms dictate, or the purchase need is there, there comes a time when there is no substitute for consulting a professional.
Having an understanding of current and future trends, knowing the detail of building construction, realising the needs of practical and ergonomic working practices, a feel for aesthetics, colour, shape and design are all essential elements of any development plan for Hospital or Medical Practice
Ultimately the only way to achieve the right result rather than end up with a mis-diagnosis is to deal with a professional. What is needful is to retain the services of an experienced and qualified designer who understands the needs from all angles, who accounts for customer experience and ergonomic demands. Who knows about colour, shape, lighting, furnishings such as seating, desking, treatment room requirements, building regulations and all the "professional" understandings that come with the experience of dealing with the needs of the "professional" services.
Ken Rand has 34 years of experience in designing and fitting interiors of Healthcare, Education, Retail and Commercial premises. Visit http://www.kenrandfurniture.co.uk/medical%20/7 to see something of the range of furniture they offer or contact him through http://www.kenrand.co.uk for design advice.
Article Source: http://EzineArticles.com/?expert=Ken_Rand
How DC Micromotors Are Powering Advances in Medical Technology
The ability to manufacture tools for complicated surgeries required high precision, miniaturized components. In particular, delivering power to these tools has been revolutionized with the use of DC micromotors.
For a particular example of how DC micromotors are advancing medical technology, take the automated cannula, a handheld device that can take tissue biopsies for cancer detection.
Technology Is Changing Medicine
Biopsies used to be a relatively invasive procedure performed by a surgeon. Incisions large enough to accommodate a surgeon's hand would be made in order to harvest a sample. Now, a cannula can take a series of samples with one single incision no larger than two centimeters and is programmed to be used in the hands of a technician rather than using the limited time of a skilled surgeon. This type of advance is vital to improving medicine for both the patient's care while lowering costs in one of the most expensive healthcare systems worldwide.
The Nuts And Bolts
The ingenuity in this technology is the driver unit. The automated unit is capable of taking samples and moving the probe along three degrees of freedom, doing this all within a two centimeter space while delivering the necessary torque to cut through tissue.
Brushed DC motors were utilized to provide the necessary torque. The use of brushed DC motors enabled the device to generate enough power for all of the cannula functions without compromising the strict size requirement. A compact planetary gearhead connected the power delivery to the cannula head, allowing the probe to rotate the cutter, rotate the outer disposable chamber, and move the cutter down the axis of the probe. The unique design of a planetary gearhead enabled all of these movement patterns to be performed in a miniature package.
Finally, a microcontroller is integrated into the entire system to allow a total programmable, automated sampling process. This flexibility allows the unit to perform any required task and to be adaptable to changing medical practice without undergoing obsolescence. Combined with the miniaturized brushed DC motors and planetary gearhead, this cannula will be able to automate procedures for hospitals.
The tools for automated tissue sampling and biopsies is just one application of how DC micromotors are helping the medical field employ smaller, more powerful tools to compliment their daily operations. These advances are vital to reforming the healthcare system in order to provide care at lower costs and with fewer risks without compromising quality. In the end, patients are the ones who enjoy the end benefits, such as lowered costs, faster recovery times, and fewer complications, of medical technology.
Chris Harmen is an author for MicroMo Medical Solutions, the leading medical industry partner providing DC micromotors and high precision components.
Article Source: http://EzineArticles.com/?expert=Chris_A._Harmen
How Robotic Medical Solutions Can Automate Surgical Procedures
Any surgical device or tool needs to have certain qualities in order to be useful in the medical field. They need to deliver a high degree of precision and accuracy while being lightweight and minimally invasive. Robotic medical tools also need to deliver power in a very compact frame and be able to respond to the environment in which they are working. Hence, these devices require compact, high torque motors to perform operations and servo motors to create a feedback loop to ensure reliability and accuracy.
Case Study - Automated Lung Biopsy
Lung biopsies are performed to sample lung tissue to test for diseases such as lung cancer. The typical procedure calls for a physician to use a CT scanner to manually guide a needle into the lungs. The physician takes a scan and then adjusts the position of the needle. These steps are repeated up to 10 times until the needle is in its proper place and a sample can be taken. This is a long and uncomfortable process for a patient under light anesthesia.
A newly developed robotic sampling device is able to utilize a smaller series of scans and adjustments, typically only four, to automate and accelerate the process. A radiologist can perform this procedure by remote control and reduce the number of total scans, ultimately decreasing the exposure to both the patient and doctor.
System Design
In order to have an automated biopsy robot, many stringent design specifications had to be met. The key to the system is a set of four servo motors that orient the needle, power a pinion drive, and a final motor to rotate the passive roller. Each high torque motor provides a 10 Newton piercing force within a 10 millimeter sized motor coupled to a minuscule 10 millimeter gearbox.
Clearly, delivering a high torque motor that can meet such extreme size restrictions is a breakthrough in servo motor technology. The entire unit is designed to sit on a patient's chest, so the entire device is extremely lightweight. The servo motors combine with a microcontroller to create a feedback system that allows an efficient harvesting process that cuts down on procedure time and patient discomfort.
In the highly complex and technical healthcare field, medical solutions often require serious engineering capabilities. Miniaturized, high torque motors have provided automated tools to facilitate delicate procedures. Saving time and reducing costs while improving patient care is the ultimate goal of any medical solution and is the best way to improve the current ailing healthcare system. The application of high precision components to assist the medical expertise of doctors will continue revolutionize how patients are treated.
Chris Harmen is an author for MicroMo Medical Solutions, the leading medical industry partner providing servo motors and high precision components.
Article Source: http://EzineArticles.com/?expert=Chris_A._Harmen
Tuesday, October 6, 2009
Choosing a Programming Language for Your Microcontroller
Assembler
Assembler is the most obvious language that you'll consider using as you probably won't need to buy any other tools to use it. More than likely the manufacturer will provide an assembler for the chip and you won't need any books as all the instructions are in the datasheet and you just start coding.
This route to programming is very easy but you may be setting yourself up for problems later on as:
- It is trivial to write short programs.
- It becomes progressively more difficult to write large programs.
- It seems to be the best option as it gives the fastest code.
- It seems to be the best option as it gives the smallest code.
Assembler: Fast & small code
There is no doubt that assembler gives the fastest and most optimized code (your brain is better at optimization than any compiler!) but assembler is difficult – typically you'll spend ten times as long writing assembler as you would writing in a high level language.
Assembler / Compiler Trade off
This is the trade off; to write the fastest most optimized code or to get the task solved more quickly.
Another problem with assembler is that to do even the most trivial task you have to think about every aspect of the code and all implications on registers and register flags.
Even making a microcontroller perform the most trivial task is difficult e.g. for making a loop in assembler you need to think about which register to use and which instructions all the while thinking about how those registers should not interact with the loop register/other registers etc.
Assembler: Problem - changing the target
Another difficulty is when you change from one microcontroller to another (even in the same device family) the assembler instructions may be changed e.g. more instructions to improve microcontroller performance. So you will have to learn an entirely different instruction set when moving either to a new target microcontroller or moving to a different device within the same family i.e. code re-use is not possible unless you stay with one microcontroller (or devices with a similar internal architecture).
High level languages
HLL: Retarget
Retargeting code to another microcontroller is easier since the HLL will know the details of the new target i.e. instruction set, fuses etc. All you need to worry about is the specific differences between the different microcontrollers (in the same family this will be setting up the internal peripherals).
The important point is that the HLL takes care of the assembler code needed to do the job.
HLL: Easy to understand.
The most useful aspect of a high level language (HLL) is that the language is written in a form you can easily understand – there are no cryptic assembler commands that you have to remember and most commands are made up of several machine code instructions – saving you coding effort (often there are built in libraries of code e.g. LCD driver, Serial port driver, I2C driver etc
So the HLL makes it easy to write code as it generates the correct assembler for the target microcontroller.
HLL : Whitespace
You can also make use of white space (areas of no code) to separate out the various operations within the program – typically assembler code is just one great big list that is really very difficult to read – I know there are comments but you need to comment almost every line so that someone else can
understand the code.
HLL: Task splitting
One of the best features of a HLL is that you can split tasks into separate functions that you can concentrate on them individually (as the HLL takes care of local variables etc.). For assembler even when using a call instruction you have to take care of preserving the register state – in the HLL it's all done
for you.
HLL: Code re-use
Once you learn the HLL you will find it easy to read code written by other people and you will be able to re-use code that you have already written whereas with assembler you will constantly need to analyze the code to see if it fits in with your new functions.
The only decision then is which high level language? There are really three contenders BASIC, C and Pascal – these are the most popular languages and for popular microcontrollers there will be an HLL compiler for each one. I'll just list the advantages and disadvantages of each
BASIC Advantages
- Very easy to learn and use.
- A BASIC compiler will produce code that runs fast as a C compiler.
- Many in built functions (depending on compiler).
- Very popular – large user base with many example programs.
BASIC Disadvantages
- Non standard language.
- If using an interpreted HLL will run very slowly.
Note: Because the language is not standardized it will be difficult to move code to a new processor target type.
Pascal Advantages
- Easy to learn and use.
- A Pascal compiler will produce code that runs fast as a C compiler.
- Many in built functions (depending on compiler).
Pascal Disadvantages
- Not as popular as C – so not as many compilers.
- A bit wordy – it was originally intended as a teaching language.
- Not as flexible as C.
C Advantages
- Compiled language - always runs fast.
- Standardized language (ANSI)- easier to port to different compilers / target devices.
- Many compilers available.
- Many in built functions (depending on compiler).
- Very popular – large user base with many example programs.
- Used in many different industries.
- Usable at the hardware level as well as higher abstraction levels (although C++ is better for very abstracted programming models).
C Disadvantages
- Hard to learn at first.
- Strong type checking means you spend time pleasing the compiler (although this protects you from making errors).
You can find more information from the website here and how to build a website like it here.
Copyright © John Main 2006 Free to distribute if the article is kept complete. http://www.best-microcontroller-projects.com Article Source: http://EzineArticles.com/?expert=John_Main |
PIC Micro Hardware Programming Methods
There are three ways to program a PIC microcontroller
- Using normal programming hardware (high volt programming HVP).
- Low volt programming (LVP).
- Bootloading.
The first two methods use the programming port of the PIC microcontroller labeled ICSP (In Circuit Serial Programming).
This port is shared between the existing pins of the microcontroller and after programming the pins revert back to normal microcontroller operation.
Note: To make ICSP work correctly you have to consider the effects and requirements of the ICSP programmer e.g. for HVP a high voltage exists at the Vpp pin (your circuit must be able to handle the high voltage - up to 13V). Also the loading for the other signals PGC and PGD must not be too high i.e. don't put an LED on these pins that uses 20mA - if you did the voltage levels would not be high enough at the inputs to the PIC for programming.
It's fairly easy to design for ICSP use by using isolation resistors to normal circuitry and choosing not to use heavy loads on these pins.
ICSP provides 6 connections from the pic ICSP programmer to your board as follows :
VPP - (or MCLRn) Programming voltage (usually 13V).
Vcc - Power (usually 5V).
GND Ground (zero volts).
PGD - Data usual port and connection RB7.
PGC - Clock usual port and connection RB6.
PGM - LVP enable usual port and connection RB3/RB4.
PIC Micro: High Volt Programming
To use the first method a hardware interface is needed or 'PIC programmer' to interface between the programming software (usually running on the PC) and the PIC chip. This hardware takes its information from the PC via one of three interfaces either:
- The RS232 COM port
- The Parallel port
- The USB port
You choose the interface you want to use and then choose an appropriate PIC programmer. The PC then communicates with the hardware generating the serial (ICSP) signals to translate the PIC hex file into a serial data stream suitable for the target microcontroller.
Note: Almost all PIC microcontrollers use the ICSP interface so once you have a HVP you can program virtually any PIC microcontroller. e.g. you can program 12F675, 16F84, 16F88, 16F877(A), 18F2550, 18F452 etc.
There are several programs for programming PIC micos e.g. ICPROG and many different hardware programmers.
PIC Micro: Low volt programming (LVP)
LVP is exactly the same as HVP except:
- The Vpp voltage is set to the normal supply voltage.
- The PGM pin indicates programming mode.
Note: In this mode you can not use the PGM pin for anything else it is dedicated solely to LVP control.
Devices are manufactured with PGM mode enabled and the only way to turn off the PGM mode is to program it using an HVP programmer.
Note: Some PIC microcontrollers can only use the HVP method since for the LVP method you have to sacrifice one pin - PGM - (to tell the PIC Micro either that it is being programmed (high volts e.g. 5V) or that it is not being programmed (0V) ) and some PIC micros only have 8 pins e.g. 12F675. For this chip the PGM pin is not available so HVP is the only way.
The real benefit of using the LVP mode is that you can program several PIC Micros on a board without having to individually program each one - you could daisy chain each extra micro to a master micro which would then program each one in turn - and this is only possible since the Vpp signal is a normal logic level in LVP mode.
PIC Micro: Bootloading
Bootloading uses any available interface to load a program into program memory. It requires a bootstrap program to interpret the interface data and translate it into program memory instructions.
Note: Note only the newer devices that are capable of programming their own memory can use this method.
Typically a serial port is used for bootloading and the PIC micro bootstrap program will wait for a set time after power up listening on the serial port for a reserved word that tells the bootstrap program to start i.e. it listens for sequence of characters that is not normally used on the interface
Once it receives this sequence it enters bootstrap mode where a hex file is transmitted to the microcontroller over the interface. It interprets this and programs the memory of the microcontroller and then starts the program.
There are two issues with this method:
- You have to program the bootstrap code using HVP or LVP.
- It uses up some of the microcontroller resources.
Once programed it provides a convenient way of using the device as you won't need programming hardware anymore and one major benefit is that you can re-program a device without undoing the equipment e.g. if you boxed up you project you could still re-program it using the serial port!
You can find more information from the website here and how to build a website like it here.
Copyright © John Main 2006 Free to distribute if the article is kept complete.
http://www.best-microcontroller-projects.com
Article Source: http://EzineArticles.com/?expert=John_Main
Sunday, September 6, 2009
The 12F675 - A PIC Microcontroller Project Guide
The 12F675 is one of the smallest PIC Microcontrollers - it's a tiny device with 8 pins but it's packed with peripherals and it even has a built in 10bit ADC which can read analogue inputs from 4 pins.
It has the following internal peripherals:
1. Two timers.
2. An analogue comparator.
3. 10 bit ADC.
It also has an internal oscillator and internal reset circuit. This means the device uses minimal external components to make it work (other devices require an external crystal oscillator). Of course it also has the usual internal programming memory, EEPROM and RAM needed for programming.
Ideas for projects:
1. 4 channel volt meter.
2. Multi channel Servo controller.
3. Temperature controller.
4. Inductance meter.
5. Touch lamp.
6. Courtesy light time delay.
Note: To get data out of the device you can implement a serial RS232 transmit interface to your PC.
Why use it?
One reason is that because of its size its easy to put into restricted spaces e.g. for a model aircraft or model trains and it's cheaper than the larger devices.
Note: The 12F629 is the same device without the ADC - so it's even more cost effective.
So it's useful in designs that you would not normally think of using a microcontroller for instance you could make a touch lamp dimmer - Note using the microcontroller means you can make far better functionality than using discrete hardware (and even change its programming later on).
With a lamp dimmer you could have an auto off delay function e.g. if no activity for an hour then turn off.
State machines
You could also implement a state machine for more complex control of the functionality e.g. pressing once moves to the next dimming level in the current direction while press and hold changes the dimming direction.
Using a state machine while not trivial lets you control complex operation which you could not achieve (without a great deal of effort) using discrete hardware - and the advantage of using the microcontroller is that if you get it wrong you just re code your software and test it again.
Note: The 12F675 and 12F629 use Flash programming memory i.e. they are re-programmable - you can change their functionality instantaneously with NO re-wiring.
The only problems are:
1. You need to program the device.
2. You need a programming language.
Programming the Device
Surprisingly you can program the device using the standard 4 pin PIC serial interface - ICSP (In Circuit Serial Programming) and with careful design you can even connect your programmer to the same pins that your circuit uses.
Programming language
The programming language normally recommended is assembler and there are good reasons for using assembler - e.g. very fast code and smaller final code size but I would recommend using a high level language such as Basic or C
This is because for assembler you need to work at such a low level that you spend a lot of effort to do trivial tasks and this is better left to the high level language.
For the example mentioned setting up and maintaining a state machine would be extremely difficult in assembler but much easier in C.
Some of the 12F675 projects are available here:12F675 Projects
John Main's website http://www.best-microcontroller-projects.com provides microcontroller resources and free projects which are fully documented including schematics and source code.
Article Source: http://EzineArticles.com/?expert=John_Main
Thursday, August 6, 2009
Interfacing a Microcontroller With a PC Using RS232 and the PC Serial Port
Serial Communication
Serial communication is a technique of transmitting data between two pieces of hardware. The smallest piece of data that is transmitted is the byte. A byte is made up of 8 bits. When data is transmitted between two pieces of hardware, the bits are sent one at a time. The hardware sends these bits by sending varying voltages across the wires connecting the devices. The sender and the receiver agree on how often a bit (or voltage level) will be sent.
How often a bit will be sent is referred to as baud rate or bits per second (bps). Then with the help of very precise clocks they can send a series of voltage levels between each other and then reassmble these voltage levels into bytes.
The Problem Communicating Between a PC and a Microcontroller
The RS232 serial port on a PC uses +3 to +25 volts to signify a logic level of 0, and -3 to -25 volts to signify a logic level of 1.
Most microcontrollers use TTL / CMOS logic levels which use 0 to some threshold voltage to signify a logic level of 0, and some threshold voltage to 5 volts to signify a logic level of 1.
In order for the PC and a microcontroller to successfully communicate some logic level translation is necessary.
Using a TTL / CMOS To RS232 Converter
There are many companies that manufacture modules that take care of the required logic level translation. The TTL / CMOS To RS232 Converter is one such module. Typically, these modules connect to the RS232 port on the PC and connect to the microcontroller's transmit and receive pins. Supply 5 volts and ground and you are ready to communicate.
Applications Ideas
Once you have your microcontroller communicating with your PC it opens up all kinds of possible applications ranging from data loggers, pc based oscilloscopes, controlling your pc from your microcontroller, controlling your microcontroller from your pc, etc.
For more information please visit http://www.m5controlsystems.com
Article Source: http://EzineArticles.com/?expert=Sidney_Kantor
Monday, July 6, 2009
Choosing a Microcontroller
Gone are the days when there were less than a handful of micro controller's to choose from. The fact is, choosing a controller for a new product is quite a daunting task and is way beyond the scope of this article, but will be covered in more detail in a future article.
However choosing a microcontroller to 'play with' for your first project, is a little easier and the tools (both hardware and software?) these days, are extremely cheap, if not, free!....
In the past, emulators, programmers etc use to cost thousands of dollars (what were they thinking?). Now it is possible to get very low cost development tools.
10 years back I chose to go with Microchip. Why?, well the fact that they provided not only a free development environment (MPLAB IDE), but also tons of support through the forums and application notes on their website.
At that time my simple project was essentially an electronic switch. So starting withsuch a simple task, almost any micro would do the job.
I picked one of their low end PIC12xxx series of micro's. These little babies had around 512 bytes of OTP (One Time Programmable) ROM and around 25 bytes of RAM! (can it run WinXP?...I don't think so!!!). This was plenty for what I had in mind though.
Today there are many more vendors (TI, Atmel etc) which provide similar devices and excellent support too.
One of the relatively new 'players' that stand out from the crowd, is Cypress' mixed signal PSoC series of micro controllers. These devices are extremely flexible from the point of view of re configurable hardware. The other big plus with these devices is the capability, using their free tool (PSoC Designer now incorporating PSoC Express) to program their micro controllers without writing a single piece of code!...more on these in another article.
So if you are just getting started in this fascinating area, keep it simple and start with a lower end micro. Most of the vendors provide samples for free from their websites listed below.
- TI - Texas Instruments
- Microchip Inc
- Cypress
There are many many more, but these have been the main players I have been interested in.
If you have any good micro controller recommendations or related, please leave a comment.
Cheers.
Dale is a design expert in the field of electronics and imparts over 20 years of knowledge gained from 'hands on' experience in the industry. Find articles like this and more at his respectful site online at http://www.allthingsembedded.com
Article Source: http://EzineArticles.com/?expert=Dale_Gomes
Saturday, June 6, 2009
Microcontrollers give you a fantastic way of creating projects.
Microcontrollers give you a
fantastic way of creating projects.
A PIC microcontroller is a processor with built in memory and RAM and you can use it to control your projects (or build projects around it). So it saves you building a circuit that has separate external RAM, ROM and peripheral chips.What this really means for you is that you have a very powerful device that has many useful built in modules e.g.
|
Even with just these four modules (note these are just example modules - there are more) you can make up many projects e.g.:
* Frequency counter - using the internal timers and reporting through UART (RS232) or output to LCD.
* Capacitance meter - analogue comparator oscillator.
* Event timer - using internal timers.
* Event data logger -capturing analogue data using an internal ADC and using the internal EEPROM for storing data (using an external I2C for high data storage capacity.
* Servo controller (Control through UART) - using the internal PWM module or using a software created PWM.
The PIC Micro is one of the most popular microcontrollers and in case you were wondering the difference between a microprocessor and a microcontroller is that a microcontroller has an internal bus with in built memory and peripherals.
In fact the 8 pin (DIL) version of the 12F675 has an amazing number of internal peripherals. These are:
- Two timers.
- One 10bit ADC with 4 selectable inputs.
- An internal oscillator (or you can use an external crystal).
- An analogue comparator.
- 1024 words of program memory.
- 64 Bytes of RAM.
- 128 Bytes of EEPROM memory.
- External interrupt (as well as interrupts from internal peripherals).
- External crystal can go up to 20MHz.
- ICSP : PIC standard programming interface.
Features
Programming
One of the most useful features of a PIC microcontroller is that you can re-program them as they use flash memory (if you choose a part with an F in the part number e.g. 12F675 not 12C509). You can also use the ICSP serial interface built into each PIC Microcontroller for programming and even do programming while it's still plugged into the circuit!You can either program a PIC microcontroller using assembler or a high level language and I recommend using a high level language such as C as it is much easier to use (after an initial learning curve). Once you have learned the high level language you are not forced to use the same processor e.g. you could go to an AVR or Dallas microcontroller and still use the same high level language.
Input / Output - I/O
A PIC Microcontroller can control outputs and react to inputs e.g. you could drive a relay or read input buttons.With the larger devices it's possible to drive LCDs or seven segment displays with very few control lines as all the work is done inside the PIC Micro.
Comparing a frequency counter to discrete web designs you'll find two or three chips for the microcontroller design and ten or more for a discrete design. So using them saves prototype design effort as you can use built in peripherals to take care of lots of the circuit operation.
Many now have a built in ADC so you can read analogue signal levels so you don't need to add an external devices e.g. you can read an LM35 temperature sensor directly with no interface logic.
Peripherals
At the end is a short summary of the main devices used in projects shown on this site.
The best way to start is to learn about the main features of a chip and then begin to use each peripheral in a project. I think learning by doing is the best way.
| PIC microcontroller Feature | PIC microcontroller feature description |
| Flash memory | Re-programmable program storage. |
| RAM | Memory storage for variables. |
| EEPROM | Long term stable memory : Electrically Erasable Programmable Read Only Memory. |
| I/O ports | High current Input/Output ports (with pin direction change). |
| Timers/Counters | Typically 3. |
| USART | Built in RS232 protocol (only needs level translator chip). |
| CCP | Capture/Compare/PWM module. |
| SSP | I2C and SPI Interfaces. |
| Comparator | An analogue comparator and internal voltage reference. |
| ADC | Analogue to digital converter. |
| PSP | Parallel Slave Port (for 8 bit microprocessor systems). |
| LCD | LCD interface. |
| Special features | ICSP,WDT,BOR,POR,PWRT,OST,SLEEP |
| ICSP | Simple programming using In Circuit Serial Programming. |
(some chips have all of these and some don't).
Flash memory
Devices used in projects on this site can be re-programmed up to 100,000 times (probably more) as they use Flash memory - these have the letter F in the part name. You can get cheaper (OTP) devices but these are One-Time-Programmable; once programmed you can't program it again!
ICSP
You can re-program the device while it's still in the circuit so once your programmer is setup you can leave it on the bench and test your programs without moving the chip around and it makes the whole process much easier.
I/O Ports
Pin direction
Most PIC microcontroller pins can be set as an input or and output and this can be done on the fly e.g. for a dallas 1 wire system a pin can be written to generate data and read at a later stage. The TRIS register controls the I/O direction and setting a bit in this register to zero sets the pin as output while setting it as one sets the pin as input.This allows you to use a pin for multiple operations e.g. the Real Time clock project uses RA0, the first pin of PORTA, to output data to a seven segment display and at a later point in the program read the analogue value as an input.
Current
The PIC I/O ports are high current ports capable of directly driving LEDs (up to 25ma output current) - the total current allowed usually ~200mA this is often for the whole chip (or specified for several ports combined together).Timer / Counters
Each PIC microcontroller has up to three timers that you can either use as a timer or a counter (Timer 1 & 2) or a baud clock (Timer 2).Timer 0
It is an 8 bit timer with an 8 bit prescaler that can be driven from an internal (Fosc/4) or external clock. It generates an interrupt on overflow when the count goes from 255 to zero.
Timer 0 always synchronizes the input clock (when using external clock).
Note: You can read and write timer 0 but you can not read the prescaler.
Note: The prescaler changes its effect depending on whether it is a timer prescaler or a watch dog prescaler - so the same prescaler setting may prescale by 2 or by 1 depending on its use!
Timer 1
This is a 16 bit timer that generates an overflow interrupt when it goes from 65535 to zero. It has an 8 bit programmable prescaler and you can drive it from the internal clock (Fosc/4) or an external pin.To eliminate false triggering it also has an optional input synchronizer for external pin input.
This timer can be used in sleep mode and will generate a wakeup interrupt on overflow.
Timer 1 is also read by the CCP module to capture an event time.
Note: Using this timer in sleep mode will use more current.
Timer 2
This is an 8 bit timer with an 8 bit prescaler and an 8 bit postscaler. It takes its input only from the internal oscillator (Fosc/4).This timer is used for the timebase of a PWM when PWM is active and it can be software selected by the SSP module as a baud clock.
USART
The USART is a useful module and saves having to code up a software version so it saves valuable program memory. You can find more information on RS232 here and how to make it work. Look here for pin outs.All you need to interface it to a PC serial port is a MAX232 chip (or equivalent).
Note: An equivalent MAX232 chip is the SP202ECP that has the same pinout as the MAX232 but lets you use 100nF capacitors - so you don't need the large 1uF caps.
Baud Rates
You have to be careful using the baud rates as they depend on the main clock in use and normal oscillator values in general do not fit very well with 'real' baud rates.CCP
The Capture/Compare/PWM module has three modes of operation:- Capture - Capture the time of an event.
- Compare - Generate an output when Timer 1 reaches a value.
- PWM - Pulse Width Modulation.
Capture
Capture mode is used to capture the value of Timer 1 when a signal at the CCP pin goes high (or low depending on how the CCP is set up). The CCP can accurately capture the arrival time of a signal at the CCP pin so it can be used for pulse time measurement.Compare
Compare mode is used to generate an output when Timer 1 reaches a value you put into CCPR1. One special event trigger mode lets you start the ADC when the compare mode triggers.PWM
PWM gives you one Pulse Width Modulation output with 10 bit resolution and with no software overhead - once started it operates all by itself unless you want to change the duty cycle.It uses Timer 2 to define its operation using Timer 2 period register to define the frequency of the PWM.
Note: The duty cycle is not a percentage it is the number of periods of the PWM clock that the output is high!
SSP
SPI and I2C are shared so you can only use one at a time (or you could use the I2C bit banged routines in the Real Time Clock project to have both at the same time).
You can find a project that uses I2C here and you can find more information on I2C here.
Comparator and comparator voltage reference
The comparator is module that has two analogue comparators which can be set up in one of 8 different ways. Either digital or analogue inputs can be compared to reference voltages.In one mode an internally generated voltage reference is used as an input to both comparators and in the same mode multiplexing lets you monitor up to four different input pins.
You can even send the output of the comparator to a pin so that it is used independently from the microcontroller e.g. in a circuit where you need a comparator you don't need an extra chip!
The analogue level must be between Vdd and Vss as protection diodes won't allow anything else.
The module will generate an interrupt if the comparator output changes.
You can use it in sleep mode and the interrupt will wake it up.
The source impedance of the analogue signal must be smaller than 10k.
ADC
The single 10 bit Analogue to Digital Converter can have up to 8 inputs for a device multiplexed from input pins.The ADC can be used during sleep but you have to use the RC clock mode. One benefit of this is that there will be no digital switching noise so you will get better conversion accuracy.
The 16F675 can measure 4 analogue input pins!
PSP
The Parallel Slave Port lets you to connect the PIC microcontroller directly into a microprocessor system. It provides an 8 bit read/write data bus and RD (read) WR (write) and CS (chip select) inputs - all active low.This provides an easy route to adding a PIC microcontroller to an 8 bit system that already exists.
LCD
Special Features
| ICSP | In Circuit Serial Programming | click here (jumps to ICSP section). |
| WDT | Watch dog timer | This is a software error protector. |
| BOR | Brown Out reset | This detects if the power supply dips slightly and resets the device if so. |
| POR | Power on reset | This starts microcontroller initialization. |
| PWRT | PoWeR up Time | A time delay to let Vdd rise. |
| OST | Oscillator start up timer | Wait for 1024 cycles after PWRT. |
| SLEEP | PIC microcontroller sleep mode | Enter low power mode. |
WDT
If your software goes haywire then this timer resets the processor. To stop the reset the well behaved software must periodically issue the CLRWDT instruction to stop a resert. The WDT runs using its own oscillator. It runs during sleep and shares Timer 0 prescaler.POR
Power On Reset starts PIC microcontroller initialization when it detects a rising edge on MCLR.PWRT
If you enable this then 72ms after a POR the PIC microcontroller is started.OST
Oscillator Startup Timer delays for 1024 oscillator cycles after PWRT (if PWRT is enabled) ensuring that the oscillator has started and is stable. It is automatic and only used for crystal oscillator modes and is active after POR or wake from sleep.SLEEP
Sleep mode (or low power consumption mode) is entered by executing the 'SLEEP' command. The device can wake from sleep caused by an external reset, Watch Dog Timer timeout, INT pin RB port change or peripheral interrupt.Project device overview
The other microchip devices are all useful in different situations - perhaps they have more memory or different peripherals - this is useful if you want to tailor your designs to the system you build - but probably more useful in a commercial environment where every cent counts in a production run.
All three devices are extremely powerful and the main difference is that they have different numbers of pins and memory size.
Note: There are differences in using the devices i.e. there are some registers that are different but in the generally you can interchange them - this is made easier using a high level language.
The devices used in this site are:
| PIC microcontroller Device | PIC microcontroller No. Pins | PIC microcontroller Flash memory WORDS |
| 12F675 | 8 | 1k |
| 16F88 | 18 | 4k |
| 16F877A | 40 | 8k |
(Note: that all of them have the letter F in - this means it is a Flash re-programmable part - don't go and buy a part with O in as its OTP - programmable only once! - only do that if you are really really sure it's the final design).
PIC Microcontroller Flash Memory size
You may think that 1k or even 8k is so tiny that it won't be useful but each PIC microcontroller uses RISC (Reduced Instruction Set Computing) which simply means that it has a cleverly arranged instruction set that only has a few instructions. The mid range parts have 35 instructions.If you use the high level language as recommended in this site then you won't need to be too aware of the instruction set it just means you can do a lot with a small amount of memory. Most of the projects on this site although they are fully working projects fit within 2k words!
Note: If you need more memory you can always move to the 18F series of PIC microcontrollers. Another option is to add an I2C serial eprom.
PIC microcontroller RAM and EEPROM size
Note: You can usually alter the program to use less RAM by choosing the right variable sizes or changing how your program works
For example don't use floating point alter it to use a different variable type e.g. you can use long integers with fixed point operation to avoid floating point.
PIC microcontroller EEROM : Electrically Erasable ROM is used to store data that must be saved between power up and power down.
This area is readable and writable and has a much longer life than the main program store i.e. it has been designed for more frequent use.
Building a Digital Thermometer
Now that you understand a little bit about your Stamp and the LCD, we can add another component and create a digital thermometer. To create a thermometer, we will use a chip called the DS1620. This chip contains:
- A temperature-sensing device
- An analog-to-digital (A/D) converter for the temperature-sensing device
- A shift register to read the data out of the A/D converter
- A little EEPROM (electrically erasable programmable read-only memory) to remember settings
The DS1620 has two modes: In one mode, it acts as a stand-alone thermostat chip, and in the other mode you hook it up to a computer and use it as a thermometer. The EEPROM remembers the current mode as well as the set temperatures for the thermostat.
Hooking up the DS1620 to the Stamp is very easy. The DS1620 comes in an 8-pin chip. Supply +5 volts from the Stamp to pin 8 of the DS1620. Supply ground to pin 4 of the DS1620. You then use three I/O pins from the Stamp to drive three pins on the DS1620:
- Pin 1 on the DS1620 is the data pin. You read and write data bits on this pin.
- Pin 2 on the DS1620 is the clock pin. You clock data in and out of the shift register with this pin.
- Pin 3 on the DS1620 is the reset/select pin. You set pin 3 high to select the chip and communicate with it.
- The data pin goes to I/O pin 2 on the Stamp.
- The clock pin goes to I/O pin 1 on the Stamp.
- The reset/select pin goes to I/O pin 0 on the Stamp.
| |
You can get a DS1620 either from Jameco (part number 146456) or Parallax (part number 27917) in an "application kit" that includes the chip, the capacitor, some good documentation and sample code. Or you can buy the chip on its own from Jameco (part number 114382). I would suggest getting the application kit the first time you try using the DS1620 because the documentation is very useful.
You can assemble the DS1620 in the prototype area of the Stamp carrier board or on a separate breadboard. Once you have assembled it, hook your LCD display up to I/O pin 3 of the Stamp, and then load and run the following program: symbol RST = 0 ' select/reset line on 1620
If you run this program, you will find that it displays the centigrade temperature with an accuracy of one-half degree.
symbol CLK = 1 ' clock line for shift registers on 1620
symbol DQ = 2 ' data line on 1620
symbol DQ_PIN = pin2 ' pin representation for DQ
symbol LCD = 3 ' data line for LCD
begin:
low RST ' deselect the 1620 unless talking to it
high CLK ' clock pin on 1620 should default high
pause 1000 ' wait for the thermometer and LCD to boot
setup:
high RST ' select the 1620
b0 = $0C ' $0c is the 1620 command byte
' saying "Write Config"
gosub shift_out ' send it to the 1620
b0 = %10 ' %10 is the 1620 command byte
' to set thermometer mode
gosub shift_out ' send it to the 1620
low RST ' deselect the 1620
pause 50 ' delay 50ms for EEPROM
start_convert:
b0 = $EE ' $EE is the 1620 command byte
' to start conversions
high RST ' select the 1620
gosub shift_out ' send it to the 1620
low RST ' deselect the 1620
' This is the main loop
' - reads and displays temperature every second
main_loop:
high RST ' select the 1620
b0 = $AA ' $AA is the 1620 command byte
' for reading temperature
gosub shift_out ' send it to the 1620
gosub shift_in ' read the temperature
' from the 1620
low RST ' deselect the DS1620.
gosub display ' display the temp in degrees C
pause 1000 ' wait a second
goto main_loop
' The shift_out subroutine sends whatever is in
' the b0 byte to the 1620
shift_out:
output DQ ' set the DQ pin to
' output mode
for b2 = 1 to 8
low CLK ' prepare to clock the bit
' into 1620
DQ_PIN = bit0 ' Send the data bit
high CLK ' latch data bit into 1620
b0 = b0/2 ' shift all bits right
' toward bit 0
next
return
' The shift_in subroutine gets a 9-bit
' temperature from the 1620
shift_in:
input DQ ' set the DQ pin to
' input mode
w0 = 0 ' clear w0
for b5 = 1 to 9
w0 = w0/2 ' shift input right.
low CLK ' ask 1620 for next bit
bit8 = DQ_PIN ' read the bit
high CLK ' toggle clock pin
next
return
' Displays the temperature in degrees C
display:
if bit8 = 0 then pos ' if bit8=1
' then temp is negative
b0 = b0 &/ b0 ' invert b0 by NANDing it
' with itself
b0 = b0 + 1
pos:
serout LCD, n2400, (254, 1) ' clear the LCD
serout LCD, n2400, ("Temp = ") ' display "Temp="
' on the display
bit9 = bit0 ' save the half degree
b0 = b0 / 2 ' convert to degrees
if bit8 = 1 then neg ' see if temp is negative
serout LCD, n2400, (#b0) ' display positive temp
goto half
neg:
serout LCD, n2400, ("-", #b0)' display negative temp
half:
if bit9 = 0 then even
serout LCD, n2400, (".5 C") ' display the half degree
goto done
even:
serout LCD, n2400, (".0 C") ' display the half degree
done:
return
The DS1620 measures temperatures in centigrade half-degrees. It returns the temperature in a 9-bit 2s-complement number with a range of -110 to 250 F (-55 to 125 C). You divide the number you receive by 2 to get the actual temperature. 2s-complement binary numbers are a convenient way to represent negative values. The following list shows the values for a 4-bit 2s-complement number:
0111 : 7
0110 : 6
0101 : 5
0100 : 4
0011 : 3
0010 : 2
0001 : 1
0000 : 0
1111 : -1
1110 : -2
1101 : -3
1100 : -4
1011 : -5
1010 : -6
1001 : -7
1000 : -8
You can see that instead of the 4 bits representing values from 0 to 15, the 4 bits in a 2s-complement number represent the values -8 to 7. You can look at the left-most bit to determine if the number is negative or positive. If the number is negative, you can invert the bits and add 1 to get the positive representation of the number.
Here's what goes on with the digital thermometer program shown here:
- It uses the symbol keyword to set up several constants that make the program slightly easier to read (and also make it easy for you to move the chip to different I/O pins on the Stamp).
- It sets the CLK and RST pins on the DS1620 to their expected values.
- It writes a command byte to the EEPROM on the DS1620 to tell the chip to operate in "thermometer mode." Because the mode is stored in EEPROM, you only have to do it once, so you could technically take this section of the code out of the program after you run the program once (to save program space).
- The program sends the command $EE ("$" means "hexadecimal number" -- $EE is 238 in decimal) to tell the thermometer to start up its conversion process.
The program then enters a loop. Every second, it sends a command to the DS1620 telling the DS1620 to return the current temperature, and then it reads the 9-bit value that the DS1620 returns into the w0 variable. The Stamp sends and receives data 1 bit at a time by toggling the CLK line on the DS1620. Remember that the w0 (16-bit) variable overlays the b0/b1 (8-bit) variables, which overlay the bit0/bit1/.../bit15 (1-bit) variables, so when you insert a bit from the DS1620 into bit 8 and divide w0 by 2, what you are doing is shifting each bit to the right to store the 9-bit temperature from the DS1620 into w0. Once the temperature has been saved in w0, the display subroutine determines whether the number is positive or negative and displays it appropriately on the LCD as a centigrade temperature. The conversion from degrees C to degrees F is:
- dF = dC * 9/5 + 32
At this point, we have succeeded in creating an extremely expensive thermometer. What might you do with it? Here's one idea. Let's say you work for a drug company and you are shipping expensive drugs across the country that MUST remain at a certain temperature the entire way or the drugs will spoil. What you can do with a Stamp is create a data logging thermometer. Both Jameco (part number 143811) and Parallax (part number 27960) sell a device called the "RAM Pack module." It contains a low-power 8-kilobyte (or optionally 32-kilobyte) RAM chip with a serial interface. You could add this component (or something similar) to your Stamp and write code that saves temperature readings to the RAM every minute. You could then slip your Stamp into the drug shipment, and at the other end of the trip retrieve the Stamp. The RAM module would contain the temperature history of the entire trip and you would know whether or not the drugs ever thawed out.
There are all kinds of neat, useful devices like this that you can build with a Stamp now that you know how microcontrollers work!
For more information on microcontrollers and related topics, check out the links on the next page.
Creating a Really Expensive Digital Clock
Spending $79 to flash an LED may seem extravagant to you. What you would probably like to do is create something useful with your BASIC stamp. By spending about $100 more you can create a really nice digital clock! This may seem extremely extravagant, until you realize that the parts are reusable in a variety of other projects that you may want to build later.
Let's say that we would like to use the I/O pins on the BASIC Stamp to display numeric values. In the digital clock article, we saw how to interface to a 7-segment LED display using a 7447 chip. 7447s would work just as well with the BASIC Stamp. You could wire four of the I/O pins straight into a 7447 and easily display a number between 0 and 9. Since the BS-1 Stamp has eight I/O pins, it is easy to drive two 7447s directly like this.
For a clock, we need a minimum of four digits. To drive four 7447s with eight I/O pins, we have to be slightly more creative. The following diagram shows you one approach:
| |
In this diagram, the eight I/O lines from the Stamp enter from the left. This approach uses four lines that run to all four 7447s. Then the other four lines from the Stamp activate the 7447s in sequence ("E" on the chips means "Enable" -- on a 7447, that would be the blanking input on pin 5). To make this arrangement work, the BASIC program in the Stamp would output the first digit on the four data lines and activate the first 7447 by toggling its E pin with the first control line. Then it would send out the value for the second digit and activate the second 7447, sequencing through all four of the 7447s like this repeatedly. By wiring things slightly differently, you could actually do this with only one 7447. By using a 74154 demultiplexer chip and some drivers, you could drive up to 16 digits using this approach.
This is, in fact, a standard way to control LED displays. For example, if you have an old LED calculator, turn it on and shake it while watching the display. You will actually be able to see that only one digit is ever illuminated at once. The approach is called multiplexing the display.
While this approach works fine for clocks and calculators, it has two important problems:
- LEDs consume a lot of power.
- 7-segment LEDs can only display numeric values.
An alternative approach is to use an LCD screen. As it turns out, LCDs are widely available and can be easily hooked to a Stamp. For example, the two-line by 16-character alphanumeric display shown below is available from both Jameco (part number 150990) and Parallax (part number 27910). A typical display is shown here, mounted on a breadboard for easier interfacing:
| |
This sort of LCD has several advantages:
- The display can be driven by a single I/O pin. The display contains logic that lets a Stamp communicate with it serially, so only one I/O pin is needed. In addition, the SEROUT command in Stamp BASIC handles serial communication easily, so talking to the display is simple.
- The LCD can display alphanumeric text: letters, numbers and even custom characters.
- The LCD consumes very little power -- only 3 milliamps.
To drive a display like this, you simply supply it with +5 volts and ground (the Stamp supplies both from the 9-volt battery) and then hook one of the I/O pins from the Stamp to the display's input line. The easiest way I have found to connect the Stamp's I/O pins to a device like an LCD is to use a wire-wrap tool (Jameco part number 34577) and 30-gauge wire wrap wire (Jameco part number 22541 is typical). That way, no soldering is involved and the connections are compact and reliable.
The following BASIC program will cause a BASIC Stamp to behave like a clock and output the time on the LCD (assuming the LCD is connected to I/O pin 0 on the Stamp):
pause 1000 'wait for LCD display to boot
serout 0, n2400, (254, 1) 'clear the display
serout 0, n2400, ("time:") 'Paint "time:" on the display
'preset before loading program
b0 = 0 'seconds
b1 = 27 'minutes
b2 = 6 'hours
again:
b0 = b0 + 1 'increment seconds
if b0 < 60 then minutes
b0 = 0 'if seconds=60
b1 = b1 + 1 ' then increment minutes
minutes:
if b1 < 60 then hours
b1 = 0 'if minutes=60
b2 = b2 + 1 ' then increment hours
hours:
if b2 < 13 then show
b2 = 1 'if hours=13 reset to 1
show:
serout 0, n2400, (254, 135) 'position cursor on display,
'then display time
serout 0, n2400, (#b2, ":", #b1, ":", #b0, " ")
pause 950 'pause 950 milliseconds
goto again 'repeat
In this program, the SEROUT commands send data to the LCD. The sequence (254, 1) clears the LCD (254 is the escape character and 1 is the command to clear the screen). The sequence (254, 135) positions the cursor. The other two SEROUT commands simply send text strings to the display.
This approach will create a reasonably accurate clock. By tweaking the PAUSE statement you can get the accuracy to within a few seconds a day. Obviously, in a real clock you would like to wire up a push-button or two to make setting it easier -- in this program, you preset the time before you download the program to the Stamp.
While this approach is simple and works, it is not incredibly accurate. If you want better accuracy, one good approach would be to wire a real-time clock chip up to your Stamp. Then, every second or so, you can read the time from the chip and display it. A real-time clock chip uses a quartz crystal to give it excellent accuracy. Clock chips also usually contain date information and handle leap year correction automatically.
One easy way to interface a real-time clock to a stamp is to use a component called the Pocket Watch B.
| Pocket Watch B Module |
The Pocket Watch B is available from both Jameco (part number 145630) and Parallax (part number 27962). This part is about as big as a quarter and contains the clock chip, crystal and a serial interface so that only one I/O pin is necessary to communicate with it. This component costs about $30 -- again, not something you want to embed in a toaster oven, but easy to play with when constructing prototypes.
Playing with a BASIC Stamp
If you would like to play with a BASIC Stamp, it's very easy to get started. What you need is a desktop computer and a BASIC Stamp starter kit. The starter kit includes the Stamp, a programming cable and an application that you run on your desktop computer to download BASIC programs into the Stamp.
You can get a starter kit either from Parallax (the manufacturer) or from a supplier like Jameco (who should be familiar to you from the electronic gates and digital clock articles). From Parallax, you can order the BASIC Stamp D Starter Kit (part number 27202), or from Jameco you can order part number 140089. You will receive the Stamp (pictured below), a programming cable, software and instructions. The kit is $79 from both suppliers. Occasionally, Parallax runs a special called "We've Bagged the Basics" that also includes Scott Edward's Programming and Customizing the BASIC Stamp Computer.
Hooking up the Stamp is easy. You connect it into the parallel port of your PC. Then you run a DOS application to edit your BASIC program and download it to the Stamp. Here is a screenshot of a typical editor (in this case, the one from Scott Edward's book):
| |
To run the program in this editor, you hit ALT-R. The editor application checks the BASIC program and then sends it down the wire to the EEPROM on the Stamp. The Stamp then executes the program. In this case, the program produces a square wave on I/O pin 3. If you hook up a logic probe or LED to pin 3 (see the electronic gates article for details), you will see the LED flash on and off twice per second (it changes state every 250 milliseconds because of the PAUSE commands). This program would run for several weeks off of a 9-volt battery. You could save power by shortening the time that the LED is on (perhaps it is on for 50 milliseconds and off for 450 milliseconds), and also by using the NAP instruction instead of PAUSE.
Programming the BASIC Stamp
You program a BASIC Stamp using the BASIC programming language. If you already know BASIC, then you will find that the BASIC used in a Stamp is straightforward but a little stripped-down. If you don't know BASIC, but you do know another language like C, Pascal or Java, then picking up BASIC will be trivial. If you have never programmed before, you probably want to go learn programming on a desktop machine first. Here is a quick rundown on the instructions available in Stamp BASIC. (For complete documentation, go to Parallax: BASIC Stamp Documentation.)
Standard BASIC instructions:
- for...next - normal looping statement
- gosub - go to a subroutine
- goto - goto a label in the program (e.g. - "label:")
- if...then - normal if/then decision
- let - assignment (optional)
- return - return from a subroutine
- end - end the program and sleep
Instructions having to do with I/O pins:
- button - read a button on an input pin, with debounce and auto-repeat
- high - set an I/O pin high
- input - set the direction of an I/O pin to input
- low - set an I/O pin low
- output - set the direction of an I/O pin to output
- pot - read a potentiometer on an I/O pin
- pulsin - read the duration of a pulse coming in on an input pin
- pulsout - send a pulse of a specific duration out on an output pin
- pwm - perform pulse width modulation on an output pin
- reverse - reverse the direction of an I/O pin
- serin - read serial data on an input pin
- serout - write serial data on an output pin
- sound - send a sound of a specific frequency to an output pin
- toggle - toggle the bit on an output pin
Instructions specific to the BASIC Stamp:
- branch - read a branching table
- debug - send a debugging string to the console on the desktop computer
- eeprom - download a program to EEPROM
- lookdown - return the index of a value in a list
- lookup - array lookup using an index
- nap - sleep for a short time
- pause - delay for the specified time
- random - pick a random number
- read - read a value from EEPROM
- sleep - power down for the specified time
- write - write data to EEPROM
Operations:
- + - addition
- - - subtraction
- * - multiplication (low-word)
- ** - multiplication (high-word)
- / - division
- // - mod
- max - return maximum of 2 values
- min - return minimum of 2 values
- & - AND
- | - OR
- ^ - XOR
- &/ - NAND
- |/ - NOR
- ^/ - XNOR
If statement logic:
- =
- <>
- <
- <=
- >
- >=
- AND
- OR
Variables
All variables in the BS-1 have pre-defined names (which you can substitute with names of your own). Remember that there are only 14 bytes of RAM available, so variables are precious. Here are the standard names:
- w0, w1, w2...w6 - 16-bit word variables
- b0, b1, b2...b13 - 8-bit byte variables
- bit0, bit1, bit2...bit15 - 1-bit bit variables
I/O pins
You can see that 14 of the instructions in the BS-1 have to do with the I/O pins. The reason for this emphasis is the fact that the I/O pins are the only way for the BASIC Stamp to talk to the world. There are eight pins on the BS-1 (numbered 0 to 7) and 16 pins on the BS-2 (numbered 0 to 15).
The pins are bi-directional, meaning that you can read input values on them or send output values to them. The easiest way to send a value to a pin is to use the HIGH or LOW functions. The statement high 3 sends a 1 (+5 volts) out on pin 3. LOW sends a 0 (Ground). Pin 3 was chosen arbitrarily here -- you can send bits out on any pin from 0 to 7.
There are a number of interesting I/O pin instructions. For example, POT reads the setting on a potentiometer (variable resistor) if you wire it up with a capacitor as the POT instruction expects. The PWM instruction sends out pulse-width modulated signals. Instructions like these can make it a lot easier to attach controls and motors to the Stamp. See the documentation for the language for details. Also, a book like Scott Edward's Programming and Customizing the BASIC Stamp Computer can be extremely helpful because of the example projects it contains.