Pages: [1]   Go Down
Author Topic: Stepper sync from encoder?  (Read 507 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Everyone:

I am very new to Arduino.
Could somebody write code for me? I want to use encoder to control Stepper(sync 1:1 or any changeable Ratio, like 1:3).
BTW, I prefer NOT use "Interrupt" to achieve, because I will use this code as one subroutine in my loop, "Interrupt" may cause mess in loop.

Thanks in advance.

Richard
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
BTW, I prefer NOT use "Interrupt" to achieve
To achieve what? Encoders are almost always read using interrupts, since you do not want to miss any pulses, even if you are busy doing something else (like waiting for a stepper to step).

Quote
because I will use this code as one subroutine in my loop, "Interrupt" may cause mess in loop.
Comparing the number of steps commanded and the number of steps achieved can be done in the subroutine, even though the number of steps achieved is counted in the ISR.

Quote
"Interrupt" may cause mess in loop.
Not if properly written. The clock ticks. That triggers an interrupt. Does that cause mess in loop()? Of course not. Serial data arrives. That causes an interrupt. Does that cause mess in loop()? Of course not.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

PaulS:

Thanks for your reply.

The code(sketch) I need:
"use Rotary Encoder(OUTPUT A, B) to control Stepper motor(DIR, STEP), when encoder turns 1 rev. , Stepper motor turns 3 rev.)

(Using Interrupt in code is OK)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First thing to do is look at the playground, and find the article on encoders. Copy the code, and connect the encoder correctly. Verify that changes to the encoder position actually cause the interrupt routine to be invoked.

When you know that that works, computing the number of steps that need to be taken is simply a matter of knowing the encoder count last time stepping happened, and the current encoder count. Multiply the difference by 3, step, and reset the previous encoder count value.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12549
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Note that the requirement is based on a ratio of revolutions, not a ratio of steps.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: