feat: 1. add uart RX decoder
2. enabled pwm on/of control via uart cmd 3. known Issue: observed unexpected spikes on the pwm waveform
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
#ifndef INC_INIT_H_
|
||||
#define INC_INIT_H_
|
||||
|
||||
#include "main.h"
|
||||
|
||||
void SYS_Config();
|
||||
void gpio_config();
|
||||
void opa_config();
|
||||
|
||||
@@ -14,35 +14,39 @@
|
||||
#define __isr_H_wuraIpBA_lTJm_HvJw_sNDo_uEd5JnucTReY__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "main.h"
|
||||
//=============================================================================
|
||||
// Constant Definition
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
// Constant Definition
|
||||
//=============================================================================
|
||||
|
||||
//=============================================================================
|
||||
// Macro Definition
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
// Macro Definition
|
||||
//=============================================================================
|
||||
|
||||
//=============================================================================
|
||||
// Structure Definition
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
// Structure Definition
|
||||
//=============================================================================
|
||||
|
||||
//=============================================================================
|
||||
// Global Data Definition
|
||||
//=============================================================================
|
||||
extern volatile bool flag_24Khz_timer;
|
||||
//=============================================================================
|
||||
// Private Function Definition
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
// Global Data Definition
|
||||
//=============================================================================
|
||||
extern volatile bool flag_24Khz_timer;
|
||||
extern volatile bool stringComplete;
|
||||
extern volatile char rxBuffer[128];
|
||||
//=============================================================================
|
||||
// Private Function Definition
|
||||
//=============================================================================
|
||||
|
||||
//=============================================================================
|
||||
// Public Function Definition
|
||||
//=============================================================================
|
||||
void isr_epwm_handle(void);
|
||||
void isr_adc_handle(void);
|
||||
//=============================================================================
|
||||
// Public Function Definition
|
||||
//=============================================================================
|
||||
void isr_epwm_handle(void);
|
||||
void isr_adc_handle(void);
|
||||
void isr_uart0_handle(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -14,35 +14,35 @@
|
||||
#define __main_H_wxBnwdPw_lq7D_H4I5_sHPp_uXof15pFLp4V__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
#include "hal_device.h"
|
||||
#include "syslog.h"
|
||||
//=============================================================================
|
||||
// Constant Definition
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
// Constant Definition
|
||||
//=============================================================================
|
||||
|
||||
//=============================================================================
|
||||
// Macro Definition
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
// Macro Definition
|
||||
//=============================================================================
|
||||
|
||||
//=============================================================================
|
||||
// Structure Definition
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
// Structure Definition
|
||||
//=============================================================================
|
||||
|
||||
//=============================================================================
|
||||
// Global Data Definition
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
// Global Data Definition
|
||||
//=============================================================================
|
||||
|
||||
//=============================================================================
|
||||
// Private Function Definition
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
// Private Function Definition
|
||||
//=============================================================================
|
||||
|
||||
//=============================================================================
|
||||
// Public Function Definition
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
// Public Function Definition
|
||||
//=============================================================================
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -4,32 +4,32 @@
|
||||
* Created on: 2025年8月18日
|
||||
* Author: jim_liao
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include "isr.h"
|
||||
#include "init.h"
|
||||
#include "hal_device.h"
|
||||
#include "isr.h"
|
||||
#include "main.h"
|
||||
|
||||
|
||||
//=============================================================================
|
||||
// Constant Definition
|
||||
//=============================================================================
|
||||
#define CONFIG_OPA_PGA_GAIN OPAMP_PGAGain_5
|
||||
#define CONFIG_OPA_PGA_GAIN OPAMP_PGAGain_5
|
||||
|
||||
unsigned long ADC0Sum = 0;
|
||||
unsigned char k;
|
||||
|
||||
#define HIRC_Freq 60000000 //Hz
|
||||
#define CurrentLoopIsrFreq 24000 //Hz
|
||||
#define PWM_PERIOD HIRC_Freq/CurrentLoopIsrFreq
|
||||
#define DEAD_TIME 200 //ns
|
||||
#define DEAD_TIME_VALUE DEAD_TIME*0.06
|
||||
#define HIRC_Freq 60000000 // Hz
|
||||
#define CurrentLoopIsrFreq 24000 // Hz
|
||||
#define PWM_PERIOD HIRC_Freq / CurrentLoopIsrFreq
|
||||
#define DEAD_TIME 200 // ns
|
||||
#define DEAD_TIME_VALUE DEAD_TIME * 0.06
|
||||
//=============================================================================
|
||||
// Public Function Definition
|
||||
//=============================================================================
|
||||
void SYS_Config()
|
||||
{
|
||||
SYSCFG_ClkInitTypeDef SysClkInit = {0};
|
||||
SysClkInit.ClkSource = SYSCFG_ClkSrc_HSI;
|
||||
SYSCFG_ClkInitTypeDef SysClkInit = { 0 };
|
||||
SysClkInit.ClkSource = SYSCFG_ClkSrc_HSI;
|
||||
SYSCFG_SysClkConfig(&SysClkInit);
|
||||
sys_config_systick(SYS_TICK_1_MS);
|
||||
|
||||
@@ -44,54 +44,54 @@ void SYS_Config()
|
||||
|
||||
void gpio_config()
|
||||
{
|
||||
//-----------------//
|
||||
// PWM
|
||||
//-----------------//
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
//-----------------//
|
||||
// PWM
|
||||
//-----------------//
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_00 | GPIO_Pin_01 | GPIO_Pin_02 | \
|
||||
GPIO_Pin_03 | GPIO_Pin_04 | GPIO_Pin_05;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStruct.GPIO_AF_Mode = GPIO_AF_6;
|
||||
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_00 | GPIO_Pin_01 | GPIO_Pin_02
|
||||
| GPIO_Pin_03 | GPIO_Pin_04 | GPIO_Pin_05;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStruct.GPIO_AF_Mode = GPIO_AF_6;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
//-----------------//
|
||||
// UART
|
||||
// PB3:TX PB5:RX
|
||||
//-----------------//
|
||||
GPIO_InitTypeDef GPIOA_InitUart;
|
||||
GPIOA_InitUart.GPIO_Pin = GPIO_Pin_03;
|
||||
GPIOA_InitUart.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIOA_InitUart.GPIO_AF_Mode = GPIO_AF_1;
|
||||
//-----------------//
|
||||
// UART
|
||||
// PB3:TX PB5:RX
|
||||
//-----------------//
|
||||
GPIO_InitTypeDef GPIOA_InitUart;
|
||||
GPIOA_InitUart.GPIO_Pin = GPIO_Pin_03;
|
||||
GPIOA_InitUart.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIOA_InitUart.GPIO_AF_Mode = GPIO_AF_1;
|
||||
GPIO_Init(GPIOB, &GPIOA_InitUart);
|
||||
|
||||
GPIO_InitTypeDef GPIOB_InitUart;
|
||||
GPIOB_InitUart.GPIO_Pin = GPIO_Pin_05;
|
||||
GPIOB_InitUart.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIOB_InitUart.GPIO_AF_Mode = GPIO_AF_1;
|
||||
GPIO_InitTypeDef GPIOB_InitUart;
|
||||
GPIOB_InitUart.GPIO_Pin = GPIO_Pin_05;
|
||||
GPIOB_InitUart.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIOB_InitUart.GPIO_AF_Mode = GPIO_AF_1;
|
||||
GPIO_Init(GPIOB, &GPIOB_InitUart);
|
||||
//-----------------//
|
||||
// ADC
|
||||
// PA12/13/14:OVP/OTP/CMD
|
||||
//-----------------//
|
||||
GPIO_InitTypeDef GPIO_InitADC;
|
||||
GPIO_InitADC.GPIO_Pin = GPIO_Pin_06 | GPIO_Pin_12;
|
||||
GPIO_InitADC.GPIO_Mode = GPIO_Mode_ANAL;
|
||||
//-----------------//
|
||||
// ADC
|
||||
// PA12/13/14:OVP/OTP/CMD
|
||||
//-----------------//
|
||||
GPIO_InitTypeDef GPIO_InitADC;
|
||||
GPIO_InitADC.GPIO_Pin = GPIO_Pin_06 | GPIO_Pin_12;
|
||||
GPIO_InitADC.GPIO_Mode = GPIO_Mode_ANAL;
|
||||
GPIO_Init(GPIOA, &GPIO_InitADC);
|
||||
#if 1
|
||||
//-----------------//
|
||||
// test
|
||||
//-----------------//
|
||||
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_14;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_Init(GPIOA , &GPIO_InitStruct);
|
||||
//-----------------//
|
||||
// test
|
||||
//-----------------//
|
||||
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_14;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
#endif
|
||||
}
|
||||
|
||||
void opa_config(void)
|
||||
{
|
||||
OPAMP_InitTypeDef opa_init = {0};
|
||||
OPAMP_InitTypeDef opa_init = { 0 };
|
||||
|
||||
opa_init.OPAMP_VinP = OPAMP_VinP_IO;
|
||||
opa_init.OPAMP_VinM = OPAMP_VinM_GND;
|
||||
@@ -104,28 +104,27 @@ void opa_config(void)
|
||||
OPAMP_Enable(OPAMP1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void adc_config(void)
|
||||
{
|
||||
|
||||
ADC_InitTypeDef init = {0};
|
||||
ADC_InitTypeDef init = { 0 };
|
||||
ADC_StructInit(&init);
|
||||
|
||||
//-----------------//
|
||||
// set
|
||||
//-----------------//
|
||||
ADC_InitTypeDef init1 = {0};
|
||||
//-----------------//
|
||||
// set
|
||||
//-----------------//
|
||||
ADC_InitTypeDef init1 = { 0 };
|
||||
ADC_StructInit(&init1);
|
||||
init1.SelChannels = ADC_Channel_06 |ADC_Channel_08;
|
||||
init1.ClkPrescaler = ADC_ClkDiv_4;
|
||||
init1.DataAlign = ADC_DataAlign_Right;
|
||||
init1.Mode = ADC_Mode_Scan;
|
||||
init1.SelChannels = ADC_Channel_06 | ADC_Channel_08;
|
||||
init1.ClkPrescaler = ADC_ClkDiv_4;
|
||||
init1.DataAlign = ADC_DataAlign_Right;
|
||||
init1.Mode = ADC_Mode_Scan;
|
||||
ADC_Init(ADC0, &init1);
|
||||
|
||||
ADC_ExtTrigConfig(ADC0,ADC_ExtTrigSource_EPWM_CCR4_UP,ADC_ExtTrigMode_Enable);
|
||||
ADC_ExtTrigConfig(ADC0,ADC_ExtTrigSource_EPWM_CCDR4_UP,ADC_ExtTrigMode_Enable);
|
||||
|
||||
ADC_ExtTrigConfig(ADC0, ADC_ExtTrigSource_EPWM_CCR4_UP,
|
||||
ADC_ExtTrigMode_Enable);
|
||||
ADC_ExtTrigConfig(ADC0, ADC_ExtTrigSource_EPWM_CCDR4_UP,
|
||||
ADC_ExtTrigMode_Enable);
|
||||
|
||||
#if 0
|
||||
{ /* Configure TIM interrupts */
|
||||
@@ -140,18 +139,19 @@ void adc_config(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void pwm_config()
|
||||
{
|
||||
TIM_OCInitTypeDef TIM_OCInitStruct;
|
||||
TIM_OCInitTypeDef TIM_OCInitStruct;
|
||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
|
||||
|
||||
{ /* Configure TIM interrupts */
|
||||
sys_irq_attr_t irq_attr = { .disable_vector = false, };
|
||||
{ /* Configure TIM interrupts */
|
||||
sys_irq_attr_t irq_attr = {
|
||||
.disable_vector = false,
|
||||
};
|
||||
|
||||
irq_attr.trig_mode = SYS_IRQ_TRIGGER_LEVEL;
|
||||
irq_attr.level = SYS_IRQ_LEVEL_H;
|
||||
irq_attr.priority = SYS_IRQ_PRIORITY_MIDDEN;
|
||||
irq_attr.trig_mode = SYS_IRQ_TRIGGER_LEVEL;
|
||||
irq_attr.level = SYS_IRQ_LEVEL_H;
|
||||
irq_attr.priority = SYS_IRQ_PRIORITY_MIDDEN;
|
||||
sys_register_IRQ(EPWM_IRQn, isr_epwm_handle, &irq_attr);
|
||||
}
|
||||
|
||||
@@ -160,23 +160,23 @@ void pwm_config()
|
||||
TIM_TimeBaseStructInit(&TIM_TimeBaseInitStruct);
|
||||
TIM_TimeBaseInitStruct.TIM_Prescaler = 0;
|
||||
TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseInitStruct.TIM_Period = PWM_PERIOD-1;
|
||||
TIM_TimeBaseInitStruct.TIM_Period = PWM_PERIOD - 1;
|
||||
TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_Div1;
|
||||
TIM_TimeBaseInitStruct.TIM_RepetitionCounter = 0;
|
||||
TIM_TimeBaseInit(EPWM, &TIM_TimeBaseInitStruct);
|
||||
|
||||
TIM_ARRPreloadConfig(EPWM,ENABLE);
|
||||
TIM_ARRPreloadConfig(EPWM, ENABLE);
|
||||
|
||||
TIM_OCStructInit(&TIM_OCInitStruct);
|
||||
TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1;
|
||||
TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Disable;
|
||||
TIM_OCInitStruct.TIM_Pulse = 0;
|
||||
TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_High;
|
||||
TIM_OCInitStruct.TIM_OCIdleState = TIM_OCIdleState_Reset;
|
||||
TIM_OCInitStruct.TIM_Pulse = 1;
|
||||
TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1;
|
||||
TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Disable;
|
||||
TIM_OCInitStruct.TIM_Pulse = 0;
|
||||
TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_High;
|
||||
TIM_OCInitStruct.TIM_OCIdleState = TIM_OCIdleState_Reset;
|
||||
TIM_OCInitStruct.TIM_Pulse = 1;
|
||||
|
||||
TIM_OCInitStruct.TIM_OutputNState = TIM_OutputNState_Disable;
|
||||
TIM_OCInitStruct.TIM_OCNPolarity = TIM_OCPolarity_High;
|
||||
TIM_OCInitStruct.TIM_OutputNState = TIM_OutputNState_Disable;
|
||||
TIM_OCInitStruct.TIM_OCNPolarity = TIM_OCPolarity_High;
|
||||
TIM_OC1Init(EPWM, &TIM_OCInitStruct);
|
||||
|
||||
TIM_OCInitStruct.TIM_Pulse = 1;
|
||||
@@ -185,8 +185,8 @@ void pwm_config()
|
||||
TIM_OCInitStruct.TIM_Pulse = 1;
|
||||
TIM_OC3Init(EPWM, &TIM_OCInitStruct);
|
||||
|
||||
{ /* Automatic Output enable, Break, dead time and lock configuration */
|
||||
TIM_BDTRInitTypeDef bdtr_init = {0};
|
||||
{ /* Automatic Output enable, Break, dead time and lock configuration */
|
||||
TIM_BDTRInitTypeDef bdtr_init = { 0 };
|
||||
bdtr_init.TIM_LOCKLevel = TIM_LockLevel_OFF;
|
||||
bdtr_init.TIM_DeadTime = DEAD_TIME_VALUE;
|
||||
|
||||
@@ -201,8 +201,7 @@ void pwm_config()
|
||||
EPWM->CCMR2_OUTPUT_b.OC3PE = 1;
|
||||
|
||||
TIM_Cmd(EPWM, ENABLE);
|
||||
TIM_CtrlPWMOutputs(EPWM,ENABLE);
|
||||
|
||||
TIM_CtrlPWMOutputs(EPWM, ENABLE);
|
||||
}
|
||||
|
||||
void pwm_set_duty(uint16_t ch1_val, uint16_t ch2_val, uint16_t ch3_val)
|
||||
@@ -214,28 +213,46 @@ void pwm_set_duty(uint16_t ch1_val, uint16_t ch2_val, uint16_t ch3_val)
|
||||
}
|
||||
void pwm_enable()
|
||||
{
|
||||
REG_SET_BITS(EPWM->CCER, TIM_CCER_CC1E_Msk | TIM_CCER_CC1NE_Msk | \
|
||||
TIM_CCER_CC2E_Msk | TIM_CCER_CC2NE_Msk | \
|
||||
TIM_CCER_CC3E_Msk | TIM_CCER_CC3NE_Msk);
|
||||
REG_SET_BITS(EPWM->CCER, TIM_CCER_CC1E_Msk | TIM_CCER_CC1NE_Msk
|
||||
| TIM_CCER_CC2E_Msk | TIM_CCER_CC2NE_Msk
|
||||
| TIM_CCER_CC3E_Msk | TIM_CCER_CC3NE_Msk);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void pwm_disable()
|
||||
{
|
||||
REG_CLR_BITS(EPWM->CCER, TIM_CCER_CC1E_Msk | TIM_CCER_CC1NE_Msk
|
||||
| TIM_CCER_CC2E_Msk | TIM_CCER_CC2NE_Msk
|
||||
| TIM_CCER_CC3E_Msk | TIM_CCER_CC3NE_Msk);
|
||||
return;
|
||||
}
|
||||
|
||||
void uart_config()
|
||||
{
|
||||
UART_InitTypeDef uart_init = {0};
|
||||
uart_init.BaudRate = 115200;
|
||||
uart_init.WordLength = UART_WordLength_8b;
|
||||
uart_init.StopBits = UART_StopBits_1;
|
||||
uart_init.Parity = UART_Parity_No;
|
||||
uart_init.Mode = UART_Mode_TxRx;
|
||||
UART_InitTypeDef uart_init = { 0 };
|
||||
uart_init.BaudRate = 115200;
|
||||
uart_init.WordLength = UART_WordLength_8b;
|
||||
uart_init.StopBits = UART_StopBits_1;
|
||||
uart_init.Parity = UART_Parity_No;
|
||||
uart_init.Mode = UART_Mode_TxRx;
|
||||
UART_Init(UART0, &uart_init);
|
||||
UART_Start(UART0);
|
||||
|
||||
UART_ITConfig(UART0, UART_FLAG_RXNE, ENABLE);
|
||||
{ /* Configure TIM interrupts */
|
||||
sys_irq_attr_t irq_attr = {
|
||||
.disable_vector = false,
|
||||
};
|
||||
|
||||
irq_attr.trig_mode = SYS_IRQ_TRIGGER_LEVEL;
|
||||
irq_attr.level = SYS_IRQ_LEVEL_H;
|
||||
irq_attr.priority = SYS_IRQ_PRIORITY_MIDDEN;
|
||||
sys_register_IRQ(UART0_IRQn, isr_uart0_handle, &irq_attr);
|
||||
}
|
||||
}
|
||||
|
||||
void UART_Send_Wait(UART_Type *pHUart, uint16_t value)
|
||||
{
|
||||
UART_SendData(pHUart,value);
|
||||
UART_SendData(pHUart, value);
|
||||
UART_WaitTxFifoEmpty(pHUart);
|
||||
}
|
||||
|
||||
@@ -10,9 +10,10 @@
|
||||
* @description
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include "isr.h"
|
||||
#include "init.h"
|
||||
#include "main.h"
|
||||
|
||||
|
||||
//=============================================================================
|
||||
// Constant Definition
|
||||
@@ -21,12 +22,16 @@
|
||||
//=============================================================================
|
||||
// Macro Definition
|
||||
//=============================================================================
|
||||
|
||||
#define RX_BUFFER_SIZE 128
|
||||
//=============================================================================
|
||||
// Global Data Definition
|
||||
//=============================================================================
|
||||
long ADC_DATA[10];
|
||||
volatile bool flag_24Khz_timer = false;
|
||||
|
||||
volatile char rxBuffer[RX_BUFFER_SIZE];
|
||||
volatile bool stringComplete = false;
|
||||
volatile uint16_t rxIndex = 0;
|
||||
//=============================================================================
|
||||
// Private Function Definition
|
||||
//=============================================================================
|
||||
@@ -37,17 +42,34 @@ volatile bool flag_24Khz_timer = false;
|
||||
__INTERRUPT void isr_epwm_handle(void)
|
||||
{
|
||||
|
||||
if ((EPWM->SR & 0x10000) == 0x10000)
|
||||
if ((EPWM->SR & 0x10000) == 0x10000)
|
||||
{
|
||||
flag_24Khz_timer = true;
|
||||
ADC_DATA[0] = ADC0->DAT6_b.DATA;
|
||||
ADC_DATA[1] = ADC0->DAT8_b.DATA;
|
||||
TIM_ClearITPendingBit(EPWM, 0x10000); // clear OVIF
|
||||
|
||||
GPIO_TogglePin(GPIOA, GPIO_Pin_14);
|
||||
flag_24Khz_timer = true;
|
||||
ADC_DATA[0] = ADC0->DAT6_b.DATA;
|
||||
ADC_DATA[1] = ADC0->DAT8_b.DATA;
|
||||
TIM_ClearITPendingBit(EPWM, 0x10000); // clear OVIF
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
__INTERRUPT void isr_uart0_handle(void)
|
||||
{
|
||||
if (UART_GetITStatus(UART0, UART_FLAG_RXNE) == 1)
|
||||
{
|
||||
char receivedChar = (char)UART_ReceiveData(UART0);
|
||||
|
||||
|
||||
if (receivedChar == '\n' || receivedChar == '\r')
|
||||
{
|
||||
if (rxIndex > 0)
|
||||
{
|
||||
rxBuffer[rxIndex] = '\0';
|
||||
stringComplete = true;
|
||||
rxIndex = 0;
|
||||
msg("Received: %s\n", rxBuffer);
|
||||
}
|
||||
}
|
||||
else if (rxIndex < RX_BUFFER_SIZE - 1)
|
||||
{
|
||||
rxBuffer[rxIndex++] = receivedChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,14 @@
|
||||
* @license
|
||||
* @description
|
||||
*/
|
||||
#include <string.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "hal_gpio.h"
|
||||
#include "hal_tim.h"
|
||||
#include "init.h"
|
||||
#include "isr.h"
|
||||
#include "main.h"
|
||||
|
||||
|
||||
//=============================================================================
|
||||
// Constant Definition
|
||||
@@ -56,6 +58,41 @@ void uvw_set_duty(uint16_t base_idx)
|
||||
EPWM->CCR3 = pwm_table[iC];
|
||||
}
|
||||
|
||||
static void cmd_parser(char *data, uint32_t len)
|
||||
{
|
||||
char cmd_reply[64] = { 0 };
|
||||
|
||||
// echo back received command
|
||||
sprintf(cmd_reply, "Received command: %s\r\n", data);
|
||||
msg("%s", cmd_reply);
|
||||
|
||||
// parse commands
|
||||
if (strncmp(data, "help", 4) == 0)
|
||||
{
|
||||
msg("Available commands:\r\n");
|
||||
msg(" help - Show this help message\r\n");
|
||||
msg(" fw_ver - Show firmware version\r\n");
|
||||
}
|
||||
else if (strncmp(data, "fw_ver", 6) == 0)
|
||||
{
|
||||
msg("FW_VER_1.0.0_20260320\r\n");
|
||||
}
|
||||
else if (strncmp(data, "pwm_enable", 10) == 0)
|
||||
{
|
||||
pwm_enable();
|
||||
msg("PWM enabled.\r\n");
|
||||
}
|
||||
else if (strncmp(data, "pwm_disable", 11) == 0)
|
||||
{
|
||||
pwm_disable();
|
||||
msg("PWM disabled.\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
msg("Unknown command. Type 'help' for available commands.\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint16_t base_idx = 0;
|
||||
@@ -68,7 +105,13 @@ int main(void)
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (sys_get_tick() - timer >= 1000)
|
||||
if (stringComplete)
|
||||
{
|
||||
cmd_parser((char *)rxBuffer, strlen((char *)rxBuffer));
|
||||
stringComplete = false;
|
||||
}
|
||||
|
||||
if (sys_get_tick() - timer >= 1)
|
||||
{
|
||||
msg("%d tick\n", sys_get_tick());
|
||||
timer = sys_get_tick();
|
||||
|
||||
Reference in New Issue
Block a user