AS5600 Magnetic encoder - A practical example

Поділитися
Вставка
  • Опубліковано 6 бер 2021
  • In this video, I continue discovering the AS5600 magnetic position encoder and its applicability in different scenarios. I rotated a stepper motor by providing pulses with a CNC handwheel and measured the angular displacement of the shaft. I wanted to compare the number of "theoretical steps" with the actually done steps and it seems that they are the same. Of course, I did not go too fast and there was no load on the shaft. Nevertheless, it seems that the motor did not skip any steps and it behaved according to the microstepping settings.
    Please don't forget to subscribe!
    Schematics and source code: curiousscientist.tech/blog/as...
    If you want to support my work, please consider buying the parts using my affiliate links:
    curiousscientist.tech/tools
  • Наука та технологія

КОМЕНТАРІ • 61

  • @andreafavero71
    @andreafavero71 Рік тому

    Hi, thank you for the extensive explanation, really appreciated. I'm going to use the magnetic encoder, and You've been of a great help.
    As little consideration, the full rotation could be divided in three equal parts parts of 120 degrees instead of quadrants: The purpose to detect turns increament/decrement could be fulfilled with a larger time period (+33%, by considering the same rotational speed).

    • @CuriousScientist
      @CuriousScientist  Рік тому

      Hi! The full rotation could also be divided into two parts or I could even only look for the 355° → 0° transition, however, I want to see the direction changes a bit more often and that's why I divided the full circle into 4 sectors. I do not need such a high speed, but I need precision.

    • @andreafavero71
      @andreafavero71 Рік тому +1

      ​@@CuriousScientist dividing the full rotation in at least 3 parts, each transition is direction dependant ... not with 2.
      I've just ordered the AS5600 boards, I'll soon experiment the method you've well explained.

  • @tinayoga8844
    @tinayoga8844 3 роки тому +1

    I got my AS5600 boards today. I will be using them on my CNC router, but I have not built it yet. So I need to decide what little project to try these on.

  • @khanhnguyen2771
    @khanhnguyen2771 2 роки тому +1

    Thanks you!

  • @julesd
    @julesd 2 роки тому +1

    This is amazing. I now have the same ESP32 board, an as56000 and a 17hs4023... and i would love to build one... can you possible provide details of the 3d printed part you used to mount the sensor to the stepper ? Much appreciated!

    • @CuriousScientist
      @CuriousScientist  2 роки тому +1

      Hi! Have you ever looked around on my website? I am pretty sure that you'll find it there under one of the AS5600-related pages. ;)

  • @HorstFederau
    @HorstFederau 2 роки тому +2

    Thank you for this wonderful video. It got me inspired to rebuild an old airplane instrument using the AS5600 to read heading inputs when the pilot dials a knob. I do have a question though. My gauge has multiple knobs to adjust angles and headings. I can see from the manual that the I2C address is 0x36 (which is what you use in your code). Do you know if that address is static? How would you go about using 3 or 4 of these units connected to the same Arduino (since they all have the same I2C address)? Is it even possible...

    • @CuriousScientist
      @CuriousScientist  2 роки тому

      Hi and thank you!
      Yes, it is possible! The answer for your question can be found in this video: ua-cam.com/video/IZ0FyiMYT48/v-deo.html
      I use 2 AS5600 with the same i2c address "simultaneously " by using an i2c multiplexer. Follow the video carefully and you can learn how to do it.

    • @HorstFederau
      @HorstFederau 2 роки тому +1

      @@CuriousScientist Thank you so much :)

    • @CuriousScientist
      @CuriousScientist  2 роки тому

      You're welcome! Cheers!

  • @darkfibres
    @darkfibres 2 роки тому +2

    The STM32F103C8/BT6 has 4 timers that can do all the QEI processing for you in hardware, the count is in a register. It takes some setting up. Perhaps this can be done in 'arduino' c++, though I've only used it in plain C. BTW: great channel, thanks for the videos!

    • @CuriousScientist
      @CuriousScientist  2 роки тому

      Thanks! Yes, I am aware of those timers, I extensively use them in one of my other project (TCD1304 CCD). It can be done in Arduino as well, however, I am not that experienced with it in Arduino. (For "deeper" STM32 programming, I used the CubeIDE with its HAL library)

    • @darkfibres
      @darkfibres 2 роки тому

      @@CuriousScientist Arduino, though easy, abstracts away a lot of things (like timers). I hadn't seen your videos from more complex projects like the linear ccd yet. Keep up the interesting work!

  • @mesquitamk1681
    @mesquitamk1681 2 роки тому

    you have a video of how to use this project at CNC

  • @itanc1
    @itanc1 2 роки тому

    hi dood, nice films! spent the whole evening watching them ! im hoping you can help me with a problem i have? i have purchased 4 AS5600 pcbs with magnets but i should have bought incremental encoders. is there a way to use the AS5600 to generate A quadrature output similar to the A B output from your cnc handwheel?
    cheers
    tanc

    • @CuriousScientist
      @CuriousScientist  2 роки тому

      Hi! You can toggle two output pins whenever there is a change in the angle. Alternatively, the AS56000 also generates PWM, maybe you can use that as well. I would just write a code that detects let's say every 1° change and then creates a pulse, or two in your case. You also have to pay attention to the directions.

  • @7alfatech860
    @7alfatech860 3 роки тому +2

    A question about the encoder. You get a 1 bit +/- result. Is the magnetic encoder error cumulative? If it is not, then one can just round up the encoder result to the nearest degree, and it the results on the OLED will match the wheel perfectly.

    • @CuriousScientist
      @CuriousScientist  3 роки тому +3

      Hi! As I noticed, the ±1 bit error is not cumulative, it is just the uncertainty of the current position. As the position of the magnet is reset at every turn, the error cannot accumulate. This error comes maybe also from the fact that the magnet is not perfectly centered over the AS5600 chip. Rounding and/or averaging would solve this, I believe. Since one bit is about 0.088 degrees, we have a lot of freedom in the rounding. For me, even ±1° would be okay, I just wanted to show the maximum capabilities of the device. To put the 1° uncertainty into perspective: If I would use a 8 mm pitch lead screw and miss 1° from its rotation, I would only have 22.2 um uncertainty of linear displacement. That is pretty OK for my not too precise applications.

  • @Flyrip
    @Flyrip 3 роки тому +1

    Thanks for really nice and informative videos! How would you go about to combine a mpg handwheel and start/stop or fwd/rev in a control panel with an arduino? I am building a control panel for a stepper motor power feed :)

    • @CuriousScientist
      @CuriousScientist  3 роки тому +1

      Thanks! Both for start/stop and forward/reverse, I would use a 3-way toggle switch, then just continuously poll their state.

    • @Flyrip
      @Flyrip 3 роки тому +1

      @@CuriousScientist Thanks 😊

  • @micultimy91
    @micultimy91 3 роки тому +1

    Have you thought about using FreeRTOS on the STM32? I mean, you really need a lagless experience in order to receive both commands from MPG and AS5600 and then send perfectly timed impulses to the stepper driver. Also, use PID if you really want a proper closed loop experience. Thanks for sharing!

    • @CuriousScientist
      @CuriousScientist  3 роки тому +2

      Hi! I haven't yet thought about this. For publishing purposes I prefer to use stm32duino because even with this simple coding people have problems. I probably won't use freertos for my videos in the near future.

    • @caffeinatedinsanity2324
      @caffeinatedinsanity2324 Рік тому +1

      I don't think using a PID for a stepper motor would be very useful since stepper motors usually move at fixed speed (although it is certainly feasable). But a closed loop control with feedback is definitely worth exploring

  • @africano313
    @africano313 2 роки тому +1

    I found the solution, the AS5600's DIR pin must be grounded. Otherwise the readings are erratic.
    thank you for your attention

  • @nikunjpatel8616
    @nikunjpatel8616 2 роки тому +1

    This is wonderful Project. i want to know how to set encoder position zero pro-grammatically ? suppose i read degree using magnetic encoder like 265 and now how to set zero this position?

    • @CuriousScientist
      @CuriousScientist  2 роки тому +1

      Thanks! If you want to burn in a zero position, you should read the manual. But, it is really easy to quickly tare the position upon the power up (like I do it), so I don't really see the need of burning in a zero position.

  • @livingrainman
    @livingrainman 8 місяців тому +1

    Hi! I have managed to get your setup working on a nano clone with a quadrature encoder. The encoder has 600 pulses per revolution. The code seems to work quite well after i accounted for the difference in the number of pulses, but I am having trouble with the board crashing when i change the direction of the encoder in rapid succession. Do you think implementing the code on a faster microcontroller (teensy 4.1 @600MHZ) would solve the problem? Thanks!

    • @CuriousScientist
      @CuriousScientist  8 місяців тому

      Hi! Did you copy the code as-is or you made some modifications to it? I never encountered issues when changing directions, so at this moment I unfortunately have no idea. Faster microcontroller is always a good idea, especially if you generate a lot of interrupts (or pin polling) quickly. Also, you might want to look at other displays or libraries for this display because I have noticed that it can mess with the interrupts and timings sometimes. If you have other type of displays, you should try to use it before switching to a more expensive Teensy.

  • @manusholm3536
    @manusholm3536 3 роки тому +1

    the error can also be in the computing of the encoders signal in the arduino. i had that with an uno, when i ran same encoder on a mega the error became almost nothing. want to try a faster micro controller like teensy 4.1

    • @CuriousScientist
      @CuriousScientist  3 роки тому

      I actually bought a few Teensy 4.0 recently. I will test it later!

  • @mesquitamk1681
    @mesquitamk1681 2 роки тому

    very cool your work. friend I will use your project on my CNH. I just have a doubt which pin of my controller board should I connect to stm32. for calibration

    • @CuriousScientist
      @CuriousScientist  2 роки тому +1

      Thanks! I published the wiring on my website.

    • @mesquitamk1681
      @mesquitamk1681 2 роки тому

      ​@@CuriousScientist OK. OK. I understand very little. the question is what is the name of the pins that come from my board to connect to pins A and B of your project... example pin-A connects to pin-B pin-C connects to pin-D... I don't know the name of the pinout that comes from the board for your project (((thank you in advance)

    • @mesquitamk1681
      @mesquitamk1681 2 роки тому

      @@CuriousScientist I don't know the name of the pins on my board that I should connect pins A-B of your project

    • @CuriousScientist
      @CuriousScientist  2 роки тому

      As I said, all the information can be found on my website! Everything is written there and shown on the schematics.

  • @africano313
    @africano313 2 роки тому

    Me and friends like your projects.
    I would like help with the AS5600, I placed the magnet on the axis of a NEMA17 and installed the AS5600 on the back. It turns out that at some angular points, the reading is jumping in two measurements alternately. Not changing the angular position, even disconnecting the power from the system and then re-feeding it, the same thing happens.
    If it's at a single-reading angle, it returns a single-reading, which seems okay to me.
    Did it have to do with a problem in defining the quadrant or something similar?

    • @CuriousScientist
      @CuriousScientist  2 роки тому

      Hi! I do not exactly understand you issue. Is it that the number is jumping with that +/- 0.0878° (1 bit) value or something else? It can be also due to the bad alignment of the magnet and the sensor, or just simply a digital noise. You will never get the same values with continuous reading, you have to average it. Or round the numbers, so the uncertainty is "buried" in the rounding.

    • @africano313
      @africano313 2 роки тому

      Total angle:
      22.50
      Deg angle:
      24.96
      Corrected angle:
      0.00
      Quadrant:
      1
      Turns:
      0
      Total angle:
      0.00
      Deg angle:
      47.46
      Corrected angle:
      22.50
      Quadrant:
      1
      Turns:
      0
      Total angle:
      22.50
      Deg angle:
      24.96
      Corrected angle:
      0.00
      Quadrant:
      1
      Turns:
      0
      Total angle:
      0.00
      Deg angle:
      47.46
      Corrected angle:
      22.50
      Quadrant:
      1
      Turns:
      0
      Total angle:
      22.50
      Look 22.50 0.00 22.50 0.00 ........This sequence occurs at some points of 360 degrees and at most angles it is correct.
      Even by turning off the power to all components and turning it back on again the error points remain fixed despite different values of course

    • @CuriousScientist
      @CuriousScientist  2 роки тому

      Did you modify anything in my code? I have never encountered this issue, but I will look into it later.

  • @marklimbrick
    @marklimbrick 6 місяців тому +1

    Apart from missed steps checking, the use of shaft encoding can be closed loop with micro stepping?
    There is no load on your motor. Changing current drive pwm to hold or achieve accurate position in microsteps would be an interesting demo. I would have to write my own code.
    PID loop with no overshoot. Telescope astrophotography drive.
    I want to use big 5 phase micro stepping but even look up table the 64 microsteps have varying torque.

    • @CuriousScientist
      @CuriousScientist  6 місяців тому

      Sure, you can PID control a stepper motor, there are some projects out there already. However, I would say that it is not a typical application, because you usually don't combine PID and stepper motors. If the system is built well (e.g. fitted for the loads and speeds...etc.), then a stepper will basically _always_ go to the position and will _always_ maintain the speed that is prescribed. Just think about 3d printers. They can print for days and their axes can travel kilometers without making any mistakes. Without PID. On the other hand, DC motors are controlled with PID. It is a different principle. For astrophotography, I am 99% sure that you don't need PID if you use stepper motors.

  • @irrealix
    @irrealix 9 місяців тому +1

    Thank you for this video. I have bought three brand new as5600, printed mount for a magnet, I have same display and use your Arduino code and also try default sketches from as5600 library with same glitchy results: the angle is not stable. and I cant reach 360 degree. Dir pin is connected. What can be wrong?

    • @CuriousScientist
      @CuriousScientist  9 місяців тому

      Hi! Is the distance between the magnet and the sensor sufficient? Do you use a proper magnet?

    • @irrealix
      @irrealix 9 місяців тому

      @@CuriousScientist I have tried sample AS5600_demo_status with as5600.detectMagnet() and as5600.magnetTooStrong() and as5600.magnetTooWeak() values printed to serial. Experimentally found the best distance is about 0.5 mm. I have used the magnet included in package. same as yours.

    • @CuriousScientist
      @CuriousScientist  9 місяців тому

      If you did _exactly_ the same things that I did, then you should not experience issues. As you can see it in my demonstration, everything goes well. Are you sure that you replicated the exact wiring? Do you use the same microcontroller? Have you checked the voltages? If you use a breadboard, make sure that it is a proper one. I sometimes get questions from others and after hours of exchanging information, it turns out that they used a garbage breadboard and some pins were not contacting properly.

  • @WarlockBE
    @WarlockBE 3 місяці тому

    Hi. I looked at you source code and you can optimize it to get the quadrant value.
    You can replace the function checkQuadrant() with 1 line.
    quadrantNumber = floor(correctedAngle / 90) + 1
    This will give you 1 2 3 or 4 ;-)

    • @CuriousScientist
      @CuriousScientist  3 місяці тому

      Hi! Oh wow, thanks! I look into this as several people suggested that my code around the quadrants could be improved. It is nice to receive feedback like this, thanks!

  • @noanyobiseniss7462
    @noanyobiseniss7462 2 місяці тому +1

    Comment for the Algo.

  • @user-tj5nk7lb8l
    @user-tj5nk7lb8l 10 місяців тому

    WOW 09:33 you dont get exact pulses from your handwheel - thats nasty (in the cnc world anyway). Are you saying its an inherent +/- 1 bit uncertainty (or more?) that needs to be rounded in s/w?. I cant have my reading jittering (like a dvm does - I often switch to my old Avo model 8 the analog display often tells you so much more)

    • @CuriousScientist
      @CuriousScientist  10 місяців тому +1

      I think that probably someone with better programming skills could make the counting to be spot on. I was using the simplest (and maybe lousiest) way of counting the pulses and since I also updated the display in parallel and so on, it could be that the missed steps are due to a badly written code. I think it is just a matter of signal conditioning and a better a better code than mine. Some day, I might revisit this topic again so I can see if I could write a better, more accurate code.

  • @mesquitamk1681
    @mesquitamk1681 2 роки тому

    friend in my life only has arduino will it work because arduino only has 1 SDA and 1 SCL