You are on page 1of 41

Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC, free


← Previouos chapter | Table of Contents | Next chapter →

Chapter 1: Introduction to PSoC
From the free online book “Architecture and Programming of PSoC Microcontrollers” Introduction 1.1 System Overview 1.2 CPU 1.3 Frequency generator 1.4 Microcontroller power consumption 1.5 Reset 1.6 Digital inputs and outputs 1.7 Analog inputs and outputs 1.8 Accessing programmable digital blocks 1.9 Global input lines 1.10 Digital programmable blocks 1.11 Analog programmable blocks 1.12 Referent voltage generators 1.13 Switch mode pump 1.14 MAC 1.15 Decimator 1.16 I2C controller 1.17 Interrupt controller 1.18 Address space

When developing more complex projects, there is often a need for additional peripheral units, such as operational and instrument amplifiers, filters, timers, digital logic circuits, AD and DA convertors, etc. As a general rule, implementation of the extra peripherals brings in additional difficulties: new components take space, require additional attention during production of a printed circuit board, increase power consumption... All of these factors can significantly affect the price and development cycle of the project. The introduction of PSoC microcontrollers has made many engineers’ dream come true of having all their project needs covered in one chip.

PSoC: Programmable System on Chip
PSoC (Programmable System on Chip) represents a whole new concept in microcontroller development. In addition to all the standard elements of 8-bit microcontrollers, PSoC chips feature digital and analog programmable blocks, which themselves allow implementation of large number of peripherals. Digital blocks consist of smaller programmable blocks that can be configured to allow different development
1 of 22

12/20/2008 6:05 PM

Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC, free


options. Analog blocks are used for development of analog elements, such as analog filters, comparators, intrumentational (non–)inverting amplifiers, as well as AD and DA convertors. There’s a number of different PSoC families you can base your project upon, depending on the project requirements. Basic difference between PSoC families is the number of available programmable blocks and the number of input/output pins. Number of components that can be devised is primarily a function of the available programmable blocks. Depending on the microcontroller family, PSoC chips have 4–16 digital blocks, and 3–12 analog programmable blocks.

Characteristics of PSoC microcontrollers
Some of the most prominent features of PSoC microcontrollers are: MAC unit, hardware 8x8 multiplication, with result stored in 32-bit accumulator, Changeable working voltage, 3.3V or 5V, Possibility of small voltage supply, to 1V, Programmable frequency choice. Programmable blocks allow you to devise: 16K bytes of programmable memory, 256 bytes of RAM, AD convertors with maximum resolution af 14 bits, DA convertors with maximum resolution of 9 bits, Programmable voltage amplifier, Programmable filters and comparators, Timers and counters of 8, 16, and 32 bits, Pseudorandom sequences and CRC code generators, Two Full-Duplex UART’s, Multiple SPI devices, Option for connection on all output pins, Option for block combining, Option for programming only the specified memory regions and write protection, For every pin there is an option of Pull up, Pull down, High Z, Strong, or Open pin state, Possibility of interrupt generation during change of state on any input/output pin, I²C Slave or Master and Multi-Master up to speed of 400KHz, Integrated Supervisory Circuit, Built-in precise voltage reference.

Is PSoC good enough for my project?
Perhaps the best way to recognize the true value of PSoC microcontrollers is through comparison with other options. Major advantages of PSoC microcontroller include the following: There is no other microcontroller that has programmable voltage, instrumentational, inverting, and non-inverting amplifiers; Hardware generators of pseudorandom and CRC code, as well as analog modulators, are unique to PSoC families;
2 of 22

12/20/2008 6:05 PM

Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC, free


MAC (Multiply-accumulate) is an essential part of digital signal processors, which allows implementation of digital signal processing algorithms. It’s worth noting that hardware accumulator multiplication is not a common feature of 8-bit microcontrollers; Having the advantage of changeable working voltage doesn’t really need a comment. This feature is particularly important for development of new devices as it eliminates the need for redesigning the PCB and implementing the level translator; Option for low voltage supply (~1V) is a tremendous advantage in battery operated systems; Timers, counters, and PWM units are more flexible than the usual implementation; Automatic code writing for accessing all the peripherals in use; In case you need a larger array of components, there is an option for dynamic reconfiguration, allowing you to change peripherals during run-time. In this way, it’s possible to minimize the processor workload at an time, leaving the largest part of the job to the specialized hardware. On the other hand, there are certain limitations of PSoC that could influence the choice of microcontroller for your design. In systems which require highly precise or fast measurement, problems may occur with analog device characteristics. In this case, you should analyze if speed of AD convertors and offset/noise of analog amplifiers are able to satisfy the project demands. Analog components do not have the ability to work with usual negative supply voltage. For example, zero voltage for inverting amplifiers is taken to be the analog ground AGND (usually 2.5V). All voltages above AGND are taken as positive, while voltages below AGND are taken as negative. Most PSoC microcontrollers have 256 bytes of RAM, which could prove to be insuficient for some projects.

1.1 System overview
PSoC microcontrollers are based on 8-bit CISC architecture. Their general structure with basic blocks is presented in the following image:

3 of 22

12/20/2008 6:05 PM

Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC, free


CPU unit is the main part of a microcontroller whose purpose is to execute program instructions and control workflow of other blocks. Frequency generator facilitates signals necessary for CPU to work, as well as an array of frequencies that are used by programmable blocks. These signals could be based on internal or external referent oscillator. Reset controller enables microcontroller start action and brings a microcontroller to regular state in the case of irregular events. Watch Dog timer is used to detect software dead-loops. Sleep timer can periodically wake up microcontroller from power saving modes. It could be also used as a regular timer. Input-Output pins enable communication between the CPU unit, digital and analog programmable blocks and outside world. Digital programmable blocks are used to configure digital programmable components which are selected by user. Analog programmable blocks are used to configure analog components, like AD and DA converters, filters, DTMF receivers, programmable, instrumental, inverting, non-inverting and operational amplifiers. Interrupt controller handles necessary operations in the case of interrupts. I2C controller Enables hardware realization of an I2C communication. Voltage reference is vital for the work of analog components that reside inside of analog programmable blocks.
4 of 22

12/20/2008 6:05 PM

CPU fetches one instruction at a time from program memory. [back to the top] 1. SMP is a system which can be used as a part of a voltage regulator. subtracting and shifting (left or right). that are associated to instruction execution process. Data handled by instructions could be stored in internal registers A and X. which is used for arithmetic operations like addition. Arithmetic logic unit (ALU) is a standard part of a CPU. Internal Registers of CPU Program counter (PC) is used as a pointer to the next program instruction that should be executed. Also. decodes it and executes appropriate operations. while Carry (C) marks that there has been carrying during arithmetic or logic operations. When these instructions occur value stored in SP is internally incremented or decremented. It also has a role during selection of a RAM memory page in case when PSoC microcontroller has more than 256 bytes of RAM.Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC. X and F. Index register (X) could behave as register A in large number of instructions. instructions are stored in program (FLASH) memory in a way which is familiar to microcontroller. With each new instruction value of program counter is being set to point on the next instruction in program memory. Accumulator register (A) is the main register which handles all arithmetical. which is going to be decoded and executed. Stack pointer (SP) points to the address of SRAM memory where data is written to or read from in case of PUSH and POP instructions respectively. logical or data transfer operations. CPU unit has internal registers PC. it is possible to supply power to a PSoC microcontroller from a single 1.2 CPU During the programming. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC).htm MAC unit is used for operations of hardware signed multiplication of 8-bit numbers. SP.5V battery. as well as ALU unit and instruction decoding unit. For example. Flag register (F) contains bits which describe result of a previously executed instruction. register X is used in the case of index addressing. A. as well as logic operations. Bit Flag Zero (Z) marks that accumulator stores a zero. or in RAM data memory [back to the top] 5 of 22 12/20/2008 6:05 PM .

CLK32K is a slow signal with a frequency of 32kHz. which varies in range between 1 and 16. It is used as a reference clock for most of other signals. 24V1 is a signal derived by dividing frequency SYSCLK with parameter N1. 24V2 signal frequency equals SYSCLK/N1N2. CPU_CLK is used as a CPU unit frequency which has a direct impact on instruction execution speed. which varies in range from 1 to 16.N2=1). 6 of 22 12/20/2008 6:05 PM . which means that possible frequency ranges from 93. SYSCLK is the main internal clock signal with a speed of 24MHz. as well as programmable blocks. Frequency 24V1. 24V2 is a signal derived by dividing 24MHz frequency with parameter N1. Each of programmable components has certain demands regarding speed. in the range from 1 to 256. 24V1. which is done by graphically selecting appropriate parameters. 24V1 frequency equals SYSCLK/N1.. CPU_CLK can have any of eight frequencies that are in range from 93.Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC. SYSCLKx2 is a clock signal with double frequency (48MHz) of SYSCLK signal.htm 1. It can also be used for Sleep timer wake-up operation in the case when other SYSCLK derived signals are inactive. Picture shows two independent systems for generating signals SYSCLK and CLK 32k.75MHz to 24MHz. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC). SYSCLK or SYSCLKx2. PSoC microcontrollers have a system for generation of different frequency signals.3 Frequency generator Frequency generator is vital to CPU unit functioning.5MHz (N1=16) to 24MHz (N1=1). 24V2. with number N.75kHz (N1. It can be used as a programmable component input. 24V3 and CPUCLK selection is done easily. 24V3 signal is derived by dividing frequency of one of the signals 24V2.N2=16) to 24MHz (N1. with a frequency from 1. by setting appropriate parameters in Device Editor or during program runtime by selecting three lower bits of OSCCR0 register.

External frequency ranges from 1 to 24MHz.4 Microcontroller power consumption Processor signal frequency CPUCLK is directly connected with the instruction execution speed of the microcontroller. is the limit factor in a precise timing applications. Fault tolerance of 2. while CLK32K signal is acquired through internal local oscillator (ILO). which is a compromise between speed and consumption. After waking microcontroller does all needed operations after which it’s being switched back to sleep mode and waits for another sleep timer interrupt.5% in the case of internal frequency generation. On the other hand. There is a appropriate type of interrupt needed to wake the microcontroller from sleep mode. Saving is achieved because of all the frequencies. brought to beginning state. Because of these problems general rule should be applied.htm Signal SYSCLK can be acquired using internal main oscillator (IMO). program executes approximately twice faster. It connects to PSoC through pin P1[4]. Microcontroller could be woken up from sleep mode only by reset or a interrupt. which is one of the main problems it the case of battery supply. which says that lowest possible satisfactory frequency should be used. Doubling the frequency. Main disadvantage in rising the frequency is it’s unwanted effect on microcontroller power consumption. after which is necessary to satisfy appropriate procedure. or more precise external 32kHz oscillator. Also GPIO pin or analog column interrupts can be used for CPU waking-up. Default value of PSoC microcontroller signal frequency is 3MHz. which may affect on surrounding devices. as said before. In such case external SYSCLK clock reference should be used. To maintain the longest possible uninterrupted work time.Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC. Similar situation is in the case of CLK32K.5 Reset 7 of 22 12/20/2008 6:05 PM . except CPU32K and SLEEP become inactive. In the both cases microcontroller starts with internal frequency generators. or in other words. Interrupt could be generated by a sleep timer or some digital block which use CPU_32k frequency. Most of microcontrollers operate only periodically. which also can be generated by internal local oscillator (ILO). higher frequency doesn’t necessary always mean better overall performances. while being in the idle state for the most of their time. Because of possibility for various irregularities to occurs during the work of microcontroller there is a need to reset it in those cases. Other disadvantage of higher frequency is more intensive generation of electromagnetic interference. while processor stops instruction execution. [back to the top] 1. Sleep timer frequency interrupt ranges from 1 to 512Hz. Sleep timer represents a special counter whose main role is to generate periodic interrupts which enable waking microcontroller from power saving mode. Begin state means all internal registers are initialized and program continues its execution from beginning. Major power saving can be achieved by bringing microcontroller to sleep mode while microcontroller does no important role. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC). it is an imperative to bring power consumption to its lowest satisfactory functional level in battery operated devices. [back to the top] 1.

[back to the top] 1. WDR Watch dog reset (WDR) is used for avoiding software dead-loops or other irregularities. write and read operations are done in the same way in any case. 8 of 22 12/20/2008 6:05 PM . and WDR occurs. Port access registers are stored inside of register address space noted as PRT0DR. because microcontroller can make some unpredictable actions. Although port number differs from the type of the microcontroller. PRT2DR.htm POR During the work of microcontroller. bringing the system in the start state.Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC. PRT3DR. In the case of such voltage drop detection.6 Digital Inputs and Outputs Connection between a PSoC microcontroller with an outside world is achieved over input-output pins. XRES External reset allows user to bring microcontroller to start state by switching a button. In normal mode after certain time WDT is being restarted once again and subprogram cycle continues. supply voltage variations occurs. But. PRT4DR or PRT5DR. It is very dangerous if voltage drops beneath certain limit. Eight pin group which could be accessed simultaneously are parts of one port. Using WDR. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC). Reset is achieved when XRES pin reads logic ONE. PRT1DR. Simplest reset circuit can be made with pull-down resistor and one switch. microcontroller is switched into Power on Reset mode in which it remains until voltage stabilizes above critical limit which is defined by Trip Voltage parameter. if program blocks in one of the subprograms WDT is not reset. after which appropriate subprograms are executed. it is watch dog timer (WDT) is periodically restarted inside of a main program.

over pull-up or pull-down resistors or through open drain output. DM1 and DM0. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC). Init circuit can pass the signal from PRTxDR register directly (strong). which enables connection to different types of devices.htm Writing to port Writing value to PRTxDR initializes register which through init circuit drives the state of pins. Pin work modes are defined according to the following table depending on contents of appropriate bit from registers DM2. Beside that. PRTxDM1 and PRTxDM0. Reading port Reading value from address PRTxDR digital state of voltage on pins is stored to register A. There is eight methods to initialize pins in total. read value could differ from voltage on PRTxDR register. Drives High Hi-Z Slow Strong Drive Strong (Slow) Strong (Slow) High Impedance Analog Hi-Z Hi-Z 9 of 22 12/20/2008 6:05 PM . DM2 bit DM1 bit DM0 bit Mode 0 0 0 Resistive Pull Down 0 0 1 Strong Drive 0 0 1 1 1 1 1 0 0 1 0 1 0 1 0 Data = 0 Resistive Strong Data = 1 Strong Strong Hi-Z Resistive Strong (Slow) High Impedance Hi-Z Resistive Pull Up Strong Open Drain. Drive Mode Selection of the way in which init register PRTxDR is connected to pins can be set inside of Device Editor or during runtime initializing registers PRTxDM2.Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC. there is a possibility to isolate value of register from pin state (Hi-Z). In case that voltage is dictated by some external device. with considerate smaller amount of external components.

