This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

how to execute the timer interrupt during button press/release event

Hello everyone,

I am trying to implement the button /timer interrupt handler function

Running Functionalities,

  1. button(1) is pressed for 3 sec and button handler interrupt executes the Timer 3sec_handler fucntion where inside the timer handler am calling the PWM_init(); so pwm pulses are getting generated

  2. button(1) is pressed for 5 sec and then button handler interrupt executes the Timer 5sec_handler fucntion where inside the timer 5sec handler am calling the PWM_uinit(); so pwm pulses are getting stopped

function (1) is executing very well but the real problem is when i pressing the button for 5 sec then the timer _3sec handler function also getting executed and reinitialize pwm_init () while timer crossing the 3sec PWM pulses are again generated and sooner timer reaches the 5sec stops the PWM

i wanted to make pwm pulses when i press the button for 3 sec and stops the pwm pulses pressing the buton for 5sec without regenerating pwm pulses so could anyone suggest me how to overcome this issue and suggest me what are best possible logics to implement the proper button and timer handler interrupt to start and stop pwm pulses

Note. same button is used for both functionalities but if i use two buttons then they are worjing very well but trying to use only one button for both functions any ideas or suggestions would be really helpful for me

Thank you

Parents
  • Just an Idea try it should work:

    just reverse the functionality of button i.e.,

    It should start generating pulses when holding button pressed for 5 Secs and Stop generating pulses when holding button pressed for 3 sec.

    or the otherway:

    You can check the status of PWM, If PWM is running the init function used for initialization should be skipped ( if...else).

  • Thank you for your reply(faizan) Actually my aim to start a pwm pulses only if i press the button for 3 seconds and stop for 5sec button press moreover i will implement additonal functionalities for 3sec button press ( when button is pressed for 3sec start pwm pulses and aslo start advertising ) so i cannot able to reciprocate the idea if possible could you suggest me some other ideas to execute the same function

Reply
  • Thank you for your reply(faizan) Actually my aim to start a pwm pulses only if i press the button for 3 seconds and stop for 5sec button press moreover i will implement additonal functionalities for 3sec button press ( when button is pressed for 3sec start pwm pulses and aslo start advertising ) so i cannot able to reciprocate the idea if possible could you suggest me some other ideas to execute the same function

Children
No Data
Related