买了这块BLDC开发板用来学习无刷电机,下了开发包里的代码,看了蛮久了,发现有几处错误:
第一:
// Mapping from Hall States to Phase Drive states (60 degree spacing).
//
// This array maps the hall state value to the set of PWM
// signals that should be driving at that time.
//
// \verbatim
// ---------+---+---+---+---+---+---+
// Phase A | + | Z | - | - | Z | + |
// Phase B | - | - | Z | + | + | Z |
// Phase C | Z | + | + | Z | - | - |
// ---------+---+---+---+---+---+---+
// Hall A | 0 | 1 | 1 | 1 | 0 | 0 |
// Hall B | 0 | 0 | 1 | 1 | 1 | 0 |
// Hall C | 0 | 0 | 0 | 1 | 1 | 1 |
// ---------+---+---+---+---+---+---+
// \endverbatim
//
//*****************************************************************************
static const unsigned long g_ulHallToPhase60[8] =
{
PWM_PHASEA_HIGH | PWM_PHASEB_LOW,
PWM_PHASEC_HIGH | PWM_PHASEB_LOW,
0,
PWM_PHASEC_HIGH | PWM_PHASEA_LOW,
PWM_PHASEA_HIGH | PWM_PHASEC_LOW,
0,
PWM_PHASEB_HIGH | PWM_PHASEC_LOW,
PWM_PHASEB_HIGH | PWM_PHASEA_LOW,
};
换相顺序根本没对应上
其实:
// If trapezoid (not sine), and slow decay, set the odd PWM at near
// 100% duty cycle.
//
if((UI_PARAM_MODULATION != MODULATION_SINE) &&
(g_ucDecayMode == DECAY_SLOW))
{
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1,
(g_ulPWMClock - UI_PARAM_PWM_DEAD_TIME));
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3,
(g_ulPWMClock - UI_PARAM_PWM_DEAD_TIME));
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_5,
(g_ulPWMClock - UI_PARAM_PWM_DEAD_TIME));
}
怎么会产生近100%占空比的pwm??
前面定义的:
// Get the number of PWM clocks in a 20 KHz period.
//
g_ulPWMClock = PWM_CLOCK / 20000;
// Configure the PWM period, duty cycle, and dead band. The initial period
// is 1 KHz (for triggering the ADC), which will be increased when the
// motor starts running.
// 配置PWM周期,占空比,死区。最初的周期是1KHZ(触发ADC),当点击开始启动时将会增加。
PWMClearDeadBand();
PWMSetFrequency();
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, PWM_CLOCK / 1000);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, PWM_CLOCK / 1000);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, PWM_CLOCK / 1000);
PWMUpdateDutyCycle();
怎么也不会有近100%的PWM产生。这个代码我不知道官方测试过没。。。。都不知道该不该继续看下去