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) |
|
ADC multiplexer selection for current sampling.
|
|
ADC multiplexer selection for reference voltage sampling.
|
|
ADC multiplexer selection for speed reference sampling.
|
|
ADC multiplexer selection for channel U sampling.
|
|
ADC multiplexer selection for channel V sampling.
|
|
ADC multiplexer selection for channel W sampling.
|
|
ADC prescaler used.
Definition at line 177 of file BLDC.h. Referenced by MotorPWMBottom(). |
|
ADC clock prescaled by 8 value.
Definition at line 174 of file BLDC.h. Referenced by InitADC(). |
|
ADC clock prescaled by 8 value.
Definition at line 171 of file BLDC.h. Referenced by InitADC(). |
|
ADC reference channel selection.
|
|
ADC result alignment for BEMF measurement.
|
|
ADC result alignment for CURRENT measurement.
|
|
ADC result alignment for reference voltage measurement.
|
|
ADC result alignment for speed reference measurement.
|
|
The ADC resolution used.
Definition at line 234 of file BLDC.h. Referenced by CalculateSpeedSetpoint(), and PWMControl(). |
|
ADC trigger source.
Definition at line 180 of file BLDC.h. Referenced by InitADC(). |
|
Zero-cross threshold.
Definition at line 290 of file BLDC.h. Referenced by MotorPWMBottom(). |
|
ADMUX register value for current sampling.
Definition at line 165 of file BLDC.h. Referenced by MotorPWMBottom(). |
|
ADMUX register value for reference voltage sampling.
Definition at line 168 of file BLDC.h. Referenced by InitADC(), and MotorPWMBottom(). |
|
ADMUX register value for speed reference sampling.
Definition at line 162 of file BLDC.h. Referenced by MotorPWMBottom(). |
|
ADMUX register value for channel U sampling.
Definition at line 153 of file BLDC.h. Referenced by MakeTables(). |
|
ADMUX register value for channel V sampling.
Definition at line 156 of file BLDC.h. Referenced by MakeTables(). |
|
ADMUX register value for channel W sampling.
Definition at line 159 of file BLDC.h. Referenced by MakeTables(). |
|
Uncomment the following line if the analog comparator should be used to detect overcurrent. |
|
Counterclockwise rotation flag. Used only in macros.
|
|
Macro that clears all Timer/counter0 interrupt flags.
Definition at line 207 of file BLDC.h. Referenced by CurrentMeasurementComplete(), and EnableZCDetection(). |
|
Macro that clears all Timer/Counter1 interrupt flags.
Definition at line 216 of file BLDC.h. Referenced by Commutate(), EnableZCDetection(), MotorPWMBottom(), and StartupDelay(). |
|
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(). |
|
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(). |
|
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(). |
|
The current value in milliAmpere where the motor should be shut down.
Definition at line 269 of file BLDC.h. Referenced by CurrentControl(). |
|
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(). |
|
The current value in milliAmpere where the current limiter starts to kick in.
Definition at line 266 of file BLDC.h. Referenced by CurrentControl(). |
|
Clockwise rotation flag. Used only in macros.
|
|
Direction of rotation. Set to either CW or CCW for clockwise and counterclockwise respectively. |
|
Macro that disables all Timer/Counter0 interrupts.
Definition at line 210 of file BLDC.h. Referenced by MotorPWMBottom(). |
|
Macro that disables all Timer/Counter1 interrupts.
Definition at line 219 of file BLDC.h. Referenced by EnableZCDetection(). |
|
Macro that cuts all power to the motor.
Definition at line 284 of file BLDC.h. Referenced by OverCurrentISR(), and WatchdogISR(). |
|
Data direction register for drive pattern output.
Definition at line 117 of file BLDC.h. Referenced by InitPorts(). |
|
Drive pattern for commutation step 1, CCW rotation.
Definition at line 71 of file BLDC.h. Referenced by MakeTables(). |
|
Drive pattern for commutation step 1, CW rotation.
Definition at line 90 of file BLDC.h. Referenced by MakeTables(). |
|
Drive pattern for commutation step 2, CCW rotation.
Definition at line 74 of file BLDC.h. Referenced by MakeTables(). |
|
Drive pattern for commutation step 2, CW rotation.
Definition at line 93 of file BLDC.h. Referenced by MakeTables(). |
|
Drive pattern for commutation step 3, CCW rotation.
Definition at line 77 of file BLDC.h. Referenced by MakeTables(). |
|
Drive pattern for commutation step 3, CW rotation.
Definition at line 96 of file BLDC.h. Referenced by MakeTables(). |
|
Drive pattern for commutation step 4, CCW rotation.
Definition at line 80 of file BLDC.h. Referenced by MakeTables(). |
|
Drive pattern for commutation step 4, CW rotation.
Definition at line 99 of file BLDC.h. Referenced by MakeTables(). |
|
Drive pattern for commutation step 5, CCW rotation.
Definition at line 83 of file BLDC.h. Referenced by MakeTables(). |
|
Drive pattern for commutation step 5, CW rotation.
Definition at line 102 of file BLDC.h. Referenced by MakeTables(). |
|
Drive pattern for commutation step 6, CCW rotation.
Definition at line 86 of file BLDC.h. Referenced by MakeTables(). |
|
Drive pattern for commutation step 6, CW rotation.
Definition at line 105 of file BLDC.h. Referenced by MakeTables(). |
|
PORT register for drive pattern output.
Definition at line 114 of file BLDC.h. Referenced by Commutate(), CurrentControl(), and StartMotor(). |
|
Zero crossing polarity flag value for falling zero crossing.
Definition at line 108 of file BLDC.h. Referenced by MotorPWMBottom(). |
|
Zero crossing polarity flag value for rinsing zero crossing.
Definition at line 111 of file BLDC.h. Referenced by MotorPWMBottom(). |
|
External reference voltage in milliVolts.
Definition at line 228 of file BLDC.h. Referenced by CalculateCurrent(). |
|
Boolean FALSE value.
|
|
The maximum allowed PWM compare value.
Definition at line 302 of file BLDC.h. Referenced by PWMControl(). |
|
The maximum number of restart attempts without external action when stall is detected.
Definition at line 198 of file BLDC.h. Referenced by ResetHandler(). |
|
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(). |
|
The minimum allowed PWM compare value.
Definition at line 299 of file BLDC.h. Referenced by PWMControl(). |
|
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(). |
|
P-regulator proportional gain.
Definition at line 311 of file BLDC.h. Referenced by SpeedControl(). |
|
P-regulator scaling factor. The result is divided by this number.
Definition at line 314 of file BLDC.h. Referenced by SpeedControl(). |
|
PWM base frequency. Used to calculate PWM TOP value.
|
|
PWM TOP value. Automatically calculated to give desired PWM_BASE_FREQUENCY.
Definition at line 33 of file BLDC.h. Referenced by InitTimers(). |
|
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(). |
|
Macro that enables Timer/Counter0 interrupt where zero crossings are detected.
Definition at line 213 of file BLDC.h. Referenced by EnableZCDetection(). |
|
Macro that enable Timer/Counter1 interrupt responsible for commutation.
Definition at line 222 of file BLDC.h. Referenced by MotorPWMBottom(). |
|
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(). |
|
Current measurement shunt value in milliOhm.
Definition at line 231 of file BLDC.h. Referenced by CalculateCurrent(). |
|
Uncomment one of the following lines to choose open or closed loop speed control.
|
|
Startup delays are given in milliseconds times STARTUP_DELAY_MULTIPLIER.
Definition at line 189 of file BLDC.h. Referenced by StartMotor(), and StartupDelay(). |
|
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(). |
|
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(). |
|
PWM compare value used during startup.
Definition at line 287 of file BLDC.h. Referenced by StartMotor(). |
|
System clock frequecy. Used to calculate PWM TOP value.
|
|
The number of Timer/Counter1 ticks per minute.
Definition at line 243 of file BLDC.h. Referenced by CalculateSpeed(). |
|
The number of Timer/Counter1 ticks per second. Equals MCU clock frequency / Timer/counter1 prescaler. |
|
Boolean TRUE expression. Can be used both for test and assignment.
Definition at line 39 of file BLDC.h. Referenced by CurrentMeasurementComplete(), and MotorPWMBottom(). |
|
Port pin connected to phase U, high side enable switch.
Definition at line 45 of file BLDC.h. Referenced by InitPorts(). |
|
Port pin connected to phase U, low side enable switch.
Definition at line 42 of file BLDC.h. Referenced by CalculateCurrent(), and InitPorts(). |
|
Port pin connected to phase V, high side enable switch.
Definition at line 51 of file BLDC.h. Referenced by InitPorts(). |
|
Port pin connected to phase V, low side enable switch.
Definition at line 48 of file BLDC.h. Referenced by InitPorts(). |
|
Port pin connected to phase W, high side enable switch.
Definition at line 57 of file BLDC.h. Referenced by InitPorts(). |
|
Port pin connected to phase W, low side enable switch.
Definition at line 54 of file BLDC.h. Referenced by InitPorts(). |
|
Holdoff time where zero-cross detection is disabled after commutation.
Definition at line 201 of file BLDC.h. Referenced by Commutate(). |
|
Referenced by CurrentControl(). |
|
Referenced by SpeedControl(). |
|
Referenced by SpeedControl(). |
|
|
|
Referenced by main(). |
|
Referenced by main(). |
|
Referenced by main(). |
|
Referenced by main(). |
|
Referenced by main(). |
|
Referenced by main(). |
|
Referenced by main(). |
|
|
|
Referenced by main(). |
|
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 }
|
|
Referenced by main(). |