Cant get I/O to work

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

 Hey

   

I am trying to understand how i can add an external button that can turn on the internal LED. I just need a little help.
 

   

I have attached a archieve of the project.

   

it is very simple.

   

when i press the button the led turns on. when i release it turns off.

   

Regards Jason

0 Likes
10 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

First, your project is using both an old PSoC3 device (ES2 version) and old components. You should upgrade to the recent version of Creator (2.2) - or are you bound to the old PSoC3 version? (the replacement program for old PSoC3 boards has unfortunately been shut down as of now).

   

But to your question: your circuit should work, but the input pin must be configured as digital input pin. When you try to compile the design, the error message gives it away:

   

Terminals "LED.y_0" connected to signal "Net_33" have mismatching types

   

To drive a digital signal (your output pin) you need a digital signal. This can be either the input pin directly, or you need to use a comparator to convert the analog input to a digital signal.

   

Which Development kit are you using? Are you sure the pins are assigned correctly? (I cannot remember a kit where the LEDs are on port 2 and an input button is on port0[0])

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Since I didn't look at your code before: you don't need it. All the functionality is already provided in the hardware 🙂

   

But when you want to solve it in software:

   
        
  • change the input pin to digital, as before
  •     
  • remove the wire between the two pins
  •     
  • set both pins not to have "HW connection" (that means they are on its own, and have no further connection inside of the PSoC hardware)
  •     
  • the code uses wrong logic - you check in both if-statements for the same condition, but the second one should be reversed. Better to use if-else.
  •     
  • use Pin_Write to set the value of an output port. Pin_SetDriveMode just changes the way the pins behaves, but doesn't set it low or high (please read the data sheet for the pin component)
  •    
0 Likes
Anonymous
Not applicable

 I am using psoc 3 first touch starter kit.

   

I am bound to the old version unfortunately.

   

basically i just need to know how to read the input from a button.

   

when i know the right command i will use it to navigate in my menu. 

   

i have change it to a digital input now. it compiles fine now but the button has no effect. The led keeps lit.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

If you are bound to the old PSoC3, you cannot update the Creator version 😞

   

Do you now have a solution completely in hardware, or do you still use the software-part?

   

When you code just wants to read the button state, you can use the debouncer component, and feed its output to a status register. Then your code can read this register, and be happy. Same goes for the LED - just add a control register (connected to the LED), and write to that.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

I just tested the hardware-only solution with my -050 kit, and it works (just needed to change the input to pullup, since the button here is connected to ground, not Vcc). It works without problems. But I checked the schematic for the FTK, and it shows the push-button connected to P15[3]. So this might be the culprit...

0 Likes
Anonymous
Not applicable

 This here is just a part of the project.

   

I am making a menu so the buttons is for navigating in my menu.

   

but i cant get the buttons to react so i just tried to make a simple project as i uploaded here.

   

the program i uploaded should just turn on the led when i press the button. 

   

on my board on pin P15_3 i have a button. thats way i have attached pin_1 there.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Does the test-project work when using the button on P15[3]  (which is the button already exisitng on the board)? If yes, the maybe your button setup is wrong... As I said - I tested the pure hardware solution (while commenting out the whole code in the while()-loop), and it works.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Some observations -

   

 

   

1) Your project will not compile because you configed input pin as analog and

   

connected it to a pin configed as digital. Input pin should be digital, with pullup

   

(since your switch connects to ground). When you compile, there is a notice

   

tab at bottom of output window, that shows all errors. You can double click an

   

error and Creator, most of the time, will show you on schematic, or in code,

   

where problem lies.

   

 

   

2) As hli pointed out, you should use glitch module to debounce pin.

   

 

   

3) You have in code a reference to Pin_1_1, but no pin on schematic. So error

   

produced, eg. a reference that does not exist.

   

 

   

4) This code -

   

 

   

    while(1)
    {
        if (CyPins_ReadPin(Pin_1_1))                    // if pin_1 equals high
        {
            LED_SetDriveMode(LED_DM_STRONG);            //Turns LED ON   
        }
        if (CyPins_ReadPin(Pin_1_0))                    // if pin_1 equals low
        {
        LED_SetDriveMode(LED_DM_STRONG);                //Turns LED ON
        }
    }

   

 

   

should be changed to -

   

 

   

    while(1)
    {
        if ( CyPins_ReadPin( Pin_1_1 ) )                    // if pin_1 equals high
 
            LED_Write( 1 );                                            //Turns LED ON   

   

        else

   

            LED_Write( 0 );                                            //Turns LED Off
 
    }

   

 

   

You were setting drive mode, not pin logical value.

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

I have an error in prior post, change the first code line to

   

 

   

        if ( CyPins_ReadPin( Pin_1_0 ) )                    // if pin_1 equals high
 

   

I had the wrong pin name, thats the corrected name of the input pin you

   

created, and Creator choose when routing. You can change the physical

   

pin by double clicking *.cydwr file in worksapce, and pick pins tab. If you

   

do the pin name will stay the same, but the physical pin will take on the

   

new setting you choose. Note generally speaking, to eliminate physical

   

vs logical pin, name the pin something meaningful, like "LEDbutton" in

   

this case.

   

 

   

Regards, Dana.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

sorry for the delay of answering.. thankyou for the replays. I Have got it to work now.  I found the command i was looking for.

   

Pin_1_Read()

0 Likes