884 views|3 replies

194

Posts

0

Resources
The OP
 

The serial port assistant sends PWM light source commands, but the light source displays strangely? [Copy link]

I use the serial assistant to send a command to light up the PWM light source with a frequency of 20Khz. When I send the command, the brightness changes from 0-6. From 7 to 99, the brightness remains the same. Then when I send 100, the brightness becomes lower. What is the reason for this?

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	uint8_t ucTemp;

	if(huart ->Instance == USART1)
    {
				ucTemp = aRxBuffer;
				Uart1_RxBuff[Uart1_Rx_Cnt++] = ucTemp;
				if(Uart1_RxBuff[0]!=0xa3)
					Uart1_Rx_Cnt=0;
				if((Uart1_Rx_Cnt==2) && (Uart1_RxBuff[1]!=0xb3))
					Uart1_Rx_Cnt=0;
				if(Uart1_Rx_Cnt==8)
				{
					if(data_test(Uart1_RxBuff))
					{

						/********************
						üDêyY
						*********************/
						
						turn = Uart1_RxBuff[2];
						pwm = Uart1_RxBuff[3];

						
						
						if(turn == 0)
						{
								pwm_light(0);
						}
						else if(turn == 1)
						{
								pwm_light( pwm);
						}
	
					}
					Uart1_Rx_Cnt = 0;
				}
				
				HAL_UART_Receive_IT(&huart1,&aRxBuffer,1);
    }
}
void  pwm_light(uint8_t pwm)
{

   __HAL_TIM_SetCompare(&htim2,TIM_CHANNEL_1, pwm);

}


99.jpg (111.18 KB, downloads: 0)

99.jpg

100.jpg (137.57 KB, downloads: 0)

100.jpg

串口助手.png (9.46 KB, downloads: 0)

串口助手.png
This post is from Programming Basics

Latest reply

There may be a problem with the duty cycle setting of the PWM controller, resulting in no change in the duty cycle at certain brightness values; or there may be a problem with the logic of the control software, resulting in the inability to correctly control the PWM output at certain brightness values   Details Published on 2024-9-11 12:03
 

6027

Posts

6

Resources
2
 

This depends on whether the duty cycle and brightness control are linear. There are many such examples. Test it with a fixed duty cycle.

This post is from Programming Basics
 
Personal signature

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 
 

288

Posts

0

Resources
3
 

There may be a problem with the duty cycle setting of the PWM controller, resulting in no change in the duty cycle at certain brightness values; or there may be a problem with the logic of the control software, resulting in the inability to correctly control the PWM output at certain brightness values

This post is from Programming Basics

Comments

The entire receiving serial port logic is only this, and the light source processing logic is PWM_light: __HAL_TIM_SetCompare(&htim2,TIM_CHANNEL_1, pwm);  Details Published on 2024-9-12 08:35
 
 
 

194

Posts

0

Resources
4
 
yangjiaxu posted on 2024-9-11 12:03 There may be a problem with the duty cycle setting of the PWM controller, resulting in no change in the duty cycle at certain brightness values; or there may be a problem with the logic of the control software...

The entire receiving serial port logic is only this, and the light source processing logic is PWM_light: __HAL_TIM_SetCompare(&htim2,TIM_CHANNEL_1, pwm);

This post is from Programming Basics
 
 
 

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