system
September 11, 2014, 12:39am
4
click the MODIFY button in the upper right of the post window.
Highlight all you code.
click the "#" CODE TAGS button on the toolbar above just to the left of the QUOTE button.
click SAVE (at the bottom).
When you post code on the forum, please make a habit of using the code tags "#" button.
http://arduino.cc/en/Reference/analogWrite
WHAT DOES THIS SAY ABOUT YOUR MOTOR-2 PWM PIN ?
The frequency of the PWM signal on most pins is approximately 490 Hz. On the Uno and similar boards, pins 5 and 6 have a frequency of approximately 980 Hz.
Now do you see why I asked you to post your code ?
system
September 11, 2014, 12:44am
5
raschemmel:
click the MODIFY button in the upper right of the post window.
Highlight all you code.
click the "#" CODE TAGS button on the toolbar above just to the left of the QUOTE button.
click SAVE (at the bottom).
When you post code on the forum, please make a habit of using the code tags "#" button.
http://arduino.cc/en/Reference/analogWrite
WHAT DOES THIS SAY ABOUT YOUR MOTOR-2 PWM PIN ?
The frequency of the PWM signal on most pins is approximately 490 Hz. On the Uno and similar boards, pins 5 and 6 have a frequency of approximately 980 Hz.
Now do you see why I asked you to post your code ?
Thanks for the help, ill check if that solves it.
system
September 11, 2014, 12:48am
6
You know what you need to do to correct it I assume ?
system
September 11, 2014, 1:02am
7
raschemmel:
You know what you need to do to correct it I assume ?
I guess changing the pins so both pwm outputs operate at the same frequency?
system
September 11, 2014, 1:15am
9
raschemmel:
right
It worked, thank you for your help
system
September 11, 2014, 1:20am
10
That was easy wasn't it ?
Aren't you glad it wasn't a hardware problem ?
Now you see why I asked you to post your code ?
system
September 11, 2014, 1:51am
11
raschemmel:
That was easy wasn't it ?
Aren't you glad it wasn't a hardware problem ?
Now you see why I asked you to post your code ?
Haha yea, i honestly thought the l298 was broken, but as usual it was just one of those little details you completely ignore
system
September 11, 2014, 2:27am
12
Can you post the link of your particular L298 module ? I assume it is a premade module on a pcb and not a breadboarded chip , correct ?
system
September 11, 2014, 3:40am
13
raschemmel:
Can you post the link of your particular L298 module ? I assume it is a premade module on a pcb and not a breadboarded chip , correct ?
Yeap, here's the sparkfun link and datasheet:
system
September 11, 2014, 5:04am
14
You don't have a heatsink or PCB ?
system
September 11, 2014, 5:29am
15
raschemmel:
You don't have a heatsink or PCB ?
Im currently testing it in a breadboard, but i do have a heatsink attached to it
system
September 11, 2014, 5:57am
16
That's really surprising. Most people use a variation of these (one of about 10 variations with different layouts):
system
September 11, 2014, 5:59am
17
Oh and BTW,
This is what your code would look like if you had followed my instructions: (in Reply#3)
#include<Wire.h>
const int GyroA=0x68;
const byte pin_motor1_dir = 2;
const byte pin_motor1_en = 3;
const byte pin_motor2_dir = 4;
const byte pin_motor2_en = 5;
const byte pin_buzzer = 6;
const byte pin_echo = 7;
const byte pin_trigger = 8;
const byte pin_led1 = 9;
const byte pin_led2 = 10;
const byte pin_btn = 12;
const byte pin_reflex_1 = A0;
const byte pin_reflex_2 = A1;
const byte pin_reflex_3 = A2;
const byte pin_reflex_4 = A3;
byte motor1_speed = 0;
int data_ultrasonido;
int data_reflex[4];
int buttonState;
int lastButtonState = LOW;
long debounceDelay = 50;
long lastDebounceTime = 0;
float data_imu[7];
byte z = 0;
void setup()
{
pinMode(pin_motor1_dir,OUTPUT);
pinMode(pin_motor1_en,OUTPUT);
pinMode(pin_motor2_dir,OUTPUT);
pinMode(pin_motor2_en,OUTPUT);
pinMode(pin_buzzer,OUTPUT);
pinMode(pin_trigger,OUTPUT);
pinMode(pin_echo,INPUT);
pinMode(pin_led1,OUTPUT);
pinMode(pin_led2,OUTPUT);
pinMode(pin_btn,INPUT);
pinMode(pin_reflex_1,INPUT);
pinMode(pin_reflex_2,INPUT);
pinMode(pin_reflex_3,INPUT);
pinMode(pin_reflex_4,INPUT);
Wire.begin();
Wire.beginTransmission(GyroA);
Wire.write(0x6B);
Wire.write(0); //Wake up
Wire.endTransmission(true);
//digitalWrite(pin_buzzer,HIGH);
//digitalWrite(pin_led1,HIGH);
//digitalWrite(pin_led2,HIGH);
Serial.begin(9600);
}
void loop()
{
//delay(350);
//debug_imu();
//debug_reflex();
//debug_ultrasonido();
debounce();
}
void debug_reflex()
{
sensar_reflex();
for(int i = 0;i<4;i++)
{
Serial.print("Reflex ");
Serial.print(i);
Serial.print(": ");
Serial.println(data_reflex);
}
Serial.println();
}
void debug_ultrasonido()
{
sensar_ultrasonido();
Serial.print("Distancia: ");
Serial.println(data_ultrasonido);
Serial.println();
}
void debug_imu()
{
sensar_imu();
Serial.print("AcX: ");
Serial.println(data_imu[2]);
Serial.print("AcY: ");
Serial.println(data_imu[1]);
Serial.print("AcZ: ");
Serial.println(data_imu[0]);
Serial.print("GyX: ");
Serial.println(data_imu[3]);
Serial.print("GyY: ");
Serial.println(data_imu[4]);
Serial.print("GyZ: ");
Serial.println(data_imu[5]);
Serial.print("Temp: ");
Serial.println(data_imu[6]);
Serial.println();
}
void sensar_ultrasonido()
{
long duration;
digitalWrite(pin_trigger, LOW);
delayMicroseconds(2);
digitalWrite(pin_trigger, HIGH);
delayMicroseconds(10);
digitalWrite(pin_trigger, LOW);
duration = pulseIn(pin_echo, HIGH,11765);
if(duration!=0)
{
data_ultrasonido = duration/59;
}
else
{
data_ultrasonido = -1;
}
}
void sensar_reflex()
{
data_reflex[0] = analogRead(pin_reflex_1);
data_reflex[1] = analogRead(pin_reflex_2);
data_reflex[2] = analogRead(pin_reflex_3);
data_reflex[3] = analogRead(pin_reflex_4);
}
void sensar_imu()
{
Wire.beginTransmission(GyroA);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(GyroA,14,true);
data_imu[0] = Wire.read()*256+Wire.read();
data_imu[1]=Wire.read()*256+Wire.read();
data_imu[2]=Wire.read()*256+Wire.read();
data_imu[6]=(Wire.read()*256+Wire.read())/340.00+36.53;
data_imu[3]=Wire.read()*256+Wire.read();
data_imu[4]=Wire.read()*256+Wire.read();
data_imu[5]=Wire.read()*256+Wire.read();
data_imu[3]/=131;
data_imu[4]/=131;
data_imu[5]/=131;
data_imu[0]/=16384;
data_imu[1]/=16384;
data_imu[2]/=16384;
}
void debounce()
{
int state = digitalRead(pin_btn);
if(state!=lastButtonState)
{
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay)
{
if (state != buttonState)
{
buttonState = state;
if (buttonState == HIGH)
{
//tone(pin_buzzer,1760,50);
if(motor1_speed < 255)
{
motor1_speed+=51;
}
else
{
motor1_speed = 0;
}
analogWrite(pin_motor1_en,motor1_speed);
analogWrite(pin_motor2_en,motor1_speed);
}
}
}
lastButtonState = state;
}
Report to moderator Logged
system
September 11, 2014, 7:10am
18
raschemmel:
That's really surprising. Most people use a variation of these (one of about 10 variations with different layouts):
L298 H-Bridge Dual Motor Driver for sale | eBay
Yea I also have one of those but for this project (micro sumo) i needed to save as much space as possible and so im going to etch my own pcb with all the circuit
system
September 11, 2014, 7:17am
20
raschemmel:
Ambitious , eh ?
I dont have much of a choice lol
system
September 11, 2014, 1:14pm
21
Sometimes we do our best work when we have a gun to our head.
That's why there is always a Boss. Someone has to hold the gun....
narzan
October 5, 2014, 5:24pm
22
hahaha @raschemmel
ok put the gun on my head and help me in this
this is my post
http://forum.arduino.cc/index.php?topic=270583.15