Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Missing pulses in fast speeds although using interrupts on: March 21, 2013, 01:01:23 pm
PaulS I will add photos and codes in a few day.

Michinyon, I try that you say, but as I said, if I able to write volatile unsigned int it is not enough also there is a problem that I couldn't compare two channel with rotary encoder libraries cides
2  Using Arduino / Programming Questions / Re: Missing pulses in fast speeds although using interrupts on: March 21, 2013, 06:04:43 am
Quote
And than, new problem was I couldn't write the "encoder0Pos" to LCD 16x2 if I identify like "volatile unsigned int encoder0Pos = 0;".
Why not? That is the question that you didn't answer. Fancy footwork, though.

What happens when you call lcd.print(encoder0Pos); when encoder0Pos is properly declared volatile? Does nothing print? Or, do you get some kind of compiler error?

I saw on the LCD confused characters like chinese alfabet. But I saw changes as the same time pulses. Moreover, although I write codes like "lcd.setCursor(0,0);" it shows that confused characters at (0,8) and (0,9).
3  Using Arduino / Programming Questions / Re: Missing pulses in fast speeds although using interrupts on: March 20, 2013, 07:03:43 pm
In addition for PeterH,

In1 and In2 is driver carriers pins.

http://thumbnails.inkfrog.com/pix/noodlehed/l298_module3.jpg/596/0

ena--->pwm

and

If in1 high and in2 low motor turning clockwise rotation and if else else..

So, I don't compare two channel to relize rotation of the turning. I read In1 and In2 outputs value to understand rotation.
4  Using Arduino / Programming Questions / Re: Missing pulses in fast speeds although using interrupts on: March 20, 2013, 06:54:33 pm
Holmes4 and PeterH firstly thanks for your interest,


My older problem was type of my encoder.

http://robotus.net/wp-content/uploads/2012/07/manyetik-encoder-forceup.jpg

 This is not usual rotary encoder. So, I tried a lot of example in Arduino Rotary Encoder Library. One of them was this code below.


Code:

/* read a rotary encoder with interrupts
   Encoder hooked up with common to GROUND,
   encoder0PinA to pin 2, encoder0PinB to pin 4 (or pin 3 see below)
   it doesn't matter which encoder pin you use for A or B 

   uses Arduino pullups on A & B channel outputs
   turning on the pullups saves having to hook up resistors
   to the A & B channel outputs

*/

#define encoder0PinA  2
#define encoder0PinB  4

volatile unsigned int encoder0Pos = 0;

void setup() {


  pinMode(encoder0PinA, INPUT);
  digitalWrite(encoder0PinA, HIGH);       // turn on pullup resistor
  pinMode(encoder0PinB, INPUT);
  digitalWrite(encoder0PinB, HIGH);       // turn on pullup resistor

  attachInterrupt(0, doEncoder, CHANGE);  // encoder pin on interrupt 0 - pin 2
  Serial.begin (9600);
  Serial.println("start");                // a personal quirk

}

void loop(){
// do some stuff here - the joy of interrupts is that they take care of themselves
}

void doEncoder() {
  /* If pinA and pinB are both high or both low, it is spinning
   * forward. If they're different, it's going backward.
   *
   * For more information on speeding up this process, see
   * [Reference/PortManipulation], specifically the PIND register.
   */
  if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) {
    encoder0Pos++;
  } else {
    encoder0Pos--;
  }

  Serial.println (encoder0Pos, DEC);
}



When I use this code, I had confused but a kind of order numeric results like that;

-1
0
1
0
-1
0
1
0
-1
...

It seems like logical step like,
http://upload.wikimedia.org/wikipedia/en/6/68/Quadrature_Diagram.svg

I couldn't find anything to solve the problem, so I decieded to use only one channel.

And It works! But,

And than, new problem was I couldn't write the "encoder0Pos" to LCD 16x2 if I identify like "volatile unsigned int encoder0Pos = 0;".

