Funpack第二季第二期-KIT_AURIX_TC275_LITE-呼吸灯效果展示
本片文章分享我在Funpack第二季第二期活动中使用KIT_AURIX_TC275_LITE开发板进行呼吸灯开发的流程及效果展示
标签
嵌入式系统
Funpack第二季第二期
KIT_AURIX_TC275_LITE
反正都一样
更新2022-10-09
385

FuwTUZ5ydtjQicgKtCdsnwKG1139

项目介绍

这里是我参加Funpack第二季第二期活动的任务总结报告,我所完成的是任务二,设计根据采集到的adc值变化而不断变化的呼吸灯

 

主要硬件介绍

基于AURIX™ TriCore™ 单片三核微控制器TC275,最高主频为200 MHz。 板载Micro USB接口的miniWiggler调试器,无需另外接调试器。 两个Infineon Shield2Go扩展接口,兼容MikroBUS 和Arduino扩展连接,带有Infineon新一代CAN 收发器TLE9251VSJ ,可用于汽车和工业应用的HS CAN网络开发。已焊接可调旋转电位计,用于评估模拟电压的采集,在我的任务中,就是不断获取该电位器的adc值。预留三个LED可作为工作指示灯和一个用户按钮,任务中,通过其中一个led灯的暗亮程度来表示出获取到的adc值的大小。Fqm8csc29jLvhvgQ3ks7BeqLOMHV

主要软件介绍

                                             Fi4Bd1-V1GaDORdbaTaK5t-V3D5w

开发这款开发板有多种方式,但有一些方式需要付费。则我使用的是英飞凌家出品的ADS,AURIX™ Development Studio是专为TriCore MCU系列设计的集成开发环境,在eclipse环境下支持使用C语言和英飞凌底层驱动库(iLLD)开发,对多核心进行在线调试。

在代码实现中,我们分别用到到了串口,ADC,PWM3个功能。

串口

FjdY6XXSXODcQ1ODUCKYzBBXq4hr

我们可以获取官方的这个例程进行学习使用

void IfxAsclin_Asc_pirnt(pchar format, ...){
    char message[STDIF_DPIPE_MAX_PRINT_SIZE+1];
    Ifx_SizeT count;
    va_list args;
    va_start(args,format);
    vsprintf((char *)message,format,args);
    va_end(args);
    count=(Ifx_SizeT)strlen(message);
    IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR,count<STDIF_DPIPE_MAX_PRINT_SIZE);

    IfxAsclin_Asc_write(&g_asc,message,&count,TIME_INFINITE);
}

在官方的基础上,我们可以重写printf函数,方便我们进行数据的输出,记得在主函数中,对串口初始化进行调用

ADC

在项目中,我们对板子上的电位器读取adc值,至于如何使用adc

FnJLM2rNMLUkiHZVF1oURNKUPtfC

我们可以使用这个官方的adc例程进行学习使用

void indicateConversionValue(void)
{
    Ifx_VADC_RES conversionResult;

    /* Retrieve the conversion value until valid flag of the result register is true */
    do
    {
        conversionResult = IfxVadc_Adc_getResult(&g_vadcBackgroundScan.adcChannel);
    }
    while (!conversionResult.B.VF);

    IfxAsclin_Asc_pirnt("the ADC value : %.2f\r\n",conversionResult.B.RESULT*3.3/4096.0);

    LED_PWM(conversionResult.B.RESULT);

}

在初始话时调用adc的初始化配置,主要是对通道数,分频系数,增益进行配置。之后不断的调用获取adc数据采集就行了。在上面这个获取adc数据函数最后,加上了将采集到的数据通过串口传到pc端并显示,因为板子的adc是12位的,需要进行一定的转换才是正确的电压值,同时传给pwm的函数处,就行占空比的改变。

PWM

Fj8cMDrEapSbcUjwzXLYUmnopSoi

我们可以使用这个官方的pwm例程进行学习使用

#include "GTM_TOM_PWM.h"
#include "Ifx_Types.h"
#include "IfxGtm_Tom_Pwm.h"

/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/
#define ISR_PRIORITY_TOM    20                                      /* Interrupt priority number                    */
#define LED                 IfxGtm_TOM1_4_TOUT14_P00_5_OUT          /* LED which will be driven by the PWM          */
#define PWM_PERIOD          50000                                   /* PWM period for the TOM                       */
#define FADE_STEP           PWM_PERIOD / 100                        /* PWM duty cycle for the TOM                   */

/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/
IfxGtm_Tom_Pwm_Config g_tomConfig;                                  /* Timer configuration structure                */
IfxGtm_Tom_Pwm_Driver g_tomDriver;                                  /* Timer Driver structure                       */
uint32 g_fadeValue = 0;                                             /* Fade value, starting from 0                  */
sint8 g_fadeDir = 1;                                                /* Fade direction variable                      */

/*********************************************************************************************************************/
/*-----------------------------------------------Function Prototypes-------------------------------------------------*/
/*********************************************************************************************************************/
void setDutyCycle(uint32 dutyCycle);                                /* Function to set the duty cycle of the PWM    */

/*********************************************************************************************************************/
/*--------------------------------------------Function Implementations-----------------------------------------------*/
/*********************************************************************************************************************/
/* This function initializes the TOM */
void initGtmTomPwm(void)
{
    IfxGtm_enable(&MODULE_GTM);                                     /* Enable GTM                                   */

    IfxGtm_Cmu_enableClocks(&MODULE_GTM, IFXGTM_CMU_CLKEN_FXCLK);   /* Enable the FXU clock                         */

    /* Initialize the configuration structure with default parameters */
    IfxGtm_Tom_Pwm_initConfig(&g_tomConfig, &MODULE_GTM);

    g_tomConfig.tom = LED.tom;                                      /* Select the TOM depending on the LED          */
    g_tomConfig.tomChannel = LED.channel;                           /* Select the channel depending on the LED      */
    g_tomConfig.period = PWM_PERIOD;                                /* Set the timer period                         */
    g_tomConfig.pin.outputPin = &LED;                               /* Set the LED port pin as output               */
    g_tomConfig.synchronousUpdateEnabled = TRUE;                    /* Enable synchronous update                    */

    IfxGtm_Tom_Pwm_init(&g_tomDriver, &g_tomConfig);                /* Initialize the GTM TOM                       */
    IfxGtm_Tom_Pwm_start(&g_tomDriver, TRUE);                       /* Start the PWM                                */
}

/* This function creates the fade effect for the LED */
void fadeLED(void)
{
    if((g_fadeValue + FADE_STEP) >= PWM_PERIOD)
    {
        g_fadeDir = -1;                                             /* Set the direction of the fade                */
    }
    else if((g_fadeValue - FADE_STEP) <= 0)
    {
        g_fadeDir = 1;                                              /* Set the direction of the fade                */
    }
    g_fadeValue += g_fadeDir * FADE_STEP;                           /* Calculation of the new duty cycle            */
    setDutyCycle(g_fadeValue);                                      /* Set the duty cycle of the PWM                */
}

/* This function sets the duty cycle of the PWM */
void setDutyCycle(uint32 dutyCycle)
{
    g_tomConfig.dutyCycle = dutyCycle;                              /* Change the value of the duty cycle           */
    IfxGtm_Tom_Pwm_init(&g_tomDriver, &g_tomConfig);                /* Re-initialize the PWM                        */
}
void LED_PWM(uint32 pwm_value)
{
    g_fadeValue =(0x1000-pwm_value)*(PWM_PERIOD/0x1000);                           /* Calculation of the new duty cycle            */
    setDutyCycle(g_fadeValue);                                      /* Set the duty cycle of the PWM                */
}

该代码的pwm效果通过TOM定时器实现,关于这个pwm的周期及占空比如何设计,可以看下图官方的文件里说明。

FlPuvLrYrmJZY6eI24NIR85GpgAi

总结

在此之前,一直没有接触过英飞凌家的板子,从这次的活动中,我学习到了如何使用ADS创建英飞凌的单片机工程,并在官网找到十分俱全的资料。

这次项目总体来说不是很难,但还是学到了不少新知识的,十分感谢硬禾学堂平台。

 

附件下载
KIT_TC275_呼吸灯.zip
团队介绍
个人
评论
0 / 100
查看更多
目录
硬禾服务号
关注最新动态
0512-67862536
info@eetree.cn
江苏省苏州市苏州工业园区新平街388号腾飞创新园A2幢815室
苏州硬禾信息科技有限公司
Copyright © 2023 苏州硬禾信息科技有限公司 All Rights Reserved 苏ICP备19040198号