dsp生成pwm波形控制mos管

2019-11-29 15:26发布

<font face="微软雅黑"><font style="font-size:18px">在生成的pwm波生成的栅极脉冲信号时,使用AQ生成的是方波 ,但是运行仿真时,使用示波器测试后发现是三角波,哪位大神可以帮忙解答一下程序如下</font></font><br><br> <fo <="" div=""></fo><pre style="max-width: 100%;"><code class="cpp hljs" codemark="1"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-string">"Example_2823xEPwm_duty.h"</span></span> <span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-string">"DSP2833x_Device.h"</span> // DSP2833x HeadeRFile Include File</span> <span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-string">"DSP2833x_Examples.h"</span> // DSP2833x Examples Include File</span> <span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> Hall_num1 0x5 <span class="hljs-comment">//BLDC电机的霍尔相序</span></span> <span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> Hall_num2 0x1</span> <span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> Hall_num3 0x3</span> <span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> Hall_num4 0x2</span> <span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> Hall_num5 0x6</span> <span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> Hall_num6 0x4</span> <span class="hljs-comment">//#include "DSP2833x_GlobalPrototypes.h"</span> <span class="hljs-comment">//Uint16 *ExRamstart = (Uint16 *)0x100000;</span> <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">EPwm_Setup</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span></span>; <span class="hljs-comment">//所有函数不用出现</span> <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">changephase</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span></span>; <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">Init_FMQ_voice</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span></span>; <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">Start_car</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span></span>; <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">Stop_car</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span></span>; <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">HVDMC_Protection</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span></span>; <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">MOS_V1_V4PWM</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> </span>; <span class="hljs-comment">// 切换V1V4MOS驱动</span> <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">MOS_V1_V6PWM</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> </span>; <span class="hljs-comment">// 切换V1V6MOS驱动</span> <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">MOS_V3_V6PWM</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> </span>; <span class="hljs-comment">// 切换V3V6MOS驱动</span> <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">MOS_V3_v2PWM</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> </span>; <span class="hljs-comment">// 切换V3V2MOS驱动</span> <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">MOS_V5_V2PWM</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> </span>; <span class="hljs-comment">// 切换V5V2MOS驱动</span> <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">MOS_V5_V4PWM</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> </span>; <span class="hljs-comment">// 切换V5V4MOS驱动</span> <span class="hljs-function">interrupt <span class="hljs-keyword">void</span> <span class="hljs-title">MotorControl_ISR</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span></span>; Uint16 hall=<span class="hljs-number">0</span>; <span class="hljs-comment">//赋值0 在Example_2823xEPwm_duty.h外部变量</span> Uint16 ThreeHall_H[<span class="hljs-number">3</span>]={<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>}; Uint16 ThreeHall_State=<span class="hljs-number">0</span>; Uint16 ThreeHall_text[<span class="hljs-number">50</span>]={<span class="hljs-number">0</span>}; Uint16 ThreeHall_OldState=<span class="hljs-number">0</span>; Uint16 ThreeHall_Speed_count=<span class="hljs-number">0</span>; Uint16 count1=<span class="hljs-number">0</span>; Uint16 count2=<span class="hljs-number">0</span>; Uint16 duty=<span class="hljs-number">5000</span>; <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> </span>{ <span class="hljs-comment">//初始化系统、中断</span> InitSysCtrl(); <span class="hljs-comment">//Initialize System Control</span> InitPieCtrl(); <span class="hljs-comment">// Initialize the PIE control registers to their default state.</span> InitPieVectTable(); <span class="hljs-comment">// Initialize the PIE vector table with pointers to the shell Interrupt</span> <span class="hljs-comment">// Interrupts that are used in this example are re-mapped to</span> InitePwmGpio(); <span class="hljs-comment">//Initialize pwmGPIO √</span> <span class="hljs-comment">// InitECapGpio(); // √</span> Init_FMQ_voice(); <span class="hljs-comment">// √ 在线调试所以先不对电机三霍尔的GPIO初始化</span> <span class="hljs-comment">// InitFlash();</span> EPwm_Setup(); <span class="hljs-comment">//初始化EPwm;</span> <span class="hljs-comment">// InitECap(); //初始化捕获</span> CpuTimer0Regs.PRD.all = <span class="hljs-number">30000000</span>; <span class="hljs-comment">// 200ms 500MS 75 000000</span> HVDMC_Protection( ); <span class="hljs-comment">//PWM的保护初始化</span> EALLOW; PieVectTable.EPWM1_INT = &amp;MotorControl_ISR; <span class="hljs-comment">//指向中断函数 PWM中断</span> EDIS; EALLOW; PieCtrlRegs.PIECTRL.bit.ENPIE = <span class="hljs-number">1</span>; <span class="hljs-comment">// 使能 PIE 时钟</span> PieCtrlRegs.PIEIER3.bit.INTx1 = <span class="hljs-number">1</span>; <span class="hljs-comment">// 中断向量 EPWM1</span> <span class="hljs-comment">//启动EPWM 1 中断</span> EPwm1Regs.ETSEL.bit.INTEN = <span class="hljs-number">1</span>; <span class="hljs-comment">// Enable EPWM1INT generation</span> EPwm1Regs.ETSEL.bit.INTSEL = <span class="hljs-number">1</span>; <span class="hljs-comment">// Enable interrupt CNT_zero event</span> EPwm1Regs.ETPS.bit.INTPRD = <span class="hljs-number">1</span>; <span class="hljs-comment">// 产生周期事件中断</span> EPwm1Regs.ETCLR.bit.INT = <span class="hljs-number">1</span>; <span class="hljs-comment">// 使能更多中断</span> IER |= M_INT3; <span class="hljs-comment">//使能 中断向量</span> EINT; <span class="hljs-comment">// 使能全局中断 INTM</span> ERTM; <span class="hljs-comment">// 使能全局中断 DBGM</span> EDIS; <span class="hljs-comment">// Step 6. IDLE loop. Just sit and loop forever (optional):</span> <span class="hljs-comment">//Start_car();</span> <span class="hljs-keyword">for</span>(;;); } <span class="hljs-comment">/*换向函数*/</span> <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">changephase</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> </span>{ <span class="hljs-comment">//捕获霍尔信号</span> ThreeHall_H[<span class="hljs-number">0</span>]=GpioDataRegs.GPCDAT.bit.GPIO67; ThreeHall_H[<span class="hljs-number">1</span>]=GpioDataRegs.GPCDAT.bit.GPIO68; ThreeHall_H[<span class="hljs-number">2</span>]=GpioDataRegs.GPCDAT.bit.GPIO69; ThreeHall_State=ThreeHall_H[<span class="hljs-number">0</span>]+(ThreeHall_H[<span class="hljs-number">1</span>]&lt;&lt;<span class="hljs-number">1</span>)+(ThreeHall_H[<span class="hljs-number">2</span>]&lt;&lt;<span class="hljs-number">2</span>); IF ( ThreeHall_State!=ThreeHall_OldState ) { <span class="hljs-comment">/*ThreeHall_text[count1]=ThreeHall_State; count1++; // 记录霍尔状态数据 if( count1&gt;49) count1=0; */</span> <span class="hljs-keyword">switch</span> (ThreeHall_State) { <span class="hljs-keyword">case</span> Hall_num1: <span class="hljs-comment">//换向 V1、V4导通</span> { MOS_V1_V4PWM(); <span class="hljs-keyword">break</span>; } <span class="hljs-keyword">case</span> Hall_num2: <span class="hljs-comment">//换向 V1、V6导通</span> { MOS_V1_V6PWM() ; <span class="hljs-keyword">break</span>; } <span class="hljs-keyword">case</span> Hall_num3: <span class="hljs-comment">//换向 V3、V6导通</span> { MOS_V3_V6PWM() ; <span class="hljs-keyword">break</span>; } <span class="hljs-keyword">case</span> Hall_num4: <span class="hljs-comment">//换向 V3、V2导通</span> { MOS_V3_V2PWM() ; <span class="hljs-keyword">break</span>; } <span class="hljs-keyword">case</span> Hall_num5: <span class="hljs-comment">//换向 V5、V2导通</span> { MOS_V5_V2PWM() ; <span class="hljs-keyword">break</span>; } <span class="hljs-keyword">case</span> Hall_num6: <span class="hljs-comment">//换向 V5、V4导通</span> { MOS_V5_V4PWM() ; <span class="hljs-keyword">break</span>; } <span class="hljs-keyword">default</span>: { Stop_car(); } <span class="hljs-keyword">break</span>; } } <span class="hljs-comment">/* else if ( ThreeHall_State==ThreeHall_OldState ) // ( Hall_Three.Hall_State==Hall_Three.OldHall_State ) { ThreeHall_Speed_count++; if( ThreeHall_Speed_count&gt;=5000 ) { Stop_car(); } switch (ThreeHall_State) { case Hall_num1: //换向 V1、V4导通 { MOS_V1_V4PWM(); break; } case Hall_num2: //换向 V1、V6导通 { MOS_V1_V6PWM() ; break; } case Hall_num3: //换向 V3、V6导通 { MOS_V3_V6PWM() ; break; } case Hall_num4: //换向 V3、V2导通 { MOS_V3_V2PWM() ; break; } case Hall_num5: //换向 V5、V2导通 { MOS_V5_V2PWM() ; break; } case Hall_num6: //换向 V5、V4导通 { MOS_V5_V4PWM() ; break; } default: { Stop_car(); } break; } } ThreeHall_OldState=ThreeHall_State;*/</span> } <span class="hljs-comment">/*6种PWM状态的开关管*/</span> <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">MOS_V1_V4PWM</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> <span class="hljs-comment">//开关管V1和V4导通</span> </span>{ <span class="hljs-comment">// Set action</span> EALLOW; EPwm1Regs.AQCSFRC.bit.CSFA=<span class="hljs-number">0x0</span>; EPwm1Regs.AQCSFRC.bit.CSFB=<span class="hljs-number">0x1</span>; EPwm2Regs.AQCSFRC.bit.CSFA=<span class="hljs-number">0x1</span>; EPwm2Regs.AQCSFRC.bit.CSFB=<span class="hljs-number">0x2</span>; EPwm3Regs.AQCSFRC.bit.CSFA=<span class="hljs-number">0x1</span>; EPwm3Regs.AQCSFRC.bit.CSFB=<span class="hljs-number">0x1</span>; EPwm1Regs.AQCTLA.bit.CAU = <span class="hljs-number">0x2</span>; EPwm1Regs.AQCTLA.bit.CAD = <span class="hljs-number">0x1</span>; EPwm1Regs.AQCTLB.bit.CBU = <span class="hljs-number">0x0</span>; EPwm1Regs.AQCTLB.bit.CBD = <span class="hljs-number">0x0</span>; EPwm2Regs.AQCTLA.bit.CAU = <span class="hljs-number">0x0</span>; EPwm2Regs.AQCTLA.bit.CAD = <span class="hljs-number">0x0</span>; EPwm2Regs.AQCTLB.bit.CBU = <span class="hljs-number">0x2</span>; EPwm2Regs.AQCTLB.bit.CBD = <span class="hljs-number">0x2</span>; EPwm3Regs.AQCTLA.bit.CAU = <span class="hljs-number">0x0</span>; EPwm3Regs.AQCTLA.bit.CAD = <span class="hljs-number">0x0</span>; EPwm3Regs.AQCTLB.bit.CBU = <span class="hljs-number">0x0</span>; EPwm3Regs.AQCTLB.bit.CBD = <span class="hljs-number">0x0</span>; EDIS; <span class="hljs-comment">// Hall_Three.MOSFET_State = 0x32;</span> } <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">MOS_V1_V6PWM</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> <span class="hljs-comment">//开关管V1和V6导通</span> </span>{ <span class="hljs-comment">// Set actions</span> EALLOW; EPwm1Regs.AQCSFRC.bit.CSFA=<span class="hljs-number">0x0</span>; EPwm1Regs.AQCSFRC.bit.CSFB=<span class="hljs-number">0x1</span>; EPwm2Regs.AQCSFRC.bit.CSFA=<span class="hljs-number">0x1</span>; EPwm2Regs.AQCSFRC.bit.CSFB=<span class="hljs-number">0x1</span>; EPwm3Regs.AQCSFRC.bit.CSFA=<span class="hljs-number">0x1</span>; EPwm3Regs.AQCSFRC.bit.CSFB=<span class="hljs-number">0x2</span>; EPwm1Regs.AQCTLA.bit.CAU = <span class="hljs-number">0x2</span>; EPwm1Regs.AQCTLA.bit.CAD = <span class="hljs-number">0x1</span>; EPwm1Regs.AQCTLB.bit.CBU = <span class="hljs-number">0x0</span>; EPwm1Regs.AQCTLB.bit.CBD = <span class="hljs-number">0x0</span>; EPwm2Regs.AQCTLA.bit.CAU = <span class="hljs-number">0x0</span>; EPwm2Regs.AQCTLA.bit.CAD = <span class="hljs-number">0x0</span>; EPwm2Regs.AQCTLB.bit.CBU = <span class="hljs-number">0x0</span>; EPwm2Regs.AQCTLB.bit.CBD = <span class="hljs-number">0x0</span>; EPwm3Regs.AQCTLA.bit.CAU = <span class="hljs-number">0x0</span>; EPwm3Regs.AQCTLA.bit.CAD = <span class="hljs-number">0x0</span>; EPwm3Regs.AQCTLB.bit.CBU = <span class="hljs-number">0x2</span>; EPwm3Regs.AQCTLB.bit.CBD = <span class="hljs-number">0x2</span>; EDIS; <span class="hljs-comment">//Hall_Three.MOSFET_State= 0x25;</span> } <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">MOS_V3_V6PWM</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> <span class="hljs-comment">//开关管V3和V6导通</span> </span>{ <span class="hljs-comment">// Set actions</span> EALLOW; EPwm1Regs.AQCSFRC.bit.CSFA=<span class="hljs-number">0x1</span>; EPwm1Regs.AQCSFRC.bit.CSFB=<span class="hljs-number">0x1</span>; EPwm2Regs.AQCSFRC.bit.CSFA=<span class="hljs-number">0x0</span>; EPwm2Regs.AQCSFRC.bit.CSFB=<span class="hljs-number">0x1</span>; EPwm3Regs.AQCSFRC.bit.CSFA=<span class="hljs-number">0x1</span>; EPwm3Regs.AQCSFRC.bit.CSFB=<span class="hljs-number">0x2</span>; EPwm1Regs.AQCTLA.bit.CAU = <span class="hljs-number">0x0</span>; EPwm1Regs.AQCTLA.bit.CAD = <span class="hljs-number">0x0</span>; EPwm1Regs.AQCTLB.bit.CBU = <span class="hljs-number">0x0</span>; EPwm1Regs.AQCTLB.bit.CBD = <span class="hljs-number">0x0</span>; EPwm2Regs.AQCTLA.bit.CAU = <span class="hljs-number">0x2</span>; EPwm2Regs.AQCTLA.bit.CAD = <span class="hljs-number">0x1</span>; EPwm2Regs.AQCTLB.bit.CBU = <span class="hljs-number">0x0</span>; EPwm2Regs.AQCTLB.bit.CBD = <span class="hljs-number">0x0</span>; EPwm3Regs.AQCTLA.bit.CAU = <span class="hljs-number">0x0</span>; EPwm3Regs.AQCTLA.bit.CAD = <span class="hljs-number">0x0</span>; EPwm3Regs.AQCTLB.bit.CBU = <span class="hljs-number">0x2</span>; EPwm3Regs.AQCTLB.bit.CBD = <span class="hljs-number">0x2</span>; EDIS; <span class="hljs-comment">// Hall_Three.MOSFET_State = 0x54;</span> } <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">MOS_V3_V2PWM</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> <span class="hljs-comment">//开关管V3和V2导通</span> </span>{ <span class="hljs-comment">// Set actions</span> EALLOW; EPwm1Regs.AQCSFRC.bit.CSFA=<span class="hljs-number">0x1</span>; EPwm1Regs.AQCSFRC.bit.CSFB=<span class="hljs-number">0x2</span>; EPwm2Regs.AQCSFRC.bit.CSFA=<span class="hljs-number">0x0</span>; EPwm2Regs.AQCSFRC.bit.CSFB=<span class="hljs-number">0x1</span>; EPwm3Regs.AQCSFRC.bit.CSFA=<span class="hljs-number">0x1</span>; EPwm3Regs.AQCSFRC.bit.CSFB=<span class="hljs-number">0x1</span>; EPwm1Regs.AQCTLA.bit.CAU = <span class="hljs-number">0x0</span>; EPwm1Regs.AQCTLA.bit.CAD = <span class="hljs-number">0x0</span>; EPwm1Regs.AQCTLB.bit.CBU = <span class="hljs-number">0x2</span>; EPwm1Regs.AQCTLB.bit.CBD = <span class="hljs-number">0x2</span>; EPwm2Regs.AQCTLA.bit.CAU = <span class="hljs-number">0x2</span>; EPwm2Regs.AQCTLA.bit.CAD = <span class="hljs-number">0x1</span>; EPwm2Regs.AQCTLB.bit.CBU = <span class="hljs-number">0x0</span>; EPwm2Regs.AQCTLB.bit.CBD = <span class="hljs-number">0x0</span>; EPwm3Regs.AQCTLA.bit.CAU = <span class="hljs-number">0x0</span>; EPwm3Regs.AQCTLA.bit.CAD = <span class="hljs-number">0x0</span>; EPwm3Regs.AQCTLB.bit.CBU = <span class="hljs-number">0x0</span>; EPwm3Regs.AQCTLB.bit.CBD = <span class="hljs-number">0x0</span>; EDIS; <span class="hljs-comment">// Hall_Three.MOSFET_State = 0x54;</span> } <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">MOS_V5_V2PWM</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> <span class="hljs-comment">//开关管V5和V2导通</span> </span>{ <span class="hljs-comment">// Set actions</span> EALLOW; EPwm1Regs.AQCSFRC.bit.CSFA=<span class="hljs-number">0x1</span>; EPwm1Regs.AQCSFRC.bit.CSFB=<span class="hljs-number">0x2</span>; EPwm2Regs.AQCSFRC.bit.CSFA=<span class="hljs-number">0x1</span>; EPwm2Regs.AQCSFRC.bit.CSFB=<span class="hljs-number">0x1</span>; EPwm3Regs.AQCSFRC.bit.CSFA=<span class="hljs-number">0x0</span>; EPwm3Regs.AQCSFRC.bit.CSFB=<span class="hljs-number">0x1</span>; EPwm1Regs.AQCTLA.bit.CAU = <span class="hljs-number">0x0</span>; EPwm1Regs.AQCTLA.bit.CAD = <span class="hljs-number">0x0</span>; EPwm1Regs.AQCTLB.bit.CBU = <span class="hljs-number">0x2</span>; EPwm1Regs.AQCTLB.bit.CBD = <span class="hljs-number">0x2</span>; EPwm2Regs.AQCTLA.bit.CAU = <span class="hljs-number">0x0</span>; EPwm2Regs.AQCTLA.bit.CAD = <span class="hljs-number">0x0</span>; EPwm2Regs.AQCTLB.bit.CBU = <span class="hljs-number">0x0</span>; EPwm2Regs.AQCTLB.bit.CBD = <span class="hljs-number">0x0</span>; EPwm3Regs.AQCTLA.bit.CAU = <span class="hljs-number">0x2</span>; EPwm3Regs.AQCTLA.bit.CAD = <span class="hljs-number">0x1</span>; EPwm3Regs.AQCTLB.bit.CBU = <span class="hljs-number">0x0</span>; EPwm3Regs.AQCTLB.bit.CBD = <span class="hljs-number">0x0</span>; EDIS; <span class="hljs-comment">// Hall_Three.MOSFET_State = 0x54;</span> } <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">MOS_V5_V4PWM</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> <span class="hljs-comment">//开关管V5和V4导通</span></span></code></pre><p><br></p>
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。