Adafruit #570 in Inc 5000 & #11 in manufacturing - fastest-growing private companies in America - INC 5000 - Read more!

Motor shield with other SPI device

by jeonlab on Fri Mar 15, 2013 11:11 am

Hi. I need to run 2 stepper motors and an SPI device but the Motor shield uses the pin 11 as one of those PWM inputs to the L239Ds. The pin 11 is needed for the SPI communication. Since I don't need servos, I tried to move the pins 11 and 3 to the pins 9 and 10, respectively. In fact, I used a breadboard to do this modification so I didn't have to take apart of the shield.
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 | TOGGLE FULL SIZE
//
//
// 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 | TOGGLE FULL SIZE
// 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
//

http://jeonlab.wordpress.com
jeonlab
 
Posts: 7
Joined: Thu Nov 10, 2011 10:34 pm
Location: Toronto, Ontario, Canada

Re: Motor shield with other SPI device

by adafruit_support_bill on Sat Mar 16, 2013 9:35 am

Are you seeing a PWM signal on pins 9 & 10?
User avatar
adafruit_support_bill
 
Posts: 28860
Joined: Sat Feb 07, 2009 9:11 am

Re: Motor shield with other SPI device

by jeonlab on Sat Mar 16, 2013 5:20 pm

I haven't ckecked the outputs of those pins. I'll test and update. Thank you as always.
http://jeonlab.wordpress.com
jeonlab
 
Posts: 7
Joined: Thu Nov 10, 2011 10:34 pm
Location: Toronto, Ontario, Canada



cron