Timer component--One Shot--ever

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

cross mob
DeCo_1926091
Level 4
Level 4
First like received

This may have been solved before but I was unable to find the info.  Here's my solution:

   

In trying to create a "soft switch" I connected a SPST pushbutton to a digital input pin and triggered a one shot timer with an interrupt on terminal count.  The timer was set for four seconds which means the PB had to be held for four seconds before the switch would be recognized and turn on and LED (used for testing).   However, I also wanted to turn it off by holding the same PB for another 4 seconds (after the PB had been released). Turning it on worked fine but it wouldn't turn off.  The problem is that the one-shot timer is REALLY one shot, meaning it will only work once after the program has been started.  It couldn't be reset from any API.  The only way to get it to work again was to restart the program.

   

The solution was as simple as it could possibly be, though it took me a long time to figure it out.  I simply changed the timer's run mode to Continuous instead of One-Shot, then stopped the timer in the ISR.  The APIs work when the Continuous Mode is selected. 

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The timer needs a reset which you could provide using a control register component.

   

 

   

Bob

View solution in original post

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The timer needs a reset which you could provide using a control register component.

   

 

   

Bob

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

I thought that the timer can be reset by calling _Stop()/_Start() again, or by its reset signal (for the UDB based timer). You might to write a 0 to the counter register before, though.

lock attach
Attachments are accessible only for community members.
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

decoburn,

   

take a look into Cypress "soft" switch example project and application note (AN54460 - PSoC® 3 and PSoC 5LP Interrupts):

   

http://www.cypress.com/documentation/application-notes/an54460-psocr-3-psoc-4-and-psoc-5lp-interrupt...

   

 

   

The project of interest there is B_PICU, showing "software button" setup without sparing hardware resources (e.g. Timer). Quite enough for simple SPST button interface.