Doubt Regarding Encoder

Azhaganandhan:
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.

I changed arduino uno to arduino mega

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... :slight_smile:

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... :slight_smile:

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

Azhaganandhan:

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

Reverse those.... R1=68.....R2=47. Or make them 6800 and 4700.

Those values are great for current limiting in LEDs or so. Not for signals. Your encoder won't be happy having to supply 13 * (12 / (47 + 68)) = 1.4A of total current on its outputs (at 12V those voltage dividers conduct 104 mA each!). Those resistors are also bound to get pretty hot, as you ask them to dissipate 0.3W resp. 0.4W.

47k and 68k will work a lot better. This way you're going to destroy your encoder (if you haven't done so already - it would explain why you get the same output all the time). In fact, if your resistors don't start smoking (I assume you're using standard 0.25W ones) you almost certainly destroyed your encoder already.

Hi,
Do you have a DMM?

Can you please answer the other two questions in my previous post?

Thanks.. Tom.. :slight_smile:

Simply depressed. need some refreshment... i was trying from last night no improvement. please share if u have some beginner type explanation and on my encoder with arduino mega with some output explanantion... :frowning: :frowning: :frowning: :frowning: :frowning: :frowning: :frowning: :frowning: :frowning: :frowning:

what is DMM?????

Hi,
DMM, Digital Multi-Meter, for measuring voltages and current around your projects.

Have you changed the resisitor values suggested by @Southpark in post #45.

At the moment your existing values are loading down the encoder so that it cannot produce the HIGH and LOW voltages needed to be read by the Mega inputs.

Have you got the gnd of the Mega connected to the gnd of the encoder power supply?

Thanks.. Tom... :slight_smile:

DMM = digital multimeter. Analog ones do just fine, too.

Again the output you claim to see and the sketch you post do not match up at all. I don't see how that sketch, which prints lines of 13 digits all being 1s and 0s, produces an output of just four digits that are not 1s and 0s.

Reading the spec sheet, several more issues come up.

For the inputs 1, 2 and 3 of the encoder: a HIGH is 10-30V. You provide 5V, very likely that is NOT read as a high signal by the encoder. You will have to add some circuits to get to a high signal here. The easiest is an NPN transistor with pull-up resistor that can pull the signal to the supply voltage of your encoder (12V). You will reverse logic this way: Arduino pin LOW means a HIGH signal to the encoder, and the other way around.

Signal durations on those pins must be >10 ms and reaction time of the encoder is up to 1 ms. Do keep those times in mind when programming.

The interface (the outputs of the encoder) are push-pull and short circuit protected, which is great. This means most likely your way too small resistor values did not destroy the encoder, but rather caused it to shut down or simply not do anything. They're also push-pull which means all you really need is a diode to interface with them.


The input: set your Arduino pin to INPUT_PULLUP. The diode stops any voltage >5V reaching your pin, while allowing the encoder to pull it low. The internal pull-up resistor makes sure your pin is pulled HIGH when the encoder's output is HIGH./ Much simpler and safer than messing around with voltage dividers.

The output: when your Arduino pin is HIGH, current flows through R26 switching on Q5 and the input of the encoder is pulled LOW. When your Arduino pin is LOW, the transistor blocks, and R19 pulls up the pin voltage to +12V (or whatever voltage you use to power the encoder - that's the voltage you want here). So you just have to remember to reverse the logic in your code.

Please note: none of the values of the resistors are critical, but you have to stay in this order of magnitude. The diodes are simple small signal diodes, both the common 1N4148 or 1N400x will do great. The transistor is a basic NPN small signal transistor, just about any NPN will do here.

And of course grounds need to be connected.

Extremely good pickup on the specs of this encoder, with the push-pull output stage. Using the diodes on the encoder output will make the interface (to the arduino) independent of the encoder's DC supply voltage. Convenient.

Finallly i got the value from the encoder while rotating the shaft. i have used voltage divider with shift register.. it works well.. But the problem how can i control the circuit using v/r, latch, preset...since am arduino can give only 5v, but the encoder latch, preset, v/r 12v as input . how this latch preset v/r can be operated....

See my circuit in #50. That's how you switch a 12V signal with a 5V signal. Just remember to invert the logic in your code.

The right-hand one of course. The one that has ARDUINO_OUTPUT as one of its connections. Explanation on how it works is in #50 as well.

Thank you for your guidance. i don't have BC548 transistor instead of that, i have used BC547 transistor. it is working for a while. i mean, i can able to give 12v to encoder, but after few trails, i am getting the same output. i think the transistor is wasted.... please give ur value suggestion

Any small signal NPN transistor will work here.

Use your multimeter to check actual signal levels, and make sure all connections are sound (if using solderless breadboard that's not always the case).