MCUInterfaceDesign MCUInterfaceWorkshpDay1

From XPUB & Lens-Based wiki
Revision as of 20:32, 23 September 2010 by Migratebot (talk | contribs) (Created page with "= MCU Interface Design Workshop - Day 1 = TOC(noheading) == What is an interface? == Simply put, an interface is a (part of a) system where information is passed through...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

MCU Interface Design Workshop - Day 1

TOC(noheading)

What is an interface?

Simply put, an interface is a (part of a) system where information is passed through form one side to the other of the interface. Very often, the information being transferred is also translated from one protocol or information-carrier to another, re-mapped or scaled in some way or another, and sometimes the interface can make certain decisions based on the incoming information, and send signals to one side or the other, triggering events or changing its own behaviour based on these decisions.

Wat is a Microcontroller (or "MCU")?

A Microcontroller is a small but complete computer-in-a-chip. Like your laprop, for example, it has a CPU (Central Processing Unit) with RAM and some non-volatile memory where the program is stored. These days, most MCUs have FLASH memory to store programs and other data that does not change during the execution of the program. The AVR 'ATmega' family of microcontrollers also have another bank of non-volatile memory, the EEPROM, where the running program can store & retrieve data that should be retained across a reset, or when the MCU is switched off.

The CPU with the RAM & FLASH memories form the 'computing core' of the MCU. In addition the MCU also has a set of peripherals, or (semi-)autonomous sub-systems that are, in fact, interfaces to the outside world. Smaller microcontrollers do not usually have a VGA (or other video) outputs, USB-ports, nor audio capabilities. Instead, they have other interesting interfaces that are specifically designed to connect to other electronic ciruits like motor-control chips, LEDs or LED-arrays, sensors, A/D & D/A converters, & lots, lots more. The idea is that the MCU becomes the heart of a system, controlling the different functions of that system. Hence the name.

Microcontroller Boards

These days, you can buy realtively cheap ready-made boards with a microcontroller chip on them, plus some power-supply regulation, and an interfaces that allows you to (re-)program the MCU.

Some examples of affordable Microcontroller boards:

The importance of !DataSheets

A Datasheet is a (rather long) document describing the Microcontroller and all of its components in great detail. For successful programming of the microcontroller, it is of vital importance to download its datasheet and read it. Carefully. Maybe not all of it, but certainly the 'Overview' and 'I/O Ports' sections. And for each component (or 'peripheral' in the microcontroller, it describes the Special Function Registers the programmer (that's you) should use to set-up and actually make use of the peripheral you want to use in your program.

Arduino (with ATmega168P or ATmega328)::
ATmega48|88|168|328.pdf
!ArduinoMega (ATmega1280)::
ATmega640|1280|1281|2560|2561.pdf
Teensy 2.0 (ATmega32U4)::
ATmega16U4|32U4.pdf
Teensy++ 2.0 (AT90USB1286)::
AT90USB646|647|1286|1287.pdf

How to make good use of the various I/O facilities of the Microcontroller.

 GPIO (& internal pullups)::
   The General Purpose Input/Output function is available for all pins that are not configured to be used by some other sub-system. Each GPIO-pin can be set to one of four states:
  • as an Output, driven low
  • as an Output, driven high
  • as an Input, floating (or 'high impedance' state)
  • as an Input, internally connected to +5V via a pull-up resistor, i.e. pulled high. Input may be driven low by an external switch, sensor, etc.


 Analog inputs::
   The ATmega MCUs have one Analog-to-Digital converter with 10-bits resolution. The different Analog Input pins can be connected, one at a time, to the ADC input, and then measured. Only one input can be measured at a time, but this takes only a very short amount of time. It is possible to program a "measure input; select next input; repeat" type of loop to sample multiple inputs in quick succesion.


 Analog Comparator::
   This is a different kind of analog input. It can compare 2 external analog voltages, or compare an external analog voltage to an internal reference voltage. The comparator will only give yes/no, 1/0, higher/lower information, and not the actual value of the input voltage(s). 


 Timers/Counters::
   These are quite complex sub-systems, and quite versatile, and so quite useful. They can be configured to operate in various different modes. These are the main ones:
  • Counting pulses of the CPU clock, (i.e. the passage of time) and causing external or internal signals to change at a certain time.
  • Waveform-generation and PWM
  • Counting external pulses
  • Capturing and storing the current time/count when an external signal changes.


 USART, TWI & SPI serial communication systems::
   Three different interfaces providing different types of serial communication, where bits of digital information are sent over a wire, one bit at a time:
  • USART = Uncommited Synchronous/Asynchronous Receiver & Transmitter. Uses two signal wires (plus ground!); one for transmitting, and one for receiving. Can receive and send at the same time, but this is not necessarily so. Both sides of the link must agree on the bit-rate, voltage-levels, frame format, endianness and which error-checking tricks to use.
  • TWI = Two Wire Interface, also known as I2C (for Inter Integrated-circuit Communication ;-). Uses two signal wires (plus ground); one for transmitting or receiving ('SDA', Serial Data), the other as a bit-clock ('SCL', Serial Clock), which tells the other side of the link when to read the bits on the data-line. Both sides must agree on the voltage-levels and error-checks to use. The frame-format, handshaking & endianness are defined by the TWI/I2C protocol.
  • SPI = Serial Peripheral Interface. Uses four signal wires; one for transmitting ('MOSI', Master Out, Slave In), one for receiving ('MISO', guess...), one bit-clock ('SCK' this time), and one extra signal that tells the other side of the link (the 'Slave') to listen ('SS' for Slave Select). Transmitting and receiving of data always happen at the same time.


 EEPROM storage memory::
   An additional block of non-volatile memory which is readable & writable from within your program. Used for storing configuration-data and such that should be retained when the MCU is reset or switched off.