Created Wed, 24 Apr 2013 16:54:19 +0000 by tsalzmann
Wed, 24 Apr 2013 16:54:19 +0000
HI, I'm trying to move 4 motors at the same time with no success. When I do it individually without my motor class, it works fine but when I add the class and the other 3 motors, the digital ports stop working. I'm using the MC33926 dual motor controller that only uses 1 PWM port and two digital ports (IN1 and IN2). only motor[3] does not move. When vel is greater than 0 digital port 45 gives 3.2V and digital port 43 gives 2.4V. And when vel is negative digital port 45 gives 0.01V and digital port 43 gives 0.89V.
Here is my code:
#include "motor.h"
Motor motor[4];
unsigned int timer;
void setup()
{
motor[0].init(5,51,53);
motor[1].init(6,7,8);
motor[2].init(9,49,47);
motor[3].init(10,45,43);
}
void loop()
{
int vel = 0;
if(digitalRead(78))
vel = 100;
else
vel = -100;
for(int i = 0; i < 4; i++)
{
motor[i].setVel(vel);
motor[i].move();
}
}
and the class:
#include "WProgram.h"
#ifndef MOTORS_H
#define MOTORS_H
class Motor
{
public:
int PWM, IN1, IN2;
int VEL;
void init(int pwm, int in1, int in2);
void setVel(int vel);
void reset();
void add(int vel);
void move();
};
void Motor::init(int pwm, int in1, int in2)
{
IN1 = in1;
IN2 = in2;
PWM = pwm;
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(pwm, OUTPUT);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
}
void Motor::setVel(int vel)
{
VEL = vel;
}
void Motor::reset()
{
VEL = 0;
}
void Motor::add(int vel)
{
VEL += vel;
}
void Motor::move()
{
if(VEL >= 0)
{
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
}
else
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
}
analogWrite(PWM, abs(VEL));
}
#endif
Thanks in advance
Wed, 24 Apr 2013 16:59:24 +0000
Same thing with this code:
void setup()
{
pinMode(5, OUTPUT);
pinMode(51, OUTPUT);
pinMode(53, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(49, OUTPUT);
pinMode(47, OUTPUT);
pinMode(10, OUTPUT);
pinMode(45, OUTPUT);
pinMode(43, OUTPUT);
}
void loop()
{
boolean in1, in2;
int vel = 0;
if(digitalRead(78))
{
in1 = HIGH;
in2 = LOW;
}
else
{
in1 = LOW;
in2 = HIGH;
}
digitalWrite(51, in1);
digitalWrite(53, in2);
analogWrite(5, 100);
digitalWrite(7, in1);
digitalWrite(8, in2);
analogWrite(6, 100);
digitalWrite(49, in1);
digitalWrite(47, in2);
analogWrite(9, 100);
digitalWrite(45, in1);
digitalWrite(43, in2);
analogWrite(10, 100);
}
Wed, 24 Apr 2013 17:16:34 +0000
Wow!!! I just found out that the digital port 43 and 51 are connected together. And on the Max32!!! How is this possible?
Wed, 24 Apr 2013 18:37:19 +0000
If jumper J3 and J4 (SPI Maste/Slave) are in Master mode pin 50 connected to pin 29 and pin 51 connected to pin 43 In Slave mode pin 50 connected to pin 439 and pin 51 connected to pin 29 Also pins 50,51,52,53 are connected to JP13 (SPI)
if you are not using spi you can change J3,J4 or just remove jumpers
Note also that pins 41,42,43 are tied to pins A11,A13,A12
I have not seen this documented anywhere. I found it by setting up an excel sheet listing where all ports pins are and I found duplicates.
George