The MIPS core that PIC32 uses is a very high performance CPU that was used in high end Windows workstations in the early to mid-1990s. It doesn't behave much like the 8 and 16 bit PIC chips, so it's taken me a while to get down the learning curve. The button function in the Mikroelektronika compiler library works, but requires about 10 msec to filter out the bounce when a limits switch is encountered.
Processing a button function for each step when I was running at half step slowed the y-axis down to 12-15 mm/sec. To get around that problem in firmware I wrote a smart limits switch routine that runs slow until it finds the first limits switch and then kicks the stepper motor up to full speed until it nears the other limits switch.
Using this approach lets me increase the maximum transition speed for the y-axis from 15 mm/sec to about 65 mm/sec for my firmware testing as you can see in the video clip.
It's worth noting that the Allegro driver chip has a maximum rating of 0.75 amps and the NEMA 23 is a six wire model drawing 0.5 amps per phase. I've wired it in series which brings that amperage down considerably. In spite of this I'm getting 65 mm/sec and both the stepper and the NEMA 23 are running quite cool. The driver chip requires no heat sink or fan.