logo elektroda
logo elektroda
X
logo elektroda

Arduino Encoder Programming: Troubleshooting Missed Pulses with Profi-360-06-AABBZZ Encoder

TraCerT 4248 14
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 16448678
    TraCerT
    Level 6  
    Hello,

    I decided to test the encoder I purchased today. . After connecting the encoder to it, the arduino reads the pulses, but has a tendency to miss them. What could be causing them?

    The encoder used for work: http://sklep.cncprofi.com/enkoder-profi-360-06-aabbzz.html
    Connection: Straight to Arduino Vcc-5V, Gnd-Gnd, Pin A to Pin 2 and Pin B to Pin 3 (with 300 Ohm resistors).
    Code: from the arduino playground website
    Code: C / C++
    Log in, to see the code


    Greetings,
    TraCerT
  • ADVERTISEMENT
  • Helpful post
    #2 16449275
    Slawek K.
    Level 35  
    Resistors should be 10k.
    Download the Rotary library, you have ready and precise encoder support, either in interrupt or normally, of your choice.

    Greetings
  • #3 16449488
    tmf
    VIP Meritorious for electroda.pl
    @TraCerT It's hard for him not to miss pulses if you don't check the encoder line status all the time the serial is sending data, and these can be milliseconds. In this case, the encoder operation should be based on interrupts.
  • ADVERTISEMENT
  • #5 16449578
    tmf
    VIP Meritorious for electroda.pl
    @DarkMajster The same error, and even worse - the time-consuming function of sending data via UART you put in interrupts. Additionally, the comparison of result == DIR_NONE does not make sense, since the {} clause is empty.
    It is also worth adding that the solution which is to connect the encoder outputs to the pin interrupts is ok in this case, but only because we have an optical encoder that does not generate vibrations. It wouldn't be a good solution for a mechanical encoder.
  • ADVERTISEMENT
  • #6 16449587
    Slawek K.
    Level 35  
    I can see that my colleague DarkMajster put in an example from the library I recommend, but I recommend the pooling mode because it is not always possible to use interrupt pins that are not there too much, and the service in this mode also works very well on "regular" pins. Of course, provided that you do not pack your code with delays.

    Greetings
  • #7 16449600
    tmf
    VIP Meritorious for electroda.pl
    rs6000 wrote:
    I can see that my colleague DarkMajster put in an example from the library I recommend, but I recommend the pooling mode because it is not always possible to use interrupt pins that are not there too much, and the service in this mode also works very well on "regular" pins. Of course, provided that you do not pack your code with delays.

    Greetings


    Pooling is the worst possible solution. Due to the unpredictability of the digestion time of the main loop of the program, you will miss pulses from the encoder. Normally the encoder is handled on the timer interrupt - just fire it from at least 2xf the encoder to recreate its signal. As a result, we have a constant, predictable CPU load, without losing pulses.
  • ADVERTISEMENT
  • #8 16449734
    DarkMajster
    Level 11  
    tmf wrote:
    @DarkMajster The same error, and even worse - the time-consuming function of sending data via UART you put in interrupts. Additionally, the comparison of result == DIR_NONE does not make sense, since the {} clause is empty.
    It is also worth adding that the solution which is to connect the encoder outputs to the pin interrupts is ok in this case, but only because we have an optical encoder that does not generate vibrations. It wouldn't be a good solution for a mechanical encoder.


    Of course I did, I just put an example from the library
  • #9 16449995
    TraCerT
    Level 6  
    Hello and thanks for any tips

    Overall, I changed the resistance to 10k Ohm and wrote a program in interrupts. I don't really need serial functions, because I check the angle with the stabilization of the inverse pendulum (so you can see that when it's around 180, the motors should stand still). Unfortunately, this happens only at the beginning for about 2-3 seconds, and then the stabilization is not assumed where it is needed (e.g. the required stabilization angle of 180 is after some time at the angle of 175). It turns out that the encoder is still losing steps. So I would like to ask for advice (preferably step by step as you can describe, because at the moment I am green: /). I don't know if this error exists in the program, or maybe in some settings or maybe it just should be like that - hysteresis?

    Here I will present all the code used to stabilize the pendulum
    Code: C / C++
    Log in, to see the code


    greetings
    TraCerT
  • #10 16450037
    tmf
    VIP Meritorious for electroda.pl
    First of all, what I wrote to you before - the encoder encodes the position in the Gray code. So in order to get information about the change of the encoder position, you have to decode the signal. Needless to say, you are doing it wrong. Another thing - you need to atomically access the variable position0encoder - volatile does not do everything. Access to this variable from the level of the main loop of the program must be included in atomic blocks (of course as short as possible, so as not to miss interrupts from the encoder).
  • #11 16450054
    TraCerT
    Level 6  
    In an incremental encoder there is a position encoded in Gray code ???
  • #12 16450072
    tmf
    VIP Meritorious for electroda.pl
    TraCerT wrote:
    In an incremental encoder there is a position encoded in Gray code ???


    How else would the information about the direction of rotation be sent? You have signals A and B that need to be decoded. In yours you also have a Z signal informing about the absolute position of the encoder shaft, which would also be worth using.
  • Helpful post
    #13 16450081
    Eagle
    Level 24  
    Quote:
    In an incremental encoder there is a position encoded in Gray code ???


    Probably the question was that the position is not coded, but the increment.
  • #14 16450089
    TraCerT
    Level 6  
    tmf wrote:
    TraCerT wrote:
    In an incremental encoder there is a position encoded in Gray code ???


    How else would the information about the direction of rotation be sent? You have signals A and B that need to be decoded. In yours you also have a Z signal informing about the absolute position of the encoder shaft, which would also be worth using.


    Then I have to read a bit about decoding ... And is the direct connection (Vcc-5V, Gnd-Gnd, Pins 2 and 4 respectively with A and B with 10k Ohm resistors) correct, or can it have an influence on it?
  • Helpful post
    #15 16450250
    tmf
    VIP Meritorious for electroda.pl
    This method of connection is OK. However, the encoder used offers differential signals, so in an environment with mega noises it can also be used.

Topic summary

The discussion revolves around troubleshooting missed pulses in an Arduino setup using the Profi-360-06-AABBZZ encoder. The user initially connected the encoder directly to the Arduino but experienced missed pulses. Suggestions included using 10k Ohm resistors instead of 300 Ohm, implementing the Rotary library for better encoder support, and utilizing interrupts for more reliable pulse detection. The importance of avoiding delays in the main loop and ensuring atomic access to encoder variables was emphasized. The user later confirmed changes made to the resistor value and code structure but continued to face issues with stabilization in their application. The conversation also touched on the necessity of decoding signals from the encoder, particularly regarding the Gray code and the use of differential signals for noise reduction.
Summary generated by the language model.
ADVERTISEMENT