| BLDC control on ATAVRMC303 with ATxMega128A1

Functions | Variables
mc_drv.c File Reference

,v More...

`#include "config.h"`
`#include "mc_drv.h"`
`#include "mc_interface.h"`
`#include "mc_control.h"`
`#include "adc\adc_drv.h"`
`#include "dac\Dac_drv.h"`
`#include "pll\pll_drv.h"`
`#include "comparator\comparator_drv.h"`
`#include "awex_driver.h"`
`#include "TC_driver.h"`
`#include "hires_driver.h"`
`#include "adc_driver.h"`
Include dependency graph for mc_drv.c:

Go to the source code of this file.

## Functions
void | ADC_Init ()
void | ConfigDTI (U8 deadTime)
void | init_amplifier_1 (void)
| init Amplifier 1 More...
__interrupt void | launch_sampling_period (void)
| Launch the regulation loop (see main.c) . More...
void | mc_ADC_Scheduler (void)
| Launch the scheduler for the ADC. More...
void | mc_disable_during_inrush (void)
| the purpose of this function is to disable the overcurrent detection during startup (inrush current) More...
void | mc_duty_cycle (U8 level)
| Set the duty cycle values in the PSC according to the value calculate by the regulation loop. More...
void | mc_estimation_speed (void)
| estimation speed More...
U8 | mc_get_hall (void)
| Get the value of hall sensors (1 to 6) More...
__interrupt void | mc_hall_a (void)
| External interruption Sensor (A) mode toggle. More...
void | mc_init_HW (void)
| init HW More...
void | mc_init_timer0 (void)
| Timer 0 Configuration The timer 0 is used to generate an IT when an overflow occurs. More...
void | mc_init_timer1 (void)
| timer 1 Configuration Use to generate a 250us activation for sampling speed regulation More...
void | mc_inrush_task (void)
| the purpose of this function is to manage the delay used when the overcurrent detection is disabled More...
void | mc_set_Over_Current (U8 Level)
| Set the Over Current threshold. More...
void | mc_switch_commutation (U8 position)
| Set the Switching Commutation value on outputs according to sensor or estimation position. More...
__interrupt void | ovfl_timer0 (void)
| Timer0 Overflow for speed measurement. More...
void | PWM_Init (unsigned int OCRnRB)
| Initialization of PWM generator PSC0. More...

## Variables
char | ADC_State = FREE
U16 | average = 0
U8 | count = 1
Bool | current_EOC = FALSE
Bool | g_mc_read_enable = FALSE
Bool | g_tick = FALSE
| Use for control the sampling period value. More...
Bool | hall1_old_val = 1
U16 | inrush_delay = 0
Bool | inrush_mask_flag = FALSE
volatile char | offset =0
U8 | ovf_timer = 0
char | State = CONV_INIT

## Detailed Description

,v

Copyright (c) 2008 Atmel.

Motor Control Driver level :

- Motor Control Init
- PWM update
- PWM -> output switching
- interrupts
  Version
    1.19

Definition in file mc_drv.c.

## Function Documentation

## ◆ ADC_Init()

void ADC_Init | ( |  | ) |

Definition at line 53 of file mc_drv.c.

References ADC_CalibrationValues_Set(), ADC_Ch_InputMode_and_Gain_Config, ADC_Ch_InputMux_Config, ADC_ConvMode_and_Resolution_Config, ADC_Enable, ADC_FreeRunning_Enable, ADC_Offset_Get(), ADC_Prescaler_Config, ADC_Referance_Config, ADC_Wait_8MHz(), and offset.

Referenced by mc_init_HW().

54 {
55 /* Move stored calibration values to ADC B. */
56 ADC_CalibrationValues_Set(&ADCB);
57
58 /* Get offset value for ADC B. */
59 offset = ADC_Offset_Get(&ADCB);
60
61 /* Set up ADC B to have signed conversion mode and 12 bit resolution. */
62 ADC_ConvMode_and_Resolution_Config(&ADCB, true, ADC_RESOLUTION_12BIT_gc);
63
64 /* Sample rate is CPUFREQ/16. Allow time for storing data. */
65 ADC_Prescaler_Config(&ADCB, ADC_PRESCALER_DIV16_gc);
66
67 /* Set referance voltage on ADC B to be VCC-0.6 V.*/
68 ADC_Referance_Config(&ADCB, ADC_REFSEL_INTVCC_gc);
69
70 /* Setup channel 0, 1, 2 and 3 to have single ended input. */
71 ADC_Ch_InputMode_and_Gain_Config(&ADCB.CH0,
72 ADC_CH_INPUTMODE_SINGLEENDED_gc,
73 ADC_CH_GAIN_1X_gc);
74
75 /* Set input to the channels in ADC B to be PIN 0. */
76 ADC_Ch_InputMux_Config(&ADCB.CH0, ADC_CH_MUXPOS_PIN0_gc, ADC_CH_MUXNEG_PIN0_gc);
77
78 /* Enable ADC B with free running mode, VCC reference and signed conversion.*/
79 ADC_Enable(&ADCB);
80
81 /* Wait until common mode voltage is stable. Default clk is 2MHz and
82 * therefore below the maximum frequency to use this function. */
83 ADC_Wait_8MHz(&ADCB);
84
85 /* Enable free running mode. */
86 ADC_FreeRunning_Enable(&ADCB);
87
88 }
ADC_Offset_Get
uint8_t ADC_Offset_Get(ADC_t *adc)
This function get the offset of the ADC.
Definition: adc_driver.c:241
ADC_CalibrationValues_Set
void ADC_CalibrationValues_Set(ADC_t *adc)
This function get the calibration data from the production calibration.
Definition: adc_driver.c:77
ADC_ConvMode_and_Resolution_Config
#define ADC_ConvMode_and_Resolution_Config(_adc, _signedMode, _resolution)
This macro set the conversion mode and resolution in the selected adc.
Definition: adc_driver.h:110
ADC_Ch_InputMode_and_Gain_Config
#define ADC_Ch_InputMode_and_Gain_Config(_adc_ch, _inputMode, _gain)
This macro configures the input mode and gain to a specific virtual channel.
Definition: adc_driver.h:197
ADC_Prescaler_Config
#define ADC_Prescaler_Config(_adc, _div)
This macro set the prescaler factor in the selected adc.
Definition: adc_driver.h:127
ADC_Ch_InputMux_Config
#define ADC_Ch_InputMux_Config(_adc_ch, _posInput, _negInput)
This macro configures the Positiv and negativ inputs.
Definition: adc_driver.h:212
ADC_Referance_Config
#define ADC_Referance_Config(_adc, _convRef)
This macro set the conversion referance in the selected adc.
Definition: adc_driver.h:137
ADC_FreeRunning_Enable
#define ADC_FreeRunning_Enable(_adc)
This macro enables the Free Running mode in the selected adc.
Definition: adc_driver.h:246
ADC_Wait_8MHz
void ADC_Wait_8MHz(ADC_t *adc)
This function waits until the adc common mode is settled.
Definition: adc_driver.c:182
ADC_Enable
#define ADC_Enable(_adc)
This macro enables the selected adc.
Definition: adc_driver.h:83
offset
volatile char offset
Definition: mc_drv.c:47
Here is the call graph for this function:

## ◆ ConfigDTI()

void ConfigDTI | ( | U8 | deadTime | ) |

Definition at line 142 of file mc_drv.c.

References AWEX_EnableDeadTimeInsertion(), AWEX_SetDeadTimesSymmetricalUnbuffered, and AWEX_SetOutputOverrideValue.

Referenced by PWM_Init().

143 {
144 /* Configure dead time insertion. */
145 AWEX_EnableDeadTimeInsertion( &AWEXC, AWEX_DTICCAEN_bm |AWEX_DTICCBEN_bm|AWEX_DTICCCEN_bm );
146 AWEX_SetOutputOverrideValue( AWEXC, 0xFF );
147 AWEX_SetDeadTimesSymmetricalUnbuffered( AWEXC, deadTime );
148 }
AWEX_SetDeadTimesSymmetricalUnbuffered
#define AWEX_SetDeadTimesSymmetricalUnbuffered(_awex, _deadTime)
This macro sets an equal dead time for high and low side.
Definition: awex_driver.h:147
AWEX_EnableDeadTimeInsertion
void AWEX_EnableDeadTimeInsertion(AWEX_t *awex, uint8_t enableMask)
Enable Dead Time Insertion.
Definition: awex_driver.c:73
AWEX_SetOutputOverrideValue
#define AWEX_SetOutputOverrideValue(_awex, _overrideValue)
This macro sets an output override value.
Definition: awex_driver.h:100
Here is the call graph for this function:

## ◆ init_amplifier_1()

void init_amplifier_1 | ( | void |  | ) |

init Amplifier 1

Precondition
  none

Postcondition
  initialization of hardware

Definition at line 130 of file mc_drv.c.

131 {
132 // AMP1CSR = (1<<AMP1EN) /* amplifier enable */ \
133 // | (1<<AMP1G1)|(0<<AMP1G0) /* gain = 20 */ \
134 // | (0<<AMP1TS1)|(1<<AMP1TS0) /* clock from PSC0 */ ;
135 }

## ◆ launch_sampling_period()

__interrupt void launch_sampling_period | ( | void |  | ) |

Launch the regulation loop (see main.c) .

Precondition
  configuration of timer 1 registers

Postcondition
  g_tick use in main.c for regulation loop

Definition at line 296 of file mc_drv.c.

References g_tick.

297 {
298 g_tick = TRUE;
299 }
g_tick
Bool g_tick
Use for control the sampling period value.
Definition: mc_drv.c:39

## ◆ mc_ADC_Scheduler()

void mc_ADC_Scheduler | ( | void |  | ) |

Launch the scheduler for the ADC.

Precondition
  none

Postcondition
  Get Channel 6 and 12 results for Potentiometer and current values.

Definition at line 388 of file mc_drv.c.

References ADC_Ch_Conversion_Complete, ADC_ResultCh_GetWord(), mc_set_potentiometer_value(), and offset.

Referenced by main().

389 {
390 do{
391 /* If the conversion on the ADCB channel 0 never is
392 * complete this will be a deadlock. */
393 }while(!ADC_Ch_Conversion_Complete(&ADCB.CH0));
394 unsigned int value;
395 value = ADC_ResultCh_GetWord(&ADCB.CH0,offset);
396
397 value = ((value)>>4);
398 value = value + 140;
399 if ( (value&0xFF) < 150) value = 0;
400
401 //value = ((value>>2)&0x00FF);
402 //value = (0xFF - value)*2;
403 mc_set_potentiometer_value(value);
404 }
ADC_ResultCh_GetWord
uint16_t ADC_ResultCh_GetWord(ADC_CH_t *adc_ch, uint8_t offset)
This function clears the interrupt flag and returns the coversion result.
Definition: adc_driver.c:98
ADC_Ch_Conversion_Complete
#define ADC_Ch_Conversion_Complete(_adc_ch)
This macro returns the channel conversion complete flag..
Definition: adc_driver.h:222
mc_set_potentiometer_value
void mc_set_potentiometer_value(U8 potentiometer)
Set the &#39;mc_potentiometer_value&#39; variable with the potentiometer value.
Definition: mc_interface.c:209
offset
volatile char offset
Definition: mc_drv.c:47
Here is the call graph for this function:

## ◆ 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 at line 422 of file mc_drv.c.

References inrush_delay, and inrush_mask_flag.

Referenced by mci_retry_run(), and mci_run().

423 {
424 inrush_delay = (U16) 1000;
425 inrush_mask_flag = TRUE;
426 //Disable_over_current();
427 }
inrush_mask_flag
Bool inrush_mask_flag
Definition: mc_drv.c:35
inrush_delay
U16 inrush_delay
Definition: mc_drv.c:36

## ◆ 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 at line 212 of file mc_drv.c.

References TC_SetCompareA, TC_SetCompareB, and TC_SetCompareC.

Referenced by mc_switch_commutation(), mci_retry_run(), and mci_run().

213 {
214 /* Output new compare value. */
215 TC_SetCompareA( &TCC0, level );
216 TC_SetCompareB( &TCC0, level );
217 TC_SetCompareC( &TCC0, level );
218 }
TC_SetCompareA
#define TC_SetCompareA(_tc, _compareValue)
Set new compare value for compare channel A. ( Double buffered )
Definition: TC_driver.h:169
TC_SetCompareB
#define TC_SetCompareB(_tc, _compareValue)
Set new compare value for compare channel B. ( Double buffered )
Definition: TC_driver.h:180
TC_SetCompareC
#define TC_SetCompareC(_tc, _compareValue)
Set new compare value for compare channel C. ( Double buffered )
Definition: TC_driver.h:193

## ◆ mc_estimation_speed()

void mc_estimation_speed | ( | void |  | ) |

estimation speed

Precondition
  configuration of timer 0
  and define or not AVERAGE_SPEED_MEASURE in config_motor.h

Postcondition
  new value for real speed

Definition at line 342 of file mc_drv.c.

References average, count, g_mc_read_enable, K_SPEED, mc_set_motor_measured_speed(), and n_SAMPLE.

Referenced by mc_hall_a().

343 {
344 U16 timer_value;
345 U32 new_measured_speed;
346
347 if (g_mc_read_enable==TRUE)
348 {
349 // Two 8 bits variables are use to simulate a 16 bits timers
350 timer_value = TCD0.CNT/2;
351
352 if (timer_value == 0) {timer_value += 1 ;} // warning DIV by 0
353 new_measured_speed = K_SPEED / timer_value;
354 if(new_measured_speed > 255) new_measured_speed = 255; // Variable saturation
355
356
357 #ifdef AVERAGE_SPEED_MEASURE
358 // To avoid noise an average is realized on 8 samples
359 average += new_measured_speed;
360 if(count >= n_SAMPLE)
361 {
362 count = 1;
363 mc_set_motor_measured_speed(average >> 3);
364 average = 0;
365 }
366 else count++;
367 #else
368 // else get the real speed
369 mc_set_motor_measured_speed(new_measured_speed);
370 #endif
371
372 // Reset Timer 0 register and variables
373 TCD0.CNT = 0x00;
374 g_mc_read_enable=FALSE;
375 }
376 }
g_mc_read_enable
Bool g_mc_read_enable
Definition: mc_drv.c:38
count
U8 count
Definition: mc_drv.c:31
average
U16 average
Definition: mc_drv.c:32
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
K_SPEED
#define K_SPEED
Definition: config_motor.h:82
n_SAMPLE
#define n_SAMPLE
Definition: config_motor.h:43
Here is the call graph for this function:

## ◆ mc_get_hall()

U8 mc_get_hall | ( | void |  | ) |

Get the value of hall sensors (1 to 6)

Parameters

  return | an unsigned char value of hall sensor

Precondition
  configuration of port PB and PD

Postcondition
  new value of position

Definition at line 179 of file mc_drv.c.

References HALL_SENSOR_VALUE.

Referenced by mci_retry_run(), and mci_run().

180 {
181 return HALL_SENSOR_VALUE();
182 }
HALL_SENSOR_VALUE
#define HALL_SENSOR_VALUE()
Definition: mc_drv.h:53

## ◆ mc_hall_a()

__interrupt void mc_hall_a | ( | void |  | ) |

External interruption Sensor (A) mode toggle.

Precondition
  configuration of external interruption (initialization)

Postcondition
  New value in Hall variable

Definition at line 191 of file mc_drv.c.

References g_mc_read_enable, hall1_old_val, HALL_SENSOR_VALUE, mc_estimation_speed(), and mc_switch_commutation().

192 {
193 mc_switch_commutation(HALL_SENSOR_VALUE());
194
195 //estimation speed on rising edge of Hall_A
196 if ((hall1_old_val == 0) && (PORTE.IN & PIN0_bm))
197 {
198 mc_estimation_speed();
199 g_mc_read_enable=FALSE; // Wait 1 period
200 }
201 else
202 {
203 g_mc_read_enable=TRUE;
204 }
205 hall1_old_val = (PORTE.IN & PIN0_bm);
206 }
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
g_mc_read_enable
Bool g_mc_read_enable
Definition: mc_drv.c:38
hall1_old_val
Bool hall1_old_val
Definition: mc_drv.c:40
HALL_SENSOR_VALUE
#define HALL_SENSOR_VALUE()
Definition: mc_drv.h:53
mc_estimation_speed
void mc_estimation_speed(void)
estimation speed
Definition: mc_drv.c:342
Here is the call graph for this function:

## ◆ mc_init_HW()

void mc_init_HW | ( | void |  | ) |

init HW

Precondition
  none

Postcondition
  initialization of hardware

Definition at line 95 of file mc_drv.c.

References ADC_Init(), mc_init_timer0(), mc_init_timer1(), and PWM_Init().

Referenced by mc_init().

97 {
98
99 //Do not modify PSCOUT Configuration
100 // PORT C :
101 PORTC.DIRSET = (PIN0_bm | PIN1_bm | PIN2_bm | PIN3_bm | PIN4_bm | PIN5_bm);
102 PORTC.OUTCLR = (PIN0_bm | PIN1_bm | PIN2_bm | PIN3_bm | PIN4_bm | PIN5_bm);
103
104 // Hall sensor input pull up activation
105 PORTE.DIRCLR = (PIN0_bm | PIN1_bm | PIN2_bm);
106
107 //Initialization of AT90PWM3 External Interrupts
108 PORTE.INTCTRL = PORT_INT0LVL_LO_gc;
109 PORTE.INT0MASK = (PIN0_bm | PIN1_bm | PIN2_bm);
110 PORTCFG.MPCMASK = (PIN0_bm | PIN1_bm | PIN2_bm);
111 PORTE.PIN0CTRL = PORT_ISC_BOTHEDGES_gc;
112
113
114 // In Center Aligned Mode :
115 // => PSCx_Init(Period_Half, Dutyx0_Half, Synchro, Dutyx1_Half)
116 PWM_Init(255);
117
118 mc_init_timer0();
119 mc_init_timer1();
120
121 ADC_Init();
122
123 }
mc_init_timer1
void mc_init_timer1(void)
timer 1 Configuration Use to generate a 250us activation for sampling speed regulation ...
Definition: mc_drv.c:283
ADC_Init
void ADC_Init()
Definition: mc_drv.c:53
mc_init_timer0
void mc_init_timer0(void)
Timer 0 Configuration The timer 0 is used to generate an IT when an overflow occurs.
Definition: mc_drv.c:313
PWM_Init
void PWM_Init(unsigned int OCRnRB)
Initialization of PWM generator PSC0.
Definition: mc_drv.c:153
Here is the call graph for this function:

## ◆ mc_init_timer0()

void mc_init_timer0 | ( | void |  | ) |

Timer 0 Configuration The timer 0 is used to generate an IT when an overflow occurs.

Precondition
  None

Postcondition
  Timer0 initialized.

Definition at line 313 of file mc_drv.c.

Referenced by mc_init_HW().

314 {
315 TCD0.PER = 0xFFFF;
316 TCD0.INTCTRLA = TC_OVFINTLVL_LO_gc;
317 TCD0.CTRLA = TC_CLKSEL_DIV256_gc;
318 }

## ◆ mc_init_timer1()

void mc_init_timer1 | ( | void |  | ) |

timer 1 Configuration Use to generate a 250us activation for sampling speed regulation

Precondition
  None

Postcondition
  An interrupt all 256us

Definition at line 283 of file mc_drv.c.

Referenced by mc_init_HW().

284 {
285 TCD1.PER = 8000;
286 TCD1.INTCTRLA = TC_OVFINTLVL_LO_gc;
287 TCD1.CTRLA = TC_CLKSEL_DIV1_gc;
288 }

## ◆ mc_inrush_task()

void mc_inrush_task | ( | void |  | ) |

the purpose of this function is to manage the delay
used when the overcurrent detection is disabled

Definition at line 431 of file mc_drv.c.

References inrush_delay, and inrush_mask_flag.

Referenced by main().

432 {
433 if (inrush_mask_flag == TRUE)
434 {
435 if (inrush_delay-- == 0)
436 {
437 inrush_mask_flag = FALSE;
438 // Enable_over_current();
439 }
440 }
441 }
inrush_mask_flag
Bool inrush_mask_flag
Definition: mc_drv.c:35
inrush_delay
U16 inrush_delay
Definition: mc_drv.c:36

