Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumWiring HardwareTangible computing › Encoder Library issue

Page Index Toggle Pages: 1
Encoder Library issue (Read 8781 times)
08/10/07 at 16:10:50

roypardi   Offline
Junior Member
I Love YaBB 2!
Boston USA

Posts: 57
**
 
Hi,
I'm trying to use a Maxon Tacho encoder with the Wiring Encoder Library. It's this one here:
http://pdf.directindustry.com/pdf/maxon-motor/programm-07-08/7173-21152-_251.html

The spec says 100 counts per turn. I think I have it wired up correctly and I am able to see values printed to the serial monitor.

There are two problems though - I am getting way more than 100 counts per turn and the accuracy of the encoder seems way off: I can turn it by hand back and forth between two positions and the reported positions seem to drift considerably.


The barebones code I am using to test this is below. I have the encoder powered + grounded off the 5v taps on the Wiring board, am using pins 2/3, and have pull-up resistors (3.3k) on the channel pins. So.... is there anything I am missing?

-thanks!

--Roy


Code:
Encoder myEncoder;
long val;
long lastVal;

void setup(){

  Serial.begin(9600);
  myEncoder.attach(2, 3); // attach an ecoder to pins 2 and 3.
  myEncoder.write(0);
  lastVal = 0;

}

int sendPosition(){
  val = myEncoder.read();
  if (val != lastVal){
    Serial.println(val);
    lastVal = val;
  }
}

void loop()
{
  sendPosition();
}  

« Last Edit: 08/10/07 at 17:51:30 by roypardi »  
IP Logged
 
Reply #1 - 08/13/07 at 02:15:28

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
hi Roy, please let me know which version of wiring are you using.
 
IP Logged
 
Reply #2 - 08/13/07 at 16:41:21

roypardi   Offline
Junior Member
I Love YaBB 2!
Boston USA

Posts: 57
**
 
hi~ I'm using v12.

I've boiled down my issues some:
--turn count: getting a reported 600 counts (using Encoder lib) per full 360 degree turn of the motor shaft when the Maxon Tacho encoder is rated at 100 counts per turn. <--am I not understanding what this spec means?

--spurious values: I have a test rig moving a load back and forth between 0 and 2000. It works except that I get an anomalous value every n cycles (not predictable) where the count will be displayed as a very high number (655369, etc.). I can filter this in code but is it indicative of some other issue. I am using Serial.print() with this - could there be some issue there?

--my rig will run fine for 50 or so cycles and then it starts to slow down/stall. I assume this is some (really bad) issue with my hardware (H bridge/motor) set up but I thought I would mention it.

My other issues seem related to my code. In a loop I grab the encoder value at the start of the loop and then use that throughout the work done in the loop. I haven't used interrupts before so I think maybe that I haven't understood that the true value of the encoder can get out of scope from my initial read.

[code]void loop()
{
  long v  = myEncoder.read();

// do some work

// ***** v may be out of scope of myEncoder state

//do some more work

} [/code]

Finally - how many interrupt pins are there? This page says 4:
http://wiring.org.co/reference/libraries/Encoder/Encoder_.html

This page says 8:
http://wiring.org.co/ioboard/index.html#070

Oh... and since I am asking a million questions here... ;-)
I want to ramp the PWM up smoothly with relative to the number of steps my motor has to move. Thinking of doing something like speed = speed + .2 (or some forumla that determes the ramp rate based on the number of steps needed).

So...........
--can I use analogWrite with floating points or should I round first

--does the port rollover if I exceed 255?

--can I add/multiply an int and a float?

Thanks! -- Roy

 
IP Logged
 
Reply #3 - 04/03/08 at 12:25:17

Alan_Kilian   Offline
Full Member
Wiring? It looks like
Java to me.

Posts: 118
***
 
So, where did you get with this?

I'm trying to use two encoders wired to different pins, but I get the same
reading from encoder1.read() and encoder2.read().

They both move with the encoder, but I should be getting two different readings.

I haven't run the code long enough to see if I'm getting jumpy readings
or drift yet.

I'm running Wiring 0015 Alpha.
 
IP Logged
 
Reply #4 - 04/03/08 at 15:30:47

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
hi Alan, can you post some code with the problem?
 
IP Logged
 
Reply #5 - 04/03/08 at 18:39:38

Alan_Kilian   Offline
Full Member
Wiring? It looks like
Java to me.

Posts: 118
***
 
Sure, I'll post later today.

How do I get "svn co" to work?
It seems that the server is down or restricted. (Or I'm using the wrong one.)
 
IP Logged
 
Reply #6 - 04/03/08 at 18:42:45

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
It should be like this: svn co svn://wiring.uniandes.edu.co/trunk/wiring
please try and let me know, I´ll try it myself later today.
 
IP Logged
 
Reply #7 - 04/03/08 at 21:26:47

Alan_Kilian   Offline
Full Member
Wiring? It looks like
Java to me.

Posts: 118
***
 
$ svn co svn://wiring.uniandes.edu.co/trunk/wiring
svn: Can't connect to host 'wiring.uniandes.edu.co': Connection timed out

kilian@kilian-xp-lap ~/Hobbies/Wiring
$ ping wiring.uniandes.edu.co
PING wiring.uniandes.edu.co (157.253.27.79): 56 data bytes

----wiring.uniandes.edu.co PING Statistics----
2311 packets transmitted, 0 packets received, 100.0% packet loss
 
IP Logged
 
Reply #8 - 04/04/08 at 00:53:00

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
yes, seems it is the school´s firewall, I sent a mail to the system administrator to fix this.
Thanks Alan.
 
IP Logged
 
Reply #9 - 04/04/08 at 01:08:10

Alan_Kilian   Offline
Full Member
Wiring? It looks like
Java to me.

Posts: 118
***
 
I'm SOOO not a C++ guy.

How in the heck does service() know which _position to increment?

Maybe encoders[_index].position++;
or encoders[this].position++;

Maybe it should look at which pin caused the interrupt, and look
in some global array setup by attach() to get the location to
increment? (or decrement)
 
IP Logged
 
Reply #10 - 04/30/08 at 05:53:02

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
I don´t know what´s the problem with the address, thye said they will fix it soon, in the mean time here is the address you can get the code from svn co svn://aeon.uniandes.edu.co/trunk/wiring

I have tested it and seems to work out of the school server. This will migrate soon to another server. Let me know if it works for you. I have updated the build page in http://wiring.org.co/source as well to point to this address to get the source.
Best,
H.
 
IP Logged
 
Page Index Toggle Pages: 1