合併 main app

This commit is contained in:
roy01
2026-04-23 14:37:26 +08:00
parent 3f10ca6e02
commit 552b3ab5b4
7 changed files with 432 additions and 337 deletions
-16
View File
@@ -1,16 +0,0 @@
#ifndef __APP_H__
#define __APP_H__
#ifdef __cplusplus
extern "C"
{
#endif
void app_init(void);
void app_task(void);
#ifdef __cplusplus
}
#endif
#endif
+1 -1
View File
@@ -14,7 +14,7 @@ extern "C"
{
#endif
#define APP_DEMO_UVW_PWM_DDS_ENABLE
#define FW_VERSION "0.0.1"
enum notify_type_e
{
+1 -1
View File
@@ -26,7 +26,7 @@ extern "C"
//=============================================================================
// Macro Definition
//=============================================================================
#define FW_VERSION "0.0.1"
//=============================================================================
// Structure Definition
//=============================================================================
-288
View File
@@ -1,288 +0,0 @@
#include "app.h"
#include "app_cfg.h"
#include "demo_uvw_pwm_dds.h"
#include "motor_control.h"
#include "uart_drv.h"
#include "uvw_adc.h"
static struct cmd_param_t g_cmd_param = { 0 };
static bool g_motor_running = false;
static void app_start_motor(void)
{
g_motor_running = true;
motor_ctrl_start();
GPIO_WriteBit(GPIOA, GPIO_Pin_14, 1U);
}
static void app_stop_motor(void)
{
g_motor_running = false;
motor_ctrl_stop();
GPIO_WriteBit(GPIOA, GPIO_Pin_14, GPIO_PIN_LOW);
}
static void app_uart_write_all(const void *buf, uint16_t len)
{
uart_write(buf, len);
}
static void motor_ctrl_print_basic_data(struct cmd_param_t *cmd_param)
{
uint8_t buffer[64] = { 0 };
uint8_t *ptr = buffer;
uint32_t mcu_timestamp = epwm_get_ms();
uint16_t adc_values[ADC_BUF_LEN] = { 0 };
uint32_t dds_amp = 0;
int32_t dds_ftw = 0;
get_adc_values_raw(adc_values, ADC_BUF_LEN);
dds_get_ftw_amp_setting(&dds_ftw, &dds_amp);
*ptr++ = 0x55;
*ptr++ = 0xAA;
*(uint16_t *)ptr = cmd_param->notify_type;
ptr += 2;
*(uint32_t *)ptr = mcu_timestamp;
ptr += 4;
*(int32_t *)ptr = ((int32_t)adc_values[IDX_IU_LF] - 2048) * (-1);
ptr += 4;
*(int32_t *)ptr = ((int32_t)adc_values[IDX_IV_LF] - 2048) * (-1);
ptr += 4;
*(int32_t *)ptr = ((int32_t)adc_values[IDX_IW_LF] - 2048) * (-1);
ptr += 4;
*(int32_t *)ptr = ((int32_t)adc_values[IDX_IALL_LF] - 2048);
ptr += 4;
*(int32_t *)ptr = adc_values[IDX_BEMF_U];
ptr += 4;
*(int32_t *)ptr = adc_values[IDX_BEMF_V];
ptr += 4;
*(int32_t *)ptr = adc_values[IDX_BEMF_W];
ptr += 4;
*(int32_t *)ptr = adc_values[IDX_VBUS];
ptr += 4;
*(uint32_t *)ptr = dds_amp;
ptr += 4;
*(int32_t *)ptr = dds_ftw;
ptr += 4;
*ptr++ = 0x0D;
*ptr++ = 0x0A;
app_uart_write_all(buffer, (uint16_t)(ptr - buffer));
}
static void print_motor_data_task(struct cmd_param_t *cmd_param)
{
static uint32_t notify_time = 0;
uint32_t now = epwm_get_ms();
if ((now - notify_time) >= cmd_param->notify_time_ms && cmd_param->notify_type != NOTIFY_TYPE_PERIOD)
{
notify_time = now;
if (cmd_param->notify_type == NOTIFY_TYPE_BASIC)
{
motor_ctrl_print_basic_data(cmd_param);
}
}
}
static void handle_cmd_task(void)
{
struct cmd_param_t *c_p = &g_cmd_param;
char *data = (char *)g_uart_rx_buf;
if (!uart_is_frame_ready())
{
return;
}
uart_send_msg("Received command:%s\r\n", data);
if (strncmp(data, "start", 5) == 0)
{
app_start_motor();
}
else if (strncmp(data, "stop", 4) == 0)
{
app_stop_motor();
}
else if (strncmp(data, "dds_ftw:", 8) == 0)
{
c_p->dds_ftw = atoi(data + 8);
dds_set_phase_acc_ftw((uint32_t)c_p->dds_ftw);
}
else if (strncmp(data, "dds_amp:", 8) == 0)
{
uint32_t dds_amp = (uint32_t)atoi(data + 8);
c_p->dds_amp = dds_amp > DDS_AMP_MAX ? DDS_AMP_MAX : dds_amp;
dds_set_phase_acc_amp(c_p->dds_amp);
}
else if (strncmp(data, "freq:", 5) == 0)
{
uint32_t freq = (uint32_t)atoi(data + 5);
c_p->dds_ftw = dds_freq_hz_to_ftw(freq);
dds_set_phase_acc_ftw((uint32_t)c_p->dds_ftw);
}
else if (strncmp(data, "amp:", 4) == 0)
{
uint32_t amp_percent = (uint32_t)atoi(data + 4);
amp_percent = amp_percent > 100U ? 100U : amp_percent;
c_p->dds_amp = (amp_percent * DDS_AMP_MAX) / 100U;
dds_set_phase_acc_amp(c_p->dds_amp);
}
else if (strncmp(data, "curve_offset:", 13) == 0)
{
c_p->soft_start.curve_offset = atoi(data + 13);
}
else if (strncmp(data, "amp+freq:", 9) == 0)
{
uint32_t freq = 0;
uint32_t amp_percent = 0;
if (sscanf(data + 9, "%lu %lu", &amp_percent, &freq) == 2)
{
amp_percent = amp_percent > 100U ? 100U : amp_percent;
c_p->dds_amp = (amp_percent * DDS_AMP_MAX) / 100U;
c_p->dds_ftw = dds_freq_hz_to_ftw(freq);
dds_set_phase_acc_amp(c_p->dds_amp);
dds_set_phase_acc_ftw((uint32_t)c_p->dds_ftw);
}
}
else if (strncmp(data, "dds_amp+dds_ftw:", 16) == 0)
{
uint32_t dds_amp = 0;
int32_t dds_ftw = 0;
if (sscanf(data + 16, "%lu %ld", &dds_amp, &dds_ftw) == 2)
{
c_p->dds_ftw = dds_ftw;
c_p->dds_amp = dds_amp > DDS_AMP_MAX ? DDS_AMP_MAX : dds_amp;
dds_set_phase_acc_amp(c_p->dds_amp);
dds_set_phase_acc_ftw((uint32_t)c_p->dds_ftw);
}
}
else if (strncmp(data, "soft_start:", 11) == 0)
{
uint32_t ddsamp_first = 0;
int32_t ddsftw_first = 0;
int32_t ddsftw_goal = 0;
uint32_t soft_start_time = 0;
if (sscanf(data + 11, "%lu %ld %ld %lu", &ddsamp_first, &ddsftw_first, &ddsftw_goal, &soft_start_time) == 4)
{
c_p->soft_start.dds_amp_first = ddsamp_first > DDS_AMP_MAX ? DDS_AMP_MAX : ddsamp_first;
c_p->soft_start.dds_ftw_first = ddsftw_first < 0 ? 0 : ddsftw_first;
c_p->soft_start.dds_ftw_goal = ddsftw_goal < 0 ? 0 : ddsftw_goal;
c_p->soft_start.soft_start_time_ms = soft_start_time;
dds_set_phase_acc_amp(c_p->soft_start.dds_amp_first);
dds_set_phase_acc_ftw((uint32_t)c_p->soft_start.dds_ftw_first);
motor_ctrl_set_mode(MOTOR_MODE_SOFT_START);
motor_ctrl_set_amp_ftw_mode(AMP_FTW_FIXED_FIXED);
}
}
else if (strncmp(data, "notify_ms:", 10) == 0)
{
c_p->notify_time_ms = (uint32_t)atoi(data + 10);
}
else if (strncmp(data, "notify_type:", 12) == 0)
{
c_p->notify_type = (uint16_t)atoi(data + 12);
}
else if (strncmp(data, "dds_ftw++", 9) == 0 || strncmp(data, "dds_ftw--", 9) == 0)
{
int32_t dftw = 0;
dds_get_ftw_amp_setting(&dftw, NULL);
dftw += (data[8] == '+') ? 1 : -1;
c_p->dds_ftw = dftw < 0 ? 0 : dftw;
dds_set_phase_acc_ftw((uint32_t)c_p->dds_ftw);
}
else if (strncmp(data, "dds_amp++", 9) == 0 || strncmp(data, "dds_amp--", 9) == 0)
{
uint32_t damp = 0;
dds_get_ftw_amp_setting(NULL, &damp);
if (data[8] == '-')
{
damp = damp == 0 ? 0 : damp - 1;
}
else
{
damp += 1;
}
c_p->dds_amp = damp > DDS_AMP_MAX ? DDS_AMP_MAX : damp;
dds_set_phase_acc_amp(c_p->dds_amp);
}
else if (strncmp(data, "vf_control_fb_enable:", 21) == 0)
{
c_p->vf_ctrl_fb_enabled = atoi(data + 21) > 0;
}
else if (strncmp(data, "fw_ver", 6) == 0)
{
uart_send_msg("FW_VER_PEC930_%s\r\n", FW_VERSION);
}
else if (strncmp(data, "help", 4) == 0)
{
static const char *help_lines[] = {
"Available commands:\r\n",
" start - Start motor\r\n",
" stop - Stop motor\r\n",
" freq:<val> - Set frequency Hz\r\n",
" amp:<val> - Set amplitude % (0-100)\r\n",
" amp+freq:<val> <val> - Set amplitude % and freq Hz\r\n",
" dds_ftw:<val> - Set dds_ftw\r\n",
" dds_ftw++ - Increment dds_ftw\r\n",
" dds_ftw-- - Decrement dds_ftw\r\n",
" dds_amp:<val> - Set dds_amp\r\n",
" dds_amp++ - Increment dds_amp\r\n",
" dds_amp-- - Decrement dds_amp\r\n",
" dds_amp+dds_ftw:<val> <val> - Set dds_amp and dds_ftw\r\n",
" soft_start:<amp> <ftw_start> <ftw_goal> <time_ms>\r\n",
" curve_offset:<val> - Set VF curve offset\r\n",
" vf_control_fb_enable:<val> - Enable/disable VF feedback\r\n",
" notify_ms:<val> - Set notify rate in ms\r\n",
" notify_type:<val> - Set notify type (0-3)\r\n",
" fw_ver - Show firmware version\r\n",
" help - Show this help\r\n",
};
for (uint32_t i = 0; i < (sizeof(help_lines) / sizeof(help_lines[0])); i++)
{
uart_send_msg("%s", help_lines[i]);
}
}
else
{
uart_send_msg("Unknown command. Type 'help' for available commands.\r\n");
}
uart_clear_rx_frame();
}
void app_init(void)
{
epwm_init();
uart_init();
adc_drv_init();
motor_ctrl_init_cmd_param(&g_cmd_param);
motor_ctrl_apply_default_settings(&g_cmd_param);
app_stop_motor();
uart_send_msg("pec930 motor app ready\r\n");
}
void app_task(void)
{
uint32_t pending_ticks = epwm_take_24khz_ticks();
while (pending_ticks-- > 0U)
{
dds_tim_period_elapsed();
}
handle_cmd_task();
if (g_motor_running)
{
motor_ctrl_update_task(&g_cmd_param);
print_motor_data_task(&g_cmd_param);
}
}
+128 -8
View File
@@ -21,17 +21,137 @@ static const uint32_t g_phase_offset[3] = {
};
static const int16_t g_lut_sin[64] = {
0, 200, 399, 594, 783, 965, 1137, 1298, 1447, 1582, 1702, 1805, 1891, 1959, 2008, 2037,
2047, 2037, 2008, 1959, 1891, 1805, 1702, 1582, 1447, 1298, 1137, 965, 783, 594, 399, 200,
0, -200, -399, -594, -783, -965, -1137, -1298, -1447, -1582, -1702, -1805, -1891, -1959, -2008, -2037,
-2047, -2037, -2008, -1959, -1891, -1805, -1702, -1582, -1447, -1298, -1137, -965, -783, -594, -399, -200,
0,
200,
399,
594,
783,
965,
1137,
1298,
1447,
1582,
1702,
1805,
1891,
1959,
2008,
2037,
2047,
2037,
2008,
1959,
1891,
1805,
1702,
1582,
1447,
1298,
1137,
965,
783,
594,
399,
200,
0,
-200,
-399,
-594,
-783,
-965,
-1137,
-1298,
-1447,
-1582,
-1702,
-1805,
-1891,
-1959,
-2008,
-2037,
-2047,
-2037,
-2008,
-1959,
-1891,
-1805,
-1702,
-1582,
-1447,
-1298,
-1137,
-965,
-783,
-594,
-399,
-200,
};
static const int16_t g_lut_cos[64] = {
2047, 2037, 2008, 1959, 1891, 1805, 1702, 1582, 1447, 1298, 1137, 965, 783, 594, 399, 200,
0, -200, -399, -594, -783, -965, -1137, -1298, -1447, -1582, -1702, -1805, -1891, -1959, -2008, -2037,
-2047, -2037, -2008, -1959, -1891, -1805, -1702, -1582, -1447, -1298, -1137, -965, -783, -594, -399, -200,
0, 200, 399, 594, 783, 965, 1137, 1298, 1447, 1582, 1702, 1805, 1891, 1959, 2008, 2037,
2047,
2037,
2008,
1959,
1891,
1805,
1702,
1582,
1447,
1298,
1137,
965,
783,
594,
399,
200,
0,
-200,
-399,
-594,
-783,
-965,
-1137,
-1298,
-1447,
-1582,
-1702,
-1805,
-1891,
-1959,
-2008,
-2037,
-2047,
-2037,
-2008,
-1959,
-1891,
-1805,
-1702,
-1582,
-1447,
-1298,
-1137,
-965,
-783,
-594,
-399,
-200,
0,
200,
399,
594,
783,
965,
1137,
1298,
1447,
1582,
1702,
1805,
1891,
1959,
2008,
2037,
};
static uint16_t dds_clamp_duty(int32_t duty)
+296 -17
View File
@@ -8,13 +8,19 @@
* @license
* @description
*/
#include "main.h"
#include "app.h"
#include "epwm_drv.h"
//=============================================================================
// Constant Definition
//=============================================================================
#include "main.h"
#include "epwm_drv.h"
#include "app_cfg.h"
#include "demo_uvw_pwm_dds.h"
#include "motor_control.h"
#include "uart_drv.h"
#include "uvw_adc.h"
//=============================================================================
// Constant Definition
//=============================================================================
//=============================================================================
// Macro Definition
@@ -31,6 +37,9 @@
//=============================================================================
// Private Function Definition
//=============================================================================
static struct cmd_param_t g_cmd_param = { 0 };
static bool g_motor_running = false;
static void sysclk_init(void)
{
SYSCFG_ClkInitTypeDef SysClkInit = { 0 };
@@ -51,18 +60,288 @@ static void test_pin_init(void)
GPIO_WriteBit(GPIOA, GPIO_Pin_14, GPIO_PIN_LOW);
GPIO_Init(GPIOA, &gpio_init);
}
static void app_start_motor(void)
{
g_motor_running = true;
motor_ctrl_start();
GPIO_WriteBit(GPIOA, GPIO_Pin_14, 1U);
}
static void app_stop_motor(void)
{
g_motor_running = false;
motor_ctrl_stop();
GPIO_WriteBit(GPIOA, GPIO_Pin_14, GPIO_PIN_LOW);
}
static void app_uart_write_all(const void *buf, uint16_t len)
{
uart_write(buf, len);
}
static void motor_ctrl_print_basic_data(struct cmd_param_t *cmd_param)
{
uint8_t buffer[64] = { 0 };
uint8_t *ptr = buffer;
uint32_t mcu_timestamp = epwm_get_ms();
uint16_t adc_values[ADC_BUF_LEN] = { 0 };
uint32_t dds_amp = 0;
int32_t dds_ftw = 0;
get_adc_values_raw(adc_values, ADC_BUF_LEN);
dds_get_ftw_amp_setting(&dds_ftw, &dds_amp);
*ptr++ = 0x55;
*ptr++ = 0xAA;
*(uint16_t *)ptr = cmd_param->notify_type;
ptr += 2;
*(uint32_t *)ptr = mcu_timestamp;
ptr += 4;
*(int32_t *)ptr = ((int32_t)adc_values[IDX_IU_LF] - 2048) * (-1);
ptr += 4;
*(int32_t *)ptr = ((int32_t)adc_values[IDX_IV_LF] - 2048) * (-1);
ptr += 4;
*(int32_t *)ptr = ((int32_t)adc_values[IDX_IW_LF] - 2048) * (-1);
ptr += 4;
*(int32_t *)ptr = ((int32_t)adc_values[IDX_IALL_LF] - 2048);
ptr += 4;
*(int32_t *)ptr = adc_values[IDX_BEMF_U];
ptr += 4;
*(int32_t *)ptr = adc_values[IDX_BEMF_V];
ptr += 4;
*(int32_t *)ptr = adc_values[IDX_BEMF_W];
ptr += 4;
*(int32_t *)ptr = adc_values[IDX_VBUS];
ptr += 4;
*(uint32_t *)ptr = dds_amp;
ptr += 4;
*(int32_t *)ptr = dds_ftw;
ptr += 4;
*ptr++ = 0x0D;
*ptr++ = 0x0A;
app_uart_write_all(buffer, (uint16_t)(ptr - buffer));
}
static void print_motor_data_task(struct cmd_param_t *cmd_param)
{
static uint32_t notify_time = 0;
uint32_t now = epwm_get_ms();
if ((now - notify_time) >= cmd_param->notify_time_ms && cmd_param->notify_type != NOTIFY_TYPE_PERIOD)
{
notify_time = now;
if (cmd_param->notify_type == NOTIFY_TYPE_BASIC)
{
motor_ctrl_print_basic_data(cmd_param);
}
}
}
static void handle_cmd_task(void)
{
struct cmd_param_t *c_p = &g_cmd_param;
char *data = (char *)g_uart_rx_buf;
if (!uart_is_frame_ready())
{
return;
}
uart_send_msg("Received command:%s\r\n", data);
if (strncmp(data, "start", 5) == 0)
{
app_start_motor();
}
else if (strncmp(data, "stop", 4) == 0)
{
app_stop_motor();
}
else if (strncmp(data, "dds_ftw:", 8) == 0)
{
c_p->dds_ftw = atoi(data + 8);
dds_set_phase_acc_ftw((uint32_t)c_p->dds_ftw);
}
else if (strncmp(data, "dds_amp:", 8) == 0)
{
uint32_t dds_amp = (uint32_t)atoi(data + 8);
c_p->dds_amp = dds_amp > DDS_AMP_MAX ? DDS_AMP_MAX : dds_amp;
dds_set_phase_acc_amp(c_p->dds_amp);
}
else if (strncmp(data, "freq:", 5) == 0)
{
uint32_t freq = (uint32_t)atoi(data + 5);
c_p->dds_ftw = dds_freq_hz_to_ftw(freq);
dds_set_phase_acc_ftw((uint32_t)c_p->dds_ftw);
}
else if (strncmp(data, "amp:", 4) == 0)
{
uint32_t amp_percent = (uint32_t)atoi(data + 4);
amp_percent = amp_percent > 100U ? 100U : amp_percent;
c_p->dds_amp = (amp_percent * DDS_AMP_MAX) / 100U;
dds_set_phase_acc_amp(c_p->dds_amp);
}
else if (strncmp(data, "curve_offset:", 13) == 0)
{
c_p->soft_start.curve_offset = atoi(data + 13);
}
else if (strncmp(data, "amp+freq:", 9) == 0)
{
uint32_t freq = 0;
uint32_t amp_percent = 0;
if (sscanf(data + 9, "%lu %lu", &amp_percent, &freq) == 2)
{
amp_percent = amp_percent > 100U ? 100U : amp_percent;
c_p->dds_amp = (amp_percent * DDS_AMP_MAX) / 100U;
c_p->dds_ftw = dds_freq_hz_to_ftw(freq);
dds_set_phase_acc_amp(c_p->dds_amp);
dds_set_phase_acc_ftw((uint32_t)c_p->dds_ftw);
}
}
else if (strncmp(data, "dds_amp+dds_ftw:", 16) == 0)
{
uint32_t dds_amp = 0;
int32_t dds_ftw = 0;
if (sscanf(data + 16, "%lu %ld", &dds_amp, &dds_ftw) == 2)
{
c_p->dds_ftw = dds_ftw;
c_p->dds_amp = dds_amp > DDS_AMP_MAX ? DDS_AMP_MAX : dds_amp;
dds_set_phase_acc_amp(c_p->dds_amp);
dds_set_phase_acc_ftw((uint32_t)c_p->dds_ftw);
}
}
else if (strncmp(data, "soft_start:", 11) == 0)
{
uint32_t ddsamp_first = 0;
int32_t ddsftw_first = 0;
int32_t ddsftw_goal = 0;
uint32_t soft_start_time = 0;
if (sscanf(data + 11, "%lu %ld %ld %lu", &ddsamp_first, &ddsftw_first, &ddsftw_goal, &soft_start_time) == 4)
{
c_p->soft_start.dds_amp_first = ddsamp_first > DDS_AMP_MAX ? DDS_AMP_MAX : ddsamp_first;
c_p->soft_start.dds_ftw_first = ddsftw_first < 0 ? 0 : ddsftw_first;
c_p->soft_start.dds_ftw_goal = ddsftw_goal < 0 ? 0 : ddsftw_goal;
c_p->soft_start.soft_start_time_ms = soft_start_time;
dds_set_phase_acc_amp(c_p->soft_start.dds_amp_first);
dds_set_phase_acc_ftw((uint32_t)c_p->soft_start.dds_ftw_first);
motor_ctrl_set_mode(MOTOR_MODE_SOFT_START);
motor_ctrl_set_amp_ftw_mode(AMP_FTW_FIXED_FIXED);
}
}
else if (strncmp(data, "notify_ms:", 10) == 0)
{
c_p->notify_time_ms = (uint32_t)atoi(data + 10);
}
else if (strncmp(data, "notify_type:", 12) == 0)
{
c_p->notify_type = (uint16_t)atoi(data + 12);
}
else if (strncmp(data, "dds_ftw++", 9) == 0 || strncmp(data, "dds_ftw--", 9) == 0)
{
int32_t dftw = 0;
dds_get_ftw_amp_setting(&dftw, NULL);
dftw += (data[8] == '+') ? 1 : -1;
c_p->dds_ftw = dftw < 0 ? 0 : dftw;
dds_set_phase_acc_ftw((uint32_t)c_p->dds_ftw);
}
else if (strncmp(data, "dds_amp++", 9) == 0 || strncmp(data, "dds_amp--", 9) == 0)
{
uint32_t damp = 0;
dds_get_ftw_amp_setting(NULL, &damp);
if (data[8] == '-')
{
damp = damp == 0 ? 0 : damp - 1;
}
else
{
damp += 1;
}
c_p->dds_amp = damp > DDS_AMP_MAX ? DDS_AMP_MAX : damp;
dds_set_phase_acc_amp(c_p->dds_amp);
}
else if (strncmp(data, "vf_control_fb_enable:", 21) == 0)
{
c_p->vf_ctrl_fb_enabled = atoi(data + 21) > 0;
}
else if (strncmp(data, "fw_ver", 6) == 0)
{
uart_send_msg("FW_VER_PEC930_%s\r\n", FW_VERSION);
}
else if (strncmp(data, "help", 4) == 0)
{
static const char *help_lines[] = {
"Available commands:\r\n",
" start - Start motor\r\n",
" stop - Stop motor\r\n",
" freq:<val> - Set frequency Hz\r\n",
" amp:<val> - Set amplitude % (0-100)\r\n",
" amp+freq:<val> <val> - Set amplitude % and freq Hz\r\n",
" dds_ftw:<val> - Set dds_ftw\r\n",
" dds_ftw++ - Increment dds_ftw\r\n",
" dds_ftw-- - Decrement dds_ftw\r\n",
" dds_amp:<val> - Set dds_amp\r\n",
" dds_amp++ - Increment dds_amp\r\n",
" dds_amp-- - Decrement dds_amp\r\n",
" dds_amp+dds_ftw:<val> <val> - Set dds_amp and dds_ftw\r\n",
" soft_start:<amp> <ftw_start> <ftw_goal> <time_ms>\r\n",
" curve_offset:<val> - Set VF curve offset\r\n",
" vf_control_fb_enable:<val> - Enable/disable VF feedback\r\n",
" notify_ms:<val> - Set notify rate in ms\r\n",
" notify_type:<val> - Set notify type (0-3)\r\n",
" fw_ver - Show firmware version\r\n",
" help - Show this help\r\n",
};
for (uint32_t i = 0; i < (sizeof(help_lines) / sizeof(help_lines[0])); i++)
{
uart_send_msg("%s", help_lines[i]);
}
}
else
{
uart_send_msg("Unknown command. Type 'help' for available commands.\r\n");
}
uart_clear_rx_frame();
}
//=============================================================================
// Public Function Definition
//=============================================================================
int main(void)
{
sysclk_init();
test_pin_init();
app_init();
while (1)
{
app_task();
}
return 0;
}
sysclk_init();
test_pin_init();
epwm_init();
uart_init();
adc_drv_init();
motor_ctrl_init_cmd_param(&g_cmd_param);
motor_ctrl_apply_default_settings(&g_cmd_param);
app_stop_motor();
uart_send_msg("pec930 motor app ready\r\n");
while (1)
{
uint32_t pending_ticks = epwm_take_24khz_ticks();
while (pending_ticks-- > 0U)
{
dds_tim_period_elapsed();
}
handle_cmd_task();
if (g_motor_running)
{
motor_ctrl_update_task(&g_cmd_param);
print_motor_data_task(&g_cmd_param);
}
}
return 0;
}
+6 -6
View File
@@ -4,13 +4,13 @@
struct vf_control_formula_t g_vf_control_formulas[2] = {
[VF_CTRL_FORMULA_STABLE] = {
.slope = VF_SLOPE_X10000,
.offset = (int32_t)(DDS_AMP_MAX * VF_OFFSET_STABLE_PCT),
},
.slope = VF_SLOPE_X10000,
.offset = (int32_t)(DDS_AMP_MAX * VF_OFFSET_STABLE_PCT),
},
[VF_CTRL_FORMULA_MIN] = {
.slope = VF_SLOPE_X10000,
.offset = VF_OFFSET_MIN,
},
.slope = VF_SLOPE_X10000,
.offset = VF_OFFSET_MIN,
},
};
static enum amp_ftw_control_mode_e g_amp_ftw_control_mode = AMP_FTW_FIXED_FIXED;