Measuring speed and position using the AS5600 magnetic encoder

Поделиться
HTML-код
  • Опубликовано: 26 окт 2024

Комментарии • 98

  • @rashmikp612
    @rashmikp612 2 года назад +3

    Hey, I absolutely love how informative your videos are and they've been really helpful in progressing through my projects as well. I have a question though, since you used the Accelstepper library to control the motors, why don't you use the AS5600 library for the encoder as well? It could reduce the number of lines of code as well, right? Just curious to know. Would appreciate your comments on it. Thanks again!

    • @CuriousScientist
      @CuriousScientist  2 года назад +6

      Hi and thanks! When it is possible, I prefer writing my own code from scratch because it also proves that I know how the hardware and the software behind it works. Anyone can copy-paste a few lines to include a library in their code but then they usually don't know how the things work. I took my time, studied the datasheet of the AS5600 and based on it I wrote my own code for it from scratch. You might ask, okay but why do I still use the AccelStepper library or libraries for displays? Because it would take huge amount of time to implement my own library. But eventually I will make my own stepper motor driver in the future.

  • @profytecnet
    @profytecnet Год назад +1

    Impressive, I suspect that variable measurement values related to motor construction are also responsible for the sound created by stepper motors at higher speeds. Thanks!

    • @CuriousScientist
      @CuriousScientist  Год назад +1

      Thanks! I don't know how the sound is related to variable measurements, but steppers have a distinct sound at high speeds even without any measurements. It is the construction of them that makes the sound and not the sensors around them.

  • @sewingmachinesindetail
    @sewingmachinesindetail 4 месяца назад

    Thank you for this video. I have tried to look for information in datasheets of this sensor and some of the other similar AMS sensors. For an application, I like to read the angle each 0.5 ms. However I am not sure how the sensor timing is. One way could be, that the sensor have a free run update of the measured angle. When you then issue a reading command, you will get the last measured angle returned. A second way could be, that the sensor synchronize its sampling of its hall sensors with the reading command you send. However, you cannot expect the AD-conversion to be finished that fast, and therefore the updated value may be, when you read later on. In this second way, you will be able to put a time stamp on the reading. The first way, you will not know, when the hall sensors were read with a possible uncertainty of 100 us. Therefore in the first way, you cannot put an accurate time stamp on the reading. In order to measure the speed, you have to be able to divide that angle change with the time change. If you have an uncertainty on your the timing, you will get a high noise level of the measured speed, when you sample this fast like every 0.5 ms. Do you have an idea how the timing is in these sensors?

    • @CuriousScientist
      @CuriousScientist  4 месяца назад

      Hi! On page 10, figure 14 of the datasheet, you can see the timing chart of the i2c communication. Then on page 14, figure 17 you can find the data read timing. This could help you to figure things out hopefully.

    • @sewingmachinesindetail
      @sewingmachinesindetail 4 месяца назад

      @@CuriousScientist Thank you for answer. I think I later found out how these sensors operate, and the measurements of the hall sensors are repeated by the sensors own clock with repetition rate (sampling rate) of max 150 us. The problem is, that you got no way to synchronize the sensors own clock with I2C reading. When you ask for data via I2C, you will get the latest updated value from the sensors own cycle update. Assume, that the sensors sample rate is 143 us and you read the sensor via I2C every 500 us. The time distance between two measurement values will sometimes be 3x143 us = 429 us and sometimes be 4x143 us = 572 us. Without more advanced data handling you will in this way introduce an rms noise in calculated speed of about 14 % of the speed signal. At low speeds you need to add the noise from the sensor values itself. It have been discussed here: community.simplefoc.com/t/questions-to-datasheet-of-as5048a-and-foc-use/5015/8

    • @CuriousScientist
      @CuriousScientist  4 месяца назад

      If you have such time critical tasks to do that you are worried about microseconds, maybe you should not rely on a $0.5 chip.

    • @sewingmachinesindetail
      @sewingmachinesindetail 4 месяца назад +1

      @@CuriousScientist 14% noise do work in many situations. The other more expensive chips of the same kind with xy magnetic sensors got the same kind of problem. But it may not be the best kind of sensor, when you need high gain in a speed control loop. Optical sensors got similar kind of problems.

  • @vinaysharma1762
    @vinaysharma1762 3 месяца назад +1

    Can you explain how to program the AS 5600 for reading the angle 0-5V

    • @CuriousScientist
      @CuriousScientist  3 месяца назад

      You don't need to program it, per say. You need to read the out pin and convert the signal to an equivalent angle value. Read the datasheet.

  • @murraymadness4674
    @murraymadness4674 6 месяцев назад +1

    I find it impressive that steppers are so accurate. However, my 3d printer can skip rather easily when it hit a clumb of filament and this ruins the print, there is no recover possible. If they used a feedback system, it would see the skip and could recover. While the print would show some defect, at least it would not keep printing half a spool of spaghetti for an hour!

    • @CuriousScientist
      @CuriousScientist  6 месяцев назад

      Hi! Have you tried yo adjust the tension on the belts and maybe increase the current for the motors? Maybe that would be enough to overcome the issue. But yeah, a closed loop system could help to alleviate the issues like this. However, you'd need a system that processes the target position as well. Probably there are already such products.

  • @adriangrzelak1451
    @adriangrzelak1451 2 года назад

    Great tutorials for this encoder. Thank you for your great work.

    • @CuriousScientist
      @CuriousScientist  2 года назад

      Thank you! I am glad that you like my tutorials!

  • @user-sergey12570nsi
    @user-sergey12570nsi 7 месяцев назад +1

    Good afternoon In the diagram, which is published on the website, the display, encoder and driver are powered by 3.3 volts from the Arduino. What is the reason for this and can it be powered from 5 V.

    • @CuriousScientist
      @CuriousScientist  7 месяцев назад

      With Arduino Nano, you can use either 3.3 V or 5 V. It doesn't matter. However, if you use an STM32 microcontroller, you must use 3.3 V because the microcontroller can not tolerate 5 V. Since many STM32 MCUs are "Arduino-compatible," and I also actively use them in my projects, I typically try to use 3.3 V whenever it is possible to avoid burning my chips.

    • @user-sergey12570nsi
      @user-sergey12570nsi 7 месяцев назад +1

      @@CuriousScientist Большое спасибо!

  • @sergejdorogin857
    @sergejdorogin857 6 месяцев назад +1

    Hello, thanks for your nice tutorial. In my project i try to use your source code for the control of AS5600. As Display i use an Oled 1.54 zoll. The display is also connected via i2c. When i implement the source code for the magnetic sensor, my oled doesnt work any more. 10 kOhm internal pull up resistor for SCL and SDA are installed on the display. Maybe you have a notice for me. Booth devices have different I2C adresses #0F36 and #0F3D.

    • @CuriousScientist
      @CuriousScientist  6 месяцев назад +1

      Hi! Do you use the *exact* same circuit as I do (except from the display, of course)? As long as the devices have different i2c addresses, it should work. The error is maybe somewhere else in the circuit. First try each component separately, then see why they don't work together.

  • @youssefbentahra
    @youssefbentahra 2 года назад +1

    Hi, I like your videos! They are very interesting and helpful.
    I would like you to help me if possible because I don't know where to start, I am trying to make a closed loop control of a stepper motor with the AS5600. It does not necessarily have to be a PID, having a position control would be enough in case the motor skips steps, the encoder can detect it and correct the error.
    It will be very interesting to make a video of it or please if you could share a small sketch with this features if you made one
    Thank you for your reply!

    • @CuriousScientist
      @CuriousScientist  2 года назад

      Hi! The simplest thing is to check if the motor is at the requested position at the end of the movement by comparing the target position with the encoder's position. If they don't match, calculate the difference between the target and the current position and move the motor accordingly. But this is strictly position based. Furthermore, I don't make videos on request for free, sorry.

  • @sus7382
    @sus7382 2 года назад +2

    Hey man, been nice watching your videos, criminally underrated and unknown.
    I have a question though, I have a tmc2208 driver that is supposed to be able to switch out with a4988s, and I want to use it on that little expansion board that you have. I tried using the expansion board myself with the accelstepper library, but to no avail. Could you please explain how you managed to get your expansion board to work with the accelstepper library, and if I would be able to hotswap it out with a tmc2208?

    • @CuriousScientist
      @CuriousScientist  2 года назад

      Hi and thanks! It is very important to connect the enable pin of the breakout board to the ground, otherwise the stepper motor will not be powered. Regarding the tmc2208 question, I don't know, because I have never used that board, but since other people also asked it, I will test it and publish a short video about it if it works.

    • @sus7382
      @sus7382 2 года назад

      @@CuriousScientist thanks alot, do you have a discord or anything alike? I highly suggest you make one for people to talk about these things

    • @CuriousScientist
      @CuriousScientist  2 года назад

      Sorry, I don't have any of these because I don't have the time and resources for it. Viewers are always welcome to discuss these questions in the comments.

    • @sus7382
      @sus7382 2 года назад

      @@CuriousScientist perfectly understandable, and thanks for the help.
      One last question relating to my first comment, how do you use the accelstepper library with the expansion board? No matter what I do I cannot seem to get it to work unless I manually set up a loop with a delay between setting the step pin to be high and low to manually spin the motor. I'm trying to use serial to get some values from a joystick in python to control the speed of 2 stepper motors for a turret, and your videos have been a great help but the one thing I cannot wrap my head around is the usage of the expansion board and accelstepper/multistepper library. I tried using your diagram and code but nothing seems to work

    • @CuriousScientist
      @CuriousScientist  2 года назад

      I have dozens of videos where I use the expansion board and they work properly, so something must be wrong with the code you use or the circuit. The expansion board is so simple, it only needs 3 wires, so you might overlook something very simple.

  • @retinapoliyn7462
    @retinapoliyn7462 2 года назад +1

    I like your videos, They deep review.
    according AS5600 datasheet magnet center should be exactly at center of SOIC8 (maximum tolerance 250 micrometer)
    How did you achieve that?

    • @CuriousScientist
      @CuriousScientist  2 года назад +1

      Thanks! My PCB is done by a professional manufacturer (PCBWay), so the placement of the components are within the tolerance. Regarding the magnet on the shaft, the bearing fits tightly around the shaft so I can use it as a sleeve to perfectly center the magnet on the shaft.

  • @SWRDMaster
    @SWRDMaster 2 года назад +2

    If you set a global 'current time' variable at the beginning of your main loop, using millis(), and reference that variable throughout your program it will dramatically improve your loop time. Millis() is very time hungry and should be used sparingly for time critical applications; such as motion control. This should not throw off any calculations unless you have branches that are _slow_ to execute _on_occasion._ If that is an issue then the long branch can be broken into smaller steps in a sequential state machine to be executed over several main loop executions.

    • @CuriousScientist
      @CuriousScientist  2 года назад

      Wow, thank you! I did not know or think about this solution, so I learned something new now. Thank you for this very constructive and helpful comment! Once I have a little time, I will test the performance of your approach and I will use it in future projects.

    • @maxlenin-k8n
      @maxlenin-k8n Год назад

      @@CuriousScientist did you test this out in a project yet? Could you post it here when you do?

    • @saiful-islam
      @saiful-islam 9 месяцев назад

      when I try to rotate my stepper for certain condition like . Is my stepper rotate and passed 2500 degree? then stop. For this ,I have wait for like 50 seconds. How to improve this? I did follow your magnetic positioning encoder.
      @@CuriousScientist

  • @stevenv.gwarlock2078
    @stevenv.gwarlock2078 2 года назад +1

    How do you get the magnet so good aligned with the sensor. I'm trying to aligned the magnet with the sensor but I don't get a linear readout. I also 3D printed a few "holders" and "casings" to get things aligned, but no luck. I also noticed that there a more status values than 39 23 and 55, but I don't know the meaning of them. ( I'm using the "white" AS5600 one you can find on amazon and are used in other of your RUclips vids )

    • @CuriousScientist
      @CuriousScientist  2 года назад

      I put the magnet on the shaft with a drop of super glue then I pushed a metal sleeve on the magnet and the shaft which had everything aligned. For the status values, please refer to the datasheet. I suspect that probably you have issues with the distance between the sensor and the magnet. It should not be an issue if it is slightly misaligned, but it will misbehave if the distance is not correct.

  • @Tuupertunut
    @Tuupertunut Год назад

    Good video! I'm wondering whether the AS5600 would be accurate enough to be used as an absolute encoder for a telescope mount. For that use case I would need an accuracy of at least 15 arc minutes or 0.25 degrees so that the telescope mount could keep track of where it's pointing at. I know that the AS5600 has a theoretical resolution of 0.09 degrees and from this video it seems to be able to measure large movements with that accuracy, but I'm left wondering how accurately it would detect really small movements. Say if I moved the telescope 0.14 degrees to point at another star, would the AS5600 always be able to detect the movement and update it's raw value by one or two?
    I think you could test this by setting your microstepping on the stepper motor really high and moving it one step at a time and checking how the measured value is growing.

    • @CuriousScientist
      @CuriousScientist  Год назад

      Hi! I think 0.14 would be challenging. Or at least you would always have that +/- 0.09 uncertainty. So, either you will get 0.23 or 0.05. Also, the problem is that the microstepping might not be in sync with the steps of the encoder. You can achieve step sizes such as 0.9, 0.45, 0.225...etc. degrees. But this does not coincide with the 0.09 step size of the encoder. Therefore, this can also lead to some uncertainty.
      Regarding testing, I can not test it right now because I don't have the setup assembled. It would take a lot of time and effort to assemble everything again.

  • @silverback3633
    @silverback3633 11 месяцев назад

    How do you resolve the dead band gap of 20 LSBs (1.8 DEGREES) in a continuous rotation reading?

  • @saiful-islam
    @saiful-islam 9 месяцев назад

    when I try to rotate my stepper for certain condition like . Is my stepper rotate and passed 2500 degree? then stop. For this ,I have wait for like 50 seconds. How to improve this? I did follow your magnetic positioning encoder.
    And Here in this video you did use same code? and how I can use accelsetepper library in my code like you did, please guide me

    • @CuriousScientist
      @CuriousScientist  9 месяцев назад

      Increase the speed, maybe!? 2500 degrees is about 7 turns. That should be possible within 1 second. If you are asking about the code for the AS5600, I used the same code in all my videos where I used the AS5600 sensor.

  • @karteeknayak4831
    @karteeknayak4831 Год назад +1

    Heyy, is it possible to not use an encoder at all and still get the position and rotation measurement using accel stepper library? I'm using a Nema 23 Hybrid stepper motor. "The position control is achieved by a simple Open Loop control mechanism so doesn’t require complex electronic control circuitry: - this is what I read.

    • @CuriousScientist
      @CuriousScientist  Год назад +1

      Hi! Yes, it is possible the get the current position (currentPosition()) and the speed (speed()) from the accelstepper library. Please read the documentation on its website to see which functions should be called to fetch those values. If I recall correctly, the function that returns the position can block the CPU, so you have to be careful with it. Don't call it too often.
      If you have a NEMA23 hybrid system, then it is a closed loop system (servo). The loop is not between the motor/encoder and the microcontroller, but between the motor/encoder and the stepper driver. The motor has an encoder and the driver makes sure that the motor is running according to the control signal received from a microcontroller (or anything else). But, you won't be able to read the position of the encoder directly. The encoder only communicates with the driver.

    • @karteeknayak4831
      @karteeknayak4831 Год назад

      @@CuriousScientist We are working on a six wheel drive for a competition (PID), so would that need encoders (ig we need them now that you explained it), and if encoders are needed then can we connect them all in I2C protocol?

    • @CuriousScientist
      @CuriousScientist  Год назад +1

      Of course you'd need encoders, because the core principle of PID control is to see how well your system is keeping up with the target value. You can use multiple encoders but you'll need an i2c multiplexer, because all encoders have the same i2c address. I have videos on that topic too, search for a X-Y milling table in my uploaded videos. Or search for i2c multiplexer.

  • @botak333
    @botak333 Год назад

    It posible to record the value to the sd card?? And after that play again with digital write??? So the motor stepper will always play the value we record ??

    • @CuriousScientist
      @CuriousScientist  Год назад

      Sure, it is possible.

    • @botak333
      @botak333 Год назад +1

      @@CuriousScientist okk i will try, if i get problem i will ask u sir🙏🙏

    • @botak333
      @botak333 Год назад

      @@CuriousScientist hi bro, first time use as5600 should be program?? Because the out(pwm analog) only show 3,3v if i turn the magnet still 3,3v. And i try to program B with 3 wire like on the tutorial ams. And now i get the pwm output but my mistake is i only set for halp circle sir, now i want to get 360deg. How do program as5600 from i2c use arduino sir??

    • @CuriousScientist
      @CuriousScientist  Год назад

      Make up your mind, am I a bro or a sir now? Please read the datasheet, your question is answered there. I don't remember the details from the top of my head, so I would also need to read the datasheet to answer your question. And I don't have time for that, sorry.

  • @jwchen119
    @jwchen119 2 года назад

    I'm curious, where's the magnet? And how you fixed the magnet on the shaft?
    It's is very important to set the magnet at the center of the AS5600

    • @CuriousScientist
      @CuriousScientist  2 года назад +1

      I told it in the video... The magnet is attached to the shaft. It sticks to the shaft because it is magnetic, but I actually added a drop of superglue, just to keep it in the center. You should check the other video that I recommended in this video because it shows more information about the magnet and its mounting.

  • @foca_
    @foca_ Год назад

    Hello! Do you know if these encoders remember the value AFTER power off? Say the AS5600 read 25344.6, will it remember this value after you shut it down, and boot it up again?

    • @CuriousScientist
      @CuriousScientist  Год назад +1

      Hi!
      Sure, it is an _absolute_ encoder.

    • @justinc2633
      @justinc2633 11 месяцев назад

      if you need to remember the state it was at when powered off (lets say it powers off, moves a little, then when you turn it on you need to know where it was) then youll have to write to eeprom yourself in code

    • @CuriousScientist
      @CuriousScientist  11 месяцев назад

      Yes! If the shaft is moved between a power off - power on cycle, then its position needs to be saved in the eeprom. But if the shaft is only moving within the 0-360° range and there's no movement, then no need to worry about it. That's what I meant in my previous response.

  • @retinapoliyn7462
    @retinapoliyn7462 2 года назад +1

    Is there any cheap solution like this for Liner Encoder?

    • @CuriousScientist
      @CuriousScientist  2 года назад +1

      Linear encoders are much more expensive. The closest solution is to hack a digital caliper. I have a video on the topic on my channel. Search for it!

  • @muhammadachsanulinammahasi1702
    @muhammadachsanulinammahasi1702 2 года назад

    thank you very helpful, the results of my experiments the rpm value is unstable, if there is no motor rotation, it shows a value of 0, but often other numbers appear, please advice for this problem

  • @melovescotch
    @melovescotch 2 года назад +1

    how fast can you spin before library looses steps?

    • @CuriousScientist
      @CuriousScientist  2 года назад

      I haven't tested it to the absolute maximum (theoretical maximum RPM of the stepper motor), but it was still okay at 2400 steps/s. I believe that it can go much more higher. But that might need some adjustment on my code to make sure that the position of the shaft is polled frequently enough. I will test this when I make another video with this board.

  • @shecterelectric432
    @shecterelectric432 2 года назад

    So can you calculate all those parameters only with the library and without the magnetic encoder?

    • @CuriousScientist
      @CuriousScientist  2 года назад

      Of course you can, but if something happens to the motor (skips steps...etc), the values are not valid anymore.

  • @JefinMarshal
    @JefinMarshal Год назад

    Does this encoder know the absolute position even if the power is turned off and on?

    • @CuriousScientist
      @CuriousScientist  Год назад

      Yes, it is also an absolute encoder. The position of the magnet relative to the chip gives you an absolute value of the angle at startup. Read the datasheet for more details.

  • @rodstartube
    @rodstartube 2 года назад

    How do you interface this encoder with a hybrid servo drive with A and B signal interface?

    • @CuriousScientist
      @CuriousScientist  2 года назад

      As far as I know, you cannot. It does not have that kind of output.

  • @unknownblueblue
    @unknownblueblue 2 года назад

    Hi sorry for asking again, my encoders arrived today and i'm having a problem, the encoder only reads the first and fourth quadrant I checked with your code this, I don't know what is I tried with other 2 and had the same problem did you had a similar problem?

    • @CuriousScientist
      @CuriousScientist  2 года назад

      Hi! I don't really understand what you mean. It should detect all the 4 quadrants. As you see it in the code, there is a commented section right after checking the current quadrant position and if you uncomment them, you can print the detected quadrant on the serial terminal. I am pretty sure that you should see all 4 quadrants.

    • @unknownblueblue
      @unknownblueblue 2 года назад

      @@CuriousScientist Yes I uncommented this part of the code and it's only detecting 2 quadrants

    • @CuriousScientist
      @CuriousScientist  2 года назад

      Hm, that is very interesting. How do the corrected angle readings look like?

    • @unknownblueblue
      @unknownblueblue 2 года назад

      @@CuriousScientist it reads like 700 to 1000 and goes back to 700 (it's just an example it's not the real numbers) and the quadrant number sometimes change sometimes when I turn the magnet with the encoder off

  • @isidoromaich7226
    @isidoromaich7226 2 года назад

    Seasons greetings!

  • @Nobody-Nowhere
    @Nobody-Nowhere 2 года назад

    What is the max speed AS5600 is able to track the movement?

    • @CuriousScientist
      @CuriousScientist  2 года назад

      It depends on many things. Mainly it depends on the MCU you are planning to use and your intention on what you are planning to do with the data. If you want to send it to the serial port or want to show it on a display, that could be a bottleneck due to the way those libraries are written. They often block and if the blocking takes too much time as compared to the movement time, you might lose some information. Polling the AS5600 does not take too long, so the maximum speed will depend on the operation you do on the data obtained.

    • @Nobody-Nowhere
      @Nobody-Nowhere Год назад

      @@CuriousScientist Well got it to work at least at 4000rpm on ESP32, should be able to do more. Im using RTOS so blocking is not an issue, as i can run several loops on 2 different cores.

    • @CuriousScientist
      @CuriousScientist  Год назад

      Hey! Thank you for coming back and sharing your experience. It is great to hear that you managed to reach over 4000 RPM. This is great news also because it is sure that we can cover the RPM range of the typical stepper motors and we can also cover some of the typical DC motors.

  • @unknownblueblue
    @unknownblueblue 2 года назад

    it's possible to make a closed loop with a pid control?

    • @CuriousScientist
      @CuriousScientist  2 года назад

      Of course. But depending on the application it might be an overkill.

    • @unknownblueblue
      @unknownblueblue 2 года назад

      @@CuriousScientist I'm going to use in a robot arm, but I don't know how to control it yet, and thanks for the videos :)

    • @CuriousScientist
      @CuriousScientist  2 года назад

      I have a video on PID controlling DC motors. Check my channel, you'll find it.

    • @unknownblueblue
      @unknownblueblue 2 года назад +1

      @@CuriousScientist i'll take a look thanks

  • @OGMann
    @OGMann Год назад

    Sent you a contact via web interface. Drop a line.

    • @CuriousScientist
      @CuriousScientist  Год назад +1

      Acknowledged! By the way, I read my inbox, and there's no need to let me know that you sent a message. I read everything when I have time. :)

  • @HolyDreamer
    @HolyDreamer 3 месяца назад

    you cant measure speed and position at the same time. sorry. at least let Heisenberg rest in his grave.

    • @CuriousScientist
      @CuriousScientist  3 месяца назад

      Thank you for your invaluable contribution to the subject!

    • @HolyDreamer
      @HolyDreamer 3 месяца назад

      @@CuriousScientist did you just call the uncertainty principle invaluable? If you want to be taken seriously, first of all, you can't disrespect the uncertainty principle under the name 'Curious Scientist,' or you need to develop a better sense of humor. Good luck.

    • @CuriousScientist
      @CuriousScientist  3 месяца назад

      You need the sense of humor, not me. And, you also need to look up the meaning of the word in the Cambridge dictionary. 🙃

    • @HolyDreamer
      @HolyDreamer 3 месяца назад +1

      @@CuriousScientist again...

    • @CuriousScientist
      @CuriousScientist  3 месяца назад

      I was reading the comment with a high speed, so I could not see _where_ the joke was located. 😄