# ftguzuntypi.py v1.5 tlfong01 2013may31
# *****************************************************************************
# Module - ftguzuntypi.py
# Description - Stepping motor, LED driver
# *****************************************************************************
# *****************************************************************************
# Imports
# *****************************************************************************
import time
import spidev
from subprocess import call
import ftspi
import ftprint
# *****************************************************************************
# Guzunty Pi test functions
# *****************************************************************************
# *****************************************************************************
# Function - Stepping motor
# Description -
# P1 pin assignment
# P1-01 = Winding 1 (A-)
# P1-02 = Winding 2 (A+)
# P1-03 = Winding 3 (B-)
# P1-04 = Winding 4 (B+)
# Activation sequences
# WaveSequence = [1, 3, 2, 4]
# FullStepSequence = [[1, 3], [1, 4], [2, 4], [2, 3]]
# HalfStepSequence = [[1], [1,4], [4], [2,4], [2], [2,3], [3]]
# Unipolar Stepping Motor Switching Sequence
# Wave sequence = 1 - 3 - 2 - 4 (A-, B-, A+, B+)
# Full step sequence = 13 - 14 - 24 - 23 (A-B-, A-B+, A+B+, A+B-)
# Half step sequence = 13 - 1 - 14 - 4 - 24 - 2 - 23 - 3
# One step swing = 1 - 3 - 1 - 3 (A-, B-, A-, B-)
# Motor windings list
# Winding A-(1) A+(2) B-(3) B+(4) COM (+5V)
# 28BYJ48 Pink Orange Blue Yellow Red
# NPM PF35 Black Yellow Brown Orange Red
# PX245 Black Green Blue Red Yelow/White
# BYJ series geared step motor - 28byj48-12-300-01
# Rated voltage - 12V
# Number of phases - 2
# Resistance per phase 300R
# Gear reduction ratio - 1:64
# Step angle - 5.625 degree /64 ??? or / 48
# Pull-in torque at 500pps - >= 300 gm
# Pull-in rate - >= 500 pps
# Detent torque - >= 350
# Noise - <= 35dB
# Sample call -
# *****************************************************************************
Wave = [0x1, 0x4, 0x2, 0x8]
WaveClockwise = [0x1, 0x4, 0x2, 0x8]
WaveCounterClockwise = list.reverse(WaveClockwise)
Clockwise = 0
CounterClockwise = 1
MilliSeconds50 = 0.05
Byj48stepAngle = 5.625
MotorStateListInit = [0x0f, 0x0f, 0x0f, 0x0f]
MotorStateQuadNibbleWordInit = 0xffff
def MoveStepMotor(motorStateList, motorNumber, stepSequence, stepAngle, stepTime, direction, angularDistance):
ftprint.PrintDoubleSpaceLine("*** Start MoveStepMotor() ***")
print "Motor state list = ", hex(motorStateList[0]), hex(motorStateList[1]), hex(motorStateList[2]), hex(motorStateList[3])
print "Motor number = ", motorNumber
print "Step sequence = ", stepSequence
print "Step angle = ", stepAngle
print "Step time = ", stepTime
print "Direction = ", direction
print "Angular distance = ", angularDistance
print "Motor state word = ", hex(MotorStateQuadNibbleWordInit)
spiChannel = spidev.SpiDev()
spiChannel.open(0, 0)
if (direction == Clockwise):
stepSequence == list.reverse(stepSequence)
print "Step sequence = ", stepSequence[0], stepSequence[1], stepSequence[2], stepSequence[3]
# motorStateQuadNibbleWord = 0x0000 | (stepSequence[0]) | (stepSequence[1] << 4) | (stepSequence[2] << 8) | (stepSequence[3] << 12)
motorStateQuadNibbleWord = 0x2222
print "StateQuadNibbleWord = ", hex(motorStateQuadNibbleWord)
motorStateHighByte = motorStateQuadNibbleWord >> 8
motorStateLowByte = motorStateQuadNibbleWord & 0x00ff
print "motorStateHighByte = ", hex(motorStateHighByte)
print "motorStateLowByte = ", hex(motorStateLowByte)
motorStateQuadNibbleWord = (motorStateQuadNibbleWord & (~(0x000f << (motorNumber * 4)))) | (0x0005 << (motorNumber * 4))
print "StateQuadNibbleWord = ", hex(motorStateQuadNibbleWord)
motorStateHighByte = motorStateQuadNibbleWord >> 8
motorStateLowByte = motorStateQuadNibbleWord & 0x00ff
print "motorStateHighByte = ", hex(motorStateHighByte)
print "motorStateLowByte = ", hex(motorStateLowByte)
spiChannel.close()
ftprint.PrintDoubleSpaceLine("*** Stop testing stepping motor N ***")
return motorStateList
# *** Sample call ***
# ftguzuntypi.MoveStepMotor(motorStateList = ftguzuntypi.MotorStateListInit,
# motorNumber = 1,
# stepSequence = ftguzuntypi.Wave,
# stepAngle = ftguzuntypi.Byj48stepAngle,
# stepTime = ftguzuntypi.MilliSeconds50,
# direction = ftguzuntypi.Clockwise,
# angularDistance = 10)
# *** Sample output ***
# *** Start Program - FongToy v1.4 tlfong01 2013may31 ***
# *** Start MoveStepMotor() ***
# Motor state list = 0xf 0xf 0xf 0xf
# Motor number = 1
# Step sequence = [1, 4, 2, 8]
# Step angle = 5.625
# Step time = 0.05
# Direction = 0
# Angular distance = 10
# Motor state word = 0xffff
# Step sequence = 8 2 4 1
# StateQuadNibbleWord = 0x2222
# motorStateHighByte = 0x22
# motorStateLowByte = 0x22
# StateQuadNibbleWord = 0x2252
# motorStateHighByte = 0x22
# motorStateLowByte = 0x52
# *** Stop testing stepping motor N ***
.END
No comments:
Post a Comment