X-CUBE-SPN11 for X-NUCLEO-IHM11M1: 6Step_Lib.h Source File

X-CUBE-SPN11 for X-NUCLEO-IHM11M1

6Step_Lib.h
Go to the documentation of this file.
1 /**
2  ******************************************************************************
3  * @file 6Step_Lib.h
4  * @author System lab
5  * @version V1.0.0
6  * @date 06-July-2015
7  * @brief This header file provides the set of functions for Motor Control
8  library
9  ******************************************************************************
10  * @attention
11  *
12  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
13  *
14  * Redistribution and use in source and binary forms, with or without modification,
15  * are permitted provided that the following conditions are met:
16  * 1. Redistributions of source code must retain the above copyright notice,
17  * this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright notice,
19  * this list of conditions and the following disclaimer in the documentation
20  * and/or other materials provided with the distribution.
21  * 3. Neither the name of STMicroelectronics nor the names of its contributors
22  * may be used to endorse or promote products derived from this software
23  * without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  ******************************************************************************
37  */
38 
39 
40 /* Define to prevent recursive inclusion -------------------------------------*/
41 #ifndef __6STEP_LIB_H
42 #define __6STEP_LIB_H
43 
44 
45 #include "stm32_nucleo_ihm11m1.h"
46 
47 #include "math.h"
48 #include "stdlib.h"
49 #include "stdio.h"
50 
51 /** @addtogroup MIDDLEWARES MIDDLEWARES
52  * @brief Middlewares Layer
53  * @{
54  */
55 
56 
57 /** @addtogroup MC_6-STEP_LIB MC_6-STEP_LIB
58  * @brief Motor Control driver
59  * @{
60  */
61 
62 /** @defgroup Exported_types Exported_types
63 * @{
64 */
65 /**
66  * @brief Six Step parameters
67  */
68 typedef enum
69 {
70  IDLE, /* 0 */
71  STARTUP, /* 1 */
72  VALIDATION, /* 2 */
73  STOP, /* 3 */
74  START, /* 4 */
75  RUN, /* 5 */
76  ALIGNMENT, /* 6 */
77  SPEEDFBKERROR, /* 7 */
78  OVERCURRENT, /* 8 */
79  STARTUP_FAILURE, /* 9 */
82 
83 /**
84  * @}
85  */
86 
87 
88 /** @defgroup Exported_types Exported_types
89 * @{
90 */
91 /**
92  * @brief Six Step parameters
93  */
94 typedef struct
95 {
96  uint32_t LF_TIMx_PSC; /*!< Prescaler variable for low frequency timer*/
97  uint32_t LF_TIMx_ARR; /*!< ARR variable for low frequency timer*/
98  uint32_t HF_TIMx_PSC; /*!< Prescaler variable for high frequency timer*/
99  uint32_t HF_TIMx_ARR; /*!< ARR variable for high frequency timer*/
100  uint32_t HF_TIMx_CCR; /*!< CCR variable for high frequency timer*/
101  uint8_t step_position; /*!< Step number variable for SixStep algorithm*/
102  SIXSTEP_Base_SystStatus_t STATUS; /*!< Status variable for SixStep algorithm*/
103  uint8_t status_prev; /*!< Previous status variable for SixStep algorithm*/
104  uint16_t pulse_value; /*!< CCR value for SixStep algorithm*/
105  uint16_t ARR_value; /*!< ARR vector for Accell compute*/
106  uint32_t Regular_channel[4]; /*!< Buffer for ADC regular channel */
107  uint32_t CurrentRegular_BEMF_ch; /*!< ADC regular channel to select */
108  uint32_t prescaler_value; /*!< Prescaler value for low freq timer*/
109  uint16_t numberofitemArr; /*!< Number of elements */
110  uint32_t ADC_BUFFER[4]; /*!< Buffer for ADC regular channel */
111  uint32_t ADC_SEQ_CHANNEL[4]; /*!< Buffer for ADC regular channel */
112  uint32_t ADC_Regular_Buffer[5]; /*!< Buffer for ADC regular channel */
113  uint16_t ADC_BEMF_threshold_UP; /*!< Voltage threshold for BEMF detection in up direction*/
114  uint16_t ADC_BEMF_threshold_DOWN; /*!< Voltage threshold for BEMF detection in down direction*/
115  uint16_t demagn_counter; /*!< Demagnetization counter*/
116  uint16_t demagn_value; /*!< Demagnetization value*/
117  int16_t speed_fdbk; /*!< Motor speed variable*/
118  int16_t speed_fdbk_filtered; /*!< Filtered Motor speed variable*/
119  int16_t filter_depth; /*!< Filter depth for speed measuring*/
120  uint16_t Current_Reference; /*!< Currrent reference for SixStep algorithm*/
121  uint16_t Ireference; /*!< Currrent reference for SixStep algorithm*/
122  int32_t Integral_Term_sum; /*!< Global Integral part for PI*/
123  uint8_t CMD; /*!< Flag control for Motor Start/Stop*/
124  uint8_t ALIGN_OK; /*!< Flag control for Motor Alignment*/
125  uint8_t ALIGNMENT; /*!< Flag control for Motor Alignment ongoing*/
126  uint8_t bemf_state_1; /*!< Bemf variable */
127  uint8_t bemf_state_2; /*!< Bemf variable */
128  uint8_t bemf_state_3; /*!< Bemf variable */
129  uint8_t bemf_state_4; /*!< Bemf variable */
130  uint8_t bemf_state_5; /*!< Bemf variable */
131  uint8_t bemf_state_6; /*!< Bemf variable */
132  uint16_t Speed_Loop_Time; /*!< Speed loop variable for timing */
133  uint16_t Speed_Ref_filtered; /*!< Filtered Reference Motor Speed variable */
134  uint16_t RUN_Motor; /*!< Flag for Motor status */
135  uint8_t ARR_OK; /*!< ARR flag control for Accell status */
136  uint8_t VALIDATION_OK; /*!< Validation flag for Closed loop control begin */
137  uint8_t SPEED_VALIDATED; /*!< Validation flag for Speed before closed loop control */
138  uint16_t Speed_target_ramp; /*!< Target Motor Speed */
139  uint16_t Speed_target_time; /*!< Target Motor Ramp time */
140  uint16_t Ramp_Start; /*!< Ramp time start*/
141  uint16_t Bemf_delay_start; /*!< Bemf variable */
142  uint16_t MediumFrequencyTask_flag; /*!< Flag for Medium Task Frequency */
143  uint32_t SYSCLK_frequency; /*!< System clock main frequency */
144  uint32_t Uart_cmd_to_set; /*!< */
145  uint32_t Uart_value_to_set; /*!< */
146  uint8_t Button_ready; /*!< */
147  uint8_t BEMF_OK; /*!< */
148  uint8_t CL_READY; /*!< */
149  uint8_t BEMF_Tdown_count; /*!< BEMF Consecutive Threshold Falling Crossings Counter */
150  uint16_t IREFERENCE; /*!< Currrent reference*/
151  uint16_t NUMPOLESPAIRS; /*!< Number of motor pole pairs */
152  uint32_t ACCEL; /*!< Acceleration start-up parameter*/
153  uint16_t KP; /*!< KP parameter for PI regulator */
154  uint16_t KI; /*!< KI parameter for PI regulator */
155  uint8_t CW_CCW; /*!< Set the motor direction */
156  uint8_t Potentiometer; /*!< Enable/Disable potentiometer for speed control */
157 } SIXSTEP_Base_InitTypeDef; /*!< Six Step Data Structure */
158 
159 /**
160  * @}
161  */
162 
163 /** @defgroup Exported_types Exported_types
164 * @{
165 */
166 /**
167  * @brief Six PI regulator parameters
168  */
169 
170 typedef struct
171 {
172  int16_t Reference; /*!< Refence value for PI regulator */
173  int16_t Kp_Gain; /*!< Kp value for PI regulator */
174  int16_t Ki_Gain; /*!< Ki value for PI regulator */
175  int16_t Lower_Limit_Output; /*!< Min output value for PI regulator */
176  int16_t Upper_Limit_Output; /*!< Max output value for PI regulator */
177  int8_t Max_PID_Output; /*!< Max Saturation indicator flag */
178  int8_t Min_PID_Output; /*!< Min Saturation indicator flag */
180 
181 /**
182  * @}
183  */
184 
185 /** @defgroup Exported_function_6StepLib Exported_function_6StepLib
186 * @{
187 */
188 
189 void MC_SixStep_INIT(void);
190 void MC_SixStep_RESET(void);
191 void MC_StartMotor(void);
192 void MC_StopMotor(void);
193 void MC_Set_Speed(uint16_t);
194 void MC_EXT_button_SixStep(void);
195 
196 /**
197  * @}
198  */
199 
200 /** MC_6-STEP_LIB
201  * @}
202  */
203 
204 
205 /** MIDDLEWARES
206  * @}
207  */
208 
209 #endif
void MC_StopMotor(void)
Definition: 6Step_Lib.c:1000
SIXSTEP_Base_SystStatus_t
Six Step parameters.
Definition: 6Step_Lib.h:68
Definition: 6Step_Lib.h:70
void MC_SixStep_RESET(void)
Definition: 6Step_Lib.c:353
Definition: 6Step_Lib.h:75
void MC_EXT_button_SixStep(void)
Definition: 6Step_Lib.c:1577
Definition: 6Step_Lib.h:73
SIXSTEP_Base_SystStatus_t STATUS
Definition: 6Step_Lib.h:102
uint16_t ADC_BEMF_threshold_UP
Definition: 6Step_Lib.h:113
uint16_t MediumFrequencyTask_flag
Definition: 6Step_Lib.h:142
uint32_t CurrentRegular_BEMF_ch
Definition: 6Step_Lib.h:107
Six Step parameters.
Definition: 6Step_Lib.h:94
This file provides the interface between the MC-lib and STM Nucleo.
void MC_StartMotor(void)
Definition: 6Step_Lib.c:978
void MC_SixStep_INIT(void)
Definition: 6Step_Lib.c:1087
uint16_t ADC_BEMF_threshold_DOWN
Definition: 6Step_Lib.h:114
void MC_Set_Speed(uint16_t)
Definition: 6Step_Lib.c:889
struct SIXSTEP_PI_PARAM_InitTypeDef_t * SIXSTEP_pi_PARAM_InitTypeDef_t
Six PI regulator parameters.
Definition: 6Step_Lib.h:170
Generated by   doxygen 1.8.11