Hey Guys,
I am curious to know how to run two routines at the same time. for example, I have Stepper_Motor1(); and Stepper_Motor2(); routines, I want both to run at the same time. What I know is only running it sequence, which means run Stepper_Motor1(); first, then after completed, run Stepper_Motor2();. I don't want it to be in a sequence. I want it to run both at the same time.
Thanks For Your Kind Help!
There is always the possibility of using an RTOS with individual tasks.
But the normal way of doing this is actually to have the main loop compute what the stepper motors are expected to do, and actually control the motors from individual interrupt handlers.
So you select a processor that has the required hardware support for handling multiple stepper motors and then write all code around this hardware functionality.
Or merge the function of both routines to provide the parallelism you require?
Unless you have multiple cores two subroutines are not going to run at the "same" time.
Well, the code must obviously be properly "interleaved" based on the hard real time requirements to actually toggle the processor pins for the motors at the specific time required.
But it is often possible to split the code that reacts to a timer tick and updates the I/O pins or dedicated hardware, and the code that decides if the speed should be increased/decreased.
If the processor doesn't afford the multi-tasking at the time quanta desired, the use of interrupts or a state machine would perhaps suffice. Either way you'd need to decompose the task into units of work you could afford to alternate between.