Hi all,
this is my project ( arduino uno, gear dc motor and encoder feedback, position control, display on LCD );
http://g1303.hizliresim.com/17/n/l8pjc.jpg
http://g1303.hizliresim.com/17/n/l8ppf.jpg
http://g1303.hizliresim.com/17/n/l8pqw.jpg
and this is entire code;
#include <LiquidCrystal.h>
const int analogInPin = A0; //speed control with pot
const int analogOutPin = 9;
const int analogInPin1 = A1; //diection control with pot
const int in1 = 4;
const int in2 = 5;
#define encoder0PinA 2
#define encoder0PinB 3
int encoder0Pos = 0;
int analog = 0;
int analog1 = 0;
int cikis = 0;
int yon = 0;
int buton = 0;
int in1d=0;
int in2d=0;
int ekran=0;
char ekr[4];
int a=0;
LiquidCrystal lcd(12, 11, 7, 6, 10, 8);
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
pinMode(encoder0PinA, INPUT);
// turn on pullup resistor
pinMode(encoder0PinB, INPUT);
// turn on pullup resistor
attachInterrupt(0, doEncoder, CHANGE); // encoder pin on interrupt 0 - pin 2
Serial.println("start"); // a personal quirk
}
void loop() {
in1d=digitalRead(in1);
in2d=digitalRead(in2);
analog1=analogRead(analogInPin1);
yon = map(analog1, 0,1023,0,255);
analog=analogRead(analogInPin);
cikis = map(analog, 0, 1023, 0, 255);
analogWrite(analogOutPin, cikis);
if (analog1 < 300 )
{
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
}
if (analog1 > 600 )
{
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
}
if (analog1 > 300 && analog1 <600 && in1d==LOW && in2d==HIGH )
{
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
delay(100);
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);
}
if (analog1 > 300 && analog1 <600 && in1d==HIGH && in2d==LOW )
{
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
delay(100);
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);
}
if (buton == HIGH )
{
if (in1d==LOW && in2d==HIGH )
{
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
delay(100);
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);
}
if (in1d==HIGH && in2d==LOW )
{
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
delay(100);
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);
}
}
lcd.setCursor(0,0);
lcd.print(encoder0Pos);
delay(1);
}
void doEncoder() {
if (digitalRead(encoder0PinB) == HIGH ) {
if (in1d==LOW && in2d==HIGH) {
encoder0Pos++;
}
else
{
encoder0Pos--;
}
}
Serial.println (encoder0Pos);
}
Problem is when I feed the motor about 5V I have 180 pulse per revolation and lover voltages too. But when I feed the motor 12V I see only 18-19 pulse on the lcd and serialmonitor and than it stops the counting.
I see healty pulses on the oscilloscope. It is about 300khz 12V feeding
I don't have any knowledge about clock cycle or perscale. But I think don't need any changing cause it have to enough speed with interrupts to count correct.
But I haven't try any feeding between 12..5 yet.
Please help If you have any idea immediately.
Thanks