使用TMS320F2812的捕获单元测量外部输入的方波的频率的代码
时间: 2024-02-21 09:01:49 浏览: 35
以下是使用TMS320F2812的捕获单元测量外部输入的方波的频率的代码:
```c
#include "DSP281x_Device.h"
#include "DSP281x_Examples.h"
interrupt void cap1_isr(void);
Uint32 cap1_count = 0;
Uint32 cap1_freq = 0;
void main(void)
{
InitSysCtrl();
InitPieCtrl();
EALLOW;
PieVectTable.TINT1 = &cap1_isr;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
EDIS;
InitCpuTimers();
ConfigCpuTimer(&CpuTimer1, 150, 1000000);
InitCapGpio();
InitCap1();
EnableInterrupts();
StartCpuTimer1();
while(1)
{
// do something
}
}
interrupt void cap1_isr(void)
{
cap1_count++;
cap1_freq = 1000000 / (2 * cap1_count);
cap1_count = 0;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
```
在此代码中,我们首先初始化系统控制器和PIE控制器,并设置捕获单元的GPIO和捕获单元本身。然后我们初始化CPU定时器和PIE向量表。在定时器中断中,我们增加计数器,计算频率,然后重置计数器。最后,我们清除PIE中断标志并启用全局中断。
请注意,此代码仅为示例,具体实现可能因项目而异。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)