diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000000000000000000000000000000000000..868bd5e84034b87192b92830591fd9654387beeb --- /dev/null +++ b/README.en.md @@ -0,0 +1,135 @@ +# STM32 FOC Motor Control Template Project + +This is an embedded project based on the STM32F103 series microcontrollers, including the implementation of FOC (Field Oriented Control) motor control algorithms and an application framework. + +## Project Introduction + +This project is a complete embedded motor control solution, adopting a modular design, supporting: + +- FOC Motor Control Algorithm +- Speed Sensor Acquisition +- Voltage Sampling Monitoring +- Serial Communication +- Button Interaction +- Display Interface +- Window Management System + +## Hardware Platform + +- **Chip**: STM32F103C8T6 +- **Core**: ARM Cortex-M3 +- **Clock Speed**: 72MHz + +## Directory Structure + +``` +templete/ +├── App/ # Application Layer +│ ├── app.c/h # Main Application and Window Management +│ ├── appdata.c/h # Application Data +│ ├── errorwindow.c/h # Error Window +│ ├── runwindow.c/h # Run Window +│ └── waitwindow.c/h # Wait Window +├── FOC/ # FOC Motor Control +│ ├── motor.c/h # Motor Control Core +│ ├── motor_device_init.c/h # Motor Device Initialization +│ └── sensor/ # Sensor Module +│ ├── velocitysensor.c/h # Speed Sensor +│ └── voltagesample.c/h # Voltage Sampling +├── Model/ # Functional Modules +│ ├── Com/communication.c/h # Serial Communication +│ ├── DISPLAY/display.c/h # Display Module +│ └── Key/key.c/h # Button Module +├── OsSystick/ # System Clock Management +│ └── systick.c/h +├── STL/ # STM32 Standard Library +│ ├── inc/ # Header Files +│ └── src/ # Source Files +├── StartUp/ # Startup Files +│ ├── startup_stm32f10x_md.s # Startup Assembly +│ └── system_stm32f10x.c/h # System Clock Configuration +├── User/ # User Code +│ ├── main.c # Main Function +│ ├── stm32f10x_it.c/h # Interrupt Handling +│ └── types.h # Type Definitions +└── Objects/ # Build Output +``` + +## Module Description + +### Application Layer (App) + +Contains the window management system, supporting multiple interface switches: +- **RunWindow**: Run window, displays motor running status +- **WaitWindow**: Wait window +- **ErrorWindow**: Error window, displays exception information + +### FOC Motor Control (FOC) + +- **Motor**: Motor control core, supports start, stop, direction setting, speed regulation +- **VelocitySensor**: Speed sensor module, used to acquire motor speed +- **VoltageSample**: Voltage sampling module, monitors power supply voltage + +### Communication Module (Model/Com) + +Supports serial communication, includes frame parsing and verification functions: +- Frame header recognition +- Data transmission/reception +- Checksum calculation +- Timeout handling + +### Button Module (Model/Key) + +Supports multiple button inputs, features debouncing and repeat press functionality. + +## Compilation Instructions + +This project uses the Keil MDK development environment for compilation. + +1. Open the `test.uvprojx` file using Keil UVision +2. Select target chip STM32F103C8 +3. Compile project to generate `test.hex` + +## Usage Instructions + +1. Initialize system clock and peripherals +2. Initialize various modules (motor, sensors, communication, buttons, etc.) +3. Call task functions of each module in the main loop + +Typical initialization flow: + +```c +// Hardware Initialization +Device_Init(); // Motor Device Initialization +Sensor_Velocity_Init(); // Speed Sensor Initialization +VoltageSample_GPIO_Config(); // Voltage Sampling Initialization +Communication_Init(); // Communication Module Initialization +Key_Init(); // Button Initialization + +// Application Initialization +App_Init(); + +// Enable Global Interrupts +// ... + +while(1) +{ + // Task Polling + App_Task(); + Motor_Task(); + Communication_Task(); + Key_Task(); + // ... +} +``` + +## Dependencies + +- Keil MDK 5.x or higher version +- STM32F1xx HAL Library or Standard Peripheral Library + +## Notes + +- This project is a template project; specific hardware configuration needs adjustment according to the actual circuit +- Motor driver parameters need to be calibrated according to actual motor characteristics +- Communication protocol can be modified according to actual requirements \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8b5f3a0d2ff254b3959ff943e3df29112a3a8740 --- /dev/null +++ b/README.md @@ -0,0 +1,135 @@ +# STM32 FOC 电机控制模板项目 + +这是一个基于 STM32F103 系列微控制器的嵌入式项目,包含了 FOC(磁场定向控制)电机控制算法的实现以及应用程序框架。 + +## 项目简介 + +本项目是一个完整的嵌入式电机控制解决方案,采用模块化设计,支持: + +- FOC 电机控制算法 +- 速度传感器采集 +- 电压采样监测 +- 串口通信 +- 按键交互 +- 显示界面 +- 窗口管理系统 + +## 硬件平台 + +- **芯片**: STM32F103C8T6 +- **内核**: ARM Cortex-M3 +- **主频**: 72MHz + +## 目录结构 + +``` +templete/ +├── App/ # 应用程序层 +│ ├── app.c/h # 主应用程序与窗口管理 +│ ├── appdata.c/h # 应用程序数据 +│ ├── errorwindow.c/h # 错误窗口 +│ ├── runwindow.c/h # 运行窗口 +│ └── waitwindow.c/h # 等待窗口 +├── FOC/ # FOC 电机控制 +│ ├── motor.c/h # 电机控制核心 +│ ├── motor_device_init.c/h # 电机设备初始化 +│ └── sensor/ # 传感器模块 +│ ├── velocitysensor.c/h # 速度传感器 +│ └── voltagesample.c/h # 电压采样 +├── Model/ # 功能模块 +│ ├── Com/communication.c/h # 串口通信 +│ ├── DISPLAY/display.c/h # 显示模块 +│ └── Key/key.c/h # 按键模块 +├── OsSystick/ # 系统时钟管理 +│ └── systick.c/h +├── STL/ # STM32 标准库 +│ ├── inc/ # 头文件 +│ └── src/ # 源文件 +├── StartUp/ # 启动文件 +│ ├── startup_stm32f10x_md.s # 启动汇编 +│ └── system_stm32f10x.c/h # 系统时钟配置 +├── User/ # 用户代码 +│ ├── main.c # 主函数 +│ ├── stm32f10x_it.c/h # 中断处理 +│ └── types.h # 类型定义 +└── Objects/ # 编译输出 +``` + +## 模块说明 + +### 应用程序层 (App) + +包含窗口管理系统,支持多种界面切换: +- **RunWindow**: 运行窗口,显示电机运行状态 +- **WaitWindow**: 等待窗口 +- **ErrorWindow**: 错误窗口,显示异常信息 + +### FOC 电机控制 (FOC) + +- **Motor**: 电机控制核心,支持启动、停止、方向设置、速度调节 +- **VelocitySensor**: 速度传感器模块,用于获取电机转速 +- **VoltageSample**: 电压采样模块,监测电源电压 + +### 通信模块 (Model/Com) + +支持串口通信,包含帧解析和校验功能: +- 帧头识别 +- 数据收发 +- 校验和计算 +- 超时处理 + +### 按键模块 (Model/Key) + +支持多个按键输入,具备去抖动和重复按功能。 + +## 编译说明 + +本项目使用 Keil MDK 开发环境编译。 + +1. 使用 Keil UVision 打开 `test.uvprojx` 文件 +2. 选择目标芯片 STM32F103C8 +3. 编译项目生成 `test.hex` + +## 使用说明 + +1. 初始化系统时钟和外设 +2. 初始化各模块(电机、传感器、通信、按键等) +3. 在主循环中调用各模块的任务函数 + +典型初始化流程: + +```c +// 硬件初始化 +Device_Init(); // 电机设备初始化 +Sensor_Velocity_Init(); // 速度传感器初始化 +VoltageSample_GPIO_Config(); // 电压采样初始化 +Communication_Init(); // 通信模块初始化 +Key_Init(); // 按键初始化 + +// 应用程序初始化 +App_Init(); + +// 开启全局中断 +// ... + +while(1) +{ + // 任务轮询 + App_Task(); + Motor_Task(); + Communication_Task(); + Key_Task(); + // ... +} +``` + +## 依赖项 + +- Keil MDK 5.x 或更高版本 +- STM32F1xx HAL 库或标准外设库 + +## 注意事项 + +- 本项目为模板项目,具体硬件配置需根据实际电路进行调整 +- 电机驱动参数需要根据实际电机特性进行校准 +- 通信协议可根据实际需求进行修改 \ No newline at end of file