“If else” will be the downfall of humanity… May 4, 2006
Posted by Matthew Rosenbrock in Strokes of Genius, Testing, Uncategorized.add a comment
Set the scene: Late Wednesday evening. The entire project must be functional by the following afternoon. But the velocity calculations continue to be erratic. WHY?
Enter Matt.
Matt: Hey, should this "if else" statement just be an "if"?
Jon: Uh…yeah.
Matt: That would be dumb if that solved the whole problem.
Jon: Yeah. Let's try running it.
Running code.
Jon: It seems fine now.
Matt: Son of a B!t&#!
And so ended the war between code and coder.
Stepper motor in a nutshell May 2, 2006
Posted by hackinjat in Design, Strokes of Genius, Uncategorized.add a comment
I thought I’d say a few words about how the stepper motor that we have is set up, and how its going to work. Basically, the motor moves 1 “step” (7.5 degrees) each time it receives a specific sequence of pulses on its 6 wires. The great thing about stepper motors is that you dont need feedback to control it; if you know its starting position and how many steps it’s taken, you know its current position.
So, we wrote code to generate the correct sequence for us, using the digital outputs on the board to generate the pulse sequence needed to move 1 step. After the chip calculates the velocity, it determines what the correct focus ring position should be for that position. Because we record the number of steps we command the motor to take, we always know the focus ring’s current position. Using this information, the code moves the stepper the appropriate number of steps to move the focus ring to the desired position, then samples the velocity again and repeats the process.
Now, how does the sequence of voltages from the DSP power the motor you ask? Each of the digital outputs is attached to a transistor. I’m sure you recall that current can flow from the source to the drain of a transistor only when a voltage is applied to the gate. This is used in our design by attaching the source of a transistor to a 5V external power supply, the drain to a motor wire, and the gate to the digital output from the DSP. Thus, when the DSP generates a high signal, it activates the transistor gate, allowing current to flow from the external source to the motor wire. Four of these transistors are used to control 4 wires from the stepper motor coils. The other 2 stepper motor wires attach to the common ground of the coils. With the appropriate sequence, the motor coils are energized such that the permanent magnet rotor inside the motor spins to the next magnetic equilibrium point, i.e. 1 step.
You can see all this on the updated electrical diagram I’ve attached below.