⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 f281xpwm.c

📁 里面包含dsp采集电压
💻 C
字号:
/* ==================================================================================
File name:       F281XPWM.C
                   
Description:   F281x全比较PWM产生模块

=====================================================================================*/

#include "DSP281x_Device.h"
#include "f281xpwm.h"

void F281X_EV1_PWM_Init(PWMGEN *p) 
{       
        EvaRegs.T1PR = p->PeriodMax;              // 初始化Timer 1周期寄存器 
        EvaRegs.T1CON.all = PWM_INIT_STATE;       // 对称波形设置 
        EvaRegs.DBTCONA.all = DBTCON_INIT_STATE;  // 初始化DBTCONA寄存器                                 
        EvaRegs.ACTRA.all = ACTR_INIT_STATE;      // 初始化ACTRA寄存器      

        EvaRegs.COMCONA.all = 0xA200;             // 初始化COMCONA寄存器 

        EvaRegs.CMPR1 = p->PeriodMax;             // 初始化CMPR1寄存器 
        EvaRegs.CMPR2 = p->PeriodMax;             // 初始化 CMPR2寄存器 
        EvaRegs.CMPR3 = p->PeriodMax;             // I初始化 CMPR3 寄存器 
        EALLOW;                       // 关写保护
        GpioMuxRegs.GPAMUX.all |= 0x003F;   // 设置 PWM1-6 的输出管脚
        EDIS;                         // 开写保护
}


void F281X_EV1_PWM_Update(PWMGEN *p) 
{       
		int16 MPeriod;
        int32 Tmp;

// Compute the timer period (Q0) from the period modulation input (Q15)
        Tmp = (int32)p->PeriodMax*(int32)p->MfuncPeriod;           // Q15 = Q0*Q15
        MPeriod = (int16)(Tmp>>16) + (int16)(p->PeriodMax>>1);     // Q0 = (Q15->Q0)/2 + (Q0/2)
        EvaRegs.T1PR = MPeriod;  

// Compute the compare 1 (Q0) from the PWM 1&2 duty cycle ratio (Q15)
        Tmp = (int32)MPeriod*(int32)p->MfuncC1;                    // Q15 = Q0*Q15
        EvaRegs.CMPR1 = (int16)(Tmp>>16) + (int16)(MPeriod>>1);    // Q0 = (Q15->Q0)/2 + (Q0/2)

// Compute the compare 2 (Q0) from the PWM 3&4 duty cycle ratio (Q15)
        Tmp = (int32)MPeriod*(int32)p->MfuncC2;                   // Q15 = Q0*Q15
        EvaRegs.CMPR2 = (int16)(Tmp>>16) + (int16)(MPeriod>>1);   // Q0 = (Q15->Q0)/2 + (Q0/2)

// Compute the compare 3 (Q0) from the PWM 5&6 duty cycle ratio (Q15)
        Tmp = (int32)MPeriod*(int32)p->MfuncC3;                   // Q15 = Q0*Q15
        EvaRegs.CMPR3 = (int16)(Tmp>>16) + (int16)(MPeriod>>1);   // Q0 = (Q15->Q0)/2 + (Q0/2)
        
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -