BLDC control on ATAVRMC303 with ATxMega128A1
mc_interface.c
Go to the documentation of this file.
1 
12 //_____ I N C L U D E S ___________________________________________________
13 #include "config.h"
14 
15 #include "mc_interface.h"
16 #include "mc_control.h"
17 #include "mc_drv.h"
18 
19 
20 Bool mci_direction = CW;
21 Bool mci_run_stop = FALSE;
22 U8 mc_cmd_speed = 0;
23 
27 
34 void mci_run(void)
35 {
36  // if (!(PCTL2 & (1<<PRUN2))) /* if there is an overcurrent */
37  /* {
38  PSC0_Init(255,0,1,0);
39  PSC1_Init(255,0,1,0);
40  PSC2_Init(255,0,1,0);
41  }*/
42  mci_run_stop = TRUE;
46  mc_disable_during_inrush(); /* disable overcurrent during inrush */
47 }
48 
55 void mci_retry_run(void)
56 {
57  mci_run_stop = TRUE;
61  mc_disable_during_inrush(); /* disable overcurrent during inrush */
62 }
63 
71 {
72  return mci_run_stop;
73 }
74 
81 void mci_stop(void)
82 {
83  mci_run_stop=FALSE;
84 }
85 
92 void mc_init()
93 {
94  mc_init_HW();
95  Enable_interrupt();
96 
97  mci_stop();
98  mci_forward();
101 }
102 
103 /*
104 * @brief speed modification
105 * @pre initialization of motor
106 * @post new value of speed
107 */
108 void mci_set_motor_speed(U8 speed)
109 {
110  mc_cmd_speed = speed;
111 }
112 
113 /*
114 * @brief speed visualization
115 * @pre initialization of motor
116 * @post get speed value
117 */
119 {
120  return mc_cmd_speed;
121 }
122 
123 /*
124 * @brief direction modification
125 * @pre initialization of motor
126 * @post new value of direction
127 */
128 void mci_forward(void)
129 {
130  mci_direction = CW;
131 }
132 
133 /*
134 * @brief direction modification
135 * @pre initialization of motor
136 * @post new value of direction
137 */
138 void mci_backward(void)
139 {
140  mci_direction = CCW;
141 }
142 
143 /*
144 * @brief direction visualization
145 * @pre initialization of motor
146 * @post get direction value
147 */
149 {
150  return mci_direction;
151 }
152 
158 void mc_set_motor_measured_speed(U8 measured_speed)
159 {
160  mc_measured_speed = measured_speed;
161 }
162 
170 {
171  return mc_measured_speed;
172 }
173 
180 {
181  return mci_measured_current/64;
182 }
183 
189 void mci_store_measured_current(U16 current)
190 {
191  mci_measured_current = ((63*mci_measured_current)+(64*current))>>6;
192 }
193 
200 {
201  return mc_potentiometer_value;
202 }
203 
209 void mc_set_potentiometer_value(U8 potentiometer)
210 {
211  mc_potentiometer_value = potentiometer;
212 }
213 
214 void mci_set_speed(U16 speed)
215 {
216  mci_set_motor_speed((U8)speed);
217 }
void mc_switch_commutation(U8 position)
Set the Switching Commutation value on outputs according to sensor or estimation position.
Definition: mc_drv.c:226
U8 mc_measured_speed
Motor Input parameter to get the motor speed.
Definition: mc_interface.c:24
void mci_set_motor_speed(U8 speed)
Definition: mc_interface.c:108
void mci_set_speed(U16 speed)
Definition: mc_interface.c:214
U16 mci_get_measured_current(void)
Get the current measured in the motor.
Definition: mc_interface.c:179
U8 mc_get_motor_direction(void)
Definition: mc_interface.c:148
Bool mc_motor_is_running(void)
get the motor state
Definition: mc_interface.c:70
Bool mci_direction
User Input parameter to set motor direction.
Definition: mc_interface.c:20
void mci_retry_run(void)
mci_retry_run retry to run if speed is null
Definition: mc_interface.c:55
void mc_duty_cycle(U8 level)
Set the duty cycle values in the PSC according to the value calculate by the regulation loop...
Definition: mc_drv.c:212
void mci_stop(void)
mci_stop stop the motor And reset the speed measured value.
Definition: mc_interface.c:81
void mc_init()
use to init programm
Definition: mc_interface.c:92
void mci_run(void)
mci_run run the motor with parameter
Definition: mc_interface.c:34
U8 mc_potentiometer_value
Motor Input to set the motor speed.
Definition: mc_interface.c:26
Bool mci_run_stop
User Input parameter to launch or stop the motor.
Definition: mc_interface.c:21
U8 mc_get_hall(void)
Get the value of hall sensors (1 to 6)
Definition: mc_drv.c:179
void mc_set_potentiometer_value(U8 potentiometer)
Set the &#39;mc_potentiometer_value&#39; variable with the potentiometer value.
Definition: mc_interface.c:209
void mci_backward(void)
Definition: mc_interface.c:138
void mci_store_measured_current(U16 current)
Set the variable &#39;mc_measured_current&#39; for initialization.
Definition: mc_interface.c:189
void mc_set_motor_measured_speed(U8 measured_speed)
set Measured of speed (for initialization)
Definition: mc_interface.c:158
U8 mc_get_Duty_Cycle()
set type of regulation
Definition: mc_control.c:197
void mc_disable_during_inrush(void)
the purpose of this function is to disable the overcurrent detection during startup (inrush current...
Definition: mc_drv.c:422
void mc_regulation_loop()
launch speed control or no regulation
Definition: mc_control.c:159
void mci_forward(void)
Definition: mc_interface.c:128
U8 mci_get_measured_speed(void)
Measured of speed.
Definition: mc_interface.c:169
U32 mci_measured_current
Motor Input parameter to get the motor current.
Definition: mc_interface.c:25
void mc_init_HW(void)
init HW
Definition: mc_drv.c:95
U8 mc_get_motor_speed(void)
Definition: mc_interface.c:118
U8 mc_get_potentiometer_value(void)
Get the potentiometer value.
Definition: mc_interface.c:199
U8 mc_cmd_speed
User Input parameter to set motor speed.
Definition: mc_interface.c:22