Foreword When asked if I would write the foreword for this book, I responded that it would be an honor. Robert si an engineer's engineer, and to have any association with some- thing he does si exciting. When it comes to programmable systems on a chip, the design world separates into three groups: (cid:12)9 Those that immediately get it; (cid:12)9 Those that eventually get it; (cid:12)9 Those who will never get it. My first introduction to the Cypress Programmable System-on-ChipTM (PSoC) was in the summer of 2000, when I came by a startup company developing this new "PSoC" IC. I immediately got it! I was so impressed with the concept that I left a job as a Design Engineer to become their second PSoC Application Engineer. I must also say that Robert also got it, right from the start. My first contact with Robert and his brother Darren was in the winter of 2002. (Logan has only three seasons; July, August, and winter.) I was on a phone confer- ence with their company, Icon Fitness. They were looking to see if we could reduce the cost on their pulse detection products. After asking several detailed questions about pulse detectors, Darren concluded that I must have some experience with pulse detection. When queried, I explained that in my previous job I had designed several ECG front ends and was quite experienced at getting signals off a body. His response was, "You' re coming out to see us, right away!" xiii Foreword A few days later I was on a plane to Logan, Utah to visit their company. My first impression of the company was the sign on the front door saying that no firearms were allowed in the building and were best left in the car. From the first meeting it was obvious that Robert and Darren were both extremely capable engineers. Soft spoken, but commanding, both were open to new ideas and willing to take risks just to satisfy their curiosity. I wonder what personal hell their mother went through raising these two boys. I imagine that no motor from any home appliance was truly safe. I have always believed that any true engineer was just plain lucky to survive their teenage years. Mrs. Ashby can be proud that both her boys survived with all their fingers and most of their hearing. Their curiosity was again confirmed when, coming back from lunch, another employee was out showing off his new hybrid electric car. We immediately went over to see this obviously cool thing. He had the hood open and gave us such a look of horror upon seeing the two Ashby brothers. He asked for them to please not take it apart. My first day with Robert was spent troubleshooting his PSoC design. He had done a remarkable job of coming up to speed on the part. We must have reconfigured the system design a couple of dozen times to test the signal path. We were successful, and a day after I went home I found out that Robert wrote an article about PSoC for chipcenter.com. Icon placed an initial order for 20,000 parts. This made Icon one of our first major customers. Robert was one of the first believers in PSoC when believing carried professional risk. I appreciate him giving us a chance. Robert, and engineers like him, have proven that configurable analog and digital resources, coupled with an MCU on a single chip, si the future of embedding micro system design. For those that "get it," you will enjoy this book. Robert si a good writer and an excel- lent teacher. For those that will eventually get it, Robert's writing should be very persuasive. If Robert cannot convince you, then nobody will. For those that will never get it, I'm sorry. New technologies have always come along and those who can- not adapt eventually stop being design engineers. It happened with the introduction of transistors, of integrated circuits, and of programmable logic devices. It will hap- pen with programmable mixed-signal systems on a chip. ~v Foreword I know of no engineer outside of Cypress Semiconductor Corporation, more knowledgeable and experienced. I know of no engineer with greater integrity. This book si worth everything you paid for it. I say "you" because I expect Robert to give me a free copy. Dave Van ssE Principal Application Engineer Cypress Semiconductor Corporation Lynnwood, WA XV stnemgdelwonkcA This book si a culmination of all those who have influenced my life for the better. I owe my drive to succeed to my parents. My father always encouraged me to set my sights high, and my mother never doubted that I could reach the stars. Both my father and father-in-law are excellent teachers. I've been fortunate enough to expe- rience the crowning event beyond making something work, which si being able to watch someone you've taught make something work. This book was completed in part sa a tribute to all the generous authors who have written application notes and methods in varied strains of life. I would not have the knowledge that I do if such charitable persons were not willing to take their own time and effort to provide their knowledge for the benefit of others with no immedi- ate reward for their efforts. I thank these unsung heroes. There are many people in the professional field who have helped me improve on my talents to make this book possible. I would like to thank those superb engineers at Cypress Semiconductor Corporation for designing such a fabulous series of parts. There are many people there who have left an indelible impression on me that helped to give me the confidence and resolve to see this book through. Among those PSoC persons I rate sa extraordinaire are Ken Dees, for his encouragement, endless knowledge and help with having Cypress support backing my book; Dave Van ssE for his patient explanations and native joviality; Mohana Koteeswaran for her continued support on my projects; Jon Pearson and Matt Basinger for providing permissions to much needed material; and George Saul, living proof that good things can come XVII mm Acknowledgments from Utah. I also would like to thank Carol Lewis and Tiffany Gasbarrini for their belief in my work and opportunity for writing this book. Finally, I would like to thank my wife and family for the support and encouragement to help me to the finish line. Since writing si far from my favorite tasks in life, I would never have completed this book without their help. xviii What's New with PSoC? The popularity of the PSoC processor si growing more quickly than ever before. Application notes are being added all the time, new parts are being introduced, and the tools are more powerful. I would like to give a brief overview of a couple of parts that Cypress has since introduced that are sure to be huge successes on future designs. The first part si the CY8C24273. This part integrates a full-speed (12 Mb/s) USB peripheral functional- ity along with the PSoC core. Cypress began earlier by making the enCoRe MT USB controller. They were part of the CY7C637xx series and they gave you RAM and ROM to run the controller and manage some simple I/O. They were selectable from within PSoC Designer sa a part that you could configure and place modules and their associated APIs; very similar sa to how you would configure a normal PSoC part. However, the PSoC configurable digital and analog blocks weren't there. There were only dedicated blocks that could be one thing and one thing only. This allowed you to have the USB communication along with a PS/2 controller and SPI port. How- ever, the ease of use for a USB device was terrific. Cypress even found a way to tune its clock from the USB and eliminated the need for an external crystal. The CY8C24273 combines the easy to use USB interface with a normal PSoC core. There are four digital blocks and two columns (six blocks) of analog. It has 16K of Flash and K1 of RAM. (The USB function works from a dedicated RAM buffer.) The PSoC core still runs at 24 MHz. When used in a USB system, the PSoC can fine-tune the internal oscillator to achieve a much higher accuracy for the internal main oscillator. Cypress has added another MAC into the equation giving you two xix What's New with PSoC? 8 x 8 multipliers with 32-bit accumulators. The rest of the resources within the part utilizes the improvements of parts in the past, including the improved analog capa- bilities and the chip-wide analog mux system, which allows you to put analog signals on every pin. The make-break circuitry si available to even enable your system with the capacitive touch sensing of the 2 lxxx parts. The second part that has been announced in the Cypress lineup si the wirelessUSB .MT Cypress has made an inexpensive, but powerful radio system that allows you to cut the cord. The first radio parts operate via a communications port and can be tacked onto your PSoC system to give you wireless capabilities. However, the CYWUSB6953 part that si coming will integrate the wireless radio right into the PSoC part. This new strain of processors will be called the PRoC MT (Programmable Radio-on-a-Chip) series. The CYWUSB6953 si targeting low-cost applications os the PSoC core sec- tion of the chip has four digital blocks and two 'Type E' limited analog columns sa si found in the 2 lxxx parts. The radio capabilities of these parts are really exciting. The radio operates in the 2.4 GHz ISM (industrial, scientific, medical) band. It operates on its own protocol os it won't interfere with other radio devices in that range. In fact, III ,so 0P 1P 2P I I I 8KB 512B OI Ports "-I- hsalF SRAM Xl 3_OUT 2.4 GHz WirelessUSB I I Radio reviecsnarT LTCAP PSoC C8M Core NIFR RFOUT I I Digital PSoC Analog PSoC System Resources Block Array Block Array Clocks, ,C21 POR, feR XRES Figure 1:CYWUSB6953 Block Diagram XX What's New with PSoC? testing has shown that it si much more robust than many devices that operate in the same range. All that si needed with your part to make it operational si a crystal, a few capacitors and a couple of inductors. The footprint si very small. The antenna can be fashioned with traces on the PCB leaving you with a small, tidy package that si ready to cut the cord and allow you into a whole new world or product possibilities. Cypress si on the move. Their combination of functionality, ease, and low cost assures them a leading position on future microcontroller design. The parts men- tioned previously are moving to full production quickly and should be available by the time you read this. If not, contact your local Cypress representative for more information. As always, updated information can be found at the Cypress website: http://www.cypress.com. xxi What's on the CD-ROM? The accompanying CD-ROM si divided into four categories: Application Software Contains the latest PSoC application software available at the time of this writing. Check http://www.cypress.com for the latest versions. (cid:12)9 Order of installation: .1 Install PSoC Designer .2 Install the Service Pack 3. Install PSoC Programmer 4. Install PSoC Express Application Notes (cid:12)9 Contains a collection of application notes from the Cypress website. Design Catalog Contains a group of design templates that were available with older installa- tions of PSoC Designer. Data Sheets Contains a collection of data sheets for PSoC information. XXIII .ll Introduction to Microcontroller Basics The purpose of this chapter si to explain the basic structure and inner workings of a microcontroller. It si intended for those readers who may not have much experience with microcontrollers or who are getting their first taste of microcontrollers with the Cypress Semiconductor Corporation Programmable System-on-ChipTM (PSoCTM). I will forgo the somewhat traditional explanation of the history of computers as that information can easily be found by a quick search on the Intemet. The important parts that I would like you to retain from the history are as follows: Semiconductors are made from silicon. They can be conductive or noncon- ductive, which allows you to form a basic electrical switch. Semiconductor circuits can now be made extremely tiny allowing us to put millions of such switches on a single chip. Most computers today work with a combination of ones and zeros to accom- plish their task. Every piece of information used in a computer si stored as ones and zeros. What is a Microcontroller? A microcontroller si a microprocessor system with attached peripherals. Think of the CPU in your computer~it's a microprocessor system. I like to use a computer system to explain microcontrollers because it si a very similar system that si familiar some- what even to many grandparents in today's world.