Recently, I was asked to design a two-channel signal converter from a bipolar input voltage to a bipolar output current. I immediately assumed that this was going to be a pure analog design, but there was something that niggled at me. One of the explicit requirements was that each channel was to have a bi-colour LED that varied in brightness proportional to the input signal, and that changed between green and red to indicate when the signal was positive or negative, respectively.
There were two issues. First, the LED drive would need to be boosted so that there is no dead zone around zero. Second, I could foresee a condition where the signal would be negative, but the LED (and possibly the output) was positive, and vice versa. The mechanical equivalent of this is called backlash. Rather than drive the LED with a variable voltage, I considered using a PWM (pulse-width modulated) driver like the LTC6992 from Linear Tech, but I would still have to generate an offset and it didn't solve the backlash issue. Also, I would need two of them (one per channel), and there would have to be additional circuitry to change from red to green. Thus, it was a logical jump to look at low-end microcontrollers (MCUs).
I started off by looking at Microchip, but the ones I found were of the 16C family with small memories, which meant using assembly language. I have worked on three projects with the 16C family (five if you include the Scenix/Parallax SX28 which used the same opcodes as the Microchip), and I am afraid I never felt at home with the paucity of instructions (it being a RISC device) to say nothing of the memory segmentation issues. Succumbing to my bias, I then looked at NXP devices and Freescale ARM Cortex-M0 chips. There are so many variations to choose from that I balked at them as well.
Additionally, sometime ago we started a project using Freescale's CodeWarrior Development Studio (that project was significantly more complex than the project in this column), but we discovered we would need to pay for support to obtain the response that we needed. Add another bias to my psychology.
Now, I will be the first to tell you that I am a fan of PSoCs (Programmable SoCs) from Cypress Semiconductor. I have worked on many smaller projects with the PSoC 1 and one large project with the PSoC 5; also, I had heard some hype about the PSoC 4, which is ARM Cortex-M0-based. I looked at the price of the PSoC 4 and I was pleasantly surprised.
Fortunately, my project had some maneuverability on price, and I am aware that the flexibility of the PSoC configuration normally has some payback with the reduction of external devices. Of course, we already have the emulator and some experience, so I decided to look into this device further with the aid of the PSoC 4 Pioneer Kit (Arduino shield compatible). This kit uses the versatile PSoC 4200 family, so that was the starting point of my project.
Cypress provides a great development environment called PSoC Creator, which allows you to configure, program, and debug their products (there is a very useful series of video series on using PSoC Creator).
The PSoC architecture sits somewhere between an MCU and an FPGA. In addition to the processor core, it has some configurable analog circuitry along with some programmable digital fabric, although this fabric is not as granular as one would find in an FPGA. You also get a whole bunch of IP with the device (termed "components") that allow you to configure the device to perform the functions you require. One aspect of the development environment is illustrated in Figure 1.
Figure 1. Starting to place the components
(Click here to see a larger image.)
You need an ADC? Just choose it from the component selection area along the right and plonk it down. You want a PWM? There you go. An opamp and/or an SPI controller? You're welcome. Connect them together as you would on a schematic. Choose what pins to associate with the various functions, compile the hardware, and you are ready to write your application. Each component that you place has its code and headers placed in the "Workspace Explorer" (shown on the left in Figure 1) alongside your code. All the API calls are included in the header files and you can simply copy and paste into your code. You can see the symbol in the bottom right hand corner with the option to "Open Datasheet" (please forgive the eyestrain). Each component has its own data sheet that you can access before you place it, or by right-clicking after you've placed it.
PSoC Creator, which includes a Keil C compiler, is free. Support is also free. As an added bonus (here is my prejudice again), this system is not Eclipse-based. If you really want to be adventurous, you can create mini-state machines and other functions in hardware using a technique Cypress calls "datapaths." You can even use Verilog if you know what you are doing.
In my next column I will use my project to describe the design process in a little more detail. In the meantime, I welcome any questions or comments.