23 #include "adc\adc_drv.h" 24 #include "dac\Dac_drv.h" 25 #include "pll\pll_drv.h" 26 #include "comparator\comparator_drv.h" 72 ADC_CH_INPUTMODE_SINGLEENDED_gc,
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);
105 PORTE.DIRCLR = (PIN0_bm | PIN1_bm | PIN2_bm);
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;
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;
190 #pragma vector = HALL_A() 286 TCD1.INTCTRLA = TC_OVFINTLVL_LO_gc;
287 TCD1.CTRLA = TC_CLKSEL_DIV1_gc;
295 #pragma vector = TCD1_OVF_vect 316 TCD0.INTCTRLA = TC_OVFINTLVL_LO_gc;
317 TCD0.CTRLA = TC_CLKSEL_DIV256_gc;
326 #pragma vector = TCD0_OVF_vect 345 U32 new_measured_speed;
350 timer_value = TCD0.CNT/2;
352 if (timer_value == 0) {timer_value += 1 ;}
353 new_measured_speed =
K_SPEED / timer_value;
354 if(new_measured_speed > 255) new_measured_speed = 255;
357 #ifdef AVERAGE_SPEED_MEASURE 397 value = ((value)>>4);
399 if ( (value&0xFF) < 150) value = 0;
void mc_set_Over_Current(U8 Level)
Set the Over Current threshold.
#define TC_SetCompareA(_tc, _compareValue)
Set new compare value for compare channel A. ( Double buffered )
void mc_switch_commutation(U8 position)
Set the Switching Commutation value on outputs according to sensor or estimation position.
Bool g_tick
Use for control the sampling period value.
void mc_init_timer1(void)
timer 1 Configuration Use to generate a 250us activation for sampling speed regulation ...
uint16_t ADC_ResultCh_GetWord(ADC_CH_t *adc_ch, uint8_t offset)
This function clears the interrupt flag and returns the coversion result.
uint8_t ADC_Offset_Get(ADC_t *adc)
This function get the offset of the ADC.
void mc_init_timer0(void)
Timer 0 Configuration The timer 0 is used to generate an IT when an overflow occurs.
U8 mc_get_motor_direction(void)
void ADC_CalibrationValues_Set(ADC_t *adc)
This function get the calibration data from the production calibration.
#define AWEX_SetDeadTimesSymmetricalUnbuffered(_awex, _deadTime)
This macro sets an equal dead time for high and low side.
Bool mc_motor_is_running(void)
get the motor state
#define ADC_ConvMode_and_Resolution_Config(_adc, _signedMode, _resolution)
This macro set the conversion mode and resolution in the selected adc.
#define ADC_Ch_InputMode_and_Gain_Config(_adc_ch, _inputMode, _gain)
This macro configures the input mode and gain to a specific virtual channel.
#define AWEX_EnableCommonWaveformChannelMode(_awex)
This macro enables the Common Waveform Channel mode.
void mci_retry_run(void)
mci_retry_run retry to run if speed is null
void mc_duty_cycle(U8 level)
Set the duty cycle values in the PSC according to the value calculate by the regulation loop...
#define ADC_Prescaler_Config(_adc, _div)
This macro set the prescaler factor in the selected adc.
void init_amplifier_1(void)
init Amplifier 1
#define ADC_Ch_Conversion_Complete(_adc_ch)
This macro returns the channel conversion complete flag..
#define ADC_Ch_InputMux_Config(_adc_ch, _posInput, _negInput)
This macro configures the Positiv and negativ inputs.
#define ADC_Referance_Config(_adc, _convRef)
This macro set the conversion referance in the selected adc.
XMEGA Timer/Counter driver header file.
void mc_inrush_task(void)
the purpose of this function is to manage the delay used when the overcurrent detection is disabled...
void PWM_Init(unsigned int OCRnRB)
Initialization of PWM generator PSC0.
__interrupt void launch_sampling_period(void)
Launch the regulation loop (see main.c) .
U8 mc_get_hall(void)
Get the value of hall sensors (1 to 6)
void mc_set_potentiometer_value(U8 potentiometer)
Set the 'mc_potentiometer_value' variable with the potentiometer value.
void mc_set_motor_measured_speed(U8 measured_speed)
set Measured of speed (for initialization)
void AWEX_EnableDeadTimeInsertion(AWEX_t *awex, uint8_t enableMask)
Enable Dead Time Insertion.
U8 mc_get_Duty_Cycle()
set type of regulation
#define ADC_FreeRunning_Enable(_adc)
This macro enables the Free Running mode in the selected adc.
XMEGA AWeX driver header file.
void mc_disable_during_inrush(void)
the purpose of this function is to disable the overcurrent detection during startup (inrush current...
#define HALL_SENSOR_VALUE()
XMEGA ADC driver header file.
void ADC_Wait_8MHz(ADC_t *adc)
This function waits until the adc common mode is settled.
void mc_ADC_Scheduler(void)
Launch the scheduler for the ADC.
void mc_estimation_speed(void)
estimation speed
void mc_init_HW(void)
init HW
#define TC_SetCompareB(_tc, _compareValue)
Set new compare value for compare channel B. ( Double buffered )
__interrupt void mc_hall_a(void)
External interruption Sensor (A) mode toggle.
U8 mc_get_motor_speed(void)
#define ADC_Enable(_adc)
This macro enables the selected adc.
void ConfigDTI(U8 deadTime)
#define AWEX_SetOutputOverrideValue(_awex, _overrideValue)
This macro sets an output override value.
#define TC_SetCompareC(_tc, _compareValue)
Set new compare value for compare channel C. ( Double buffered )
XMEGA HiRes driver header file.
__interrupt void ovfl_timer0(void)
Timer0 Overflow for speed measurement.