# ========= ========= ========= ========= ========= ========= ========= ========= # *** TMC2130/2160/2208/2209/2225 Testing Functions *** # ========= ========= ========= ========= ========= ========= ========= ========= # 5. TMC2225 Config/Functions enblPinNum = 20 dirPinNum = 21 stepPinNum = 22 ms1PinNum = 26 ms2PinNum = 27 # *** tmc2225 Functions *** def testToggleTmc2225ControlPins(): print(' Begin testToggleTmc2225ControlPins(), ...') toggleGpOutPinNumList([enblPinNum, dirPinNum, stepPinNum, ms1PinNum, ms2PinNum], \ highTime = quarterSecond, lowTime = quarterSecond, \ repeatTimes = once, totalToggleTimes = once) print(' End testToggleTmc2225ControlPins(), ...') return # *** Sample Tests *** #printProgramName() #testToggleTmc2225ControlPins() # *** Enable/Disable Driver *** def tmcEnblDriver(enblPinNum): enblPin = gpOutPinDict[str(enblPinNum)] setGpOutPinLow(enblPin) return #tmcEnblDriver(enblPinNum) def tmcDisblDriver(enblPinNum): enblPin = gpOutPinDict[str(enblPinNum)] setGpOutPinHigh(enblPin) return #tmcDisblDriver(enblPinNum) # *** Set CW/CCW Direction *** def tmcSetDirCcw(dirPinNum): dirPin = gpOutPinDict[str(dirPinNum)] setGpOutPinHigh(dirPin) return #tmcSetDirCcw(dirPinNum) def tmcSetDirCw(dirPinNum): dirPin = gpOutPinDict[str(dirPinNum)] setGpOutPinLow(dirPin) return #tmcSetDirCw(dirPinNum) # *** Set 1/4, 1/8, 1/16, 1/32 microstepping resolution *** def tmcSetOneFourthStep(ms1PinNum, ms2PinNum): # MS2, MS1: 00: 1/4, 01: 1/8, 10: 1/16, 11: 1/32 ms2Pin = gpOutPinDict[str(ms2PinNum)] ms1Pin = gpOutPinDict[str(ms1PinNum)] setGpOutPinLow(ms2Pin) setGpOutPinLow(ms1Pin) return #tmcSetOneFourthStep(ms1PinNum, ms2PinNum) def tmcSetOneEighthStep(ms1PinNum, ms2PinNum): ms2Pin = gpOutPinDict[str(ms2PinNum)] ms1Pin = gpOutPinDict[str(ms1PinNum)] setGpOutPinLow(ms2Pin) setGpOutPinHigh(ms1Pin) return #tmcSetOneEighthStep(ms1PinNum, ms2PinNum) def tmcSetOneSixteenthStep(ms1PinNum, ms2PinNum): ms2Pin = gpOutPinDict[str(ms2PinNum)] ms1Pin = gpOutPinDict[str(ms1PinNum)] setGpOutPinHigh(ms2Pin) setGpOutPinLow(ms1Pin) return #tmcSetOneSixteenthStep(ms1PinNum, ms2PinNum) def tmcSetOneThirtySecondStep(ms1Pin, ms2Pin): ms1Pin = gpOutPinDict[str(ms1PinNum)] ms2Pin = gpOutPinDict[str(ms2PinNum)] setGpOutPinHigh(ms1Pin) setGpOutPinHigh(ms2Pin) return # tmcSetOneThirtySecondStep(ms1PinNum, ms2PinNum) # sample test call def tmcSendOneStepPulse(stepPinNum, halfPulsePeriodUs): stepPin = gpOutPinDict[str(stepPinNum)] setGpOutPinHigh(stepPin) utime.sleep_us(halfPulsePeriodUs) setGpOutPinLow(stepPin) utime.sleep_us(halfPulsePeriodUs) return def tmcSendMultipleStepPulses(stepPinNum, halfPulsePeriodUs, pulsesTotal): print(' Begin tmcSendMultipelStepPulses(), ...') for count in range(pulsesTotal): tmcSendOneStepPulse(stepPinNum, halfPulsePeriodUs) print(' End tmcSendMultipleStepPulses().') return def tmcSendOneMilliSecondStepPulses(stepPinNum, pulsesTotal): tmcSendMultipleStepPulses(stepPinNum, 500, pulsesTotal) return #tmcSendMultipleStepPulses(stepPinNum = 22, halfPulseTime = halfMilliSecond, pulsesTotal = fiveThousand) #tmcSendMultipleStepPulses(stepPinNum = 22, halfPulsePeriodUs = 500, pulsesTotal = 5000) def testTmc2225V01(): printProgramName() # Print program name, author name, data testToggleTmc2225ControlPins() tmcSetOneFourthStep(ms1PinNum, ms2PinNum) # Set microstepping resolution 1/4 tmcSetDirCcw(dirPinNum = 21) # Set direction counter clockwise tmcSendOneMilliSecondStepPulses(stepPinNum = 22, pulsesTotal = 2000) # Send 2000 1ms step pulses pause(oneSecond) # Pause one second tmcSetDirCw(dirPinNum = 21) # Set direction clockwise tmcSendOneMilliSecondStepPulses(stepPinNum = 22, pulsesTotal = 3000) # Send 3000 1ms step pulses pause(oneSecond) # Pause one second tmcSetOneEighthStep(ms1PinNum, ms2PinNum) # Set microstepping resolution 1/32 tmcSendOneMilliSecondStepPulses(stepPinNum = 22, pulsesTotal = 3000) # Send 3000 1ms step pulses return # *** Sample Tests *** #testTmc2225V01() # test <<<<<<<<<<