-
Notifications
You must be signed in to change notification settings - Fork 0
Tyler pit steppers #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Using periodic interrupt timers, we can hopefully avoid the blocking code and still have full control over the stepper motors with timer based pulse control
|
You will have to walk me through the larger chunks of new code. Seems like you reference a lot of mysterious registers which I would like to know their purpose. some comments wouldn't hurt either, especially in cases where the code is not very self explanatory or uses niche info from the datasheet. other than that the code looks good. see if you can make any additional changes now because I'm still new to the built in code review process and would like to see how that works |
ethanholter
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see other comment
Changed to a more popular way of interfacing with the same pit timers. I have used this library before to good success. It takes away our responsibility of having to directly deal with timer registers
|
My previous implementation directly wrote to the timer control registers for the PIT timers. While I have found several examples of this usage, I could not find it in the official ARM Cortex-M7 docs, so I opted to switch to the interval timer library made for the teensy. I have used this library before and trust it to work well. Here is what they use to interface with the timers:: It's similar to what I was doing, but a little more intricate and flexible. with commit 2fb7243 I have switched to this IntervalTimer implementation, hopefully clarifying what is happening. I have also added comments throughout the IntervalTimers.hpp and Steppers.hpp files to explain my changes |
| #include <IntervalTimer.h> | ||
| #include <functional> | ||
|
|
||
| // There are only 4 timers allowed, as described in the interval timer code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might be a problem. currently we are using every single one of these. If we want to add any more hardware then we will need to find more options. for now I think this is still a better way of doing things but its something to be aware of
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, It's not totally ideal.
We have a couple options if we want to add more steppers controlled with common anode pulses in the future::
- Utilize other types of timers that should be on the teensy. We would need to interact with registers directly as these timer types are regularly controlled by analogwrite functions on teensy:: https://github.com/PaulStoffregen/cores/blob/master/teensy4/pwm.c#L236. We just need to add the open drain configuration not regularly available with pwm.
- Use dedicated hardware, I think some LED drivers would be capable of creating up to 8 or even 16 or these signals originating from I2C or SPI commands, reducing connections to the teensy, and still not something that gets blocked by serial intake.
If we are bored I think these would both be good upgrades, the dedicated hardware would allow for more full utilization of the teensy, imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

fixes #10
Primary Changes
In this I use PITs (Periodic Interrupt Timer) to output pulses for stepper motor control rather than the previous strategy where it continuously checked if the period was up.
This technically limits the steppers to 4 using these specific timers.
The timer is setup in the stepper constructor and attached to a function to flip the pulse pin of the stepper.
This allows us to reduce the calls in the main loop to only be the call to parse serial input. and never block the motors, just flip them based on interrupts.
Minor Changes
I also made a few minor stylistic changes.
All header files were changed to .hpp extension vs .h.
Header guard preprocessing statements were changed from #IFDEF style guards to #PRAGMA once
Status:
built successfully but not tested in practice