In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "what is the interface mode of arduino encoder". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Encoder classification:
According to the working principle: photoelectric type, magnetoelectric type and contact brush type
The engraving methods of the code disk: incremental and absolute
This is from the Internet to see a profile, only contact with the Arduino encoder, the other has not been used yet.
The encoder of Arduino is incremental. It has a total of five wires.
They are "CLK", "DT", "SW", "+" and "GND".
"+", "GND":
Needless to say, VCC and GND can be connected to the VCC and GND of the board.
"SW":
Arduino said that when the knob rotates once, the foot will emit a level jump signal, which is equivalent to the "Z" signal often said by rotary encoders. In fact, the one I bought is just a switch, that is, the part of the knob can be pressed (similar to the volume adjustment button on a car), and the interface will produce a falling edge. Then MCU will do the relevant processing.
"CLK", "DT":
The screen printing names displayed on this module are these two. I don't understand why it is this screen printing. It should actually correspond to the "A" and "B" signals commonly used by encoders. The occurrence of these two signals is as follows:
Positive rotation
As in the figure above, when the knob starts to rotate forward, "A" changes from low level to high level, and "B" remains the same; when the knob rotates to the predetermined position, "A" remains high, and "B" then jumps from low level to high level. In other words, when spinning, "A" always starts with "B" to change the level.
Reverse rotation
Reverse rotation: in contrast to positive rotation, "B" always begins with "A" level change.
So here, screen printing the two wires as "CLK" and "DT" makes me a little confused. Also did not find the relevant information, first temporarily release, the next time there is a practical application, we will know why.
According to the law of forward rotation and reverse rotation, the rotation direction of the encoder can be determined and the rotation angle can be calculated according to the output information of the encoder.
Connect "CLk" and "DT" to any IO port with external interrupt of MCU, respectively, and handle it as follows:
The two IO ports are configured as two-sided external interrupts.
When one of the IO ports detects the rising edge or the falling edge, the level state of the other IO port is detected in the interrupt function. Take the positive spin as an example, in the positive rotation, the first rising edge of "A" causes interruption, and the level state of "A" and "B" is "10". Then, the rising edge of "B" is detected and the level state of "A" and "B" is 11.
If it turns positive all the time, the level state of "A" and "B" is "10-11-01-00-10 -."
If you keep reversing, the level states of "A" and "B" are "01-11-10-00-01 -."
Based on this, the rotation direction of the encoder can be determined, and after the simultaneous jump of "A" and "B" is completed, the rotation count of the encoder can be increased or decreased according to the rotation direction of the encoder.
The above is to use the external interrupt mode to deal with the output information of the rotary encoder, of course, this article uses the interface mode of the STM32 timer, so it will not be judged by the above method. So how does the interface mode of the timer count the rotary encoder?
In fact, the principle is the same: the "CLK (A)" and "DT (B)" pins of the rotary encoder are connected to the channel of the TIMx, and the corresponding channel pins are configured as the encoder interface mode to enable counting, and then the value of the STM32 will be added or subtracted on the hardware according to the above rules.
The "PB6 (TIM4_CH1)" and "PB7 (TIM4_CH2)" of STM32F103 are received in this lab. The specific configurations are as follows:
This is the end of the content of "what is the interface mode of arduino encoder". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.