Hi all,
I’m experimenting whit an Arduino R4 WifFi and a DF robot quad motor driver (https://www.dfrobot.com/product-1513.html). The board is PWM controlled. To control the speed of a motor I use the analogWrite command.
void M1_advance(char Speed) ///<Motor1 Advance
{
digitalWrite(M1,LOW);
analogWrite(E1,Speed);
}
This works between 0 and 128 any value between 129 and 255 results in a 100% duty cycle.
I experimented setting the analogWriteResolution to 12. This resulted in a bigger jump in speed. I still get 100% when I specify a value larger than 128. Below 128 I get a lower duty cycle on the PWM
The motor shield seems not to be the problem, I used a scope to watch the PWM signal from the Uno R4 (on pin 3) and its jumps from 50% to 100%.
Using an unsigned was not the solution, what am I missing?
Test software:
/*!
* @file QuadMotorDriverShield.ino
* @brief QuadMotorDriverShield.ino Motor control program
*
* Every 2 seconds to control motor positive inversion
*
* @author linfeng(490289303@qq.com)
* @version V1.0
* @date 2016-4-5
*/
const int E1 = 3; ///<Motor1 Speed
const int E2 = 11;///<Motor2 Speed
const int E3 = 5; ///<Motor3 Speed
const int E4 = 6; ///<Motor4 Speed
const int M1 = 4; ///<Motor1 Direction
const int M2 = 12;///<Motor2 Direction
const int M3 = 8; ///<Motor3 Direction
const int M4 = 7; ///<Motor4 Direction
//minimum speed = 75
// maximum speed = 255
const int sollSpeed = 120;
int loopCounter = 0;
int factor = 1;
int step = 1;
void M1_advance(char Speed) ///<Motor1 Advance
{
digitalWrite(M1,LOW);
analogWrite(E1,Speed);
}
void M2_advance(char Speed) ///<Motor2 Advance
{
digitalWrite(M2,HIGH);
analogWrite(E2,Speed);
}
void M3_advance(char Speed) ///<Motor3 Advance
{
digitalWrite(M3,LOW);
analogWrite(E3,Speed);
}
void M4_advance(char Speed) ///<Motor4 Advance
{
digitalWrite(M4,HIGH);
analogWrite(E4,Speed);
}
void M1_back(char Speed) ///<Motor1 Back off
{
digitalWrite(M1,HIGH);
analogWrite(E1,Speed);
}
void M2_back(char Speed) ///<Motor2 Back off
{
digitalWrite(M2,LOW);
analogWrite(E2,Speed);
}
void M3_back(char Speed) ///<Motor3 Back off
{
digitalWrite(M3,HIGH);
analogWrite(E3,Speed);
}
void M4_back(char Speed) ///<Motor4 Back off
{
digitalWrite(M4,LOW);
analogWrite(E4,Speed);
}
void setup() {
analogWriteResolution(8);// - 12 bit analog out resolution.
for(int i=3;i<9;i++)
pinMode(i,OUTPUT);
for(int i=11;i<13;i++)
pinMode(i,OUTPUT);
Serial.begin(9600); //Initialiseer de seriele monitor
}
void loop() {
if (sollSpeed + (loopCounter * factor) < 130){
Serial.println(sollSpeed + (loopCounter * factor));
M1_back(sollSpeed + (loopCounter * factor));
M2_back(sollSpeed + (loopCounter * factor));
M3_back(sollSpeed + (loopCounter * factor));
M4_back(sollSpeed + (loopCounter * factor));
delay(2000); ///<Delay 2S
loopCounter = loopCounter + step;
}
else {
M1_advance(0);
M2_advance(0);
M3_advance(0);
M4_advance(0);
}
}