本帖最后由 punan2010 于 2023-3-23 19:24 编辑
根据lks32mc08x_demo_prj\4.ADC\ADC_MCPWM_Trigger示例程序:
#define MCU_MCLK (96000000LL) /* PWM模块运行主频 */
#define PWM_MCLK ((u32)MCU_MCLK) /* PWM模块运行主频 */
#define PWM_PRSC ((u8)0) /* PWM模块运行预分频器 */
#define PWM_FREQ ((u16)16000) /* PWM斩波频率 */
/* 电机控制PWM 周期计数器值 */
#define PWM_PERIOD ((u16) (PWM_MCLK / (u32)(2 * PWM_FREQ *(PWM_PRSC+1))))
/* PFC控制PWM 周期计数器值 */
#define PFC_PERIOD ((u16) (PWM_MCLK / (u32)(2 * PFC_FREQ *(PWM_PRSC+1))))
MCU、PWM模块运行主频为96MHz,PWM斩波频率为16KHz,电机控制PWM周期计数器值PWM_PERIOD = 96000000/(2*16000)=3000;
void MCPWM_init(void)
{
MCPWM_InitTypeDef MCPWM_InitStructure;
MCPWM_StructInit(&MCPWM_InitStructure);
MCPWM_InitStructure.CLK_DIV = PWM_PRSC; /* MCPWM时钟分频设置 */
MCPWM_InitStructure.MCLK_EN = ENABLE; /* 模块时钟开启 */
MCPWM_InitStructure.MCPWM_Cnt_EN = ENABLE; /* 主计数器开始计数使能开关 */
MCPWM_InitStructure.MCPWM_PERIOD = PWM_PERIOD; /* 计数周期设置即MCPWM输出周期*/
MCPWM_InitStructure.TriggerPoint0 = (u16)(10 - PWM_PERIOD); /* MCPWM_TMR0 ADC触发事件T0 设置 */
MCPWM_InitStructure.TriggerPoint1 = (u16)(1000 - PWM_PERIOD); /* MCPWM_TMR1 ADC触发事件T1 设置 */
MCPWM_InitStructure.TriggerPoint2 = (u16)(PWM_PERIOD - 1000); /* MCPWM_TMR0 ADC触发事件T0 设置 */
MCPWM_InitStructure.TriggerPoint3 = (u16)(PWM_PERIOD - 1); /* MCPWM_TMR1 ADC触发事件T1 设置 */
MCPWM_Init(&MCPWM_InitStructure);
}
MCPWM_InitStructure.TriggerPoint0 = 10 -3000 = -2990;
MCPWM_InitStructure.TriggerPoint1 = 1000 - 3000 = -2000;
MCPWM_InitStructure.TriggerPoint2 = 3000 - 1000 = 2000;
MCPWM_InitStructure.TriggerPoint3 = 3000 - 1 = 2999;
ADC使用1段触发模式
ADC_InitStructure.Trigger_Mode = ADC_1SEG_TRG; /*ADC采样1段模式*/
请问如何计算出ADC采样频率?
在ADC0中断处理函数中反转LED1电平,使用示波器量出LED1反转频率为304kHz。
void ADC0_IRQHandler(void)
{
Invers_GPIO(GPIO0,GPIO_Pin_6);
}
PWM波形频率为16KHz,ADC0中断处理函数调用的频率是304KHz*2=608Khz.
他们之间是什么关系?
|