公告

大中华汽车电子生态圈社区并入开发者社区- 更多资讯点击此

Tip / 登入 to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
韦弦之佩
Level 2
Level 2
First comment on blog Welcome! First solution authored
下面代码是STM的程序,想请问一下大家: 1、这里面具体是怎么控制灯的亮灭的,不太懂程序里面的逻辑。 2、还有这个stm0CompareValue为什么得到是1ms啊? #include "PortIoIfxPort_Io.h" #include "StmStdIfxStm.h" uint32 OS_TICK_IN_SECONDS; uint32 stm0CompareValue; #define STM0_TICK_PERIOD_IN_MICROSECONDS 1000 void STM_Demo_init(void) { /* Initialize STM for the triggers*/ IfxStm_CompareConfig stmCompareConfig; // configure P33.8 as general output IfxPort_setPinMode(&MODULE_P13, 0, IfxPort_Mode_outputPushPullGeneral); /* Calculate the compare value of STM0 */ stm0CompareValue = IfxStm_getFrequency(&MODULE_STM0) / STM0_TICK_PERIOD_IN_MICROSECONDS; /* 1ms */
0 点赞
11 回复数
韦弦之佩
Level 2
Level 2
First comment on blog Welcome! First solution authored
#include "PortIoIfxPort_Io.h" #include "StmStdIfxStm.h" uint32 OS_TICK_IN_SECONDS; uint32 stm0CompareValue; #define STM0_TICK_PERIOD_IN_MICROSECONDS 1000 void STM_Demo_init(void) { /* Initialize STM for the triggers*/ IfxStm_CompareConfig stmCompareConfig; // configure P33.8 as general output IfxPort_setPinMode(&MODULE_P13, 0, IfxPort_Mode_outputPushPullGeneral); /* Calculate the compare value of STM0 */ stm0CompareValue = IfxStm_getFrequency(&MODULE_STM0) / STM0_TICK_PERIOD_IN_MICROSECONDS; /* 1ms */ IfxStm_enableOcdsSuspend(&MODULE_STM0); /* Configure interrupt service requests for STM trigger outputs */ //IfxSrc_init(&MODULE_SRC.STM[0].SR[0], IfxSrc_Tos_cpu0, IFX_CFG_ISR_PRIORITY_STM0_COMPARE0); //IfxSrc_enable(&MODULE_SRC.STM[0].SR[0]); stmCompareConfig.servProvider = IfxSrc_Tos_cpu0; /* Call the constructor of configuration */ IfxStm_initCompareConfig(&stmCompareConfig); /* Modify only the number of ticks and enable the trigger output */ stmCompareConfig.ticks = stm0CompareValue; /*Interrupt after stm0CompareValue ticks from now */ stmCompareConfig.triggerInterruptEnabled = TRUE; /* Now Compare functionality is initialized */ IfxStm_initCompare(&MODULE_STM0, &stmCompareConfig); } IFX_INTERRUPT(Ifx_STM0_Isr,0,IFX_CFG_ISR_PRIORITY_STM0_COMPARE0) { uint32 stmTicks; stmTicks= (uint32)(stm0CompareValue * 100); IfxStm_updateCompare (&MODULE_STM0, IfxStm_Comparator_0, IfxStm_getCompare (&MODULE_STM0, IfxStm_Comparator_0) + stmTicks); IfxPort_togglePin(&MODULE_P13, 0); __enable (); //CounterTick(IFX_OSTASK_COUNTER); } 这是完全的代码,没用过这个论坛,没排版好,不好意思~
0 点赞
wcer520
Level 2
Level 2
5 replies posted First question asked First reply posted
你设定的是100Mhz的频率,所以10ns分辨率,比较数100000,所以是1ms中断一次。 IfxPort_togglePin(&MODULE_P13, 0)翻转IO口。
0 点赞
韦弦之佩
Level 2
Level 2
First comment on blog Welcome! First solution authored
您好: 意思就是IfxStm_getFrequency(&MODULE_STM0)取得是STM默认频率100Mhz对吧。 还想麻烦问下您, 下面这两句更新比较值的意义是什么? stmTicks= (uint32)(stm0CompareValue * 100); IfxStm_updateCompare (&MODULE_STM0, IfxStm_Comparator_0, IfxStm_getCompare (&MODULE_STM0, IfxStm_Comparator_0) + stmTicks);
0 点赞
小柯
Level 4
Level 4
First like received 50 replies posted 25 replies posted
建议你先看看芯片手册STM部分,因为这个定时器与其他的定时器不一样,到达比较值之后,不复位。也就是说,STM定时器一直在向上计数,通过两个数之差,计算时间。
0 点赞
韦弦之佩
Level 2
Level 2
First comment on blog Welcome! First solution authored
好的好的,谢谢您,我再去看看,摸索一下。
0 点赞
独秀一郎
Level 5
Level 5
Welcome! 50 comments on blog 25 comments on blog
要是把程序截图放上来更容易查看。
0 点赞
我不知道这个论坛怎么上传图片,本来也想传图来着。
0 点赞
Quanqiu
Employee
Employee
First like received 100 comments on blog 50 comments on blog
如果需要通过图片表示,可以到下列地址发布:https://www.infineon-autoeco.com/BBS/Index。
0 点赞
韦弦之佩
Level 2
Level 2
First comment on blog Welcome! First solution authored
好的,谢谢您。了解~
0 点赞
纳尼
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted
这么一堆代码,可读性太差了
0 点赞
韦弦之佩
Level 2
Level 2
First comment on blog Welcome! First solution authored
代码可读性还是可以的,毕竟是demo程序;因为提问它限制字数,我就简略了一些,然后我提问的时候排版了, 发出来就有点乱,不知道怎么调整。(捂脸??)
0 点赞