Definition in file mc_drv.c.
#include "config.h"
#include "config_motor.h"
#include "mc_drv.h"
#include "mc_interface.h"
#include "mc_control.h"
#include "adc\adc_drv.h"
#include "dac\dac_drv.h"
#include "amplifier\amplifier_drv.h"
#include "pll\pll_drv.h"
#include "comparator\comparator_drv.h"
Include dependency graph for mc_drv.c:

Go to the source code of this file.
Functions | |
| __interrupt void | ADC_EOC (void) |
| Launch the sampling procedure to get current value. | |
| void | mc_ADC_Scheduler (void) |
| Launch the scheduler for the ADC. | |
| void | mc_config_sampling_period (void) |
| Timer 1 Configuration Use to generate a 250us activation for main loop. | |
| void | mc_config_time_estimation_speed (void) |
| Timer 0 Configuration The timer 0 is used to generate an IT when an overflow occurs. | |
| 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 | |
| U8 | mc_get_hall (void) |
| Get the value of hall sensors (1 to 6). | |
| S32 | mc_get_Num_Turn () |
| Get the number of rotor rotation. | |
| __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. | |
| __interrupt void | mc_hall_c (void) |
| External interruption Hall Sensor (C) mode toggle. | |
| void | mc_init_HW (void) |
| init hardware (peripherals) | |
| void | mc_init_IT (void) |
| Initialization of AT90PWM3B External Interrupts. | |
| void | mc_init_port (void) |
| Initialization of IO PORTS for AT90PWM3B. | |
| void | mc_init_pwm () |
| Initialization of PWM generators (PSC) for AT90PWM3B. | |
| void | mc_init_SW (void) |
| init SW | |
| void | mc_reset_Num_Turn () |
| Reset the number of rotor rotation. | |
| void | mc_set_Over_Current (U8 Level) |
| Set the Over Current threshold. | |
| void | mc_switch_commutation (U8 position) |
| Set the Switching Commutation value on outputs according to sensor or estimation position. | |
| __interrupt void | ovfl_timer (void) |
| Timer0 Overflow for speed measurement. | |
| void | PSC0_Init (unsigned int OCRnRB, unsigned int OCRnSB, unsigned int OCRnRA, unsigned int OCRnSA) |
| Initialization of PWM generator PSC0. | |
| void | PSC1_Init (unsigned int OCRnRB, unsigned int OCRnSB, unsigned int OCRnRA, unsigned int OCRnSA) |
| Initialization of PWM generator PSC1. | |
| void | PSC2_Init (unsigned int OCRnRB, unsigned int OCRnSB, unsigned int OCRnRA, unsigned int OCRnSA) |
| Initialization of PWM generator PSC2. | |
| void | PSC_Run (void) |
| void | PSC_Stop (void) |
| __interrupt void | timer1_periodic_interrupt (void) |
| Timer 1 interrupt Timer 1 generates a periodic interrupt for motor and main loop. | |
Variables | |
| static char | ADC_State = FREE |
| State of the ADC scheduler. | |
| static U16 | average = 0 |
| variable "count" is use for calculate the "average" speed on 'n' samples | |
| volatile S16 | comp_delay_30d = MIN_DELAY |
| static U8 | count = 1 |
| static U8 | count_sub_tick = 8 |
| static U8 | delay_30d = 0 |
| static Bool | delay_armed = FALSE |
| static U8 | delay_mask = 0 |
| static Bool | g_mc_read_enable = FALSE |
| variable "ovf_timer" is use to simulate a 16 bits timer with 8 bits timer | |
| Bool | g_tick = FALSE |
| Use for control the sampling period value. | |
| static U8 | hall_state = 0 |
| Used to count the number of motor revolutions. | |
| static S32 | Num_turn = 0 |
| static U8 | ovf_timer = 0 |
| average of speed | |
| static char | State = CONV_INIT |
| __interrupt void ADC_EOC | ( | void | ) |
Launch the sampling procedure to get current value.
Definition at line 640 of file mc_drv.c.
References Adc_get_10_bits_result, Adc_get_8_bits_result, ADC_State, CONV_CURRENT, CONV_POT, FREE, mci_store_measured_current(), mci_store_potentiometer_value(), and State.
00641 { 00642 if(State == CONV_CURRENT) mci_store_potentiometer_value(Adc_get_8_bits_result()); 00643 if(State == CONV_POT) mci_store_measured_current(Adc_get_10_bits_result()); 00644 ADC_State = FREE; 00645 }
Here is the call graph for this function:

| void mc_ADC_Scheduler | ( | void | ) |
Launch the scheduler for the ADC.
Definition at line 652 of file mc_drv.c.
References ADC_State, BUSY, CONV_CURRENT, CONV_INIT, CONV_POT, FREE, init_adc(), Left_adjust_adc_result, Right_adjust_adc_result, Start_amplified_conv_channel, Start_conv_channel, and State.
Referenced by main().
00653 { 00654 switch(State) 00655 { 00656 case CONV_INIT : 00657 init_adc(); 00658 init_amp1(); 00659 ADC_State = FREE; 00660 State = CONV_POT; 00661 break; 00662 00663 case CONV_POT : 00664 if(ADC_State == FREE) 00665 { 00666 ADC_State = BUSY; 00667 State= CONV_CURRENT; 00668 Left_adjust_adc_result(); 00669 Start_conv_channel(6); 00670 } 00671 break; 00672 00673 case CONV_CURRENT : 00674 if(ADC_State == FREE) 00675 { 00676 ADC_State = BUSY; 00677 State = CONV_POT; 00678 Right_adjust_adc_result(); 00679 Start_amplified_conv_channel(12); 00680 // Start_conv_channel(9); 00681 } 00682 break; 00683 } 00684 00685 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void mc_config_sampling_period | ( | void | ) |
Timer 1 Configuration Use to generate a 250us activation for main loop.
Definition at line 495 of file mc_drv.c.
References CS10, CS11, OCIE1A, and WGM12.
Referenced by mc_init_HW().
00496 { 00497 TCCR1A = 0; /* Normal port operation + Mode CTC */ 00498 TCCR1B = 1<<WGM12 | 1<<CS11 | 1<<CS10 ; /* Mode CTC + prescaler 64 */ 00499 TCCR1C = 0; 00500 OCR1AH = 0; 00501 OCR1AL = 7; /* 31.25 µS */ 00502 TIMSK1=(1<<OCIE1A); /* Output compare B Match interrupt Enable */ 00503 }
Here is the caller graph for this function:

| void mc_config_time_estimation_speed | ( | void | ) |
Timer 0 Configuration The timer 0 is used to generate an IT when an overflow occurs.
Definition at line 559 of file mc_drv.c.
References CS00, CS01, CS02, and TOIE0.
Referenced by mc_init_HW().
00560 { 00561 TCCR0A = 0; 00562 TCCR0B = (0<<CS02)|(1<<CS01)|(1<<CS00); // 64 prescaler (8us) 00563 TIMSK0 = (1<<TOIE0); 00564 }
Here is the caller graph for this function:

| 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 379 of file mc_drv.c.
References PCLKSEL0, PCLKSEL1, PCLKSEL2, POP0, POP1, POP2, RAMP_MODE_NUMBER, RELEASE_PLOCK, and SET_PLOCK.
Referenced by mc_switch_commutation().
00380 { 00381 U8 duty; 00382 duty = level; 00383 00384 PCNF0 = SET_PLOCK | RAMP_MODE_NUMBER |(1<<PCLKSEL0)|(1<<POP0); /* set plock */ 00385 PCNF1 = SET_PLOCK | RAMP_MODE_NUMBER |(1<<PCLKSEL1)|(1<<POP1); /* set plock */ 00386 PCNF2 = SET_PLOCK | RAMP_MODE_NUMBER |(1<<PCLKSEL2)|(1<<POP2); /* set plock */ 00387 00388 // Duty = 0 => Duty Cycle 0% 00389 // Duty = 255 => Duty Cycle 100% 00390 00391 // Set the duty cycle for PSCn0 00392 OCR0SAH = 0; 00393 OCR0SAL = 255 - duty; 00394 00395 OCR1SAH = 0; 00396 OCR1SAL = 255 - duty; 00397 00398 OCR2SAH = 0; 00399 OCR2SAL = 255 - duty; 00400 00401 // Set the duty cycle for PSCn1 according to the PWM strategy 00402 #ifdef HIGH_AND_LOW_PWM 00403 // apply PWM on high side and low side switches 00404 OCR0SBH = 0; 00405 OCR0SBL = 255 - duty ; 00406 00407 OCR1SBH = 0; 00408 OCR1SBL = 255 - duty ; 00409 00410 OCR2SBH = 0; 00411 OCR2SBL = 255 - duty ; 00412 #else 00413 // PWM is only applied on high side switches 00414 // 100% duty cycle on low side switches 00415 OCR0SBH = 0; 00416 OCR0SBL = 2; 00417 00418 OCR1SBH = 0; 00419 OCR1SBL = 2; 00420 00421 OCR2SBH = 0; 00422 OCR2SBL = 2; 00423 #endif 00424 00425 Disable_interrupt(); 00426 PCNF0 = RELEASE_PLOCK | RAMP_MODE_NUMBER |(1<<PCLKSEL0)|(1<<POP0); /* release plock */ 00427 PCNF1 = RELEASE_PLOCK | RAMP_MODE_NUMBER |(1<<PCLKSEL1)|(1<<POP1); /* release plock */ 00428 PCNF2 = RELEASE_PLOCK | RAMP_MODE_NUMBER |(1<<PCLKSEL2)|(1<<POP2); /* release plock */ 00429 Enable_interrupt(); 00430 }
Here is the caller graph for this function:

| void mc_estimation_speed | ( | void | ) |
estimation speed
Definition at line 590 of file mc_drv.c.
References average, comp_delay_30d, count, FILTER_DELAY, g_mc_read_enable, K_SPEED, KO, MAX_DELAY, mci_store_measured_speed(), MIN_DELAY, OK, and ovf_timer.
Referenced by mc_hall_a().
00591 { 00592 U16 timer_value; 00593 U32 new_measured_speed; 00594 00595 if (g_mc_read_enable==OK) 00596 { 00597 // Two 8 bits variables are use to simulate a 16 bits timers 00598 timer_value = (ovf_timer<<8) + TCNT0; 00599 00600 /* compute delay for 30 degres */ 00601 comp_delay_30d = (timer_value / 94) - FILTER_DELAY; 00602 /* apply a saturation */ 00603 if (comp_delay_30d < (S16)MIN_DELAY) comp_delay_30d = MIN_DELAY; 00604 else if (comp_delay_30d > (S16)MAX_DELAY) comp_delay_30d = MAX_DELAY; 00605 00606 if (timer_value == 0) {timer_value += 1 ;} // warning DIV by 0 00607 new_measured_speed = K_SPEED / timer_value; 00608 if(new_measured_speed > 255) new_measured_speed = 255; // Variable saturation 00609 00610 00611 // To avoid noise an average is realized on 16 samples 00612 average += new_measured_speed; 00613 if(count >= 16) 00614 { 00615 count = 1; 00616 mci_store_measured_speed(average >> 4); 00617 average = 0; 00618 } 00619 else count++; 00620 00621 // Reset Timer 0 register and variables 00622 TCNT0=0x00; 00623 ovf_timer = 0; 00624 g_mc_read_enable=KO; 00625 } 00626 }
Here is the call graph for this function:

Here is the caller graph for this function:

| U8 mc_get_hall | ( | void | ) |
Get the value of hall sensors (1 to 6).
| return | an unsigned char value of hall sensor |
Definition at line 288 of file mc_drv.c.
References HALL_SENSOR_VALUE.
00289 { 00290 return HALL_SENSOR_VALUE(); /* sensor */ 00291 // return ((~HALL_SENSOR_VALUE())&0x07); /* sensorless */ 00292 }
| S32 mc_get_Num_Turn | ( | void | ) |
Get the number of rotor rotation.
Definition at line 715 of file mc_drv.c.
References Num_turn.
Referenced by mc_control_position().
00716 { 00717 return Num_turn; 00718 }
Here is the caller graph for this function:

| __interrupt void mc_hall_a | ( | void | ) |
External interruption Sensor (A) mode toggle.
Definition at line 301 of file mc_drv.c.
References AC0O, comp_delay_30d, delay_30d, delay_armed, FALSE, g_mc_read_enable, hall_state, mc_estimation_speed(), Num_turn, PORTD7, and TRUE.
00302 { 00303 00304 delay_armed = TRUE; 00305 delay_30d = comp_delay_30d; 00306 00307 //estimation speed on rising edge of Hall_A 00308 #ifdef USE_INTERNAL_COMPARATORS 00309 if (ACSR&(1<<AC0O)) 00310 #else 00311 if (PIND&(1<<PORTD7)) 00312 #endif 00313 { 00314 mc_estimation_speed(); 00315 g_mc_read_enable=FALSE; // Wait 1 period 00316 } 00317 else 00318 { 00319 g_mc_read_enable=TRUE; 00320 } 00321 00322 00323 switch(hall_state) 00324 { 00325 case 2 : Num_turn++;break; 00326 case 3 : Num_turn--;break; 00327 default: break; 00328 } 00329 hall_state = 1; 00330 }
Here is the call graph for this function:

| __interrupt void mc_hall_b | ( | void | ) |
External interruption Hall Sensor (B) mode toggle.
Definition at line 339 of file mc_drv.c.
References comp_delay_30d, delay_30d, delay_armed, hall_state, Num_turn, and TRUE.
00340 { 00341 00342 delay_armed = TRUE; 00343 delay_30d = comp_delay_30d; 00344 00345 switch(hall_state) 00346 { 00347 case 1 : Num_turn--;break; 00348 case 3 : Num_turn++;break; 00349 default: break; 00350 } 00351 hall_state = 2; 00352 }
| __interrupt void mc_hall_c | ( | void | ) |
External interruption Hall Sensor (C) mode toggle.
Definition at line 361 of file mc_drv.c.
References comp_delay_30d, delay_30d, delay_armed, hall_state, Num_turn, and TRUE.
00362 { 00363 00364 delay_armed = TRUE; 00365 delay_30d = comp_delay_30d; 00366 00367 switch(hall_state) 00368 { 00369 case 2 : Num_turn--;break; 00370 case 1 : Num_turn++;break; 00371 default: break; 00372 } 00373 hall_state = 3; 00374 }
| void mc_init_HW | ( | void | ) |
init hardware (peripherals)
Definition at line 57 of file mc_drv.c.
References init_comparator0(), init_comparator1(), init_comparator2(), init_dac(), mc_config_sampling_period(), mc_config_time_estimation_speed(), mc_init_IT(), mc_init_port(), mc_init_pwm(), and mc_set_Over_Current().
Referenced by mc_motor_init().
00058 { 00059 mc_init_port(); 00060 mc_init_IT(); 00061 00062 // Be careful : initialize DAC and Over_Current before PWM. 00063 init_dac(); 00064 mc_set_Over_Current(200); // 5 => 1A ; 8 => 40A 00065 mc_init_pwm(); 00066 00067 mc_config_time_estimation_speed(); 00068 mc_config_sampling_period(); 00069 00070 init_comparator0(); 00071 init_comparator1(); 00072 init_comparator2(); 00073 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void mc_init_IT | ( | void | ) |
Initialization of AT90PWM3B External Interrupts.
Definition at line 168 of file mc_drv.c.
References INT0, INT1, INT2, INTF0, INTF1, INTF2, ISC00, ISC01, ISC10, ISC11, ISC20, and ISC21.
Referenced by mc_init_HW().
00169 { 00170 EICRA =(0<<ISC21)|(1<<ISC20)|(0<<ISC11)|(1<<ISC10)|(0<<ISC01)|(1<<ISC00); 00171 EIFR = (1<<INTF2)|(1<<INTF1)|(1<<INTF0); // clear possible IT due to config 00172 EIMSK=(1<<INT2)|(1<<INT1)|(1<<INT0); 00173 }
Here is the caller graph for this function:

| void mc_init_port | ( | void | ) |
Initialization of IO PORTS for AT90PWM3B.
Definition at line 90 of file mc_drv.c.
References ACMP0D, ACMP1D, ADC2D, ADC3D, ADC6D, AMP1ND, AMP1PD, DDB0, DDB1, DDB3, DDB4, DDB5, DDB6, DDB7, DDC0, DDC1, DDC2, DDD0, DDD2, DDD3, DDD4, DDE0, DDE1, DDE2, PORTB0, PORTB1, PORTB3, PORTB6, PORTB7, PORTC0, PORTC1, PORTC6, PORTD0, PORTD1, PORTD5, and PORTD7.
Referenced by mc_init_HW().
00091 { 00092 // Output Pin configuration 00093 // PD0 => H_A PB7 => L_A 00094 // PC0 => H_B PB6 => L_B 00095 // PB0 => H_C PB1 => L_C 00096 00097 //Do not modify PSCOUT Configuration 00098 // PORT B : 00099 DDRB = (1<<DDB7)|(1<<DDB6)|(1<<DDB3)|(1<<DDB1)|(1<<DDB0); 00100 // PORT C : 00101 DDRC = (1<<DDC0); 00102 // PORT D : 00103 DDRD = (1<<DDD0); 00104 00105 00106 // DDnx = 0:Input 1:Output (n = B,C,D,E ; x = 0,1,2,3,4,5,6,7) 00107 // PB3 => EXT1 PB4 => EXT2 00108 // PC1 => EXT3 PC2 => EXT4 00109 // PB5 => EXT5/POT PE1 => EXT6 00110 // PD3 => EXT7/MOSI/LIN_TxD/TxD PD4 => EXT8/MISO/LIN_RxD/RxD 00111 // PE0 => EXT9/NRES PD2 => EXT10/MISO 00112 00113 // Modify DDnx according to your hardware implementation 00114 // PORT B : 00115 DDRB |= (0<<DDB5)|(1<<DDB4)|(0<<DDB3); 00116 // PORT C : 00117 DDRC |= (0<<DDC2)|(0<<DDC1); 00118 // PORT D : 00119 DDRD |= (0<<DDD4)|(0<<DDD3)|(0<<DDD2); // Becareful if using the UART interface or JTAGE ICE mkII. 00120 // PORT E : 00121 DDRE |= (1<<DDE2)|(0<<DDE1)|(0<<DDE0); // Becareful PE0 is you by JTAGE ICE mkII. 00122 00123 00124 // Warning Output Low for MOSFET Drivers 00125 PORTB &= ~(1<<PORTB7 | 1<<PORTB6 | 1<<PORTB3 |1<<PORTB1 | 1<<PORTB0); 00126 PORTC &= ~(1<<PORTC0); 00127 PORTD &= ~(1<<PORTD0); 00128 00129 // pull up activation 00130 PORTC |= (1<<PORTC6)|(1<<PORTC1); 00131 PORTD |= (1<<PORTD7)|(1<<PORTD5)|(1<<PORTD1); 00132 00133 // Disable Digital Input for amplifier1 00134 // Digitals Inputs for comparators are not disable. 00135 DIDR0 = (0<<ADC6D)|(0<<ADC3D)|(0<<ADC2D); 00136 DIDR1 = (0<<ACMP0D)|(0<<ACMP1D)|(1<<AMP1PD)|(1<<AMP1ND); 00137 }
Here is the caller graph for this function:

| void mc_init_pwm | ( | void | ) |
Initialization of PWM generators (PSC) for AT90PWM3B.
Definition at line 144 of file mc_drv.c.
References PSC0_Init(), PSC1_Init(), PSC2_Init(), Start_pll_32_mega, and Wait_pll_ready.
Referenced by mc_init_HW().
00145 { 00146 Start_pll_32_mega(); 00147 Wait_pll_ready(); 00148 00149 // In Center Aligned Mode : 00150 // => PSCx_Init(Period_Half, Dutyx0_Half, Synchro, Dutyx1_Half) 00151 #ifdef MCU_REV_B 00152 PSC0_Init(255,0,255,0); 00153 PSC1_Init(255,0,255,0); 00154 PSC2_Init(255,0,255,0); 00155 #else 00156 PSC0_Init(255,0,1,0); 00157 PSC1_Init(255,0,1,0); 00158 PSC2_Init(255,0,1,0); 00159 #endif 00160 00161 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void mc_init_SW | ( | void | ) |
init SW
Definition at line 80 of file mc_drv.c.
Referenced by mc_motor_init().
Here is the caller graph for this function:

| void mc_reset_Num_Turn | ( | void | ) |
| void mc_set_Over_Current | ( | U8 | Level | ) |
Set the Over Current threshold.
Definition at line 698 of file mc_drv.c.
References Set_dac_8_bits.
Referenced by mc_init_HW().
00699 { 00700 Set_dac_8_bits(Level); 00701 }
Here is the caller graph for this function:

| void mc_switch_commutation | ( | U8 | position | ) |
Set the Switching Commutation value on outputs according to sensor or estimation position.
| position | (1 to 6) and direction (FORWARD or BACKWARD) |
Definition at line 438 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(), mci_get_motor_direction, mci_get_motor_speed(), mci_motor_is_running(), Set_none, Set_Q1Q4, Set_Q1Q6, Set_Q3Q2, Set_Q3Q6, Set_Q5Q2, and Set_Q5Q4.
Referenced by main(), and timer1_periodic_interrupt().
00439 { 00440 // get the motor direction to commute the right switches. 00441 char direction = mci_get_motor_direction(); 00442 00443 // Switches are commuted only if the user start the motor and 00444 // the speed consign is different from 0. 00445 if ((mci_motor_is_running()) && (mci_get_motor_speed()!=0)) 00446 { 00447 mc_duty_cycle(mc_get_Duty_Cycle()); 00448 switch(position) 00449 { 00450 // cases according to rotor position 00451 case HS_001: if (direction==CCW) {Set_Q3Q2();} 00452 else {Set_Q5Q2();} 00453 break; 00454 00455 case HS_101: if (direction==CCW) {Set_Q5Q2();} 00456 else {Set_Q5Q4();} 00457 break; 00458 00459 case HS_100: if (direction==CCW) {Set_Q5Q4();} 00460 else {Set_Q1Q4();} 00461 break; 00462 00463 case HS_110: if (direction==CCW) {Set_Q1Q4();} 00464 else {Set_Q1Q6();} 00465 break; 00466 00467 case HS_010: if (direction==CCW) {Set_Q1Q6();} 00468 else {Set_Q3Q6();} 00469 break; 00470 00471 case HS_011: if (direction==CCW) {Set_Q3Q6();} 00472 else {Set_Q3Q2();} 00473 break; 00474 default : break; 00475 } 00476 } 00477 else 00478 { 00479 Set_none(); // all switches are switched OFF 00480 } 00481 }
Here is the call graph for this function:

Here is the caller graph for this function:

| __interrupt void ovfl_timer | ( | void | ) |
Timer0 Overflow for speed measurement.
Definition at line 572 of file mc_drv.c.
References mci_store_measured_speed(), and ovf_timer.
00573 { 00574 TCNT0=0x00; 00575 ovf_timer++; 00576 // if they are no commutation after 125 ms 00577 // 125 ms = (61<<8) * 8us 00578 if(ovf_timer >= 100) 00579 { 00580 ovf_timer = 0; 00581 mci_store_measured_speed(0); 00582 } 00583 }
Here is the call graph for this function:

| void PSC0_Init | ( | unsigned int | OCRnRB, | |
| unsigned int | OCRnSB, | |||
| unsigned int | OCRnRA, | |||
| unsigned int | OCRnSA | |||
| ) |
Initialization of PWM generator PSC0.
Definition at line 184 of file mc_drv.c.
References HIGH, LOW, OUTPUT_ACTIVE_HIGH, PAOC0A, PARUN0, PCLKSEL0, PELEV0A, PFLTE0A, PRESC_DIV_BY_4, PRFM0A0, PRFM0A1, PRFM0A2, PRFM0A3, PSYNC00, and RAMP_MODE_NUMBER.
Referenced by mc_init_pwm().
00188 { 00189 OCR0SAH = HIGH(OCRnSA); 00190 OCR0SAL = LOW(OCRnSA); 00191 OCR0RAH = HIGH(OCRnRA); 00192 OCR0RAL = LOW(OCRnRA); 00193 OCR0SBH = HIGH(OCRnSB); 00194 OCR0SBL = LOW(OCRnSB); 00195 OCR0RBH = HIGH(OCRnRB); 00196 OCR0RBL = LOW(OCRnRB); 00197 00198 PCNF0 = RAMP_MODE_NUMBER | (1<<PCLKSEL0) | OUTPUT_ACTIVE_HIGH ; 00199 /* use PSC 0 Input A as Fault Input */ 00200 PFRC0A = (1<<PELEV0A)|(1<<PFLTE0A)|(0<<PRFM0A3)|(1<<PRFM0A2)|(1<<PRFM0A1)|(1<<PRFM0A0); 00201 // PFRC0A = 0; 00202 PFRC0B = 0; 00203 PSOC0 = (1<<PSYNC00); //Send signal on match with OCRnSA (during counting up of PSC) 00204 PCTL0 = (0<<PAOC0A)|(1<<PARUN0)|PRESC_DIV_BY_4; /* AUTORUN !! */ 00205 }
Here is the caller graph for this function:

| void PSC1_Init | ( | unsigned int | OCRnRB, | |
| unsigned int | OCRnSB, | |||
| unsigned int | OCRnRA, | |||
| unsigned int | OCRnSA | |||
| ) |
Initialization of PWM generator PSC1.
Definition at line 210 of file mc_drv.c.
References HIGH, LOW, OUTPUT_ACTIVE_HIGH, PAOC1A, PARUN1, PCLKSEL1, PRESC_DIV_BY_4, and RAMP_MODE_NUMBER.
Referenced by mc_init_pwm().
00214 { 00215 OCR1SAH = HIGH(OCRnSA); 00216 OCR1SAL = LOW(OCRnSA); 00217 OCR1RAH = HIGH(OCRnRA); 00218 OCR1RAL = LOW(OCRnRA); 00219 OCR1SBH = HIGH(OCRnSB); 00220 OCR1SBL = LOW(OCRnSB); 00221 OCR1RBH = HIGH(OCRnRB); 00222 OCR1RBL = LOW(OCRnRB); 00223 00224 PCNF1 = RAMP_MODE_NUMBER | (1<<PCLKSEL1) | OUTPUT_ACTIVE_HIGH ; 00225 PFRC1A = 0; 00226 PFRC1B = 0; 00227 PCTL1 = (0<<PAOC1A)|(1<<PARUN1)|PRESC_DIV_BY_4; /* AUTORUN !! */ 00228 }
Here is the caller graph for this function:

| void PSC2_Init | ( | unsigned int | OCRnRB, | |
| unsigned int | OCRnSB, | |||
| unsigned int | OCRnRA, | |||
| unsigned int | OCRnSA | |||
| ) |
Initialization of PWM generator PSC2.
Definition at line 234 of file mc_drv.c.
References HIGH, LOW, OUTPUT_ACTIVE_HIGH, PCLKSEL2, and RAMP_MODE_NUMBER.
Referenced by mc_init_pwm().
00238 { 00239 OCR2SAH = HIGH(OCRnSA); 00240 OCR2SAL = LOW(OCRnSA); 00241 OCR2RAH = HIGH(OCRnRA); 00242 OCR2RAL = LOW(OCRnRA); 00243 OCR2SBH = HIGH(OCRnSB); 00244 OCR2SBL = LOW(OCRnSB); 00245 OCR2RBH = HIGH(OCRnRB); 00246 OCR2RBL = LOW(OCRnRB); 00247 00248 PCNF2 = RAMP_MODE_NUMBER | (1<<PCLKSEL2) | OUTPUT_ACTIVE_HIGH ; 00249 PFRC2A = 0; 00250 PFRC2B = 0; 00251 // PCTL2 = (0<<PAOC2A)|(1<<PRUN2)|PRESC_DIV_BY_4; /* RUN !! */ 00252 }
Here is the caller graph for this function:

| void PSC_Run | ( | void | ) |
Definition at line 270 of file mc_drv.c.
References PAOC2A, PRESC_DIV_BY_4, and PRUN2.
Referenced by mci_run().
00271 { 00272 PCTL2 = (0<<PAOC2A)|(1<<PRUN2)|PRESC_DIV_BY_4; /* RUN !! */ 00273 }
Here is the caller graph for this function:

| void PSC_Stop | ( | void | ) |
| __interrupt void timer1_periodic_interrupt | ( | void | ) |
Timer 1 interrupt Timer 1 generates a periodic interrupt for motor and main loop.
Definition at line 512 of file mc_drv.c.
References AC0IF, AC1IF, AC2IF, count_sub_tick, delay_30d, delay_armed, delay_mask, Disable_comparator0_interrupt, Disable_comparator1_interrupt, Disable_comparator2_interrupt, Enable_comparator0_interrupt, Enable_comparator1_interrupt, Enable_comparator2_interrupt, FALSE, g_tick, HALL_SENSOR_VALUE, MASK_DEMAG, mc_switch_commutation(), and TRUE.
00513 { 00514 count_sub_tick --; 00515 if (count_sub_tick == 0) 00516 { 00517 g_tick = TRUE; 00518 count_sub_tick = 8; 00519 } 00520 00521 if (delay_armed == TRUE) 00522 { 00523 delay_30d --; 00524 if (delay_30d == 0) 00525 { 00526 delay_armed = FALSE; 00527 delay_mask = MASK_DEMAG; 00528 Disable_comparator0_interrupt(); 00529 Disable_comparator1_interrupt(); 00530 Disable_comparator2_interrupt(); 00531 mc_switch_commutation(HALL_SENSOR_VALUE()); 00532 } 00533 } 00534 if (delay_mask != 0) 00535 { 00536 delay_mask --; 00537 if (delay_mask == 0) 00538 { 00539 ACSR = (1<<AC2IF)|(1<<AC1IF)|(1<<AC0IF); 00540 Enable_comparator0_interrupt(); 00541 Enable_comparator1_interrupt(); 00542 Enable_comparator2_interrupt(); 00543 } 00544 } 00545 }
Here is the call graph for this function:

char ADC_State = FREE [static] |
State of the ADC scheduler.
Definition at line 43 of file mc_drv.c.
Referenced by ADC_EOC(), and mc_ADC_Scheduler().
variable "count" is use for calculate the "average" speed on 'n' samples
Definition at line 27 of file mc_drv.c.
Referenced by mc_estimation_speed().
| volatile S16 comp_delay_30d = MIN_DELAY |
Definition at line 35 of file mc_drv.c.
Referenced by mc_estimation_speed(), mc_hall_a(), mc_hall_b(), and mc_hall_c().
U8 count_sub_tick = 8 [static] |
Definition at line 34 of file mc_drv.c.
Referenced by mc_hall_a(), mc_hall_b(), mc_hall_c(), and timer1_periodic_interrupt().
Bool delay_armed = FALSE [static] |
Definition at line 33 of file mc_drv.c.
Referenced by mc_hall_a(), mc_hall_b(), mc_hall_c(), and timer1_periodic_interrupt().
U8 delay_mask = 0 [static] |
Bool g_mc_read_enable = FALSE [static] |
variable "ovf_timer" is use to simulate a 16 bits timer with 8 bits timer
Definition at line 30 of file mc_drv.c.
Referenced by mc_estimation_speed(), and mc_hall_a().
Use for control the sampling period value.
Definition at line 31 of file mc_drv.c.
Referenced by main(), and timer1_periodic_interrupt().
U8 hall_state = 0 [static] |
Used to count the number of motor revolutions.
Definition at line 40 of file mc_drv.c.
Referenced by mc_hall_a(), mc_hall_b(), and mc_hall_c().
Definition at line 39 of file mc_drv.c.
Referenced by mc_get_Num_Turn(), mc_hall_a(), mc_hall_b(), mc_hall_c(), and mc_reset_Num_Turn().
average of speed
Definition at line 28 of file mc_drv.c.
Referenced by mc_estimation_speed(), and ovfl_timer().
char State = CONV_INIT [static] |
1.4.7