AtTiny as coprocessor

Hi, I have an Arduino which has to read an encoder, write the LCD and move stepper motors accordingly.

To have more accurate encoder reads, I connected both encoder pins to interrupt pins. This is ok for the encoder + encoder library, but the stepper doesn't run so smooth.
Too much for it!

So I thought why not to play with coprocessors?
My idea is to use an AtTiny as a coprocessor for the encoder reads, I can read both encoder pins with interrupt pins of the AtTiny and the encoder library as well. I've already tested it, and even at 8Mhz the results are excellent, I can read at much more speed.
Now I have to output the reads to the arduino. Serial or I2C seems to slow, so my thought is to do some kind of "easier output" for the Arduino.

Up to know the best idea I've has is to connect two output pins of the AtTiny to the arduino, one pin will be HIGH/LOW depending on the rotating sense, and the other pin will give the movement pulses.
I think this way I only need one interrupt in the Arduino, so maybe it has less work to do.

But I'm not 100% satisfied with the idea, so maybe I can find someone with more experience with encoders here, and can give me an idea of what should I do.

Any help will be very appreciated!

Why use interrupts at all?

a fast polling loop should easily do this, unless you have overly long delays on your code;

  • use of delay() (instead of using timers)
  • use of blocking code (eg while statements to wait for an event)
  • overly frequent updating of slow peripherals (eg displays, which i suspect will be your problem..consider dropping the update frequency on this).

Maybe you could post your code and someone could advise?

It can be helpful to track a looptimer variable in the main loop and display this on the serial port (just for diagnostics)

sergiv:
To have more accurate encoder reads, I connected both encoder pins to interrupt pins. This is ok for the encoder + encoder library, but the stepper doesn't run so smooth.
Too much for it!

Post your code.

You have not provided any data about the number of encoder pulses or motor steps per second and without that it is impossible to judge whether an Atmeg 328 can do what you want.

What sort of stepper motor driver are your using?

...R
stepper motor basics

Hi, thanks for posting.

I meant exactly this:

When using my coprocessor, what is better to minimize the main processor overload, while keeping the maximum response:

  • Output the coprocessor signal as a sense + pulse
  • Pin pulse for CC and other pin for CCW
  • Counter (difficult! I don't want to use I2c, serial, etc.)

sergiv:
Hi, thanks for posting.

You have not answered the questions

...R

  • Max. encoder pulses: 4kHz more is better
  • Max. Stepper pulses: 4kHz using Accelstepper
  • LCD refresh: min. 1 time per second.
  • Drivers used: Leadshine digital drivers, the model depends on the selected motor.

A single Arduino should be well able to read 4000 encoder pulses per second and produce 4000 motor steps.

Why do you think it would not be able to?

For the third time, post your code.

...R