[example] dds
feat: 1. updated uvw duty cycle every 41.6us (24KHz) 2. EPWM->CCMRn_OUTPUT_b.OCnPE=1
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Wisetop. All Rights Reserved.
|
||||
*/
|
||||
/** @file main.c
|
||||
*
|
||||
* @author Roy Luo
|
||||
* @version 0.1
|
||||
* @date 2026/03/20
|
||||
* @license
|
||||
* @description
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include "hal_gpio.h"
|
||||
#include "hal_tim.h"
|
||||
#include "init.h"
|
||||
#include "isr.h"
|
||||
//=============================================================================
|
||||
// Constant Definition
|
||||
//=============================================================================
|
||||
|
||||
//=============================================================================
|
||||
// Macro Definition
|
||||
//=============================================================================
|
||||
#define PWM_TABLE_SIZE 64
|
||||
//=============================================================================
|
||||
// Structure Definition
|
||||
//=============================================================================
|
||||
|
||||
//=============================================================================
|
||||
// Global Data Definition
|
||||
//=============================================================================
|
||||
const uint16_t pwm_table[PWM_TABLE_SIZE] = { 1250, 1372, 1493, 1612, 1728, 1839, 1944, 2042, 2133, 2216, 2289,
|
||||
2352, 2404, 2446, 2475, 2493, 2499, 2493, 2475, 2446, 2404, 2352,
|
||||
2289, 2216, 2133, 2042, 1944, 1839, 1728, 1612, 1493, 1372, 1250,
|
||||
1127, 1006, 887, 771, 660, 555, 457, 366, 283, 210, 147,
|
||||
95, 53, 24, 6, 0, 6, 24, 53, 95, 147, 210,
|
||||
283, 366, 457, 555, 660, 771, 887, 1006, 1127 };
|
||||
//=============================================================================
|
||||
// Private Function Definition
|
||||
//=============================================================================
|
||||
|
||||
//=============================================================================
|
||||
// Public Function Definition
|
||||
//=============================================================================
|
||||
void uvw_set_duty(uint16_t base_idx)
|
||||
{
|
||||
uint16_t iA = base_idx;
|
||||
uint16_t iB = (base_idx + PWM_TABLE_SIZE / 3) % PWM_TABLE_SIZE;
|
||||
uint16_t iC = (base_idx + 2 * PWM_TABLE_SIZE / 3) % PWM_TABLE_SIZE;
|
||||
|
||||
EPWM->CCR1 = pwm_table[iA];
|
||||
EPWM->CCR2 = pwm_table[iB];
|
||||
EPWM->CCR3 = pwm_table[iC];
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
static uint16_t base_idx = 0;
|
||||
uint32_t timer = sys_get_tick();
|
||||
|
||||
SYS_Config();
|
||||
uvw_set_duty(base_idx);
|
||||
pwm_enable();
|
||||
|
||||
while (1)
|
||||
{
|
||||
#if 0
|
||||
if (sys_get_tick() - timer >= 1)
|
||||
{
|
||||
GPIO_TogglePin(GPIOA, GPIO_Pin_14);
|
||||
base_idx = (base_idx + 1) % PWM_TABLE_SIZE;
|
||||
uvw_set_duty(base_idx);
|
||||
timer = sys_get_tick();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
if (flag_24Khz_timer)
|
||||
{
|
||||
GPIO_TogglePin(GPIOA, GPIO_Pin_14);
|
||||
base_idx = (base_idx + 1) % PWM_TABLE_SIZE;
|
||||
uvw_set_duty(base_idx);
|
||||
flag_24Khz_timer = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user