Forum Index
Problem with program using inputcapture

 
Author Message
abcuser



Joined: 27 Mar 2008

Posted: 25 July 2008, 2:41 AM    Post subject: Problem with program using inputcapture

I am using inputcapture() to collect the time between each pulse from an encoder.

The encoder has 500 pulses per revolution and is attached to a shaft.

The problem is that each of the 500 pulses are different so I have to keep the index position to make sure I know where I am at all time.

I then compare the values I get to the ones on a reference file at each index position.

When I first start the program it runs very well, but when I stop the shaft and restart the motion at a later time my data is off.

I am assuming that when the shaft stops, it will be somewhere in the middle of a pulse. Not sure if I am losing a count in between.

Any help would be appreciated. Or if someone knows a better way to do it, please let me know


Below is the program that I am using
Code:
sub main()
  register.timerspeed1 = 4
  i=0
  call read.source("reference.txt")
  Call WaitForInterrupt(zxPinRisingEdge,WaitInt2)
  Do
    Call inputcapture(data,1,0,5)
    if (data > 65530) then
      ans = 0.0
    else
      width =csng(data)*(1.0/28799.5) 
      i=i+1
      index = i Mod 500
      if (index = 0) then
        ans = (read(500)/width)
      else
        ans = (read(index)/width)
      end if
    end if
    debug.print cstr(ans)   
  loop
end sub
Back to top
pjc30943



Joined: 02 Dec 2005

Posted: 26 July 2008, 1:32 AM    Post subject:

Is the shaft rotating in just one direction?
Back to top
abcuser



Joined: 27 Mar 2008

Posted: 26 July 2008, 21:02 PM    Post subject:

yes, it only rotates in one direction
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 27 July 2008, 0:40 AM    Post subject: Re: Problem with program using inputcapture

abcuser wrote:
I am using inputcapture() to collect the time between each pulse from an encoder.
It may be helpful if you describe your requirements, e.g. keep track of angular position, monitor rotational speed, track number of rotations per unit time, etc. Also, it may be helpful if you can give a link to a datasheet for the encoder.

Also, which ZX are you using? I ask this because some solutions are only available on the native mode devices.
Back to top
abcuser



Joined: 27 Mar 2008

Posted: 27 July 2008, 22:21 PM    Post subject:

I need to keep track of the angular positions and the pulse width at that position. I don't have the data sheet for the encoder, it is a drc tk731. It is compatible with this encoder
http://www.encoder.com/literature/datasheet-121.pdf
I am using the zx24a, but I also have a zx24n if that is needed.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 29 July 2008, 16:31 PM    Post subject:

abcuser wrote:
I don't have the data sheet for the encoder, it is a drc tk731. It is compatible with this encoder
I don't fully understand your application so I can't figure out why you need to keep track of the pulse width. The link that you gave referred to a quadrature encoder with an index pulse. It seems to me that you can track the angular position by simply counting the leading edges of the pulses from one channel of the quadrature output. When the leading edge occurs, you could sample the index output to know if you are at the index position.

What is the maximum rotational speed that you need to support?
Back to top
spamiam



Joined: 13 Nov 2005

Posted: 29 July 2008, 18:22 PM    Post subject: Re: Problem with program using inputcapture

abcuser wrote:
but when I stop the shaft and restart the motion at a later time my data is off.


It sounds as if you can tell by looking at the data whether it is in-synch with what you expected. Can you translate this to an algorithm? The idea would be that the software can determine, based on the last good data, whether this new data fits the sequence. If not can a single dropped transition account for the lost sequence.

BUT

Usually, you can determine absolute position by simply examining the sequence of transitions when using something like a standard quadrature encoder, but not quite. Usually it takes a full rotation to be able to determine the absolute position, but with a non-standard encoder where one channel has a fixed angular rotation per transition, then a second channel with a progressively greater rotation per transition, then you can count the CH1 transitions that occur per CH2 transition and then get the absolute position after 2 CH2 transitions. The problem is that this might take a fair amount of rotation before you get 2 CH2 transitions depending on where you are in the rotation. This will only work for unidirectional rotation unless you add a third channel which works with channel 1 as a standard quadrature encoder.

The encoder might look like this

    CH1:10101010101010101010101010101....
    CH2:10110001111000001111110000000....


you could also have Channel 2 look like this:
    CH2:10110111011110111110111111011111110.....

Channel 1 is used to measure the rotational speed and amount. Channel 2 is used to determine the starting point (retrospectively). There is likely to be a more sophisticated manner to get 2 channels to give absolute position in less than one full rotation, but I am not aware of it.

By using more channels (bits) you can get absolute position more quickly and more precisely. See this link:http://mechatronics.mech.northwestern.edu/design_ref/sensors/encoders.html

-Tony
Back to top
abcuser



Joined: 27 Mar 2008

Posted: 03 August 2008, 9:51 AM    Post subject:

I was able to get the program to work.

I just changed the inputcapture timeout value from 5 to 1.
inputcapture(data,1,0,5) -> inputcature(data,1,0,1)

I also used a wait interrupt after the data gets larger than 65500. I use the inverse of the pulse that I am using currently to trigger the wiat interrupt
if (data > 65530) then
ans = 0.0
waitinterrupt()
Back to top
spamiam



Joined: 13 Nov 2005

Posted: 04 August 2008, 1:13 AM    Post subject:

what sort of encoder are you using to get absolute position. What is its resolution?
Back to top
Display posts from previous:   
Page 1 of 1

 



ZBasic Microcontrollers Home
All content Copyright © 2005, 2006, 2007, 2008 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group