Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frequency and period not initialized #211

Closed
AKAMEDIASYSTEM opened this issue Nov 30, 2017 · 4 comments
Closed

frequency and period not initialized #211

AKAMEDIASYSTEM opened this issue Nov 30, 2017 · 4 comments
Labels

Comments

@AKAMEDIASYSTEM
Copy link

Hello, I'm trying to use the newly-supported frequency getters and setters, but running into some difficulty.

My script begins by initializing eQEP0 and eQEP1. Because I wasn't sure what the default encoder polling frequency was, I then go:

    print(qep0.frequency)
    qep0.frequency(1000000)
    qep1.frequency(1000000)

...this resulted in some python3 errors (I needed to wrap int() around some inputs in the frequency methods), and after clearing those up I encountered an error in which self._eqep.node.period is not initialized.
More specifically, I get the error

File "/usr/local/lib/python3.5/dist-packages/Adafruit_BBIO-1.0.8-py3.5-linux-armv7l.egg/Adafruit_BBIO/Encoder.py", line 279, in frequency
    self._eqep.channel, frequency, period))

...thanks in advance for any advice/help you can provide!

AKA

@dplanella
Copy link
Contributor

@AKAMEDIASYSTEM thanks for the feedback. A few things:

  • I've fixed the int() cast issue and the frequency calculation on the fix-encoder-frequency branch you can test on PR Encoder: fix frequency calculation from period #213
  • There is a bug in your test snippet: frequency is a property, not a function. Thus to set the frequency to 1 MHz as you're intending to do, you'd do an assignment qep0.frequency = 1000000.
  • If I'm not mistaken, this sample frequency is most relevant if you set your eQEP channel to relative with the setRelative() function. The default mode is absolute. Quoting from this documentation (note: the API only exposes frequency as the inverse of the period described below):

mode - the capture mode of the eQEP hardware. 0 - Absolute mode. The position starts at zero and is incremented or decremented by the encoder's movement. 1 - Relative mode. The position is reset when the unit timer overflows. This allows for tracking of the encoders movement per unit time. Useful for velocity regulation

period - the time in nanoseconds for the unit timer to overflow. The internal clock to the eQEP hardware runs at 100 MHz. Since the unit timer is a 32 bit timer, this puts the maximum value of this parameter at around 40 seconds. Note the value for this would be 40,000,000,000 nanoseconds.

position - the position of the encoder. In absolute mode, this attribute represents the current position of the encoder. In relative mode, this attribute represents the position of the encoder at the last unit timer overflow. This attribute is pollable. In either operating mode, the unit timer overflow event wakes up any process polling on this attribute. This feature is most useful in relative mode. It allows the process or thread to awake when there is measurement available in the last time period.

@pdp7 pdp7 added the bug label Dec 1, 2017
@pdp7
Copy link
Collaborator

pdp7 commented Dec 1, 2017

@AKAMEDIASYSTEM please try again. I've merged #213 from @dplanella

@pdp7
Copy link
Collaborator

pdp7 commented Dec 1, 2017

I have created a new Release 1.0.9 (which includes #213), and it has been published on PyPI

@pdp7
Copy link
Collaborator

pdp7 commented Jan 26, 2018

@AKAMEDIASYSTEM please re-open if this is still an issue

@pdp7 pdp7 closed this as completed Jan 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants