Definition in file mc_control.c.
#include "mc_control.h"
#include "mc_drv.h"
Go to the source code of this file.
Defines | |
#define | STARTUP_NUM_COMMUTATIONS 29 |
Start sequence number of commutations. | |
Functions | |
void | delay_us (volatile long delay) |
This function generates a delay used during startup. | |
void | mc_regulation_loop () |
This function launches speed control or no regulation. | |
void | mc_set_duty_cycle (U16 duty) |
This function set duty cycle. | |
void | mc_start_motor () |
Executes the motor startup sequence. | |
Variables | |
ADMUXTableForward [6] | |
ADMUXTableReverse [6] | |
commTableForward [6] | |
commTableReverse [6] | |
volatile U8 | nextCommutationStep |
The commutation step that starts at next commutation. | |
volatile U16 | speedReferenceADC |
ADC reading of external analog speed reference. | |
volatile U8 | speedUpdated |
Flag that specifies whether a new external speed reference and a motor speed measurement is available. | |
start_delay [STARTUP_NUM_COMMUTATIONS+1] | |
volatile U8 | zcPolarity |
Polarity of the expected zero crossing. | |
zcTableForward [6] | |
zcTableReverse [6] |
#define STARTUP_NUM_COMMUTATIONS 29 |
Start sequence number of commutations.
Definition at line 114 of file mc_control.c.
Referenced by mc_start_motor().
void delay_us | ( | volatile long | delay | ) |
This function generates a delay used during startup.
Definition at line 126 of file mc_control.c.
Referenced by mc_start_motor().
void mc_regulation_loop | ( | ) |
This function launches speed control or no regulation.
Definition at line 243 of file mc_control.c.
References FALSE, mc_set_duty_cycle(), MIN_PWM_COMPARE_VALUE, speedReferenceADC, and speedUpdated.
Referenced by main().
00244 { 00245 // Only update duty cycle if a new speed reference measurement has been made. (Done right after speed measurement is ready) 00246 if (speedUpdated) 00247 { 00248 speedUpdated = FALSE; 00249 // Calculate duty cycle from speed reference value. 00250 mc_set_duty_cycle(MIN_PWM_COMPARE_VALUE+(speedReferenceADC>>3)); 00251 } 00252 }
void mc_set_duty_cycle | ( | U16 | duty | ) |
This function set duty cycle.
Definition at line 133 of file mc_control.c.
References TC1_WRITE_10_BIT_REGISTER.
Referenced by mc_regulation_loop(), and mc_start_motor().
00134 { 00135 TC1_WRITE_10_BIT_REGISTER(OCR1A, duty); 00136 }
void mc_start_motor | ( | ) |
Executes the motor startup sequence.
This function locks the motor into a known position and fires off a commutation sequence controlled by the Timer/counter1 overflow interrupt.
Definition at line 143 of file mc_control.c.
References ADMUXTableForward, ADMUXTableReverse, commTableForward, commTableReverse, delay_us(), mc_set_duty_cycle(), nextCommutationStep, SET_TIMER1_INT_ZC_DETECTION, start_delay, STARTUP_NUM_COMMUTATIONS, STARTUP_PWM_COMPARE_VALUE, TC0_WRITE_TCNT0, zcPolarity, zcTableForward, and zcTableReverse.
Referenced by main().
00144 { 00145 U8 i = 0; 00146 U8 j = 0; 00147 U8 end_of_start = 0; 00148 mc_set_duty_cycle(STARTUP_PWM_COMPARE_VALUE) ; 00149 00150 nextCommutationStep = 0; 00151 00152 while(end_of_start!=1) 00153 { 00154 switch(nextCommutationStep) 00155 { 00156 case 0: 00157 #if (DIRECTION_OF_ROTATION == CCW) 00158 TCCR1E = commTableReverse[0]; 00159 #else 00160 TCCR1E = commTableForward[0]; 00161 #endif 00162 if (i < 2) i += 1; 00163 if ((i == 2)&&(j<STARTUP_NUM_COMMUTATIONS)) { 00164 j += 1;i=0; 00165 } 00166 if ((i==2)&&(j==STARTUP_NUM_COMMUTATIONS)){ 00167 end_of_start = 1; 00168 } 00169 delay_us(start_delay[j]); 00170 nextCommutationStep = 1; 00171 break; 00172 case 1: 00173 #if (DIRECTION_OF_ROTATION == CCW) 00174 TCCR1E = commTableReverse[1]; 00175 #else 00176 TCCR1E = commTableForward[1]; 00177 #endif 00178 delay_us(start_delay[j]); 00179 nextCommutationStep = 2; 00180 break; 00181 case 2: 00182 #if (DIRECTION_OF_ROTATION == CCW) 00183 TCCR1E = commTableReverse[2]; 00184 #else 00185 TCCR1E = commTableForward[2]; 00186 #endif 00187 delay_us(start_delay[j]); 00188 nextCommutationStep = 3; 00189 break; 00190 case 3: 00191 #if (DIRECTION_OF_ROTATION == CCW) 00192 TCCR1E = commTableReverse[3]; 00193 #else 00194 TCCR1E = commTableForward[3]; 00195 #endif 00196 delay_us(start_delay[j]); 00197 nextCommutationStep = 4; 00198 break; 00199 case 4: 00200 #if (DIRECTION_OF_ROTATION == CCW) 00201 TCCR1E = commTableReverse[4]; 00202 #else 00203 TCCR1E = commTableForward[4]; 00204 #endif 00205 delay_us(start_delay[j]); 00206 nextCommutationStep = 5; 00207 break; 00208 case 5: 00209 #if (DIRECTION_OF_ROTATION == CCW) 00210 TCCR1E = commTableReverse[5]; 00211 #else 00212 TCCR1E = commTableForward[5]; 00213 #endif 00214 delay_us(start_delay[j]); 00215 nextCommutationStep = 0; 00216 break; 00217 default : 00218 nextCommutationStep = nextCommutationStep; 00219 break; 00220 } 00221 } 00222 00223 //nextCommutationStep++; 00224 nextCommutationStep = 0; 00225 // Use LSB of nextCommutationStep to determine zero crossing polarity. 00226 #if (DIRECTION_OF_ROTATION == CCW) 00227 zcPolarity = zcTableReverse[nextCommutationStep]; 00228 ADMUX = ADMUXTableReverse[nextCommutationStep]; 00229 #else 00230 zcPolarity = zcTableForward[nextCommutationStep]; 00231 ADMUX = ADMUXTableForward[nextCommutationStep]; 00232 #endif 00233 // Switch to sensorless commutation. 00234 TC0_WRITE_TCNT0(0); 00235 00236 // Enable Timer 1 Interrupt 00237 SET_TIMER1_INT_ZC_DETECTION; 00238 00239 }
volatile U8 nextCommutationStep |
The commutation step that starts at next commutation.
The commutation step that starts at next commutation. This is used to keep track on where in the commutation cycle we are. Stored in register R11 for quick access
Definition at line 171 of file mc_drv.c.
Referenced by Commutate(), and mc_start_motor().
volatile U16 speedReferenceADC |
ADC reading of external analog speed reference.
Definition at line 174 of file mc_drv.c.
Referenced by ADCInit(), mc_regulation_loop(), and MotorPWMBottom().
volatile U8 speedUpdated |
Flag that specifies whether a new external speed reference and a motor speed measurement is available.
Definition at line 177 of file mc_drv.c.
Referenced by mc_regulation_loop(), and MotorPWMBottom().
start_delay[STARTUP_NUM_COMMUTATIONS+1] |
Initial value:
{2000,1900,1800,1600,1400,1200,1000,800,600,550,500,480,460,440,420,400,380,360,355,350,345,340,335,330,325,320,315,310,305,300}
Definition at line 121 of file mc_control.c.
Referenced by mc_start_motor().
volatile U8 zcPolarity |
Polarity of the expected zero crossing.
The polarity of the expected zero crossing. Could be eiter EDGE_FALLING or EDGE_RISING.
Definition at line 163 of file mc_drv.c.
Referenced by Commutate(), mc_start_motor(), and MotorPWMBottom().