How to run program in parallel?


Closed Thread
Results 1 to 3 of 3

Hybrid View

  1. #1
    vanxn's Avatar
    vanxn Guest

    Question How to run program in parallel?

    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
    Last edited by vanxn; - 18th July 2006 at 21:51.

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    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.
    Charles Linquist

  3. #3
    vanxn's Avatar
    vanxn Guest


    Did you find this post helpful? Yes | No

    Thumbs up Thanks a million!

    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

Similar Threads

  1. Presetting Configuration Fuses (PIC Defines) into your Program
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 82
    Last Post: - 15th December 2013, 09:54
  2. Replies: 1
    Last Post: - 23rd May 2009, 09:22
  3. Program compiles and writes but can't run
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 23rd March 2009, 04:38
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts