28335的ECAP模块在检测电网电压正负过零点时的配置问题

2019-11-30 10:27发布

<p> 大家好,我在使用CAP模块时遇到了一些问题。看了ti的几个eCAP例程,对其中的配置还是有一些疑问,例程里基本都要用到中断,然后eCAP1模块的CAP1-4都要用到,然后算频率之类的等等。</p><p> 而我想实现的功能是:比如EPwm1A输出一个50Hz的方波,将该方波送入ECAP1口检测。检测上升沿时强制EPwm1B置高,检测下降沿时强制EPwm1B置低(其实就是检测电网电压过零点产生50Hz的方波去驱动一个逆变桥)。然后我看了eCAP模块在捕获事件发生时会将ECFLG寄存器中对应的状态位CEVTx置位。</p><p> 但是我有两个疑问:</p><p> 1. 如果不配置中断,状态位CEVTx在捕获事件发生时会被置位么?(实际上我就是不需要配置中断,因为最后这段程序本来就会运行在系统的中断程序里,没必要再加一个中断。)</p><p> 2. 在使用ECAP1时,我可以只使用CAP1-2,3-4不使用么?因为我只需要捕获一个上升沿,EPwm1B置高,等待下一次上升沿;捕获一次下降沿,EPwm1B置低,等待下一次下降沿。</p><p> 我按照这个想法去写了一个测试程序,没有出现正确现象,我感觉配置上也有一点问题,所以不确定是不是中断的原因。50Hz的pwm波是正常产生,接线也没有错,我的ECAP1配置如下:</p><pre style="max-width: 100%;"><code class="cpp hljs" codemark="1"><span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">SetCap1Mode</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> </span>{ ECap1Regs.ECCTL1.bit.CAP1POL = EC_RISING; ECap1Regs.ECCTL1.bit.CAP2POL = EC_FALLING; ECap1Regs.ECCTL1.bit.CTRRST1 = EC_ABS_MODE; ECap1Regs.ECCTL1.bit.CTRRST2 = EC_ABS_MODE; ECap1Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE; ECap1Regs.ECCTL1.bit.PRESCALE = EC_DIV1; ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE; ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS; ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS; ECap1Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE; ECap1Regs.ECEINT.all = <span class="hljs-number">0x0000</span>; <span class="hljs-comment">//stop all interrupt</span> ECap1Regs.ECCLR.all = <span class="hljs-number">0xFFFF</span>; <span class="hljs-comment">//clare all flag</span> ECap1Regs.ECCTL2.bit.RE ARM = EC_ARM; ECap1Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN; <span class="hljs-comment">// 启动</span> ECap1Regs.ECCTL2.bit.STOP_WRAP = EC_EVENT2; }</code></pre><p> 在主循环里是这样判断的(总感觉好像缺点什么,比如ECAP要不要重新再启动一下?)</p><pre style="max-width: 100%;"><code class="cpp hljs" codemark="1"><span class="hljs-keyword">while</span>(<span class="hljs-number">1</span>) { IF ( ECap1Regs.ECFLG.bit.CEVT1 ==<span class="hljs-number">1</span> )<span class="hljs-comment">//when cap the rising,the flag CEVT1 will be set automatically</span> { LED <span class="hljs-number">1</span> = ~LED1; EPwm1Regs.AQCSFRC.bit.CSFB = <span class="hljs-number">2</span>; ECap1Regs.ECCLR.bit.CEVT1 = <span class="hljs-number">1</span>; <span class="hljs-comment">//clear the flag CEVT1 to wait for the next rising</span> } <span class="hljs-keyword">if</span>( ECap1Regs.ECFLG.bit.CEVT2 == <span class="hljs-number">1</span> )<span class="hljs-comment">//when cap the falling,the flag CEVT2 will be set automatically</span> { LED2 = ~LED2; EPwm1Regs.AQCSFRC.bit.CSFB = <span class="hljs-number">1</span>; ECap1Regs.ECCLR.bit.CEVT2 = <span class="hljs-number">1</span>; <span class="hljs-comment">//clear the flag CEVT2 to wait for the next falling</span> } }</code></pre><p> 希望得到高手指点,谢谢!</p><br> <br> <p><br></p>