26 lines
804 B
Python
26 lines
804 B
Python
"""Encoder functions."""
|
|
|
|
MAX_RPM = 1200.0
|
|
|
|
|
|
def pulse_freq(rpm, pulses_per_rev):
|
|
"""Calculate the pulse frequency."""
|
|
rotations_per_second = rpm / 60.0
|
|
pulses_per_second = rotations_per_second * pulses_per_rev
|
|
return pulses_per_second
|
|
|
|
|
|
if __name__ == '__main__':
|
|
for x in range(0, 101):
|
|
rpm = MAX_RPM * (x * 0.01)
|
|
pulse_freq_at_rpm = pulse_freq(rpm, 6000)
|
|
print("{}\t\t{}".format(rpm, round(pulse_freq_at_rpm / 1000000.0, 4)))
|
|
|
|
last_freq_at_maxrpm = 0.0
|
|
for pulses_per_rev in range(0, 65536):
|
|
freq_at_maxrpm = pulse_freq(MAX_RPM, pulses_per_rev)
|
|
if last_freq_at_maxrpm < 500000.0 and freq_at_maxrpm >= 500000.0:
|
|
print("500 kHz at {}".format(pulses_per_rev))
|
|
exit()
|
|
last_freq_at_maxrpm = freq_at_maxrpm
|