受到这个帖子(http://www.openedv.com/posts/list/40175.htm)的启发,做了一下实验。
测试平台:
STM32Cube IDE Ver1.0.2
NUCLEO-G431(clock:170MHz)
CODE:
1 2 3 4 5 6 7 8 9 10 | /* USER CODE BEGIN PV */ float f_num=9.8; float f_out; double d_num=9.8; double d_out; const float con = 1.0 / 0.0043; float con_f_out; /* USER CODE END PV */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | while (1) { HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); f_out=(1.43f-f_num)/0.0043f+25; f_out=(1.43f-f_num)/0.0043f+25; f_out=(1.43f-f_num)/0.0043f+25; f_out=(1.43f-f_num)/0.0043f+25; f_out=(1.43f-f_num)/0.0043f+25; f_out=(1.43f-f_num)/0.0043f+25; f_out=(1.43f-f_num)/0.0043f+25; f_out=(1.43f-f_num)/0.0043f+25; f_out=(1.43f-f_num)/0.0043f+25; f_out=(1.43f-f_num)/0.0043f+25; HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); f_out=(1.43-f_num)/0.0043+25; f_out=(1.43-f_num)/0.0043+25; f_out=(1.43-f_num)/0.0043+25; f_out=(1.43-f_num)/0.0043+25; f_out=(1.43-f_num)/0.0043+25; f_out=(1.43-f_num)/0.0043+25; f_out=(1.43-f_num)/0.0043+25; f_out=(1.43-f_num)/0.0043+25; f_out=(1.43-f_num)/0.0043+25; f_out=(1.43-f_num)/0.0043+25; HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); d_out=(1.43-d_num)/0.0043+25; d_out=(1.43-d_num)/0.0043+25; d_out=(1.43-d_num)/0.0043+25; d_out=(1.43-d_num)/0.0043+25; d_out=(1.43-d_num)/0.0043+25; d_out=(1.43-d_num)/0.0043+25; d_out=(1.43-d_num)/0.0043+25; d_out=(1.43-d_num)/0.0043+25; d_out=(1.43-d_num)/0.0043+25; d_out=(1.43-d_num)/0.0043+25; HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); con_f_out= (1.43-f_num) * con + 25; con_f_out= (1.43-f_num) * con + 25; con_f_out= (1.43-f_num) * con + 25; con_f_out= (1.43-f_num) * con + 25; con_f_out= (1.43-f_num) * con + 25; con_f_out= (1.43-f_num) * con + 25; con_f_out= (1.43-f_num) * con + 25; con_f_out= (1.43-f_num) * con + 25; con_f_out= (1.43-f_num) * con + 25; con_f_out= (1.43-f_num) * con + 25; HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); con_f_out= (1.43f-f_num) * con + 25; con_f_out= (1.43f-f_num) * con + 25; con_f_out= (1.43f-f_num) * con + 25; con_f_out= (1.43f-f_num) * con + 25; con_f_out= (1.43f-f_num) * con + 25; con_f_out= (1.43f-f_num) * con + 25; con_f_out= (1.43f-f_num) * con + 25; con_f_out= (1.43f-f_num) * con + 25; con_f_out= (1.43f-f_num) * con + 25; con_f_out= (1.43f-f_num) * con + 25; HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET); HAL_Delay(10); HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); |
实际测试效果(右键新标签页打开观看大图)