Based on the schematic diagram of iMcHineSe, an OLED display module (Mini_SimpleFOC brushless motor drive and control integrated board - Jialichuang EDA open source hardware platform (oshwhub.com)) was added, and the standard version was migrated to the professional version, and the layout and Optimize the wiring, use manual wiring, try to make the wiring beautiful, and add a button to switch the mode (the development board is currently initialized successfully, the V1 version forgot to add the serial port, the V2 version has been optimized, the serial port is added, and is currently being verified by the board ).
Add OLED. OLED uses the PB4 and PB3 pins corresponding to JLINK. When using it, you need to turn on the AFIO clock and disable the JLINK function.
Adding stlink pin header, you can use stlink for program burning, which is convenient for debugging.
The motor drive module uses TI's DVR8313PWPR
AMS1117. It may not be suitable to use LDO for voltage reduction, but DC-DC takes up too much space, so 1117 is used. If you are capable, you can optimize it (mainly because I am not good at device selection)
The motor uses a 4008 or 4010 brushless gimbal motor (available on Taobao and Xianyu).
Overall appearance:
Interactive BOM table (you can export the PCB in Lichuang EDA to an AD format file, and then run the AD script (https:// github.com/lianlian33/InteractiveHtmlBomForAD) generated, specific usage tutorials can be searched at station B)
3D model (stl and sldprt) of the pointer above the knob, open using solidworks2021 (added to the attachment)
software simulates IIC reading AS5600 angle value and displays it in The second line on the OLED
is RAWNUM (original data, type unsinedshort), and the third line is angle data (angle system).
You can modify the source code and get software simulation (because I used IIC's AS5600 in the first version (the schematic wiring was wrong) Yes, I received PA6 and PA7. These two pins do not support hardware IIC, so the code was changed to software IIC driver. The version uploaded now has changed the pins to hardware IIC) and forgot to install the serial port, so I changed the and The printf related to the serial port is replaced by the OLED display function (OLED is also driven by the analog IIC, just modify the corresponding pin))

as5600.c file:
#include "as5600.h" #include "delay.h"
void IIC_Init(void){ GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE ); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitS structure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_SetBits(GPIOA,GPIO_Pin_6|GPIO_Pin_7 );}
void IIC_Start(void){ SDA_OUT(); IIC_SDA=1; IIC_SCL=1; delay_us(4); IIC_SDA=0; delay_us(4); IIC_SCL=0;}
void IIC_Stop(void){ SDA_OUT(); IIC_SCL=0; IIC_SDA=0;//STOP: when CLK is high DATA change form low to high delay_us(4); IIC_SCL=1; IIC_SDA=1; delay_us(4);}
u8 IIC_Wait_Ack(void){ u8 ucErrTime= 0; SDA_IN(); IIC_SDA=1;delay_us(1); IIC_SCL=1;delay_us(1); while(READ_SDA) { ucErrTime++; if(ucErrTime>250) { IIC_Stop(); return 1; } } IIC_SCL=0 ; return 0; }
void IIC_Ack(void){ IIC_SCL=0; SDA_OUT(); IIC_SDA=0; delay_us(2); IIC_SCL=1; delay_us(2); IIC_SCL=0;} void IIC_NAck(void){ IIC_SCL= 0; SDA_OUT(); IIC_SDA=1; delay_us(2); IIC_SCL=1; delay_us(2); IIC_SCL=0;}
void IIC_Send_Byte(u8 txd){ u8 t; SDA_OUT(); IIC_SCL=0;// for (t=0;t<8;t++) { if((txd&0x80)>>7) IIC_SDA=1; else IIC_SDA=0; txd<<=1; delay_us(2); IIC_SCL=1; delay_us(2); IIC_SCL=0; delay_us(2); } }
u8 IIC_Read_Byte(unsigned char ack){ unsigned char i,receive=0; SDA_IN(); for(i=0;i<8;i++ ) { IIC_SCL=0; delay_us(2); IIC_SCL=1; receive<<=1; if(READ_SDA)receive++; delay_us(1); } if (!ack) IIC_NAck(); else IIC_Ack(); return receive;} //读取一个字节u8 AS5600_ReadOneByte(u16 ReadAddr){ u8 temp=-1; IIC_Start(); IIC_Send_Byte((0X36<<1)|0x00); IIC_Wait_Ack(); IIC_Send_Byte(ReadAddr); IIC_Wait_Ack(); IIC_Start(); IIC_Send_Byte((0X36<<1)|0x01); IIC_Wait_Ack(); temp=IIC_Read_Byte(0); IIC_Stop(); return temp;} //写入一个字节的数据void AS5600_WriteOneByte(u16 WriteAddr,u8 WriteData){ IIC_Start(); IIC_Send_Byte((0X36<<1)|0x00); IIC_Wait_Ack(); IIC_Send_Byte(WriteAddr); IIC_Wait_Ack(); IIC_Start(); IIC_Send_Byte(WriteData); IIC_Wait_Ack(); IIC_Stop(); delay_ms(10);} //得到原始数据u16 AS5600_ReadTwoByte(u16 ReadAddr_hi,u16 ReadAddr_lo){ u16 TwoByte_Data=-1; u8 hi_Data=0,lo_Data=0; hi_Data=AS5600_ReadOneByte(ReadAddr_hi); lo_Data=AS5600_ReadOneByte(ReadAddr_lo); TwoByte_Data = (hi_Data<<8)|lo_Data; return TwoByte_Data;}
主要就是软件模拟IIC实现控制(代码原工程已放在附件)
视频主要包括正常运行,软件模拟IIC获取AS5600角度值闭环控制,闭环控制空载时电流大小(50ma左右)