PDA

View Full Version : How to run program in parallel?



vanxn
- 18th July 2006, 18:05
Hi,

I am trying to program a multi stepper motor control program using a single PIC microcontroller. My idea is to use stepper motor controller to control the stepper motor with the step input from the PIC microcontroller. The microcontroller will also connect to some other periperals and check their status and respond to control the motors in real time. I am using MicroCode Studio and PicBasic Pro.

My idea about the program flow is like this:

When the program starts, the microcontroller will be in a main loop to check the status of the peripherals. When a signal coming in, the microcontroller will start the stepper motors as instructed. I will use "For... Next" loop and "Pulsout" to generate the step input for the stepper motors. But now the problem comes: while the microcontroller is generating the "For... Next" loop and "Pulsout" for the pulse width generation, it won't go back to the main loop to check the status of the peripherals, so if another signal coming in from the peripherals at this time, the microcontroller will not detect it.

My question is: is there any way that I can programm the micro controller to send the step out in parallel with the main loop so that the main loop will keep tracking the signals from the peripherals all the time? Any help will be highly appreciated! Thanks a lot in advance!

Sean

Charles Linquis
- 18th July 2006, 20:44
I don't know exactly what you are trying to do, but....

Most stepper motor controllers need only a very short pulse to toggle them. If that is your case, then you don't need to issue a pulse more than a couple of instructions long. You can do that in PBP with something as simple as

PORTB.0 = 0
@ nop
PORTB.0 = 1

If you truly DO need to hold the pin low (or high) for awhile, then you can set the pin to one state during one loop, and set it to the other state on a later loop. The pulse width is the loop time X the number of loops you have selected.
You can check all your inputs while you are in the loop. You will have to experiment a bit to get your timing right.

Or, you could use what I call a pseudo-interrupt. Not precise, but possibly workable in your case. Sit in a loop that checks your inputs AND for a timer roll-over. When the timer rolls over, reload it with a suitable value and jump to a routine that sets/resets your stepper controller pins. Then go back to the loop.


And then there are interrupts. If you can tolerate the overhead, you can use "ON INTERRUPT GOTO" structures. Check the PBP manual.

Or you can use Darrel Taylor's "Instant Interrupts". Search for that on this forum.

Lots of ways.

vanxn
- 18th July 2006, 21:59
Charles,

First of all I would like to thank you for your time and message you typed in. You saved my life!!!!!! I have been struggling for this issue in the past several days since I am a starter in PBP and microcontroller. I believe that you have answered my questions very well and I will follow your answers to test my program.

Best wishes to you and have a great day!

Sean