使用了 Timer PWM 和 PWM 模块产生 250KHZ 的方波, 用示波器测试,发现 PWM 模块方波频率很准, 但是Timer PWM 产生的方波在 249.8~250.2 KHZ 之间跳动,请问这是什么问题?
Susan Yang:
请问您timer与PWM模块的时钟源是什么?若是可以的话,请给出配置代码,谢谢
user5228509:
回复 Susan Yang:
uint32_t g_cpuFrequency = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN |SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
//timer 方波ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);ROM_GPIOPinConfigure(GPIO_PD3_T1CCP1);
ROM_GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_3);ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PWM);ROM_TimerLoadSet(TIMER1_BASE, TIMER_B, 480);ROM_TimerMatchSet(TIMER1_BASE, TIMER_B,ROM_TimerLoadGet(TIMER1_BASE, TIMER_B) / 2);ROM_TimerEnable(TIMER1_BASE, TIMER_B);
//PWM 方波
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
ROM_GPIOPinConfigure(GPIO_PF0_M0PWM0);ROM_GPIOPinConfigure(GPIO_PF2_M0PWM2);ROM_GPIOPinConfigure(GPIO_PK4_M0PWM6);
ROM_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_2);ROM_GPIOPinTypePWM(GPIO_PORTK_BASE, GPIO_PIN_4);
ROM_PWMClockSet(PWM0_BASE,PWM_SYSCLK_DIV_2);ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN |PWM_GEN_MODE_NO_SYNC);ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN |PWM_GEN_MODE_NO_SYNC);ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_3, PWM_GEN_MODE_UP_DOWN |PWM_GEN_MODE_NO_SYNC);
ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 240);// 120M/2/240= 250KROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, 240);ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_3, 480);ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,ROM_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) / 2);
ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2,ROM_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_1) / 2);
ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_6,ROM_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_3) / 2);
ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
ROM_PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, true);
ROM_PWMOutputState(PWM0_BASE, PWM_OUT_6_BIT, true);
Susan Yang:
回复 user5228509:
谢谢您的快速回复,我手边暂时没有这个板子,所以先将您的问题发给了国外的工程师测试。
请跟踪下面的回复
e2e.ti.com/…/926013