Go Down

Topic: Doubt Regarding Encoder (Read 862 times) previous topic - next topic

BJHenry

If you have questions you should post them in the ongoing thread that you have started to deal with this topic, not make a new thread each time you have something else to ask.

Azhaganandhan

yes hereafter i will ask in same thread.... can u give me any help over the sketch code to read encoder output......

Southpark

#32
Apr 17, 2018, 03:50 am Last Edit: Apr 17, 2018, 06:20 am by Southpark
Check this thread...and more to read port pins ....


http://forum.arduino.cc/index.php?topic=44771.0

https://www.avrfreaks.net/forum/port-vs-pin

http://www.elecrom.com/avr-tutorial-2-avr-input-output/


You'll likely encounter pre-defined registers, with labels 'PINA', 'PINB', 'PINC' etc.

wvmarle

the sketch code to read encoder output......
I think you forgot to include something. The code, specifically. Or is it in your other thread? Sorry, can't be bothered to search.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Coding Badly


@Azhaganandhan, do not cross-post.  Threads merged.


Azhaganandhan

int pin2, pin3, pin4, pin5, pin6, pin7, pin8, pin9, pin10, pin11, pin12, pin13, pin41;
unsigned int myByte;
// if pin in input, you can read value from it.
// if pin is set as output, you can write to it.
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(7, INPUT);
  pinMode(8, INPUT);
  pinMode(9, INPUT);
  pinMode(10, INPUT);
  pinMode(11, INPUT);
  pinMode(12, INPUT);
  pinMode(13, INPUT);
  pinMode(41, INPUT);

  pinMode(39, OUTPUT);
  pinMode(37, OUTPUT);
  pinMode(35, OUTPUT);

  digitalWrite(39, HIGH); // VR
 
  digitalWrite(35, HIGH); // preset
  delay(20);
  digitalWrite(35, LOW); // preset

  digitalWrite(37, LOW);

}

void loop() {
   put your main code here, to run repeatedly:
  digitalWrite(37, HIGH);
  delay(150);

 most significant bit on the right
  pin2 = digitalRead(2);
  pin3 = digitalRead(3);
  pin4 = digitalRead(4);
  pin5 = digitalRead(5);
  pin6 = digitalRead(6);
  pin7 = digitalRead(7);
  pin8 = digitalRead(8);
  pin9 = digitalRead(9);
  pin10 = digitalRead(10);
  pin11 = digitalRead(11);
  pin12 = digitalRead(12);
  pin13 = digitalRead(13);
  pin41 = digitalRead(14);

  Serial.print(pin2);
  Serial.print(pin3);
  Serial.print(pin4);
  Serial.print(pin5);
  Serial.print(pin6);
  Serial.print(pin7);
  Serial.print(pin8);
  Serial.print(pin9);
  Serial.print(pin10);
  Serial.print(pin11);
  Serial.print(pin12);
  Serial.print(pin13);
  Serial.print(pin41);

  Serial.print("\n");

//  digitalWrite(37, LOW);
    delay(3000);

}








this is the code am using. am getting output as 3453 regularly please help me out in the code

BJHenry

Code: [Select]

  pinMode(41, INPUT);

  pinMode(39, OUTPUT);
  pinMode(37, OUTPUT);
  pinMode(35, OUTPUT);

  digitalWrite(39, HIGH); // VR
 
  digitalWrite(35, HIGH); // preset
  delay(20);
  digitalWrite(35, LOW); // preset

  digitalWrite(37, LOW);



this is the code am using. am getting output as 3453 regularly please help me out in the code
You might want to check those pin numbers for a start.

wvmarle

this is the code am using. am getting output as 3453 regularly please help me out in the code
The code prints out a series of 1s and 0s and you say you get 3453 as output? That doesn't match up.

Also the code as you posted suffers from a lack of code tags, and two lines that appear to be comments miss // at the start.

What is connected to pins 35, 37, 39 and 41?

Why is pin 37 set to LOW in setup(), then to HIGH in loop() and kept that way? The line where it's set to LOW in loop() is commented out.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Azhaganandhan

35- pin 18(preset)
37- pin  17(latch)
39- pin  16(V/R)
41- pin   Bit Output pin



Input for selection of counting direction (V/R)
The counting direction for the absolute value rotary encoder as seen looking on the shaft is defined as right rotating (cw) rising or descending. The counting
direction can be reversed with the V/R input. If the input is not used, the counting direction is defined as rising (standard), the level is at "1". Pulse duration
T > 10 ms.
Input level: "1" or unused = rising code value with direction of rotation cw.
Input level: "0" = descending code value for direction of rotation cw.


Input for temporary storage (LATCH)
With LATCH input "active", the position data on the parallel interface are "frozen". This makes it possible to accept position data without errors (especially
for binary position data), since any change in the data during the read procedure is prevented. If this input is unused, its value is "0". Pulse duration T > 100
┬Ás.
Input level: "1" = position data saved and stable at the output.
Input level: "0" or unused = position data free running at the output.


Input zero setting (PRESET)
By means of the PRESET input, the absolute value rotary encoder can be adjusted electronically to position value 0. Pulse duration T > 10 ms.
Input level: "0" or unused = inactive.
Input level: "1" = Data output word is set to 0.

BJHenry

What I am going for (and I think wvmarle is also trying to point out) is that the Uno doesn't have pins 35-41.

Southpark

this is the code am using. am getting output as 3453 regularly please help me out in the code
It's likely better to read the port registers themselves .... like PINA, PINB, PINC, PIND etc.... or whichever ports you want to use. Once the registers are correctly set up, you could then pull out the bits of interest and then form your own 13 bit value from the relevant bits.

Azhaganandhan

#41
Apr 17, 2018, 09:51 am Last Edit: Apr 17, 2018, 09:57 am by Azhaganandhan Reason: spell
I changed arduino uno to arduino mega

TomGeorge

#42
Apr 17, 2018, 10:19 am Last Edit: Apr 17, 2018, 10:21 am by TomGeorge
Hi,

  • If you do not move the encoder do you get a stable monitor display?
  • If you remove power from the encoder, what is displayed on the monitor display?
  • Have you got the ground of the Mega connected to the gnd of the power supply for the encoder?


Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

TomGeorge

#43
Apr 17, 2018, 10:50 am Last Edit: Apr 17, 2018, 10:50 am by TomGeorge
Hi,
Each one of your Mega inputs should have a potential divider configured like this.

What values do you have for R1 and R2?
Have you got the gnds connected together?

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

Azhaganandhan

#44
Apr 17, 2018, 12:09 pm Last Edit: Apr 17, 2018, 12:16 pm by Azhaganandhan


I have connected r1= 47ohms r2= 68ohms   ... i have trouble in sketch code

Go Up