This file contains all defines, typedefs and prototypes related to the motor control.
Definition in file PMSM.h.
#include "stdint.h"
Include dependency graph for PMSM.h:

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

Go to the source code of this file.
Data Structures | |
| struct | PMSMflags |
| Collection of all motor control flags. More... | |
Defines | |
| #define | BLOCK_COMMUTATION_DUTY_MULTIPLIER 3 |
| The number to multiply speed input with to produce duty cycle compare value (0-255). | |
| #define | COMMUTATION_TICKS_STOPPED 6000 |
| #define | COMPARE_REGISTER_PHASE_U OCR1A |
| Output compare register for phase U. | |
| #define | COMPARE_REGISTER_PHASE_V OCR1B |
| Output compare register for phase V. | |
| #define | COMPARE_REGISTER_PHASE_W OCR1D |
| Output compare register for phase W. | |
| #define | CPU_FREQUENCY 16000000UL |
| CPU clock frequency. | |
| #define | DEAD_TIME 10 |
| Dead time (Timer/counter1 clock cycles). | |
| #define | DIRECTION_FORWARD 0 |
| Forward direction flag value. | |
| #define | DIRECTION_PIN PA3 |
| Pin where direction input signal is connected. | |
| #define | DIRECTION_REVERSE 1 |
| Reverse direction flag value. | |
| #define | DIRECTION_UNKNOWN 3 |
| Unknown direction flag value. | |
| #define | FALSE 0 |
| FALSE constant value. | |
| #define | H1_PIN PA0 |
| Pin where hall sensor 1 is connected. | |
| #define | H2_PIN PA1 |
| Pin where hall sensor 2 is connected. | |
| #define | H3_PIN PA2 |
| Pin where hall sensor 3 is connected. | |
| #define | HALL_PULL_UP_ENABLE FALSE |
| Hall sensor pull-up enable. Set to TRUE to enable, FALSE to disable. | |
| #define | PID_K_D 0 |
| #define | PID_K_I 10 |
| #define | PID_K_P 256 |
| #define | PWM1X 7 |
| Bit position of PWM1X flag in TCCR1B register. | |
| #define | PWM_INVERT_OUTPUT 0 |
| Selects inversion of PWM outputs. | |
| #define | PWM_PIN_MASK_PORTB ((1 << UL) | (1 << UH) | (1 << VL) | (1 << VH) | (1 << WL) | (1 << WH)) |
| Mask of all pins used for motor control PWM outputs. | |
| #define | PWM_TOP_VALUE 0x03ff |
| Top value of Timer/Counter1. | |
| #define | SINE_TABLE_LENGTH 192U |
| The number of elements in the sine modulation table per phase. | |
| #define | SINE_TABLE_SIZE SINE_TABLE_SIZE_LARGE |
| #define | SINE_TABLE_SIZE_LARGE 0 |
| SINE_TABLE_SIZE value for large (3 * 192 elements) sine table. | |
| #define | SINE_TABLE_SIZE_SMALL 1 |
| SINE_TABLE_SIZE value for small (64 elements) sine table. | |
| #define | SPEED_CONTROL_CLOSED_LOOP 1 |
| Speed control selection for closed loop control. | |
| #define | SPEED_CONTROL_METHOD SPEED_CONTROL_OPEN_LOOP |
| #define | SPEED_CONTROL_OPEN_LOOP 0 |
| Speed control selection for open loop control. | |
| #define | SPEED_CONTROLLER_MAX_INCREMENT 620 |
| #define | SPEED_CONTROLLER_MAX_INPUT 1024 |
| #define | SPEED_CONTROLLER_TIME_BASE 150 |
| #define | SYNCHRONIZATION_COUNT 2 |
| #define | TABLE_ELEMENTS_PER_COMMUTATION_SECTOR (SINE_TABLE_LENGTH / 6) |
| The number of elements in the sine modulation table for each phase per commutation sector. | |
| #define | TC1_PWM6_SET_DUTY_CYCLE(dutyCycle) TC1_WRITE_10_BIT_REGISTER(OCR1A, (dutyCycle)) |
| Set duty cycle in PWM6 mode. | |
| #define | TRUE (!FALSE) |
| TRUE constant value, defined to be compatible with comparisons. | |
| #define | TURN_MODE TURN_MODE_BRAKE |
| #define | TURN_MODE_BRAKE 1 |
| TURN_MODE value for braking (low side braking). | |
| #define | TURN_MODE_COAST 0 |
| TURN_MODE value for coasting (disabled drivers). | |
| #define | UH PB1 |
| Pin connected to UH. | |
| #define | UH_OCOE OC1OE1 |
| #define | UL PB0 |
| Pin connected to UL. | |
| #define | UL_OCOE OC1OE0 |
| #define | VH PB3 |
| Pin connected to VH. | |
| #define | VH_OCOE OC1OE3 |
| #define | VL PB2 |
| Pin connected to VL. | |
| #define | VL_OCOE OC1OE2 |
| #define | WAVEFORM_BLOCK_COMMUTATION 0 |
| Waveform status flag value for block commutation. | |
| #define | WAVEFORM_BRAKING 2 |
| Waveform status flag value for braking. | |
| #define | WAVEFORM_SINUSOIDAL 1 |
| Waveform status flag value for sinusoidal driving. | |
| #define | WAVEFORM_UNDEFINED 3 |
| Waveform status flag value used in transitions between different types of driving. | |
| #define | WH PB5 |
| Pin connected to WH. | |
| #define | WH_OCOE OC1OE5 |
| #define | WL PB4 |
| Pin connected to WL. | |
| #define | WL_OCOE OC1OE4 |
Typedefs | |
| typedef PMSMflags | PMSMflags_t |
| Collection of all motor control flags. | |
Functions | |
| static void | ActualDirectionUpdate (uint8_t lastHall, const uint8_t newHall) |
| static void | ADCInit (void) |
| static void | AdjustSineTableIndex (const uint16_t increment) |
| static void | BlockCommutate (const uint8_t direction, const uint8_t hall) |
| static void | BlockCommutationSetDuty (const uint16_t compareValue) |
| static void | CommutationTicksUpdate (void) |
| static void | DesiredDirectionUpdate (void) |
| static void | DisablePWMOutputs (void) |
| static void | EnablePWMOutputs (void) |
| static void | ExternalInterruptInit (void) |
| static uint8_t | GetActualDirection (void) |
| static uint8_t | GetDesiredDirection (void) |
| static uint8_t | GetHall (void) |
| static uint8_t | IsMotorSynchronized (void) |
| static void | MotorSynchronizedUpdate (void) |
| static unsigned int | MultiplyUS15x8 (const uint16_t m15, const uint8_t m8) |
| static void | PinChangeInit (void) |
| static void | PLLInit (void) |
| static void | PortsInit (void) |
| static void | PWMInit (void) |
| static void | SetAdvanceCommutation (const uint8_t advanceCommutation) |
| static void | SineOutputUpdate (void) |
| static uint16_t | SineTableIncrementCalculate (const uint16_t ticks) |
| static uint8_t | SineTableSmallGetValue (uint8_t index) |
| static void | SpeedController (uint16_t speedReference) |
| static void | TimerSetModeBlockCommutation (void) |
| static void | TimerSetModeBrake (void) |
| static void | TimerSetModeSinusoidal (void) |
| static void | TimersInit (void) |
| #define BLOCK_COMMUTATION_DUTY_MULTIPLIER 3 |
The number to multiply speed input with to produce duty cycle compare value (0-255).
Definition at line 210 of file PMSM.h.
Referenced by Timer1OverflowISR().
| #define COMMUTATION_TICKS_STOPPED 6000 |
The number of commutation 'ticks' that must pass without any hall changes before the motor is considered to be stopped.
Definition at line 185 of file PMSM.h.
Referenced by CommutationTicksUpdate().
| #define COMPARE_REGISTER_PHASE_U OCR1A |
Output compare register for phase U.
Definition at line 122 of file PMSM.h.
Referenced by SineOutputUpdate().
| #define COMPARE_REGISTER_PHASE_V OCR1B |
Output compare register for phase V.
Definition at line 125 of file PMSM.h.
Referenced by SineOutputUpdate().
| #define COMPARE_REGISTER_PHASE_W OCR1D |
Output compare register for phase W.
Definition at line 128 of file PMSM.h.
Referenced by SineOutputUpdate().
| #define DEAD_TIME 10 |
| #define DIRECTION_FORWARD 0 |
Forward direction flag value.
Definition at line 141 of file PMSM.h.
Referenced by ActualDirectionUpdate(), BlockCommutate(), DesiredDirectionUpdate(), HallChangeISR(), and SineOutputUpdate().
| #define DIRECTION_PIN PA3 |
Pin where direction input signal is connected.
Definition at line 109 of file PMSM.h.
Referenced by DesiredDirectionUpdate().
| #define DIRECTION_REVERSE 1 |
Reverse direction flag value.
Definition at line 144 of file PMSM.h.
Referenced by ActualDirectionUpdate(), and DesiredDirectionUpdate().
| #define DIRECTION_UNKNOWN 3 |
Unknown direction flag value.
Definition at line 147 of file PMSM.h.
Referenced by ActualDirectionUpdate(), main(), and Timer1OverflowISR().
| #define H1_PIN PA0 |
Pin where hall sensor 1 is connected.
Definition at line 95 of file PMSM.h.
Referenced by GetHall(), and PortsInit().
| #define H2_PIN PA1 |
Pin where hall sensor 2 is connected.
Definition at line 98 of file PMSM.h.
Referenced by GetHall(), and PortsInit().
| #define H3_PIN PA2 |
Pin where hall sensor 3 is connected.
Definition at line 101 of file PMSM.h.
Referenced by GetHall(), and PortsInit().
| #define HALL_PULL_UP_ENABLE FALSE |
| #define PID_K_D 0 |
| #define PID_K_I 10 |
| #define PID_K_P 256 |
| #define PWM1X 7 |
| #define PWM_INVERT_OUTPUT 0 |
| #define PWM_PIN_MASK_PORTB ((1 << UL) | (1 << UH) | (1 << VL) | (1 << VH) | (1 << WL) | (1 << WH)) |
Mask of all pins used for motor control PWM outputs.
Definition at line 91 of file PMSM.h.
Referenced by DisablePWMOutputs(), and EnablePWMOutputs().
| #define PWM_TOP_VALUE 0x03ff |
Top value of Timer/Counter1.
Definition at line 177 of file PMSM.h.
Referenced by PWMInit(), SpeedController(), and Timer1OverflowISR().
| #define SINE_TABLE_LENGTH 192U |
The number of elements in the sine modulation table per phase.
This is the number of elements in the sine modulation table used to represent the waveform for one phase. Note that this is not the same as the number of elements in the sineTable stored in flash.
Definition at line 156 of file PMSM.h.
Referenced by AdjustSineTableIndex(), and SineTableIncrementCalculate().
| #define SINE_TABLE_SIZE SINE_TABLE_SIZE_LARGE |
| #define SINE_TABLE_SIZE_LARGE 0 |
| #define SINE_TABLE_SIZE_SMALL 1 |
| #define SPEED_CONTROL_CLOSED_LOOP 1 |
| #define SPEED_CONTROL_METHOD SPEED_CONTROL_OPEN_LOOP |
| #define SPEED_CONTROL_OPEN_LOOP 0 |
| #define SPEED_CONTROLLER_MAX_INCREMENT 620 |
The maximum increment (maximum speed) to use as setpoint when the maximum speed reference value is input.
Definition at line 265 of file PMSM.h.
Referenced by SpeedController().
| #define SPEED_CONTROLLER_MAX_INPUT 1024 |
Max speed reference input. (Rounded up to closest power of 2 in this case, which is recommended to speed up division.
Definition at line 272 of file PMSM.h.
Referenced by SpeedController().
| #define SPEED_CONTROLLER_TIME_BASE 150 |
| #define SYNCHRONIZATION_COUNT 2 |
This constant specifies the number of subsequent detections of correct direction of rotation needed before the firmware is considered synchronized with the motor. (SYNCHRONIZATION_COUNT + 1) hall sensor changes in the same direction are needed.
Definition at line 193 of file PMSM.h.
Referenced by MotorSynchronizedUpdate().
| #define TABLE_ELEMENTS_PER_COMMUTATION_SECTOR (SINE_TABLE_LENGTH / 6) |
The number of elements in the sine modulation table for each phase per commutation sector.
Definition at line 173 of file PMSM.h.
Referenced by HallChangeISR().
| #define TC1_PWM6_SET_DUTY_CYCLE | ( | dutyCycle | ) | TC1_WRITE_10_BIT_REGISTER(OCR1A, (dutyCycle)) |
Set duty cycle in PWM6 mode.
This macro sets the duty cycle in PWM6 mode.
Definition at line 310 of file PMSM.h.
Referenced by BlockCommutationSetDuty().
| #define TRUE (!FALSE) |
| #define TURN_MODE TURN_MODE_BRAKE |
| #define TURN_MODE_BRAKE 1 |
| #define TURN_MODE_COAST 0 |
| #define WAVEFORM_BLOCK_COMMUTATION 0 |
Waveform status flag value for block commutation.
Definition at line 197 of file PMSM.h.
Referenced by CommutationTicksUpdate(), HallChangeISR(), Timer1OverflowISR(), and TimerSetModeBlockCommutation().
| #define WAVEFORM_BRAKING 2 |
Waveform status flag value for braking.
Definition at line 203 of file PMSM.h.
Referenced by TimerSetModeBrake().
| #define WAVEFORM_SINUSOIDAL 1 |
Waveform status flag value for sinusoidal driving.
Definition at line 200 of file PMSM.h.
Referenced by HallChangeISR(), Timer1OverflowISR(), and TimerSetModeSinusoidal().
| #define WAVEFORM_UNDEFINED 3 |
Waveform status flag value used in transitions between different types of driving.
Definition at line 206 of file PMSM.h.
Referenced by main(), and Timer1OverflowISR().
| typedef struct PMSMflags PMSMflags_t |
Collection of all motor control flags.
This struct contains all motor control flags used in this implementation.
| static void ADCInit | ( | void | ) | [static] |
| static void AdjustSineTableIndex | ( | const uint16_t | increment | ) | [static] |
| static void BlockCommutationSetDuty | ( | const uint16_t | compareValue | ) | [static] |
| static void CommutationTicksUpdate | ( | void | ) | [static] |
| static void DesiredDirectionUpdate | ( | void | ) | [static] |
| static void DisablePWMOutputs | ( | void | ) | [static] |
| static void EnablePWMOutputs | ( | void | ) | [static] |
| static void ExternalInterruptInit | ( | void | ) | [static] |
| static uint8_t GetActualDirection | ( | void | ) | [static] |
| static uint8_t GetDesiredDirection | ( | void | ) | [static] |
| static uint8_t GetHall | ( | void | ) | [static] |
| static uint8_t IsMotorSynchronized | ( | void | ) | [static] |
| static void MotorSynchronizedUpdate | ( | void | ) | [static] |
| static void PinChangeInit | ( | void | ) | [static] |
| static void PLLInit | ( | void | ) | [static] |
| static void PortsInit | ( | void | ) | [static] |
| static void PWMInit | ( | void | ) | [static] |
| static void SetAdvanceCommutation | ( | const uint8_t | advanceCommutation | ) | [static] |
| static void SineOutputUpdate | ( | void | ) | [static] |
| static void SpeedController | ( | uint16_t | speedReference | ) | [static] |
| static void TimerSetModeBlockCommutation | ( | void | ) | [static] |
| static void TimerSetModeBrake | ( | void | ) | [static] |
| static void TimerSetModeSinusoidal | ( | void | ) | [static] |
| static void TimersInit | ( | void | ) | [static] |
1.5.2