Pages: [1]   Go Down
Author Topic: encoder troubles  (Read 510 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"The old Europe"
Offline Offline
Edison Member
*
Karma: 1
Posts: 2005
Bootloaders suck!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

10-bit pwm or analog output?
Logged

• 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!

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using the 10-bit PWM version
Logged

"The old Europe"
Offline Offline
Edison Member
*
Karma: 1
Posts: 2005
Bootloaders suck!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

• 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!

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: