|
brazos-trapezoidal
|
Implementation of trapezoidal sensorless control for wye connected BLDC motors. More...
#include "TrapSless.h"#include "includes.h"
Go to the source code of this file.
Macros | |
| #define | PATTERN_BEMF_U_MASK (0x04) |
| #define | PATTERN_BEMF_V_MASK (0x02) |
| #define | PATTERN_BEMF_W_MASK (0x01) |
Functions | |
| void | outputPwmExec (void) |
| Update the pwm outputs. More... | |
| void | AvgOffset () |
| void | TrapSless__Init (void) |
| Initialization of TrapSless module. More... | |
| uint8_t | TrapSless__GetTooEarly (void) |
| Too early detection mechanism For every commutation there is an expected zcross at a given phase. This algorithm will check if the event has already passed and is missed. More... | |
| uint8_t | TrapSless__GetCmtToNum (uint8_t cmt, uint8_t dir) |
| Returns the index of the given commutation pattern For CW rotation the index matches the commutation pattern. For CCW rotation the index does not match the commutation pattern. More... | |
| uint8_t | TrapSless__GetBemfToNum (uint8_t bemf, uint8_t after_zc, uint8_t dir) |
| Returns the index of the given bemf pattern. More... | |
| uint8_t | TrapSless__GetCmtFromBemf (uint8_t dir, uint8_t bemf, uint8_t after_zc) |
| Returns the commutation pattern given a bemf pattern. More... | |
| uint8_t | TrapSless__GetBemfFromCmt (uint8_t dir, uint8_t CmtNum, uint8_t after_zc) |
| Returns the bemf pattern given a commutation index. More... | |
| void | TrapSless__Handler () |
| Handler for Trapezoidal control - 16KHz call rate. More... | |
| void | TrapSless__SlowHandler () |
| Handler for Trapezoidal control - 1KHz call rate. More... | |
| uint8_t | TrapSless__GetBemfSignal (int32_t va, int32_t vb, int32_t vc) |
| Returns the bemf pattern based on pole voltage reading [a,b,c]. More... | |
| int32_t | TrapSless__CalcSpeed () |
| Speed computation based on Bemf Zcross events. More... | |
| void | TrapSless__ResetVars () |
| Resetting of trapezoidal key variables. More... | |
| void | TrapSless__SetSpd (int32_t spd_rpm, int32_t ramp_rpm) |
| BLDC motor rotation command. More... | |
| void | TrapSless__SetPatternAndPwm (uint8_t after_zc) |
| Set pwm duty cycle and output pattern. More... | |
| void | TrapSless__SetPwm (void) |
| Set pwm duty cycle. More... | |
| void | TrapSless__PiCalc (int32_t curr_clamp) |
| Pi regulator If curr_clamp is different than zero, then only runs the clamp algorithm If curr_clamp is zero, then execute regular pi. More... | |
| void | TrapSless__SetVbusIbus (void) |
| Read ADC and Set Vbus and Ibus variables. More... | |
| void | TrapSless__SetVabc (void) |
| Read ADC and set pole voltage variables. More... | |
| void | TrapSless__BemfCnterUpdate (void) |
| Accumulate the counter for bemf. More... | |
| TRAPSLESS_PATTERN_TYPE * | TrapSless__GetVars (void) |
| Obtaine the trapezoidal variables. More... | |
| void | TrapSless__ExecuteCmt (void) |
| Execution of commutation. More... | |
| void | decodeOutput (UVW_STATE_TYPE state) |
| Set the outputs according to the pole voltage state. More... | |
Variables | |
| TRAPSLESS_PATTERN_TYPE | TrapSlessData |
| volatile uint8_t | AUTO_COMM_CNTER = 255 |
| volatile uint8_t | AUTO_COMM_CNTER_BREAK = 255 |
| const uint8_t | PortStateCW [8][2] |
| const uint8_t | PortStateCCW [8][2] |
| const uint8_t | TrapSlessBemfSeqCW [][2] = {{5,4},{4,6},{6,2},{2,3},{3,1},{1,5}} |
| const uint8_t | TrapSlessBemfSeqCCW [][2] = {{4,5},{5,1},{1,3},{3,2},{2,6},{6,4}} |
| const uint8_t | TrapSlessCmtSeqCW [] = {0,1,2,3,4,5} |
| const uint8_t | TrapSlessNxtCmtSeqCW [] = {1,2,3,4,5,0} |
| const uint8_t | TrapSlessCmtSeqCCW [] = {0,5,4,3,2,1} |
| const uint8_t | TrapSlessNxtCmtSeqCCW [] = {5,4,3,2,1,0} |
| uint16_t | OffsetTimeout = 2500 |
| mc_t | TrapDutyMaxCnts |
| uint32_t | PwmHalfMaxCnts |
| uint32_t | PwmMaxMinusDtCnts |
| mc_t | ParamPwmFreqKHz |
| mc_t | ParamDegZcToCmt |
| mc_t | ParamMinPreCarrierCnt |
| mc_t | ParamMaxPreCarrierCnt |
| int64_t | ParamSpdCalcNum |
| int32_t | CurrClampValue |
| uint32_t | ParamOpenLoopSpdBemfCnt |
| uint32_t | ParamMaxSpdBemfCnt |
| int32_t | OutMaxVbus |
| uint32_t | ParamOpenLoopSpdBemfCntVar |
Implementation of trapezoidal sensorless control for wye connected BLDC motors.
This control does not fit to delta type motors.
Definition in file TrapSless.c.
| #define PATTERN_BEMF_U_MASK (0x04) |
< Back-emf reading pattern Mask for U phase bemf signal build
Definition at line 44 of file TrapSless.c.
| #define PATTERN_BEMF_V_MASK (0x02) |
Mask for V phase bemf signal build
Definition at line 45 of file TrapSless.c.
| #define PATTERN_BEMF_W_MASK (0x01) |
Mask for W phase bemf signal build
Definition at line 46 of file TrapSless.c.
| enum UVW_STATE_TYPE |
Definitions of switches states (12 active states and 2 non active states)
Defines the switches states: Float (FL), Low (LO), Duty at Low (DL), Duty at high (DH) and High (HI).
Definition at line 53 of file TrapSless.c.
| void AvgOffset | ( | ) |
@brief Average the current offset. @details
This function is called at INIT state of motor statemachine It is used for sampling of ADC current offsets while inverter switches are off. When motor current is zero the ADC is about the half scale of ADC range
Definition at line 1298 of file TrapSless.c.

| void decodeOutput | ( | UVW_STATE_TYPE | state | ) |
Set the outputs according to the pole voltage state.
| state | - pole uvw state [state]. |
Definition at line 1209 of file TrapSless.c.

|
inline |
Update the pwm outputs.
Definition at line 1277 of file TrapSless.c.


| void TrapSless__BemfCnterUpdate | ( | void | ) |
Accumulate the counter for bemf.
Definition at line 1104 of file TrapSless.c.

| int32_t TrapSless__CalcSpeed | ( | void | ) |
Speed computation based on Bemf Zcross events.
Definition at line 864 of file TrapSless.c.
| void TrapSless__ExecuteCmt | ( | void | ) |
Execution of commutation.
Definition at line 1123 of file TrapSless.c.

| uint8_t TrapSless__GetBemfFromCmt | ( | uint8_t | dir, |
| uint8_t | CmtNum, | ||
| uint8_t | after_zc | ||
| ) |
Returns the bemf pattern given a commutation index.
| dir | direction |
| CmtNum | Commutation index |
| after_zc | if before (0) or after (1) zero cross . |
Definition at line 424 of file TrapSless.c.
| uint8_t TrapSless__GetBemfSignal | ( | int32_t | va, |
| int32_t | vb, | ||
| int32_t | vc | ||
| ) |
Returns the bemf pattern based on pole voltage reading [a,b,c].
| va | Pole voltage |
| vb | Pole voltage |
| vc | Pole voltage |
Definition at line 842 of file TrapSless.c.
| uint8_t TrapSless__GetBemfToNum | ( | uint8_t | bemf, |
| uint8_t | after_zc, | ||
| uint8_t | dir | ||
| ) |
Returns the index of the given bemf pattern.
| bemf | Bemf pattern |
| after_zc | if before (0) or after (1) the zerocross (zc) |
| dir | direction (CW, CCW) |
Definition at line 296 of file TrapSless.c.

| uint8_t TrapSless__GetCmtFromBemf | ( | uint8_t | dir, |
| uint8_t | bemf, | ||
| uint8_t | after_zc | ||
| ) |
Returns the commutation pattern given a bemf pattern.
| dir | direction |
| bemf | Bemf pattern |
| after_zc | if before (0) or after (1) zero cross . |
Definition at line 410 of file TrapSless.c.

| uint8_t TrapSless__GetCmtToNum | ( | uint8_t | cmt, |
| uint8_t | dir | ||
| ) |
Returns the index of the given commutation pattern For CW rotation the index matches the commutation pattern. For CCW rotation the index does not match the commutation pattern.
| cmt | Commutation. |
| dir | Direction (CW, CCW). |
Definition at line 256 of file TrapSless.c.

| uint8_t TrapSless__GetTooEarly | ( | void | ) |
Too early detection mechanism For every commutation there is an expected zcross at a given phase. This algorithm will check if the event has already passed and is missed.
Definition at line 222 of file TrapSless.c.
| TRAPSLESS_PATTERN_TYPE * TrapSless__GetVars | ( | void | ) |
Obtaine the trapezoidal variables.
Definition at line 1116 of file TrapSless.c.

| void TrapSless__Handler | ( | void | ) |
Handler for Trapezoidal control - 16KHz call rate.
< Zero speed for feedback
< Time count for bemf events (for speed calc) is zero
Definition at line 437 of file TrapSless.c.

| void TrapSless__Init | ( | void | ) |
Initialization of TrapSless module.
Definition at line 184 of file TrapSless.c.

| void TrapSless__PiCalc | ( | int32_t | curr_clamp | ) |
Pi regulator If curr_clamp is different than zero, then only runs the clamp algorithm If curr_clamp is zero, then execute regular pi.
| curr_clamp | Current Clamp value. |
Definition at line 993 of file TrapSless.c.
| void TrapSless__ResetVars | ( | void | ) |
Resetting of trapezoidal key variables.
| Trapezoidal | data structure [data]. |
Definition at line 885 of file TrapSless.c.

| void TrapSless__SetPatternAndPwm | ( | uint8_t | after_zc | ) |
Set pwm duty cycle and output pattern.
| after_zc | if before (0) or after (1) zcross. |
Definition at line 924 of file TrapSless.c.


| void TrapSless__SetPwm | ( | void | ) |
Set pwm duty cycle.
Definition at line 938 of file TrapSless.c.

| void TrapSless__SetSpd | ( | int32_t | spd_rpm, |
| int32_t | ramp_rpm | ||
| ) |
BLDC motor rotation command.
| spd_rpm | Speed in rpm |
| ramp_rpm | Speed ramp in rpm/s |
Definition at line 899 of file TrapSless.c.


| void TrapSless__SetVabc | ( | void | ) |
Read ADC and set pole voltage variables.
Definition at line 1087 of file TrapSless.c.
| void TrapSless__SetVbusIbus | ( | void | ) |
Read ADC and Set Vbus and Ibus variables.
Definition at line 1052 of file TrapSless.c.
| void TrapSless__SlowHandler | ( | void | ) |
Handler for Trapezoidal control - 1KHz call rate.
Definition at line 694 of file TrapSless.c.

| volatile uint8_t AUTO_COMM_CNTER = 255 |
Number of commutations until auto commutation is reached.
Definition at line 48 of file TrapSless.c.
| volatile uint8_t AUTO_COMM_CNTER_BREAK = 255 |
Above this value zero voltage is applied until the counter reaches AUTO_COMM_CNTER
Definition at line 49 of file TrapSless.c.
| int32_t CurrClampValue |
[A] Current at which the control will limit the operation
Definition at line 167 of file TrapSless.c.
| uint16_t OffsetTimeout = 2500 |
2,5 seconds, slot time 1ms, time for sampling the offset level of current reading
Definition at line 158 of file TrapSless.c.
| int32_t OutMaxVbus |
[V] Hold the maximum voltage the pi controller will output.
Definition at line 170 of file TrapSless.c.
| mc_t ParamDegZcToCmt |
Electrical angle in [deg] from a zero cross to a commutation instant
Definition at line 163 of file TrapSless.c.
| mc_t ParamMaxPreCarrierCnt |
This is the carrier counting expected, for one commutation [60deg], when operating at lowest speed
Definition at line 165 of file TrapSless.c.
| uint32_t ParamMaxSpdBemfCnt |
This is the carrier bemf counting expected, for one commutation [60deg], when operating at highest speed
Definition at line 169 of file TrapSless.c.
| mc_t ParamMinPreCarrierCnt |
This is the carrier counting expected, for one commutation [60deg], when operating at highest speed
Definition at line 164 of file TrapSless.c.
| uint32_t ParamOpenLoopSpdBemfCnt |
This is the carrier bemf counting expected, for one commutation [60deg], when operating at lowest speed
Definition at line 168 of file TrapSless.c.
| uint32_t ParamOpenLoopSpdBemfCntVar |
This variable limits the time counts for the commutation instant at startup [counts]
Definition at line 172 of file TrapSless.c.
| mc_t ParamPwmFreqKHz |
Hold the pwm frequency in [KHz]
Definition at line 162 of file TrapSless.c.
| int64_t ParamSpdCalcNum |
[rad.s-1] Constant for speed computation
Definition at line 166 of file TrapSless.c.
| const uint8_t PortStateCCW[8][2] |
Commutation patterns for Clockwise (CCW)
HI is high side active permanently within one commutation.
LO is low side switch active permanently within one commutation.
DH is the high side active with Pwm
DL is the low side active with Pwm
FL is the phase floating
(before zc) U V W || (after zc) U V W
Commutation #0: DH LO FL || HI DL FL (active)
Commutation #1: FL DL HI || FL LO DH (active)
Commutation #2: LO FL DH || DL FL HI (active)
Commutation #3: DL HI FL || LO DH FL (active)
Commutation #4: FL DH LO || FL HI DL (active)
Commutation #5: HI FL DL || DH FL LO (active)
Commutation #6: FL FL FL || FL FL FL (non active)
Commutation #7: LO LO LO || LO LO LO (non active)
Definition at line 121 of file TrapSless.c.
| const uint8_t PortStateCW[8][2] |
Commutation patterns for Clockwise (CW)
HI is high side active permanently within one commutation.
LO is low side switch active permanently within one commutation.
DH is the high side active with Pwm
DL is the low side active with Pwm
FL is the phase floating
(before zc) U V W || (after zc) U V W
Commutation #0: HI DL FL || DH LO FL (active)
Commutation #1: DH FL LO || HI FL DL (active)
Commutation #2: FL HI DL || FL DH LO (active)
Commutation #3: LO DH FL || DL HI FK (active)
Commutation #4: DL FL HI || LO FL DH (active)
Commutation #5: FL LO DH || FL DL HI (active)
Commutation #6: FL FL FL || FL FL HI (non active)
Commutation #7: LO LO LO || LO LO LO (non active)
Definition at line 94 of file TrapSless.c.
| uint32_t PwmHalfMaxCnts |
Half of maximum pwm count value when at duty cycle max
Definition at line 160 of file TrapSless.c.
| uint32_t PwmMaxMinusDtCnts |
Maximum pwm count value minus deadtime when at duty cycle max
Definition at line 161 of file TrapSless.c.
| mc_t TrapDutyMaxCnts |
Maximum pwm count value when at duty cycle max
Definition at line 159 of file TrapSless.c.
| const uint8_t TrapSlessBemfSeqCCW[][2] = {{4,5},{5,1},{1,3},{3,2},{2,6},{6,4}} |
Actual Commutation sequence for clockwise operation - CW
Definition at line 143 of file TrapSless.c.
| const uint8_t TrapSlessBemfSeqCW[][2] = {{5,4},{4,6},{6,2},{2,3},{3,1},{1,5}} |
< Bemf sequence based on commutation CW 4 6 2 3 1 5 Bemf sequence based on commutation CCW 5 1 3 2 6 4
Definition at line 141 of file TrapSless.c.
| const uint8_t TrapSlessCmtSeqCCW[] = {0,5,4,3,2,1} |
Next Commutation sequence for counter clockwise operation - CCW
Based on bemf information
Definition at line 152 of file TrapSless.c.
| const uint8_t TrapSlessCmtSeqCW[] = {0,1,2,3,4,5} |
Next Commutation sequence for clockwise operation - CW
Definition at line 146 of file TrapSless.c.
| TRAPSLESS_PATTERN_TYPE TrapSlessData |
< Struct variable carry all motor control related informatin
Definition at line 21 of file TrapSless.c.
| const uint8_t TrapSlessNxtCmtSeqCCW[] = {5,4,3,2,1,0} |
Variables for algorithm handling
Definition at line 155 of file TrapSless.c.
| const uint8_t TrapSlessNxtCmtSeqCW[] = {1,2,3,4,5,0} |
Actual Commutation sequence for counter clockwise operation - CCW
Based on bemf information
Definition at line 148 of file TrapSless.c.