Main Page | File List | Globals

motor.h

Go to the documentation of this file.
00001 // This file has been prepared for Doxygen automatic documentation generation.
00023 #ifndef __MOTOR_H__
00024 #define __MOTOR_H__
00025 
00031 #define SYS_FREQ              9600000UL
00032 
00038 #define MILLISEC_NUM_CYCLES   (SYS_FREQ / 1000U)
00039 
00046 #define ROTOR_STABILIZATION_TIME_MS       1800U
00047 
00049 #define ROTOR_LOCK_RAMPUP_DELAY_MS        5U
00050 
00052 #define ROTOR_LOCK_RAMPDOWN_DELAY_MS      1U
00053 
00054 
00061 #define TICK_NUM_CYCLES       (510UL)
00062 
00067 #define COMMUTATIONS_PER_REV  4UL
00068 
00074 #define MIN_OCR_VALUE         0x01
00075 
00082 #define MAX_OCR_VALUE         0xff
00083 
00088 #define MAX_RPM               2800UL
00089 
00097 #define MIN_RPM               550UL
00098 
00105 #define CRITICALLY_LOW_RPM    500UL
00106 
00116 #define RPM2COMM_TICKS(RPM)   (unsigned int)(SYS_FREQ / ((RPM * TICK_NUM_CYCLES * COMMUTATIONS_PER_REV) / 60))
00117 
00118 
00120 #define MAX_RPM_TICKS             (RPM2COMM_TICKS(MAX_RPM))
00121 
00123 #define MIN_RPM_TICKS             (RPM2COMM_TICKS(MIN_RPM))
00124 
00126 #define CRITICALLY_LOW_RPM_TICKS  (RPM2COMM_TICKS(CRITICALLY_LOW_RPM))
00127 
00134 #define WINDING1_PIN             PB0
00135 
00142 #define WINDING2_PIN             PB1
00143 
00151 #define PWM_PHASE1            ((1 << COM0A1) | (0 << COM0A0) | (0 << COM0B1) | (0 << COM0B0) | (0<<WGM01) | (1<<WGM00))
00152 
00160 #define PWM_PHASE2            ((0 << COM0A1) | (0 << COM0A0) | (1 << COM0B1) | (0 << COM0B0) | (0<<WGM01) | (1<<WGM00))
00161 
00167 #define PWM_OFF               ((0 << COM0A1) | (0 << COM0A0) | (0 << COM0B1) | (0 << COM0B0) | (0<<WGM01) | (1<<WGM00))
00168 
00174 #define ADC_PHASE1            ((1 << REFS0) | (1 << ADLAR) | (1 << MUX1) | (0 << MUX0))
00175 
00181 #define ADC_PHASE2            ((1 << REFS0) | (1 << ADLAR) | (1 << MUX1) | (1 << MUX0))
00182 
00188 #define ADC_SPEED_REF         ((1 << REFS0) | (1 << ADLAR) | (0 << MUX1) | (1 << MUX0))
00189 
00191 #define ADC_PRESCALER         ((0 << ADPS2) | (1 << ADPS1) | (1 << ADPS0))
00192 
00194 #define PHASE1                0
00195 
00197 #define PHASE2                1
00198 
00204 #define ADC_WAIT_TICKS        50
00205 
00212 #define ADC_THRESHOLD          0x78
00213 
00219 //#define TACHO_ENABLED
00220 
00221 #ifdef TACHO_ENABLED
00222 
00228 #define TACHO_OUT_PIN         PB5
00229 #endif
00230 
00237 #define SET_DUTY_PHASE1(duty)         (OCR0A = (duty))
00238 
00245 #define SET_DUTY_PHASE2(duty)         (OCR0B = (duty))
00246 
00253 #define SET_DUTY_BOTH_PHASES(duty)    (OCR0A = OCR0B = (duty))
00254 
00255 
00256 // Prototypes
00257 static void CheckResetSource(void);
00258 static void InitPORTB(void);
00259 static void InitPWM(void);
00260 static void InitUART(void);
00261 static void InitADC(void);
00262 static void WDTOff(void);
00263 static void InitWDT(void);
00264 static void WaitMillisecs(unsigned int milliSeconds);
00265 static void StartMotor(void);
00266 static unsigned char CalculateDutyCycle(unsigned char duty);
00267 
00268 
00269 #endif

Generated on Thu Sep 29 15:48:28 2005 for AVR440 - Sensorless Control of Two-Phase Brushless DC Motor by  doxygen 1.4.4