You are on page 1of 5

CSE 143 MICROELECTRONICS DESIGN, WINTER 2008, PROF.

RAJESH GUPTA

Lab 4: Programming the PSoC Embedded Platform

Due: 03/06/2008 noon

In this lab, we will use a simple microcontroller board featuring mixed-signal components:
Cypress CY3214-PSoCEvalUSB Kit. The kit contains an evaluation board with USB connector
and C-compiler license. The on-board single-chip PSoC part (CY8C24094) contains a 24-MHz
8-bit microcontroller with digital and analog components that can be configured using assembly or
C. You can pick up the kit from Virginia McIlwain in EBU3b 2244.

The purpose of this lab is to familiarize you with the microcontroller platform and how it can be
accessed through typical programming environments. You will also learn how to design finite state
machines for PSoC using C programming.

Once you have read the documentation on the evaluation board and installed the programming
environment, you are to complete a state machine design that monitors user input and displays
temperature (ADC result of VR1)

Setting up the environment:

1) Read the Quick Start document that comes with the Kit.
2) Install PSoC Designer.
3) Install PSoC Programmer.
4) Enable the ImageCraft 'C' Compiler (Start PSoC designer, Click Tools Æ Options Æ
Compiler Tab Æ Enter license key XZ59631-0RJLXR)
5) Connect your computer to CY3214-PSoCEvalUSB through PSoC MiniProg (Fig. 1)

Fig. 1. Connect CY3214-PSoCEvalUSB to Computer


Temperature Sensing State Machine Design

State machine diagram is shown in Fig 2:

Fig 2. State Machine with 4 States


EVENT_PRESS_S1: Button S1 is pressed
EVENT_PRESS_S2: Button S2 is pressed
EVENT_PRESS_S1S2: Button S1 and S2 are pressed
EVENT_PRESS_S3: Button S3 is pressed
ACTION_DISP_GOBACK: Current State number is displayed on LCD line 1 and line 2 of LCD reads: “Press S3 2
Go Back”
ACTION_CLEAR_LCD_LINE_2: Current State number is displayed on LCD line 1 while line 2 of LCD is empty

The code provided on lab website (CSE143_Lab4.zip) only has the first three states implemented.
You need to add your own code to implement STATE_NUMBER_3 and finish the design. To add
the fourth state, you will need to modify the following files:

./lib/statemachine.c
./lib/statemachine.h
./lib/event.c
./lib/event.h
./lib/action.c
./lib/action.h

Jumper wires for the state machine design:

Fig. 3-1 Jumper Wires Fig. 3-2 Left Corner Zoom In Fig. 3-3 Right Corner Zoom In
Note: the yellow wire on Fig. 3-3 is our “button” S3. Jumper in means S3 is pressed and jumper
out means S3 is released.

Hints and Tips

1) Look at the code of statemachine.c/h, event.c/h, action.c/h to see how the state machine
actually works.
2) Button S1 and S2 are actual buttons on the board, button S3 simulated by port3 bit 2.
Jumper in means the S3 button is “pressed” and jumper out means S3 is “released”.
3) For more information about state machine design for PSoC, please read (source code
available)

EMBEDDED STATE MACHINE DESIGN FOR PSOC USING C


PROGRAMMING (PART I OF III) - AN2329

EMBEDDED STATE MACHINE DESIGN FOR PSOC(TM) USING AN


AUTOMATIC CODE ENERATOR (PART II OF III) - AN2332

4) Here is an good PSoC design example: (source code available)

PSoC-Based USB Device Design By Example - AN2298

Lab #4 Receivables:

„ Your submission should include a short description of the design along with the whole
project directory
„ Please zip your files and email to hepeng@cs.ucsd.edu
PSoC Designer and PSoC Programmer Tutorial:

In this section we will show how to use PSoC designer and PSoC Programmer using the provided
code CSE143_Lab4.

1) Connect the jumper wires as shown in Fig. 3.


2) Start PSoC Designer

3) Enter the full path of the project file cse143_lab4.SOC and click the “Start Debugger
(Debug project code)” button
4) Your project will be loaded and compiled. Bottom left of the screen shows compile status.

5) If there is no error a HEX file cse143_lab4.hex will be generated in ./output directory.

If your project failed at the compile stage because of the error “!E ./lib/usb.h(124): redeclaration
of `T_USB_XFER_STATUS_BLOCK'.” Open ./lib/usb.h and comment out following lines:
typedef struct {
BYTE bStatus;
WORD wLength;
} T_USB_XFER_STATUS_BLOCK;

6) In PSoC designer click “Program”Æ “Program Part” to start the PSoC Programmer.
7) Make sure “Device Family” is 24x94 and “Device” is CY8C24894-24LFXI
8) Click the “File Load” button and load the HEX file cse143_lab4.hex generated in step 5)
9) Click the “Program” button to start programming.
10) Once programming succeeded, click the “Toggle Device Power” button to power on your
device.
11) Press S1 on the board. The LCD on the board reads (actual temperature depends on the
value of VR1 on your board):

PSoC STATE NO. 1

Temperature = 123

12) Rotate VR1 on the board and press S1 again, you’ll see a new temperature value shows
on the LCD
13) Press S2 on the board. The LCD on the board reads:

PSoC STATE NO. 2

Please Confirm

14) Once you have finished your code to implement the fourth state STATE_NUMBER_3,
you can press S1 and S2 (hold S2 then press S1, you need to make sure S3 is released).
The LCD on the board should read:

PSoC STATE NO. 3

Press S3 2 GO BK

15) Press S3 (jumper in). The LCD on the board should read:

PSoC STATE NO. 1

You might also like