Arduino motor controller ( To be)

Stoneww

Apr 18, 2017
42
Joined
Apr 18, 2017
Messages
42
I've been trying to make a motor control circuit with PWM. The end goal is to have a working buggy.


Now my problem lies within the fact that the frequency of these LEDs when they are powered is pretty low, I don't have a tool to measure it but I can see the LEDs clearly flashing. The individual PWM circuit I made beforehand gave a pretty high frequency output. So how come this time around the frequency is so much lower?

My guess is due to processing time of code, so is there anyway to improve the frequency?

Thank you for your time.
New-Schematic-2.png upload_2017-10-4_21-51-56.png
Code:
int PRM=11;                                 //Positive Right Motor
int NRM=6;                                  //Negative Right Motor
int PLM=3;                                  //Positive Left Motor
int NLM=5;                                  //Negative Left Motor
int Forward=13;
int Back=12;
int Right=8;
int Left=7;
int Speed=A0;
int outs[4] = {PRM, NRM, PLM, NLM};
int ins[4] = {Forward, Back, Right, Left};

void setup() 
{
for (int i=0; i<4; i++)
pinMode(ins[i], INPUT);

for (int x=0; x<4; x++)
pinMode(outs[x], OUTPUT);

pinMode(Speed, INPUT);
}

void loop() 
{
if (digitalRead(Forward)== HIGH)              //Forward
{
  analogWrite(PRM, analogRead(Speed)/4);
  analogWrite(PLM, analogRead(Speed)/4);
  digitalWrite(NRM, LOW);
  digitalWrite(NRM, LOW);
}
else
{
  digitalWrite(PRM, LOW);
  digitalWrite(PLM, LOW);
}
if (digitalRead(Back) == HIGH)                //Backwards
{
  analogWrite(NRM, 300);
  analogWrite(NLM, 300);
  digitalWrite(PRM, LOW);
  digitalWrite(PLM, LOW);
}
else
{
  digitalWrite(NRM, LOW);
  digitalWrite(NLM, LOW);
}
if (digitalRead(Right) == HIGH)                //Right
{
  analogWrite(NRM, 300);
  analogWrite(PLM, 600);
  digitalWrite(PRM, LOW);
  digitalWrite(NLM, LOW);
}
else
{
  digitalWrite(NRM, LOW);
  digitalWrite(PLM, LOW);
}
if (digitalRead(Left) == HIGH)                //Left
{
  analogWrite(PRM, 600);
  analogWrite(NLM, 300);
  digitalWrite(NRM, LOW);
  digitalWrite(PLM, LOW);
}
else
{
  digitalWrite(PRM, LOW);
  digitalWrite(NLM, LOW);
}
}
 
Top