Hi there, I'm using an Arduino Uno to program an ATtiny84 chip. I'm trying to drive a DC motor, and everything works except that if I set the PWM output to anything lower than 150, it's as if it's set to 0.
Here's my code:
//define the two direction logic pins and the speed / PWM pin
const int DIR_A = 2;
const int DIR_B = 1;
const int PWM = 7;
void setup()
{
//set all pins as output
pinMode(DIR_A, OUTPUT);
pinMode(DIR_B, OUTPUT);
pinMode(PWM, OUTPUT);
}
void loop()
{
//drive forward at full speed by pulling DIR_A High
//and DIR_B low, while writing a full 255 to PWM to
//control speed
digitalWrite(DIR_A, HIGH);
digitalWrite(DIR_B, LOW);
analogWrite(PWM, 150);
//wait 1 second
delay(1000);
//Brake the motor by pulling both direction pins to
//the same state (in this case LOW). PWM doesn't matter
//in a brake situation, but set as 0.
digitalWrite(DIR_A, LOW);
digitalWrite(DIR_B, LOW);
analogWrite(PWM, 0);
//wait 1 second
delay(2000);
//change direction to reverse by flipping the states
//of the direction pins from their forward state
digitalWrite(DIR_A, LOW);
digitalWrite(DIR_B, HIGH);
analogWrite(PWM, 255);
//wait 1 second
delay(1000);
//Brake again
digitalWrite(DIR_A, LOW);
digitalWrite(DIR_B, LOW);
analogWrite(PWM, 0);
//wait 1 second
delay(2000);
}
The above code works, but as I said, if I set any of those analogWrite()s to anything lower than 150, at that point in the code, the motor will brake.
I have my PWM pin attached to physical leg 6 on the ATtiny. Which, according to this, should be pin 7 in the Arduino IDE.
The other side of the PWM wire is connected to pin 1 of this chip
the 2 logic pins go from pins 1 and 2 on the ATtiny to pins 2 and 7 on the H bridge.
I have the chip set to 8mhz. I've also tried it on 4mhz and the PWM set to 50, and then I can hear the motor "buzz" but it doesn't move.
Any ideas why this is happening? TIA!