Tuesday, February 24, 2009

Microcontroller Dot-to-Dot Programming

Ditch that Arduino for an even easier way to build a microcontroller project

PSoC FirstTouch Parts: From left to right: rechargeable battery pack for iPod shuffle (with included port extension cord; very handy), FTPC Bridge, and FTMF Expansion Card. Dave Prochnow

OK, you don't have to actually throw away your Arduino, but you might wish to consider this slick alternative the next time you're going to build a temperature-sensing microcontroller project. Or, for that matter, a light-sensing project, or a proximity-sensing project, or a capacitance-sensing project.

This "alternative" is a relatively new kid on the embedded design block called PSoC® FirstTouch, from Cypress Semiconductor Corporation. The Cypress PSoC is better known as a programmable mixed signal array or Programmable System-on-Chip (PSoC). While sporting an 8-bit microcontroller clocking in at a maximum 24MHz and supporting 512 bytes of SRAM, 8KB flash, these rather lackluster specs are offset by four analog and four digital customizable advanced peripheral building blocks (known as PSoC Blocks), and the ability to build a crazy-small microcontroller project.

How small, you ask?

Well, the entire PSoC microcontroller fits roughly on a 1-by-2-inch PCB, which includes a USB interface and type-A plug! This PCB is called the FirstTouch PC (FTPC) Bridge. It's encased in a sealed transparent enclosure. But the real magic happens with the interchangeable FirstTouch Multifunction (FTMF) Expansion Card. Although narrower than the FTPC Bridge, the FTMF Expansion Card is bristling with sensors, output indicators, and human interface devices (e.g., an eight-segment capacitance input slider; just slide your finger along the slider for varying your input).

All of this hardware excitement would fall short if not for the nifty drag-and-drop "code-less" programming environment (based on Microsoft's Visual .NET Framework) that supports the FirstTouch PSoC. Just like the Arduino's elegant programming language, FirstTouch's coding interface consists of an integrated development environment called PSoC Express and a graphical user interface programmer. That's where all other similarity with Arduino's Processing programming paradigm ends, however.

PSoC Catalog: Dave Prochnow

Unlike "writing" C code, PSoC Express relies on a series of devices which integrate with the peripheral analog and digital PSoC Blocks. You don't write no stinking code, here, man. You just find the sensor, input device, or output device that you want to use, drag it onto the Design surface, and then connect your building blocks together with some dot-to-dot linking truth tables known as Transfer Functions. When you've completed your programming design, you can test the program's logic with a visual simulator. If everything checks out OK, it's off to build, compile, and program your design on the FirstTouch PSoC.

PSoC Design: Dave Prochnow

While you can certainly roll your own design, FirstTouch comes preloaded with four designs that you can modify for your own applications: proximity sensor, capacitance sensing, light sensor, and temperature sensor. As a demonstration, I built a temperature sensor design (e.g., FirstTouch_Temp) based on the canned Cypress temperature sensor design. The result is a portable temperature sensor that uses a tri-state LED (e.g., red, green, and blue) and buzzer for representing various temperature states (e.g., temps higher than 95ºF are shown by a red LED and a tone from the buzzer, temps ranging between 75ºF and 80ºF are shown by a green LED, temps lower than 60ºF are indicated by a blue LED and a buzzer tone, and so forth). There are a total of nine different temperature ranges that are indicated by this FirstTouch temperature sensor LED/buzzer design.

Although the FirstTouch kit does not allow for portable operation, I was able to make my temperature sensor operate independently from a PC's USB port with a discontinued rechargeable battery pack for an Apple iPod shuffle (1st generation) available from All Electronics. Just make sure to snip the clips off the battery pack's recharging port cap. This simple modification will make it easier to hold both the FirstTouch PSoC FTPC Bridge + FTMF Expansion Card and the rechargeable battery pack. Now you can run around the office and "sample" temps. Or carry it on the street and let the buzzer shriek as your fingers freeze in the winter.

Kludging together a quick and dirty hardware/software design with a microcontroller has never been so easy. Plus the final form factor is ideal for a simple "proof of concept" evaluation prior to committing valuable resources to a full-blown design.

The biggest drawback to FirstTouch, however, might be the unbelievably bright blue LED that is housed in the FTPC Bridge. This crazy-bright LED flashes incessantly during design, development, and programming. Later, when your PSoC design is being tested via the portable battery pack option, this blue LED glows brighter than the indicator LED on the FTMF Expansion Card. Replacement of this LED might be possible with an 0805 package SMD LED along with a more potent SMD 0805 package resistor (i.e., R13 on the underside of the FTPC Bridge PCB). A dab of black ink on the LED lens will suffice, too.

COST: $29.95 (FirstTouch) + $5.75 (rechargeable iPod shuffle battery pack); $35.70
TIME: 5 hours (software installation, programming, and hardware setup)
DIFFICULTY: easy (with previous microcontroller experience)


PSoC FirstTouch: A temperature sensor built with Cypress PSoC FirstTouch kit. Dave Prochnow

Microcontroller features

Since embedded processors are usually used to control devices, they sometimes need to accept input from the device they are controlling. This is the purpose of the analog to digital converter. . Since processors are built to interpret and process digital data, i.e. 1s and 0s, they won't be able to do anything with the analog signals that may be being sent to it by a device. So the analog to digital converter is used to convert the incoming data into a form that the processor can recognize. There is also a analog to digital converter that allows the processor to send data to the device it is controlling.

In addition to the converters, many embedded microprocessors include a variety of timers as well. One of the most common types of timers is theProgrammable Interval Timer , or PIT for short. A PIT just counts down from some value to zero. Once it reaches zero, it sends an interrupt to the processor indicating that it has finished counting. This is useful for devices such as thermostats, which periodically test the temperature around them to see if they need to turn the air conditioner on, the heater on, etc.

Time Processing Unit or TPU for short. Is essentially just another timer, but more sophisticated. In addition to counting down, the TPU can detect input events, generate output events, and other useful operations.

Dedicated PWM block makes it possible for the CPU to control power converters, resistive load, motors, etc., without using lots of CPU resources in tight time loops.

Universal Asynchronous Receiver/transmitter(UART) block makes it possible to receive and transmit data over a serial line with very little load on the CPU.

For those wanting ethernet one can use an external chip like Crystal Semiconductor CS8900A, Realtek RTL8019, or Microchip ENC 28J60. All of them allow easy interfacing with low pin count.

what is microcontroller



A microcontroller (also MCU or µC) is a small computer on a single integrated circuit consisting of a relatively simple CPU combined with support functions such as a crystal oscillatior , timers, watchdog, serial and analog I/O etc. Program memory in the form of Nor flash is also often included on chip, as well as a, typically small, read/write memory.

Thus, in contrast to the microprocessors used inpersonal computer and other high perfomance applications, simplicity is emphasized. Some microcontrollers may operate at clock frequencies as low as 32KHz, as this is adequate for many typical applications, enabling low power consumption (milliwatts or microwatts). They will generally have the ability to retain functionality while waiting for an event such as a button press or other interrupt; power consumption while sleeping (CPU clock and most peripherals off) may be just nanowatts, making many of them well suited for long lasting battery applications.

Microcontrollers are used in automatically controlled products and devices, such as automobile engine control systems, remote controls, office machines, appliances, power tools, and toys. By reducing the size and cost compared to a design that uses a separate microprocessor, memory, and input/output devices, microcontrollers make it economical to digitally control even more devices and processes.