PMSM.h File Reference


Detailed Description

Motor control header file.

This file contains all defines, typedefs and prototypes related to the motor control.

Application note:
AVR447: Sinusoidal driving of three-phase permanent motor using ATtiny261/461/861.
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
$Name$
Revision
2571
$RCSfile$
Date
2007-10-08 15:53:50 +0200 (ma, 08 okt 2007)

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 Documentation

#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.

Todo:
Adjust the motor stopped limit.

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 CPU_FREQUENCY   16000000UL

CPU clock frequency.

Definition at line 56 of file PMSM.h.

#define DEAD_TIME   10

Dead time (Timer/counter1 clock cycles).

Definition at line 59 of file PMSM.h.

Referenced by PWMInit().

#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 FALSE   0

FALSE constant value.

Definition at line 49 of file PMSM.h.

#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

Hall sensor pull-up enable. Set to TRUE to enable, FALSE to disable.

Definition at line 104 of file PMSM.h.

#define PID_K_D   0

PID controller derivative gain constant.

Todo:
Adjust PID controller derivative gain. (Only for closed loop)

Definition at line 258 of file PMSM.h.

Referenced by main().

#define PID_K_I   10

PID controller integral gain constant.

Todo:
Adjust PID controller integral gain. (Only for closed loop)

Definition at line 253 of file PMSM.h.

Referenced by main().

#define PID_K_P   256

PID controller proportional gain constant.

Todo:
Adjust PID controller proportional gain. (Only for closed loop)

Definition at line 248 of file PMSM.h.

Referenced by main().

#define PWM1X   7

Bit position of PWM1X flag in TCCR1B register.

Bit position of PWM1X flag in TCCR1B register. Included in this file becuase it was not defined in the compilers header files.

Definition at line 68 of file PMSM.h.

Referenced by PWMInit().

#define PWM_INVERT_OUTPUT   0

Selects inversion of PWM outputs.

Setting this flag to "1" causes the PWM outputs from Timer/Counter1 to be inverted. Inversion happens after dead time insertion.

Definition at line 136 of file PMSM.h.

Referenced by PWMInit().

#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

Sine table size. Select what sine table size should be used.

Todo:
Select sine table size.

Definition at line 168 of file PMSM.h.

#define SINE_TABLE_SIZE_LARGE   0

SINE_TABLE_SIZE value for large (3 * 192 elements) sine table.

Definition at line 159 of file PMSM.h.

#define SINE_TABLE_SIZE_SMALL   1

SINE_TABLE_SIZE value for small (64 elements) sine table.

Definition at line 162 of file PMSM.h.

#define SPEED_CONTROL_CLOSED_LOOP   1

Speed control selection for closed loop control.

Definition at line 231 of file PMSM.h.

#define SPEED_CONTROL_METHOD   SPEED_CONTROL_OPEN_LOOP

Type of speed control. select either SPEED_CONTROL_OPEN_LOOP or SPEED_CONTROL_CLOSED_LOOP.

Todo:
Select speed control method.

Definition at line 237 of file PMSM.h.

#define SPEED_CONTROL_OPEN_LOOP   0

Speed control selection for open loop control.

Definition at line 228 of file PMSM.h.

#define SPEED_CONTROLLER_MAX_INCREMENT   620

The maximum increment (maximum speed) to use as setpoint when the maximum speed reference value is input.

Todo:
Adjust maximum increment. (Maximum speed, used by speed controller)

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.

Todo:
Adjust Maximum speed reference input value.

Definition at line 272 of file PMSM.h.

Referenced by SpeedController().

#define SPEED_CONTROLLER_TIME_BASE   150

The number of ticks between each iteration of the speed loop.

Todo:
Adjust speed control loop time base.

Definition at line 243 of file PMSM.h.

Referenced by main().

#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)

TRUE constant value, defined to be compatible with comparisons.

Definition at line 52 of file PMSM.h.

#define TURN_MODE   TURN_MODE_BRAKE

Turn mode. Set to either TURN_MODE_COAST or TURN_MODE_BRAKE.

Todo:
Select turn mode.

Definition at line 224 of file PMSM.h.

#define TURN_MODE_BRAKE   1

TURN_MODE value for braking (low side braking).

Definition at line 217 of file PMSM.h.

#define TURN_MODE_COAST   0

TURN_MODE value for coasting (disabled drivers).

Definition at line 214 of file PMSM.h.

#define UH   PB1

Pin connected to UH.

Definition at line 76 of file PMSM.h.

#define UH_OCOE   OC1OE1

Definition at line 114 of file PMSM.h.

#define UL   PB0

Pin connected to UL.

Definition at line 73 of file PMSM.h.

#define UL_OCOE   OC1OE0

Definition at line 113 of file PMSM.h.

#define VH   PB3

Pin connected to VH.

Definition at line 82 of file PMSM.h.

#define VH_OCOE   OC1OE3

Definition at line 116 of file PMSM.h.

#define VL   PB2

Pin connected to VL.

Definition at line 79 of file PMSM.h.

#define VL_OCOE   OC1OE2

Definition at line 115 of file PMSM.h.

#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().

#define WH   PB5

Pin connected to WH.

Definition at line 88 of file PMSM.h.

#define WH_OCOE   OC1OE5

Definition at line 118 of file PMSM.h.

#define WL   PB4

Pin connected to WL.

Definition at line 85 of file PMSM.h.

#define WL_OCOE   OC1OE4

Definition at line 117 of file PMSM.h.


Typedef Documentation

typedef struct PMSMflags PMSMflags_t

Collection of all motor control flags.

This struct contains all motor control flags used in this implementation.


Function Documentation

static void ActualDirectionUpdate ( uint8_t  lastHall,
const uint8_t  newHall 
) [static]

static void ADCInit ( void   )  [static]

static void AdjustSineTableIndex ( const uint16_t  increment  )  [static]

static void BlockCommutate ( const uint8_t  direction,
const uint8_t  hall 
) [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 unsigned int MultiplyUS15x8 ( const uint16_t  m15,
const uint8_t  m8 
) [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 uint16_t SineTableIncrementCalculate ( const uint16_t  ticks  )  [static]

static uint8_t SineTableSmallGetValue ( uint8_t  index  )  [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]


Generated on Wed Oct 10 15:31:45 2007 for AVR449 by  doxygen 1.5.2