I am trying to control a dc motor using an Uno along with the Motor Shield v2 and I’m hoping someone can help because I can not seem to figure this out.
Ideally I would be able to control a single DC motor that only needs to move in one direction.
The PWM should be set at 15khz but Im not sure I have that option so I believe I can get away using timer 1 available on pins 9/10 with TCCR1B = TCCR1B & 0b11111000 | 0x01; (~31khz)
The speed/duty cycle precisely controlled by a constantly varying 5k potentiometer/ throttle.
The issue Im having is controlling the Uno’s outputted PWM frequency and having the motor shield output the same. No matter what changes Ive made, I always seem to get the default frequencies on the Motor Shield side.
How can I control the Motor Shields outputted frequency.
Thank you in advance for the help, its much appreciated!
#include “MotorDriver.h”
const int POT_PIN = A0;
int motorSpeed = 0;
int potVal = 0;
int pinI1=8;//define I1 interface
int pinI2=11;//define I2 interface
int speedpinA=9;//enable motor A
void setup()
{
Serial.begin(9600);
TCCR1B = TCCR1B & 0b11111000 | 0x01;
pinMode(pinI1,OUTPUT);
pinMode(pinI2,OUTPUT);
pinMode(speedpinA,OUTPUT);
}
void loop()
{
potVal = analogRead(POT_PIN);
motorSpeed = map(potVal, 0, 1023, 0, 255);
Serial.print(motorSpeed);
analogWrite(speedpinA, motorSpeed);
digitalWrite(pinI2,LOW);//turn DC Motor A move anticlockwise
digitalWrite(pinI1,HIGH);
}