Jump to content

Timing how long a button is pressed?


Recommended Posts

Hello,

 

I'm attempting to set up a program for jogging a stepper motor using my Samba 7 unit. I'm using a separate stepper controller because the output from the Samba when creating a pulse train was too noisy for the stepper driver at high output current (motor ran smoothly at low current, jitters at high current). Because I'm not using the Samba to produce the pulse train, I have 4bits to work with when connecting to the stepper controller. The controller will have two input bits for movement--one for running the stepper forward and one for running it backwards. I'd like to have multiple settings on the Samba for controlling how far the stepper moves a translation stage. I've setup a data table with strings and corresponding timers for the various run times to store settings. I can store and update strings in the data table, but I'd like to run a timer while the user is running the motor forwards or backwards. My questions are: how can I time how long a user presses a button, and can I do arithmetic with the timer values, and how can I store the timer in the data table (the same as how I'm currently doing it with strings?).

 

Tl;dr How can I time how long a button is pressed, can I do arithmetic with timers, and how can I store the timer in a data table.

 

I apologize if these questions have been addressed in previous forum posts that I might not have found when searching for answers.

 

Thanks,

 

Mark

Link to comment
Share on other sites

  • MVP 2023

You may perhaps want to read this post:

 

and perhaps the rest of the topic.  My program will give you an idea of the best way you can create your own timer at the smallest resolution the system can do, don't forget it uses 2.5ms when the lowest available is 1.25ms.  Checkout Interrupt routines in Help.

You might also want to look at Utils/Immediate/read 1.25ms counter, but I think the interrupt method is easiest.

cheers,

Aus

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.