1. Encoder
Figure 1 Encoder schematic diagram
Figure 1 is a schematic diagram of the encoder. In the middle is a code disk with a grating. When light passes through the grating, the receiving tube receives a high level. If light does not pass through, it receives a low level. When the motor rotates one circle, the number of gratings on the code disk is equal to the number of high levels received by the receiving tube.
2.stm32 encoder interface mode (register)
The encoder interface mode of STM32 is described in detail in the STM32 Chinese reference manual.
Figure 2 STM chip encoder interface mode description
The following figure is an example of a counter operation, showing the generation and direction control of the count signal. It also shows how input jitter is suppressed when both edges are selected; jitter can occur when the sensor is positioned close to a transition point. In this example, we assume the following configuration:
Figure 3 Example of counter operation in encoder mode
When the TI 1 waveform precedes the TI 2 waveform by 90°, the counter increases by 1 each time the edge changes (addition and subtraction can be set by registers). It can be seen that one raster is counted 4 times. When the TI 1 waveform lags behind the TI 2 waveform by 90°, the counter decreases by 1 each time an edge changes.
1. //TIM2_Encoder_Init,Tim2_CH1(PA0);Tim2_CH2(PA1)
2. //arr: automatically reload value 0XFFFF
3. //psc: clock pre-division number, no division
4. void TIM2_Encoder_Init(u16 arr,u16 psc)
5. {
6. RCC->APB1ENR|=1<<0; //TIM2 clock enable
7. RCC->APB2ENR|=1<<2; //Enable PORTA clock
8.
9. GPIOA->CRL&=0XFFFFFF00; //PA0, PA1 clear previous settings
10. GPIOA->CRL|=0X00000044; //PA0, PA1 floating input
11.
12. TIM2->ARR=arr; //Set the counter to automatically reload value
13. TIM2->PSC=psc; //Prescaler
14.
15. TIM2->CCMR1 |= 1<<0; //Input mode, IC1FP1 is mapped to TI1
16. TIM2->CCMR1 |= 1<<8; //Input mode, IC2FP2 is mapped to TI2
17. TIM2->CCER |= 0<<1; //IC1 does not reverse
18. TIM2->CCER |= 0<<5; //IC2 does not reverse
19. TIM2->SMCR |= 3<<0; //All inputs are valid on the rising or falling edge
20. TIM2->CR1 |= 1<<0; //Enable counter
21. }
Previous article:Detailed explanation of two methods of STM32 PWM capture
Next article:STM32 encoder development setup notes
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Tuya Sandwich Wi-Fi & BLE SoC NANO Main Control Board WBRU Unboxing Review
- TMS320C674x Reverse Engineering
- Analysis of Typical Anti-Reverse Connection Circuits for Automotive Electronics
- Consulting employment
- [Runhe Neptune Review] Four network communications
- [RISC-V MCU CH32V103 Review] Light up the second LED
- EEWORLD University Hall----What can universal fast charging bring?
- Complete learning manual for using RT-Thread on RISC-V (based on Longan development board)
- How does Tbox protect itself to ensure data security? What good methods can you recommend?
- The amount of heat required to heat water