F28335_ECAP使用

本文介绍了一种通过两次过零点检测来准确测量相对时间的方法,并提供了详细的代码实现过程。利用eCAP模块进行信号捕获,通过计数器复位确保测量准确性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目要求对工频电压进行过零检测,而为了防止出现误差,应该检测两次过零点的时间间隔是不是大于一定值,因此需要测量两次捕捉的相对时间。

进行两次检测,第一次检测到信号就复位计数器,第二次检测到的结果就是需要的相对时间,可直接使用。

	IER |= M_INT4;
	
   // Initialize eCAP1/2/3
	InitECap1Gpio();
   
	ECap1Regs.ECEINT.all = 0x0000;             // Disable all capture interrupts
	ECap1Regs.ECCLR.all = 0xFFFF;              // Clear all CAP interrupt flags
	ECap1Regs.ECCTL1.bit.CAPLDEN = 0;          // Disable CAP1-CAP4 register loads
	ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0;        // Make sure the counter is stopped

	// Configure peripheral registers
	ECap1Regs.ECCTL2.bit.CONT_ONESHT = 1;      // continue
	ECap1Regs.ECCTL2.bit.STOP_WRAP = 1;        // Stop at 2 events
	ECap1Regs.ECCTL1.bit.CAP1POL = 0;          // Rising edge
	ECap1Regs.ECCTL1.bit.CAP2POL = 0;          // Rising edge
	
	ECap1Regs.ECCTL1.bit.CTRRST1 = 1;          // Difference operation 
	ECap1Regs.ECCTL1.bit.CTRRST1 = 0; 		//第一次捕获,复位计数器,
       										//第二次得到的值就是需要的时间
	ECap1Regs.ECCTL2.bit.SYNCI_EN = 0;         // Enable sync in
	ECap1Regs.ECCTL2.bit.SYNCO_SEL = 0x10;        // Pass through
	ECap1Regs.ECCTL1.bit.CAPLDEN = 1;          // Enable capture units
	
	ECap1Regs.ECCTL2.bit.REARM = 1;

	ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1;        // Start Counter
	ECap1Regs.ECCTL1.bit.CAPLDEN = 1;          // Enable CAP1-CAP4 register loads
	ECap1Regs.ECEINT.bit.CEVT2 = 1;            // 1 events = interrupt
	// Enable eCAP INTn in the PIE: Group 3 interrupt 1

	PieCtrlRegs.PIEIER4.bit.INTx1 = 1;


每个CAP模块都有一个PIE中断,而CAP模块中又有7个触发源能够触发此中断,因而在相应的中断函数中,要进行识别,或者限制的处理

 

每次CAP模块捕获wrap的次数后,对应的引脚则被冻结,停止捕获,而ECap1Regs.ECCTL2.bit.REARM = 1;则能解除冻结,同时返回到cap1

因此在中断函数中应该加入

  ECap1Regs.ECCLR.bit.CEVT2 = 1;
  ECap1Regs.ECCLR.bit.INT = 1;
  ECap1Regs.ECCTL2.bit.REARM = 1;//	用于重新启动CAP




### TMS320F28377D DSP eCAP Module Documentation and Examples The Enhanced Capture (eCAP) module within the TMS320F28377D Digital Signal Processor is a versatile peripheral designed to handle precise timing tasks, including capturing time-stamped events or generating PWM signals. The system clock operates at 150 MHz, providing a resolution of approximately 6.67 nanoseconds for its 32-bit timer base[^4]. This high-resolution capability makes it suitable for applications requiring accurate timing measurements. #### Key Features of the eCAP Module - **High Resolution Timing**: With a 32-bit counter operating under a 150 MHz clock rate, each tick represents about 6.67 ns. - **Capture Functionality**: Supports up to four levels of capture event sequences with configurable edge polarity detection on input pins. - **Interrupt Generation**: Each level of captured data can trigger an interrupt request when new values are recorded. - **Flexible Configuration Options**: Allows configuration as either a capture unit or single-channel PWM output generator depending upon application needs. For developers looking into practical implementations involving this feature-rich component, several resources exist that provide detailed guidance along with code samples: - A comprehensive guide specifically addressing how to work with these modules exists in "DSP_TMS320F28377D_eCAP Learning Notes"[^4], which covers not only theoretical aspects but also includes hands-on exercises demonstrating real-world usage scenarios like setting up interrupts based on specific conditions detected by the sensor inputs connected through GPIOs configured as external triggers for the eCAP interface. Additionally, there's official documentation available from Texas Instruments regarding programming interfaces provided alongside example projects bundled inside development kits such as those mentioned earlier concerning F2837xD series devices[^3]. ```c // Example C Code Snippet Showing Basic Setup For ECAP Peripheral On TMS320F28377D void InitECap(void){ ECapRegs.ECCTL2.bit.TSCTRSTOP = 0; // Disable stop bit ECapRegs.ECEINT.all = 0x0000; // Clear all CAP Interrupt sources ECapRegs.ECCLR.all = 0xFFFF; // Clear all CAP Events // Configure Edge Detection Logic Here According To Application Requirements... PieCtrlRegs.PIEIER9.bit.INT_ecap_ch1=1;// Enable INT_ecap_ch1 In PIE Group 9 Register Set } ``` This setup function initializes the enhanced capture block according to user-defined parameters while ensuring proper initialization states before enabling any associated hardware features. --related questions-- 1. How does one configure the eCAP module for different modes? 2. What kind of applications benefit most from using the eCAP functionality? 3. Can you explain more about configuring edges sensitivity settings within the eCAP registers? 4. Are there limitations imposed by the number of channels used simultaneously across multiple peripherals? 5. Is it possible to synchronize operations between two separate instances of the eCAP units present on-chip?
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值