BLDC control on ATAVRMC303 with ATxMega128A1
mc_drv.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define BUSY   1
 
#define Clear_EXT1()   (PORTB &= ~(1<<PB3))
 
#define Clear_EXT10()   (PORTD &= ~(1<<PD2))
 
#define Clear_EXT2()   (PORTB &= ~(1<<PB4))
 
#define Clear_EXT3()   (PORTC &= ~(1<<PC1))
 
#define Clear_EXT4()   (PORTC &= ~(1<<PC2))
 
#define Clear_EXT5()   (PORTB &= ~(1<<PB5))
 
#define Clear_EXT6()   (PORTE &= ~(1<<PE1))
 
#define Clear_EXT7()   (PORTD &= ~(1<<PD3))
 
#define Clear_EXT8()   (PORTD &= ~(1<<PD4))
 
#define Clear_EXT9()   (PORTE &= ~(1<<PE0))
 
#define Clear_Port_Q1()   (PORTC.OUTCLR = PIN5_bm)
 
#define Clear_Port_Q2()   (PORTC.OUTCLR = PIN4_bm)
 
#define Clear_Port_Q3()   (PORTC.OUTCLR = PIN3_bm)
 
#define Clear_Port_Q4()   (PORTC.OUTCLR = PIN2_bm)
 
#define Clear_Port_Q5()   (PORTC.OUTCLR = PIN1_bm)
 
#define Clear_Port_Q6()   (PORTC.OUTCLR = PIN0_bm)
 
#define CONV_CURRENT   2
 
#define CONV_INIT   0
 
#define CONV_POT   1
 
#define Disable_over_current()
 
#define Enable_over_current()
 
#define FREE   0
 
#define Get_EXT1()   ((PINB & (1<<PB3))>>PB3)
 
#define Get_EXT10()   ((PIND & (1<<PD2))>>PD2)
 
#define Get_EXT2()   ((PINB & (1<<PB4))>>PB4)
 
#define Get_EXT3()   ((PINC & (1<<PC1))>>PC1)
 
#define Get_EXT4()   ((PINC & (1<<PC2))>>PC2)
 
#define Get_EXT5()   ((PINB & (1<<PB5))>>PB5)
 
#define Get_EXT6()   ((PINE & (1<<PE1))>>PE1)
 
#define Get_EXT7()   ((PIND & (1<<PD3))>>PD3)
 
#define Get_EXT8()   ((PIND & (1<<PD4))>>PD4)
 
#define Get_EXT9()   ((PINE & (1<<PE0))>>PE0)
 
#define HALL_A()   (PORTE_INT0_vect)
 
#define HALL_SENSOR_VALUE()   (PORTE.IN & 0x07)
 
#define OUTPUT_ACTIVE_HIGH   (1<<POP0)
 
#define OUTPUT_ACTIVE_LOW   (0<<POP0)
 
#define output_disconnected   0x01
 
#define PRESC_DIV_BY_16   (1<<PPRE01)|(0<<PPRE00)
 
#define PRESC_DIV_BY_4   (0<<PPRE01)|(1<<PPRE00)
 
#define PRESC_DIV_BY_64   (1<<PPRE01)|(1<<PPRE00)
 
#define PRESC_NODIV   (0<<PPRE01)|(0<<PPRE00)
 
#define PSC_CENTERED   (1<<PMODE01)|(1<<PMODE00)
 
#define PSC_FOUR_RAMP   (1<<PMODE01)|(0<<PMODE00)
 
#define PSC_ONE_RAMP   (0<<PMODE01)|(0<<PMODE00)
 
#define PSC_TWO_RAMP   (0<<PMODE01)|(1<<PMODE00)
 
#define RAMP_MODE_NUMBER   PSC_CENTERED
 
#define RELEASE_PLOCK   (0<<PLOCK0)
 
#define Set_EXT1()   (PORTB |= (1<<PB3))
 
#define Set_EXT10()   (PORTD |= (1<<PD2))
 
#define Set_EXT2()   (PORTB |= (1<<PB4))
 
#define Set_EXT3()   (PORTC |= (1<<PC1))
 
#define Set_EXT4()   (PORTC |= (1<<PC2))
 
#define Set_EXT5()   (PORTB |= (1<<PB5))
 
#define Set_EXT6()   (PORTE |= (1<<PE1))
 
#define Set_EXT7()   (PORTD |= (1<<PD3))
 
#define Set_EXT8()   (PORTD |= (1<<PD4))
 
#define Set_EXT9()   (PORTE |= (1<<PE0))
 
#define Set_none()   (AWEX_SetOutputOverrideValue(AWEXC,0))
 
#define SET_PLOCK   (1<<PLOCK0)
 
#define Set_Port_Q2()   (PORTC.OUTSET = PIN4_bm)
 
#define Set_Port_Q4()   (PORTC.OUTSET = PIN2_bm)
 
#define Set_Port_Q6()   (PORTC.OUTSET = PIN0_bm)
 
#define Set_Q1Q4()   AWEX_SetOutputOverrideValue(AWEXC,PIN5_bm | PIN2_bm)
 
#define Set_Q1Q6()   AWEX_SetOutputOverrideValue(AWEXC,PIN5_bm | PIN0_bm)
 
#define Set_Q3Q2()   AWEX_SetOutputOverrideValue(AWEXC,PIN3_bm | PIN4_bm)
 
#define Set_Q3Q6()   AWEX_SetOutputOverrideValue(AWEXC,PIN3_bm | PIN0_bm)
 
#define Set_Q5Q2()   AWEX_SetOutputOverrideValue(AWEXC,PIN1_bm | PIN4_bm)
 
#define Set_Q5Q4()   AWEX_SetOutputOverrideValue(AWEXC,PIN1_bm | PIN2_bm)
 
#define Set_timer_data_register_to_zero()   (TCNT0=0x00)
 
#define switch_OFF_LED()   (PORTE |= (1<<PE2))
 
#define switch_ON_LED()   (PORTE &= ~(1<<PE2))
 
#define Toggle_EXT2()   (PINB |= (1<<PINB4))
 

Functions

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_Current (void)
 
U8 mc_get_hall (void)
 Get the value of hall sensors (1 to 6) More...
 
U8 mc_Get_Potentiometer (void)
 
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...
 
void PWM_Init (unsigned int OCRnRB)
 Initialization of PWM generator PSC0. More...
 

Macro Definition Documentation

◆ BUSY

#define BUSY   1

Definition at line 124 of file mc_drv.h.

◆ Clear_EXT1

#define Clear_EXT1 ( )    (PORTB &= ~(1<<PB3))

Definition at line 86 of file mc_drv.h.

◆ Clear_EXT10

#define Clear_EXT10 ( )    (PORTD &= ~(1<<PD2))

Definition at line 105 of file mc_drv.h.

◆ Clear_EXT2

#define Clear_EXT2 ( )    (PORTB &= ~(1<<PB4))

Definition at line 88 of file mc_drv.h.

◆ Clear_EXT3

#define Clear_EXT3 ( )    (PORTC &= ~(1<<PC1))

Definition at line 91 of file mc_drv.h.

◆ Clear_EXT4

#define Clear_EXT4 ( )    (PORTC &= ~(1<<PC2))

Definition at line 93 of file mc_drv.h.

◆ Clear_EXT5

#define Clear_EXT5 ( )    (PORTB &= ~(1<<PB5))

Definition at line 95 of file mc_drv.h.

◆ Clear_EXT6

#define Clear_EXT6 ( )    (PORTE &= ~(1<<PE1))

Definition at line 97 of file mc_drv.h.

◆ Clear_EXT7

#define Clear_EXT7 ( )    (PORTD &= ~(1<<PD3))

Definition at line 99 of file mc_drv.h.

◆ Clear_EXT8

#define Clear_EXT8 ( )    (PORTD &= ~(1<<PD4))

Definition at line 101 of file mc_drv.h.

◆ Clear_EXT9

#define Clear_EXT9 ( )    (PORTE &= ~(1<<PE0))

Definition at line 103 of file mc_drv.h.

◆ Clear_Port_Q1

#define Clear_Port_Q1 ( )    (PORTC.OUTCLR = PIN5_bm)

Definition at line 55 of file mc_drv.h.

◆ Clear_Port_Q2

#define Clear_Port_Q2 ( )    (PORTC.OUTCLR = PIN4_bm)

Definition at line 58 of file mc_drv.h.

◆ Clear_Port_Q3

#define Clear_Port_Q3 ( )    (PORTC.OUTCLR = PIN3_bm)

Definition at line 56 of file mc_drv.h.

◆ Clear_Port_Q4

#define Clear_Port_Q4 ( )    (PORTC.OUTCLR = PIN2_bm)

Definition at line 59 of file mc_drv.h.

◆ Clear_Port_Q5

#define Clear_Port_Q5 ( )    (PORTC.OUTCLR = PIN1_bm)

Definition at line 57 of file mc_drv.h.

◆ Clear_Port_Q6

#define Clear_Port_Q6 ( )    (PORTC.OUTCLR = PIN0_bm)

Definition at line 60 of file mc_drv.h.

◆ CONV_CURRENT

#define CONV_CURRENT   2

Definition at line 121 of file mc_drv.h.

◆ CONV_INIT

#define CONV_INIT   0

Definition at line 119 of file mc_drv.h.

◆ CONV_POT

#define CONV_POT   1

Definition at line 120 of file mc_drv.h.

◆ Disable_over_current

#define Disable_over_current ( )
Value:
PFRC0A = (1<<PELEV0A)|(1<<PFLTE0A)|\
(0<<PRFM0A3)|(0<<PRFM0A2)|(0<<PRFM0A1)|(0<<PRFM0A0);

Definition at line 43 of file mc_drv.h.

◆ Enable_over_current

#define Enable_over_current ( )
Value:
PFRC0A = (1<<PELEV0A)|(1<<PFLTE0A)|\
(0<<PRFM0A3)|(1<<PRFM0A2)|(1<<PRFM0A1)|(1<<PRFM0A0);

Definition at line 40 of file mc_drv.h.

◆ FREE

#define FREE   0

Definition at line 123 of file mc_drv.h.

◆ Get_EXT1

#define Get_EXT1 ( )    ((PINB & (1<<PB3))>>PB3)

Definition at line 107 of file mc_drv.h.

◆ Get_EXT10

#define Get_EXT10 ( )    ((PIND & (1<<PD2))>>PD2)

Definition at line 116 of file mc_drv.h.

◆ Get_EXT2

#define Get_EXT2 ( )    ((PINB & (1<<PB4))>>PB4)

Definition at line 108 of file mc_drv.h.

◆ Get_EXT3

#define Get_EXT3 ( )    ((PINC & (1<<PC1))>>PC1)

Definition at line 109 of file mc_drv.h.

◆ Get_EXT4

#define Get_EXT4 ( )    ((PINC & (1<<PC2))>>PC2)

Definition at line 110 of file mc_drv.h.

◆ Get_EXT5

#define Get_EXT5 ( )    ((PINB & (1<<PB5))>>PB5)

Definition at line 111 of file mc_drv.h.

◆ Get_EXT6

#define Get_EXT6 ( )    ((PINE & (1<<PE1))>>PE1)

Definition at line 112 of file mc_drv.h.

◆ Get_EXT7

#define Get_EXT7 ( )    ((PIND & (1<<PD3))>>PD3)

Definition at line 113 of file mc_drv.h.

◆ Get_EXT8

#define Get_EXT8 ( )    ((PIND & (1<<PD4))>>PD4)

Definition at line 114 of file mc_drv.h.

◆ Get_EXT9

#define Get_EXT9 ( )    ((PINE & (1<<PE0))>>PE0)

Definition at line 115 of file mc_drv.h.

◆ HALL_A

#define HALL_A ( )    (PORTE_INT0_vect)

Definition at line 48 of file mc_drv.h.

◆ HALL_SENSOR_VALUE

#define HALL_SENSOR_VALUE ( )    (PORTE.IN & 0x07)

Definition at line 53 of file mc_drv.h.

Referenced by mc_get_hall(), and mc_hall_a().

◆ OUTPUT_ACTIVE_HIGH

#define OUTPUT_ACTIVE_HIGH   (1<<POP0)

Definition at line 37 of file mc_drv.h.

◆ OUTPUT_ACTIVE_LOW

#define OUTPUT_ACTIVE_LOW   (0<<POP0)

Definition at line 38 of file mc_drv.h.

◆ output_disconnected

#define output_disconnected   0x01

Definition at line 16 of file mc_drv.h.

◆ PRESC_DIV_BY_16

#define PRESC_DIV_BY_16   (1<<PPRE01)|(0<<PPRE00)

Definition at line 34 of file mc_drv.h.

◆ PRESC_DIV_BY_4

#define PRESC_DIV_BY_4   (0<<PPRE01)|(1<<PPRE00)

Definition at line 33 of file mc_drv.h.

◆ PRESC_DIV_BY_64

#define PRESC_DIV_BY_64   (1<<PPRE01)|(1<<PPRE00)

