Main Page | File List | Globals

BLDC.h File Reference


Detailed Description

Atmel Corporation

Revision
1.1
Date
Monday, October 10, 2005 11:15:46 UTC

Definition in file BLDC.h.

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define ADC_MUX_CURRENT   0x3
 ADC multiplexer selection for current sampling.
#define ADC_MUX_REF_VOLTAGE   0x5
 ADC multiplexer selection for reference voltage sampling.
#define ADC_MUX_SPEED_REF   0x4
 ADC multiplexer selection for speed reference sampling.
#define ADC_MUX_U   0x0
 ADC multiplexer selection for channel U sampling.
#define ADC_MUX_V   0x1
 ADC multiplexer selection for channel V sampling.
#define ADC_MUX_W   0x2
 ADC multiplexer selection for channel W sampling.
#define ADC_PRESCALER   ADC_PRESCALER_8
 ADC prescaler used.
#define ADC_PRESCALER_16   ((1 << ADPS2) | (0 << ADPS1) | (0 << ADPS0))
 ADC clock prescaled by 8 value.
#define ADC_PRESCALER_8   ((0 << ADPS2) | (1 << ADPS1) | (1 << ADPS0))
 ADC clock prescaled by 8 value.
#define ADC_REF_CHANNEL   ((0 << REFS1) | (0 << REFS0))
 ADC reference channel selection.
#define ADC_RES_ALIGNMENT_BEMF   (1 << ADLAR)
 ADC result alignment for BEMF measurement.
#define ADC_RES_ALIGNMENT_CURRENT   (1 << ADLAR)
 ADC result alignment for CURRENT measurement.
#define ADC_RES_ALIGNMENT_REF_VOLTAGE   (1 << ADLAR)
 ADC result alignment for reference voltage measurement.
#define ADC_RES_ALIGNMENT_SPEED_REF   (1 << ADLAR)
 ADC result alignment for speed reference measurement.
#define ADC_RESOLUTION   256
 The ADC resolution used.
#define ADC_TRIGGER_SOURCE   ((1 << ADTS2) | (0 << ADTS1) | (0 << ADTS0))
 ADC trigger source.
#define ADC_ZC_THRESHOLD   0x98
 Zero-cross threshold.
#define ADMUX_CURRENT   (ADC_REF_CHANNEL | ADC_RES_ALIGNMENT_CURRENT | ADC_MUX_CURRENT)
 ADMUX register value for current sampling.
#define ADMUX_REF_VOLTAGE   (ADC_REF_CHANNEL | ADC_RES_ALIGNMENT_REF_VOLTAGE | ADC_MUX_REF_VOLTAGE)
 ADMUX register value for reference voltage sampling.
#define ADMUX_SPEED_REF   (ADC_REF_CHANNEL | ADC_RES_ALIGNMENT_SPEED_REF | ADC_MUX_SPEED_REF)
 ADMUX register value for speed reference sampling.
#define ADMUX_U   (ADC_REF_CHANNEL | ADC_RES_ALIGNMENT_BEMF | ADC_MUX_U)
 ADMUX register value for channel U sampling.
#define ADMUX_V   (ADC_REF_CHANNEL | ADC_RES_ALIGNMENT_BEMF | ADC_MUX_V)
 ADMUX register value for channel V sampling.
#define ADMUX_W   (ADC_REF_CHANNEL | ADC_RES_ALIGNMENT_BEMF | ADC_MUX_W)
 ADMUX register value for channel W sampling.
#define ANALOG_COMPARATOR_ENABLE
#define CCW   1
 Counterclockwise rotation flag. Used only in macros.
#define CLEAR_ALL_TIMER0_INT_FLAGS   (TIFR0 = TIFR0)
 Macro that clears all Timer/counter0 interrupt flags.
#define CLEAR_ALL_TIMER1_INT_FLAGS   (TIFR1 = TIFR1)
 Macro that clears all Timer/Counter1 interrupt flags.
#define COMMUTATION_CORRECTION   50
#define COMMUTATION_TIMING_IIR_COEFF_A   1
 Input value relative gain in IIR filter.
#define COMMUTATION_TIMING_IIR_COEFF_B   3
 Relative feedback gain in IIR filter.
#define CURRENT_LIMITER_CRITICAL   3000
 The current value in milliAmpere where the motor should be shut down.
#define CURRENT_LIMITER_FACTOR   (1 / 5)
#define CURRENT_LIMITER_START   2500
 The current value in milliAmpere where the current limiter starts to kick in.
#define CW   0
 Clockwise rotation flag. Used only in macros.
#define DIRECTION_OF_ROTATION   CCW
#define DISABLE_ALL_TIMER0_INTS   (TIMSK0 = 0)
 Macro that disables all Timer/Counter0 interrupts.
#define DISABLE_ALL_TIMER1_INTS   (TIMSK1 = 0)
 Macro that disables all Timer/Counter1 interrupts.
#define DISABLE_DRIVING   (DRIVE_PORT = 0x00)
 Macro that cuts all power to the motor.
#define DRIVE_DDR   DDRB
 Data direction register for drive pattern output.
#define DRIVE_PATTERN_STEP1_CCW   ((1 << UL) | (1 << VH))
 Drive pattern for commutation step 1, CCW rotation.
#define DRIVE_PATTERN_STEP1_CW   ((1 << VH) | (1 << WL))
 Drive pattern for commutation step 1, CW rotation.
#define DRIVE_PATTERN_STEP2_CCW   ((1 << UL) | (1 << WH))
 Drive pattern for commutation step 2, CCW rotation.
#define DRIVE_PATTERN_STEP2_CW   ((1 << UH) | (1 << WL))
 Drive pattern for commutation step 2, CW rotation.
#define DRIVE_PATTERN_STEP3_CCW   ((1 << VL) | (1 << WH))
 Drive pattern for commutation step 3, CCW rotation.
#define DRIVE_PATTERN_STEP3_CW   ((1 << UH) | (1 << VL))
 Drive pattern for commutation step 3, CW rotation.
#define DRIVE_PATTERN_STEP4_CCW   ((1 << VL) | (1 << UH))
 Drive pattern for commutation step 4, CCW rotation.
#define DRIVE_PATTERN_STEP4_CW   ((1 << WH) | (1 << VL))
 Drive pattern for commutation step 4, CW rotation.
#define DRIVE_PATTERN_STEP5_CCW   ((1 << WL) | (1 << UH))
 Drive pattern for commutation step 5, CCW rotation.
#define DRIVE_PATTERN_STEP5_CW   ((1 << WH) | (1 << UL))
 Drive pattern for commutation step 5, CW rotation.
#define DRIVE_PATTERN_STEP6_CCW   ((1 << WL) | (1 << VH))
 Drive pattern for commutation step 6, CCW rotation.
#define DRIVE_PATTERN_STEP6_CW   ((1 << VH) | (1 << UL))
 Drive pattern for commutation step 6, CW rotation.
#define DRIVE_PORT   PORTB
 PORT register for drive pattern output.
#define EDGE_FALLING   1
 Zero crossing polarity flag value for falling zero crossing.
#define EDGE_RISING   0
 Zero crossing polarity flag value for rinsing zero crossing.
#define EXTERNAL_REF_VOLTAGE   ((4930UL * 10) / 43)
 External reference voltage in milliVolts.
#define FALSE   0
 Boolean FALSE value.
#define MAX_PWM_COMPARE_VALUE   200
 The maximum allowed PWM compare value.
#define MAX_RESTART_ATTEMPTS   10
 The maximum number of restart attempts without external action when stall is detected.
#define MAX_SPEED   8000UL
 The maximum allowed speed. (Only has effect when closed loop speed control is used).
#define MIN_PWM_COMPARE_VALUE   90
 The minimum allowed PWM compare value.
#define MIN_SPEED   3000UL
 The minimum allowed speed. (Only has effect when closed loop speed control is used).
#define P_REG_K_P   64
 P-regulator proportional gain.
#define P_REG_SCALING   65536
 P-regulator scaling factor. The result is divided by this number.
#define PWM_BASE_FREQUENCY   20000
 PWM base frequency. Used to calculate PWM TOP value.
#define PWM_TOP_VALUE   (SYSTEM_FREQUENCY / PWM_BASE_FREQUENCY / 2)
 PWM TOP value. Automatically calculated to give desired PWM_BASE_FREQUENCY.
#define SET_PWM_COMPARE_VALUE(compareValue)   (OCR0B = compareValue)
 Macro that sets a new duty cycle by changing the PWM compare value.
#define SET_TIMER0_INT_ZC_DETECTION   (TIMSK0 = (1 << TOIE0))
 Macro that enables Timer/Counter0 interrupt where zero crossings are detected.
#define SET_TIMER1_INT_COMMUTATION   (TIMSK1 = (1 << OCIE1A))
 Macro that enable Timer/Counter1 interrupt responsible for commutation.
#define SET_TIMER1_INT_HOLDOFF   (TIMSK1 = (1 << OCIE1B))
 Macro that enables Timer/Counter1 interrupt responsible for enabling ADC sampling after ADC holdoff period.
#define SHUNT_RESISTANCE   220
 Current measurement shunt value in milliOhm.
#define SPEED_CONTROL_OPEN_LOOP
 Uncomment one of the following lines to choose open or closed loop speed control.
#define STARTUP_DELAY_MULTIPLIER   100
 Startup delays are given in milliseconds times STARTUP_DELAY_MULTIPLIER.
#define STARTUP_LOCK_DELAY   10000
#define STARTUP_NUM_COMMUTATIONS   8
#define STARTUP_PWM_COMPARE_VALUE   130
 PWM compare value used during startup.
#define SYSTEM_FREQUENCY   8000000
 System clock frequecy. Used to calculate PWM TOP value.
#define TICKS_PER_MINUTE   (TICKS_PER_SECOND * 60)
 The number of Timer/Counter1 ticks per minute.
#define TICKS_PER_SECOND   1000000UL
#define TRUE   (!FALSE)
 Boolean TRUE expression. Can be used both for test and assignment.
#define UH   PB4
 Port pin connected to phase U, high side enable switch.
#define UL   PB5
 Port pin connected to phase U, low side enable switch.
#define VH   PB2
 Port pin connected to phase V, high side enable switch.
#define VL   PB3
 Port pin connected to phase V, low side enable switch.
#define WH   PB0
 Port pin connected to phase W, high side enable switch.
#define WL   PB1
 Port pin connected to phase W, low side enable switch.
#define ZC_DETECTION_HOLDOFF_TIME_US   (filteredTimeSinceCommutation / 2)
 Holdoff time where zero-cross detection is disabled after commutation.

Functions

static unsigned int CalculateCurrent ()
static unsigned long CalculateSpeed ()
static unsigned long CalculateSpeedSetpoint ()
static unsigned char CurrentControl (void)
static void InitADC (void)
static void InitAnalogComparator (void)
static void InitPorts (void)
static void InitTimers (void)
static void MakeTables (void)
static void PWMControl (void)
static void ResetHandler (void)
static signed int SpeedControl (void)
static void StartMotor (void)
static void StartupDelay (unsigned int delay)
 Generates a delay used during startup.
static void WatchdogTimerEnable (void)


Define Documentation

#define ADC_MUX_CURRENT   0x3
 

ADC multiplexer selection for current sampling.

Definition at line 132 of file BLDC.h.

#define ADC_MUX_REF_VOLTAGE   0x5
 

ADC multiplexer selection for reference voltage sampling.

Definition at line 135 of file BLDC.h.

#define ADC_MUX_SPEED_REF   0x4
 

ADC multiplexer selection for speed reference sampling.

Definition at line 129 of file BLDC.h.

#define ADC_MUX_U   0x0
 

ADC multiplexer selection for channel U sampling.

Definition at line 120 of file BLDC.h.

#define ADC_MUX_V   0x1
 

ADC multiplexer selection for channel V sampling.

Definition at line 123 of file BLDC.h.

#define ADC_MUX_W   0x2
 

ADC multiplexer selection for channel W sampling.

Definition at line 126 of file BLDC.h.

#define ADC_PRESCALER   ADC_PRESCALER_8
 

ADC prescaler used.

Definition at line 177 of file BLDC.h.

Referenced by MotorPWMBottom().

#define ADC_PRESCALER_16   ((1 << ADPS2) | (0 << ADPS1) | (0 << ADPS0))
 

ADC clock prescaled by 8 value.

Definition at line 174 of file BLDC.h.

Referenced by InitADC().

#define ADC_PRESCALER_8   ((0 << ADPS2) | (1 << ADPS1) | (1 << ADPS0))
 

ADC clock prescaled by 8 value.

Definition at line 171 of file BLDC.h.

Referenced by InitADC().

#define ADC_REF_CHANNEL   ((0 << REFS1) | (0 << REFS0))
 

ADC reference channel selection.

Definition at line 138 of file BLDC.h.

#define ADC_RES_ALIGNMENT_BEMF   (1 << ADLAR)
 

ADC result alignment for BEMF measurement.

Definition at line 141 of file BLDC.h.

#define ADC_RES_ALIGNMENT_CURRENT   (1 << ADLAR)
 

ADC result alignment for CURRENT measurement.

Definition at line 147 of file BLDC.h.

#define ADC_RES_ALIGNMENT_REF_VOLTAGE   (1 << ADLAR)
 

ADC result alignment for reference voltage measurement.

Definition at line 150 of file BLDC.h.

#define ADC_RES_ALIGNMENT_SPEED_REF   (1 << ADLAR)
 

ADC result alignment for speed reference measurement.

Definition at line 144 of file BLDC.h.

#define ADC_RESOLUTION   256
 

The ADC resolution used.

Definition at line 234 of file BLDC.h.

Referenced by CalculateSpeedSetpoint(), and PWMControl().

#define ADC_TRIGGER_SOURCE   ((1 << ADTS2) | (0 << ADTS1) | (0 << ADTS0))
 

ADC trigger source.

Definition at line 180 of file BLDC.h.

Referenced by InitADC().

#define ADC_ZC_THRESHOLD   0x98
 

Zero-cross threshold.

Definition at line 290 of file BLDC.h.

Referenced by MotorPWMBottom().

#define ADMUX_CURRENT   (ADC_REF_CHANNEL | ADC_RES_ALIGNMENT_CURRENT | ADC_MUX_CURRENT)
 

ADMUX register value for current sampling.

Definition at line 165 of file BLDC.h.

Referenced by MotorPWMBottom().

#define ADMUX_REF_VOLTAGE   (ADC_REF_CHANNEL | ADC_RES_ALIGNMENT_REF_VOLTAGE | ADC_MUX_REF_VOLTAGE)
 

ADMUX register value for reference voltage sampling.

Definition at line 168 of file BLDC.h.

Referenced by InitADC(), and MotorPWMBottom().

#define ADMUX_SPEED_REF   (ADC_REF_CHANNEL | ADC_RES_ALIGNMENT_SPEED_REF | ADC_MUX_SPEED_REF)
 

ADMUX register value for speed reference sampling.

Definition at line 162 of file BLDC.h.

Referenced by MotorPWMBottom().

#define ADMUX_U   (ADC_REF_CHANNEL | ADC_RES_ALIGNMENT_BEMF | ADC_MUX_U)
 

ADMUX register value for channel U sampling.

Definition at line 153 of file BLDC.h.

Referenced by MakeTables().

#define ADMUX_V   (ADC_REF_CHANNEL | ADC_RES_ALIGNMENT_BEMF | ADC_MUX_V)
 

ADMUX register value for channel V sampling.

Definition at line 156 of file BLDC.h.

Referenced by MakeTables().

#define ADMUX_W   (ADC_REF_CHANNEL | ADC_RES_ALIGNMENT_BEMF | ADC_MUX_W)
 

ADMUX register value for channel W sampling.

Definition at line 159 of file BLDC.h.

Referenced by MakeTables().

#define ANALOG_COMPARATOR_ENABLE
 

Uncomment the following line if the analog comparator should be used to detect overcurrent.

Definition at line 275 of file BLDC.h.

#define CCW   1
 

Counterclockwise rotation flag. Used only in macros.

Definition at line 63 of file BLDC.h.

#define CLEAR_ALL_TIMER0_INT_FLAGS   (TIFR0 = TIFR0)
 

Macro that clears all Timer/counter0 interrupt flags.

Definition at line 207 of file BLDC.h.

Referenced by CurrentMeasurementComplete(), and EnableZCDetection().

#define CLEAR_ALL_TIMER1_INT_FLAGS   (TIFR1 = TIFR1)
 

Macro that clears all Timer/Counter1 interrupt flags.

Definition at line 216 of file BLDC.h.

Referenced by Commutate(), EnableZCDetection(), MotorPWMBottom(), and StartupDelay().

#define COMMUTATION_CORRECTION   50
 

The number of milliseconds to subtract from the zero-crossing to commutation time. Used to compensate for zero-cross sample frequency.

Definition at line 296 of file BLDC.h.

Referenced by MotorPWMBottom().

#define COMMUTATION_TIMING_IIR_COEFF_A   1
 

Input value relative gain in IIR filter.

This value specifies the relative gain given to the input value in the IIR filter. The value should be an integer. Make sure that COEFF_A + COEFF_B is a power of 2, to avoid instability.

Definition at line 251 of file BLDC.h.

Referenced by MotorPWMBottom().

#define COMMUTATION_TIMING_IIR_COEFF_B   3
 

Relative feedback gain in IIR filter.

This value specifies the relative feedback gain given to the input value in the IIR filter. The value should be an integer. Make sure that COEFF_A + COEFF_B is a power of 2, to avoid instability.

Definition at line 259 of file BLDC.h.

Referenced by MotorPWMBottom().

#define CURRENT_LIMITER_CRITICAL   3000
 

The current value in milliAmpere where the motor should be shut down.

Definition at line 269 of file BLDC.h.

Referenced by CurrentControl().

#define CURRENT_LIMITER_FACTOR   (1 / 5)
 

The maximum duty cycles is decreased by this number of PWM duty cycle steps per milliAmpere current consumption over CURRENT_LIMITER_START.

Definition at line 281 of file BLDC.h.

Referenced by CurrentControl().

#define CURRENT_LIMITER_START   2500
 

The current value in milliAmpere where the current limiter starts to kick in.

Definition at line 266 of file BLDC.h.

Referenced by CurrentControl().

#define CW   0
 

Clockwise rotation flag. Used only in macros.

Definition at line 60 of file BLDC.h.

#define DIRECTION_OF_ROTATION   CCW
 

Direction of rotation. Set to either CW or CCW for clockwise and counterclockwise respectively.

Definition at line 68 of file BLDC.h.

#define DISABLE_ALL_TIMER0_INTS   (TIMSK0 = 0)
 

Macro that disables all Timer/Counter0 interrupts.

Definition at line 210 of file BLDC.h.

Referenced by MotorPWMBottom().

#define DISABLE_ALL_TIMER1_INTS   (TIMSK1 = 0)
 

Macro that disables all Timer/Counter1 interrupts.

Definition at line 219 of file BLDC.h.

Referenced by EnableZCDetection().

#define DISABLE_DRIVING   (DRIVE_PORT = 0x00)
 

Macro that cuts all power to the motor.

Definition at line 284 of file BLDC.h.

Referenced by OverCurrentISR(), and WatchdogISR().

#define DRIVE_DDR   DDRB
 

Data direction register for drive pattern output.

Definition at line 117 of file BLDC.h.

Referenced by InitPorts().

#define DRIVE_PATTERN_STEP1_CCW   ((1 << UL) | (1 << VH))
 

Drive pattern for commutation step 1, CCW rotation.

Definition at line 71 of file BLDC.h.

Referenced by MakeTables().

#define DRIVE_PATTERN_STEP1_CW   ((1 << VH) | (1 << WL))
 

Drive pattern for commutation step 1, CW rotation.

Definition at line 90 of file BLDC.h.

Referenced by MakeTables().

#define DRIVE_PATTERN_STEP2_CCW   ((1 << UL) | (1 << WH))
 

Drive pattern for commutation step 2, CCW rotation.

Definition at line 74 of file BLDC.h.

Referenced by MakeTables().

#define DRIVE_PATTERN_STEP2_CW   ((1 << UH) | (1 << WL))
 

Drive pattern for commutation step 2, CW rotation.

Definition at line 93 of file BLDC.h.

Referenced by MakeTables().

#define DRIVE_PATTERN_STEP3_CCW   ((1 << VL) | (1 << WH))
 

Drive pattern for commutation step 3, CCW rotation.

Definition at line 77 of file BLDC.h.

Referenced by MakeTables().

#define DRIVE_PATTERN_STEP3_CW   ((1 << UH) | (1 << VL))
 

Drive pattern for commutation step 3, CW rotation.

Definition at line 96 of file BLDC.h.

Referenced by MakeTables().

#define DRIVE_PATTERN_STEP4_CCW   ((1 << VL) | (1 << UH))
 

Drive pattern for commutation step 4, CCW rotation.

Definition at line 80 of file BLDC.h.

Referenced by MakeTables().

#define DRIVE_PATTERN_STEP4_CW   ((1 << WH) | (1 << VL))
 

Drive pattern for commutation step 4, CW rotation.

Definition at line 99 of file BLDC.h.

Referenced by MakeTables().

#define DRIVE_PATTERN_STEP5_CCW   ((1 << WL) | (1 << UH))
 

Drive pattern for commutation step 5, CCW rotation.

Definition at line 83 of file BLDC.h.

Referenced by MakeTables().

#define DRIVE_PATTERN_STEP5_CW   ((1 << WH) | (1 << UL))
 

Drive pattern for commutation step 5, CW rotation.

Definition at line 102 of file BLDC.h.

Referenced by MakeTables().

#define DRIVE_PATTERN_STEP6_CCW   ((1 << WL) | (1 << VH))
 

Drive pattern for commutation step 6, CCW rotation.

Definition at line 86 of file BLDC.h.

Referenced by MakeTables().

#define DRIVE_PATTERN_STEP6_CW   ((1 << VH) | (1 << UL))
 

Drive pattern for commutation step 6, CW rotation.

Definition at line 105 of file BLDC.h.

Referenced by MakeTables().

#define DRIVE_PORT   PORTB
 

PORT register for drive pattern output.

Definition at line 114 of file BLDC.h.

Referenced by Commutate(), CurrentControl(), and StartMotor().

#define EDGE_FALLING   1
 

Zero crossing polarity flag value for falling zero crossing.

Definition at line 108 of file BLDC.h.

Referenced by MotorPWMBottom().

#define EDGE_RISING   0
 

Zero crossing polarity flag value for rinsing zero crossing.

Definition at line 111 of file BLDC.h.

Referenced by MotorPWMBottom().

#define EXTERNAL_REF_VOLTAGE   ((4930UL * 10) / 43)
 

External reference voltage in milliVolts.

Definition at line 228 of file BLDC.h.

Referenced by CalculateCurrent().

#define FALSE   0
 

Boolean FALSE value.

Definition at line 36 of file BLDC.h.

#define MAX_PWM_COMPARE_VALUE   200
 

The maximum allowed PWM compare value.

Definition at line 302 of file BLDC.h.

Referenced by PWMControl().

#define MAX_RESTART_ATTEMPTS   10
 

The maximum number of restart attempts without external action when stall is detected.

Definition at line 198 of file BLDC.h.

Referenced by ResetHandler().

#define MAX_SPEED   8000UL
 

The maximum allowed speed. (Only has effect when closed loop speed control is used).

Definition at line 308 of file BLDC.h.

Referenced by CalculateSpeedSetpoint().

#define MIN_PWM_COMPARE_VALUE   90
 

The minimum allowed PWM compare value.

Definition at line 299 of file BLDC.h.

Referenced by PWMControl().

#define MIN_SPEED   3000UL
 

The minimum allowed speed. (Only has effect when closed loop speed control is used).

Definition at line 305 of file BLDC.h.

Referenced by CalculateSpeedSetpoint().

#define P_REG_K_P   64
 

P-regulator proportional gain.

Definition at line 311 of file BLDC.h.

Referenced by SpeedControl().

#define P_REG_SCALING   65536
 

P-regulator scaling factor. The result is divided by this number.

Definition at line 314 of file BLDC.h.

Referenced by SpeedControl().

#define PWM_BASE_FREQUENCY   20000
 

PWM base frequency. Used to calculate PWM TOP value.

Definition at line 30 of file BLDC.h.

#define PWM_TOP_VALUE   (SYSTEM_FREQUENCY / PWM_BASE_FREQUENCY / 2)
 

PWM TOP value. Automatically calculated to give desired PWM_BASE_FREQUENCY.

Definition at line 33 of file BLDC.h.

Referenced by InitTimers().

#define SET_PWM_COMPARE_VALUE compareValue   )     (OCR0B = compareValue)
 

Macro that sets a new duty cycle by changing the PWM compare value.

Definition at line 204 of file BLDC.h.

Referenced by PWMControl(), and StartMotor().

#define SET_TIMER0_INT_ZC_DETECTION   (TIMSK0 = (1 << TOIE0))
 

Macro that enables Timer/Counter0 interrupt where zero crossings are detected.

Definition at line 213 of file BLDC.h.

Referenced by EnableZCDetection().

#define SET_TIMER1_INT_COMMUTATION   (TIMSK1 = (1 << OCIE1A))
 

Macro that enable Timer/Counter1 interrupt responsible for commutation.

Definition at line 222 of file BLDC.h.

Referenced by MotorPWMBottom().

#define SET_TIMER1_INT_HOLDOFF   (TIMSK1 = (1 << OCIE1B))
 

Macro that enables Timer/Counter1 interrupt responsible for enabling ADC sampling after ADC holdoff period.

Definition at line 225 of file BLDC.h.

Referenced by Commutate().

#define SHUNT_RESISTANCE   220
 

Current measurement shunt value in milliOhm.

Definition at line 231 of file BLDC.h.

Referenced by CalculateCurrent().

#define SPEED_CONTROL_OPEN_LOOP
 

Uncomment one of the following lines to choose open or closed loop speed control.

Definition at line 262 of file BLDC.h.

#define STARTUP_DELAY_MULTIPLIER   100
 

Startup delays are given in milliseconds times STARTUP_DELAY_MULTIPLIER.

Definition at line 189 of file BLDC.h.

Referenced by StartMotor(), and StartupDelay().

#define STARTUP_LOCK_DELAY   10000
 

Number of milliseconds to lock rotor in first commutation step before the timed startup sequence is initiated.

Definition at line 195 of file BLDC.h.

Referenced by StartMotor().

#define STARTUP_NUM_COMMUTATIONS   8
 

Number of commutations performed during startup. Also specifies size of startupDelays. Do not change without also changing MakeTables().

Definition at line 186 of file BLDC.h.

Referenced by StartMotor().

#define STARTUP_PWM_COMPARE_VALUE   130
 

PWM compare value used during startup.

Definition at line 287 of file BLDC.h.

Referenced by StartMotor().

#define SYSTEM_FREQUENCY   8000000
 

System clock frequecy. Used to calculate PWM TOP value.

Definition at line 27 of file BLDC.h.

#define TICKS_PER_MINUTE   (TICKS_PER_SECOND * 60)
 

The number of Timer/Counter1 ticks per minute.

Definition at line 243 of file BLDC.h.

Referenced by CalculateSpeed().

#define TICKS_PER_SECOND   1000000UL
 

The number of Timer/Counter1 ticks per second. Equals MCU clock frequency / Timer/counter1 prescaler.

Definition at line 240 of file BLDC.h.

#define TRUE   (!FALSE)
 

Boolean TRUE expression. Can be used both for test and assignment.

Definition at line 39 of file BLDC.h.

Referenced by CurrentMeasurementComplete(), and MotorPWMBottom().

#define UH   PB4
 

Port pin connected to phase U, high side enable switch.

Definition at line 45 of file BLDC.h.

Referenced by InitPorts().

#define UL   PB5
 

Port pin connected to phase U, low side enable switch.

Definition at line 42 of file BLDC.h.

Referenced by CalculateCurrent(), and InitPorts().

#define VH   PB2
 

Port pin connected to phase V, high side enable switch.

Definition at line 51 of file BLDC.h.

Referenced by InitPorts().

#define VL   PB3
 

Port pin connected to phase V, low side enable switch.

Definition at line 48 of file BLDC.h.

Referenced by InitPorts().

#define WH   PB0
 

Port pin connected to phase W, high side enable switch.

Definition at line 57 of file BLDC.h.

Referenced by InitPorts().

#define WL   PB1
 

Port pin connected to phase W, low side enable switch.

Definition at line 54 of file BLDC.h.

Referenced by InitPorts().

#define ZC_DETECTION_HOLDOFF_TIME_US   (filteredTimeSinceCommutation / 2)
 

Holdoff time where zero-cross detection is disabled after commutation.

Definition at line 201 of file BLDC.h.

Referenced by Commutate().


Function Documentation

static unsigned int CalculateCurrent  )  [static]
 

Referenced by CurrentControl().

static unsigned long CalculateSpeed  )  [static]
 

Referenced by SpeedControl().

static unsigned long CalculateSpeedSetpoint  )  [static]
 

Referenced by SpeedControl().

static unsigned char CurrentControl void   )  [static]
 

static void InitADC void   )  [static]
 

Referenced by main().

static void InitAnalogComparator void   )  [static]
 

Referenced by main().

static void InitPorts void   )  [static]
 

Referenced by main().

static void InitTimers void   )  [static]
 

Referenced by main().

static void MakeTables void   )  [static]
 

Referenced by main().

static void PWMControl void   )  [static]
 

Referenced by main().

static void ResetHandler void   )  [static]
 

Referenced by main().

static signed int SpeedControl void   )  [static]
 

static void StartMotor void   )  [static]
 

Referenced by main().

static void StartupDelay unsigned int  delay  )  [static]
 

Generates a delay used during startup.

This functions is used to generate a delay during the startup procedure. The length of the delay equals delay * STARTUP_DELAY_MULTIPLIER microseconds. Since Timer/Counter1 is used in this function, it must never be called when sensorless operation is running.

Definition at line 593 of file main.c.

References CLEAR_ALL_TIMER1_INT_FLAGS, and STARTUP_DELAY_MULTIPLIER.

Referenced by StartMotor().

00594 {
00595   CLEAR_ALL_TIMER1_INT_FLAGS;
00596   do
00597   {
00598     TCNT1 = 0xffff - STARTUP_DELAY_MULTIPLIER;
00599     // Wait for timer to overflow.
00600     while (!(TIFR1 & (1 << TOV1)))
00601     {
00602 
00603     }
00604 
00605     CLEAR_ALL_TIMER1_INT_FLAGS;
00606     delay--;
00607   } while (delay);
00608 }

static void WatchdogTimerEnable void   )  [static]
 

Referenced by main().


Generated on Tue Oct 11 10:57:03 2005 for Sensorless control of 3-phase brushless DC motors by  doxygen 1.4.4