aamott / petinator

Firmware for bottle-to-filament machines
GNU General Public License v3.0
24 stars 2 forks source link

Use a different way to control steppers #11

Closed T00ManySecrets closed 1 year ago

T00ManySecrets commented 1 year ago

Is your feature request related to a problem? Please describe.

Maybe it would be possible to use a different way to control steppers as fastAccelStepper does not support a lot of chips. eg. I'm trying to reuse an old board for a 3D printer that uses Atmega1284P. It has everything i would need for this project but mighty core chips are not supported by the fastAccelStepper library.

Describe the solution you'd like

Use the standard stepper library for Arduino if possible as most of the chips that are added to Arduino support it.

Describe any alternatives you've considered

Additional context

I do not know the exact reason why fastAccelStepper is used but I think we do not need anything fancy to just use one stepper to pull material. If people can use most 3d printer boards would make this a much better project.

aamott commented 1 year ago

I actually wanted to use that in the first place, but the trouble is that the Arduino stepper library needs to run in the foreground. Even a 5ms delay in a loop causes the stepper to jolt, and updating the display takes ~300ms. The display library is far from optimized though, so maybe it would be feasible after optimizing it. I remember finding someone who showed how to optimize it in fact. Still, even updating the PID values took enough time to cause noticeable "ticking" when spinning fast.

FastAccelStepper uses timers. It uses assembly code (as I understand it) to manipulate the 3 PWM pin timers into controlling one pin (the step pin) at a specific rate. These timers can run in the background unaffected by the other code running in the foreground. I believe Marlin uses the same method, but better coded and much better supported. I've thought about the issue and wondered if Marlin's stepper code could be adapted for this.

aamott commented 1 year ago

I did a little more research today and it looks like Marlin and GRBL both use highly optimized code, mostly using int instead of float (which is used everywhere in every other library) for almost everything. Here's a thread on the Arduino Forum talking about it. For future note, this section of GRBL might be useful: stepper.h. Making use of this will require optimizing the menu, the LCD code, and the PID code. AutoPID could be changed to FastPID. The hd44780 LCD library is supposed to be fast. I think it can run the LCD without i2C as well using the hd44780_pinIO subclass. This would mean rewriting the menu code to use that library and separating it out into a file.

aamott commented 1 year ago

Update: It looks like there's a generic library, TimerInterrupt_Generic, that supports many processors, including pretty much every one I've seen in a 3D printer. I think it might be easier to write a timer interrupt to call the standard Arduino stepper library.

aamott commented 1 year ago

@T00ManySecrets If you want to give it a try, I made some major changes in the timer-free branch to get everything to run in the main loop, no interrupts required. There's still some work to be done, and I would rather get the interrupts working like Marlin, but it seems like for now, it's more important to make it flexible. Once the PID is tuned, it should work quite well.

aamott commented 1 year ago

@T00ManySecrets Give this a go. I haven't pulled it in yet so others can test it if wanted, but if you pull the timer-free branch, it should compile as soon as you've got the pinout. I'd love to have a tester!