Menu

Small motor control program needs work?

Help
2009-02-09
2013-05-30
  • Nobody/Anonymous

    [code]
    #chip PIC16F84A, 20 MHz
    #define Xinputstep PORTA.1
    #define Xinputdirection PORTA.2 
    #define Xmotoroutput1 PORTB.0 
    #define Xmotoroutput2 PORTB.1
    #define Xmotoroutput3 PORTB.2
    #define Xmotoroutput4 PORTB.3
    ADOff
        DIR Xinputdirection IN
        DIR Xinputdirection IN
        DIR Xmotoroutput1   OUT
        DIR Xmotoroutput2   OUT
        DIR Xmotoroutput3   OUT
        DIR Xmotoroutput4   OUT

    If xinputstep       = ON THEN
    If Xinputdirection = ON THEN

        PULSEOUT xmotoroutput1, 10us
       WAIT 10us
        PULSEOUT xmotoroutput1, 10us
        PULSEOUT xmotoroutput2, 10us
       WAIT 10us
        PULSEOUT xmotoroutput2, 10us
       WAIT 10us
        PULSEOUT xmotoroutput2, 10us
        PULSEOUT xmotoroutput3, 10us
       WAIT 10us
        PULSEOUT xmotoroutput3, 10us
       WAIT 10us
        PULSEOUT xmotoroutput3, 10us
        PULSEOUT xmotoroutput4, 10us
       WAIT 10us
        PULSEOUT xmotoroutput4, 10us
       WAIT 10us
        PULSEOUT xmotoroutput4, 10us
        PULSEOUT xmotoroutput1, 10us
    END IF
    END IF

    Will pulse out work or should I use set? set on and then set off for a specific time?
    The ouput of the parrallel port for the cnc program is a high (low voltage actually) for a step and the direction is either a high(for one direction or low for the opposite). I have defined 1 direction but I need a bit of help figuring out the other.
    Can you use [ELSE]?
    Could I rewrite the first bit
    (
    If xinputstep       = ON THEN
    If Xinputdirection = OFF THEN
    + the opposite motor sequence?
    )
    Is their a easier way!!??
    First program ever so it might be really crappy!!!
    Also could you take a quick look for any mistakes - im so excited to learn about the motor control in general -my dog needs to go out every morning at 5am - im thinking automatic sliding door!!

    Thanks in advance, Chris  

     
    • Nobody/Anonymous

      **Code amended**
      How do you use the internal clock aswell, or should i buy a 4mhz crystal? still have to do Y axis.

      #chip PIC16F84A, 4 MHz
      #define Xinputstep PORTA.1
      #define Xinputdirection PORTA.2 
      #define Xmotoroutput1 PORTB.0 
      #define Xmotoroutput2 PORTB.1
      #define Xmotoroutput3 PORTB.2
      #define Xmotoroutput4 PORTB.3
      ADOff
          DIR Xinputdirection IN
          DIR Xinputdirection IN
          DIR Xmotoroutput1   OUT
          DIR Xmotoroutput2   OUT
          DIR Xmotoroutput3   OUT
          DIR Xmotoroutput4   OUT
      start: 
      If xinputstep       ON THEN
      If Xinputdirection ON THEN

          PULSEOUT xmotoroutput1, 10us
         WAIT 10us
          PULSEOUT xmotoroutput1, 10us
          PULSEOUT xmotoroutput2, 10us
         WAIT 10us
          PULSEOUT xmotoroutput2, 10us
         WAIT 10us
          PULSEOUT xmotoroutput2, 10us
          PULSEOUT xmotoroutput3, 10us
         WAIT 10us
          PULSEOUT xmotoroutput3, 10us
         WAIT 10us
          PULSEOUT xmotoroutput3, 10us
          PULSEOUT xmotoroutput4, 10us
         WAIT 10us
          PULSEOUT xmotoroutput4, 10us
         WAIT 10us
          PULSEOUT xmotoroutput4, 10us
          PULSEOUT xmotoroutput1, 10us
      END IF
      If Xinputdirection OFF THEN
          PULSEOUT xmotoroutput4, 10us
          PULSEOUT xmotoroutput1, 10us
         WAIT 10us
             PULSEOUT xmotoroutput4, 10us
         WAIT 10us
          PULSEOUT xmotoroutput3, 10us
          PULSEOUT xmotoroutput4, 10us
         WAIT 10us
          PULSEOUT xmotoroutput3, 10us
         WAIT 10us
          PULSEOUT xmotoroutput2, 10us
          PULSEOUT xmotoroutput3, 10us
         WAIT 10us
          PULSEOUT xmotoroutput2, 10us
         WAIT 10us
          PULSEOUT xmotoroutput1, 10us
          PULSEOUT xmotoroutput2, 10us
         WAIT 10us
          PULSEOUT xmotoroutput1, 10us
      END IF
      END IF
      goto start
      RETURN

       
    • Nobody/Anonymous

      hey I was compiling to HEX and got this  ""Register in operand not in bank 0.  Ensure that bank bits are correct."" should I be worried?

       
    • Nobody/Anonymous

      >hey I was compiling to HEX and got this ""Register in operand not in bank 0. Ensure that >bank bits are correct."" should I be worried?

      No... don't worry that's just an informative message from assembler, GCBasic takes care about bank issues...

       
    • Nobody/Anonymous

      thanx for the reply Im building the circuit now i'll see if this code approah goes alright compared to an array

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.