And then I modified the AFMotor.cpp and AFMotor.h where the pins were defined as below, but I couldn't run the test program: only the stepper motor #2 (which I did't change the pins) works. The stepper motor 1 is trying to rotate (I can feel when I touched it) but it seems to have not enough power or mixed pulses.
I thought those pins, 11,3 and 9,10 are all PWM capable pins so it should work. Any suggesion or comment will be appreciated.
Oh, I also changed the pins for the shift register to save the pin 12.
Here are the parts of the libraries I modified.
AFMotor.h
- Code: Select all
//
//
// Bit positions in the 74HCT595 shift register output
#define MOTOR1_A 1 //2
#define MOTOR1_B 2 //3
#define MOTOR2_A 0 //1
#define MOTOR2_B 3 //4
#define MOTOR3_A 4 //5
#define MOTOR3_B 6 //7
#define MOTOR4_A 5 //0
#define MOTOR4_B 7 //6
//
//
// Arduino pin names for interface to 74HCT595 latch
#define MOTORLATCH 18 //12
#define MOTORCLK 19 //4
#define MOTORENABLE 16 //7
#define MOTORDATA 17 //8
//
//
AFMotor.cpp
- Code: Select all
// initPWM1(uint8_t freq)
// use PWM from timer1A on PB3 (Arduino pin #9) //#11: 2A 2B
TCCR1A |= _BV(COM1A1) | _BV(WGM20) | _BV(WGM21); // fast PWM, turn on oc1a
TCCR1B = freq & 0x7;
OCR1A = 0;
// setPWM1(uint8_t s)
// use PWM from timer1B (pin 10) //#3 2B
TCCR1A |= _BV(COM1B1) | _BV(WGM20) | _BV(WGM21); // fast PWM, turn on oc1b
TCCR1B = freq & 0x7;
OCR1B = 0;
// initPWM2(uint8_t freq)
// use PWM from timer1B (pin 10) //#3 2B
TCCR1A |= _BV(COM1B1) | _BV(WGM20) | _BV(WGM21); // fast PWM, turn on oc1b
TCCR1B = freq & 0x7;
OCR1B = 0;
// setPWM2(uint8_t s)
// use PWM from timer1A on PB3 (Arduino pin #9)
OCR1B = s;
// AF_Stepper::AF_Stepper(uint16_t steps, uint8_t num)
// enable both H bridges
pinMode(9, OUTPUT); //11
pinMode(10, OUTPUT); //3
digitalWrite(9, HIGH); //11
digitalWrite(10, HIGH); //3
//

