Todo sobre Microcontroladores

advertisement
Todo sobre Microcontroladores
Un microcontrolador es un computador pequeño, barato, usualmente usados para sensar los input del
mundo real y controlar devices basadas en ese input. Muchos devices electrónicos usados hoy tienen un
microcontrolador de alguna u otra manera.
Los microcontroladores son fáciles de usar con un sensor y devoces output simples, y se pueden
comunicar con computadores de escritorio de manera simple, también. Cuando estás construyendo alguna
forma de sensor personalizado, o device output, usar un Microcont es una excelente manera de separar y
personalizar tu proyecto del computador de escritorio.
Como cualquier otro computador, un microcont tiene que tener puertos de inputs para detectar una acción
por un usuario y puertos de output que expresan los resultados del programa.
Los pines que salen del chip son inputs y outputs. Otros devices, como sensores de luz, calor,
movimiento (motores) o sonido, están conectados a estos pines para permitir que el microcont sea
sensible al mundo y lo exprese.
Hay muchos diferentes niveles de microcont y sistemas de microcont. Algunos son muy pequeños y sus
chip deben ser conectados a los circuitos. Otros son más grandes y están compuetos por muchos
componentes y puertos para input y output, listos para enchufar otros devices.
Microcont de alto nivel, tendrán hardware simple como interfase para otro device (usualmente un enchufe
y un par de cables) y un aún más simple lenguaje de programación. Será también los mcrocont más caros
porque alguien más debió hacer el trabajo por ti. Estos tipos de microcont deben estar adjuntos a un
computador de escritorio o laptop via USB para operar.
Un microcont de más bajo nivel, requerirá más trabajo, en términos de conexión de hardware (tienes que
hacer tus propias conexiones para interfasearlas con otros devices) y en términos de programación
deberás usar un nivel bajo de lenguaje de programación como C o similar. Como sea, procesadores de
nivel bajo son generalmente más baratos y más flexibles en términos de lo que puedes hacer con ellos.
Algunos ejemplos típicos de microcont de varios niveles son:
Alto nivel: Gainer
Qué es: un microcontrolador que como interfase es un módulo que te permite construir tu propio sensor
y actuador como interfaz de circuito y controlarlos desde un ambiente de programación multimedia
regular.
Lenguaje de Programación: Actionscript, Max/MSP, Processing. Estos módulos en sí mismos están
pre-programados, y dialogan en un protocolo serial de recurso abierto (open-source serial protocol). Se
les puede asignar una dirección vía una serie de interfases de lenguaje de programación.
Interfase hardware: USB
Costo: Kits principiantes varían entre U$130 y U$530 el pro.
Alto nivel: Phidgets
Qué es: es una serie de intrefases modulares que permiten al usuario conectar sensores, motores, luces,
MIDI y más con poco o nulo trabajo electrónico.
Lenguaje de Programación: C/C++, Java, Actionscript, etc. Los módulos en sí mismos están preprogramados y dialogan via protocolo serial propio USB. Pueden obtener dirección vía una serie de
interfases con aplicaciones de programación (APIs) para diferentes lenguajes de programación.
Interfase Hardware: USB
Costo: Kits principiantes varían entre U$130 a $530 el pro.
Microcontroladores Nivel Medio son usualmente programados conectando un cable serial de un PC en
el cual el código está escrito al microcont en sí mismo. Aparte de esto, no se requiere hardware adicional.
Existe un amplia variedad de módulos nivel medio y nivel bajo.
Nivel Medio: Wiring y Arduino
Qué es: es un módulo electrónico con microcontrolador, fuente de poder, interfase serial a USB, interfase
input/output pins
Lenguaje de Programación: Wiring, una variación más simple de C que es similar a Processing.
Interfase Hardware: circuitos simples digitales y análogos interfaseados a pins I/O.
Costo: Wiring: U$80 y Arduino: U$30. Ambas con software open source.
Como otros microcontroladores nivel medio, Arduino se conecta directamente al computador. A
diferencia de los otros, tiene una interfaz construida en la placa USB a interfase serial, así que se conecta
directo a tu computador vía puerto USB. Aparte de esto, no se requiere hardware adicional.
Ambos, el software y hardware son open source, con planos disponibles en línea para ser
construidas.Ambas se basan en la familia de microcont Atmel.
Existen diferentes variaciones de Arduino en relación a los proyectos, fabricantes, etc. Chequea la web:
Arduino.cc
Nivel Medio: NetMedia’s BX-24 Microcontroller module
Qué es: es un módulo electrónico con microcontrolador, interfase serial, memoria, pins input/output
Lenguaje de Programación: BX BASIC, muy cerca de Visual Basic.
Interfase Hardware: pins simples digitales y análogos a pins I/O.
Costo: U$50
Microcontroladores Nivel Bajo algunos carecen de circuitos básicos que ofrecen los módulos de nivel
medio. En algunos faltan reguladores de voltaje, memoria EEPROM y buffer de puerto serial, éstos deben
ser puestos al ser usados, si se requieren.
Estos microcont típicamente requieren un hardware programador externo para ser programados.
Típicamente, el programador es incorporado al PC via cable serial, paralelo, o USB, y el microcont es
situado en el para ser re-programado. Algunos programadores tienen cables para permitir que se conecten
al circuito en el que el microcont está puesto para poder programarlo, Esto se llama programación en
circuito o in-circuit programming.
Low Level: Atmel’s AVR microcontrollerhttp://www.microchip.com
What is it: Microcontroller chip
Programming Language: Assembler, C, BASIC, Wiring
Hardware Interface: requires programmer to make power and timing circuitry in order to operate;
thereafter, I/O circuits are similar to BX-24 and other middle and low-level circuits.
Cost: $1.00 – $15.00 depending on model used.
The Atmel controllers are the controllers at the heart of the Wiring, Arduino, and BX-24 modules.Â
There are a variety of controllers in the AVR family with different features. Some feature more I/O
pins, some feature more memory, some can speak USB natively, and so forth. There is a good open
source C compiler for the AVR chips, AVR-GCC. It’s the basis for both the Wiring and Arduino
development environments, and available on Windows, OSX, and Linux. Objective Development has a
nice package of the AVR-GCC for OSX users.
Low Level: Microchip’s PICMicro microcontroller
What is it: Microcontroller chip
Programming Language: Assembler, C, BASIC
Hardware Interface: requires programmer to make power and timing circuitry in order to operate;
thereafter, I/O circuits are similar to BX-24 and other middle and low-level circuits.
Cost: $1.00 – $15.00 depending on model used.
Things to consider when picking a microcontroller:
Costs
How much do I want to spend? The higher the level, the higher the cost. But if it reduces the time taken
between setting up and expressing yourself, it may be worth spending the extra money.
Time
How much work do I want to do? a higher level controller will generally minimize the amount of work
you do to build your interface to the world. Lower level controllers will take more work before you have
things working.
What programming languages/communications protocols/electronics do I already know? All other
things being equal, pick a system whose components you know something about.
What’s the knowledge base like? Most microcontrollers have several websites and listserves dedicated
to their use and programming. Quite often, the best ones are linked right off the manufacturer’s or
distributor’s website. Check them out, look at the code samples and application notes. Read a few of the
discussion threads. Do a few web searches for the microcontroller environment you’re considering. Is
there a lot of collected knowledge available in a form you understand? This is a big factor to consider.
Sometimes a particular processor may seem like the greatest thing in the world, but if nobody besides you
is using it, you’ll find it much harder to learn.
Expandability/Compatibility
What other components is the microcontroller compatible with? Can you add on modules to your
microcontroller? For example, are their motor controllers compatible with it? Display controllers?
Sensors or sensor modules? Often these modules are expensive but they just snap into place without you
making any special circuitry. If your time is worth a great deal, then these modules are a good buy.
Sometimes even if you know how to build it with a lower level controller, a higher level system is worth
the cost because it saves building and maintenance time.
What do I have to connect to? Are you connecting to a MIDI synthesizer? A DMX-512 lighting board?
A desktop computer? The phone system? The Internet? Different microcontrollers will have different
interface capabilities. Make sure you can connect everything together. Sometimes this requires some
creative combinations of controllers if no one controller can speak to all the devices you want it to speak
to.
Physical and Electrical Characteristics
How many inputs/outputs do I need? Every system has a certain number of ins and outs. If you can,
decide how many things you want to sense or control before you pick your controller.
What kinds of inputs and outputs do I need? Do you need analog inputs and outputs, for sensing
changing values, or do you only need digital ins and outs, for sensing whether something is on or off?
What kind of power is available to me? Does it need to be battery powered? Does it need to match the
voltage of another device? Does it need to draw very little amperage?
How fast do I need to process data? Lower level processors will generally give you more speed.
How much memory do I need? If you’re planning some complex data processing or logging, you may
need a microprocessor with lots memory, or the ability to interface with external memory.
How small does it need to be? A lower level controller generally lets you build your own circuitry,
allowing you to reduce the size of the hardware you need.
The Economics of Microcontroller Development
One of the first questions that people usually ask when they learn that low-level and mid-level controllers
can do many of the same things is, why the difference in cost? Why does a BX-24 or a Basic Stamp cost
$50 and up, while a PIC or an SX micro costs less than $10? Furthermore, why are mid-level controllers’
development software free, while the software for low-level controllers is not? The answer, as you might
expect, lies in the aims of the people selling them.
Companies that make mid-level microcontroller modules (NetMedia for the BX-24, Parallax for the Basic
Stamp, Basic Micro for the Basic Atomm) are in the hardware business. They make their money by
selling you modules. They typically serve a fairly low-volume customer who buys sometimes one,
sometimes a dozen, but seldom more than a hundred modules at a time. In order to keep that customer
coming back, they also develop proprietary development environments, so that you can’t reprogram their
modules with the other guy’s software. However, so you won’t get upset about that, they give it away for
free. It’s their belief that the unique combination of microcontroller, supporting circuitry, and
development environment that they offer makes for the best way to use microcontrollers, and it’s worth a
premium price. For beginners, they’re often right.
The open source hardware movement is making some interesting changes in this model through projects
like Gainer, Wiring, Arduino, and others. Open source hardware makers recognize the value in mid- to
high-level programming environments for lower level controllers as well as the desire of some users to go
low-level once they understand more than the basics. They also see the value in several groups working
together on compatible systems. Though the companies making these modules are in competition with
one another for customers, they are also in collaboration to make their hardware and software better. It
can sometimes be a difficult collaboration, but in the long run, everyone’s tools get better as a result.
Open-source mid-level tools are promising because they combine the best of both worlds. They let you
learn at a mid or high level, then when you know what you’re doing, you can take the low-level guts of
the device (an Atmel controller, in the case of these two tools) and gain the cost benefits of working low
level. There are more hybrid open-source projects like this coming online all the time. A number of them
were presented at the Sketching in Hardware workshop in 2006, and resource links were gathered online
at that link, if you’d like to learn more.
Companies that make low-level controllers, on the other hand (Microchip, Atmel, Ubicom), are used to
selling in very high volumes. They sell controllers to major manufacturers who put them in things like
cars, toys, light switches, microwave ovens, and more. Their customers need to shave off every spare
expense in order to make a profit on the end product. These customers willing to train engineers in lowlevel coding, to develop their own software tools, and so forth, in order to get a high-volume, low-cost
chip. In fact, the low-level processors are the hearts of the mid-level processors. Check out the big chip
on a Basic Stamp 2; it’s a PIC. Low-level manufacturers don’t spend a lot of time making development
environments, so they can specialize on making a wide variety of good chips. They’re used to dealing in
such large volumes, in fact, that a few chips more or less is no big deal. Most of them even offer a limited
number of free samples on their websites, for prospective customers.
So what if you’re a beginner or small guy who wants to use low-level chips? You probably don’t have the
time or expertise to develop your own compiler for it, and you’d rather not have to use the assembly
language of the controller, if you can avoid it. This is where third-party software developers come in.
Companies like CCS, Microengineering Labs, Crownhilll, Hi-Tech, and others make and sell custom
higher-level development environments for low-level controllers. They’re in the software business.
Because the profit margin on low-level controllers is already so low, they choose not to develop extra
hardware to sell you premium hardware, but instead, they make really good software tools so that it’s
easy for you to program the low-level controllers. Many of them also make custom hardware
programmers, that make it easier on the hardware end too.
So where does this leave you, the hobbyist or beginner with microcontrollers? What should you
choose?
Using mid-level microcontrollers will cost you relatively little up front, in terms of peripherals. The
software’s free, and a serial cable is about $5.00. The various components you’ll need to make a typical
project will run you $50 – $75, maybe. The microcontroller will run you another $50. If you know your
way around a circuit, and you’re reasonably sure you won’t destroy your microcontroller, this isn’t a bad
way to go. You can always keep the project intact and re-use the microcontroller for other projects.
You’ll save yourself time not having to learn how a hardware programmer works, or which compiler to
choose, or how to configure it. For the beginner seeking immediate gratification, mid-level is the way to
go.
The only downside is that if you want to build many more projects, you’ve got that $50 cost on top of any
other project costs each time. And if you damage the microcontroller, there’s another $50. And another
and another, until you learn to be careful with your circuits.
Using low-level controllers, on the other hand, is more of a hassle up front. You’ve got to choose a
development environment and pay for it, choose a hardware programmer and pay for it, and learn to set
all the stuff up. For a decent compiler and a decent but cheap programmer, you’ll probably shell out about
$300.00. You’ll spend a lot of time early on cursing and wishing you’d bought a Basic Stamp 2, or a BX24. The advantage comes a bit later on, once everything’s set up and you begin making projects. First, if
you fry the chip, you’re only out a few dollars to replace it. It gets better the longer you continue making
microcontroller projects. You don’t have to spend more money on the development environment, and the
chips are cheap. If you can work a bit for gratification, and you’re in for the long haul, it’s a good way to
go.
Download