![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | Thread Tools | Display Modes |
| | (permalink) |
| Experienced Member | Hi. Writing a code for my bot and I ran into this problem... The following is a piece of my code for moving the stepper motors. Code: STEPS macro number movlw number movwf STEPCOUNT endm STEPPER macro dir movlw dir movwf PORTB WAIT .100 DECF STEPCOUNT,1 btfsc STATUS,Z goto loop endm and to move 10 steps forward: Code: STEPS .10 forward STEPPER 0x88 STEPPER 0x9A STEPPER 0x12 STEPPER 0x56 STEPPER 0x44 STEPPER 0x65 STEPPER 0x21 STEPPER 0xA9 goto forward
__________________ Here...let me improve it for you! *Puff of smoke* ....oops... |
| | |
| | (permalink) | |
| Experienced Member | Quote:
Code: STEPPER: call GET_MOTOR_STATE movwf PORTB wait .100 decfsz STEPCOUNT,f goto STEPPER return GET_MOTOR_STATE: incf COUNTER,f movf COUNTER,w andlw b'00000111' addwf PCL,F retlw 0x88 retlw 0x9A retlw 0x12 retlw 0x56 retlw 0x44 retlw 0x65 retlw 0x21 retlw 0xA9
__________________ "Having to do with Motion Control" | |
| | |
| | (permalink) |
| Experienced Member | but what happens when I need to turn after moving forward? Let's say the mottors stopped at 0x21. There won't be such position in left-turn table...
__________________ Here...let me improve it for you! *Puff of smoke* ....oops... |
| | |
| | (permalink) | |
| Super Moderator | Quote:
So if your forward table is stopped at 0x21, you need to start at 0x21 in the reverse table. | |
| | |
| | (permalink) |
| Experienced Member | yes, but for turning the values are 22,44,88,AA,99,11 I was thinking of having separate tables for each stepper. Like 0x8,0x9,0xA for one stepper ans 0x08, 0x09, 0x0A for the other and adding up the two values to get the actual portb value.
__________________ Here...let me improve it for you! *Puff of smoke* ....oops... |
| | |
| | (permalink) | |
| Super Moderator | Quote:
| |
| | |
| | (permalink) |
| Experienced Member | You need two separate counters, one for each motor. To move forward, you increment the counter. To move in reverse, you decrement. After increment/decrement, call GET_MOTOR_STATE to obtain the motor phase (once per motor/ twice for two motors). You then merge the values and output to PORTB. Code: STEPPER: btfsc MOTOR_DIR1 incf COUNTER1,f btfss MOTOR_DIR1 decf COUNTER1,f ; movf COUNTER1,w call GET_MOTOR_STATE movwf TEMP_REG swapf TEMP_REG,f ; btfsc MOTOR_DIR2 incf COUNTER2,f btfss MOTOR_DIR2 decf COUNTER2,f ; movf COUNTER2,w call GET_MOTOR_STATE iorwf TEMP_REG,w movwf PORTB ; wait .100 decfsz STEP_COUNT,f goto STEPPER ; return GET_MOTOR_STATE: andlw b'00000111' addwf PCL,F retlw 0x8 retlw 0xA retlw 0x2 retlw 0x6 retlw 0x4 retlw 0x5 retlw 0x1 retlw 0x9
__________________ "Having to do with Motion Control" |
| | |