This mode is convenient for realization of a line which signals if there has been a mistake to one of the microcontrollers. This way of connection is applied when pin is used as an input. [back to the top] 1. Pins on PSoC microcontroller allow user to generate interrupt on any pin. Pull-up or pull-down resistors are used when connecting with buttons or some other devices which demand this type of components. when signal changes. all internal connections between PRTxDR register and pin are disconnected. when used pull-up resistor version when zero (error) occurs on any of output pins state of this line will be zero.htm DM2 bit DM1 bit DM0 bit Mode Data = 0 Data = 1 1 1 1 Open Drain.7 Analog inputs and outputs Some of input-output pins. Analog Hi-Z mode is used when connecting analog signals. For example. like AD converter input. so not to interfere with value of brought voltage. These resistors are defining the state on input when button is not pushed. Open drain mode is used when it is needed to bring several devices to the same line. Drives Low Strong (Slow) Hi-Z Strong mode is used when it is needed to connect the state on PRTxDR register directly to pins.Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC). beside their standard use can perform analog input or output operation. or on signal rising or falling edge. Any pin of 10 of 22 12/20/2008 6:05 PM . when it is needed to add one external pull-up or pull-down resistor. In this case.

line GIO_0 can connect only to zero pin of some of the odd index ports (P1[0]. Outputs from analog blocks can be connected to 4 output buffers.P3[0].P5[0]). Pins P2[4] and P2[6] can serve as external referent voltage inputs.8 Accessing programmable digital blocks Digital components. It is done in a way shown on following picture. [back to the top] 1. which depicts group of four digital programmable blocks.P0[3]. which are connected to P0[2]. [back to the top] 1.Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC. two or four digital programmable block groups like this one depending on their family. aren’t connected directly to input or output pins. PSoC microcontrollers can have one. while in case of port P2 they are connected directly to programmable SC blocks. As it could be seen. Rule of connection is that it is possible to connect only between a line and a pin which have the same index. 11 of 22 12/20/2008 6:05 PM . pin connection is established using global connection lines. For example.htm port P0 as well as lower four pins of port P2 can be used as analog input. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC). depending on weather they can connect to ports with odd (GIO) or even (GIE) index. multiplexer and lines of programmable blocks. Global input lines are divided in two groups.P0[4] and P0[5] pins. Inputs of port P0 are connected to analog blocks over analog multiplexers.9 Global input lines Global input lines establishes connection between the pins and input multiplexers. which are stored inside of programmable blocks.

which enables custom hardware adjustment of the system for specific uses. communication components like Rx. but at first is necessary to understand the way those components function. On the other side. like counters. [back to the top] 1. PRS and CRC generators can be stored inside of any free block. Picture shows that input block lines can be connected to GIO or GIE lines with same index. PRS.10 Digital programmable blocks Inside of digital programmable blocks user can configure components like timers.htm Input multiplexers of block lines Input multiplexer selects one of global lines and connects it to signal carrying line which leads to programmable blocks. or with index with offset four. UART and SPI can be set on the right side of the programmable blocks. counters.Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC. Most components. 12 of 22 12/20/2008 6:05 PM . CRC generators and devices for SPI. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC). Tx. PWM. IrDA and UART communication. The process of setting and connecting using PSoC Designer is very simple to understand.

VC3. Component input signal Most of the components. SPIM/SPIS 2 Counter16. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC). PWMDB8. Timer24. Timer32 Frequency signal (CLK) Frequency signal is needed for digital components to work. Depending on wanted speed there is a range of several built-in frequencies to choose from: internal signal frequency VC1. outputs from Counter.VC2 and VC3 could not offer specified frequency.htm The number of necessary blocks which are used for component configuration shown in the table: Number of blocks Components 1 Counter8. PWM8. Timer or PWM. PRS16. CRC16. RX8/TX8. In case that signal needs to be routed across several blocks. There are different possibilities in selection of the component input signal: 13 of 22 12/20/2008 6:05 PM . because when used with different prescalers. Picture above shows in dotted line direct way to connect output of previous block with the input of the next block. VC2. PRS8. CPU_32 output from adjacent blocks common Broadcast line (BC) input (RI) or output (RO) block lines Most common internal signals are VC1. connection is done over common frequency line BC. they offer broad range of possible frequencies. UART. which can be used like like additional prescalers. Timer8. For example. PWMDB16 Counter32. SYSCLKx2. IrDARx/IrDATx 3 4 Counter24. beside frequency signal. In case that signals VC1. Timer16. PWM16. in the case of a counter and PWM generator input is used for enabling counting.Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC. has one or two digital inputs. VC2 and VC3.

which can make connection to one. Line of programmable blocks with some index can be connected to GOO or GOE lines with same or by four higher index. Signal could be routed from output lines further toward output of the microcontroller or input of some other component. which is a case of external signal block output lines (RO). Output drivers Logic circuit output can be routed to four output drivers. They are separated in two groups. which enables additional processing of the input signal. OR or XOR over input signals which could be inverted previously. global output lines. or more. Output multiplexers are used for connecting lines of programmable blocks with global output lines. depending on where they can be connected to ports with odd (FGIO) or even (GIE) index. Beside that there is a possibility to establish a connection between input and output lines. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC). Multiplexer Depending on the state of multiplexer.Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC. Logic circuit Selected signal can be brought to the output of logic circuit. 14 of 22 12/20/2008 6:05 PM . As other input could be used some of adjacent lines of programmable blocks (RO). output (RO) or input (RI) line of programmable block could be connected.htm block input lines (RI). Global output lines makes connection between drivers and pins. Rule of connection says that only lines and pins with the same index can be interconnected. in the case of component cascading analog block comparator lines signal of logic one(high) signal of logic zero (low) Component output signals Digital outputs of the component are used for connecting programmable blocks with output lines RO. Logic circuit can: pass one of two signals invert input signals do logic operations AND.

as analog inputs could be used four lower pins of port P2. one frequency line. Each column has input multiplexer.Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC. output analog and a comparator line. while two middle columns have the ability to choose either pins of port P0. Multiplexers can select even (Port0_even) or odd (Port0_Odd) pins. 2 or 4 analog columns. there could be 1. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC).11 Analog programmable blocks Analog programmable blocks are grouped in columns of three programmable blocks. Depending on family of microcontroller.htm [back to the top] 1. This pins can be connected directly 15 of 22 12/20/2008 6:05 PM . Analog inputs of port P2 Beside port P0. Analog multiplexers of port P0 Signals from port 0 are connected to analog ACB blocks over appropriate input multiplexers.

