Calibrating TM310 motors speed vs PWM duty cycle
Now I am using pico’s GP0, 1, 2, 3 to output 4 PWM signals to the two TB6612FNG motor drivers’s 4 motor driving channels, and check out the corresponding motor speed by detecting the encoder’s A signals and do the pps (pulse per second) to rpm calculation by using Pico.
Notes:
-
C = GP 0, 1, 2, 3 PWM output pins
-
D = GP 4, 5, 6, 7 Interrupt input pins
-
E = 4 x TM301 motor encoder A signals
-
F = 4 x TB6612FNG PWM input control signals
-
A, B = 2 x TB6612FNG’s other control signals manually jumpered to Vcc and Gnd.
-
G, H = 2 x TB6612 motor driver modules
Testing PWM Duty Cycle 50%, 10%, 90% OK
I am using the following function calls to generate signals of duty cycle 50%, 10%, and 90% and found all is well. Next step is to calibrate duty cycle vs motor speed.
# testSetupPwmPinList(pwmDutyCycle = 50)
# testSetupPwmPinList(pwmDutyCycle = 10)
# testSetupPwmPinList(pwmDutyCycle = 90)
The full listing of code.
# *** pwm_int_37.py - pwm and interrupt testing, tlfong01, 2021oct03hkt2110 ***
from machine import Pin, PWM
import utime
# ========= ========= ========= ========= ========= ========= ========= =========
# ========= ========= ========= ========= ========= ========= ========= =========
# Conents
#
# Part 1 - PWM Functions
# 1.1 Using PWM pin to fade in and fade out the system LED
# 1.2 Using GP 0, 1, 2, 3 pins' PWM signalsto control the speed of TB6612FNG driving TM310 DC motor
# Part 2 - Interrupt Functions
# 2.1 Using GP4, 5, 6, 7 input pins to detect and count mtor encoder A signals and calculate motor speed
# *** Part 1 - PWM Functions ***
def pwmSystemLed():
systemLedPinNum = 25
pwmPin = PWM(Pin(systemLedPinNum))
pwmPin.freq(1000)
for count in range(4):
for dutyCycle in range(65025):
pwmPin.duty_u16(dutyCycle)
utime.sleep(0.0001)
for dutyCycle in range(65025, 0, -1):
pwmPin.duty_u16(dutyCycle)
utime.sleep(0.0001)
return
def testPwmSystemLed():
print('testPwmSystemLed(), ...')
print(' System LED now fades in and out a couple of times')
pwmSystemLed()
print(' End of test.')
return
# *** Sample Test ***
#testPwmSystemLed()
# ========= ========= ========= ========= ========= ========= ========= =========
# ========= ========= ========= ========= ========= ========= ========= =========
# *** Setup 4 PWM Pins ***
# Notes:
# 1. Setting up GP 0, 1, 2, 3 as pwm pins at 1 kHz, 50% duty cycle
# 2. Connecting the pwm pins to the pwm inputs of TB6612FNG move the DC motor TM310.
# *** Pwm Pin Numbers and List ***
pwmPinNum0 = 0
pwmPinNum1 = 1
pwmPinNum2 = 2
pwmPinNum3 = 3
pwmPinNumList = [pwmPinNum0, pwmPinNum1, pwmPinNum2, pwmPinNum3]
# *** Pwm Pin Objects and List ***
pwmPin0 = PWM(Pin(pwmPinNum0))
pwmPin1 = PWM(Pin(pwmPinNum1))
pwmPin2 = PWM(Pin(pwmPinNum2))
pwmPin3 = PWM(Pin(pwmPinNum3))
pwmPinList01 = [pwmPin0, pwmPin1, pwmPin2, pwmPin3]
# *** Defualt Frequency and Duty Cycle ***
defaultPwmFreq = 1000
defaultPwmDutyCycle = 50
# *** Initializing Pwm Pin Objects and List ***
def setPwmFreq(pwmPin, pwmFreq):
pwmPin.freq(pwmFreq)
return
def setPwmDutyCycle(pwmPin, dutyCycle):
u16DutyCycle = int((dutyCycle / 100) * 65536)
pwmPin.duty_u16(u16DutyCycle)
return
def setupPwmPinList(pwmPinList, pwmFreq, pwmDutyCycle):
print(' pwmFreq =', pwmFreq)
print(' pwmDutyCycle =', pwmDutyCycle)
for pwmPin in pwmPinList:
setPwmFreq(pwmPin, pwmFreq)
setPwmDutyCycle(pwmPin, pwmDutyCycle)
return
def testSetupPwmPinList(pwmDutyCycle):
setupPwmPinList(pwmPinList = pwmPinList01, pwmFreq = 1000, pwmDutyCycle = pwmDutyCycle)
return
# Sample test ***
#testSetupPwmPinList(pwmDutyCycle = 50)
#testSetupPwmPinList(pwmDutyCycle = 10)
testSetupPwmPinList(pwmDutyCycle = 90)
# ========= ========= ========= ========= ========= ========= ========= =========
# ========= ========= ========= ========= ========= ========= ========= =========
# Interrupt functions for multiple (4) interrupt pins GP 4, 5, 6, 7 ***
intPinNum0 = 4
intPinNum1 = 5
intPinNum2 = 6
intPinNum3 = 7
intPinNumList = [intPinNum0, intPinNum1, intPinNum2, intPinNum3]
intPin0 = Pin(intPinNum0, Pin.IN, Pin.PULL_DOWN)
intPin1 = Pin(intPinNum1, Pin.IN, Pin.PULL_DOWN)
intPin2 = Pin(intPinNum2, Pin.IN, Pin.PULL_DOWN)
intPin3 = Pin(intPinNum3, Pin.IN, Pin.PULL_DOWN)
intPinDict = {
'0': intPin0,
'1': intPin1,
'2': intPin2,
'3': intPin3,
}
global intCount0
global intCount1
global intCount2
global intCount3
intCount0 = 0
intCount1 = 0
intCount2 = 0
intCount3 = 0
intCountDict = {
'0': intCount0,
'1': intCount1,
'2': intCount2,
'3': intCount3,
}
def intCallBack0(pin):
global intCount0
intCount0 = intCount0 + 1
return
def intCallBack1(pin):
global intCount1
intCount1 = intCount1 + 1
return
def intCallBack2(pin):
global intCount2
intCount2 = intCount2 + 1
return
def intCallBack3(pin):
global intCount3
intCount3 = intCount3 + 1
return
intCallBackDict = {
'0': intCallBack0,
'1': intCallBack1,
'2': intCallBack2,
'3': intCallBack3,
}
intPin0.irq(intCallBack0, Pin.IRQ_FALLING)
intPin1.irq(intCallBack1, Pin.IRQ_FALLING)
intPin2.irq(intCallBack2, Pin.IRQ_FALLING)
intPin3.irq(intCallBack3, Pin.IRQ_FALLING)
def measureIntPinIntSeconds(intPinNum, seconds):
#intPin = intPinDict[str(intPinNum)]
#intPin.irq(intCallBackDict[str(intPinNum)], Pin.IRQ_FALLING)
global intCount0
global intCount1
global intCount2
global intCount3
intCount0 = 0
intCount1 = 0
intCount2 = 0
intCount3 = 0
utime.sleep(seconds)
if intPinNum == 0:
newIntCount = intCount0
elif intPinNum == 1:
newIntCount = intCount1
elif intPinNum == 2:
newIntCount = intCount2
else:
newIntCount = intCount3
return newIntCount
def testMeasureIntPinIntSeconds(intPinNum, seconds):
newIntCount = measureIntPinIntSeconds(intPinNum, seconds)
print('\n', intPinNum, ' ', end = '')
print(newIntCount, ' ', end = '')
print('{:.2f}'.format(newIntCount / 12), ' ', end = '')
print('{:.2f}'.format((newIntCount / 12) / 90), ' ', end = '')
print('{:.2f}'.format(((newIntCount / 12) / 90) * 60), ' ', end = '')
return
def measureFourIntPinIntSeconds(intPinNumList):
intCountList = [0, 0, 0, 0]
for count in range(len(intPinNumList)):
intCountList[count] = measureIntPinIntSeconds(intPinNumList[count], 1)
return intCountList
# *** Test functions ***
def testMeasureQuadInterrupts():
print('\ntestMeasureQuadInterrupts(), ...')
print('\n ------------------------------------------------------------------', end = '')
print('\n intPinNum pps 1:1 rps 1:90 rps rpm', end = '')
print('\n ------------------------------------------------------------------', end = '')
testMeasureIntPinIntSeconds(intPinNum = 0, seconds = 1)
testMeasureIntPinIntSeconds(intPinNum = 1, seconds = 1)
testMeasureIntPinIntSeconds(intPinNum = 2, seconds = 1)
testMeasureIntPinIntSeconds(intPinNum = 3, seconds = 1)
print('\n ------------------------------------------------------------------', end = '')
return
def testMeasureFourInterrupts(intPinNumList):
ppsList = measureFourIntPinIntSeconds(intPinNumList)
print('ppsList =', ppsList)
print('minimum =', min(ppsList))
print('maximum =', max(ppsList))
print('average =', int(sum(ppsList) / len(ppsList)))
rpmList = ppsList.copy()
for count in range(len(rpmList)):
rpmList[count] = int(((rpmList[count] / 12) / 90) * 60)
print('\nrpmList =', rpmList)
print('minimum =', min(rpmList))
print('maximum =', max(rpmList))
print('average =', int(sum(rpmList) / len(rpmList)))
dpsList = ppsList.copy()
for count in range(len(dpsList)):
dpsList[count] = float(((dpsList[count] / 12) / 90) * 3.14 * 6.3)
print('\ndpsList =', (dpsList))
print('minimum =', '{:.2f}'.format(min(dpsList)))
print('maximum =', '{:.2f}'.format(max(dpsList)))
print('average =', '{:.2f}'.format(float(sum(dpsList) / len(dpsList))))
return
# *** Main Tests ***
#testMeasureFourInterrupts([4, 5, 6, 7])
# *** End ***
# *** Sample Output tlfong01 2021oct0201 ***
'''
'''
# *** End of Sample Output ***
Measuring 4 PWMs vs 4 Speeds OK
Now I am using the setPWM and MeasureInterrupts to do PWM vs Speed and found things more or less OK, except minor things such as one wheel does not turn at duty cycle at 10%. So 20% dc seems to be the smallest to do practical experiments.
#testSetupPwmPinList(pwmDutyCycle = 50)
#testSetupPwmPinList(pwmDutyCycle = 90)
testSetupPwmPinList(pwmDutyCycle = 20)
testMeasureFourInterrupts([4, 5, 6, 7])
Below is a summary of the results. Full result and code listing is shown after that.
>>> %Run -c $EDITOR_CONTENT
testSetupPwmPinList(), ... tlfong01 2021oct04hkt1025
pwmFreq = 1000
pwmDutyCycle = 50
ppsList = [2391, 2401, 2391, 2396]
rpmList = [132, 133, 132, 133]
dpsList = [43.79516, 43.97832, 43.79516, 43.88674]
pwmDutyCycle = 90
ppsList = [2796, 2874, 2883, 2859]
rpmList = [155, 159, 160, 158]
dpsList = [51.2134, 52.64211, 52.80696, 52.36735]
>>> %Run -c $EDITOR_CONTENT
pwmDutyCycle = 20
ppsList = [1631, 1505, 1631, 1613]
rpmList = [90, 83, 90, 89]
dpsList = [29.87449, 27.56658, 29.87449, 29.54479]
pwmDutyCycle = 10
ppsList = [1295, 1019, 941, 967]
rpmList = [71, 56, 52, 53]
dpsList = [23.72008, 18.66468, 17.23598, 17.71222]
# *** pwm_int_40.py - pwm and interrupt testing, tlfong01, 2021oct04hkt1037 ***
from machine import Pin, PWM
import utime
# ========= ========= ========= ========= ========= ========= ========= =========
# ========= ========= ========= ========= ========= ========= ========= =========
# Conents
#
# Part 1 - Interrupt Functions
# 1.1 Using GP4, 5, 6, 7 input pins to detect and count mtor encoder A signals and calculate motor speed
# Part 2 - PWM Functions
# 2.1 Using PWM pin to fade in and fade out the system LED
# 2.2 Using GP 0, 1, 2, 3 pins' PWM signalsto control the speed of TB6612FNG driving TM310 DC motor
# ========= ========= ========= ========= ========= ========= ========= =========
# ========= ========= ========= ========= ========= ========= ========= =========
# Interrupt functions for multiple (4) interrupt pins GP 4, 5, 6, 7 ***
intPinNum0 = 4
intPinNum1 = 5
intPinNum2 = 6
intPinNum3 = 7
intPinNumList = [intPinNum0, intPinNum1, intPinNum2, intPinNum3]
intPin0 = Pin(intPinNum0, Pin.IN, Pin.PULL_DOWN)
intPin1 = Pin(intPinNum1, Pin.IN, Pin.PULL_DOWN)
intPin2 = Pin(intPinNum2, Pin.IN, Pin.PULL_DOWN)
intPin3 = Pin(intPinNum3, Pin.IN, Pin.PULL_DOWN)
intPinDict = {
'0': intPin0,
'1': intPin1,
'2': intPin2,
'3': intPin3,
}
global intCount0
global intCount1
global intCount2
global intCount3
intCount0 = 0
intCount1 = 0
intCount2 = 0
intCount3 = 0
intCountDict = {
'0': intCount0,
'1': intCount1,
'2': intCount2,
'3': intCount3,
}
def intCallBack0(pin):
global intCount0
intCount0 = intCount0 + 1
return
def intCallBack1(pin):
global intCount1
intCount1 = intCount1 + 1
return
def intCallBack2(pin):
global intCount2
intCount2 = intCount2 + 1
return
def intCallBack3(pin):
global intCount3
intCount3 = intCount3 + 1
return
intCallBackDict = {
'0': intCallBack0,
'1': intCallBack1,
'2': intCallBack2,
'3': intCallBack3,
}
intPin0.irq(intCallBack0, Pin.IRQ_FALLING)
intPin1.irq(intCallBack1, Pin.IRQ_FALLING)
intPin2.irq(intCallBack2, Pin.IRQ_FALLING)
intPin3.irq(intCallBack3, Pin.IRQ_FALLING)
def measureIntPinIntSeconds(intPinNum, seconds):
#intPin = intPinDict[str(intPinNum)]
#intPin.irq(intCallBackDict[str(intPinNum)], Pin.IRQ_FALLING)
global intCount0
global intCount1
global intCount2
global intCount3
intCount0 = 0
intCount1 = 0
intCount2 = 0
intCount3 = 0
utime.sleep(seconds)
if intPinNum == 0:
newIntCount = intCount0
elif intPinNum == 1:
newIntCount = intCount1
elif intPinNum == 2:
newIntCount = intCount2
else:
newIntCount = intCount3
return newIntCount
def testMeasureIntPinIntSeconds(intPinNum, seconds):
newIntCount = measureIntPinIntSeconds(intPinNum, seconds)
print('\n', intPinNum, ' ', end = '')
print(newIntCount, ' ', end = '')
print('{:.2f}'.format(newIntCount / 12), ' ', end = '')
print('{:.2f}'.format((newIntCount / 12) / 90), ' ', end = '')
print('{:.2f}'.format(((newIntCount / 12) / 90) * 60), ' ', end = '')
return
def measureFourIntPinIntSeconds(intPinNumList):
intCountList = [0, 0, 0, 0]
for count in range(len(intPinNumList)):
intCountList[count] = measureIntPinIntSeconds(intPinNumList[count], 1)
return intCountList
# *** Test functions ***
def testMeasureQuadInterrupts():
print('\ntestMeasureQuadInterrupts(), ...')
print('\n ------------------------------------------------------------------', end = '')
print('\n intPinNum pps 1:1 rps 1:90 rps rpm', end = '')
print('\n ------------------------------------------------------------------', end = '')
testMeasureIntPinIntSeconds(intPinNum = 0, seconds = 1)
testMeasureIntPinIntSeconds(intPinNum = 1, seconds = 1)
testMeasureIntPinIntSeconds(intPinNum = 2, seconds = 1)
testMeasureIntPinIntSeconds(intPinNum = 3, seconds = 1)
print('\n ------------------------------------------------------------------', end = '')
return
def testMeasureFourInterrupts(intPinNumList):
ppsList = measureFourIntPinIntSeconds(intPinNumList)
print('ppsList =', ppsList)
print('minimum =', min(ppsList))
print('maximum =', max(ppsList))
print('average =', int(sum(ppsList) / len(ppsList)))
rpmList = ppsList.copy()
for count in range(len(rpmList)):
rpmList[count] = int(((rpmList[count] / 12) / 90) * 60)
print('\nrpmList =', rpmList)
print('minimum =', min(rpmList))
print('maximum =', max(rpmList))
print('average =', int(sum(rpmList) / len(rpmList)))
dpsList = ppsList.copy()
for count in range(len(dpsList)):
dpsList[count] = float(((dpsList[count] / 12) / 90) * 3.14 * 6.3)
print('\ndpsList =', (dpsList))
print('minimum =', '{:.2f}'.format(min(dpsList)))
print('maximum =', '{:.2f}'.format(max(dpsList)))
print('average =', '{:.2f}'.format(float(sum(dpsList) / len(dpsList))))
return
# ========= ========= ========= ========= ========= ========= ========= =========
# ========= ========= ========= ========= ========= ========= ========= =========
# *** Part 2 - PWM Functions ***
def pwmSystemLed():
systemLedPinNum = 25
pwmPin = PWM(Pin(systemLedPinNum))
pwmPin.freq(1000)
for count in range(4):
for dutyCycle in range(65025):
pwmPin.duty_u16(dutyCycle)
utime.sleep(0.0001)
for dutyCycle in range(65025, 0, -1):
pwmPin.duty_u16(dutyCycle)
utime.sleep(0.0001)
return
def testPwmSystemLed():
print('testPwmSystemLed(), ...')
print(' System LED now fades in and out a couple of times')
pwmSystemLed()
print(' End of test.')
return
# *** Sample Test ***
#testPwmSystemLed()
# ========= ========= ========= ========= ========= ========= ========= =========
# ========= ========= ========= ========= ========= ========= ========= =========
# *** Setup 4 PWM Pins ***
# Notes:
# 1. Setting up GP 0, 1, 2, 3 as pwm pins at 1 kHz, 50% duty cycle
# 2. Connecting the pwm pins to the pwm inputs of TB6612FNG move the DC motor TM310.
# *** Pwm Pin Numbers and List ***
pwmPinNum0 = 0
pwmPinNum1 = 1
pwmPinNum2 = 2
pwmPinNum3 = 3
pwmPinNumList = [pwmPinNum0, pwmPinNum1, pwmPinNum2, pwmPinNum3]
# *** Pwm Pin Objects and List ***
pwmPin0 = PWM(Pin(pwmPinNum0))
pwmPin1 = PWM(Pin(pwmPinNum1))
pwmPin2 = PWM(Pin(pwmPinNum2))
pwmPin3 = PWM(Pin(pwmPinNum3))
pwmPinList01 = [pwmPin0, pwmPin1, pwmPin2, pwmPin3]
# *** Defualt Frequency and Duty Cycle ***
defaultPwmFreq = 1000
defaultPwmDutyCycle = 50
# *** Initializing Pwm Pin Objects and List ***
def setPwmFreq(pwmPin, pwmFreq):
pwmPin.freq(pwmFreq)
return
def setPwmDutyCycle(pwmPin, dutyCycle):
u16DutyCycle = int((dutyCycle / 100) * 65536)
pwmPin.duty_u16(u16DutyCycle)
return
def setupPwmPinList(pwmPinList, pwmFreq, pwmDutyCycle):
print(' pwmFreq =', pwmFreq)
print(' pwmDutyCycle =', pwmDutyCycle)
for pwmPin in pwmPinList:
setPwmFreq(pwmPin, pwmFreq)
setPwmDutyCycle(pwmPin, pwmDutyCycle)
return
def testSetupPwmPinList(pwmDutyCycle):
print(' testSetupPwmPinList(), ... tlfong01 2021oct04hkt1025')
setupPwmPinList(pwmPinList = pwmPinList01, pwmFreq = 1000, pwmDutyCycle = pwmDutyCycle)
return
# Sample test ***
#testSetupPwmPinList(pwmDutyCycle = 50)
#testSetupPwmPinList(pwmDutyCycle = 10)
#testSetupPwmPinList(pwmDutyCycle = 90)
# *** Main Tests ***
#testSetupPwmPinList(pwmDutyCycle = 50)
#testSetupPwmPinList(pwmDutyCycle = 90)
testSetupPwmPinList(pwmDutyCycle = 20)
testMeasureFourInterrupts([4, 5, 6, 7])
# *** End ***
# *** Sample Output tlfong01 2021oct0201 ***
'''
>>> %Run -c $EDITOR_CONTENT
testSetupPwmPinList(), ... tlfong01 2021oct04hkt1025
pwmFreq = 1000
pwmDutyCycle = 50
ppsList = [0, 0, 0, 0]
minimum = 0
maximum = 0
average = 0
rpmList = [0, 0, 0, 0]
minimum = 0
maximum = 0
average = 0
dpsList = [0.0, 0.0, 0.0, 0.0]
minimum = 0.00
maximum = 0.00
average = 0.00
>>> %Run -c $EDITOR_CONTENT
testSetupPwmPinList(), ... tlfong01 2021oct04hkt1025
pwmFreq = 1000
pwmDutyCycle = 50
ppsList = [2391, 2401, 2391, 2396]
minimum = 2391
maximum = 2401
average = 2394
rpmList = [132, 133, 132, 133]
minimum = 132
maximum = 133
average = 132
dpsList = [43.79516, 43.97832, 43.79516, 43.88674]
minimum = 43.80
maximum = 43.98
average = 43.86
>>> %Run -c $EDITOR_CONTENT
testSetupPwmPinList(), ... tlfong01 2021oct04hkt1025
pwmFreq = 1000
pwmDutyCycle = 90
ppsList = [2796, 2874, 2883, 2859]
minimum = 2796
maximum = 2883
average = 2853
rpmList = [155, 159, 160, 158]
minimum = 155
maximum = 160
average = 158
dpsList = [51.2134, 52.64211, 52.80696, 52.36735]
minimum = 51.21
maximum = 52.81
average = 52.26
>>> %Run -c $EDITOR_CONTENT
testSetupPwmPinList(), ... tlfong01 2021oct04hkt1025
pwmFreq = 1000
pwmDutyCycle = 10
ppsList = [1295, 1019, 941, 967]
minimum = 941
maximum = 1295
average = 1055
rpmList = [71, 56, 52, 53]
minimum = 52
maximum = 71
average = 58
dpsList = [23.72008, 18.66468, 17.23598, 17.71222]
minimum = 17.24
maximum = 23.72
average = 19.33
>>> %Run -c $EDITOR_CONTENT
testSetupPwmPinList(), ... tlfong01 2021oct04hkt1025
pwmFreq = 1000
pwmDutyCycle = 20
ppsList = [1631, 1505, 1631, 1613]
minimum = 1505
maximum = 1631
average = 1595
rpmList = [90, 83, 90, 89]
minimum = 83
maximum = 90
average = 88
dpsList = [29.87449, 27.56658, 29.87449, 29.54479]
minimum = 27.57
maximum = 29.87
average = 29.22
>>> %Run -c $EDITOR_CONTENT
testSetupPwmPinList(), ... tlfong01 2021oct04hkt1025
pwmFreq = 1000
pwmDutyCycle = 20
ppsList = [1572, 1620, 1614, 1665]
minimum = 1572
maximum = 1665
average = 1617
rpmList = [87, 90, 89, 92]
minimum = 87
maximum = 92
average = 89
dpsList = [28.7938, 29.673, 29.5631, 30.49725]
minimum = 28.79
maximum = 30.50
average = 29.63
>>>
'''
# *** End of Sample Output ***
A shorter summary is this:
DutyCycle 90%, pps = 2853, rpm = 158
DutyCycle 50%, pps = 2394, rpm = 132
DutyCycle 20%, pps = 1595, rpm = 88
DutyCycle 10%, pps = 1055, rpm = 58
Excel shows that duty cycle vs rpm is more or less linear:
Actually it is not important for duty cycle vs speed to be linear, because to sync speeds, Pico will be adjusting duty cycles in real time.
The time has come to do the real thing: synchronizing the wheel speeds, which is necessary to move the 4WD in straight line, in a circle, in a square etc. Stay tuned. 
Setting up PWM and measuring motor speed as a list of 4 motors/pins
Now I have modified the code to process the four motors as a list. The code is again too long, hitting the 32k limit, so I am not listing it here. A summary of the tests is show below:
# *** Main Tests ***
setupPwmPinListV2(pwmPinNumList = [0, 1, 2, 3], pwmFreqList = [1000, 1000, 1000, 1000],
pwmDutyCycleList = [90, 90, 90, 90])
testMeasureIntPinNumListInt100Ms([0, 1, 2, 3])
# *** End ***
# *** Sample Output tlfong01 2021oct04hkt1657 ***
'''
>>> %Run -c $EDITOR_CONTENT
testSetupPwmPinNumListV2(), ...
pwmPinNumList = [0, 1, 2, 3]
pwmFreqList = [1000, 1000, 1000, 1000]
pwmDutyCycleList = [90, 90, 90, 90]
testMeasureIntPinNumListInt100Ms()
ppsList = [36, 34, 26, 33] , min = 26 , max = 36 , avg = 32
rpmList = [20, 18, 14, 18] , min = 14 , max = 20 , avg = 17
>>>
'''
# *** End of Sample Output ***
Cross Calibrating Speed of Four 4WD Motors
Now I have modified the program to do the following:
-
Setup PWM frequency and PWM duty cycle of the list of 4 motors.
-
Repeat count the interrupts (pps) and calculate the speed (rpm)
The following results shows how reliable or consistent are the speed of four motors at the same pwm frequency and duty cycle.
Next step is to try to adjust individual duty cycle to each motor so that they move the “same” speed.
# *** Sample Output tlfong01 2021oct04hkt1657 ***
'''
>>> %Run -c $EDITOR_CONTENT
setupPwmPinNumList(), ...
pwmPinNumList = [0, 1, 2, 3]
pwmFreqList = [1000, 1000, 1000, 1000]
pwmDutyCycleList = [50, 50, 50, 50]
testCountIntPinNumListIntOneTenthSecond()
ppsList = [32, 28, 26, 24] , min 24 , max 32 , avg 27 rpmList = [17, 15, 14, 13] , min 13 , max 17 , avg 14
ppsList = [27, 24, 31, 34] , min 24 , max 34 , avg 29 rpmList = [15, 13, 17, 18] , min 13 , max 18 , avg 15
ppsList = [31, 28, 27, 21] , min 21 , max 31 , avg 26 rpmList = [17, 15, 15, 11] , min 11 , max 17 , avg 14
ppsList = [27, 27, 28, 30] , min 27 , max 30 , avg 28 rpmList = [15, 15, 15, 16] , min 15 , max 16 , avg 15
>>> %Run -c $EDITOR_CONTENT
setupPwmPinNumList(), ...
pwmPinNumList = [0, 1, 2, 3]
pwmFreqList = [1000, 1000, 1000, 1000]
pwmDutyCycleList = [25, 25, 25, 25]
testCountIntPinNumListIntOneTenthSecond()
ppsList = [32, 22, 24, 20] , min 20 , max 32 , avg 24 rpmList = [17, 12, 13, 11] , min 11 , max 17 , avg 13
ppsList = [17, 16, 24, 20] , min 16 , max 24 , avg 19 rpmList = [9, 8, 13, 11] , min 8 , max 13 , avg 10
ppsList = [21, 21, 22, 21] , min 21 , max 22 , avg 21 rpmList = [11, 11, 12, 11] , min 11 , max 12 , avg 11
ppsList = [24, 22, 17, 27] , min 17 , max 27 , avg 22 rpmList = [13, 12, 9, 15] , min 9 , max 15 , avg 12
>>> %Run -c $EDITOR_CONTENT
setupPwmPinNumList(), ...
pwmPinNumList = [0, 1, 2, 3]
pwmFreqList = [1000, 1000, 1000, 1000]
pwmDutyCycleList = [20, 20, 20, 20]
testCountIntPinNumListIntOneTenthSecond()
ppsList = [21, 23, 19, 21] , min 19 , max 23 , avg 21 rpmList = [11, 12, 10, 11] , min 10 , max 12 , avg 11
ppsList = [20, 19, 16, 18] , min 16 , max 20 , avg 18 rpmList = [11, 10, 8, 10] , min 8 , max 11 , avg 9
ppsList = [21, 22, 14, 20] , min 14 , max 22 , avg 19 rpmList = [11, 12, 7, 11] , min 7 , max 12 , avg 10
ppsList = [21, 23, 20, 15] , min 15 , max 23 , avg 19 rpmList = [11, 12, 11, 8] , min 8 , max 12 , avg 10
>>> %Run -c $EDITOR_CONTENT
setupPwmPinNumList(), ...
pwmPinNumList = [0, 1, 2, 3]
pwmFreqList = [1000, 1000, 1000, 1000]
pwmDutyCycleList = [90, 90, 90, 90]
testCountIntPinNumListIntOneTenthSecond()
ppsList = [71, 24, 21, 21] , min 21 , max 71 , avg 34 rpmList = [39, 13, 11, 11] , min 11 , max 39 , avg 18
ppsList = [25, 41, 26, 31] , min 25 , max 41 , avg 30 rpmList = [13, 22, 14, 17] , min 13 , max 22 , avg 16
ppsList = [29, 41, 24, 29] , min 24 , max 41 , avg 30 rpmList = [16, 22, 13, 16] , min 13 , max 22 , avg 16
ppsList = [37, 37, 0, 35] , min 0 , max 37 , avg 27 rpmList = [20, 20, 0, 19] , min 0 , max 20 , avg 14
>>>
'''
Unreliable/unrepeatable speeds at duty cylcle 90%. Duty cycles in the range of 20% to 50% are more reliable.
So I will start experimenting with duty cycle 25%.
This reply is approaching the forum;s 32k words limit. So I will start a new reply.
/ to continue, …