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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...