Go Down

Topic: encoder troubles (Read 642 times) previous topic - next topic

jamicubro

I am trying to read the output from a MA3 encoder (link below) it is a 10-bit version.

http://www.usdigital.com/products/encoders/absolute/rotary/shaft/ma3

I have the basic idea of how this should be done through arduino code, but maybe I am missing something. All I want to do is read the values coming off of the encoder through the serial monitor. Seems straight forward, but when I run the code I the number changes from 300-360 randomly without any motion of the shaft. My code is pasted below.

int enc = 10;
int x = 0;




void setup()
{
  pinMode(enc, INPUT);
  Serial.begin(9600);
 
}

void loop()
{
  x = analogRead(enc);
  Serial.println(x);
  delay(1000);
 
}

Any help would be much appreciated. I am doing this basic code so I can know how to construct the LabView code which will be used in a larger project I am working on. Thanks.

madworm

10-bit pwm or analog output?
• Upload doesn't work? Do a loop-back test.
• There's absolutely NO excuse for not having an ISP!
• Your AVR needs a brain surgery? Use the online FUSE calculator.
My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets...
• Microsoft is not the answer. It is the question, and the answer is NO!

jamicubro

I am using the 10-bit PWM version

madworm

Then you need to add a suitable low-pass filter. analogRead() cannot read PWM signals, only true analog voltages.

OR

measure the duty-cycle of the signal using the pulseIn() function.
• Upload doesn't work? Do a loop-back test.
• There's absolutely NO excuse for not having an ISP!
• Your AVR needs a brain surgery? Use the online FUSE calculator.
My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets...
• Microsoft is not the answer. It is the question, and the answer is NO!

jamicubro

Ok great! That worked, thanks. It is now outputting a value between 0 and 1023 which is what the datasheet on the encoder prescribes. This was done using the pulseIn() function. LabView doesn't have an arduino vi for pulseIn(), but thats a problem for another forum I suppose.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy