Quick Notes on the PSoC

Updated at the end, to include how2play programming.

Today, I spent some time tinkering with the PSoC 5 LP prototyping kit. This prototyping kit is physically very portable, and contains some very surprising features for it’s price point (~$10-20, depending on supplier). Unfortunately, I had horrendous trouble navigating the documentation, so I write this blog post both as a note to myself, and hopefully to assist anyone else trying to work out how to use PSoC Creator.

The uniqueness of PSoC comes from a number of analog components which are directly accessible from the MCU itself, and the flexbility of the microcontroller pins. Think of it as a microcontroller on top of an FPGA on top of a stack of analog components (for the princely sum of $16) and you’re there. I think this is extremely cool, and hope you do to.

To start, let’s try driving a status LED from the firmware. After creating a new project and selecting the correct development kit, we are presented with a blank schematic. We begin by using the Component Catalog tab on the right to add a Digital Output Pin (under Ports and Pins). We drag this to our schematic:

Think of this pin as an arbitrary “slot” – this isn’t connected to anything yet. We double click the pin on the schematic, and untick “HW Connection”. Leave the rest as-is (strong drive, we’re driving a LED).

Our next step is to map this to a physical pin. Click the components tab on the left hand side, to bring up a tab which looks like a square microcontroller:

On the right, you’ll have a window which allows you to assign Pin_1 to a port. The “port” corresponds to the port numbers printed on the prototyping kit’s silk screen. For this example, we inspect the physical LED element, and we note it says “2.1” underneath the LED. We select “P2[1]” for the “Port”, and leave the rest as-is. The middle picture should change, with P2[1] becoming blue to denote the change:

This is enough to begin programming on the microcontroller. Click the “Sources” tab on the left, and open “main.c”.

The code generation is unfortunately a bit strange. You’ll need to use a few Cypress functions to do things. A LED blink looks like this:

#include "project.h"

int main(void)
 CyGlobalIntEnable; /* Enable global interrupts. */

/* Place your initialization/startup code here (e.g. MyInst_Start()) */


Now, save your work, compile your project then program this to your dev kit (the board comes with a KitProg programmer built in, similar to the STMicroelectronics boards), you should get a blinking LED.

Note that I had problems getting the PSoC4 equivalent (CY8CKIT-049) working, and I ended up resorting to an external MiniProg programmer to make this work. YMMV, this may just be hardware damage on my end.

Now, let’s replicate the functionality in programmable logic and reroute the output. Firstly, go to the Components tab on the left, and right click the “Project ‘Design01′” row (or whatever you named it), and click “Add Component Item”. Do not use this while TopDesign is selected, or you can unfuck your project later.

Now, use the Symbol Wizard to define a clock input and a simple digital output:

You should be presented with another schematic-looking thingy. Right click the blank space, and select “Generate Verilog”. Now, use the following code to create a blinker:

reg [32:0] ctr;
reg led_out_r;
assign led_out = ctr[27];

ctr <= 0;

always @(posedge clk_in)
 ctr <= ctr + 1;

Note that this is a bit stricter than Xilinx’s Vivado: we need an explicit initial block instead of just assigning variables at the start. Enter this in the body section of your Verilog, and save your work.

Our next step is to add a clock input, and connect it to our LED. Select the “TopDesign.cysch” tab up the top, and modify our pin to enable “HW Connection”. Now, use the Component Catalog’s “Default” tab on the right to add one instance of our new component:

Now, connect the two components, using this tool to the left of your schematic:

Note that this tool is a “clicking only” tool, and does wierd things if you attempt to drag like a normal person. Instead, click once and only once on the starting component’s “connector box”, and click once and only once on the end component’s connector box. A successful connection looks like the above.

Now, use the Component Catalog on the left to add a Clock (under the “Cypress” tab, in “System”). Leave this at whatever the frequency is, and wire it up:

Now, go to main.c, and delete the code we added (so leave it as an empty main function). Build your project, and program it, for a very slowly blinking LED.

You can easily redirect ythe output to another pin – simply open Design01.cydwr (the MCU square thing), and select a new port (P2.0 is an excellent choice for testing – it’s right in the corner), rebuild and reflash your project.

I look forward to working more with this interesting hardware.

Appendix – Programming with MiniProg 3

I have also done some experimentation with the MiniProg programming adapter – I’m a huge fan of having seperate debug hardware, instead of relying on on-board debug (which seems a bit too much like having a process report on it’s own integrity). Unfortunately, the “PSoC Programmer” standalone application is a flaming pile of shit.

To program a PSoC device using the external programmer, go into PSoC Creator. Select “Debug / Select Target and Program”. You should see a window like this:

Now, right click the MiniProg 3 entry, and select “configure”. Select the correct options for your kit – ensure that you select the correct voltage, connector and acquisition mode (for a PSoC5LP kit, this was 5V, Reset and 5-Pin Connector (replacing the KitProg connector effectively). Click OK, and hit Port Acquire, and your target should show up.

This works, despite the device never being acquired under the PSoC Programmer standalone application (why?).

If you can’t find your programmer on your desk (in fairness, it looks like a USB stick), no problem – just hit the “Visual Identification” button and all the LED’s will cycle. Hooray!

About Norman

Sometimes, I write code. Occasionally, it even works.
This entry was posted in Bards, Computers, Jesting. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.