STM32 encoder interface mode

Publisher:eta17Latest update time:2019-01-29 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Encoder

 Write the picture description here 

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. 

Write the picture description here

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: 

 

Write the picture description here 
Write the picture description here

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. }


Keywords:STM32 Reference address:STM32 encoder interface mode

Previous article:Detailed explanation of two methods of STM32 PWM capture
Next article:STM32 encoder development setup notes

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号