Definition at line 35 of file mc_drv.h.

◆ PRESC_NODIV

#define PRESC_NODIV   (0<<PPRE01)|(0<<PPRE00)

Definition at line 32 of file mc_drv.h.

◆ PSC_CENTERED

#define PSC_CENTERED   (1<<PMODE01)|(1<<PMODE00)

Definition at line 25 of file mc_drv.h.

◆ PSC_FOUR_RAMP

#define PSC_FOUR_RAMP   (1<<PMODE01)|(0<<PMODE00)

Definition at line 24 of file mc_drv.h.

◆ PSC_ONE_RAMP

#define PSC_ONE_RAMP   (0<<PMODE01)|(0<<PMODE00)

Definition at line 22 of file mc_drv.h.

◆ PSC_TWO_RAMP

#define PSC_TWO_RAMP   (0<<PMODE01)|(1<<PMODE00)

Definition at line 23 of file mc_drv.h.

◆ RAMP_MODE_NUMBER

#define RAMP_MODE_NUMBER   PSC_CENTERED

Definition at line 27 of file mc_drv.h.

◆ RELEASE_PLOCK

#define RELEASE_PLOCK   (0<<PLOCK0)

Definition at line 30 of file mc_drv.h.

◆ Set_EXT1

#define Set_EXT1 ( )    (PORTB |= (1<<PB3))

Definition at line 85 of file mc_drv.h.

◆ Set_EXT10

#define Set_EXT10 ( )    (PORTD |= (1<<PD2))

Definition at line 104 of file mc_drv.h.

◆ Set_EXT2

#define Set_EXT2 ( )    (PORTB |= (1<<PB4))

Definition at line 87 of file mc_drv.h.

◆ Set_EXT3

#define Set_EXT3 ( )    (PORTC |= (1<<PC1))

Definition at line 90 of file mc_drv.h.

◆ Set_EXT4

#define Set_EXT4 ( )    (PORTC |= (1<<PC2))

Definition at line 92 of file mc_drv.h.

◆ Set_EXT5

#define Set_EXT5 ( )    (PORTB |= (1<<PB5))

Definition at line 94 of file mc_drv.h.

◆ Set_EXT6

#define Set_EXT6 ( )    (PORTE |= (1<<PE1))

Definition at line 96 of file mc_drv.h.

◆ Set_EXT7

#define Set_EXT7 ( )    (PORTD |= (1<<PD3))

Definition at line 98 of file mc_drv.h.

◆ Set_EXT8

#define Set_EXT8 ( )    (PORTD |= (1<<PD4))

Definition at line 100 of file mc_drv.h.

◆ Set_EXT9

#define Set_EXT9 ( )    (PORTE |= (1<<PE0))

Definition at line 102 of file mc_drv.h.

◆ Set_none

#define Set_none ( )    (AWEX_SetOutputOverrideValue(AWEXC,0))

Definition at line 66 of file mc_drv.h.

Referenced by mc_switch_commutation().

◆ SET_PLOCK

#define SET_PLOCK   (1<<PLOCK0)

Definition at line 29 of file mc_drv.h.

◆ Set_Port_Q2

#define Set_Port_Q2 ( )    (PORTC.OUTSET = PIN4_bm)

Definition at line 61 of file mc_drv.h.

◆ Set_Port_Q4

#define Set_Port_Q4 ( )    (PORTC.OUTSET = PIN2_bm)

Definition at line 62 of file mc_drv.h.

◆ Set_Port_Q6

#define Set_Port_Q6 ( )    (PORTC.OUTSET = PIN0_bm)

Definition at line 63 of file mc_drv.h.

◆ Set_Q1Q4

#define Set_Q1Q4 ( )    AWEX_SetOutputOverrideValue(AWEXC,PIN5_bm | PIN2_bm)

Definition at line 68 of file mc_drv.h.

Referenced by mc_switch_commutation().

◆ Set_Q1Q6

#define Set_Q1Q6 ( )    AWEX_SetOutputOverrideValue(AWEXC,PIN5_bm | PIN0_bm)

Definition at line 70 of file mc_drv.h.

Referenced by mc_switch_commutation().

◆ Set_Q3Q2

#define Set_Q3Q2 ( )    AWEX_SetOutputOverrideValue(AWEXC,PIN3_bm | PIN4_bm)

Definition at line 72 of file mc_drv.h.

Referenced by mc_switch_commutation().

◆ Set_Q3Q6

#define Set_Q3Q6 ( )    AWEX_SetOutputOverrideValue(AWEXC,PIN3_bm | PIN0_bm)

Definition at line 74 of file mc_drv.h.

Referenced by mc_switch_commutation().

◆ Set_Q5Q2

#define Set_Q5Q2 ( )    AWEX_SetOutputOverrideValue(AWEXC,PIN1_bm | PIN4_bm)

Definition at line 76 of file mc_drv.h.

Referenced by mc_switch_commutation().

◆ Set_Q5Q4

#define Set_Q5Q4 ( )    AWEX_SetOutputOverrideValue(AWEXC,PIN1_bm | PIN2_bm)

Definition at line 78 of file mc_drv.h.

Referenced by mc_switch_commutation().

◆ Set_timer_data_register_to_zero

#define Set_timer_data_register_to_zero ( )    (TCNT0=0x00)

Definition at line 19 of file mc_drv.h.

◆ switch_OFF_LED

#define switch_OFF_LED ( )    (PORTE |= (1<<PE2))

Definition at line 82 of file mc_drv.h.

◆ switch_ON_LED

#define switch_ON_LED ( )    (PORTE &= ~(1<<PE2))

Definition at line 81 of file mc_drv.h.

◆ Toggle_EXT2

#define Toggle_EXT2 ( )    (PINB |= (1<<PINB4))

Definition at line 89 of file mc_drv.h.

Function Documentation

◆ 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;
404 }
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
#define ADC_Ch_Conversion_Complete(_adc_ch)
This macro returns the channel conversion complete flag..
Definition: adc_driver.h:222
void mc_set_potentiometer_value(U8 potentiometer)
Set the &#39;mc_potentiometer_value&#39; variable with the potentiometer value.
Definition: mc_interface.c:209
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 }
Bool inrush_mask_flag
Definition: mc_drv.c:35
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 }
#define TC_SetCompareA(_tc, _compareValue)
Set new compare value for compare channel A. ( Double buffered )
Definition: TC_driver.h:169
#define TC_SetCompareB(_tc, _compareValue)
Set new compare value for compare channel B. ( Double buffered )
Definition: TC_driver.h:180
#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;
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 }
Bool g_mc_read_enable
Definition: mc_drv.c:38
U8 count
Definition: mc_drv.c:31
U16 average
Definition: mc_drv.c:32
void mc_set_motor_measured_speed(U8 measured_speed)
set Measured of speed (for initialization)
Definition: mc_interface.c:158
#define K_SPEED
Definition: config_motor.h:82
#define n_SAMPLE
Definition: config_motor.h:43
Here is the call graph for this function:

◆ mc_Get_Current()

U8 mc_Get_Current ( void  )

◆ mc_get_hall()

U8 mc_get_hall ( void  )

Get the value of hall sensors (1 to 6)

Parameters
returnan 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 }
#define HALL_SENSOR_VALUE()
Definition: mc_drv.h:53

◆ mc_Get_Potentiometer()

U8 mc_Get_Potentiometer ( void  )

◆ 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 }
void mc_init_timer1(void)
timer 1 Configuration Use to generate a 250us activation for sampling speed regulation ...
Definition: mc_drv.c:283
void ADC_Init()
Definition: mc_drv.c:53
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
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 }
Bool inrush_mask_flag
Definition: mc_drv.c:35
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  {
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 }
#define Set_Q1Q6()
Definition: mc_drv.h:70
#define Set_Q5Q2()
Definition: mc_drv.h:76
U8 mc_get_motor_direction(void)
Definition: mc_interface.c:148
#define Set_none()
Definition: mc_drv.h:66
Bool mc_motor_is_running(void)
get the motor state
Definition: mc_interface.c:70
#define Set_Q3Q2()
Definition: mc_drv.h:72
#define Set_Q3Q6()
Definition: mc_drv.h:74
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
#define Set_Q5Q4()
Definition: mc_drv.h:78
U8 mc_get_Duty_Cycle()
set type of regulation
Definition: mc_control.c:197
#define Set_Q1Q4()
Definition: mc_drv.h:68
U8 mc_get_motor_speed(void)
Definition: mc_interface.c:118
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 );
163 }
#define AWEX_EnableCommonWaveformChannelMode(_awex)
This macro enables the Common Waveform Channel mode.
Definition: awex_driver.h:71
void ConfigDTI(U8 deadTime)
Definition: mc_drv.c:142
#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: