You are here

How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3 | Cypress Semiconductor

How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3

Summary: 19 Replies, Latest post by prabhu05fe_1711731 on 13 Sep 2016 01:24 AM PDT
Verified Answers: 0
Last post
Log in to post new comments.
prabhu05fe_1711731's picture
User
39 posts

Hello Everyone,

 

I am started working on the PSOSC 3 EVB i would like to configure timer for 2sec and 5 sec interrupt (button press detection) so i cant able to execute both logic in an simple way so i request can anyone provide me some suggestions or ideas or examples how to configure the timer to detect the button pressed for 2 sec follwed by the interrupt exection and then 5 sec button press followed by timer interrupt  execution any hlep will be greatly aprreciated

 

Thank you

prabhu

user_1377889's picture
User
10120 posts

Welcome in the forum prabhu!

Easiest would be to use 2 timer components, one for 2 seconds delay, the other for 5 seconds.

 

Bob

prabhu05fe_1711731's picture
User
39 posts

Hello Bob

 

Thnak you so much for your kind reply i have attached the picture of my timer and switch top design schematics but i didnot able to configure properly 

psoc creator3.0 am using to design the top design,

in the timer there is period section which accepts max of 256 only but  i did not understand where should i place 2 seconds in the timer component and also do i suppose to use terminal count TC or nothing? where shiould i connect the output from switch? interrupt output should be connected to switch or tc ? please provide me some reference designs or suggestions to do the simple 2 seconds timer example so that i can able to cofigure 5 seconds timer by myself and also i can learn how to configure timer component by your help

 

Looking forward for your reply

 

Thank you

prabhu

user_1377889's picture
User
10120 posts

prabhu, can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

 

Bob

prabhu05fe_1711731's picture
User
39 posts

Hello Bob

Thank you for your kind reply actually what am trying to do in thsi project press the button for 2 seconds and it will turn on the device and then press the button four times whent he button press the reached the fifth press and then it will reset the device could you please chack my project and let me know what should i modify or to do to achieve this specificatiosn

 

Thank you

prabhu

user_1377889's picture
User
10120 posts

Yes, I understood, but where is your project bundle?

 

Bob

prabhu05fe_1711731's picture
User
39 posts

yes i have already attached in my top question please check it anyhow i have uploaded once again

prabhu

user_1377889's picture
User
10120 posts

Avoid lengthy code in interrupt handlers. Especially for the 8051 core this will not work.

Use code as I outlined it. Better do not make changes in the generated files. Use _StartEx() instead or the newer macro callback feature.

Do not forget to clear the interrupts: The timer needs a status register read to reset the tc flag.

Your components are a bit outdated. Use latest Creator 3.3 CP3 and update your components (under Project -> Update...)

You may set all your SCREEN_DBn to use one port. Then you can save the control register and write to the port at once.

 

Happy coding

Bob

 

prabhu05fe_1711731's picture
User
39 posts

Hello Bob

 

Thank you so much for your kind reply i did not quite  able to understand your topdesign especially timer 

in the timer configuration you set TC bu the TC is not not connected to either switch or anything else and also in the period section it is mentioned 200(unknown source what does it meant by 200?) could you please tell me exact functionality of the timer that you ahve added in the top design because i would like to add the timer for 2 seconds

I have modified my program and also the interrupt section  reduce the amount of codes

STEP1)while during the switch press it is displaying name in the LCD and during the first time button release it is displaying the LOGO

STEP2) while pressing the switch second time it is searching for UMTS and further switch press thirs time started searching the 2G/GSM

but the real issue is when i press the switch for thr fourth time it is still searching only 2G networks but i wanted to change the 3G network what is going wrong on my design?

mainly the fourth switch press suppose to happen within 5 seconds that is i would like make interrupt function to change from 3G to 2G or 2g/3g within 5 seconds what amm doing wrong in my top design or in my source code could you please cross check and provide me some necessary guidance?

i have attached my updated code

Thank you

prabhu

user_1377889's picture
User
10120 posts

In the timer configuration you set TC bu the TC is not not connected

I set the generating of an interrupt to terminal count (TC)

The clock for the timer is your 100ms clock. Period is 200, so this will be 100ms*200 = 2s

 

Switches tend to bounce. Best would be to wait after a switch interrupt happened for 100ms and see if the input is still low. Do not wait in the interrupt handler!!!

 

I do not understand your 2G/3G mimic, this you will need to solve yourself. Sounds a bit like a state machine which is solved best using a switch statement with cases.

 

Bob

prabhu05fe_1711731's picture
User
39 posts

Hello Bob 

Could you please suggest me some possible best ways to handle the button press based on your guidance i am continuing to proceed further in my project 

my questions about switch handling are:
int main()
{
    InitializeSystem();
    for(;;)
    {
            
       if(SwitchPressed)   
        {   
            HandleSwitch();
            SwitchPressed = 0;
        }
                
    }
}

Initialized the switch press  like above in the main function  during the switch press  for the first time it is getting executed properly calling the handleswitch() but after the first time i dont want my switch press to call the handleswitch() fucntion  rather i would like call another function so what should i do to handle the switch in this way can you suggest me some ideas? please

 

Thank you

prabhu

Log in to post new comments.