Introduction: PSoC - My First Project
Are you feeling that arduinos don't really challenge you anymore? And that you have a need to take a new step, upwards!
Well I got that feeling and had a discussion about FPGA's CPLD's and I also found PSoC's thats kinda all of the above in one, Kinda.
Anyways I ordered up a few cheap dev boards the Kit-49-41xx and kit-49-42xx because they were $4 each, in hindsight, don't get the kit-49-41xx if you don't really need that one the 42xx has much more abilities, just take my word for it, i wont expand on what the differences are here. And I also got the PSoC 5 kit-59 and this is the one I got stuck using for my test projects. The reason: It's got a quasi real programmer the kitprog! which made playing with it a lot easier, with the two kit-49 boards you need to hassle around with a bootloader that is not as easy as Arduinos but anyhow it took a few more steps programming the board, enough about me and my ranting about what board to get, there are other boards with all the bells and whistles but i like doing things the rough way so lets hop into our programming environment The PSoC Creator (find it at Cypress)
Step 1: The PSoC Creator
Now for you guys used to and comfortable with the arduino environment, don't be intimidated it just looks bad, it's really not that bad as you get used to it, there are a few more steps needed to get tings rolling with PSoC's but that's what i costs to be as versatile as these chips go.
First off we take a look at the environment, we have the Workspace explorer for our files, then in the middle we have our TopDesign tab where we will design our circuit, with the components from the components catalog on our right.
Now we are familiar with the environment, and can start our project. I have already done 'File - New - Project' and selected the right chip for the Kit-59 board (the CYC5888LTI-LP097 chip) and have called the project "Blink", Guess now what this project will do...
For our circuit we will be needing some components, lets start with a "Digital Output Pin" that you find in the Component Catalog under 'Ports and Pins' and we drag it onto our design.
Ah, that looks simple enough doesn't it? well lets double click on it and look at what we can do with a Digital Output Pin.
Step 2: The Digital Output Pin
Whoa, thats a bit more than you signed up for, or is it really. Theres a lot of settings here, but it really comes down to only a few things that we need to concern ourselves about for this little project, and that is to rename it to LED, for guess what, this is going to be the pin connected to the onboard blue led on our Kit-59 board. but what pin that really is in the physical world (or board) we'll get to at a later step. For now just rename the pin to LED and press OK, and you see that the component now shows its name as LED.
Now for our next component we are going to pull out a Counter which you find in your Components catalog under 'Digital - Functions'
Step 3: The Counter
In this tiny project of ours now we are going to use this, the simplest of counters that simply count the number of clocks given and when passing 255 it will give out a signal on the tc output so the only thing we want to do here is to give it a new name, lets just get rid of the "_1" and call it "Counter". And press OK for we are done with setting it up.
Next we are going to need a fixed logical '0' for the reset input that you will find in the components catalog under 'Digital - Logic' and its there called "Logic Low '0'" pull it out and hook it up to the reset input of the counter. A small hint "W" button makes you draw the "wires" ;)
And we need a clock, the clock component is a system component and therefore found under 'System', pull it out and drop it on the design board.
Step 4: The Clock!
This component needs a tiny bit of configuring, as you see the frequency is set to 12Mhz that's 12 million times a second, if we were to use that speed the LED would blink 12 million divided by 255 , that's still almost 50'000 times a second so we change that to 255 hz (not Mhz or Khz, just hz). and we press OK, we are done with the clock.
Now if you havent already connected the LED Digital Output Pin to the tc output of the counter, do that now (remember the 'W' key for Wiring things up).
And basically we are done with our circuit. Next step is for us to take a look at our code or rather our main.c file, so find your main.c file in the workspace explorer and double click.
Now the first thing you might notice is the big red X marked in your code window, and it's there. It's not that you have done anything yet and already got an error.
The reason for this is that all the "libraries" that you need will be added to the project as soon as you build it for the first time, by that i mean that the code doesent yet know that we will be using a Digital output pin that we have called LED, nor does it yet know that we have a Counter. so for us to be given all the libraries or API's as they are referred to in PSoC creator we need to build our project once.
Goto "Build - Build Blink" or just press Shift + F6 and the Creator will start working it's magic. Now if you have done anything wrong it the TopDesign the build process will stop, and tell you what it thinks is wrong in the Output window below the middle of your screen, If your Workplace explorer got filled with files all went well and the big red X should be gone too.
Step 5: The Code!
Alright, now we are set up to punch some sleek juicy C code for this project.
As it turns out, most of our circuit is done in hardware on our TopDesign tab and therefore shouldn't be too much coding to do, but there are one thing most of components need, and that's a (kik-) start.
so we type in, on a line for our initialization of our counter :
And that's all the code we need for this project....
But now, for the feature I am most happy with when I play with this board, the last step of our project:
Step 6: Pin Selection !!
Open the file called Blink.cydwr and be amazed !
First, the square image is a representation of the chip itselves, not the board we have it on, just be aware of that.
Now on the right hand side we see that we have a pin called LED that has gotten a default placement at pin P0 but unless you want to have it there and have a led connected at that physical pin on your board we need to move it. On my board the kit-59 the onboard led is connected to P2 so we just use the pulldown and select P2.
And we Build our project one last time and program our board, and if all is set and done as I have instructed we should have a blue led blink once a second.
We have a be nice policy.
Please be positive and constructive.