📄 ui.c
字号:
UIButtonHold
}
};
//*****************************************************************************
//
//! The number of switches in the g_sUISwitches array. This value is
//! automatically computed based on the number of entries in the array.
//
//*****************************************************************************
#define NUM_SWITCHES (sizeof(g_sUISwitches) / \
sizeof(g_sUISwitches[0]))
//*****************************************************************************
//
//! The number of switches on this target. This value is used by the on-board
//! user interface module.
//
//*****************************************************************************
const unsigned long g_ulUINumButtons = NUM_SWITCHES;
//*****************************************************************************
//
//! This is the count of the number of samples during which the switches have
//! been pressed; it is used to distinguish a switch press from a switch
//! hold. This array is used by the on-board user interface module.
//
//*****************************************************************************
unsigned long g_pulUIHoldCount[NUM_SWITCHES];
//*****************************************************************************
//
//! This is the board id, read once from the configuration switches at startup.
//
//*****************************************************************************
unsigned char g_ucBoardID = 0;
//*****************************************************************************
//
//! The running count of system clock ticks.
//
//*****************************************************************************
static unsigned long g_ulUITickCount = 0;
//*****************************************************************************
//
//! Updates the Ethernet TCP connection timeout.
//!
//! This function is called when the variable controlling the presence of an
//! encoder is updated. The value is then reflected into the usFlags member
//! of #g_sParameters.
//!
//! \return None.
//
//*****************************************************************************
static void
UIConnectionTimeout(void)
{
//
// Update the encoder presence flag in the flags variable.
//
g_ulConnectionTimeoutParameter = g_sParameters.ulConnectionTimeout;
}
//*****************************************************************************
//
//! Updates the encoder presence bit of the motor drive.
//!
//! This function is called when the variable controlling the presence of an
//! encoder is updated. The value is then reflected into the usFlags member
//! of #g_sParameters.
//!
//! \return None.
//
//*****************************************************************************
static void
UIEncoderPresent(void)
{
//
// Update the encoder presence flag in the flags variable.
//
HWREGBITH(&(g_sParameters.usFlags), FLAG_ENCODER_BIT) = g_ucEncoder;
}
//*****************************************************************************
//
//! Updates the sensor presence bit of the motor drive.
//!
//! This function is called when the variable controlling the presence of an
//! sensor is updated. The value is then reflected into the usFlags member
//! of #g_sParameters.
//!
//! \return None.
//
//*****************************************************************************
static void
UISensorPresent(void)
{
//
// Update the sensor presence flag in the flags variable.
//
HWREGBITH(&(g_sParameters.usFlags), FLAG_SENSOR_BIT) = g_ucSensor;
//
// Reconfigure the ADC sequences, as needed.
//
if(HWREGBITH(&(g_sParameters.usFlags), FLAG_SENSOR_BIT) ==
FLAG_SENSOR_PRESENT)
{
//
// Disasble the Back EMF sequence if a sensor is present.
//
ADCEnableBackEMFSequence(false);
//
// Enable the Linear Hall Sequence is the sensor type is Linear.
//
if(HWREGBITH(&(g_sParameters.usFlags), FLAG_SENSOR_TYPE_BIT) ==
FLAG_SENSOR_TYPE_LINEAR)
{
ADCEnableLinearHallSequence(true);
}
//
// Otherwise, disable the Linear Hall Sequence.
//
else
{
ADCEnableLinearHallSequence(false);
}
}
//
// Here, enable the Back EMF sequence (i.e. no sensor is present)
// and disable Linear Hall sequence processing.
//
else
{
ADCEnableLinearHallSequence(false);
ADCEnableBackEMFSequence(true);
}
}
//*****************************************************************************
//
//! Updates the sensor type bit of the motor drive.
//!
//! This function is called when the variable controlling the type of sensor
//! is updated. The value is then reflected into the usFlags member of
//! #g_sParameters.
//!
//! \return None.
//
//*****************************************************************************
static void
UISensorType(void)
{
//
// Update the sensor type flag in the flags variable.
//
HWREGBITH(&(g_sParameters.usFlags), FLAG_SENSOR_TYPE_BIT) =
g_ucSensorType;
//
// Reconfigure the ADC sequences, as needed.
//
if(HWREGBITH(&(g_sParameters.usFlags), FLAG_SENSOR_BIT) ==
FLAG_SENSOR_PRESENT)
{
//
// Disasble the Back EMF sequence if a sensor is present.
//
ADCEnableBackEMFSequence(false);
//
// Enable the Linear Hall Sequence is the sensor type is Linear.
//
if(HWREGBITH(&(g_sParameters.usFlags), FLAG_SENSOR_TYPE_BIT) ==
FLAG_SENSOR_TYPE_LINEAR)
{
ADCEnableLinearHallSequence(true);
}
//
// Otherwise, disable the Linear Hall Sequence.
//
else
{
ADCEnableLinearHallSequence(false);
}
}
//
// Here, enable the Back EMF sequence (i.e. no sensor is present)
// and disable Linear Hall sequence processing.
//
else
{
ADCEnableLinearHallSequence(false);
ADCEnableBackEMFSequence(true);
}
}
//*****************************************************************************
//
//! Updates the sensor polarity bit of the motor drive.
//!
//! This function is called when the variable controlling the polarity of
//! the sensor is updated. The value is then reflected into the usFlags
//! member of #g_sParameters.
//!
//! \return None.
//
//*****************************************************************************
static void
UISensorPolarity(void)
{
//
// See if the motor drive is running.
//
if(MainIsRunning())
{
//
// The sensor polarity can not be changed when the motor drive is
// running, so revert the sensor polarity variable back to the value
// in the flags.
//
g_ucSensorPolarity = HWREGBITH(&(g_sParameters.usFlags),
FLAG_SENSOR_POLARITY_BIT);
//
// There is nothing further to do.
//
return;
}
//
// Update the sensor type flag in the flags variable.
//
HWREGBITH(&(g_sParameters.usFlags), FLAG_SENSOR_POLARITY_BIT) =
g_ucSensorPolarity;
}
//*****************************************************************************
//
//! Updates the modulation waveform type bit in the motor drive.
//!
//! This function is called when the variable controlling the modulation
//! waveform type is updated. The value is then reflected into the usFlags
//! member of #g_sParameters.
//!
//! \return None.
//
//*****************************************************************************
static void
UIModulationType(void)
{
//
// See if the motor drive is running.
//
if(MainIsRunning())
{
//
// The modulation type can not changed when the motor drive is running
// (that could be catastrophic!), so revert the modulation type
// variable back to the value in the flags.
//
g_ucModulation = HWREGBITH(&(g_sParameters.usFlags), FLAG_DRIVE_BIT);
//
// There is nothing further to do.
//
return;
}
//
// Update the modulation waveform type flag in the flags variable.
//
HWREGBITH(&(g_sParameters.usFlags), FLAG_DRIVE_BIT) = g_ucModulation;
//
// Reconfigure the ADC Phase Current sequence based on the modulation
// scheme.
//
if(HWREGBITH(&(g_sParameters.usFlags), FLAG_DRIVE_BIT) ==
FLAG_DRIVE_SINE)
{
ADCConfigurePhaseCurrentSequence(1);
}
else
{
ADCConfigurePhaseCurrentSequence(0);
}
}
//*****************************************************************************
//
//! Updates the motor drive direction bit.
//!
//! This function is called when the variable controlling the motor drive
//! direction is updated. The value is then reflected into the usFlags
//! member of #g_sParameters.
//!
//! \return None.
//
//*****************************************************************************
static void
UIDirectionSet(void)
{
//
// Update the direction flag in the flags variable.
//
HWREGBITH(&(g_sParameters.usFlags), FLAG_DIR_BIT) = g_ucDirection;
//
// Change the direction of the motor drive.
//
MainSetDirection(g_ucDirection ? false : true);
}
//*****************************************************************************
//
//! Updates the PWM frequency of the motor drive.
//!
//! This function is called when the variable controlling the PWM frequency of
//! the motor drive is updated. The value is then reflected into the usFlags
//! member of #g_sParameters.
//!
//! \return None.
//
//*****************************************************************************
static void
UIPWMFrequencySet(void)
{
//
// See if the value is zero.
//
if(g_ucFrequency == 0)
{
//
// Set the frequency to 8 KHz.
//
g_sParameters.usFlags = ((g_sParameters.usFlags &
~FLAG_PWM_FREQUENCY_MASK) |
FLAG_PWM_FREQUENCY_8K);
}
//
// See if the value is one.
//
else if(g_ucFrequency == 1)
{
//
// Set the frequency to 12.5 KHz.
//
g_sParameters.usFlags = ((g_sParameters.usFlags &
~FLAG_PWM_FREQUENCY_MASK) |
FLAG_PWM_FREQUENCY_12K);
}
//
// See if the value is two.
//
else if(g_ucFrequency == 2)
{
//
// Set the frequency to 16 KHz.
//
g_sParameters.usFlags = ((g_sParameters.usFlags &
~FLAG_PWM_FREQUENCY_MASK) |
FLAG_PWM_FREQUENCY_16K);
}
//
// Otherwise, assume that the value is three.
//
else
{
//
// Set the frequency to 20 KHz.
//
g_sParameters.usFlags = ((g_sParameters.usFlags &
~FLAG_PWM_FREQUENCY_MASK) |
FLAG_PWM_FREQUENCY_20K);
}
//
// Change the PWM frequency.
//
MainSetPWMFrequency();
}
//*****************************************************************************
//
//! Sets the update rate of the motor drive.
//!
//! This function is called when the variable specifying the update rate of the
//! motor drive is updated. This allows the motor drive to perform a
//! synchronous change of the update rate to avoid discontinuities in the
//! output waveform.
//!
//! \return None.
//
//*****************************************************************************
static void
UIUpdateRate(void)
{
//
// Set the update rate of the motor drive.
//
PWMSetUpdateRate(g_ucUpdateRate);
}
//*****************************************************************************
//
//! Updates the I coefficient of the frequency PI controller.
//!
//! This function is called when the variable containing the I coefficient of
//! the frequency PI controller is updated. The value is then reflected into
//! the parameter block.
//!
//! \return None.
//
//*****************************************************************************
static void
UIFAdjI(void)
{
//
// Update the frequency PI controller.
//
MainUpdateFAdjI(g_lFAdjI);
}
//*****************************************************************************
//
//! Updates the dynamic brake bit of the motor drive.
//!
//! This function is called when the variable controlling the dynamic braking
//! is updated. The value is then reflected into the usFlags member of
//! #g_sParameters.
//!
//! \return None.
//
//*****************************************************************************
static void
UIDynamicBrake(void)
{
//
// Update the dynamic braking flag in the flags variable.
//
HWREGBITH(&(g_sParameters.usFlags), FLAG_BRAKE_BIT) = g_ucDynamicBrake;
}
//*****************************************************************************
//
//! Updates the decay mode bit of the motor drive.
//!
//! This function is called when the variable controlling the decay mode
//! is updated. The value is then reflected into the usFlags member of
//! #g_sParameters.
//!
//! \return None.
//
//*****************************************************************************
static void
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -