大家好、
我的同事和我 目前正在尝试使用 ePWM 作为 SOC 触发器以每秒1M 次采样的速度对信号进行采样(以分析信号的频谱)。 外部 OSC 频率为16M、我们使用 了示例 ADC_ex2_SoC_ePWM.c 中的函数 但我们发现它没有以我们希望的速度进行采样。
ePWM 初始化代码如下:
void initEPWM(void)
{
//
// Disable SOCA
//
EPWM_disableADCTrigger(EPWM1_BASE, EPWM_SOC_A);
EPWM_setClockPrescaler(EPWM1_BASE,
EPWM_CLOCK_DIVIDER_1,
EPWM_HSCLOCK_DIVIDER_1);
//
// Configure the SOC to occur on the first up-count event
//
EPWM_setADCTriggerSource(EPWM1_BASE, EPWM_SOC_A, EPWM_SOC_TBCTR_U_CMPA);
EPWM_setADCTriggerEventPrescale(EPWM1_BASE, EPWM_SOC_A, 1);
//
// Set the compare A value to 2048 and the period to 4096
//
EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_A, 0x01);// max 100Mhz
EPWM_setTimeBasePeriod(EPWM1_BASE, 0x200);
//
// Freeze the counter
//
EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_STOP_FREEZE);
}
时钟设置为:
#define DEVICE_OSCSRC_FREQ 16000000U
//
// Define to pass to SysCtl_setClock(). Will configure the clock as follows:
// PLLSYSCLK = 16MHz (XTAL_OSC) * 20 (IMULT) * 1 (FMULT) / 2 (PLLCLK_BY_2)
//
#define DEVICE_SETCLOCK_CFG (SYSCTL_OSCSRC_XTAL | SYSCTL_IMULT(20) | \
SYSCTL_FMULT_NONE | SYSCTL_SYSDIV(2) | \
SYSCTL_PLL_ENABLE)
//
// 192MHz SYSCLK frequency based on the above DEVICE_SETCLOCK_CFG. Update the
// code below if a different clock configuration is used!
//
#define DEVICE_SYSCLK_FREQ ((DEVICE_OSCSRC_FREQ * 20 * 1) / 2)
根据我对 ePWM 的了解、时钟和 HSCLOCK 的预分频器都为1。 我们仅使用 CPU1、 ePWM 应为16MHz x 20 x 1 / 2 = 192MHz。 ePWM 周期为200、因此采样频率应约为1MHz (192Mhz / 200)。 但是、我们切换了 adcA1ISR 中的输出引脚、并以372khz 的频率切换。 什么可能是错误的,为什么是372khz?
感谢您的回复!
此致