Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 3 > how to toggle digital pins?

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



how to toggle digital pins?
Moderator:
RKRM

Post Reply
Follow this topic



how to toggle digital pins?

neha posted on 18 Jun 2012 2:18 AM PST
Top Contributor
85 Forum Posts

hi!

how do i toggle a software controlled digital outpin using setpin and clearpin APIs'?

kindly see the project attached below




Re: how to toggle digital pins?

srim posted on 18 Jun 2012 03:10 AM PST
Cypress Employee
121 Forum Posts

 Hi Neha,

 

You can toggle using CyPins_SetPin(CYREG_PRTx_PCy) and CyPins_ClearPin(CYREG_PRTx_PCy) where x and y are port and pin configs which in the attached project is PRT1_PC7. (x=1,y=7)

 



Re: how to toggle digital pins?

danaaknight posted on 18 Jun 2012 04:11 AM PST
Top Contributor
1773 Forum Posts


Re: how to toggle digital pins?

danaaknight posted on 18 Jun 2012 04:13 AM PST
Top Contributor
1773 Forum Posts
Declare a couple of macros #define LED2on LED_2_Write(1) #define LED2off LED_2_Write(0) Then use in code – LED2on; ………… ………… LED2off; Note, when your project compiled you have some warnings, like on this – if (statusflag= TRUE) should be if (statusflag == TRUE) Always clear your warning issues. Regards, Dana.

Re: how to toggle digital pins?

neha posted on 18 Jun 2012 05:34 AM PST
Top Contributor
85 Forum Posts

thnx srim, thnx dana..it worked!!!

cheers :)



Re: how to toggle digital pins?

sachinbvp posted on 11 Jul 2012 06:58 AM PST
Top Contributor
139 Forum Posts

neha i'll suggest u

dont depend on API use basic software coding constructs

like

use delays   P[1]=0 and then gave delay again put these statements in loop to get toggling digital led or output

 



Re: how to toggle digital pins?

Bob Marlowe posted on 11 Jul 2012 11:06 AM PST
Top Contributor
1768 Forum Posts

I am sorry, but I have to contradict your last post.

Not using APIs is a technique that will lead into a one-way-road dead-end-street.

The world is changing and so are PSoCs (there is some rumor about a PSoC4 coming). One thing that can be kept unchanged is the API for an underlying technical (hardware) function. So using APIs will prevent you from having to change your program when the outer world suddenly looks different. That might be a simple thing like a pin swapped by accident on your PCB. Everything went well on the Kit, now on frabicated pcb it won't. So change the pin. In creator when you did a good work it is only in the pins-window assigning a new value (or two if it was a swap). No API? Going trugh the program and looking up all occurences of this port- and pin-accesses and do not forget a single one. Now can you imagine what amount of program-changes you might have, when you switch from a PSoC3 to a PSoC5 when you hand-coded everything and didn't use APIs? I even find it easier to use an API for an LED-component than to use some construct to change a port pin without influencing the other pins on the same port.

 

You will sleep better when using APIs.

Bob



Re: how to toggle digital pins?

hli posted on 11 Jul 2012 12:16 PM PST
Top Contributor
675 Forum Posts

I can only second Bob with regards to the API. Use them, they make your life easier. You don't need to read so much documentation, and they avoid many pitfalls and traps for you.

However, there are two exception: if you need to access features which aren't exposed via the APIs, or if you really really need to care about performance, and the APIs provide too much overhead (which is rarely the case with PSoC, since the generated code is already streamlined for your configuration). And for the latter one, look up the two rules of Donald Knuth about performance optimizations, before you do any :)



Re: how to toggle digital pins?

danaaknight posted on 11 Jul 2012 12:26 PM PST
Top Contributor
1773 Forum Posts

I will contradict the API rule as follows -

 

1) The reason we love PSOC is its register based architecture. Finally analog meets digital

meets FPGA flexibility.

2) Coders writing APIs do not have your specific project in mind and its performance needs.

3) We love PSOC because there are APIs for the basics (contradicting my own points).

4) All of us are getting pushed competitively, exploiting HW and SW is how that gets done.

5) There are dangers in register manipulation, same is true trying to get an ice cream cone

at MacDonalds. :)

6) PSOC has a component authoring tool for the purpose of creating off the wall components.

7) PSOC has Verilog to get down to the sub register level, gates. Hoorah.

 

So lets walk that tightrope and memorialize the ones that fall, and laud the ones that make it :)

 

Regards, Dana.



Re: how to toggle digital pins?

neha posted on 11 Jul 2012 09:45 PM PST
Top Contributor
85 Forum Posts

Thnx sachin, Bob, hli  and danaa.

 



Re: how to toggle digital pins?

pnielsen3 posted on 25 Oct 2012 08:05 AM PST
Top Contributor
107 Forum Posts

In PSoC 1 I created a h file for all the I/O ports. This let me toggle all pins. EX: P1[1] . Turm on port 1 bit 1. Can I use this type of code for the PSoC 3?



Re: how to toggle digital pins?

Bob Marlowe posted on 25 Oct 2012 09:32 AM PST
Top Contributor
1768 Forum Posts

For every pin of a PSoC3 / 5 there is a #define to access it with the help of 3 macros to read, set or reset any pin (except on port 15 some pins). Have a look into the System Reference Guide (Help -> Documentation -> System Reference)

 

Bob 



Re: how to toggle digital pins?

pnielsen3 posted on 25 Oct 2012 01:52 PM PST
Top Contributor
107 Forum Posts

Thank you very much for responding so quickly. I will do my homework so I can toggle the pins.

 

Thank You,

Philip

 



Re: how to toggle digital pins?

PSoC Rocks posted on 26 Oct 2012 10:11 PM PST
Top Contributor
128 Forum Posts

 Refer to the attached project for toggling the GPIO using SFRs.



Re: how to toggle digital pins?

pnielsen3 posted on 26 Oct 2012 11:42 AM PST
Top Contributor
107 Forum Posts

Where is the attached project?



Re: how to toggle digital pins?

pnielsen3 posted on 26 Oct 2012 01:16 PM PST
Top Contributor
107 Forum Posts

Under help, the reference guide was excelent.

 

Thank You,

 

Philip 



Re: how to toggle digital pins?

Bob Marlowe posted on 27 Oct 2012 11:01 PM PST
Top Contributor
1768 Forum Posts

You are always welcome!

 

Bob



Re: how to toggle digital pins?

PSoC Rocks posted on 28 Oct 2012 05:33 AM PST
Top Contributor
128 Forum Posts

Attaching the project here...



Re: how to toggle digital pins?

sachinbvp posted on 31 Oct 2012 06:57 AM PST
Top Contributor
139 Forum Posts

Digital Pins can be toggled by using the software constructs or PWM API






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20