psoc encoder design

24
PSoC Encoder Design Project Manual Course: ME 458 Semester: Fall, 2007 Yi Liu and Ryan Krauss SIUE

Upload: others

Post on 04-Feb-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PSoC Encoder Design

PSoC Encoder Design 

Project Manual

Course: ME 458

Semester: Fall, 2007

Yi Liu and Ryan Krauss

SIUE

Page 2: PSoC Encoder Design

                    Contents1. Introduction of PSoC                                                                                                                                   .............................................................................................................................   3  

1.1 What is PSoC?                                                                                                                                    ..............................................................................................................................   3  1.2 Characteristics of PSoC microcontrollers                                                                                         ...................................................................................   5  

2 Preliminary Project of Generating a Square Wave                                                                                       .................................................................................   6  2.1PSoC Design Flow                                                                                                                              ........................................................................................................................   6  2.2 What is interrupt?                                                                                                                              ........................................................................................................................   7  2.3 Project creating                                                                                                                                  ............................................................................................................................   9  2.4 Device editing                                                                                                                                  ............................................................................................................................   11   2.5 Application generating                                                                                                                     ...............................................................................................................   18   2.6 Application editing and programming                                                                                             .......................................................................................   19   

 

Page 3: PSoC Encoder Design

1. Introduction of PSoC

1.1 What is PSoC?

Fig.1

Page 4: PSoC Encoder Design

When we develop 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, and 

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) 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 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.

Page 5: PSoC Encoder Design

1.2 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. 

Page 6: PSoC Encoder Design

2 Preliminary Project of Generating a Square 

Wave

Now it’s time to perform a simple example project through which you will be able to obtain the idea 

on how PSoC system works. Here, our goal is to develop a PSoC Designer project that can generate a 

square wave for any freqeuency between 100 Hz and 10 kHz.

2.1PSoC Design Flow

Before we start a PSoC design, let’s structure the basic PSoC Design Flow:

Determine System requirements

Choose User Modules

Place User Modules

Set global and User Module Parameter

Define the pin­out for the device

Generate the application

Review generated code

Page 7: PSoC Encoder Design

Demonstrate working configuration

In addition, it is necessary to refresh the concept “Interrupt” in microprocessor which serves as the 

very basis for the consecutive PSoC projects. 

2.2 What is interrupt?

By definition, Interrupt is a signal informing a program that an event has occurred.  Events could be 

internal (timer overrun, end of AD conversion) or external (character receiving over serial connection, 

pin   state   change).When   interrupt   occurs   program   execution   is   interrupted   (hence   the   name)   by 

jumping to part of the program that is called  interrupt service routine(IRS). Upon ending of that 

routine program continues from place in program where interruption took place. Interrupt controller 

makes hardware interrupt detection, program flow interruption by jumping to interrupt routine, as well 

as returning to interruption point from the routine. These operations are executed in several steps:

1. When event that triggers interruption takes place, interrupt controller stores interrupt type. 

2. End of current instruction is awaited. 

3. If interrupt is allowed and if global interrupt permit is set to 0ne (GIE = 1), interrupt 

processing begins. For later continuing of instructions execution, stack holds values of PCH, 

PCL and F registers. 

4. New interrupt occurrence is disabled by setting values of register F to zero (GIE = 0). 

5. Program counter is set to address of interrupt routine, which is same as interrupt type, after 

which execution jumps to interrupt routine address. 

6. Program executes interrupt routine instructions. 

7. When it gets to instruction reti, which marks return from main program, values of F register 

are restored from stack, and program counter is reset to old value before interrupt occurred. 

Page 8: PSoC Encoder Design

Fig.2

Register PRTxIF is used as indication of GPIO interrupt on certain port, while PRTxIC1and PRTxIC0 

are appropriate control registers. Every interrupt type can be masked or deleted, which is done with 

help of INT_MSK and INT_CLR registers, which will be discussed in more detail in examples part.

Interrupt handlers can be written in C. In order to employ them, we must first inform the Compiler that 