Depending on interconnections made inside of ACB blocks.htm to analog programmable blocks. It should be noted.Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC. Comparator output could be connected to digital blocks (most common way of doing it is as counter signal. Outputs of these blocks can be routed to some of adjacent blocks. Analog columns One column of analog blocks is made of three types of blocks: ACB. 16 of 22 12/20/2008 6:05 PM . DA and analog filters could be implemented depending on configuration inside of these blocks. As inputs to SC blocks. that signals from analog multiplexers couldn’t be brought directly to SC blocks. through a buffer. there is a possibility to modify or combine comparator output of some column (A) with next comparator line (B). Comparator outputs Every analog column has one comparator line. ACB blocks are used to store amplifiers with rail-to-rail inputs and outputs. Analog output lines can be are connected. They contains amplifiers with rail-to-rail input and outputs. to which could be connected digital output from one of analog blocks. noninverting. Frequency signal Many components. which affects the component’s speed. using some logic operation. Frequency signal selection done over appropriate multiplexers. DA convertors and filters. input from some adjacent block could be used. or timer). Analog outputs For every analog column is common to have an AnalogOutBus line. but over ACB blocks. such as AD. ASC i ASD. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC). digital controlled resistors and internal multiplexers. AD. need to have a frequency signal in the specific range. to four middle pins of port A. As input to ACB blocks can be used analog multiplexer or output signal of some of adjacent blocks. it is possible to implement inverting. ASC and ASD blocks are of switched capacitor (SC) type. condensators and internal multiplexers. Before connecting. instrument amplifier or comparator. output analog line or comparator line.

RefHi and RefLo represent referent higher and lower voltage. Referent voltages are made from internal temperature stabilized bandgap voltage reference Vbg = 1. This enables simple adjustment to different types of voltage sensors. PSoC microcontrollers have a system that can generate several referent signal values AGND. most commonly counter timer and PWM generator.12 Referent voltage generators There are three stable voltage generators in PSoC microcontroller: AGND RefH RefLo AGND is ground voltage for analog components. while less are negative. supply voltage VDD or external signal as shown in the following table. for AD and DA components. Voltage values higher than AGND are considered as positive.htm For each of the columns it is possible to select: internal frequency VC1 internal frequency VC2 output over some of the digital blocks. PSoC microcontrollers have one-side power supply. 17 of 22 12/20/2008 6:05 PM . [back to the top] 1. PSoC microcontrollers are well adjusted to work with battery supply. which is selected through the multiplexer.Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC. RefHi and RefLo. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC). so value of analog ground is somewhere in between GND and VDD.3V. AGND value is selected by user.

8/2.16 3.65 1. inductivity and a capacitive.2 2.htm Ref Mux Vdd/2 ± Vbg Vdd/2 ± Vdd/2 Vbg ± Vbg 1.2 [back to the top] 1.3 1.2 5.9 3.5/1.95 2. beside battery. a diode.2 0 0 0 1.6 2.13 Switch Mode Pump In the case of battery suply Switch Mode Pump (SMP) system can be used.2/0. This type of convertor gives voltage supply value higher than battery voltage.Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC.6Vbg ± 1. For SMP to function properly.5 3.0/3.3 2.6Vbg 2Vbg ± Vbg 2Vbg ± P2[6] P2[4] ± Vbg P2[4] ± P2[6] AGND [V] RefLo [V] RefHi [V] 2.6 3.5/1.35 3. which makes possible power suplly with 1. [back to the top] 18 of 22 12/20/2008 6:05 PM .6 0.08 2.6 4.3 2.5V battery. it is necessary to connect. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC).6 2. Its operation is based on principle of BOOSTDC/DC convertor.9 1.65 1.

result can be added to previously stored value inside of 32-bit accumulator. and reading output from 16-bit result from registers MUL_DH and MUL_DL.reg[MUL_DH] A. For execution of these operations there is no special instruction.Initialize X = -2 . but all of the work is done by writing to and reading from certain registers.reg[MUL_DL] reg[MUL_X].file: main.htm 1.0xFE reg[MUL_Y].Read low byte of result (0xB0) . convolutions and filtering.reg[MUL_DH] A.0x03 A. 19 of 22 12/20/2008 6:05 PM .Initialize X = 100 . In that way is made sum product operation.Read low byte of result (0xFA) Sum of products During multiplication.asm .project: MAC mov mov mov mov mov mov mov mov reg[MUL_X].0x0C A.0x64 reg[MUL_Y]. Hardware multiplication Multiplication operation is done by writing 8-bit inputs X and Y into registers MUL_X and MUL_Y.Read high byte of result (0xFF) . which represents most important operation of digital signal processing for correlations.Read high byte of result (0x04) .Initialize Y = 3 . free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC).Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC.14 MAC MAC unit is a device that implements operation of hardware multiplication of 8-bit signed numbers. Beside that MAC unit allows simple implementation of multibyte multiplication.reg[MUL_DL] . .Initialize Y = 12 . as well as sum of product.

6 .(Acc = 0 + 5 * 4 = 20) mov reg[MUL_X]. Transfer speed: 50K.(Acc = 20 + 6 * 5 = 50) mov reg[MUL_X]. Result of product summing operation is stored inside of registers ACC_DR3. Most important operations of I2C controller are: Master or Slave.15 Decimator Decimator component is component that is used for digital data processing during sigma delta.(Acc = 50 + 3 * 2 = 56) mov reg[MAC_Y]. In the next example shows method of initializing input data.(0x46 = 70dec) .(Acc = 56 + 3 * 2 = 62) mov reg[MAC_X].asm .5 .file: main.reg[Acc_DR0] .5 . [back to the top] 1. ACC_DR2.16 I2C Controller I2C controller implements hardware serial I2C communication. and in that way minimizes usage of CPU units resources.project: MAC mov reg[MAC_CL0]. as well as some types of incremental AD conversion.Clear Accumulator mov reg[MUL_X].Initialize X and execute MAC .2 .2 .Initialize Y and execute MAC .Read low byte of result [back to the top] 1.Initialize X mov reg[MAC_Y].3 . Input data X and Y could also be initialized by writing into registers MUL_X and MUL_Y.Initialize Y and execute MAC .Initialize X mov reg[MAC_Y]. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC).Initialize Y and execute MAC .(Acc = 0) . in which case operation of product summing does not take place.0 .Initialize X mov reg[MAC_Y].4 .Initialize Y and execute MAC .Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC. sending or receiving data Byte level data processing Connected to CPU over interrupts or polling mode. .4 .(Acc = 62 + 4 * 2 = 70) mov A. ACC_DR1 i ACC_DR0. as well as operation of summing products. 100K and 400K Frequency synching in case of larger number of masters 7or 10-bit addressing of I2C unit [back to the top] 20 of 22 12/20/2008 6:05 PM .htm Summing products is done when data X and Y are initialized by writing into registers MAC_X or MAC_Y. Starting value of accumulator is set to zero by writing any value to register MAC_CL1 or MAC_CL0.

Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC. When it gets to instruction reti. program flow interruption by jumping to interrupt routine. pin state change). For later continuing of instructions execution. When interrupt occurs program execution is interrupted (hence the name) by jumping to part of the program that is called interrupt routine. Program counter is set to address of interrupt routine. Register PRTxIF is used as indication of GPIO interrupt on certain port. which will be discussed in more detail in examples part. Upon ending of that routine program continues from place in program where interruption took place.18 Address space PSoC microcontrollers have three address spaces: ROM RAM registers As in all Harvard architecture processors access to ROM memory is done with special lines. Every interrupt type can be masked or deleted. stack holds values of PCH. New interrupt occurrence is disabled by setting values of register F to zero (GIE = 0). as well as returning to interruption point from the routine. which is done with help of INT_MSK and INT_CLR registers.htm 1. interrupt controller stores interrupt type. Events could be internal (timer overrun. and program counter is reset to old value before interrupt occurred. after which execution jumps to interrupt routine address.17 Interrupt Controller Interrupts are mechanisms inside of a microcontroller that allow responding to some event immediately after its detection. values of F register are restored from stack. while PRTxIC1and PRTxIC0 are appropriate control registers. These operations are executed in several steps: 1. which marks return from main program. interrupt processing begins. 5. end of AD conversion) or external (character receiving over serial connection. PCL and F registers. so microcontroller is able to acquire instructions and access data at the same time. 21 of 22 12/20/2008 6:05 PM . 7. End of current instruction is awaited. 2. If interrupt is allowed and if global interrupt permit is set to 0ne (GIE = 1). When event that triggers interruption takes place. 4. Interrupt controller makes hardware interrupt detection. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC). which is same as interrupt type. Program executes interrupt routine instructions. 6. [back to the top] 1. 3.

free file:///D:/PSoC/Material/PSoC%20Chapter/chapter1(PSoC). PSoC. All Rights Reserved. it is possible access this part of memory. 22 of 22 12/20/2008 6:05 PM . which is written in this part of memory written by programming hardware. Register Register address space contains registers used for peripheral's global parameters and programmable blocks of a PSoC microcontroller. Program memory size depends on the family of PSoC microcontrollers and is 2. what is needed is to also state the name of the bank in which resides wanted register. Program memory is implemented in FLASH technology. user apart from 8-bit address must state appropriate page. 4. memory is organized in 256 byte pages. 16 and 32 kB. and PSoC Pros are trademarks of Cypress MicroSystems. With special instruction SSC. If you have any questions. PSoC Designer. in most PSoC microcontrollers. [back to the top] ← Previouos chapter | Table of Contents | Next chapter → © 1998–2005 mikroElektronika. Supervisory ROM Supervisory ROM is part of ROM which is used during start of PSoC microcontroller. Access to certain bank is done by using macros M8C_SetBank0 and M8C_SetBank1. which is used for storing program code. beside stating its name. RAM RAM enables storing of variables and stack which are used during work of microcontroller. as well as for calibration of components. please contact our office. Size of RAM.htm Program memory Program memory is the part of ROM. To access some variable. is 256 bytes. which delete or set bit XIO in CPU_F register. with stack residing on the last page. When microcontrollers have more than 256 bytes of RAM (series CY8C29xx and CY8C21x34). All other trade and/or services marks are the property of the respective owners.Chapter 1: Introduction to PSoC | Architecture and Programming of PSoC. PSoC microcontrollers have 512 registers. which are grouped in two 256 bytes banks. which allows simple development time change of the program inside of microcontroller. 8. To access some register. Inc.

counters. because differences are shown only in addition of new programmable components and some minor improvements. It is used for setting and connecting components and parameter adjustment. Device editor consists of two windows. but this book will still remain competent in case of newer versions. but during the course of this book it is only mentioned as an option. To open Interconnection View or User Module Select windows.2 Application Editor Introduction PSoC Designer is program package that leads user through all stages of developing project. [back to the top] 2. First one is for selection and is called User Module selection View. analog communications. appropriate graphical symbol would be shown in selected components slot.html ← Previouos chapter | Table of Contents | Next chapter → Chapter 2: PSoC Designer From the free online book “Architecture and Programming of PSoC Microcontrollers” Introduction 2. etc. Transfering from one to the other part of the PSoC Designer is done easily by clicking appropriate icon. Other. is called Interconnection View. Device Editor icon must be selected first. because it demands additional hardware.2. Lower image shows look of the programmable component choice window.Chapter 2: PSoC Designer | Architecture and Programming of PSoC. In the case of successful selection. The most important for user is is to get familiar with two main parts of PSoC Designer: Device Editor Application Editor Beside these two. or right-click on select.2 Interconnection View 2. necessary component for project should be selected with double-click. 1 of 9 12/20/2008 6:05 PM .1 Programmable Component Selection Most important part of the programmable component selection window is placed on the left side. After group selection. amplifiers. Components sorted in several groups. there is also a debugger part.1 Programmable Component Selection 2. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter2. Version discussed here will be 4. like AD converters.

Chapter 2: PSoC Designer | Architecture and Programming of PSoC. which gives information about block characteristics.html The rest of the window offers some other useful information. but really much simpler. because this part holds all necessary information. This important part of work can be done in Interconnection View window. you can be sure that it isn’t hard to master the way it is all connected. 2 of 9 12/20/2008 6:05 PM . 16-bit counter takes two programmable blocks. In the case of microcontroller of CY8C27xxx series. [back to the top] 2.2 Interconnection View Previously selected components are still unusable. Resource Meter shows how much space is left for new programmable blocks. and global purpose input/output lines. For example. until they are placed in digital or analog programmable blocks. User does not have to know by heart all details about the component he uses. and until appropriate parameters are set. Central part of this window is graphical representation of programmable blocks and connection lines. so it is possible to place 4 counters like this one altogether. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter2. In some way it resembles PCB routing. usage and code example. During selection of each of the components. in lower side of the window is opened detailed instruction. eight digital and twelve analog programmable blocks can be used. In the place between blocks there are internal lines for interconnection. Although this scheme looks complicated at first sight.

All global parameters have default values. When higher frequency precision is necessary it is possible to add external oscillator on lower two pins of port 1. but with more versatility. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter2. For example supply voltage can be 5V or 3. which means that even without setting microcontroller will be able to work.html Global Parameters On the upper left side can be found Global Resources window. and choose external as option in mentioned parameter. Supply Voltage parameter would be set on it's default value of 5V.Chapter 2: PSoC Designer | Architecture and Programming of PSoC.3V. Most important parameters for our examples are 3 of 9 12/20/2008 6:05 PM . It is used for general parameters selection. depending on selection in parameter Supply Voltage. Click on any of the parameters opens pull-down menu with given options. If user does not make selection.This method of setting is similar to configuration words on other microcontrollers.

This is of importance while working with devices like push-button switches. Component Parameters Central window on the left side is designated as User Module Parameters. then pin have standard input/output function. Pull-up or pull-down resistors must not be used on analog inputs. enables selection of possible clock signals. or ZERO. V2 and V3. and exiting programmable components. Acquiring signal V3 is done in similar fashion. by dividing some signal with value in N3. At a later point. but is however desired.html internal frequency prescaler values of V1. V1 signal frequency value can be derived by dividing system frequency of 24MHz with prescaler N1. which set default logic state of pin to ONE. In the picture below example for setting up component PWM16 is represented. Obligatory part of parameter are signals that are entering. In this case frequency signal is VC2. based on who are processed instructions of microcontroller. In such case state of high impedance. there is possibility for changing these values by calling specific procedures. Option select is used for choosing the way pins are driven. in which microcontroller cannot change pin states. like input of AD convertor because they can have impact on input voltage level. If selected option is StdCPU. component specific parameters can be set. so it is required to set the way of their operation. and it will be more discussed in chapter 5. V2 and V3 are used by various analog and digital programmable blocks. connecting it with some other blocks and internal connection lines. Also. Specific parameters like impulse and pause interval. Click on black triangle. In order to protect external devices from unexpected signals. with possibility to choose from several different signals the one that will be divided. Pin drive mode selection can be done graphically by selecting appropriate parameters in column Drive or software by setting appropriate registers. which represents signal input. because they allow direct connection to PSoC microcontroller without need for external resistors. Easiest way to do it is graphical. while writing program in Application Editor. This operation can also be done in graphical mode. marked 4 of 9 12/20/2008 6:05 PM . as it will be explained in next section of the book. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter2. Picture holds example of adjusting signal frequency on component PWM16. Pin Parameters Lower left side holds pin parameter options. CPU_Clock represents frequency value.Chapter 2: PSoC Designer | Architecture and Programming of PSoC. V2 signal frequency value is aquired by dividng signal V1 with N2. Peripherals in PSoC microcontroller are very flexible. respectively. Signals V1. clicking inputs and outputs on set component. enable and similar are not obligatory to be set in this window. Such parameters are component specific. Typically this is done by selecting frequency of the signal. of chosen frequency signal. Column Drive is used for pin drive mode settings. default pin state of PSoC microcontrollers is Analog Hi-Z. Time interval of impulse and pause is 32000 and 16000. respectively. Options pull-up or pull-down activate internal resistors. If pin is supposed to be connected to appropriate global lines over which is established connection with peripherals it is expected to be done by user. and is disconnected from programmable blocks.

should be chosen. marks placement space in graphical part.Chapter 2: PSoC Designer | Architecture and Programming of PSoC. than with components from lower four blocks. general rule applies. is allowed interrupt on falling edge. Components of upper four digital blocks are more easily connected among themselves.html with Hi-Z Analog. 5 of 9 12/20/2008 6:05 PM . where timer is stopped in interrupt routine. During the placement of analog and digital components. For example. Clicking some of selected components. one of efficient ways to measure signal interval could be allowing interrupt on rising edge of signal. and intended pin could not be established. that components that are to be connected should be placed in adjacent blocks. next available location could be selected. It is possible to to select interrupt on rising edge. the most important thing is to get to know the basic elements of programmable blocks. using icon Place. and following that. Digital Components Interconnection For start. Similarly. In case that communication from selected block. and then right-clicking on Place. Placement Free locations for setting programmable blocks are represented by grey rectangles. as shown on picture. Third column is used when in the case of pin interrupts. falling edge or state change depending on previous readout. it is easier to connect analog components that are placed inside of one column. or shorter. Digital blocks are grouped in two entireties of four blocks. using icon Next Allowed Placement. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter2. In interrupt routine is then started a timer. Component placement is done by selecting component.

Global lines are connected with digital lines from programmable components over the multiplexer. while global output lines are placed at the right side. Multiplexer has a function to choose one input signal that will be connected with his output. and from the lower side of each block are four output lines marked in blue. Port 0. On upper left side is positioned multiplexer. Procedure of connection global lines to pins is very simple. pins of ports with according index will be offered. Global input lines are placed on the left side. Port 2. which is routed to output buffers. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter2.even or O . GIE represents global input line that can only be connected to ports with even index (i. which can select optionally connecting shown input line..Chapter 2: PSoC Designer | Architecture and Programming of PSoC. The selected output line is taken. O . Selecting option Pin. There are input and output multiplexers. Global lines are marked in green. Graphically. For example. When certain line is clicked on. opens window with possible choice of connection.input. or interconnecting input and output global lines. Clicking on some of input lines of digital programmable blocks. Connectiong on global output lines is a little bit more complicated than in previous case.. global line GIO4 can be connected only with fourth pin of odd number ports.html On the upper side of each row there are four input lines to digital blocks. but over multiplexer and global input or output lines. it is represented with a small square. Connection to global lines is established 6 of 9 12/20/2008 6:05 PM . Digital blocks aren’t connected directly to output pins.output.e. is shown. Second letter in name tells about direction of the line I . depending on connecting input or output lines.odd ports. a external pin name. marked in red.). For example. Last letter in name gives information if lines could be connected only to E .

which is represented in shape of triangle. Beside frequency input. V3. Selection of logical functions is done by clicking on small square. Four analog columns and several 7 of 9 12/20/2008 6:05 PM . V2. Analog Components Interconnection Analog blocks are placed on lower side of the graphic part of the window. V1. after which is shown appropriate symbol. other input/output lines could be found. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter2. With left-click menu with possible selection of signal frequencies is shown. Some of possibilities are 48MHz. Frequency signal is marked with black triangle. There are two groups of common lines marked as BC1 and BC0. 32kHz. depending on component type. As additional element there appears a possibility for implementing logic functions with adjacent lines. as well as signals from some of global lines.Chapter 2: PSoC Designer | Architecture and Programming of PSoC. buffer will be painted blue as well as line that goes out from it. BC lines or adjacent blocks.html by clicking on appropriate buffer. All digital components have input for frequency. If this step is done correctly. and by choosing one of the options.

With help of two additional multiplexers there could be connected two middle analog columns to any pin of port 0. which can be done using assembly or C. Connection is established by using buffer that resides on bottom of every column. which could serve as analog inputs or outputs. Each of analog columns can have one output that leads to one of four pins of port 0.html multiplexers can be noticed. upper block ACB is used for analog amplifiers realization. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter2. respectively. by connecting frequency signal. bears much resemblance to IDE-s of other standard 8-bit microcontrollers. Most important file for users is called main.3 Application Editor Application Editor is used for writing programs. while lower two are used for AD and DA convertors. and input signal to the same analog column. In every of columns.Chapter 2: PSoC Designer | Architecture and Programming of PSoC. Columns on far left or right side could be connected only to odd or even pins of port 0. Left side window holds list of files that are contained in current project. 8 of 9 12/20/2008 6:05 PM . [back to the top] 2. Application Editor itself. Pins with analog input/output of ports 0 and 2 are shown on the left side. Routing is done graphically.

asm is should not be changed because it is automatically rewritten during each new configuration. pga. For example. At the same time. and PSoC Pros are trademarks of Cypress MicroSystems. [back to the top] ← Previouos chapter | Table of Contents | Next chapter → © 1998–2005 mikroElektronika. All Rights Reserved. In case of succesful compiling there will be shown message in lower window 0 Errors.hex file will be shown which can be programmed into microcontroller. PSoC. PSoC Designer. in folder output of the current project. Include files are generated automatically based on selected programmable blocks in Device Editor. clicking on icon Generate Application. If you have any questions.html This is the place of user code start. if set programmable blocks are adcinc12. programming is done as simply as calling subprogram with start instruction call ADCINC12_Start and result readout with call ADCINC12_GetSamples.Chapter 2: PSoC Designer | Architecture and Programming of PSoC. please contact our office. All other trade and/or services marks are the property of the respective owners. So in the case of AD conversion. . Inc. Names of available subprograms in part Library Source are in file with according name. When process of programming is done. 9 of 9 12/20/2008 6:05 PM . and lcd. compiling is started by clicking icon Build. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter2. File Boot. PSoC Designer automatically generates files with data and subprograms for their usage.

