Gas sampling using active gas extraction method to ensure adequate and stable airflow, so we use air pump to extract gas to complete.
1 , design Overview
This requirement allows the customer to set the speed of the motor, but does not require dynamic adjustment. There are many ways to control the motor, and we use it in a relatively simple way. We implement this control process by using a timer to generate PWM imports.
2 , Hardware connection
Control of the motor we use the Advanced timer TIM1 generate PWM wave control, for the onenet Kylin seat TIM1 channels 1, 2, 3 and their complementary outputs have been led to the terminal row j2-5 (PA10), 2-6 (PA9), j2-7 (PA8), j5-7 (PA7) , J3-2 (PB0), j3-3 (PB1), as shown in:
The air pump used is a relatively small equipment, the need for 12v-24v power supply, specifically as follows:
Since the motor is 12v-24v, we also need the necessary circuitry to complete this function, as shown in the Control Panel:
The schematic diagram of this dashboard is shown below, and we will design it as one of the following designs:
Next we make the corresponding configuration in the STM32CUBEMX, configured as follows:
3 , Software design
After we have finished configuring and connecting the hardware, we begin to write the software, first of all, we implement the necessary initialization, so that the PWM waveform can be generated.
/*initializing the TIM1 configuration*/Static voidTim1_pwm_initialization (void) {tim_masterconfigtypedef smasterconfig; Tim_oc_inittypedef Sconfigoc; Tim_breakdeadtimeconfigtypedef Sbreakdeadtimeconfig; Htim1. Instance=TIM1; Htim1. Init.prescaler=0; Htim1. Init.countermode=tim_countermode_up; Htim1. Init.period=0; Htim1. Init.clockdivision=Tim_clockdivision_div1; Htim1. Init.repetitioncounter=0; if(Hal_tim_oc_init (&HTIM1)! =HAL_OK) {_error_handler (__file__, __line__); } Smasterconfig.masteroutputtrigger=Tim_trgo_reset; Smasterconfig.masterslavemode=tim_masterslavemode_disable; if(Hal_timex_masterconfigsynchronization (&HTIM1, &smasterconfig)! =HAL_OK) {_error_handler (__file__, __line__); } Sconfigoc.ocmode=tim_ocmode_timing; Sconfigoc.pulse=0; Sconfigoc.ocpolarity=Tim_ocpolarity_high; Sconfigoc.ocnpolarity=Tim_ocnpolarity_high; Sconfigoc.ocfastmode=tim_ocfast_disable; Sconfigoc.ocidlestate=Tim_ocidlestate_reset; Sconfigoc.ocnidlestate=Tim_ocnidlestate_reset; if(Hal_tim_oc_configchannel (&HTIM1, &SCONFIGOC, tim_channel_1)! =HAL_OK) {_error_handler (__file__, __line__); } if(Hal_tim_oc_configchannel (&HTIM1, &SCONFIGOC, tim_channel_2)! =HAL_OK) {_error_handler (__file__, __line__); } if(Hal_tim_oc_configchannel (&HTIM1, &SCONFIGOC, tim_channel_3)! =HAL_OK) {_error_handler (__file__, __line__); } Sbreakdeadtimeconfig.offstaterunmode=tim_ossr_disable; Sbreakdeadtimeconfig.offstateidlemode=tim_ossi_disable; Sbreakdeadtimeconfig.locklevel=Tim_locklevel_off; Sbreakdeadtimeconfig.deadtime=0; Sbreakdeadtimeconfig.breakstate=tim_break_disable; Sbreakdeadtimeconfig.breakpolarity=Tim_breakpolarity_high; Sbreakdeadtimeconfig.automaticoutput=tim_automaticoutput_disable; if(Hal_timex_configbreakdeadtime (&HTIM1, &sbreakdeadtimeconfig)! =HAL_OK) {_error_handler (__file__, __line__); } hal_tim_msppostinit (&htim1);}
After the configuration is complete, we then write a control program to adjust the duty ratio. The specific implementation code is as follows:
//Configuring the TIM1 for PWM outputvoidPwm_configuration (void){ //Calculate the frequency and duty ratio of the initializationTimerperiod = Pwmtimeperiod;//calculates the value that is used to set the ARR register to generate a signal at a frequency of 17.57 KhzPwm1pulse = (uint16_t) ((uint32_t)5* (Timerperiod-1)) /Ten);//calculates the value of the CCR1 register to generate 50% duty-TIM1 on channels 1 and 1NPwm2pulse = (uint16_t) ((uint32_t)5* (Timerperiod-1)) /Ten);//calculates the value of the CCR1 register to generate 50% duty-TIM8 on channels 1 and 1Npwm_initprocess (tim1,timerperiod,pwm1pulse);}
After the configuration is completed, the basic performance is achieved, and we will further improve it in the subsequent design.
Onenet Unicorn Seat Application Development Seven: Control the sampling motor