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!
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.