TC275-11CCU6_PWM_Generation

基础知识

CCU6,Capture/Compare Unit 6捕获/比较单元,是一个专门用于电机控制而设计的16位捕获和比较单元。

CCU6包含多个定时器,将它们的计数值和参考值进行比较,来生成PWM信号。

定时器12(T12)配有三个比较器。通过同步它们,最多可以产生三个同步的PWM信号,这些信号可以是中心对齐的或边缘对齐的。

实验目标

使用CCU6产三个固定频率和不同占空比的中心对准脉冲宽调制(PWM)信号。

实验现象

使用三个示波器探头连到三各引脚。

可以观察到三个中心对齐的PWM信号,配置占空比,每个周期为50 us

三个频率为20 kHz和不同占空比(25%、50%和75%)的PWM信号。T12被配置为上下倒计时,这三个信号在中心对齐。

实验原理

一个图搞定

实验代码

禁用/初始化中断

在进行CCU6初始化时,第一步先禁用中断IfxCpu_disableInterrupts()

    boolean interruptState = IfxCpu_disableInterrupts();            /* Disable global interrupts                    */

这样可以避免还没有进行配置的外设抢占任务。

在初始化要结束的阶段别忘了重新启用中断:

    /* Restore interrupts to their initial state */
    IfxCpu_restoreInterrupts(interruptState);

CCU6的配置

先创建一个结构体IfxCcu6_TimerWithTrigger_Config,并使用IfxCcu6_TimerWithTrigger_initConfig()按默认配置进行初始化:

/* Timer configuration: timer used as counter */
IfxCcu6_TimerWithTrigger_Config timerConf;
IfxCcu6_TimerWithTrigger_initConfig(&timerConf, &MODULE_CCU60); /* Initialize the timer configuration with default values                               */

需要修改的参数有:

  • PWM信号的频率
  • 计数器模式,向上/向下

然后再次调用IfxCcu6_TimerWithTrigger_init()进行参数使能。

    /* User timer configuration */
    timerConf.base.frequency = PWM_FREQUENCY;                       /* Set the desired frequency for the PWM signal */
    timerConf.base.countDir = IfxStdIf_Timer_CountDir_upAndDown;    /* Configure the timer to count up and down, in
                                                                     * order to generate center-aligned PWM signals */
    /* Initialize the timer driver */
    IfxCcu6_TimerWithTrigger_init(&g_timer, &timerConf);

配置PWM的高低驱动程序

配置输出引脚和占空比,以及三个通道的比较模块。

首先也是配置一个结构体IfxCcu6_PwmHl_Config,使用IfxCcu6_PwmHl_initConfig()进行默认参数的初始化:

    /* PWM High/Low driver configuration */
    IfxCcu6_PwmHl_Config pwmHlConf;
    IfxCcu6_PwmHl_initConfig(&pwmHlConf);                           /* Initialize the PwmHl configuration with
                                                                     * default values                               */

指定使用的通道数量,然后再次进行初始化:

    /* User PWM High/Low driver configuration */
    pwmHlConf.timer = &g_timer;                                     /* Use the already configured timer             */
    pwmHlConf.base.channelCount = NUMBER_OF_CHANNELS;               /* Configure the driver to use use all three
                                                                     * compare modules available in T12             */
    /* Assign output pins */
    pwmHlConf.cc0 = &IfxCcu60_CC60_P02_0_OUT;
    pwmHlConf.cc1 = &IfxCcu60_CC61_P02_7_OUT;
    pwmHlConf.cc2 = &IfxCcu60_CC62_P02_4_OUT;
    pwmHlConf.cout0 = &IfxCcu60_COUT60_P02_1_OUT;
    pwmHlConf.cout1 = &IfxCcu60_COUT61_P02_3_OUT;
    pwmHlConf.cout2 = &IfxCcu60_COUT62_P02_5_OUT;

    /* Initialize the PwmHl driver */
    IfxCcu6_PwmHl_init(&g_driver, &pwmHlConf);

选择对齐方式IfxCcu6_PwmHl_setMode():

    /* Instruct the driver to generate center aligned PWM signals */
    IfxCcu6_PwmHl_setMode(&g_driver, Ifx_Pwm_Mode_centerAligned);

设置三个通道的占空比,并更新数据

    /* Instruct the driver to generate center aligned PWM signals */
    IfxCcu6_PwmHl_setMode(&g_driver, Ifx_Pwm_Mode_centerAligned);

    /* Set the duty cycles for the three channels */
    Ifx_TimerValue cmpValues[NUMBER_OF_CHANNELS];
    cmpValues[0] = CHANNEL1_COMPARE_VALUE;                          /* Set the compare value for channel 1          */
    cmpValues[1] = CHANNEL2_COMPARE_VALUE;                          /* Set the compare value for channel 2          */
    cmpValues[2] = CHANNEL3_COMPARE_VALUE;                          /* Set the compare value for channel 3          */

    g_driver.update(&g_driver, cmpValues);                          /* Apply the compare values                     */

最后RUN:

    IfxCcu6_TimerWithTrigger_run(&g_timer);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值