Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 1 > Newbie program question

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



Newbie program question
Moderator:
ARVI

Post Reply
Follow this topic



Newbie program question

Cf_corp posted on 16 Aug 2012 6:29 AM PST
Top Contributor
74 Forum Posts

Hi guys,

Im just trying to familiarise with the wondeful world of PSoC,

I have the PSoC 3210 Eval1 board and ive written a little code that makes an output (connected to an led) go high when an input is low and the output will go low when the input is high (switching off the led)

basically i have an output configured which is driven "strong" all the time and its connected via cable to an input which if its high the led will be off and if its low the led will illuminate

my code looks a little like this:

void main(void)

{

PRT0DR |= 0X10; //makes P0.4 HIGH, this provides a high signal for the input P0.0

while(1)

{

if (PRT0Dr & 0x01) //checks

{

PRT1DR &= ~0X01; //toggles output 1.0 which has led connected to show result

}

else

{

PRT1DR |= 0X01;

}

when i power the psoc board up and the input is low the led is on but when i make the input high the output led goes off, the problem is if i make the input low again the led wont illuminate again. I want to be able to make the led go on and off an infinite number of time depending on whether the input is high or low,

any help would be appreciated

thank you

 

 




Re: Newbie program question

Cf_corp posted on 16 Aug 2012 06:53 AM PST
Top Contributor
74 Forum Posts

In my other post I was asking about the led_Read() and led_Write(1) as I wanted to know if i could just use the read and write command to manipulate port pins rather than using the PRT0DR etc command,

I also noticed that if i made the input pin "high" resulting in the LED/Output port being "low" and I reset the PSoC chip then when i make the input port low then output port/LED would stay the same and not change.



Re: Newbie program question

Bob Marlowe posted on 16 Aug 2012 07:05 AM PST
Top Contributor
1768 Forum Posts

Hi Cathal,

At first sight I can see that you did nor obey the hint of either using a shadow-register or using an LED-component.

PRT1DR |= 0x01 is a read-modify-write instruction for a port. The read gets the voltage currently connected to the pin (NOT the value you wrote to the pin the last time) which will be about 1.7V (due to the LED-voltage) which will be interpreted as a logical Zero (0).

To circumvent this problem see above: Use a shadow-register or an LED-component.

 

Bob



Re: Newbie program question

Cf_corp posted on 16 Aug 2012 07:10 AM PST
Top Contributor
74 Forum Posts

Thanks Bob,

I will take your advice and try using a shadow-register or an LED component,

thank you for your assistance



Re: Newbie program question

danaaknight posted on 16 Aug 2012 07:37 AM PST
Top Contributor
1773 Forum Posts

Taken from LED datashsheet -

 

The project using the LED User Module which manipulates pins on a port shared with an instance of the LED

User Module must avoid direct PRTxDR writes. The Shadow Registers should be used for such manipulation

to prevent incorrect LED User Module operation.

 

Regards, Dana.



Re: Newbie program question

Cf_corp posted on 17 Aug 2012 03:30 AM PST
Top Contributor
74 Forum Posts

I was following up on the shadow register guide and video here: http://www.cypress.com/?rID=2900

I downloaded the project files and had a look at the sample code for the shadow registers, it seems a bit much for a sample code for all i want my code to do,

I followed the video as much as I could understand, I set up a shadow register on port 1 and from the psocconfig.asm file in the source folder I see its called Port_1_Data_Shade

I set up a small program that has P1.1 as a constant output, P1.1 as an output to drive and LED for example, and P1.0 as the input which when high will activate the LED on port 1.2.

void main(void)

{

Port_1_Data_Shade |= 0x04;

PRT1DR = Port_1_Data_SHADE; // not sure if this required as this should always be high

while(1)

{

if (PRT1DR & 0X01)

{

Port_1_Data_Shade |= 0x02;

PRT1DR = Port_1_Data_Shade;

}

else

{

Port_1_Data_SHADE &= ~0x02;

PRT1DR = Port_1_Data_SHADE;

}

This seems to work ok,

Any pointers?

thanks guys

 

 

 

 

 



Re: Newbie program question

danaaknight posted on 17 Aug 2012 04:06 AM PST
Top Contributor
1773 Forum Posts


Re: Newbie program question

danaaknight posted on 17 Aug 2012 04:14 AM PST
Top Contributor
1773 Forum Posts


Re: Newbie program question

danaaknight posted on 17 Aug 2012 04:19 AM PST
Top Contributor
1773 Forum Posts

You need to setup switch debounce for mechanical switches/buttons.
Use Sleep timer, and set up an ISR for it. Inside ISR set a flag,
return, then inc a cnttime variable, looking for ~ > 100 mS key down.
Essentially same for key release.


ISRs


http://www.planetpsoc.com/psoc1-articles-digital/13-basics-of-psoc-gpio.html?start=7
http://www.planetpsoc.com/psoc1-articles-digital/13-basics-of-psoc-gpio.html?start=6
http://www.planetpsoc.com/component/content/article/43-writing-a-c-isr.html

 


Regards, Dana.



Re: Newbie program question

Cf_corp posted on 17 Aug 2012 06:16 AM PST
Top Contributor
74 Forum Posts

Hi Dana,

Thanks for your reply, I am using a switch for now but eventually the signal will be a digital input, in that application with a digital output can i still use stdCPU and strong drive to make the output high and can the output still be stdCPU in pulldown mode to toggle an LED or something on another output. I plan on not using a mechanical switch and just stick to using a wire which when cut or damaged will illuminate an led

thanks



Re: Newbie program question

danaaknight posted on 17 Aug 2012 07:39 AM PST
Top Contributor
1773 Forum Posts

If you are driving an LED normally you drive it with low side MOSFET in the

output (on when output low), open drain, or just STDCPU is fine as well. Driving

with low side MOSFET is a lower RDSon device than high side device, due to

source bulk effect affecting high side MOSFET threshold.

 

So preferred drive is LED to port, other side thru current limit R to Vdd.

 

Regards, Dana.



Re: Newbie program question

Cf_corp posted on 17 Aug 2012 07:50 AM PST
Top Contributor
74 Forum Posts

Hi Dana,

Thanks for your input, very helpful indeed,

I have the output set to strong at the moment and the LEDs have a current limiting resistor before them,

is strong ok if i want to make an output high to drive a transistor to say trigger a relay?

thanks very much

 



Re: Newbie program question

rolf posted on 17 Aug 2012 10:42 AM PST
Top Contributor
81 Forum Posts

 Hi Cathal,

 

You may use strong or strong-slow to drive the transistor. Use strong if you need fast switching, use strong-slow if you have EMC issues.

 

Regards,

Rolf



Re: Newbie program question

Cf_corp posted on 17 Aug 2012 11:33 AM PST
Top Contributor
74 Forum Posts

Hi Rolf,

Thanks so much for your useful info,

The diagram is excellent, thank you for that,

My own wiring diagram is the same as that although nowhere near as tidy. lol

thanks for your help, very helpful community here



Re: Newbie program question

danaaknight posted on 17 Aug 2012 01:12 PM PST
Top Contributor
1773 Forum Posts

To design see attached -

 

Regards, Dana.



Re: Newbie program question

danaaknight posted on 17 Aug 2012 01:16 PM PST
Top Contributor
1773 Forum Posts

A couple of additions -

 

Regards, Dana.



Re: Newbie program question

Cf_corp posted on 20 Aug 2012 03:00 AM PST
Top Contributor
74 Forum Posts

Hi Dana,

Thanks for your reply, Ive had a look through you GPIO driver circuit diagram, its very informative.

Thanks for your assistance, I really appreciate it,

 






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