2281 views|5 replies

1w

Posts

16

Resources
The OP
 

[Review of Arteli Development Board AT32F421] 6. Further study of EC11 encoder [Copy link]

 

Last time, I succeeded with interrupts, but this time I succeeded with reading the level. Last time I thought interrupts were the best, but this time I think level is better, because after all, there is no need for interrupts.

This time it’s the same picture:

It can be seen that when A is low, if B is also low, it rotates clockwise.

If B is high when A is low, it rotates counterclockwise.

The reason I failed to adjust it last time was because I added a 330 ohm current limiting resistor, which interfered with the shape of the wave.

I connected A and B to A8 and A9 respectively. The program is as follows:

void EC11_Display()
{

  
   uint8_t i;  
	
	EC11_Flag = 0;
  Left_Flag = 0;
  Right_Flag = 0;	
	
	if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pins_8) == 0)//开始检测是否旋转了开关
                {
                        Delay_ms(1);//消除抖动
                        if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pins_8) == 0) //确实是旋转了,进行正反转判断
                        {
                                if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pins_9) == 0)//正转,进行正转处理
                                {
                                        EC11_Value++;//为了使LED正向递增
																	     
                                }
                                else if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pins_9) == 1)//反转,进行反转处理
                                {
                                        EC11_Value--;//为了使LED反向递减
//																	      printf("This is %d\n\t",EC11_Value);
//																	      Delay_ms(200);//延时等待
                                }
                        }
                        while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pins_8) == 0)//等待开关A端复位(断开),防止出现乱加减的现象
                        {
                                Delay_ms(20);//延时等待
                        }
	
	
					}
	

	
	
}

The results of the operation are as follows:

This post is from Domestic Chip Exchange

Latest reply

Thanks for sharing, looking forward to the follow-up!   Details Published on 2021-4-25 17:13

赞赏

1

查看全部赞赏

Personal signaturehttp://shop34182318.taobao.com/
https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr
 
 

6593

Posts

0

Resources
2
 

The encoder turns left and right, and uses a timer to detect the status and how often it is detected

The author's review progress is very fast and it is already the sixth article

This post is from Domestic Chip Exchange

Comments

A timer is definitely fine, I think the faster the better, for example once every 2MS, because the user's rotation speed is not fixed.  Details Published on 2021-4-26 08:17
 
 
 

1942

Posts

2

Resources
3
 

Not bad! The progress is very fast!

This post is from Domestic Chip Exchange
 
 
 

1412

Posts

3

Resources
4
 
The review is very detailed, come on
This post is from Domestic Chip Exchange
 
 
 

7462

Posts

2

Resources
5
 

Thanks for sharing, looking forward to the follow-up!

This post is from Domestic Chip Exchange
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

1w

Posts

16

Resources
6
 
Jacktang posted on 2021-4-23 22:34 The encoder has the function of turning left and right. The timer is used to detect the status. How long does it take to detect it? The author's evaluation progress is very fast and it is already the sixth article

A timer is definitely fine, I think the faster the better, for example once every 2MS, because the user's rotation speed is not fixed.

This post is from Domestic Chip Exchange
Personal signaturehttp://shop34182318.taobao.com/
https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list