#include "table_sin81.h"
#include "lib_mcu/pll/pll_drv.h"

Go to the source code of this file.
Defines | |
| #define | HAS1 (1<<PIND5) | (0<<PINC6) | (1<<PIND7) |
| #define | HAS2 (0<<PIND5) | (0<<PINC6) | (1<<PIND7) |
| #define | HAS3 (0<<PIND5) | (1<<PINC6) | (1<<PIND7) |
| #define | HAS4 (0<<PIND5) | (1<<PINC6) | (0<<PIND7) |
| #define | HAS5 (1<<PIND5) | (1<<PINC6) | (0<<PIND7) |
| #define | HAS6 (1<<PIND5) | (0<<PINC6) | (0<<PIND7) |
Functions | |
| void | Do_Sensor_Interrupt (void) |
| void | init (void) |
| U16 | mc_control_speed_16b (U16 speed_ref, U16 speed_measure) |
| void | PSC_Init (unsigned int ot0, unsigned int ot1) |
| void | PSC_Load (unsigned int dt0a, unsigned int dt1a, unsigned int dt0b, unsigned int dt1b, unsigned int dt0c, unsigned int dt1c) |
| void | PSC_Start (void) |
| void | PSC_Stop (void) |
| S16 | read_acquisition () |
| void | Start_ADC (void) |
| void | SVPWM (U16 amp, U8 Counter_Value, U8 Top, U8 Sector) |
Variables | |
| volatile U16 | Amplitude = 0 |
| voltage to apply | |
| volatile U8 | Delay_For_Change = 1 |
| delay | |
| volatile U8 | Hall_Event_Count = 8 |
| measure the speed on 8 cycles | |
| volatile U16 | Hall_Period = 65535 |
| period of Hall sensor signal | |
| volatile U8 | Hall_Sector = HAS1 |
| current Hall sector | |
| volatile U8 | Main_Tick |
| Tick signal for main. | |
| Bool | mci_direction |
| User Input parameter to set motor direction. | |
| volatile Bool | mci_run_stop |
| command for motor | |
| volatile U16 | Measured_Speed |
| measured speed | |
| volatile U8 | Mem_Hall_Sector = HAS1 |
| future Hall sector | |
| volatile U16 | Mem_Hall_Time = 0 |
| memorisation of Hall event time | |
| volatile U8 | Mem_Top_Counter = 1 |
| memorization at top | |
| volatile U16 | Mem_Top_CounterX8 = 1 |
| for filter | |
| volatile U16 | Permanent_Clock = 0 |
| volatile U8 | Prescaler_Main_Tick |
| prescaler for Tick | |
| volatile U16 | PWM0 |
| volatile U16 | PWM1 |
| volatile U16 | PWM2 |
| duty cycle | |
| volatile U8 | Sensor_Counter_Down = 1 |
| current counter for svpwm | |
| volatile U8 | Sensor_Counter_Up = 0 |
| measure of the time | |
| volatile U8 | Top_Counter = 1 |
| current top counter | |
| void Do_Sensor_Interrupt | ( | void | ) |
| void init | ( | void | ) |
ports direction configuration, timer 0 configuration, run the PLL, allow interruptions
Definition at line 29 of file init.c.
References Enable_interrupt.
00030 { 00031 /*************************************************************************************/ 00032 /* ports direction configuration */ 00033 /*************************************************************************************/ 00034 00035 DDRB = 0xC3; 00036 // DDRC = 0x89; MC200 00037 DDRC = 0x8A; //MC100 00038 DDRD = 0x01; 00039 // DDRE = 0x02; // MC200 00040 DDRE = 0x04; // MC100 00041 00042 PORTC = 0x06; /* enable pull up */ 00043 00044 /*************************************************************************************/ 00045 /* Timer 0 Configuration : generates the sampling fréquency */ 00046 /*************************************************************************************/ 00047 TCCR0A = (1<<WGM01); // mode CTC : Clear Timer on Compare 00048 TCCR0B = (1<<CS02); // f_quartz = 8 MHz / 256 = 32 kHz 00049 // OCR0A = 0x20; // one interruption every 1.056ms @8 Mhz 00050 // OCR0A = 0x10; // one interruption every 0.544ms @8 Mhz 00051 // OCR0A = 0x08; // one interruption every 0.288ms @8 Mhz (0.144ms @16 Mhz) 00052 // OCR0A = 0x02; // one interruption every 48µS @16 Mhz 00053 OCR0A = 0x03; // one interruption every 64µS @16 Mhz 00054 00055 // !! 48µS is too quick for GCC , please use at least 64µS 00056 // and adjust Prescaler_Main_Tick 00057 // in mc_drv.c 00058 00059 00060 TIMSK0 = (1<<OCIE0A); // allow interruption when timer=compare 00061 00062 init_comparator0(); 00063 init_comparator1(); 00064 init_comparator2(); 00065 00066 00067 // initialize external interrupts /* MC200 */ 00068 00069 // EICRA =(0<<ISC21)|(1<<ISC20)|(0<<ISC11)|(1<<ISC10)|(0<<ISC01)|(1<<ISC00); 00070 // EIFR = (1<<INTF2)|(1<<INTF1)|(1<<INTF0); // clear possible IT due to config 00071 // EIMSK=(0<<INT2)|(1<<INT1)|(1<<INT0); 00072 00073 Enable_interrupt(); // allow interruptions 00074 }
speed controller
Definition at line 35 of file mc_control.c.
References MAX_AMPLITUDE, speed_error, speed_integ, speed_integral, and speed_proportional.
00036 { 00037 U16 result = 0; 00038 S16 increment = 0; 00039 00040 // Error calculation 00041 // speed_error = speed_ref - speed_measure/2 ; 00042 speed_error = speed_ref - speed_measure; 00043 00044 // proportional term calculation : Kp= 7/64=0.1 00045 speed_proportional = speed_error * 4; 00046 00047 // integral term calculation 00048 speed_integral = speed_integral + speed_error; 00049 00050 // speed integral saturation 00051 if(speed_integral > 32000) speed_integral = 32000; 00052 if(speed_integral < -32000) speed_integral = -32000; 00053 00054 speed_integ = (speed_integral - speed_integral/8 + speed_integral/32) / 16 ; 00055 00056 // amplitude calculation 00057 increment = speed_proportional + speed_integ; 00058 00059 // saturation of the PI output 00060 if (increment > 0) 00061 { 00062 if (increment <= (S16)(MAX_AMPLITUDE)) result = (S16)increment ; 00063 else result = MAX_AMPLITUDE ; 00064 } 00065 else result = 0; 00066 00067 // return Duty Cycle 00068 return result; 00069 }
| void PSC_Init | ( | unsigned int | ot0, | |
| unsigned int | ot1 | |||
| ) |
This function initiliazes the 3 PSC
| none |
| void PSC_Load | ( | unsigned int | dt0a, | |
| unsigned int | dt1a, | |||
| unsigned int | dt0b, | |||
| unsigned int | dt1b, | |||
| unsigned int | dt0c, | |||
| unsigned int | dt1c | |||
| ) | [inline] |
Load the OCR0SA et OCR0SB registers with new duty cycle values
| new | duty cycles |
Definition at line 150 of file mc_drv.c.
00153 { 00154 PCNF0 = (1<<PLOCK0)|(1<<PMODE01) | (1<<PMODE00) | (1<<POP0) | (1<<PCLKSEL0); 00155 PCNF1 = (1<<PLOCK1)|(1<<PMODE11) | (1<<PMODE10) | (1<<POP1) | (1<<PCLKSEL1); 00156 PCNF2 = (1<<PLOCK2)|(1<<PMODE21) | (1<<PMODE20) | (1<<POP2) | (1<<PCLKSEL2); 00157 00158 OCR0SAH = HIGH(dt0a); 00159 OCR0SAL = LOW(dt0a); 00160 OCR0SBH = HIGH(dt1a); 00161 OCR0SBL = LOW(dt1a); 00162 00163 OCR1SAH = HIGH(dt0b); 00164 OCR1SAL = LOW(dt0b); 00165 OCR1SBH = HIGH(dt1b); 00166 OCR1SBL = LOW(dt1b); 00167 00168 OCR2SAH = HIGH(dt0c); 00169 OCR2SAL = LOW(dt0c); 00170 OCR2SBH = HIGH(dt1c); 00171 OCR2SBL = LOW(dt1c); 00172 00173 PCNF0 = (1<<PMODE01) | (1<<PMODE00) | (1<<POP0) | (1<<PCLKSEL0); 00174 PCNF1 = (1<<PMODE11) | (1<<PMODE10) | (1<<POP1) | (1<<PCLKSEL1); 00175 PCNF2 = (1<<PMODE21) | (1<<PMODE20) | (1<<POP2) | (1<<PCLKSEL2); 00176 }
| void PSC_Start | ( | void | ) |
| void PSC_Stop | ( | void | ) |
This function stops the PSCs
| none |
Definition at line 196 of file mc_drv.c.
Referenced by mci_stop().

| S16 read_acquisition | ( | void | ) |
Get the ADC conversion result
| none |
Definition at line 128 of file adc.c.
References LSB, MSB, and Union16::w.
00129 { 00130 Union16 resultADC ; 00131 00132 LSB(resultADC) = ADCL ; // the ADC output has 10 bit resolution 00133 MSB(resultADC) = ADCH ; 00134 00135 return (resultADC.w) ; 00136 }
| void Start_ADC | ( | void | ) |
Start the ADC conversion
| none |
Definition at line 109 of file adc.c.
References ADC_PRESCALER_16.
00110 { 00111 ADCSRA = (1<<ADEN) /* ADC enable */ \ 00112 | (1<<ADSC) /* start conversion */ \ 00113 | (0<<ADATE) \ 00114 | (1<<ADIE) /* interrupt enable */ \ 00115 | (ADC_PRESCALER_16 <<ADPS0) \ 00116 ; 00117 00118 }
| volatile U8 Delay_For_Change = 1 |
| volatile U8 Hall_Event_Count = 8 |
| volatile U16 Hall_Period = 65535 |
| volatile U8 Hall_Sector = HAS1 |
User Input parameter to set motor direction.
Definition at line 36 of file mc_interface.c.
Referenced by mci_backward(), mci_forward(), mci_get_direction(), mci_set_direction(), and ushell_task().
| volatile Bool mci_run_stop |
| volatile U16 Measured_Speed |
| volatile U8 Mem_Hall_Sector = HAS1 |
| volatile U16 Mem_Hall_Time = 0 |
| volatile U8 Mem_Top_Counter = 1 |
| volatile U16 Mem_Top_CounterX8 = 1 |
| volatile U16 Permanent_Clock = 0 |
| volatile U8 Prescaler_Main_Tick |
| volatile U8 Sensor_Counter_Down = 1 |
| volatile U8 Sensor_Counter_Up = 0 |
| volatile U8 Top_Counter = 1 |
1.5.3