00001
00012
00013
00014
00015 #ifndef _MC_DRV_H_
00016 #define _MC_DRV_H_
00017
00018 #include "config.h"
00019
00020 #define Disable_over_current() \
00021 Psc_config_input_1(PSC_OVERLAP_ENABLE,\
00022 PSC_USE_COMPARATOR,\
00023 PSC_USE_HIGH_LEVEL,\
00024 PSC_INPUT_FILTER_ENABLE,\
00025 PSC_SYNCHRONOUS_OUTPUT_CONTROL,\
00026 PSC_INPUT_NO_ACTION);
00027
00028 #define Enable_over_current() \
00029 Psc_config_input_1(PSC_OVERLAP_ENABLE,\
00030 PSC_USE_COMPARATOR,\
00031 PSC_USE_HIGH_LEVEL,\
00032 PSC_INPUT_FILTER_ENABLE,\
00033 PSC_SYNCHRONOUS_OUTPUT_CONTROL,\
00034 PSC_INPUT_HALT);
00035
00036
00037
00038
00039 #define HALL_A() (PCINT1_vect)
00040 #define HALL_B() (PCINT0_vect)
00041
00042
00043 #define HALL_SENSOR_VALUE() \
00044 (Motor_Position)(\
00045 ( (PINC & (1<<PINC3)) >> PINC3 ) \
00046 | ( (PINB & (1<<PINB3)) >> 2 ) \
00047 | ( (PINB & (1<<PINB4)) >> 2 ))
00048
00049 #define Clear_Port_Q5() (PORTB &= ( ~(1<<PORTB0)))
00050 #define Clear_Port_Q3() (PORTC &= ( ~(1<<PORTC0)))
00051 #define Clear_Port_Q1() (PORTD &= ( ~(1<<PORTD0)))
00052 #define Clear_Port_Q6() (PORTB &= ( ~(1<<PORTB1)))
00053 #define Clear_Port_Q4() (PORTB &= ( ~(1<<PORTB6)))
00054 #define Clear_Port_Q2() (PORTB &= ( ~(1<<PORTB7)))
00055 #define Set_Port_Q2() (PORTB |= (1<<PORTB1))
00056 #define Set_Port_Q4() (PORTB |= (1<<PORTB6))
00057 #define Set_Port_Q6() (PORTB |= (1<<PORTB7))
00058
00059
00060 #define Set_none() \
00061 POC = (0<<POEN0A)|(0<<POEN0B)|\
00062 (0<<POEN1A)|(0<<POEN1B)|\
00063 (0<<POEN2A)|(0<<POEN2B);\
00064 Clear_Port_Q2(); \
00065 Clear_Port_Q4(); \
00066 Clear_Port_Q6(); \
00067 Clear_Port_Q1(); \
00068 Clear_Port_Q3(); \
00069 Clear_Port_Q5();
00070
00071 #if (CURRENT_DECAY == SLOW_DECAY_SYNCHRONOUS)
00072 #define Set_Q5Q4() \
00073 PORTB &= ( ~((1<<PORTB1)|(1<<PORTB7)));\
00074 POC = (0<<POEN0A)|(0<<POEN0B)|\
00075 (0<<POEN1A)|(0<<POEN1B)|\
00076 (1<<POEN2A)|(1<<POEN2B);\
00077 PORTB |= (1<<PORTB6);
00078
00079 #define Set_Q5Q2() \
00080 PORTB &= ( ~((1<<PORTB1)|(1<<PORTB6)));\
00081 POC = (0<<POEN0A)|(0<<POEN0B)|\
00082 (0<<POEN1A)|(0<<POEN1B)|\
00083 (1<<POEN2A)|(1<<POEN2B);\
00084 PORTB |= (1<<PORTB7);
00085
00086 #define Set_Q3Q6() \
00087 PORTB &= ( ~((1<<PORTB6)|(1<<PORTB7)));\
00088 POC = (0<<POEN0A)|(0<<POEN0B)|\
00089 (1<<POEN1A)|(1<<POEN1B)|\
00090 (0<<POEN2A)|(0<<POEN2B);\
00091 PORTB |= (1<<PORTB1);
00092
00093 #define Set_Q3Q2() \
00094 PORTB &= ( ~((1<<PORTB1)|(1<<PORTB6)));\
00095 POC = (0<<POEN0A)|(0<<POEN0B)|\
00096 (1<<POEN1A)|(1<<POEN1B)|\
00097 (0<<POEN2A)|(0<<POEN2B);\
00098 PORTB |= (1<<PORTB7);
00099
00100 #define Set_Q1Q6() \
00101 PORTB &= ( ~((1<<PORTB6)|(1<<PORTB7)));\
00102 POC = (1<<POEN0A)|(1<<POEN0B)|\
00103 (0<<POEN1A)|(0<<POEN1B)|\
00104 (0<<POEN2A)|(0<<POEN2B);\
00105 PORTB |= (1<<PORTB1);
00106
00107 #define Set_Q1Q4() \
00108 PORTB &= ( ~((1<<PORTB1)|(1<<PORTB7)));\
00109 POC = (1<<POEN0A)|(1<<POEN0B)|\
00110 (0<<POEN1A)|(0<<POEN1B)|\
00111 (0<<POEN2A)|(0<<POEN2B);\
00112 PORTB |= (1<<PORTB6);
00113
00114 #else
00115
00116 #if (CURRENT_DECAY == FAST_DECAY_SYNCHRONOUS)
00117 #define Set_Q5Q4() \
00118 POC=0;\
00119 PCTL = (PCTL&~((1<<PSWAP2)|(1<<PSWAP1)|(1<<PSWAP0)))\
00120 | ((0<<PSWAP2)|(1<<PSWAP1)|(0<<PSWAP0));\
00121 POC = (0<<POEN0A)|(0<<POEN0B)|\
00122 (1<<POEN1A)|(1<<POEN1B)|\
00123 (1<<POEN2A)|(1<<POEN2B);
00124
00125 #define Set_Q5Q2() \
00126 POC=0;\
00127 PCTL = (PCTL&~((1<<PSWAP2)|(1<<PSWAP1)|(1<<PSWAP0)))\
00128 | ((0<<PSWAP2)|(0<<PSWAP1)|(1<<PSWAP0));\
00129 POC = (1<<POEN0A)|(1<<POEN0B)|\
00130 (0<<POEN1A)|(0<<POEN1B)|\
00131 (1<<POEN2A)|(1<<POEN2B);
00132
00133 #define Set_Q3Q6() \
00134 POC=0;\
00135 PCTL = (PCTL&~((1<<PSWAP2)|(1<<PSWAP1)|(1<<PSWAP0)))\
00136 | ((1<<PSWAP2)|(0<<PSWAP1)|(0<<PSWAP0));\
00137 POC = (0<<POEN0A)|(0<<POEN0B)|\
00138 (1<<POEN1A)|(1<<POEN1B)|\
00139 (1<<POEN2A)|(1<<POEN2B);
00140
00141 #define Set_Q3Q2() \
00142 POC=0;\
00143 PCTL = (PCTL&~((1<<PSWAP2)|(1<<PSWAP1)|(1<<PSWAP0)))\
00144 | ((0<<PSWAP2)|(0<<PSWAP1)|(1<<PSWAP0));\
00145 POC = (1<<POEN0A)|(1<<POEN0B)|\
00146 (1<<POEN1A)|(1<<POEN1B)|\
00147 (0<<POEN2A)|(0<<POEN2B);
00148
00149 #define Set_Q1Q6() \
00150 POC=0;\
00151 PCTL = (PCTL&~((1<<PSWAP2)|(1<<PSWAP1)|(1<<PSWAP0)))\
00152 | ((1<<PSWAP2)|(0<<PSWAP1)|(0<<PSWAP0));\
00153 POC = (1<<POEN0A)|(1<<POEN0B)|\
00154 (0<<POEN1A)|(0<<POEN1B)|\
00155 (1<<POEN2A)|(1<<POEN2B);
00156
00157 #define Set_Q1Q4() \
00158 POC=0;\
00159 PCTL = (PCTL&~((1<<PSWAP2)|(1<<PSWAP1)|(1<<PSWAP0)))\
00160 | ((0<<PSWAP2)|(1<<PSWAP1)|(0<<PSWAP0));\
00161 POC = (1<<POEN0A)|(1<<POEN0B)|\
00162 (1<<POEN1A)|(1<<POEN1B)|\
00163 (0<<POEN2A)|(0<<POEN2B);\
00164 // *** end FAST_DECAY_SYNCHRONOUS
00165
00166 #else
00167
00168
00169 #define Set_Q5Q4() \
00170 POC = (0<<POEN0A)|(0<<POEN0B)|\
00171 (0<<POEN1A)|(1<<POEN1B)|\
00172 (1<<POEN2A)|(0<<POEN2B);
00173
00174 #define Set_Q5Q2() \
00175 POC = (0<<POEN0A)|(1<<POEN0B)|\
00176 (0<<POEN1A)|(0<<POEN1B)|\
00177 (1<<POEN2A)|(0<<POEN2B);
00178
00179 #define Set_Q3Q6() \
00180 POC = (0<<POEN0A)|(0<<POEN0B)|\
00181 (1<<POEN1A)|(0<<POEN1B)|\
00182 (0<<POEN2A)|(1<<POEN2B);
00183
00184 #define Set_Q3Q2() \
00185 POC = (0<<POEN0A)|(1<<POEN0B)|\
00186 (1<<POEN1A)|(0<<POEN1B)|\
00187 (0<<POEN2A)|(0<<POEN2B);
00188
00189 #define Set_Q1Q6() \
00190 POC = (1<<POEN0A)|(0<<POEN0B)|\
00191 (0<<POEN1A)|(0<<POEN1B)|\
00192 (0<<POEN2A)|(1<<POEN2B);
00193
00194 #define Set_Q1Q4() \
00195 POC = (1<<POEN0A)|(0<<POEN0B)|\
00196 (0<<POEN1A)|(1<<POEN1B)|\
00197 (0<<POEN2A)|(0<<POEN2B);
00198 #endif
00199 #endif
00200
00201
00202 #define Force_CMP0_high() \
00203 PORTD |= (1<<PORTD7); \
00204 PORTB &= ~(1<<PORTB2); \
00205 DDRD |= (1<<DDD7); \
00206 DDRB |= (1<<DDB2);
00207
00208 #define Force_CMP0_low() \
00209 PORTD &= ~(1<<PORTD7); \
00210 PORTB |= (1<<PORTB2); \
00211 DDRD |= (1<<DDD7); \
00212 DDRB |= (1<<DDB2);
00213
00214 #define Release_CMP0() \
00215 DDRD &= ~(1<<DDD7); \
00216 DDRB &= ~(1<<DDB2);
00217
00218 #define Force_CMP1_high() \
00219 PORTC |= (1<<PORTC6); \
00220 PORTB &= ~(1<<PORTB5); \
00221 DDRC |= (1<<DDC6); \
00222 DDRB |= (1<<DDB5);
00223
00224 #define Force_CMP1_low() \
00225 PORTC &= ~(1<<PORTC6); \
00226 PORTB |= (1<<PORTB5); \
00227 DDRC |= (1<<DDC6); \
00228 DDRB |= (1<<DDB5);
00229
00230 #define Release_CMP1() \
00231 DDRC &= ~(1<<DDC6); \
00232 DDRB &= ~(1<<DDB5);
00233
00234 #define Force_CMP2_high() \
00235 PORTD |= (1<<PORTD5); \
00236 PORTD &= ~(1<<PORTD6); \
00237 DDRD |= ((1<<DDD6)|(1<<DDD5));
00238
00239 #define Force_CMP2_low() \
00240 PORTD &= ~(1<<PORTD5); \
00241 PORTD |= (1<<PORTD6); \
00242 DDRD |= ((1<<DDD6)|(1<<DDD5));
00243
00244 #define Release_CMP2() \
00245 DDRD &= ~((1<<DDD6)|(1<<DDD5));
00246
00247 #define Enable_IT_comparator2_1_0() \
00248 ACSR |= (1<<AC2IF)|(1<<AC1IF)|(1<<AC0IF); \
00249 AC0CON |= (1<<AC0IE); \
00250 AC1CON |= (1<<AC1IE); \
00251 AC2CON |= (1<<AC2IE);
00252
00253 #define Enable_IT_comparator0() \
00254 ACSR |= (1<<AC0IF); \
00255 AC0CON |= (1<<AC0IE);
00256
00257 #define Enable_IT_comparator1() \
00258 ACSR |= (1<<AC1IF); \
00259 AC1CON |= (1<<AC1IE);
00260
00261 #define Enable_IT_comparator2() \
00262 ACSR |= (1<<AC2IF); \
00263 AC2CON |= (1<<AC2IE);
00264
00265 #define Disable_IT_comparator2_1_0() \
00266 AC0CON &= ~((1<<AC0IE)); \
00267 AC1CON &= ~((1<<AC1IE)); \
00268 AC2CON &= ~((1<<AC2IE));
00269
00270 #define Disable_IT_comparator0() \
00271 AC0CON &= ~(1<<AC0IE);
00272
00273 #define Disable_IT_comparator1() \
00274 AC1CON &= ~(1<<AC1IE);
00275
00276 #define Disable_IT_comparator2() \
00277 AC2CON &= ~(1<<AC2IE);
00278
00279 #define STATE_CMP0 0
00280 #define STATE_CMP1 1
00281 #define STATE_CMP2 2
00282 #define STATE_CW100 3
00283 #define STATE_CW110 4
00284 #define STATE_CW010 5
00285 #define STATE_CW011 6
00286 #define STATE_CW001 7
00287 #define STATE_CW101 8
00288
00289
00290 #define CONV_INIT 0
00291 #define CONV_POT 1
00292 #define CONV_CURRENT 2
00293
00294 #define FREE 0
00295 #define BUSY 1
00296
00297
00298
00299
00300
00301 void mc_init_HW(void);
00302 void PSC_Init (void);
00303 void start_running_phase(void);
00304
00305
00306 Motor_Position mc_get_hall(void);
00307 void mc_duty_cycle(U8 level);
00308 void mc_switch_commutation(Motor_Position position);
00309
00310
00311 void mc_init_timer1(void);
00312
00313
00314 void mc_init_timer0(void);
00315 void mc_estimation_speed(void);
00316
00317
00318 void mc_ADC_Scheduler(void);
00319 U8 mc_Get_Current(void);
00320 U8 mc_Get_Potentiometer(void);
00321
00322
00323 void mc_disable_during_inrush(void);
00324 void mc_inrush_task(void);
00325
00326 #endif