Use stm32f10x minimum system board PWM output to control steering gear (self-learning)

First understand the internal structure of the steering gear. The steering gear is mainly composed of the following parts: steering wheel, casing, DC motor, reduction gear set, angle sensor, control drive circuit and interface cables, etc.

The main angle sensor is responsible for the position feedback of the steering gear. It is directly installed on the main output shaft of the steering gear, and the angle change generated after the shaft rotation is converted into a voltage signal and sent back to the control circuit; the steering gear circuit board is used to receive external signals. The signal from the interface and the voltage value fed back by the angle sensor drive the DC motor to rotate; a reduction gear is used to reduce the speed of the DC motor and increase the torque.

According to the control circuit, the steering gear is divided into: digital steering gear and analog steering gear. The digital steering gear has a microcontroller, and it only needs to send the target value once to complete the corresponding task; Yes (that's why the timer is used).

working principle

The closed-loop control formed simulates that the control drive circuit board inside the steering gear receives control signals from the outside, and after processing, it becomes a DC bias voltage. There is a reference voltage inside the control board. This reference voltage is generated by the potentiometer, and the external The obtained DC bias voltage is compared with the voltage of the potentiometer to obtain the voltage difference, and output to the motor driver chip to drive the motor. The positive or negative of the voltage difference determines the positive and negative rotation of the motor, and the size determines the rotation angle. When the voltage difference is 0, The motor stops turning.
 

The steering gear can be controlled in two ways: PWM output control and serial bus control

Setting of PWM output (taking F103z8t6 as an example)

1. First define the structure variables of GPIO and TIM

                    GPIO_InitTypeDef GPIO_InitStructure;//Initialize GPIO
                     TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;//Initialize timer
                     TIM_OCInitTypeDef Tim_OCInitStructure;//Initialize peripheral TIM
             

2. Turn on the clock of TIM4

              RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); //Enable the GPIOB clock
              RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);//Enable the TIM4 clock

3. Set the mode of the GPIO port and enable the pin multiplexing push-pull mode

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; 
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//复用功能
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;    //速度50MHz
        GPIO_Init(GPIOB,&GPIO_InitStructure); 

4. Initialize the timer, set the preloaded value and frequency division value of the timer

        TIM_TimeBaseInitStructure.TIM_Period=19999;
        TIM_TimeBaseInitStructure.TIM_Prescaler=71;
        TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM4,&TIM_TimeBaseInitStructure);

5. Set the PWM mode of TIM4_CH1 and enable it to output

        Tim_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
        Tim_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
        Tim_OCInitStructure.TIM_OCPolarity= TIM_OCPolarity_High;//The output starts as a high level mode
        TIM_OC1Init(TIM4,&Tim_OCInitStructure);

6. Enable the timer

        TIM_OC1PreloadConfig(TIM4,TIM_OCPreload_Enable);
        TIM_Cmd(TIM4,ENABLE);

7. Modify TIM4_CCR1 to control the duty cycle

         TIM_SetCompare1(TIM4,600);

connect:

The servo has three wires: GND, VCC and control wire. The GND needs a single-chip microcomputer, and the steering gear and power supply are all on the same GND.

Precautions:

1. The minimum system board timer 4 corresponds to PB6 7 8 9, and the steering gear only needs one PWM output

2. The duty cycle of the servo can be within 500-1000, TIM_Period=19999, TIM_Prescaler (frequency division value: 71+1=72)=71;

Learning comes from (13 messages) Chapter 9 Steering Gear Control

The article is a note written by myself, there are mistakes, thank you for your corrections.

Guess you like

Origin blog.csdn.net/qq_60043905/article/details/124129478