Hello I used Arduino Due and Dfrobot TB6612 DC motor driver for controlling my 6V DC motor. But i realized that, every start of my code, output pwm signal is different. My code is here:
int DIR1 = 4;
float y;
int yi;
void setup()
{
pinMode(DIR1, OUTPUT);
analogWriteResolution(12);
}
void loop()
{
int x=analogRead(A0);
if (x<31)
{y=0.0;}
else if ((31<=x)&&(x<590))
{y=(4096.0/559.0)*x-227;}
else if (x>590)
{y=4095.0;}
digitalWrite(DIR1,LOW);
yi=(int)y;
analogWrite(5,yi);
}
As you can see, I have a input signal and its a constant data that recorded by a potantiometer before. This data is produced by a data acquisition card every start my code. So I hope my PWM signal would be same everytime. But the output is different every I start my code. When I used Arduino Uno, everytghing is fine. But when I used Due, the output is unstable. Do you have any idea about that? Thanks in advance!