Altough, I try a few type of conversation such as "itoa(x,encoder0Pos,10)" "itoa(x,encoder0Pos,16)" , it was not work.
So, I use only "int encoder0Pos = 0;". This is why I don't use volatile.

I hope I explained problems understandable.

Now I got only about %20 missing pulses per revolation, thanks to Paul. But it isn't acceptable mistake.

Thank a lot again.
Yours faithfully
5  Using Arduino / Programming Questions / Re: Missing pulses in fast speeds although using interrupts on: March 20, 2013, 04:11:41 pm
Thank you very much I moved serial.print void loop and now I have about 140 pulse per revolation but it have to be 180. If I use volatile int I can't write it LCD and what can I do else ?
6  Using Arduino / Programming Questions / Missing pulses in fast speeds although using interrupts on: March 20, 2013, 02:09:04 pm
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;

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

7  Using Arduino / Programming Questions / Is there anybody know about this type of encoder using on: March 09, 2013, 11:08:20 am
Hi all,

I have these encoder below ( Please see encoder );

http://robotus.net/wp-content/uploads/2012/07/manyetik-encoder-forceup.jpg

and I want to do these;



I have already done the 200 RPM DC Motor PWM control and now only I am trying to see position on serial monitor.
(using arduino uno)

I search a lot of code and try in the rotary encoder libraries etc. but
For example when I  use this code;

Code:

#include <Encoder.h>

Encoder myEnc(2, 3);


void setup() {
  Serial.begin(9600);
  Serial.println("Basic Encoder Test:");
}

long oldPosition  = -999;

void loop() {
  long newPosition = myEnc.read();
  if (newPosition != oldPosition) {
    oldPosition = newPosition;
    Serial.println(newPosition);
  }
}


I have this result in Serial Monitor;

Basic Encoder Test:
-1
0
1
0
-1
0
1
0
-1
...

I tried a lot of working code and most of them give me same result

But I want to have
Basic Encoder Test:
1
2
3
4
...

something like that. I am wondering is the problem could be my encoder type ? Because, I have never seen any project example in net.

So, anybody have an idea about to use these kind of encoder with interrupt.

Thanks.
8  Topics / Home Automation and Networked Objects / Re: Turning lamps off 12:00 - 01:00 PM on: December 06, 2012, 03:18:33 pm
 smiley

Thanks a lot all,

I fixed it using TimeAlarm is perfect idea. smiley-money And also, for other person that have similar problems,while using TimeAlarm example,i have one more problem which says:

C:\arduino-1.0\libraries\TimeAlarm\TimeAlarm.cpp:268: error: 'millis' was not declared in this scope

And than,I solve it with these;

https://www.element14.com/community/thread/16455

Link says that find these adress Documents/Arduino/Libraries/TimeAlarm/TimeAlarm.cpp
and open it and change the #include < WProgram.h > line to #include < Arduino.h >

That's all.

You can also use these unit;

https://www.sparkfun.com/products/99

it provides you real timing.Moreover,you turn the arduinos power off,unless you think if the setting time will be gone.With other words,you shouldn't set the arduino's time,like in the example every upload bacause of the fact that it has a simple timer logic,you set the time and date,though.

Thanks again for your interest,

See you in next project,questions or solutions.
9  Topics / Home Automation and Networked Objects / Turning lamps off 12:00 - 01:00 PM on: December 05, 2012, 06:09:54 pm
Hi everybody,

I want to turn the lamps off such as between 12-1 pm or 5-6 pm with relay.
I have relaies, Arduino Ethernet (software v1.0.2) and basic knowledge about using arduino, but i have problems with software.
 
I tried to use that i read discussions about the "datetime" libraries.Although I solve a few problem like "BYTE",i couldn't do anything finally.


Would you mind if you let me know how can I do these project easily.Is there any way to do without using libraries and except timer(delay etc).Any simple way like Visual Basic or Pascal to got it a few code.


It is not important working with perfect timing.  Moreover, maybe it could be work with stability only feeding with adaptory etc.

Please help me immediately,I am in a hurry

Thanks for your interest
Pages: [1]