I'm controlling 4 stepper motors with my raspberry PI, and I need to step them in a control loop cycling at a specified rate as low as once every 40 microseconds. The motors won't always be stepped every loop; instead, one will be stepped every 3 loops for example while another will be stepped every two. This I'll be able to code in myself. I'm just stuck with getting a timer interrupt on the Raspberry Pi that calls a function every 40 or more microseconds.
I've seen from research on the internet that Linux wouldn't be able to do this well because of other interrupts going on in the OS. So is there a bare metal way I could do this? I want to preferably program the actual stepper controller in C++.
I know this is doable with an Arduino because of the hardware timers, but unless it's totally not possible on the RPI I want to stick to using the RPI.
EDIT: Due to some confusion in comments, I'm gonna clear up what exactly I need. I need about 48 different possible frequencies for 4 different pins. The frequency individual pins give out will change from time to time as well. I will use a serial pin for communication to change the frequencies of pins.