Open Naitry opened 2 months ago
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
-> https://github.com/roboticsatiowa/Rover_Embedded/pull/11#issuecomment-2369965179
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:: https://github.com/PaulStoffregen/cores/blob/master/teensy4/IntervalTimer.h https://github.com/PaulStoffregen/cores/blob/master/teensy4/IntervalTimer.cpp
It's similar to what I was doing, but a little more intricate and flexible.
with commit https://github.com/roboticsatiowa/Rover_Embedded/pull/11/commits/2fb7243c6902b2cc5d13aede30b3e2cb7de3219b 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
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.
Status:
built successfully but not tested in practice