#include "config.h"#include "mc_drv.h"#include "mc_interface.h"#include "mc_control.h"#include "psc\psc_drv.h"#include "adc\adc_drv.h"#include "dac\dac_drv.h"#include "pll\pll_drv.h"#include "comparator\comparator_drv.h"
Go to the source code of this file.
Defines | |
| #define | ADVANCE 70 |
| #define | PSWAP0 2 |
| #define | PSWAP1 3 |
| #define | PSWAP2 4 |
Functions | |
| __interrupt void | ADC_end_of_conversion (void) |
| Launch the sampling procedure to get current value. | |
| __interrupt void | demag_interrupt (void) |
| end of demagnetization delay interrupt | |
| void | mc_ADC_Scheduler (void) |
| Launch the scheduler for the ADC. | |
| __interrupt void | mc_comparator_0 (void) |
| __interrupt void | mc_comparator_1 (void) |
| __interrupt void | mc_comparator_2 (void) |
| void | mc_disable_during_inrush (void) |
| the purpose of this function is to disable the overcurrent detection during startup (inrush current) | |
| void | mc_duty_cycle (U8 level) |
| Set the duty cycle values in the PSC according to the value calculate by the regulation loop. | |
| void | mc_estimation_speed (void) |
| estimation speed | |
| Motor_Position | mc_get_hall (void) |
| Get the value of hall sensors (1 to 6). | |
| __interrupt void | mc_hall_a (void) |
| External interruption Sensor (A) mode toggle. | |
| __interrupt void | mc_hall_b (void) |
| External interruption Hall Sensor (B) mode toggle. | |
| void | mc_init_HW (void) |
| mc_init_HW : Hardware Initialization | |
| void | mc_init_timer0 (void) |
| Timer 0 Configuration The timer 0 is used to generate an IT when an overflow occurs. | |
| void | mc_init_timer1 (void) |
| timer 1 Configuration | |
| void | mc_inrush_task (void) |
| the purpose of this function is to manage the delay used when the overcurrent detection is disabled | |
| __interrupt void | mc_overcurrent_detect (void) |
| void | mc_switch_commutation (Motor_Position position) |
| Set the Switching Commutation value on outputs. | |
| __interrupt void | ovfl_timer0 (void) |
| Timer0 Overflow => 4µS. | |
| void | PSC_Init (void) |
| PSC Init : Initialize the PSC according to the settings in config.h. | |
| void | start_running_phase (void) |
| __interrupt void | thirty_degres_interrupt (void) |
| 30 degres interrupt | |
Variables | |
| static char | ADC_State = FREE |
| U16 | average = 0 |
| U8 | count = 1 |
| Bool | current_EOC = FALSE |
| volatile Bool | g_tick = FALSE |
| Use for control the sampling period value. | |
| static U16 | inrush_delay = 0 |
| static Bool | inrush_mask_flag = FALSE |
| static U8 | motor_step |
| Bool | overcurrent = FALSE |
| static char | State = CONV_INIT |
| static U16 | stored_time = 0 |
| static volatile U8 | timer0_ext = 0 |
| static U32 | top_average = 200 |
| __interrupt void ADC_end_of_conversion | ( | void | ) |
Launch the sampling procedure to get current value.
Definition at line 663 of file mc_drv.c.
References Adc_get_10_bits_result, Adc_get_8_bits_result, ADC_INPUT_GND, Adc_select_channel, ADC_State, CONV_CURRENT, CONV_POT, FREE, mc_set_potentiometer_value(), mci_store_measured_current(), and State.
00665 { 00666 Adc_select_channel(ADC_INPUT_GND); /* release the amplified channel */ 00667 if(State == CONV_POT) mc_set_potentiometer_value(Adc_get_8_bits_result()); 00668 if(State == CONV_CURRENT) mci_store_measured_current(Adc_get_10_bits_result()); 00669 ADC_State = FREE; 00670 }
| __interrupt void demag_interrupt | ( | void | ) |
end of demagnetization delay interrupt
Definition at line 428 of file mc_drv.c.
References Enable_IT_comparator0, Enable_IT_comparator1, Enable_IT_comparator2, Enable_IT_comparator2_1_0, motor_step, MS_001, MS_010, MS_011, MS_100, MS_101, and MS_110.
00430 { 00431 00432 switch(motor_step) 00433 { 00434 case (MS_100): 00435 Enable_IT_comparator0(); 00436 break; 00437 00438 case (MS_110): 00439 Enable_IT_comparator1(); 00440 break; 00441 00442 case (MS_010): 00443 Enable_IT_comparator2(); 00444 break; 00445 00446 case (MS_011): 00447 Enable_IT_comparator0(); 00448 break; 00449 00450 case (MS_001): 00451 Enable_IT_comparator1(); 00452 break; 00453 00454 case (MS_101): 00455 Enable_IT_comparator2(); 00456 break; 00457 00458 default : 00459 Enable_IT_comparator2_1_0(); 00460 motor_step=MS_010; 00461 break; 00462 } 00463 }
| void mc_ADC_Scheduler | ( | void | ) |
Launch the scheduler for the ADC.
Definition at line 675 of file mc_drv.c.
References ADC_INPUT_AMP1, ADC_INPUT_ISRC, Adc_left_adjust_result, Adc_right_adjust_result, Adc_start_conv_channel, ADC_State, BUSY, CONV_CURRENT, CONV_INIT, CONV_POT, FREE, and State.
Referenced by main().
00676 { 00677 switch(State) 00678 { 00679 case CONV_INIT : 00680 ADC_State = FREE; 00681 State = CONV_CURRENT; 00682 break; 00683 00684 case CONV_CURRENT : /* previous state was CONV_CURRENT */ 00685 if(ADC_State == FREE) 00686 { 00687 ADC_State = BUSY; 00688 State= CONV_POT; /* new state is CONV_POT */ 00689 Adc_left_adjust_result(); 00690 Adc_start_conv_channel(ADC_INPUT_ISRC); /* get POT on ISRC input */ 00691 } 00692 break; 00693 00694 case CONV_POT : /* previous state was CONV_POT */ 00695 if(ADC_State == FREE) 00696 { 00697 ADC_State = BUSY; 00698 State = CONV_CURRENT; /* new state is CONV_CURRENT */ 00699 Adc_right_adjust_result(); 00700 Adc_start_conv_channel(ADC_INPUT_AMP1); /* get current on amplifier 1 */ 00701 } 00702 break; 00703 } 00704 }
| __interrupt void mc_comparator_0 | ( | void | ) |
Definition at line 471 of file mc_drv.c.
References Disable_IT_comparator2_1_0, LSB, MSB, and top_average.
00473 { 00474 U16 top; 00475 U16 tmp1; 00476 U16 tmp2; 00477 U8 temp; 00478 TCCR1B = 0 ; // stop timer 1 00479 temp = TCNT1L; 00480 top = (TCNT1H<<8) + temp; 00481 TCNT1H = 0; 00482 TCNT1L = 0; 00483 top_average = ((U32)top_average*15 + top ) >> 4; 00484 tmp1 = (top_average >> 1); 00485 tmp2 = tmp1 + (top_average >> 2); 00486 // tmp2 = tmp1 + 40; 00487 /* if (tmp1 > (4*ADVANCE)) 00488 { 00489 tmp1 = tmp1 - ADVANCE; 00490 tmp2 = tmp2 - ADVANCE; 00491 }*/ 00492 OCR1AH = MSB(tmp1); 00493 OCR1AL = LSB(tmp1); 00494 OCR1BH = MSB(tmp2); 00495 OCR1BL = LSB(tmp2); 00496 TCCR1B = 1<<CS11 | 1<<CS10 ; // start timer 1 00497 Disable_IT_comparator2_1_0(); 00498 00499 }
| __interrupt void mc_comparator_1 | ( | void | ) |
Definition at line 505 of file mc_drv.c.
References Disable_IT_comparator2_1_0, LSB, mc_estimation_speed(), MSB, and top_average.
00507 { 00508 U16 top; 00509 U16 tmp1; 00510 U16 tmp2; 00511 U8 temp; 00512 TCCR1B = 0 ; // stop timer 1 00513 temp = TCNT1L; 00514 top = (TCNT1H<<8) + temp; 00515 TCNT1H = 0; 00516 TCNT1L = 0; 00517 top_average = ((U32)top_average*15 + top ) >> 4; 00518 tmp1 = (top_average >> 1); 00519 tmp2 = tmp1 + (top_average >> 2); 00520 // tmp2 = tmp1 + 40; 00521 /* if (tmp1 > (4*ADVANCE)) 00522 { 00523 tmp1 = tmp1 - ADVANCE; 00524 tmp2 = tmp2 - ADVANCE; 00525 }*/ 00526 OCR1AH = MSB(tmp1); 00527 OCR1AL = LSB(tmp1); 00528 OCR1BH = MSB(tmp2); 00529 OCR1BL = LSB(tmp2); 00530 TCCR1B = 1<<CS11 | 1<<CS10 ; // start timer 1 00531 Disable_IT_comparator2_1_0(); 00532 mc_estimation_speed(); 00533 }
| __interrupt void mc_comparator_2 | ( | void | ) |
Definition at line 539 of file mc_drv.c.
References Disable_IT_comparator2_1_0, LSB, MSB, and top_average.
00541 { 00542 U16 top; 00543 U16 tmp1; 00544 U16 tmp2; 00545 U8 temp; 00546 //Toggle_PE1(); 00547 TCCR1B = 0 ; // stop timer 1 00548 temp = TCNT1L; 00549 top = (TCNT1H<<8) + temp; 00550 TCNT1H = 0; 00551 TCNT1L = 0; 00552 top_average = ((U32)top_average*15 + top ) >> 4; 00553 tmp1 = (top_average >> 1); 00554 tmp2 = tmp1 + (top_average >> 2); 00555 // tmp2 = tmp1 + 40; 00556 /* if (tmp1 > (4*ADVANCE)) 00557 { 00558 tmp1 = tmp1 - ADVANCE; 00559 tmp2 = tmp2 - ADVANCE; 00560 }*/ 00561 OCR1AH = MSB(tmp1); 00562 OCR1AL = LSB(tmp1); 00563 OCR1BH = MSB(tmp2); 00564 OCR1BL = LSB(tmp2); 00565 TCCR1B = 1<<CS11 | 1<<CS10 ; // start timer 1 00566 Disable_IT_comparator2_1_0(); 00567 }
| void mc_disable_during_inrush | ( | void | ) |
the purpose of this function is to disable
the overcurrent detection during startup (inrush current)
Definition at line 715 of file mc_drv.c.
References Disable_over_current, inrush_delay, inrush_mask_flag, and TRUE.
Referenced by mci_retry_run(), mci_run(), and ushell_task().
00716 { 00717 inrush_delay = (U16) 500; 00718 inrush_mask_flag = TRUE; 00719 Disable_over_current(); 00720 }
| 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 272 of file mc_drv.c.
References A_RA_VAL, B_RA_VAL, C_RA_VAL, DEADTIME, Psc_lock, Psc_set_module_A, Psc_set_module_B, Psc_set_module_C, and Psc_unlock.
Referenced by main(), mci_run(), and mci_stop().
00273 { 00274 U8 duty; 00275 duty = level; 00276 00277 #if ((CURRENT_DECAY == SLOW_DECAY_SYNCHRONOUS)||(CURRENT_DECAY == FAST_DECAY_SYNCHRONOUS)) 00278 U8 dutydt; /* duty with dead time */ 00279 if (duty >= DEADTIME) dutydt = duty - DEADTIME; 00280 #endif 00281 00282 Psc_lock(); 00283 00284 // Duty = 0 => Duty Cycle 0% 00285 // Duty = 255 => Duty Cycle 100% 00286 00287 #if (CURRENT_DECAY == FAST_DECAY) 00288 Psc_set_module_A(duty,A_RA_VAL,duty); 00289 Psc_set_module_B(duty,B_RA_VAL,duty); 00290 Psc_set_module_C(duty,C_RA_VAL,duty); 00291 #else 00292 #if ((CURRENT_DECAY == SLOW_DECAY_SYNCHRONOUS)||(CURRENT_DECAY == FAST_DECAY_SYNCHRONOUS)) 00293 Psc_set_module_A(duty,A_RA_VAL,dutydt); 00294 Psc_set_module_B(duty,B_RA_VAL,dutydt); 00295 Psc_set_module_C(duty,C_RA_VAL,dutydt); 00296 #else 00297 Psc_set_module_A(duty,A_RA_VAL,0); 00298 Psc_set_module_B(duty,B_RA_VAL,0); 00299 Psc_set_module_C(duty,C_RA_VAL,0); 00300 #endif 00301 #endif 00302 00303 Psc_unlock(); 00304 }
| void mc_estimation_speed | ( | void | ) |
estimation speed
Definition at line 627 of file mc_drv.c.
References mc_set_measured_period(), stored_time, and timer0_ext.
Referenced by mc_comparator_1(), and mc_hall_a().
00628 { 00629 U16 actual_time; 00630 U16 period_motor; 00631 00632 // Two 8 bits variables are use to simulate a 16 bits timer 00633 actual_time = (timer0_ext<<8) + TCNT0; 00634 00635 if (actual_time > stored_time) 00636 { 00637 period_motor = actual_time - stored_time; 00638 } 00639 else 00640 { 00641 period_motor = (U16)65535 - stored_time + actual_time; 00642 } 00643 00644 stored_time = actual_time; 00645 00646 mc_set_measured_period(period_motor>>1); 00647 00648 }
| Motor_Position mc_get_hall | ( | void | ) |
Get the value of hall sensors (1 to 6).
| return | an unsigned char value of hall sensor |
Definition at line 221 of file mc_drv.c.
References HALL_SENSOR_VALUE.
Referenced by mci_retry_run().
00222 { 00223 return HALL_SENSOR_VALUE(); 00224 }
| __interrupt void mc_hall_a | ( | void | ) |
External interruption Sensor (A) mode toggle.
Definition at line 236 of file mc_drv.c.
References mc_estimation_speed().
00238 { 00239 // if (ramp_up == TRUE) mc_switch_commutation(HALL_SENSOR_VALUE()); 00240 // mc_switch_commutation(HALL_SENSOR_VALUE()); 00241 00242 //estimation speed on rising edge of Hall_A 00243 if (PINC&(1<<PORTC3)) 00244 { 00245 mc_estimation_speed(); 00246 } 00247 00248 }
| __interrupt void mc_hall_b | ( | void | ) |
External interruption Hall Sensor (B) mode toggle.
Definition at line 260 of file mc_drv.c.
00262 { 00263 // if (ramp_up == TRUE) mc_switch_commutation(HALL_SENSOR_VALUE()); 00264 // mc_switch_commutation(HALL_SENSOR_VALUE()); 00265 }
| void mc_init_HW | ( | void | ) |
mc_init_HW : Hardware Initialization
Definition at line 90 of file mc_drv.c.
References Adc_config, Amp1_config, Comp_0_config, Comp_1_config, Comp_2_config, Dac_config, Dac_set_8_bits, IMAX, Init_PC7, mc_init_timer0(), mc_init_timer1(), PSC_Init(), Start_pll_64_mega, and Wait_pll_ready.
Referenced by mc_init().
00091 { 00092 // Output Pin configuration (used by PSC outputs) 00093 // PD0 => UH PB7 => UL 00094 // PC0 => VH PB6 => VL 00095 // PB0 => WH PB1 => WL 00096 00097 // Warning Output Low for MOSFET Drivers 00098 PORTB &= ~(1<<PORTB7 | 1<<PORTB6 | 1<<PORTB1 | 1<<PORTB0); 00099 PORTC &= ~(1<<PORTC0); 00100 PORTD &= ~(1<<PORTD0); 00101 00102 /* to removed */ 00103 PORTB |= (1<<PORTB4)|(1<<PORTB3); /* activate PB4 and PB3 pull up for sensorless debug */ 00104 PORTC |= (1<<PORTC3); /* activate PC3 pull up for sensorless debug */ 00105 00106 /* pull up for external comparators : to remove when internal comp are used */ 00107 #ifdef USE_INTERNAL_COMPARATORS 00108 #else 00109 PORTD |= (1<<PORTD7)|(1<<PORTD5); 00110 PORTC |= (1<<PORTC6); 00111 #endif 00112 00113 // PORT B : 00114 DDRB = (1<<DDB7)|(1<<DDB6)|(1<<DDB1)|(1<<DDB0); 00115 // PORT C : 00116 DDRC = (1<<DDC0); 00117 // PORT D : 00118 DDRD = (1<<DDD0); 00119 // PORT E : /* to be removed */ 00120 DDRE |= (1<<DDE2)|(1<<DDE1); 00121 00122 Init_PC7(); /* PC7 is used to display the overcurrent */ 00123 00124 // Disable Digital Input for amplifier1 00125 DIDR1 = (1<<ADC9D)|(1<<ADC8D); 00126 00127 // Disable Digital Input for comparators 0, 1 & 2 : to remove when external comp are used 00128 #ifdef USE_INTERNAL_COMPARATORS 00129 DIDR0 = (1<<ADC6D)|(1<<ADC5D)|(1<<ADC3D)|(1<<ADC2D); 00130 DIDR1 = (1<<ADC10D)|(1<<ACMP0D); 00131 #endif 00132 00133 // Select the Vref Source 00134 // init_vref_source (); 00135 00136 // init_adc(); 00137 Adc_config(); 00138 Amp1_config(); 00139 00140 // Be careful : initialize DAC and Over_Current before PWM. 00141 // DAC is used for oevr current level 00142 Dac_config(); 00143 /* set the overcurrent level */ 00144 Dac_set_8_bits(IMAX); 00145 00146 mc_init_timer0(); 00147 mc_init_timer1(); 00148 00149 Comp_0_config(); 00150 Comp_1_config(); 00151 Comp_2_config(); 00152 00153 // Use PCINT14 to detect change on H2 sensor 00154 PCMSK0 = (1<<PCINT4)|(1<<PCINT3); 00155 PCMSK1 = (1<<PCINT11); 00156 PCICR = (1<<PCIE1)|(1<<PCIE0); 00157 00158 // Start_pll_32_mega(); // Start the PLL and use the 32 MHz PLL output 00159 Start_pll_64_mega(); // Start the PLL and use the 64 MHz PLL output 00160 Wait_pll_ready(); 00161 00162 00163 // => PSCx_Init(Period_Half, Dutyx0_Half, Synchro, Dutyx1_Half) 00164 PSC_Init(); 00165 00166 }
| void mc_init_timer0 | ( | void | ) |
Timer 0 Configuration The timer 0 is used to generate an IT when an overflow occurs.
Definition at line 599 of file mc_drv.c.
Referenced by mc_init_HW().
00600 { 00601 TCCR0A = 0; 00602 TCCR0B = (0<<CS02)|(1<<CS01)|(1<<CS00); // prescaler /64 (4us) 00603 TIMSK0 = (1<<TOIE0); 00604 }
| void mc_init_timer1 | ( | void | ) |
timer 1 Configuration
Definition at line 357 of file mc_drv.c.
Referenced by mc_init_HW().
00358 { 00359 TCCR1A = 0; //Normal port operation + Mode CTC 00360 TCCR1B = 1<<CS11 | 1<<CS10 ; // Mode CTC + prescaler 64 => T timer1 = 4µS 00361 TCCR1C = 0; 00362 }
| 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 724 of file mc_drv.c.
References Enable_over_current, FALSE, inrush_delay, inrush_mask_flag, and TRUE.
00725 { 00726 if (inrush_mask_flag == TRUE) 00727 { 00728 if (inrush_delay-- == 0) 00729 { 00730 inrush_mask_flag = FALSE; 00731 Enable_over_current(); 00732 } 00733 } 00734 }
| __interrupt void mc_overcurrent_detect | ( | void | ) |
Definition at line 741 of file mc_drv.c.
References mci_stop(), overcurrent, and TRUE.
00743 { 00744 PIFR = (1<<PEV1); // clear the interrupt 00745 overcurrent = TRUE; 00746 mci_stop(); 00747 }
| void mc_switch_commutation | ( | Motor_Position | position | ) |
Set the Switching Commutation value on outputs.
| position | (1 to 6) and direction (FORWARD or BACKWARD) |
Definition at line 311 of file mc_drv.c.
References mci_get_motor_direction(), mci_motor_is_running(), motor_step, MS_001, MS_010, MS_011, MS_100, MS_101, MS_110, Set_none, Set_Q1Q4, Set_Q1Q6, Set_Q3Q2, Set_Q3Q6, Set_Q5Q2, and Set_Q5Q4.
Referenced by main(), mci_retry_run(), and mci_run().
00312 { 00313 // get the motor direction to commute the right switches. 00314 char direction = mci_get_motor_direction(); 00315 00316 // Switches are commuted only if the user start the motor 00317 if (mci_motor_is_running()) 00318 { 00319 switch(position) 00320 { 00321 // cases according to rotor position 00322 case MS_001: {Set_Q1Q6();motor_step=MS_001;} 00323 break; 00324 00325 case MS_101: {Set_Q1Q4();motor_step=MS_101;} 00326 break; 00327 00328 case MS_100: {Set_Q5Q4();motor_step=MS_100;} 00329 break; 00330 00331 case MS_110: {Set_Q5Q2();motor_step=MS_110;} 00332 break; 00333 00334 case MS_010: {Set_Q3Q2();motor_step=MS_010;} 00335 break; 00336 00337 case MS_011: {Set_Q3Q6();motor_step=MS_011;} 00338 break; 00339 default : break; 00340 } 00341 } 00342 else 00343 { 00344 Set_none(); // all switches are switched OFF 00345 } 00346 }
| __interrupt void ovfl_timer0 | ( | void | ) |
Timer0 Overflow => 4µS.
Definition at line 614 of file mc_drv.c.
References g_tick, timer0_ext, and TRUE.
00616 { 00617 timer0_ext++; 00618 g_tick = TRUE; 00619 }
| void PSC_Init | ( | void | ) |
PSC Init : Initialize the PSC according to the settings in config.h.
Definition at line 172 of file mc_drv.c.
References A_RA_VAL, A_SA_VAL, A_SB_VAL, B_RA_VAL, B_SA_VAL, B_SB_VAL, C_RA_VAL, C_SA_VAL, C_SB_VAL, Psc_config, Psc_config_input_0, Psc_config_input_1, Psc_config_input_2, PSC_INPUT_FILTER_ENABLE, PSC_INPUT_NO_ACTION, PSC_OVERLAP_ENABLE, Psc_run, Psc_set_module_A, Psc_set_module_B, Psc_set_module_C, Psc_set_register_RB, PSC_SYNCHRONOUS_OUTPUT_CONTROL, PSC_USE_COMPARATOR, PSC_USE_HIGH_LEVEL, PSC_USE_LOW_LEVEL, PSC_USE_PIN, and RB_VAL.
Referenced by mc_init_HW(), and mci_run().
00173 { 00174 Psc_set_module_A(A_SA_VAL,A_RA_VAL,A_SB_VAL); 00175 Psc_set_module_B(B_SA_VAL,B_RA_VAL,B_SB_VAL); 00176 Psc_set_module_C(C_SA_VAL,C_RA_VAL,C_SB_VAL); 00177 Psc_set_register_RB(RB_VAL); 00178 00179 Psc_config(); 00180 00181 Psc_config_input_0(PSC_OVERLAP_ENABLE,\ 00182 PSC_USE_PIN,\ 00183 PSC_USE_LOW_LEVEL,\ 00184 PSC_INPUT_FILTER_ENABLE,\ 00185 PSC_SYNCHRONOUS_OUTPUT_CONTROL,\ 00186 PSC_INPUT_NO_ACTION); 00187 00188 Psc_config_input_1(PSC_OVERLAP_ENABLE,\ 00189 PSC_USE_COMPARATOR,\ 00190 PSC_USE_HIGH_LEVEL,\ 00191 PSC_INPUT_FILTER_ENABLE,\ 00192 PSC_SYNCHRONOUS_OUTPUT_CONTROL,\ 00193 PSC_INPUT_NO_ACTION); 00194 00195 Psc_config_input_2(PSC_OVERLAP_ENABLE,\ 00196 PSC_USE_PIN,\ 00197 PSC_USE_LOW_LEVEL,\ 00198 PSC_INPUT_FILTER_ENABLE,\ 00199 PSC_SYNCHRONOUS_OUTPUT_CONTROL,\ 00200 PSC_INPUT_NO_ACTION); 00201 00202 PIFR = (1<<PEV2)|(1<<PEV1)|(1<<PEV0)|(1<<PEOP); 00203 PIM = (1<<PEVE1); 00204 00205 Psc_run(); 00206 }
| void start_running_phase | ( | void | ) |
Definition at line 570 of file mc_drv.c.
References HIGH, LOW, TIMER1_AT_STARTUP_END, and top_average.
Referenced by main().
00571 { 00572 U16 top; 00573 TCCR1B = 0 ; // stop timer 1 00574 top_average = TIMER1_AT_STARTUP_END; 00575 top = (top_average >> 1); 00576 TCNT1H = HIGH(top); 00577 TCNT1L = LOW(top); 00578 OCR1AH = 0; 00579 OCR1AL = 0; 00580 top = top + (top_average >> 2); 00581 OCR1BH = HIGH(top); 00582 OCR1BL = LOW(top); 00583 TCCR1B = (1<<CS11) | (1<<CS10) ; // start timer 1 00584 TIFR1 = (1<<OCF1B) | (1<<OCF1A) | (1<<TOV1); 00585 TIMSK1= (1<<OCIE1B) | (1<<OCIE1A); // Output compare A Match interrupt Enable 00586 }
| __interrupt void thirty_degres_interrupt | ( | void | ) |
30 degres interrupt
Definition at line 372 of file mc_drv.c.
References CCW, mci_get_motor_direction(), mci_motor_is_running(), motor_step, MS_001, MS_010, MS_011, MS_100, MS_101, MS_110, Set_none, Set_Q1Q4, Set_Q1Q6, Set_Q3Q2, Set_Q3Q6, Set_Q5Q2, and Set_Q5Q4.
00374 { 00375 char direction = mci_get_motor_direction(); 00376 00377 if (mci_motor_is_running()) 00378 { 00379 00380 switch(motor_step) 00381 { 00382 case (MS_100): 00383 if (direction==CCW) {Set_Q1Q4();motor_step=MS_101;} 00384 else {Set_Q5Q2();motor_step=MS_110;} 00385 break; 00386 00387 case (MS_110): 00388 if (direction==CCW) {Set_Q5Q4();motor_step=MS_100;} 00389 else {Set_Q3Q2();motor_step=MS_010;} 00390 break; 00391 00392 case (MS_010): 00393 if (direction==CCW) {Set_Q5Q2();motor_step=MS_110;} 00394 else {Set_Q3Q6();motor_step=MS_011;} 00395 break; 00396 00397 case (MS_011): 00398 if (direction==CCW) {Set_Q3Q2();motor_step=MS_010;} 00399 else {Set_Q1Q6();motor_step=MS_001;} 00400 break; 00401 00402 case (MS_001): 00403 if (direction==CCW) {Set_Q3Q6();motor_step=MS_011;} 00404 else {Set_Q1Q4();motor_step=MS_101;} 00405 break; 00406 00407 case (MS_101): 00408 if (direction==CCW) {Set_Q1Q6();motor_step=MS_001;} 00409 else {Set_Q5Q4();motor_step=MS_100;} 00410 break; 00411 00412 default : 00413 Set_none(); // all switches are switched OFF 00414 motor_step=MS_010; 00415 break; 00416 00417 } 00418 } 00419 }
char ADC_State = FREE [static] |
Definition at line 79 of file mc_drv.c.
Referenced by ADC_end_of_conversion(), and mc_ADC_Scheduler().
| Bool current_EOC = FALSE |
Use for control the sampling period value.
Definition at line 74 of file mc_drv.c.
Referenced by main(), and ovfl_timer0().
U16 inrush_delay = 0 [static] |
Definition at line 66 of file mc_drv.c.
Referenced by mc_disable_during_inrush(), and mc_inrush_task().
Bool inrush_mask_flag = FALSE [static] |
Definition at line 65 of file mc_drv.c.
Referenced by mc_disable_during_inrush(), and mc_inrush_task().
U8 motor_step [static] |
Definition at line 72 of file mc_drv.c.
Referenced by demag_interrupt(), mc_switch_commutation(), and thirty_degres_interrupt().
| Bool overcurrent = FALSE |
char State = CONV_INIT [static] |
Definition at line 78 of file mc_drv.c.
Referenced by ADC_end_of_conversion(), and mc_ADC_Scheduler().
U16 stored_time = 0 [static] |
volatile U8 timer0_ext = 0 [static] |
U32 top_average = 200 [static] |
Definition at line 70 of file mc_drv.c.
Referenced by mc_comparator_0(), mc_comparator_1(), mc_comparator_2(), and start_running_phase().
1.5.7.1