the function is an interrupt handler. To do this, use the following pragma (in the file where you define 

the function, before the function definition):

 #pragma interrupt_handler <name> 

In this project, we will use the ISR to toggle a pin, so that a square wave is generated. A timer 

interrupt is to be used since we need to specify the frequency of the square wave. To do this, use 

the following pragma:

#pragma interrupt_handler Timer8_1_ISR

Page 9: PSoC Encoder Design

2.3 Project creating

At this time, you need to make sure that the CY3210­MiniEval1 board is attached to your computer. 

Then use the Getting Started Guide that came with the CY3210­MiniProg1 to learn how to attach 

CY3210­MiniEval1 board to your computer.

Fig.3

Left  click the Start  Button,  and then select  All program­> Cypress MicroSystems­> PSoC 

Designer to open up the PSoC Designer.

Page 10: PSoC Encoder Design

Fig.4

Press “Start new project” button, create our New project with the name “Square_wave”, and then 

click “Next>”

Page 11: PSoC Encoder Design

Fig.5

In   the   window   that   appears   below,   you   are   able   to   select   base   part   of   the   project,   use 

“CY8C2966­24PXI” as default. Click the circle left to C, thus choosing C as the language that 

the project main file would read in. Then click “Finish” Button.

Fig.6

2.4 Device editing

Next, we find ourselves in the “Device Editor” selection view. as shown in Fig.7. It can be seen 

that on the far left, is the user module catalog in which each Bar gives the name of the user 

module family. To the right of the user module catalog is the diagram of user modules, along with 

the data sheet that corresponds to the selected user module, in this case, Timer8.

Page 12: PSoC Encoder Design

Fig.7

Double click Timer8 under the Timer bar in the user module catalog, thus we select Timer8 as 

the user module in our project. After you have done this, you will see a Timer8 Icon appear in 

the user module tray.

Page 13: PSoC Encoder Design

Fig.8

Now let’s switch to interconnect view of Device Editor by single clicking the Interconnect 

View button (circled in Fig 9). We will see on the far left there are three sets of parameter and 

resource tables. On top, in the upper left, there are global resources below which are the user 

module parameter tables; and on the bottom, is the port table. As we move from left to right, we 

will see the center window which can be thought of as the main workplace. This is where we 

place our selected user modules and do all the routing. To the right of the main workspace 

window is the pinouts window.

Page 14: PSoC Encoder Design

Fig.9

After a short tour of the interconnect view, now it is time to place our selected user module, 

namely, Timer8 in the main workspace window. To do this, single click Timer8 Icon in the user 

module tray and you will see a target placer appears in green highlights, designating a possible 

placement for a Timer8. If we want find other possible locations, simply click the “Next Allowed 

Placement” button (Circled in the upper left in Fig.10) to move sequentially through the digital 

system. Try that on your own.

Page 15: PSoC Encoder Design

Fig.10

We will place Timer8 into the DBB00 (zoom in if needed to see it clearly), the first possible 

location, by clicking the “Place User Module” Button circled in Fig.11.  

Fig.11

Page 16: PSoC Encoder Design

Now it is time to configure the Global Resources. Set the Global Resources as shown in Fig.12.

Fig.12

Thus, if the power frequency  VCC ( f Sysclk ) is set to be 24MHz, the actual frequency of Vc1, Vc2, 

Vc3 are to be calculated as 

f VC1=f SysclkN1

=24 ,000 ,00012

=200kHz  where  1≤N1≤16

f VC2=f VC1N2

=200 ,00010

=20kHz   where  1≤N2≤16

f VC3=f VC2N3

=2000Hz  where  1≤N2≤256

Page 17: PSoC Encoder Design

Next step is to configure the user module parameter of Timer8. The value of each parameter as 

shown in the Fig.13 below. We set the Clock to be VC3, indicating we want Timer8 to have the 

clock source of VC3. 

Fig.13

The value of period shows how many periods of clock that we would have between the two interrupt 

produced by Timer8. This could be illustrated by Fig.14 below. It is clear that the period set in the 

Timer8 parameter  PP is NOT the real period of interrupt P I . Indeed, the relation between the 

former and the latter is  PP=P I−T . Therefore, the frequency of interrupt  f I can be calculated as

f I=f VC 3

91=200Hz

Page 18: PSoC Encoder Design

T = t i m e d u r a t i o n o f u n i t c l o c k

T i m e rI n t e r r u p t

1 2 3 N - 1 N 1

T i m e rI n t e r r u p t

P e r i o d = P p = ( N - 1 ) T

Fig.14

We need a further step to finalize configuration of user module catalog,  namely, we need to 

configure the port table. Set Drive of Port_0_0 to be “Strong” and leave the rest as defaulted.

Fig.15

2.5 Application generating

Now we are ready to generate our application. Click the “Generate Application” button and the 

PSoC   designer   will   take   all   our   configuration   settings   and   generate   an  Application 

Programming Interface (API) for us.

Page 19: PSoC Encoder Design

Fig.16

You will see the following message in the result tray on the bottom once you successfully generate 

your application.

Fig.17

2.6 Application editing and programming

Then we will move on to the  Application Editor  by clicking the circled icon shown in Fig.18 

below. 

Fig.18

Page 20: PSoC Encoder Design

Once we enter   the  Application Editor,  we are  able   to  write  our  C codes  and  program the 

CY3210­MiniEval1 board. To do this, first expand the source files on the left and double click 

“main.c”.

Fig.19

Write the following code in main.c:

#pragma interrupt_handler Timer8_1_ISR   // call Timer ISR

void Timer8_1_ISR(void){PRT0DR^=0x01;  // generate a square wave and output it from pins. 

                   //”^=”means exclusive or(XOR); i.e.0 XOR 1=1;1 XOR 1=0

}

void main(){    // Insert your main routine code here.    Timer8_1_EnableInt();    M8C_EnableGInt;

Page 21: PSoC Encoder Design

    Timer8_1_Start();    while(1); //Setting a endless loop awaiting interrupt

}

The logics and mechanism for  generating a  square wave can be illustrated by  the  following  time 

sequence diagram. It is easily seen that the frequency of the square wave is half of that of the timer 

interrupt, namely,  f Square=0.5f I=100Hz

T i m e rI n t e r r u p t

0 X O R 1 = 1 1 X O R 1 = 0

1 X O R 1 = 0 0 X O R 1 = 1

P R T 0 D R i s i n i t i a l l y l o w ( 0 )

P R T 0 D R i s i n i t i a l l y h i g h ( 1 )

Fig.20

Next, we will build our project with application editor by left clicking “Build” pull­down menu 

on the top and select “Build”. This might take a few second.

Fig.21

Once having successfully built up our PSoC project, we might open up PSoC designer Debugger 

and   perform   program   debugging;   however,   this   preliminary   project   is   so   simple   that   no 

debugging is required. Therefore, we can move directly to programming PSoC part and execute 

our project. Before we do this, make sure that CY3210­MiniEval1 board is correctly connected to 

Page 22: PSoC Encoder Design

the computer while the AC adapter is detached from the borad, as we mentioned previously. Then 

we can either  left  click the Program pull­down menu on the  top and select program part,  or 

directly click the Program Button circled in Fig.22 :

Fig.22

After clicking Program Part, PSoC programmer will pop­up on the computer screen in front of 

PSoC the PSoC designer  as  shown  in  Fig.23 below. For  programming mode,  select  “Power 

mode”. Lastly,  press the “Program” button on the top.

Page 23: PSoC Encoder Design

Fig.23

We would see the Final message at the top of Action/Result box as shown in Fig.24

Page 24: PSoC Encoder Design

Fig. 24

Now that we have programmed the CY3210­MiniEval1 board, we may plug in the power adapter 

and start to execute our project. To demonstrate the result, we may export to one channel of an 

oscilloscope signals from any of the 28 pins, along with a reference ground on CY3210­

MiniEval1 board. Also, we could resort to a DAQ card thereby showing the waveform on the 

computer screen. Supposedly, we would obtain a square wave sequence with frequency 100Hz.