It is done in a very simple way. Most common choice is to start new project by click on Create New Project icon.html ← Previouos chapter | Table of Contents | Next chapter → Chapter 3: Quick Start From the free online book “Architecture and Programming of PSoC Microcontrollers” Introduction 3. Left side of the window is used to choose the way that new project will be formed.1 Creating a Project Click on the New Project icon opens a New project Wizard. one of lower two choices should be selected. where user should specify name. All the steps are similar in more complex projects. and location of the project. Because of that. What else could be in a microcontroller world than LED blinking? Basic idea is that we implement LED blinking by using PWM16 component. for base frequency of PWM16. 1 of 5 12/20/2008 6:06 PM . and write simple code to start PWM component. with the same signal/pause ratio. as soon as possible.1 Creating a Project Introduction Every beginning is the hardest part of every job. If there was a need to modify already existing project. User just should connect output of PWM component to output pin Port_1_0 to where is LED connected. [back to the top] 3. by selecting frequency of 32kHz with period set to 32000.Chapter 3: Quick Start | Architecture and Programming of PSoC. it is very important to write complete project that works. and impulse to 16000. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter3. or change of microcontroller type of some previous design.

Option Assembler is available to all users. For this example. Button Finish opens Device Editor window where user can select programmable components. As a result of this operation. automatically named as PWM16_1. by marking its icon. while for C one needs license. Importing it to the project is done simply. we go to interconnection window by click on the icon Interconnect View. This name can be changed by user. new window with assembler or C selection is opened. graphical simbol of PWM16 block will appear in selected components slot. After component selection.Chapter 3: Quick Start | Architecture and Programming of PSoC. Component PWM16 can be found in PWMs section. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter3. Note that resource window shows that component PWM16 takes two digital blocks.html Click on the Next. 2 of 5 12/20/2008 6:06 PM . microcontroller CY8C27643 and Assembler should be selected. which means that it is possible to place a maximum of three blocks like this. and right-click selection.

16000. since LED has been connected to pin Port_1_0. PWM16 output signal CompareOut is connected to output pin P1[0] in three steps. Next step is to adjust parameters of PWM16 component. 3 of 5 12/20/2008 6:06 PM .Chapter 3: Quick Start | Architecture and Programming of PSoC. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter3.g. PWM16 output CompareOut should be connected to digital output line with index 0. in this case Row_0_Output_0. where should be done connection to a global output line by enabling appropriate buffer.html Component placement in a marked free locations is simply done by right click on the component. Click on this line opens output digital multiplexer settings. As a first. Period and width of PWM impulse is set in window User Module Parameters. Final view of the User Module Parameter window is illustrated in the figure below. Parameter value of 32000 with input frequency CPU_32_KHz results in one second period. e. For equal length of signal and pause. Pulse Width is set to half of period.

all necessary is to call Start procedure PWM16_1_Start. All available subprograms from this file are declared with directive extern. For PWM16 to start working. Application editor selection is done by appropriate icon click. 4 of 5 12/20/2008 6:06 PM . On the left side of Application Editor. and connected to output pin user can start to write code. List of all other subprograms that could be used for given component is found by opening . list of all automatic generated files can be found.html Since LED is placed on odd Port_1_0. Click on pwm16_1. Click on file main.asm from Source Files section.Chapter 3: Quick Start | Architecture and Programming of PSoC. Generate Application icon should be clicked. Before that. which starts automatic generation of files for PWM16 component. which is shown in the figure below. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter3. or in appropriate component manual. opens the main program window. it is necessary to make connection trough Odd buffer line GOO_0 as it was illustrated in a figure above. When component is placed.asm opens a window with all subprograms. Final link with output pin is accomplished by click on Global_OUTOdd_0 linije and selecting pin Port_1_0.asm file with the same name as the component in Library Source section.

PSoC. please contact our office. compiling will be succesfully. Inc. 5 of 5 12/20/2008 6:06 PM . compiling should be started by clicking on icon Build. and PSoC Pros are trademarks of Cypress MicroSystems. All Rights Reserved. PSoC Designer. In case when code does not contain any mistakes.html After code is written. [back to the top] ← Previouos chapter | Table of Contents | Next chapter → © 1998–2005 mikroElektronika.Chapter 3: Quick Start | Architecture and Programming of PSoC. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter3. All other trade and/or services marks are the property of the respective owners. If you have any questions.hex file will be generated in the folder output. and blink.

i.1 Instruction types Data transfer Data transfer is done by instructions MOV. and other is the value of variable that has a role of pointer to array. Instruction MVI is optimized for data transfer between accumulator A and array of sequential data locations. One disadvantages is that instructions are not optimized for speed. which 1 of 5 12/20/2008 6:06 PM . and result is stored in the first value Beside basic operations of adding and subtracting. First argument is destination location. because their execution takes several instruction cycles. Arithmetic and logic PSoC as well as other microcontrollers has built-in support for arithmetic operations. MOV represents basic transfer instruction. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter4. are explained in this chapter. There are 21 types of MOV instruction in total.html ← Previouos chapter | Table of Contents | Next chapter → Chapter 4: Assembly Language From the free online book “Architecture and Programming of PSoC Microcontrollers” Introduction 4. takes place. One of the arguments is register A. whose instructions allow pretty much conform programming.3 Constants 4. while it is the longest when transferring contents of two variables.1 Instruction types 4. which offers large number of arguments. Reason for such large number of instructions lies in the fact that this is a CISC architecture microcontroller.2 Operators 4. at the same time initialization. there are also existing their modifications. in dependence of data types. like addition or subtraction.e.X and a value of some variable Beside that. while second source location. Instruction SWAP is used for direct exchange between registers A. There are instructions INC and DEC. Value of the first argument is added or subtracted with other argument. there’s also a possibility of exchange of values in registers A and SP. which makes with their sub-variants total number of 136 instructions. Instructions ADD and SUB are two basic operations. 4. which is needed for acquiring next element.4 Instruction set 4. MVI and SWAP.Chapter 4: Assembly Language | Architecture and Programming of PSoC.6 Addressing modes Introduction Complete set of 37 basic instructions. Shortest execution time is in the case when data is transferred trough internal registers A and X. Aside from transferring data. which holds address of the first array element.5 Directives 4.

