Hello, I have a project in which I am making a CNC machine. I am using stepper motors, however, I am having problems making the acceleration/decleration timer values work. My machine requires 3200 steps to move one inch. Now, this is what I have done. I am using Timer0 to handle acceleration and deceleration. I am using timer 1 to handle constant speed. What I want to happen is that initially the motion begins in timer 0 which is constantly adjusted until timer 0 values are equal or greater that timer 1 values. Then, turn off timer 0 and turn on timer 1 for the constant maintained speed. Then when the motion is about over, timer 1 will disable itself and set a flag for timer 0 to indicate a deceleration and then enable timer 0. First, my question is how can I determine the constant acceleration value given an acceleration rate of 30"/sec^2. I mean what value do I add to the timer 0 registers on each interrupt to achieve a smooth acceleration from 0" to say 5"/sec with a give acceleration rate? I can't seem to get this part to work at all. Here is the code that I have tried. ;My variables are ACCELRATE_L ACCELRATE_H ;This is the constant to add to the current acceleration timer 0 values. ACCELMOTION_L ACCELMOTION_H ;These are the current timer values each time timer 0 interrupts. MOTIONRATE_L MOTIONRATE_H ;These are the desired speed to accelerate up to. These are use to set timer 1 for constant rate. Now, lets say that I want to have a constant speed of 5"/sec that would make my MOTIONRATE LOW AND HIGH = (0xffff - (.10000000/(.5*3200))) remembering that 1" inch is 3200 pulses. This makes it equal to 0xFD8E. Is this correct? My device is running at 40MHz so Focs/4 = .10000000 as shown above. So I set MOTIONRATE_L = 0X8E and MOTIONRATE_H = 0XFD. For an acceleration I initially set ACCELMOTION_L and ACCELMOTION_H = 0x00 because we are starting from 0" /sec QUESTION: What should I set ACCELRATE_L and ACCELRATE_H to for an acceleration rate of 30"/sec^2? How do I calculate this value? Such that my timer 0 routine would look something like this: BTFSS ACCELFLAGS, ACCEL_ACTIVE ; Are we accelerating or decelerating? BRA Decelerate ; Ok we are accelerating. MOVF ACCELRATE_L, W, BANKED ADDWF ACCELMOTION_L, F, BANKED MOVF ACCELRATE_H, W, BANKED ADDWFC ACCELMOTION_H, F, BANKED ; Check to see if Rate is >= to desired rate MOVF ACCELMOTION_L, W, BANKED SUBWF MOTIONRATE_L, W, BANKED MOVF ACCELMOTION_H, W, BANKED SUBWFB MOTIONRATE_H, W, BANKED ;Is new value greate than desired constant speed? BTFSS STATUS, C, A ; A low on C indicates a borrow. BRA AccComplete ;Yes, then we are done accelerating. ; No, then load need rate into timer 0 and take motion set for desired axis. MOVFF ACCELMOTION_H, TMR0H MOVFF ACCELMOTION_L, TMR0L BRA TakeMotionSteps ; Branch to step routine I have tried using a constant like 0x04ff for the acceleration rate, but it does not seem to work because for the first second of motion, the motors appear to only move at a fixed slow rate, then just jump to full speed. It does appear however, that the deceleration routine works.???? It code is the following: ;Make sure we are in an active deceleration BTFSS ACCELFLAGS,DECEL_ACTIVE,BANKED RETFIE FAST ;This condition should not happen. ;Timer 0 is for accel/decel only. MOVF ACCELRATE_L,W,BANKED SUBWF ACCELMOTION_L,F,BANKED MOVF ACCELRATE_H,W,BANKED SUBWFB ACCELMOTION_H,F,BANKED BTFSS STATUS,C,A ;If result is a borrow then we are done. BRA DeccComplete ;Check for < than desired rate MOVF PREVIOUSRATE_L,W,BANKED SUBWF ACCELMOTION,W,BANKED MOVF PREVIOUSRATE_L,W,BANKED SUBWFB ACCELMOTION,W,BANKED BTFSS STATUS,C,A ;If negative, then make equal. BRA DeccComplete ;Check for equality MOVF PREVIOUSRATE_L, W, BANKED CPFSEQ ACCELMOTION_L, W, BANKED BRA DecelContinue ;Not equal so continue. MOVF PREVIOUSRATE_H, W, BANKED CPFSEQ ACCELMOTION_H, W, BANKED BRA DecelContinue ; Not equal so continue. ;Ok values are equal so complete the routine and turn off timer. MOVF A_ARG_L,W,BANKED IORWF A_ARG_H,BANKED ;Equal? BTFSC STATUS,Z,A BRA DeccComplete DecelContinue: ;Otherwise, move new rate into timer zero, then CALL step routine MOVFF ACCELMOTION_H,TMR3H MOVFF ACCELMOTION_L,TMR3L BRA TakeMotionSteps -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu