Browse Source

debug完成, 加入卡尔曼滤波器,减少线对编码器数值的影响

master
htujun 3 years ago
parent
commit
ef1d5bead6
  1. 23
      stm32/HARDWARE/KEY/key.c
  2. 16
      stm32/HARDWARE/KEY/key.h
  3. 29
      stm32/HARDWARE/TIMER/timer.c
  4. BIN
      stm32/OBJ/Template.axf
  5. 19
      stm32/OBJ/Template.build_log.htm
  6. 1937
      stm32/OBJ/Template.hex
  7. 883
      stm32/OBJ/Template.htm
  8. 1212
      stm32/OBJ/Template_Target 1.dep
  9. BIN
      stm32/OBJ/adc.crf
  10. BIN
      stm32/OBJ/adc.o
  11. BIN
      stm32/OBJ/delay.crf
  12. BIN
      stm32/OBJ/delay.o
  13. BIN
      stm32/OBJ/encoder.crf
  14. BIN
      stm32/OBJ/encoder.o
  15. BIN
      stm32/OBJ/key.crf
  16. BIN
      stm32/OBJ/key.o
  17. BIN
      stm32/OBJ/led.crf
  18. BIN
      stm32/OBJ/led.o
  19. BIN
      stm32/OBJ/main.crf
  20. BIN
      stm32/OBJ/main.o
  21. BIN
      stm32/OBJ/misc.crf
  22. BIN
      stm32/OBJ/misc.o
  23. BIN
      stm32/OBJ/motor.crf
  24. BIN
      stm32/OBJ/motor.o
  25. BIN
      stm32/OBJ/oled.crf
  26. BIN
      stm32/OBJ/oled.o
  27. BIN
      stm32/OBJ/stm32f10x_adc.crf
  28. BIN
      stm32/OBJ/stm32f10x_adc.o
  29. BIN
      stm32/OBJ/stm32f10x_gpio.crf
  30. BIN
      stm32/OBJ/stm32f10x_gpio.o
  31. BIN
      stm32/OBJ/stm32f10x_it.crf
  32. BIN
      stm32/OBJ/stm32f10x_it.o
  33. BIN
      stm32/OBJ/stm32f10x_rcc.crf
  34. BIN
      stm32/OBJ/stm32f10x_rcc.o
  35. BIN
      stm32/OBJ/stm32f10x_tim.crf
  36. BIN
      stm32/OBJ/stm32f10x_tim.o
  37. BIN
      stm32/OBJ/stm32f10x_usart.crf
  38. BIN
      stm32/OBJ/stm32f10x_usart.o
  39. BIN
      stm32/OBJ/sys.crf
  40. BIN
      stm32/OBJ/sys.o
  41. BIN
      stm32/OBJ/system_stm32f10x.crf
  42. BIN
      stm32/OBJ/system_stm32f10x.o
  43. BIN
      stm32/OBJ/timer.crf
  44. BIN
      stm32/OBJ/timer.o
  45. BIN
      stm32/OBJ/usart.crf
  46. BIN
      stm32/OBJ/usart.o
  47. BIN
      stm32/OBJ/wifi.crf
  48. BIN
      stm32/OBJ/wifi.o
  49. 44
      stm32/USER/.vscode/c_cpp_properties.json
  50. 8
      stm32/USER/.vscode/keil-assistant.log
  51. 5
      stm32/USER/.vscode/settings.json
  52. 14
      stm32/USER/.vscode/uv4.log
  53. 2
      stm32/USER/.vscode/uv4.log.lock
  54. 980
      stm32/USER/Template.map
  55. 101
      stm32/USER/Template.uvguix.QY
  56. 2
      stm32/USER/Template.uvoptx
  57. 26
      stm32/USER/main.c

23
stm32/HARDWARE/KEY/key.c

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
/*
* @Author: your name
* @Date: 2022-04-17 21:03:46
* @LastEditTime: 2022-04-19 17:45:57
* @LastEditors: lishengyin
* @LastEditTime: 2022-04-19 23:32:17
* @LastEditors: Please set LastEditors
* @Description: koroFileHeader查看配置 : https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @FilePath: \undefinede:\\\MotorPid\stm32\HARDWARE\KEY\key.c
*/
@ -28,18 +28,13 @@ void KEY_Init(void) //IO<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD> @@ -28,18 +28,13 @@ void KEY_Init(void) //IO��ʼ��
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC,ENABLE);//ʹ<EFBFBD><EFBFBD>PORTA,PORTEʱ<EFBFBD><EFBFBD>
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOB,ENABLE);//ʹ<EFBFBD><EFBFBD>PORTA,PORTEʱ<EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_13 | GPIO_Pin_12;//KEY0-KEY1
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //<EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_Init(GPIOC, &GPIO_InitStructure);//<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>GPIOE4,3
//<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD> WK_UP-->GPIOA.0 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //PA0<EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD><EFBFBD>룬Ĭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_Init(GPIOA, &GPIO_InitStructure);//<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>GPIOA.0
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<EFBFBD><EFBFBD><EFBFBD>ذ<EFBFBD><EFBFBD><EFBFBD>ֵ
//mode:0,<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;1,֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
@ -52,14 +47,14 @@ u8 KEY_Scan(u8 mode) @@ -52,14 +47,14 @@ u8 KEY_Scan(u8 mode)
{
static u8 key_up=1;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿ<EFBFBD><EFBFBD><EFBFBD>־
if(mode)key_up=1; //֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(key_up&&(KEY0==0||KEY1==0 || KEY2==0 ||WK_UP==1))
if(key_up&&(KEY0==0 || KEY1==0 || KEY2==0 ||WK_UP==0))
{
delay_ms(10);//ȥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
key_up=0;
if(KEY0==0)return KEY0_PRES;
else if(KEY1==0)return KEY1_PRES;
else if(WK_UP==1)return WKUP_PRES;
else if(WK_UP==0)return WKUP_PRES;
else if(KEY2 == 0)return KEY2_PRES;
}else if(KEY0==1&&KEY1==1&&WK_UP==0&&KEY2==1)key_up=1;
}else if(KEY0==1&&KEY1==1&&WK_UP==1&&KEY2==1)key_up=1;
return 0;// <EFBFBD>ް<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}

16
stm32/HARDWARE/KEY/key.h

@ -15,16 +15,10 @@ @@ -15,16 +15,10 @@
//////////////////////////////////////////////////////////////////////////////////
//#define KEY0 PEin(4) //PE4
//#define KEY1 PEin(3) //PE3
//#define WK_UP PAin(0) //PA0 WK_UP
#define KEY0 GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_1)//<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
#define KEY1 GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_13)//<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
#define KEY2 GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_12)
#define WK_UP GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)//<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>3(WK_UP)
#define KEY0 GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_15)//<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
#define KEY1 GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_14)//<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
#define KEY2 GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_13)
#define WK_UP GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_0)//<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>3(WK_UP)
#define KEY0_PRES 1 //KEY0<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define KEY1_PRES 2 //KEY1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
@ -33,4 +27,6 @@ @@ -33,4 +27,6 @@
void KEY_Init(void);//IO<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
u8 KEY_Scan(u8); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɨ<EFBFBD><EFBFBD><EFBFBD>
#endif

29
stm32/HARDWARE/TIMER/timer.c

@ -11,7 +11,6 @@ extern char beam_value_buf[7]; @@ -11,7 +11,6 @@ extern char beam_value_buf[7];
extern struct UserInfo userInfo;
/**
* @description: pwm
* @param {int} motor
@ -24,6 +23,26 @@ void Set_Pwm(int motor) @@ -24,6 +23,26 @@ void Set_Pwm(int motor)
PWMA=abs(motor);
}
/**
* @description:
* @param {unsigned long} inData
* @return {*}
*/
int KalmanFilter(int inData)
{
static float kalman = 0; //上次卡尔曼值(估计出的最优值)
static float p = 10;
float q = 0.02; //q:过程噪声
float r = 7.0000; //r:测量噪声
float kg = 0; //kg:卡尔曼增益
p += q;
kg = p / ( p + r ); //计算卡尔曼增益
kalman = kalman + (kg * (inData - kalman)); //计算本次滤波估计值
p = (1 - kg) * p; //更新测量方差
return (int)kalman; //返回估计值
}
/**
* @description:
* @param {int} Encoder
@ -33,15 +52,16 @@ void Set_Pwm(int motor) @@ -33,15 +52,16 @@ void Set_Pwm(int motor)
int velocity_PID(int Encoder,int Target){
static float velocity_KP = 7.7, velocity_KI = 1.1;
static int Last_bias;
int Bias, pwm = 0;
static int Bias, pwm;
Bias = Encoder - Target; //计算偏差
pwm = velocity_KP * Bias + velocity_KI * (Bias - Last_bias); //增量式PI控制器
pwm += velocity_KP * Bias + velocity_KI * (Bias - Last_bias); //增量式PI控制器
if(pwm > 7200) pwm = 7200;
if(pwm < -7200) pwm = -7200;
Last_bias = Bias; //保存上一次偏差
return pwm;
}
/**
* @description:
* @param {u16} arr
@ -73,7 +93,6 @@ void TIM3_Int_Init(u16 arr,u16 psc) @@ -73,7 +93,6 @@ void TIM3_Int_Init(u16 arr,u16 psc)
NVIC_Init(&NVIC_InitStructure);
TIM_Cmd(TIM3, ENABLE);
}
void TIM3_IRQHandler(void)
@ -82,7 +101,9 @@ void TIM3_IRQHandler(void) @@ -82,7 +101,9 @@ void TIM3_IRQHandler(void)
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
userInfo.currentSpeed = Read_Encoder(2);
userInfo.currentSpeed = KalmanFilter(userInfo.currentSpeed);
if(userInfo.run)pwm = velocity_PID(userInfo.currentSpeed, userInfo.targetSpeed);
else pwm = 0;
userInfo.pwm_val = pwm;
Set_Pwm(pwm);
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);

BIN
stm32/OBJ/Template.axf

Binary file not shown.

19
stm32/OBJ/Template.build_log.htm

@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
<h2>Tool Versions:</h2>
IDE-Version: ¦ÌVision V5.25.2.0
Copyright (C) 2018 ARM Ltd and ARM Germany GmbH. All rights reserved.
License Information: li Administrator, li, LIC=LSNX7-ESVPU-ARPXW-QH3G4-M33TV-HZM1L
License Information: sasasa QY, asas, LIC=QF8WF-6I29G-55ZT2-95TJS-AUNX7-U54RF
Tool Versions:
Toolchain: MDK-ARM Plus Version: 5.25.2.0
@ -21,19 +21,18 @@ Target DLL: STLink\ST-LINKIII-KEIL_SWO.dll V3.0.1.0 @@ -21,19 +21,18 @@ Target DLL: STLink\ST-LINKIII-KEIL_SWO.dll V3.0.1.0
Dialog DLL: TCM.DLL V1.35.1.0
<h2>Project:</h2>
e:\workspace\items\MotorPid-master\motorpid\stm32\USER\Template.uvprojx
Project File Date: 04/18/2022
e:\ÏîÄ¿\¼æÖ°ÏîÄ¿\20220418-MotorPid\stm32\USER\Template.uvprojx
Project File Date: 04/17/2022
<h2>Output:</h2>
*** Using Compiler 'V5.06 update 6 (build 750)', folder: 'D:\Keil_v5\ARM\ARMCC\Bin'
Build target 'Target 1'
compiling key.c...
compiling main.c...
main.c(113): warning: #167-D: argument of type "char *" is incompatible with parameter of type "u8 *"
OLED_ShowString(0,0, str, 16);
main.c: 1 warning, 0 errors
compiling timer.c...
..\HARDWARE\TIMER\timer.c(23): warning: #223-D: function "abs" declared implicitly
PWMA=abs(motor);
..\HARDWARE\TIMER\timer.c: 1 warning, 0 errors
linking...
Program Size: Code=12802 RO-data=2342 RW-data=392 ZI-data=1344
Program Size: Code=13154 RO-data=2342 RW-data=408 ZI-data=1344
FromELF: creating hex file...
"..\OBJ\Template.axf" - 0 Error(s), 1 Warning(s).
@ -49,7 +48,7 @@ Package Vendor: Keil @@ -49,7 +48,7 @@ Package Vendor: Keil
D:\Keil_v5\ARM\PACK\Keil\STM32F1xx_DFP\2.3.0\Device\Include
<h2>Collection of Component Files used:</h2>
Build Time Elapsed: 00:00:03
Build Time Elapsed: 00:00:01
</pre>
</body>
</html>

1937
stm32/OBJ/Template.hex

File diff suppressed because it is too large Load Diff

883
stm32/OBJ/Template.htm

File diff suppressed because it is too large Load Diff

1212
stm32/OBJ/Template_Target 1.dep

File diff suppressed because it is too large Load Diff

BIN
stm32/OBJ/adc.crf

Binary file not shown.

BIN
stm32/OBJ/adc.o

Binary file not shown.

BIN
stm32/OBJ/delay.crf

Binary file not shown.

BIN
stm32/OBJ/delay.o

Binary file not shown.

BIN
stm32/OBJ/encoder.crf

Binary file not shown.

BIN
stm32/OBJ/encoder.o

Binary file not shown.

BIN
stm32/OBJ/key.crf

Binary file not shown.

BIN
stm32/OBJ/key.o

Binary file not shown.

BIN
stm32/OBJ/led.crf

Binary file not shown.

BIN
stm32/OBJ/led.o

Binary file not shown.

BIN
stm32/OBJ/main.crf

Binary file not shown.

BIN
stm32/OBJ/main.o

Binary file not shown.

BIN
stm32/OBJ/misc.crf

Binary file not shown.

BIN
stm32/OBJ/misc.o

Binary file not shown.

BIN
stm32/OBJ/motor.crf

Binary file not shown.

BIN
stm32/OBJ/motor.o

Binary file not shown.

BIN
stm32/OBJ/oled.crf

Binary file not shown.

BIN
stm32/OBJ/oled.o

Binary file not shown.

BIN
stm32/OBJ/stm32f10x_adc.crf

Binary file not shown.

BIN
stm32/OBJ/stm32f10x_adc.o

Binary file not shown.

BIN
stm32/OBJ/stm32f10x_gpio.crf

Binary file not shown.

BIN
stm32/OBJ/stm32f10x_gpio.o

Binary file not shown.

BIN
stm32/OBJ/stm32f10x_it.crf

Binary file not shown.

BIN
stm32/OBJ/stm32f10x_it.o

Binary file not shown.

BIN
stm32/OBJ/stm32f10x_rcc.crf

Binary file not shown.

BIN
stm32/OBJ/stm32f10x_rcc.o

Binary file not shown.

BIN
stm32/OBJ/stm32f10x_tim.crf

Binary file not shown.

BIN
stm32/OBJ/stm32f10x_tim.o

Binary file not shown.

BIN
stm32/OBJ/stm32f10x_usart.crf

Binary file not shown.

BIN
stm32/OBJ/stm32f10x_usart.o

Binary file not shown.

BIN
stm32/OBJ/sys.crf

Binary file not shown.

BIN
stm32/OBJ/sys.o

Binary file not shown.

BIN
stm32/OBJ/system_stm32f10x.crf

Binary file not shown.

BIN
stm32/OBJ/system_stm32f10x.o

Binary file not shown.

BIN
stm32/OBJ/timer.crf

Binary file not shown.

BIN
stm32/OBJ/timer.o

Binary file not shown.

BIN
stm32/OBJ/usart.crf

Binary file not shown.

BIN
stm32/OBJ/usart.o

Binary file not shown.

BIN
stm32/OBJ/wifi.crf

Binary file not shown.

BIN
stm32/OBJ/wifi.o

Binary file not shown.

44
stm32/USER/.vscode/c_cpp_properties.json vendored

@ -3,30 +3,30 @@ @@ -3,30 +3,30 @@
{
"name": "Target 1",
"includePath": [
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\HARDWARE\\LED",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\SYSTEM\\delay",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\SYSTEM\\sys",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\SYSTEM\\usart",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\USER",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\STM32F10x_FWLib\\inc",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\CORE",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\HARDWARE\\ESP8266",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\HARDWARE\\DHT11",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\HARDWARE\\LCD1602",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\HARDWARE\\ADC",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\HARDWARE\\TIMER",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\HARDWARE\\DS18B20",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\HARDWARE\\cJSON",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\HARDWARE\\DS1302",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\HARDWARE\\LCD",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\HARDWARE\\OLED",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\HARDWARE\\MOTOR",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\HARDWARE\\ENCODER",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\HARDWARE\\KEY",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\HARDWARE\\LED",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\SYSTEM\\delay",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\SYSTEM\\sys",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\SYSTEM\\usart",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\USER",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\STM32F10x_FWLib\\inc",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\CORE",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\HARDWARE\\ESP8266",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\HARDWARE\\DHT11",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\HARDWARE\\LCD1602",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\HARDWARE\\ADC",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\HARDWARE\\TIMER",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\HARDWARE\\DS18B20",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\HARDWARE\\cJSON",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\HARDWARE\\DS1302",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\HARDWARE\\LCD",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\HARDWARE\\OLED",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\HARDWARE\\MOTOR",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\HARDWARE\\ENCODER",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\HARDWARE\\KEY",
"D:\\Keil_v5\\ARM\\ARMCC\\include",
"D:\\Keil_v5\\ARM\\ARMCC\\include\\rw",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32\\STM32F10x_FWLib\\src",
"e:\\workspace\\items\\MotorPid-master\\motorpid\\stm32"
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32\\STM32F10x_FWLib\\src",
"e:\\项目\\兼职项目\\20220418-MotorPid\\stm32"
],
"defines": [
"STM32F10X_MD",

8
stm32/USER/.vscode/keil-assistant.log vendored

@ -24,3 +24,11 @@ @@ -24,3 +24,11 @@
[info] Log at : 2022/4/19|17:22:46|GMT+0800
[info] Log at : 2022/4/19|22:29:34|GMT+0800
[info] Log at : 2022/4/20|20:44:57|GMT+0800
[info] Log at : 2022/4/20|20:45:03|GMT+0800
[info] Log at : 2022/4/20|20:45:31|GMT+0800

5
stm32/USER/.vscode/settings.json vendored

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
{
"files.associations": {
"cstdlib": "c"
}
}

14
stm32/USER/.vscode/uv4.log vendored

@ -1,12 +1,2 @@ @@ -1,12 +1,2 @@
*** Using Compiler 'V5.06 update 6 (build 750)', folder: 'D:\Keil_v5\ARM\ARMCC\Bin'
Build target 'Target 1'
compiling key.c...
compiling main.c...
main.c(113): warning: #167-D: argument of type "char *" is incompatible with parameter of type "u8 *"
OLED_ShowString(0,0, str, 16);
main.c: 1 warning, 0 errors
linking...
Program Size: Code=12802 RO-data=2342 RW-data=392 ZI-data=1344
FromELF: creating hex file...
"..\OBJ\Template.axf" - 0 Error(s), 1 Warning(s).
Build Time Elapsed: 00:00:03
Load "..\\OBJ\\Template.axf"
Erase Done.Programming Done.Verify OK.Flash Load finished at 21:42:22

2
stm32/USER/.vscode/uv4.log.lock vendored

@ -1 +1 @@ @@ -1 +1 @@
2022/4/19 17:46:52
2022/4/20 21:42:23

980
stm32/USER/Template.map

File diff suppressed because it is too large Load Diff

101
stm32/USER/Template.uvguix.QY

File diff suppressed because one or more lines are too long

2
stm32/USER/Template.uvoptx

@ -295,7 +295,7 @@ @@ -295,7 +295,7 @@
<GroupNumber>2</GroupNumber>
<FileNumber>7</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\HARDWARE\TIMER\timer.c</PathWithFileName>

26
stm32/USER/main.c

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
/*
* @Author: your name
* @Date: 2022-04-17 21:03:48
* @LastEditTime: 2022-04-19 17:44:21
* @LastEditors: lishengyin
* @LastEditTime: 2022-04-20 21:32:40
* @LastEditors: Please set LastEditors
* @Description: koroFileHeader查看配置 : https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @FilePath: \undefinede:\\\MotorPid\stm32\USER\main.c
*/
@ -60,23 +60,25 @@ void processingTasks(void) @@ -60,23 +60,25 @@ void processingTasks(void)
{
case WKUP_PRES:
userInfo.diversion = ~userInfo.diversion;
// 方向
if(userInfo.diversion && userInfo.targetSpeed > 0) userInfo.targetSpeed = 0 - userInfo.targetSpeed;
else if(userInfo.diversion == 0) userInfo.targetSpeed = abs(userInfo.targetSpeed);
break;
case KEY1_PRES:
userInfo.targetSpeed++;
if(userInfo.targetSpeed > 20) userInfo.targetSpeed = 20;
break;
case KEY0_PRES:
if(userInfo.targetSpeed > 0)userInfo.targetSpeed--;
userInfo.targetSpeed--;
if(userInfo.targetSpeed < -20) userInfo.targetSpeed = -20;
break;
case KEY2_PRES:
userInfo.run = ~userInfo.run;
if(userInfo.run == 0) userInfo.run = 1;
else userInfo.run = 0;
break;
default:
break;
}
// 方向
if(userInfo.diversion) AIN1 = 1, AIN1 = 0;
else AIN1 = 0, AIN1 = 1;
}
/**
@ -97,9 +99,11 @@ void Sys_Init(void) @@ -97,9 +99,11 @@ void Sys_Init(void)
OLED_Clear();
// 初始化为0
userInfo.targetSpeed = 0;
userInfo.run = 0;
userInfo.run = 1;
}
/**
* @description: Oled显示
* @param {*}
@ -107,9 +111,9 @@ void Sys_Init(void) @@ -107,9 +111,9 @@ void Sys_Init(void)
*/
void OLED_Display(void)
{
char str[30];
if(userInfo.diversion) sprintf(str, "speed:-%d,pwd_val:%d,target:%d CW", abs(userInfo.currentSpeed), abs(userInfo.pwm_val), userInfo.targetSpeed);
else sprintf(str, "speed:-%d,pwd_val:%d,target:%d REV", abs(userInfo.currentSpeed), abs(userInfo.pwm_val), userInfo.targetSpeed);
char str[50];
if(userInfo.diversion) sprintf(str, "speed:%d,pwm_val:%d,target:%d CW ", abs(userInfo.currentSpeed), abs(userInfo.pwm_val), userInfo.targetSpeed);
else sprintf(str, "speed:%d,pwm_val:%d,target:%d REV ", abs(userInfo.currentSpeed), abs(userInfo.pwm_val), userInfo.targetSpeed);
OLED_ShowString(0,0, str, 16);
}

Loading…
Cancel
Save