1. 项目介绍
本项目基于Infineon AURIX TC275微控制器的开发板TC275 lite硬件平台,软件开发环境采用基于Eclipse的免费IDE AURIX™ Development Studio。通过ADC采集电位器电压的大小来控制PWM占空比,从而实现呼吸灯的闪耀频率,同时将ADC采集到的数据,通过串口发送至PC机。
TC275TP作为第一代 Aurix TC27xT系列产品,专为满足极高的安全标准,同时大幅提高性能而设计。采用创新多核心架构,三个独立的 32 位 TriCore CPU均可工作在200 MHz。
2. 各功能对应的主要代码片段及说明
串口部分采用串口0,管脚采用P14_0,P14_1, 通过板载的仿真器串口,与上位机进行通信。
/* This function initializes the ASCLIN UART module */
void init_ASCLIN_UART(void)
{
/* Initialize an instance of IfxAsclin_Asc_Config with default values */
IfxAsclin_Asc_Config ascConfig;
IfxAsclin_Asc_initModuleConfig(&ascConfig, &MODULE_ASCLIN0);
/* Set the desired baud rate */
ascConfig.baudrate.baudrate = UART_BAUDRATE;
/* ISR priorities and interrupt target */
ascConfig.interrupt.txPriority = INTPRIO_ASCLIN0_TX;
ascConfig.interrupt.rxPriority = INTPRIO_ASCLIN0_RX;
ascConfig.interrupt.typeOfService = IfxCpu_Irq_getTos(IfxCpu_getCoreIndex());
/* FIFO configuration */
ascConfig.txBuffer = &g_ascTxBuffer;
ascConfig.txBufferSize = UART_TX_BUFFER_SIZE;
ascConfig.rxBuffer = &g_ascRxBuffer;
ascConfig.rxBufferSize = UART_RX_BUFFER_SIZE;
/* Pin configuration */
const IfxAsclin_Asc_Pins pins =
{
NULL_PTR, IfxPort_InputMode_pullUp, /* CTS pin not used */
&UART_PIN_RX, IfxPort_InputMode_pullUp, /* RX pin */
NULL_PTR, IfxPort_OutputMode_pushPull, /* RTS pin not used */
&UART_PIN_TX, IfxPort_OutputMode_pushPull, /* TX pin */
IfxPort_PadDriver_cmosAutomotiveSpeed1
};
ascConfig.pins = &pins;
IfxAsclin_Asc_initModule(&g_ascHandle, &ascConfig); /* Initialize module with above parameters */
}
/* This function sends and receives the string "Hello World!" */
void send_ASCLIN_UART_message(const void *data, Ifx_SizeT *count)
{
IfxAsclin_Asc_write(&g_ascHandle, data, count, TIME_INFINITE); /* Transmit data via TX */
}
ADC部分,通过ADC采集电位器电压,量程范围0-3.3v
/* The VADC module and group are initialized */
void vadcBackgroundScanInit(void)
{
/* VADC module configuration */
/* Create VADC configuration */
IfxVadc_Adc_Config adcConfig;
/* Initialize the VADC configuration with default values */
IfxVadc_Adc_initModuleConfig(&adcConfig, &MODULE_VADC);
/* Initialize the VADC module using the VADC configuration */
IfxVadc_Adc_initModule(&g_vadcBackgroundScan.vadc, &adcConfig);
/* VADC group configuration */
/* Create group configuration */
IfxVadc_Adc_GroupConfig adcGroupConfig;
/* Initialize the group configuration with default values */
IfxVadc_Adc_initGroupConfig(&adcGroupConfig, &g_vadcBackgroundScan.vadc);
/* Define which ADC group is going to be used */
adcGroupConfig.groupId = VADC_GROUP;
adcGroupConfig.master = VADC_GROUP;
/* Enable background scan source */
adcGroupConfig.arbiter.requestSlotBackgroundScanEnabled = TRUE;
/* Enable background auto scan mode */
adcGroupConfig.backgroundScanRequest.autoBackgroundScanEnabled = TRUE;
/* Enable the gate in "always" mode (no edge detection) */
adcGroupConfig.backgroundScanRequest.triggerConfig.gatingMode = IfxVadc_GatingMode_always;
/* Initialize the group using the group configuration */
IfxVadc_Adc_initGroup(&g_vadcBackgroundScan.adcGroup, &adcGroupConfig);
}
/* The input channels to be used are setup and the VADC is set into run mode */
void vadcBackgroundScanRun(void)
{
/* Initialize the channel configuration of application handle g_vadcBackgroundScan with default values */
IfxVadc_Adc_initChannelConfig(&g_vadcBackgroundScan.adcChannelConfig, &g_vadcBackgroundScan.adcGroup);
g_vadcBackgroundScan.adcChannelConfig.channelId = (IfxVadc_ChannelId)CHANNEL_ID;
g_vadcBackgroundScan.adcChannelConfig.resultRegister = (IfxVadc_ChannelResult)CHANNEL_RESULT_REGISTER;
g_vadcBackgroundScan.adcChannelConfig.backgroundChannel = TRUE;
/* Initialize the channel of application handle g_VadcBackgroundScan using the channel configuration */
IfxVadc_Adc_initChannel(&g_vadcBackgroundScan.adcChannel, &g_vadcBackgroundScan.adcChannelConfig);
/* Enable background scan for the channel */
IfxVadc_Adc_setBackgroundScan(&g_vadcBackgroundScan.vadc,
&g_vadcBackgroundScan.adcGroup,
(1 << (IfxVadc_ChannelId)CHANNEL_ID),
(1 << (IfxVadc_ChannelId)CHANNEL_ID));
/* Start background scan conversion */
IfxVadc_Adc_startBackgroundScan(&g_vadcBackgroundScan.vadc);
}
GTM部分,通过GTM产生PWM波形,对LED灯进行调光,实现呼吸灯效果
/* This function is creating the fade effect for the LED */
void fadeLED(float Step)
{
if(g_fadeValue >= PWM_PERIOD)
{
g_fadeDir = -1; /* Set the direction of the fade */
}
else if(g_fadeValue <= 0)
{
g_fadeDir = 1; /* Set the direction of the fade */
}
g_fadeValue += g_fadeDir * (Step*(1000/3.3)); /* Calculation of the new duty cycle */
setDutyCycle(g_fadeValue); /* Call the function which is setting the duty cycle of the PWM */
}
主函数,首先通过ADC采集电位器电压,然后将电压值通过串口发送至PC机,然后根据ADC采集的电压值,调整PWM的步进,来改变呼吸灯闪耀频率。
实际改变呼吸灯的闪耀频率,可通过两种方式,一个是,改变主循环中的延时时间,另外就是改变每次PWM调整的步进。本实验采用改变步进的方式。
while(1)
{
unsigned int len = 0;
indicateConversionValue();
len = snprintf(buf, PRINTBUFF_LEN, "ADC VALUE: %.2f FADE STEP:%d\r\n", Value, (int)(Value*(1000/3.3)));
send_ASCLIN_UART_message(buf, (Ifx_SizeT *)&len);
waitTime(ticksFor10ms);
fadeLED(Value); /* Change the intensity of the LED */
// printf("hard word \r\n");
}
3. 功能展示及说明
通过串口将ADC数据发送至PC机
通过电位器控制呼吸灯闪耀频率
4. 对本活动的心得体会
第一次接触infineon的芯片,虽然之前有过arm 系芯片的使用经验,但是首次上手还是遇到了些问题,从环境的搭建,到芯片的仿真,调试,再到完成项目,整体还是比较顺利的,不得不说infineon的芯片支持做的还是非常到位的,有非常完善的例程,稳定的开发环境,极大的方便了广大开发及学习者。
另外非常感谢此次活动举办方,非常喜欢这个活动,希望能够一直举办下去!