-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Getting range of 18-4095 #22
Comments
Thanks for the issue, |
It seems to be fluctuating, i noticed this when i set it to home at under 10. And it never reached it. But occasionally i do get 10. Not sure what this is about, there was something in the datasheet about rotations. I noticed in the datasheet, that if used via 3.3v the 3.3v & 5v should be connected. I have never done this before and used these... and even now it seems to work kinda fine. Seems the pull up resistors are connected only to the 5v line.. so they were out of action. This board seems to have 10k pull ups, datasheet says 4.7k for 3.3v so they are sized probably to fit both voltages. |
I soldered the 3.3v & 5v together. Ran another test, this time at 256 microsteps.. slowly. The numbers stopped at 4095 for some time, and then skipped to 10!.. really weird. I will try this again. Redid the test, the same result. Stops at 4095 for some time and next up is 10. Third test, default settings. Removed all the settings i had. Same result. |
Tested on the Seeduinos AS5600 library that i used before, it works.. but it also has a weird issue. This is how it goes from 4095 to 0 :
I think you have a bug in your library. Maybe its about this:
Am i reading the wrong output with readAngle()? |
Ok, that was the issue. I was reading the wrong output.
|
Yeah, i think this works now! I was worried that this encoder cant keep up, as a lot of people seem to be under the impression that this is only a slow speed encoder. But im running this up to 25rps and now it seems to keep track. With sparkfuns library i had issues as it occasionally messed the rotation calculations, and now i know it was the lack of filtering that caused it. Im running this at 900 000khz on ESP32. I would recommend adding a linear counter in your library, and also output based on steps. You already have degrees, so why not steps directly. Just for user convenience and laziness. Aaand, just when i got this working..i find this : https://www.aliexpress.com/item/1005004570883506.html |
Great!
Would that be something like int32_t getCounter(); returns -2 billion .. 2 billion (do a mod 4095 for position?)
void resetCounter(); or how would you prefer the API calls? |
Found the datasheet, - http://www.magntek.com.cn/upload/MT6701_Rev.1.0.pdf |
I celebrated a bit too early it seems, it still occasionally fails.. i have been using this code to keep track of linear movement, its from an example of the original old as5600 library and has worked thus far on my applications. But now as i need more speed, it fails. I need to replace this with something that cant fail, as i know the direction the motor is moving.. i can probably use that information to come up with a more robust way of keeping track of the total amount of steps. As magnetic encoder is absolute, the only real problem to solve is to keep track of revolutions. As the stepper already knows its position, all i need is a back up if it stalls and loses count. output = as5600.rawAngle(); // get the raw value of the encoder
if ((lastOutput - output) > 2047 ) // check if a full rotation has been made
revolutions++;
if ((lastOutput - output) < -2047 )
revolutions--;
position = revolutions * 4096 + output; // calculate the position the the encoder is at based off of the number of revolutions
lastOutput = output; // save the last raw value for the next loop
encoderStep = (position - zeroPosition) / (4096 / 200); // converts to full steps & deducts starting point. |
Going to pick one of those up for testing, seems really interesting. The same seller also has a more expensive MT6825: And also seems to be more robust as it only monitors X/Y magnetic field. 3 or 4 wire SPI. |
That can only be done by measuring the angle at least 3x per rotation. In theory 2 but in practice maybe even 4x. With 3 samples per rotations the angle is max 120° so a full rotation is always detectable. These samples have to be spaced in time (roughly) equally to work. This implies that your code should have no blocking code to get this timing right. (thinking out loud)
|
Im measuring once per 1ms, and i'm exactly using 2 cores on ESP32. So its running on a separate core with high priority. Wire clock is set at 900 000Khz. The sensor can do 1Mhz, but i got errors at 1Mhz and with 900 000Khz its smooth sailing. I use 1kOhm pull ups on the ESP32 based on this : espressif/arduino-esp32#6444 (comment) Im lagging only 5 steps (5 steps is exactly 1ms) if moving at 5000steps per second (full steps, so 5000/200=25rps), so i can get 40 measurements per rotation. So the speed should not be an issue, i should be able to measure much faster if needed. Even now i think the 1ms comes from me using vTaskDelay(1), even though it should not be exactly 1ms. I think the sensor can go faster. I think the issue i'm having is the noise when moving from 4095 to 0. How to handle the possibility of random change of getting 4095 when you should be getting 0? |
If you can make 40 samples per rotation (~ 1 sample every 9°) , you could thinking of skipping the measurements in the "danger zone". E.g if rawAngle is between 4090 and 5. |
Yes, you are thinking this in degrees. Is that how its usually done? with optical encoders? The example code i'm using, is probably more suited for knobs etc. And it exactly measures the move from 4095 to 0. While i should indeed think this in degrees and check the rotation at some other point. |
Datasheet states that sampling rate is 150 us. So the sensor can in theory make 6000 samples / second. |
Yes, exactly. Even the slow 2x filter could do 0.286ms. So the sensor should be plenty fast. |
Optical encoders mostly use interrupts. When a step is made, or after N steps, an interrupt is generated. |
That MT6701 sensor you mentioned, has an ABZ interface. |
Yes, that seems to be what it is... i tried to do a quick google when i read about it thinking it was some sort of bus that i had not heard of. Already ordered one for testing, even the module is small enough to fit my use. As i tracked down these AS5600 modules that are only 15x15mm in size to fit my device. The only issue is, that on that MT6701, there are components on the backside.. that would be a problem for me. I dont have room for that. I think i should be ok with as5600 for this project though, i only need precession of 200 steps. That's 20.48 clicks per step, that should be more than enough to cover the possible noise. If i have like a buffer of 5 clicks at full rotation, that would be only 1/4th of a full step. And set the measuring point based on the starting point so that it always lands between steps.. so that i wont ever have the possibility of stopping at the edge. BTW. Can your library do wire & wire1 at the same time? I'm using two of these, one on wire and the other on wire1? Other tracks the motor, the other is just a knob. Previously i have used a crudely hacked version of the sparkfuns library that i did to accomplish this. |
(was occupied by gardening and some other libraries)
Yes, that should work. |
Ok i will try that. The problem seems to not be the transition from 4095 to 0, but just random noise that can happen. No matter what filters i use, this just happens randomly. Tested all the way up to 16x slow filter. Here is an example printout of moving down at constant speed, from somewhere it gets weird numbers and counts one revolution up.
These are the |
Ok, finally solved it. I just figured i don't need it, but apparently what i had was essentially a dark matter detector.. and when a dark matter particle hit it, it changed direction. Good thing its now back to being a normal encoder. If you want to improve your library, just type in big bold letters that you need to solder that DIR pin & 3.3v to 5v if you use 3v. I had not seen anything about that DIR pin before i found your library, and its really hard to understand what the issue is as its so random. I thought i only needed it for analog use. So the speed is not an issue, this can track much faster speeds if needed. I'm still using 4x slow filter at this speed. |
😂 you're in for the next Nobel prize!
OK, will add the following to the readme.md. From the datasheet, page 30 Direction (clockwise vs. counterclockwise) |
Please note that there is already an explanation of the use of the DIR pin in the readme.md. The DIR (direction) pin of the sensor should be connected to:
In the latter setup the library can control the direction of
(*) if begin() is called without directionPin or with this See Software Direction Control below for more information. Software Direction ControlExperimental 0.2.0 Normally one controls the direction of the sensor by connecting the DIR pin The directionPin is default set to 255, which defines a software direction control. The gain is that the user does not need an IO pin for this, The user still calls setDirection() as before to change the direction. TODO: measure performance impact. TODO: investigate impact on functionality of other registers. |
I have updated the readme.md in the master branch. |
Yes, i noticed it but still skipped it :) Just thought that it would be good to have it really clearly mentioned in the start. How to set up the hardware side. The DIR pin & 3.3v & 5v connection. If i make this mistake, i bet there are a lot of other people making the same mistake. As it seems you cant leave it floating, that will lead to issues. "a free floating IO pin of the processor = under library control." So i would maybe rephrase this part. Having the "floating" as third option might make it seem like you can just leave it floating and control it via the library. I would have never noticed this if i had not tried to use it on this motor & found your library, as i have used these as dials.. and never did anything with the dir pin, i didn't even knew about its existence. Really good thing. As if i had not learned this, my other project would have had random weird issues that i could not have been able to fix via software. |
Check if I can move it up.
I'll check if I can add some diagram.
Just updated that section, when I reread it, it looked at least ambiguous to say it nicely. If you have time, would you read the current readme.md. |
@cranefist |
Merged, create a new 0.3.2 release |
@cranefist |
As I think the issue is solved I close it. Feel free to reopen it if needed, or open a new one if not related. |
Hello
Great to find a fresh library for this chip. I switched using this library, and ran across a weird thing.
I get a range of 18-4095. Any idea why this is happening?
Im moving a stepper motor slowly, and reading it via serial monitor. It shows all the steps clearly, with 1 increments. Just somehow starts at 18.
Can the filters affect this? These are my settings:
The text was updated successfully, but these errors were encountered: