This week was kind of a losing battle against stepper motor programming. I had started working on this last week, and had gotten to the point where everything was connected but the motor would only twitch, not turn. I spent a lot of time going through tutorials, data sheets, and other references. So despite being entirely too time-consuming for limited results, I did learn quite a bit this week. I'm hoping that what I'm developing now will directly go towards my final project, so it's worth the extra time.
void step_ccw() { // pulse_ApBm(); // pulse_AmBm(); // pulse_AmBp(); // pulse_ApBp(); pulse_ApBp(); pulse_AmBp(); pulse_AmBm(); pulse_ApBm(); }However, the same problem persisted. As per the data sheet, Black was paired with Green and Blue was paired with Red (though I also tried rotating the 2x2 header in increments of 90 degrees just to see...same thing...it would twitch when it was in what should be the correct orientation, and do nothing if rotated 90 degrees). Neil made a point of clarifying that wire colors, even when referenced from the correct data sheet, are never guaranteed to actually denote correct pairings. The only way to be sure is to check resistance with an oscilloscope (which I also did, and confirmed that in this case, the pairings from the data sheet were indeed correct). Charles then helped me hook it up to the oscilloscope as he supposed there might be an issue with the signal timing. We routed two channels to opposing pins on the header, and trying different configurations consistently noticed this ghosting effect on one of the channels (below). This seemed to confirm Charles' suspicion about a timing problem. The last thing we tried was changing the PWM_count variable from 100 to 200, but this also didn't have a noticeable effect.
Looking at your scope picture, the time between step pulses appears to be around 20-30us. This would imply a step frequency of 33,000 Hz, which is far too fast - think about it, at 33,000 hz stepping with a 200-step-per-rev motor, it implies the motor is rotating 10,000 rpm. Our generic iron core stepper motors cannot do this. Notice the triangular waveform of your step which is on the order or 4-5us long. This is the stepper driver trying to ramp the output voltage up but getting cut off because you end your pulses so soon. I'd recommend increasing your 'pwm counter' to, like 10000 or 20000 and trying again.So I went back and changed the PWM and step duration variables from Neil's examples. I changed the PWM_count variable from 100 to 10000 as per Charles' suggestion. When I checked on the scope, I was getting wave forms and no longer truncated triangles (although I realize now perhaps I was misusing the scope...I'm still pretty new to this). And anyway, the motor wasn't even twitching anymore.