## ◆ mc_set_Over_Current()

void mc_set_Over_Current | ( | U8 | Level | ) |

Set the Over Current threshold.

Precondition
  DAC initialization

Postcondition
  the Over Current threshold is set.

Definition at line 415 of file mc_drv.c.

416 {
417 //Set_dac_8_bits(Level);
418 }

## ◆ mc_switch_commutation()

void mc_switch_commutation | ( | U8 | position | ) |

Set the Switching Commutation value on outputs according to sensor or estimation position.

Parameters

  position | (1 to 6) and direction (FORWARD or BACKWARD)

Definition at line 226 of file mc_drv.c.

References CCW, HS_001, HS_010, HS_011, HS_100, HS_101, HS_110, mc_duty_cycle(), mc_get_Duty_Cycle(), mc_get_motor_direction(), mc_get_motor_speed(), mc_motor_is_running(), Set_none, Set_Q1Q4, Set_Q1Q6, Set_Q3Q2, Set_Q3Q6, Set_Q5Q2, and Set_Q5Q4.

Referenced by mc_hall_a(), mci_retry_run(), and mci_run().

227 {
228 // get the motor direction to commute the right switches.
229 char direction = mc_get_motor_direction();
230
231 // Switches are commuted only if the user start the motor and
232 // the speed consign is different from 0.
233 if ((mc_motor_is_running()) && (mc_get_motor_speed()!=0))
234 {
235 mc_duty_cycle(mc_get_Duty_Cycle());
236 switch(position)
237 {
238 // cases according to rotor position
239 case HS_001: if (direction==CCW) {Set_Q1Q6();}
240 else {Set_Q5Q2();}
241 break;
242
243 case HS_101: if (direction==CCW) {Set_Q3Q6();}
244 else {Set_Q5Q4();}
245 break;
246
247 case HS_100: if (direction==CCW) {Set_Q3Q2();}
248 else {Set_Q1Q4();}
249 break;
250
251 case HS_110: if (direction==CCW) {Set_Q5Q2();}
252 else {Set_Q1Q6();}
253 break;
254
255 case HS_010: if (direction==CCW) {Set_Q5Q4();}
256 else {Set_Q3Q6();}
257 break;
258
259 case HS_011: if (direction==CCW) {Set_Q1Q4();}
260 else {Set_Q3Q2();}
261 break;
262 default : break;
263 }
264 }
265 else
266 {
267 Set_none(); // all switches are switched OFF
268 }
269 }
Set_Q1Q6
#define Set_Q1Q6()
Definition: mc_drv.h:70
Set_Q5Q2
#define Set_Q5Q2()
Definition: mc_drv.h:76
mc_get_motor_direction
U8 mc_get_motor_direction(void)
Definition: mc_interface.c:148
Set_none
#define Set_none()
Definition: mc_drv.h:66
mc_motor_is_running
Bool mc_motor_is_running(void)
get the motor state
Definition: mc_interface.c:70
Set_Q3Q2
#define Set_Q3Q2()
Definition: mc_drv.h:72
Set_Q3Q6
#define Set_Q3Q6()
Definition: mc_drv.h:74
HS_101
Definition: config_motor.h:23
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
HS_110
Definition: config_motor.h:23
Set_Q5Q4
#define Set_Q5Q4()
Definition: mc_drv.h:78
mc_get_Duty_Cycle
U8 mc_get_Duty_Cycle()
set type of regulation
Definition: mc_control.c:197
HS_010
Definition: config_motor.h:23
HS_001
Definition: config_motor.h:23
Set_Q1Q4
#define Set_Q1Q4()
Definition: mc_drv.h:68
HS_100
Definition: config_motor.h:23
CCW
Definition: config_motor.h:34
mc_get_motor_speed
U8 mc_get_motor_speed(void)
Definition: mc_interface.c:118
HS_011
Definition: config_motor.h:23
Here is the call graph for this function:

## ◆ ovfl_timer0()

__interrupt void ovfl_timer0 | ( | void |  | ) |

Timer0 Overflow for speed measurement.

Precondition
  configuration of timer 0

Postcondition
  generate an overflow when the motor turns too slowly

Definition at line 327 of file mc_drv.c.

References mc_motor_is_running(), mc_set_motor_measured_speed(), and mci_retry_run().

328 {
329 mc_set_motor_measured_speed(0);
330 //if the motor was turning and no stop order
331 // was given, motor run automatically.
332 if(mc_motor_is_running())mci_retry_run();
333
334 }
mc_motor_is_running
Bool mc_motor_is_running(void)
get the motor state
Definition: mc_interface.c:70
mci_retry_run
void mci_retry_run(void)
mci_retry_run retry to run if speed is null
Definition: mc_interface.c:55
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
Here is the call graph for this function:

## ◆ PWM_Init()

void PWM_Init | ( | unsigned int | OCRnRB | ) |

Initialization of PWM generator PSC0.

Definition at line 153 of file mc_drv.c.

References AWEX_EnableCommonWaveformChannelMode, AWEX_SetOutputOverrideValue, and ConfigDTI().

Referenced by mc_init_HW().

154 {
155 ConfigDTI( 3 );
156 TCC0.PER = OCRnRB;
157 TCC0.CTRLB = TC0_CCAEN_bm | TC0_CCBEN_bm | TC0_CCCEN_bm | TC0_CCDEN_bm| TC_WGMODE_DS_T_gc;
158 TCC0.INTCTRLA = TC_OVFINTLVL_LO_gc;
159 TCC0.CTRLA = TC_CLKSEL_DIV4_gc;
160
161 AWEX_SetOutputOverrideValue( AWEXC, 0 );
162 AWEX_EnableCommonWaveformChannelMode(AWEXC);
163 }
AWEX_EnableCommonWaveformChannelMode
#define AWEX_EnableCommonWaveformChannelMode(_awex)
This macro enables the Common Waveform Channel mode.
Definition: awex_driver.h:71
ConfigDTI
void ConfigDTI(U8 deadTime)
Definition: mc_drv.c:142
AWEX_SetOutputOverrideValue
#define AWEX_SetOutputOverrideValue(_awex, _overrideValue)
This macro sets an output override value.
Definition: awex_driver.h:100
Here is the call graph for this function:

## Variable Documentation

## ◆ ADC_State

char ADC_State = FREE

Definition at line 45 of file mc_drv.c.

## ◆ average

U16 average = 0

Definition at line 32 of file mc_drv.c.

Referenced by mc_estimation_speed().

## ◆ count

U8 count = 1

Definition at line 31 of file mc_drv.c.

Referenced by mc_estimation_speed().

## ◆ current_EOC

Bool current_EOC = FALSE

Definition at line 42 of file mc_drv.c.

## ◆ g_mc_read_enable

Bool g_mc_read_enable = FALSE

Definition at line 38 of file mc_drv.c.

Referenced by mc_estimation_speed(), and mc_hall_a().

## ◆ g_tick

Bool g_tick = FALSE

Use for control the sampling period value.

Definition at line 39 of file mc_drv.c.

Referenced by launch_sampling_period(), and main().

## ◆ hall1_old_val

Bool hall1_old_val = 1

Definition at line 40 of file mc_drv.c.

Referenced by mc_hall_a().

## ◆ inrush_delay

U16 inrush_delay = 0

Definition at line 36 of file mc_drv.c.

Referenced by mc_disable_during_inrush(), and mc_inrush_task().

## ◆ inrush_mask_flag

Bool inrush_mask_flag = FALSE

Definition at line 35 of file mc_drv.c.

Referenced by mc_disable_during_inrush(), and mc_inrush_task().

## ◆ offset

volatile char offset =0

Definition at line 47 of file mc_drv.c.

Referenced by ADC_Init(), ADC_Offset_Get(), ADC_ResultCh_GetLowByte(), and mc_ADC_Scheduler().

## ◆ ovf_timer

U8 ovf_timer = 0

Definition at line 33 of file mc_drv.c.

## ◆ State

char State = CONV_INIT

Definition at line 44 of file mc_drv.c.