| BLDC control on ATAVRMC303 with ATxMega128A1

Functions | Variables
mc_interface.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Functions
U8 | mc_get_motor_direction (void)
U8 | mc_get_motor_speed (void)
U8 | mc_get_potentiometer_value (void)
| Get the potentiometer value. More...
void | mc_init (void)
| use to init programm More...
Bool | mc_motor_is_running (void)
| get the motor state More...
void | mc_set_motor_measured_speed (U8 measured_speed)
| set Measured of speed (for initialization) More...
void | mc_set_potentiometer_value (U8 potentiometer)
| Set the 'mc_potentiometer_value' variable with the potentiometer value. More...
void | mci_backward (void)
void | mci_forward (void)
U16 | mci_get_measured_current (void)
| Get the current measured in the motor. More...
U8 | mci_get_measured_speed (void)
| Measured of speed. More...
void | mci_retry_run (void)
| mci_retry_run retry to run if speed is null More...
void | mci_run (void)
| mci_run run the motor with parameter More...
void | mci_set_motor_speed (U8 speed)
void | mci_set_speed (U16 speed)
void | mci_stop (void)
| mci_stop stop the motor And reset the speed measured value. More...
void | mci_store_measured_current (U16 current)
| Set the variable 'mc_measured_current' for initialization. More...

## Variables
Bool | mci_direction
| User Input parameter to set motor direction. More...
Bool | mci_run_stop
| User Input parameter to launch or stop the motor. More...

## Function Documentation

## ◆ mc_get_motor_direction()

U8 mc_get_motor_direction | ( | void |  | ) |

Definition at line 148 of file mc_interface.c.

References mci_direction.

Referenced by mc_switch_commutation().

149 {
150 return mci_direction;
151 }
mci_direction
Bool mci_direction
User Input parameter to set motor direction.
Definition: mc_interface.c:20

## ◆ mc_get_motor_speed()

U8 mc_get_motor_speed | ( | void |  | ) |

Definition at line 118 of file mc_interface.c.

References mc_cmd_speed.

Referenced by mc_regulation_loop(), and mc_switch_commutation().

119 {
120 return mc_cmd_speed;
121 }
mc_cmd_speed
U8 mc_cmd_speed
User Input parameter to set motor speed.
Definition: mc_interface.c:22

## ◆ mc_get_potentiometer_value()

U8 mc_get_potentiometer_value | ( | void |  | ) |

Get the potentiometer value.

Precondition
  Launch ADC scheduler

Postcondition
  Get ADC Channel 6 result (Potentiometer value on 8bits).

Definition at line 199 of file mc_interface.c.

References mc_potentiometer_value.

Referenced by main(), mc_regulation_loop(), and UpdateScreen().

200 {
201 return mc_potentiometer_value;
202 }
mc_potentiometer_value
U8 mc_potentiometer_value
Motor Input to set the motor speed.
Definition: mc_interface.c:26

## ◆ mc_init()

void mc_init | ( | void |  | ) |

use to init programm

Parameters

Definition at line 92 of file mc_interface.c.

References mc_init_HW(), mc_set_motor_measured_speed(), mci_forward(), mci_set_motor_speed(), and mci_stop().

Referenced by main().

93 {
94 mc_init_HW();
95 Enable_interrupt();
96
97 mci_stop();
98 mci_forward();
99 mci_set_motor_speed(0);
100 mc_set_motor_measured_speed(0);
101 }
mci_set_motor_speed
void mci_set_motor_speed(U8 speed)
Definition: mc_interface.c:108
mci_stop
void mci_stop(void)
mci_stop stop the motor And reset the speed measured value.
Definition: mc_interface.c:81
mc_set_motor_measured_speed
void mc_set_motor_measured_speed(U8 measured_speed)
set Measured of speed (for initialization)
Definition: mc_interface.c:158
mci_forward
void mci_forward(void)
Definition: mc_interface.c:128
mc_init_HW
void mc_init_HW(void)
init HW
Definition: mc_drv.c:95
Here is the call graph for this function:

## ◆ mc_motor_is_running()

Bool mc_motor_is_running | ( | void |  | ) |

get the motor state

Parameters

Definition at line 70 of file mc_interface.c.

References mci_run_stop.

Referenced by mc_switch_commutation(), and ovfl_timer0().

71 {
72 return mci_run_stop;
73 }
mci_run_stop
Bool mci_run_stop
User Input parameter to launch or stop the motor.
Definition: mc_interface.c:21

## ◆ mc_set_motor_measured_speed()

void mc_set_motor_measured_speed | ( | U8 | measured_speed | ) |

set Measured of speed (for initialization)

Precondition
  none

Postcondition
  mc_measured_speed initialized

Definition at line 158 of file mc_interface.c.

References mc_measured_speed.

Referenced by mc_estimation_speed(), mc_init(), and ovfl_timer0().

159 {
160 mc_measured_speed = measured_speed;
161 }
mc_measured_speed
U8 mc_measured_speed
Motor Input parameter to get the motor speed.
Definition: mc_interface.c:24

## ◆ mc_set_potentiometer_value()

void mc_set_potentiometer_value | ( | U8 | potentiometer | ) |

Set the 'mc_potentiometer_value' variable with the potentiometer value.

Precondition
  Launch ADC scheduler

Postcondition
  'mc_potentiometer_value' set with the potentiometer value

Definition at line 209 of file mc_interface.c.

References mc_potentiometer_value.

Referenced by mc_ADC_Scheduler().

210 {
211 mc_potentiometer_value = potentiometer;
212 }
mc_potentiometer_value
U8 mc_potentiometer_value
Motor Input to set the motor speed.
Definition: mc_interface.c:26

## ◆ mci_backward()

void mci_backward | ( | void |  | ) |

Definition at line 138 of file mc_interface.c.

References CCW, and mci_direction.

Referenced by ushell_task().

139 {
140 mci_direction = CCW;
141 }
mci_direction
Bool mci_direction
User Input parameter to set motor direction.
Definition: mc_interface.c:20
CCW
Definition: config_motor.h:34

## ◆ mci_forward()

void mci_forward | ( | void |  | ) |

Definition at line 128 of file mc_interface.c.

References CW, and mci_direction.

Referenced by mc_init(), and ushell_task().

129 {
130 mci_direction = CW;
131 }
mci_direction
Bool mci_direction
User Input parameter to set motor direction.
Definition: mc_interface.c:20
CW
Definition: config_motor.h:34

## ◆ mci_get_measured_current()

U16 mci_get_measured_current | ( | void |  | ) |

Get the current measured in the motor.

Precondition
  Launch ADC scheduler

Postcondition
  Get ADC Channel 12 result (Current value on 8bits).

Definition at line 179 of file mc_interface.c.

References mci_measured_current.

Referenced by mc_control_current(), and ushell_task().

180 {
181 return mci_measured_current/64;
182 }
mci_measured_current
U32 mci_measured_current
Motor Input parameter to get the motor current.
Definition: mc_interface.c:25

## ◆ mci_get_measured_speed()

U8 mci_get_measured_speed | ( | void |  | ) |

Measured of speed.

Returns
  return value of speed (8 bits)

Precondition
  none

Postcondition
  none

Definition at line 169 of file mc_interface.c.

References mc_measured_speed.

Referenced by mc_control_speed(), UpdateScreen(), and ushell_task().

170 {
171 return mc_measured_speed;
172 }
mc_measured_speed
U8 mc_measured_speed
Motor Input parameter to get the motor speed.
Definition: mc_interface.c:24

## ◆ mci_retry_run()

void mci_retry_run | ( | void |  | ) |

mci_retry_run retry to run if speed is null

Parameters

Definition at line 55 of file mc_interface.c.

References mc_disable_during_inrush(), mc_duty_cycle(), mc_get_Duty_Cycle(), mc_get_hall(), mc_regulation_loop(), mc_switch_commutation(), and mci_run_stop.

Referenced by ovfl_timer0().

56 {
57 mci_run_stop = TRUE;
58 mc_regulation_loop();
59 mc_duty_cycle(mc_get_Duty_Cycle());
60 mc_switch_commutation(mc_get_hall());
61 mc_disable_during_inrush(); /* disable overcurrent during inrush */
62 }
mc_switch_commutation
void mc_switch_commutation(U8 position)
Set the Switching Commutation value on outputs according to sensor or estimation position.
Definition: mc_drv.c:226
mc_duty_cycle
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
mci_run_stop
Bool mci_run_stop
User Input parameter to launch or stop the motor.
Definition: mc_interface.c:21
mc_get_hall
U8 mc_get_hall(void)
Get the value of hall sensors (1 to 6)
Definition: mc_drv.c:179
mc_get_Duty_Cycle
U8 mc_get_Duty_Cycle()
set type of regulation
Definition: mc_control.c:197
mc_disable_during_inrush
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
mc_regulation_loop
void mc_regulation_loop()
launch speed control or no regulation
Definition: mc_control.c:159
Here is the call graph for this function:

## ◆ mci_run()

void mci_run | ( | void |  | ) |

mci_run run the motor with parameter

Parameters

Definition at line 34 of file mc_interface.c.

References mc_disable_during_inrush(), mc_duty_cycle(), mc_get_Duty_Cycle(), mc_get_hall(), mc_regulation_loop(), mc_switch_commutation(), and mci_run_stop.

Referenced by main(), and ushell_task().

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;
43 mc_regulation_loop();
44 mc_duty_cycle(mc_get_Duty_Cycle());
45 mc_switch_commutation(mc_get_hall());
46 mc_disable_during_inrush(); /* disable overcurrent during inrush */
47 }
mc_switch_commutation
void mc_switch_commutation(U8 position)
Set the Switching Commutation value on outputs according to sensor or estimation position.
Definition: mc_drv.c:226
mc_duty_cycle
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
mci_run_stop
Bool mci_run_stop
User Input parameter to launch or stop the motor.
Definition: mc_interface.c:21
mc_get_hall
U8 mc_get_hall(void)
Get the value of hall sensors (1 to 6)
Definition: mc_drv.c:179
mc_get_Duty_Cycle
U8 mc_get_Duty_Cycle()
set type of regulation
Definition: mc_control.c:197
mc_disable_during_inrush
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
mc_regulation_loop
void mc_regulation_loop()
launch speed control or no regulation
Definition: mc_control.c:159
Here is the call graph for this function:

## ◆ mci_set_motor_speed()

void mci_set_motor_speed | ( | U8 | speed | ) |

Definition at line 108 of file mc_interface.c.

References mc_cmd_speed.

Referenced by main(), mc_init(), and mci_set_speed().

109 {
110 mc_cmd_speed = speed;
111 }
mc_cmd_speed
U8 mc_cmd_speed
User Input parameter to set motor speed.
Definition: mc_interface.c:22

## ◆ mci_set_speed()

void mci_set_speed | ( | U16 | speed | ) |

Definition at line 214 of file mc_interface.c.

References mci_set_motor_speed().

Referenced by ushell_task().

215 {
216 mci_set_motor_speed((U8)speed);
217 }
mci_set_motor_speed
void mci_set_motor_speed(U8 speed)
Definition: mc_interface.c:108
Here is the call graph for this function:

## ◆ mci_stop()

void mci_stop | ( | void |  | ) |

mci_stop stop the motor And reset the speed measured value.

Precondition
  motor run (mci_run executed)

Postcondition
  motor stop

Definition at line 81 of file mc_interface.c.

References mci_run_stop.

Referenced by mc_init(), and ushell_task().

82 {
83 mci_run_stop=FALSE;
84 }
mci_run_stop
Bool mci_run_stop
User Input parameter to launch or stop the motor.
Definition: mc_interface.c:21

## ◆ mci_store_measured_current()

void mci_store_measured_current | ( | U16 | current | ) |

Set the variable 'mc_measured_current' for initialization.

Precondition
  none

Postcondition
  'mc_measured_current' set with the current value

Definition at line 189 of file mc_interface.c.

References mci_measured_current.

190 {
191 mci_measured_current = ((63*mci_measured_current)+(64*current))>>6;
192 }
mci_measured_current
U32 mci_measured_current
Motor Input parameter to get the motor current.
Definition: mc_interface.c:25

## Variable Documentation

## ◆ mci_direction

Bool mci_direction

User Input parameter to set motor direction.

Definition at line 20 of file mc_interface.c.

Referenced by mc_get_motor_direction(), mci_backward(), mci_forward(), UpdateScreen(), and ushell_task().

## ◆ mci_run_stop

Bool mci_run_stop

User Input parameter to launch or stop the motor.

Definition at line 21 of file mc_interface.c.

Referenced by mc_motor_is_running(), mci_retry_run(), mci_run(), mci_stop(), UpdateScreen(), and ushell_task().