- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello !! I am beginner in psoc. i am having a simple problem that i want to assign any pin as a input and when the input to that particular pin is given logic high then it should perform the desired looping operation. Plz help abt how to keep tht pin as input and how to read data from it..
Solved! Go to Solution.
- Labels:
-
PSoC 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Datasheet for PSoC4 tells: Ports 4 and larger cannot be used for routing, only for firmware control. Yes, reading and writing is the same for bidirectional pins.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
first download and install PSoC Creator software.
Then drop an Input Pin component on the schematic and adjust the number of pins you like to experiment with.
In your main() program you read the pins with
uint8 Values;
Values = PinName_Read()
Happy coding
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thnx for quick reply.. 🙂 but if i want to use p1[7] as input pin then how should i go forward with it ?? tht means how to initialise it and how to get data from it ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi blueblood,
You can drag and place a Digital Input Pin component from the component catalog onto the schematic.
You can double click on the component to open the Configuration Window where you can select its Drive Mode (if you want to alter).
The schematic will look like this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Once you save the project, open the .cydwr file from the Workspace Explorer.
In the Pins tab select the Port Pin to which you want to assign this pin (in this case it's P1[7]).
Once you select the required pin, you can build the project. APIs will be generated for this Pin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As Bob Marlowe has already mentioned, the Pin value can be ready by simply using the API <PinName>_Read( ) in the main.
The default Drive Mode of Digital Input Pin is High Impedance Digital. However, you can select other drive modes, if the situation demands, to Resistive Pull-up, Resistive Pull-down, etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should put the line
uint8 Values;
at the bdginning of you function before any opertions. EG
void main (void)
{
/* all variable declare first */
uint8 a;
uint16 b;
...
/* Then the c program here */
..
..
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should put the line
uint8 Values;
at the bdginning of you function before any opertions. EG
void main (void)
{
/* all variable declare first */
uint8 a;
uint16 b;
uint8 Values;
...
/* Then the c program here */
..
..
pga_start();
values = PIN_2_Read();
...
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, as lleung has already mentioned, declare all the variables used in the code before calling the component APIs.
Rearranging the declarations should eliminate the error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thank you everyone for the help.. 🙂 the method worked !! i also found other technique of using "CyPins_ReadPin(Pin_2_0)" which simply does the reading of the port pin without initialization..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
http://publications.gbdirect.co.uk/c_book/ is a pretty good C-Syntax description.
C is not easy or simple, there are lots(!!!) of pitfalls and misunderstandings you will experience, so don't get frustrated.
Happy coding
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am a professional programmer (for about 40 years now) and I would like to put you on the right track.
The main goal for a good program is not "It Works!". If it doesn't work, its not a program at all, a piece of wood doesn't work eather.
So what are the kriteria for a "good" program?
Here are some of mine:
Cheap - Programmed and tested in a short time
Cheap - Re-usable code from former projects
Cheap - Flexible programming adopts easily to different hardware
Cheap - Make the program human readable as much as possible
You can add yours here...
Reading directly in your program from a specific pin violates some of the above kriteria, saving the initialization part has the downgrade that there IS NO initialization part. HAVING an initialization part makes it easy to pre-check some external situations before the program really runs (or deny the running with an error-message.
All my PSoC-programs have the following structure which make it easy to look up, control or change the appropiate part:
Title of the Program, date, version and what it should perform
#includes
#defines
Global Variables (but only a few!)
void InitializeHardvare(void
{
Yes, exactly that, nomen est omen...
}
void main(void)
{
InitializeHardware();
Here goes the initialization of the software
while(forever) // #define forever 1 helps readability
{
The main task, normally calling some functions defined in other files
}
// NO FINALIZATION, forever is forever, this code will never be reached
Happy coding
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ooops, forgot a ")" here are some spare, insert where requred "(())){{{}}}[[]];;;"
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanx bob for the suggestions !! it was my first experience with psoc.. i must say it is great piece of software.. very easy to use !! Just one simple query that i have made my sub modules individually.. tht means in different projects.. but when i combine them, one of the sub modules doesn't work.. any idea why this is happening ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Interesting conversation. Blueblood, could you tell us what submodules are you referring to ? Do you mean different projects or C funtions to do smaller tasks ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am facing some problems in pin mapping , am not getting what exactly the problem .
please explain briefly about this error and please let me know the solution.
i am using these two pins as bidirectional , is it same way to using API's(Read and Write functions used for output pin) for bidirectional pin also?
for more information about the pin mapping question , find the below image.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Datasheet for PSoC4 tells: Ports 4 and larger cannot be used for routing, only for firmware control. Yes, reading and writing is the same for bidirectional pins.
Bob