打印

pfc886+MD520pwm06版07

[复制链接]
501|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
34af9uc|  楼主 | 2021-5-14 22:12 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
/***************************************PFC886+MF520PWM**********************************************/
/***************************************QQ:774145445*************************************************/
/****************************************快手:共同学习STM8*******************************************/
/****************************************20210423****************************************************/
//                     _________   _________
//              PWM2L-|1 pa2    \_/   pa1 20|-PWM2H
//              PWM1L-|2 pa3          pa0 19|-PWM1H
//              pwm0L-|3 pa4          pa7 18|-pwm0H
//                    |4 pa5          pa6 17|-led_1
//         与gnd相连|-|5 nc            nc 16|-|与vdd相连
//                  |-|6 gnd          vdd 15|-|
//                k_1-|7 pb0          pb7 14|-led_2
//                k_2-|8 pb1          pb6 13|-led_3
//                k_3-|9 pb2          pb5 12|-led_4
//                k_4-|10_pb3_________pb4_11|-led_5
#include        "extern.h"
/****************************************************************************************************/
k_1                        bit                pb.0;
k_2                        bit                pb.1;
k_3                        bit                pb.2;
k_4                        bit                pb.3;
led_1                bit                pa.6;
led_2                bit                pb.7;
led_3                bit                pb.6;
led_4                bit                pb.5;
led_5                bit                pb.4;
/****************************************************************************************************/
void                zhengxianbo();                //正弦波
void                fuzhi();                        //赋值
void                anjian();                        //按键
void                yanshi();                        //延时
/****************************************************************************************************/
word                a1,b1,c1;
word                yanshi_a1;
/****************************************************************************************************/
void        FPPA0 (void)
{
.ADJUST_IC        SYSCLK=IHRC/4                //        SYSCLK=IHRC/4
pmode                31;                        ///8/8/8/8/8/8/8/8带宽共享
fppen        =        0xFF;                //8核全开有8个核心可以分时全部运行,可以分别干8件事8核真爽!
/****************************************************************************************************/
$                led_1                out,low;
$                k_1                        in,pull;
$                k_2                        in,pull;
/****************************************************************************************************/                //pwm配置
//f----------------0 f----------------0 f----------------0 f----------------0(word,int)
//f----------------0 f----------------0 f----------------0    //12位PWM0,1,2(左对齐)
// ↑上限(pwmcub)    ↑占空比(pwmdt)    |--死区(pwmdz)---|

//上限pwmcub=0xfff0,死区pwmdz=0xff,
//pwm0dtl(先写)pwm0dth,pwm1dtl(先写)pwm1dth,pwm2dtl(先写)pwm2dth,

//最大0xf010,        pwm_h=1+死区,    pwm_l=0,
//最小0x000,0x0010,  pwm_h=0,         pwm_l=1,
//PWM最大0x0fff-死区 =0xf000,
//PWM最小0x0000+2    =0x0020,
//pwm最大值取0xf000-0xff    =<0xef00高脉冲4us
//pwm最小值取0x0020+0xff    =>0x00ff高脉冲4us
/*
a1=0xf010;fuzhi();yanshi();
//a1=0x0000;fuzhi();yanshi();
a1=0x0010;fuzhi();yanshi();
a1=0xf000;fuzhi();yanshi();
a1=0x0020;fuzhi();yanshi();*/
/****************************************************************************************************/
$                pwmgc                enable,updown,reset;
$                pwmgm                protection_enable,ihrc,/4;
//pwmgc                =0b1_0_1_1_0000;                //PWMG控制寄存器位7,停用启用位6,输出状态位5,中心排列模式位4,PWM计数器清零

//pwmgm                =0b0_0_1_0_10_10;                //PWMG分频寄存器位7,上臂反极性位6,下臂反极性位5,臂保护位4,臂保护模式位32,PWM时钟源位10,PWM分频
//pwmgm                =0b0_0_1_0_10_11;                //PWMG分频寄存器

pwmgc1                =0b1_11_0_01_10;                //PWMG控制寄存器1位7,互补发生器位65,三相电机位4,读零位32,PWM5.PWM+位10,PWM4.PWM-

pwmgc2                =0b01_10_01_10;                //PWMG控制寄存器2位76,PWM3.PWM+位54,PWM2.PWM-位32,PWM1.PWM+位10,PWM0.PWM-

pwmcubl                =0b1111_0000;                //pwm上限寄存器l
pwmcubh                =0b1111_1111;                //pwm上限寄存器h

//pwmdz                =0b1111_0000;                //死区寄存器
pwmdz                =0b1111_1111;                //死区寄存器//*注意死区占上臂时间需要扣除

//pwm0dtl                =0b1111_0000;                //pwm0占空比低位寄存器//先写低位
//pwm0dth                =0b1111_1111;                //pwm0占空比高位寄存器

//pwm1dtl                =0b0000_0000;                //pwm1占空比低位寄存器//先写低位
//pwm1dth                =0b1000_0000;                //pwm1占空比高位寄存器

//pwm2dtl                =0b1111_0000;                //pwm2占空比低位寄存器//先写低位
//pwm2dth                =0b0000_0000;                //pwm2占空比高位寄存器

/****************************************************************************************************/
while (1)
{
if(led_1){led_1=0;}        else{led_1=1;}
.delay        10000;
}
}
/****************************************************************************************************/
void        FPPA1 (void)
{
while(1)
{
zhengxianbo();                //正弦波

}
}
/****************************************************************************************************/
void        FPPA2 (void)
{
yanshi_a1                =2000;
while(1)
{
anjian();
}
}
/****************************************************************************************************/
void        FPPA3 (void)
{
        goto        $;
}
/****************************************************************************************************/
void        FPPA4 (void)
{
        goto        $;
}
/****************************************************************************************************/
void        FPPA5 (void)
{
        goto        $;
}
/****************************************************************************************************/
void        FPPA6 (void)
{
        goto        $;
}
/****************************************************************************************************/
void        FPPA7 (void)
{
        goto        $;
}
/****************************************************************************************************/
/*
void        Interrupt (void)
{
        pushaf;

        if (Intrq.T16)
        {        //        T16 Trig
                //        User can add code
                Intrq.T16        =        0;
                //...
        }

        popaf;
}
*/
/****************************************************************************************************///使用spwm_calc生成幅值61184,周内点数48(52),对称,半波模式,
void                zhengxianbo()                //正弦波
{
while(1)
{

a1 =0x795D; b1 =0xE438; c1 =0x25D3; fuzhi(); yanshi();
// a1 =0x84C8; b1 =0xDF65; c1 =0x1DD4; fuzhi(); yanshi();
a1 =0x9010; b1 =0xD998; c1 =0x16A9; fuzhi(); yanshi();
// a1 =0x9B1C; b1 =0xD2DD; c1 =0x1063; fuzhi(); yanshi();
a1 =0xA5D0; b1 =0xCB46; c1 =0x0B11; fuzhi(); yanshi();
// a1 =0xB012; b1 =0xC2E4; c1 =0x06C0; fuzhi(); yanshi();
a1 =0xB9CC; b1 =0xB9CC; c1 =0x037A; fuzhi(); yanshi();
// a1 =0xC2E4; b1 =0xB012; c1 =0x06C0; fuzhi(); yanshi();
a1 =0xCB46; b1 =0xA5D0; c1 =0x0B11; fuzhi(); yanshi();
// a1 =0xD2DD; b1 =0x9B1C; c1 =0x1063; fuzhi(); yanshi();
a1 =0xD998; b1 =0x9010; c1 =0x16A9; fuzhi(); yanshi();
// a1 =0xDF65; b1 =0x84C8; c1 =0x1DD4; fuzhi(); yanshi();
a1 =0xE438; b1 =0x795D; c1 =0x25D3; fuzhi(); yanshi();
// a1 =0xE805; b1 =0x6DEB; c1 =0x2E92; fuzhi(); yanshi();
a1 =0xEAC2; b1 =0x628E; c1 =0x37FE; fuzhi(); yanshi();
// a1 =0xEC6A; b1 =0x5761; c1 =0x41FF; fuzhi(); yanshi();
a1 =0xECF7; b1 =0x4C7E; c1 =0x4C7E; fuzhi(); yanshi();
// a1 =0xEC6A; b1 =0x41FF; c1 =0x5761; fuzhi(); yanshi();
a1 =0xEAC2; b1 =0x37FE; c1 =0x628E; fuzhi(); yanshi();
// a1 =0xE805; b1 =0x2E92; c1 =0x6DEB; fuzhi(); yanshi();



a1 =0xE438; b1 =0x25D3; c1 =0x795D; fuzhi(); yanshi();
// a1 =0xDF65; b1 =0x1DD4; c1 =0x84C8; fuzhi(); yanshi();
a1 =0xD998; b1 =0x16A9; c1 =0x9010; fuzhi(); yanshi();
// a1 =0xD2DD; b1 =0x1063; c1 =0x9B1C; fuzhi(); yanshi();
a1 =0xCB46; b1 =0x0B11; c1 =0xA5D0; fuzhi(); yanshi();
// a1 =0xC2E4; b1 =0x06C0; c1 =0xB012; fuzhi(); yanshi();
a1 =0xB9CC; b1 =0x037A; c1 =0xB9CC; fuzhi(); yanshi();
// a1 =0xB012; b1 =0x06C0; c1 =0xC2E4; fuzhi(); yanshi();
a1 =0xA5D0; b1 =0x0B11; c1 =0xCB46; fuzhi(); yanshi();
// a1 =0x9B1C; b1 =0x1063; c1 =0xD2DD; fuzhi(); yanshi();
a1 =0x9010; b1 =0x16A9; c1 =0xD998; fuzhi(); yanshi();
// a1 =0x84C8; b1 =0x1DD4; c1 =0xDF65; fuzhi(); yanshi();
a1 =0x795D; b1 =0x25D3; c1 =0xE438; fuzhi(); yanshi();
// a1 =0x6DEB; b1 =0x2E92; c1 =0xE805; fuzhi(); yanshi();
a1 =0x628E; b1 =0x37FE; c1 =0xEAC2; fuzhi(); yanshi();
// a1 =0x5761; b1 =0x41FF; c1 =0xEC6A; fuzhi(); yanshi();
a1 =0x4C7E; b1 =0x4C7E; c1 =0xECF7; fuzhi(); yanshi();
// a1 =0x41FF; b1 =0x5761; c1 =0xEC6A; fuzhi(); yanshi();
a1 =0x37FE; b1 =0x628E; c1 =0xEAC2; fuzhi(); yanshi();
// a1 =0x2E92; b1 =0x6DEB; c1 =0xE805; fuzhi(); yanshi();


a1 =0x25D3; b1 =0x795D; c1 =0xE438; fuzhi(); yanshi();
// a1 =0x1DD4; b1 =0x84C8; c1 =0xDF65; fuzhi(); yanshi();
a1 =0x16A9; b1 =0x9010; c1 =0xD998; fuzhi(); yanshi();
// a1 =0x1063; b1 =0x9B1C; c1 =0xD2DD; fuzhi(); yanshi();
a1 =0x0B11; b1 =0xA5D0; c1 =0xCB46; fuzhi(); yanshi();
// a1 =0x06C0; b1 =0xB012; c1 =0xC2E4; fuzhi(); yanshi();
a1 =0x037A; b1 =0xB9CC; c1 =0xB9CC; fuzhi(); yanshi();
// a1 =0x0B11; b1 =0xCB46; c1 =0xA5D0; fuzhi(); yanshi();
a1 =0x1063; b1 =0xD2DD; c1 =0x9B1C; fuzhi(); yanshi();
// a1 =0x16A9; b1 =0xD998; c1 =0x9010; fuzhi(); yanshi();
a1 =0x1DD4; b1 =0xDF65; c1 =0x84C8; fuzhi(); yanshi();
// a1 =0x25D3; b1 =0xE438; c1 =0x795D; fuzhi(); yanshi();
a1 =0x2E92; b1 =0xE805; c1 =0x6DEB; fuzhi(); yanshi();
// a1 =0x37FE; b1 =0xEAC2; c1 =0x628E; fuzhi(); yanshi();
a1 =0x41FF; b1 =0xEC6A; c1 =0x5761; fuzhi(); yanshi();
// a1 =0x4C7E; b1 =0xECF7; c1 =0x4C7E; fuzhi(); yanshi();
a1 =0x5761; b1 =0xEC6A; c1 =0x41FF; fuzhi(); yanshi();
// a1 =0x628E; b1 =0xEAC2; c1 =0x37FE; fuzhi(); yanshi();
a1 =0x6DEB; b1 =0xE805; c1 =0x2E92; fuzhi(); yanshi();


}
}
/****************************************************************************************************/
void                fuzhi()                        //赋值
{
pwm0dtl                =a1 $0;                //先写
pwm0dth                =a1 $1;

pwm1dtl                =b1 $0;
pwm1dth                =b1 $1;

pwm2dtl                =c1 $0;
pwm2dth                =c1 $1;
}
/****************************************************************************************************/
void                yanshi()                        //延时
{
word                yanshi_b1;
yanshi_b1                =yanshi_a1;
while(yanshi_b1--){}
//while(k_1){.delay 1000;if(k_2==0){a1--;fuzhi();}}                //定在这
//while(!k_1){.delay 1000;}
}
/****************************************************************************************************/
void                anjian()                        //按键
{
if(k_1==0)
{
yanshi_a1++;
.delay 800;
}
if(k_2==0)
{
yanshi_a1--;
.delay 800;
}
}
/****************************************************************************************************/
/****************************************************************************************************/
/****************************************************************************************************/
/****************************************************************************************************/

pwm067.rar

2.36 KB

使用特权

评论回复

相关帖子

发新帖
您需要登录后才可以回帖 登录 | 注册

本版积分规则

300

主题

457

帖子

59

粉丝