program continues to execute the next instruction. Unconditional jumps use two sets of instructions. Instructions JACC uses offset jump relative to given label. If both arguments are equal. ASL and ASR instructions are used for signed multiplication and dividing by number 2. and in the case of ASR.Chapter 4: Assembly Language | Architecture and Programming of PSoC. Result of these instructions represents state of Z and C flags in F register. in standard ways. There are no special instructions for this operation.C. For close jumps instructions JMP and JACC are used. If first argument is lower than the other C flag will be set to one. during which the result is not written in first argument. shifting (ASL. and opposite. while instruction POP returns values in opposite order. and low end bytes are read from registers MUL_DH and MUL_DL. In the case of ASL zero bit is set to 0. As eight-bit constant should be taken mask value. These instructions have two comparing arguments that don't change their value. and Z for JZ and JNZ jumps. Values that are multiplying are transferred to registers MUL_X and MUL_Y with MOV instruction. RRC). since all the work is done in special multiplication registers. ADC and SBB makes addition or subtraction operation. In this case. There are differences in the way how are set bit 0 or bit 7. in every opposite case C and Z flags will be set to zero. and the result is stored in first argument. which explains a little bit more the way 2 of 5 12/20/2008 6:06 PM . for jumps JC and JNC. flag Z shows that bit is set to one. while instruction LJMP is used for far jumps. PSoC microcontrollers support conditional. OR. For operations that have two arguments holds rule that operation is executing on according bits of both arguments. which means Last In First Out. so that every zero is replaced by one. and eight-bit constant.html implements increment (add 1) or decrement (subtract 1) operations. allowing storing values of important registers inside of stack during procedure calling. PUSH instruction is copying value of register A and X. MAC unit allows operation of hardware multiplication. Rotation instructions RLC and RRC are writing bit exiting register Carry Flag into which is later written to bit on opposite side of register. whose value is stored in register A. Calling routine (CALL) and return (RET) from subprogram. If result of AND operation is zero. Decision and Control statements Instructions of relative jumps allow us to continue program execution from given label if condition for that jump is met. while the bit that exits register is written into Carry Flag of F register. Stack is LIFO ordered. bit seven is not changed. and then high end. which means that appropriate flag is set . ASR) and rotation (RLC. TST instruction is doing AND operation between the first argument. XOR. negation (CPL). Comparation instructions Because of need to compare arguments. Instructions of shifting and rotation moves bits one space to the left (toward bit 7) or one space to the right (toward bit 0). which has all zeroes. Z flag will be set to one. TST instruction gives possibility to test if certain bit of some register is set to zero or one. If condition is not met. and one in position where are test bits. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter4. there are two instructions CMP and TST. Logic unit of PSoC microcontroller has ability to handle standard logical operations AND. which allows simple multi-byte operations. like in case of AND operation. In case of CPL instruction content of accumulator is completed bit by bit. depending on how far jump address is. while Carry Flag is added to the result. unconditional and subprogram jumps. Instructions for stack operations Instructions PUSH and POP are. as well as returning from interrupt (RETI) are executed the same way as in other microcontrollers. Instruction CMP is used to compare two values. then flag Z will be set to one.

because that work is being done by compiler during program translation. but is used for time delaying that lasts four instruction cycles. which does no special operation. which will be discussed later in examples part. while hexadecimal ones have prefix 0x or $. 4. Table2: DW 0x1234. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter4. Beside holding important registers. by storing parameter using PUSH before procedure call.Chapter 4: Assembly Language | Architecture and Programming of PSoC. where constants appear. Constant character arrays are written inside of quotation marks. 4.2 Operators Among instructions. Other instructions Of other instructions. Table1: DB 1. Result of read value is stored in register A. Execution of operators has nothing with work of microcontroller. DWL When it is needed to form look-up tables with word type elements. lower then higher or contrary. DB DB directive is convenient for look-up table forming where bytes are used as data.3 DW. Instructions PUSH and POP with help of index addressing allow realization of local variables inside procedures. Accessing ROM Data that is stored in ROM can be accessed with help of instructions INDEX and ROMX. Stack is positioned in upper part of RAM. while binary ones have 0b or %. Next table gives comprehensive list of assembly operators. depending on which byte do they store first. these instructions allow transporting procedure parameters over stack. so it wouldn’t overlap with defined variables.3 Constants Decimal constants are written without any prefixes. then it is possible to use directives DW and DWL. Offset of the element that is being accessed is previously stored in accumulator A. it is possible to form statements with help of assembler operators for arithmetic and logic functions. 4. Some of more important directives will be covered further. most important one is NOP.2.4 Instruction set (work in progress) 4. while the label of look-up table is called as argument. INDEX is of special importance during look-up table reading.5 Directives Directives represent useful elements in assembly that give various information of interest for program translation. and taking it from stack by calling PUSH instruction from inside of procedure. Binary values of constants are written inside of ROM memory at the address specified by label.html PUSH and POP instructions function.0x1235 3 of 5 12/20/2008 6:06 PM .

terminate: jmp . There is a directive in the beginning of main program include “m8c. . usually in the begging of that file.Chapter 4: Assembly Language | Architecture and Programming of is used as a connection towards files that contain procedures for working with selected programmable blocks. it is often needed to use ASCII values instead of" // PSoC API definitions for all User Modules include "User. in memory will be written character ASCII value 48. thus improving code readability and reusability. Because of that it is common to add ASCII character NULL to an end of files. EQU equ value Directive EQU enables giving constant name to some value Before compiling that name is automatically changed into according constant value. there is a need to somehow detect an end of array. Directive Export is put before procedure implementation. 4. In the case of character “0”. In this way it is possible to combine several files which contain different parts of” which enables access to microcontrollers registers.terminate EXPORT export procedure_name Directive EXPORT is being used to mark that the procedure written in current file can be used in other files. File PSoCAPI. Table5: DS “HelloWorld” DB 0 INCLUDE include "filename" Directive include is used to insert content of given . Assembly main line include "" // Constants & macros for SMM/LMM and Compiler include "PSoCAPI.6 Addressing modes 4 of 5 12/20/2008 6:06 PM .0x1235 DS During the work with serial communication or writing data on LCD. As an example is given file with procedures for programmable component" // include "memory.html Table3: DWL" export _main _main: call PWM16_1_Start . Table4: DS “0123456789” When all elements of constant character array are loaded in memory.asm or . free file:///D:/PSoC/Material/PSoC%20Chapter/chapter4. which is represented as binary 0. Directive DS writes to program memory ASCII values of constant array of characters that are written inside the quotes.

Easiest way to access value of that variable is by putting it’s name inside of brackets. it is also needed to put registered word reg. please contact our office. which has a possibility of index addressing. and PSoC Pros are trademarks of Cypress MicroSystems.html There are several ways to fetch data during instruction execution. Index addressing One other thing that also happens very often is the need to access continuous memory locations. For example: Data could be RAM variable. [back to the top] ← Previouos chapter | Table of Contents | Next chapter → © 1998–2005 mikroElektronika. with initialization of pointer-variable so it stores address of next variable in array. it is no longer needed to continuously increment register X. free file:///D:/PSoC/Material/PSoC%20Chapter/chapter4. in a simple way. In that case we could some help from register X. Inc. index and indirect addressing method. Its value is previously initialized to hold address of the variable that is being accessed. which shows that it is done in register address space. RAM variable or register variable. Register addressing When accessing register. Index register X is used to store address of some variable. there are immediate. All other trade and/or services marks are the property of the respective owners. to access elements of an array. 5 of 5 12/20/2008 6:06 PM . instead of its value. direct. Incrementing and decrementing values of the index register it is possible. PSoC Designer. All Rights Reserved. PSoC. very simple procedures are hidden. beside brackets. Immediate addressing When data is a constant value. If you have any questions. or a register.Chapter 4: Assembly Language | Architecture and Programming of PSoC. In this case variable which plays role of a pointers used instead of register X. Beside these complicated looking names. Using instruction MVI. If we didn't put those brackets. we would access address of that variable. then it is considered as immediate addressing. which are all called under one name addressing methods Depending on whether data is a constant. MVI transfers values between accumulator A and value of the variable.