搜索: 用户名:密码:
政策法规
国家产业政策 市级产业政策 省级产业政策 区级产业政策
当前位置电子学会首页 >> 政策法规 >> 市级产业政策 >>正文

基于L6219的脉宽调制细分技术的实现


作者:深圳市电子学会 来源:深圳市电子学会 2006-09-19 00:00:00
摘要:
基于L6219的脉宽调制细分技术的实现
 
刘德新  范再明
深圳信息职业技术学院电子通信技术系
 
摘  要:本文简要介绍了L6219的功能、电路设计和实现方法,重点介绍利用细分技术实现脉宽调制的新方法,并用单片机实现。此技术已经应用在自动注射泵中,取得了良好的效果。
ABSTRACT:This paper simply introduced L6219 function, circuit designed and completion methods, especially introduced a new method of subdivision technology to finish PWM, and apply with MCU. This technology has used at auto-syringe, and attained a very good effectiveness.
 
关键字:L6219,脉宽调制,细分,PCA
Key Word: L6219, PWM, Subdivision, PCA
 
概述
脉宽调制(PWM)目前在许多较为高档的单片机和DSP(数字信号处理)芯片中都已经出现,特别是在16位和32位的单片机中,例如:ARM芯片,AVR芯片等,几乎都有PWM,并且随着PWM技术的发展,其应用领域也越来越广阔。PWM的主要应用领域是较为高档的家用电器、机电、变频等领域,随着PWM的发展,PWM的应用将具有更为广阔的应用前景。
 
1 L6219的介绍及电路设计
1.1 L6219的性能介绍
L6219是一个有两极的集成电路,它能控制和驱动具有两极步进电机的绕组,还可以双向控制两个直流电机。L6219可以非常方便地与微处理器连接成控制步进电机的系统,其电压范围可以从10V~46V,输出的电流可达到750mA,峰值电流高达1A。因为内部具有保护二极管及PWM电流控制,所以在可靠性和稳定性方面提供了保障。
1.2 L6219电路的具体实现:
 
图1   用L6219与单片机的电路图
 
1.3 L6219的电路说明
L6219是一个24脚的芯片,功能说明如下:
1.3.1 PCA(Programmable Counter Array)的简介
P89V51RD内部含有一个PCA模块,输出复用P1口的P1.3、P1.4、P1.5、P1.6、P1.7。PCA有上升下降沿捕捉、定时、高速输出、看门狗、PWM输出5个工作模式,可通过编程控制P1.3——P1.7工作于任意模式。这里只对8位PWM输出模式做详细介绍,其他工作模式可参考相关资料。
1.3.2 PWM相关寄存器的介绍
PCA有一些相关的控制寄存器:计数模式寄存器(CMOD)、计数控制寄存器(CCON)PCA定时器(CH、CL)、工作模式寄存器(CCAPMn,其中n对应为:0、1、2、3、4)可对这些寄存器编程来控制PWM的输出。  
CMOD:计数模式寄存器
CIDL
WDTE
——
——
——
CPS1
CPS0
ECF
CCON:计数控制寄存器
CF
CR
——
CCF4
CCF3
CCF2
CCF1
CCF0
CCAPMn:工作模式寄存器
——
ECOMn
CAPPn
CAPNn
MATn
TOGn
PWMn
ECCFn
 
2细分技术
一般步进马达的当前位置是由磁场合成决定的,所以常用的方法是采用如图(b),是利用电压驱动时和线圈个数的关系,直接驱动它们,此时合成的最小角度都是固定的。这里采用的细分是电流细分,电流引起的磁场的合成就决定马达的角度。所以用电流合成图来代替磁场合成图,如图(a)电流矢量合成图,用控制电压的方式代替电流,在电压稳定后,线圈的电流和电压成正比,所以,用电流细分电路稳定,但是马达的速度也不能太高。
 
                                  Ib
                                  y                                                                Ia
 
                                                                                        A
 
 
                                                                                        A
                                                                                        
                                                                                                   B               B
                                                                    Ia                                                     Ib
x
 
 
                                         (a)                                                       (c)
 
图2-1  矢量合成图
 
 
 
 
 
                             Ib
                                    y
 
 
                                                                                                          A
 
 

                                                                                      Ia                  A
x
 
                                                                                            Vp                        B              B
 
 
                                      (b)                                                               (d)
 
图2-2  矢量合成图
 
3细分技术的实现
单片机实现时将0~360℃作细分,一个步距角度是1.8℃,首先根据矢量合成图建立相应的向量表,程序再根据向量表运行控制马达的旋转,可以是步距的1、2、4、8、16、……2n的倍数。
程序的具体实现如下:
#define PWM0enable(); CCAPM0|=0x42;           //配置P1.3引脚为PWM输出
#define PWM1enable(); CCAPM1|=0x42;           //配置P1.4引脚为PWM输出
#define PWM2enable(); CCAPM2|=0x42;           //配置P1.5引脚为PWM输出
#define PWM3enable(); CCAPM3|=0x42;           //配置P1.6引脚为PWM输出
#define PWM4enable(); CCAPM4|=0x42;           //配置P1.7引脚为PWM输出
 
#define PWM0disable(); CCAPM0&=0xBD; //停止P1.3引脚输出PWM
#define PWM1disable(); CCAPM1&=0xBD; //停止P1.4引脚输出PWM
#define PWM2disable(); CCAPM2&=0xBD; //停止P1.5引脚输出PWM
#define PWM3disable(); CCAPM3&=0xBD; //停止P1.6引脚输出PWM
#define PWM4disable(); CCAPM4&=0xBD; //停止P1.7引脚输出PWM
 
#define MotorIdel                 0x00                     //电机空闲模式
#define MotorPowerOn         0x01                     //电机上电
#define MotorNormalState     0x02                     //电机正常运转
#define MotorPowerOff        0x03                     //电机掉电
 
//定义细分表结构
typedef struct tagSubdivideTable{
       unsigned char mQuardrant;                        //象限0-3
       unsigned char mA_PWM;                          //A相输出的PWM
       unsigned char mB_PWM;                           //B相输出的PWM
}SubdivideTable;
 
typedef struct tagWorkInformation{
       unsigned int SubdivideTableID;                  //细分表ID
       unsigned char MotorDirect;                        //马达旋转方向
unsigned char SubdivideNumber;                       //细分倍数,这里的细分倍数就是访问细分表 //的步长,如果选用128倍细分,那么//SubdivideNumber=1,选用64倍细分,//SubdivideNumber=2
       unsigned int MotorSteps;                            //马达旋转总的步距,一个步距角1.8度
       unsigned char WorkState;                           //马达工作状态
unsigned char MaxStep;                                    //马达一个脉冲走过的最大步距,对应细分表//的间隔取值是:1、2、4、8、16...2的倍数
}WorkInformation;
 
sbit PhaseA = P1^4;
sbit PhaseB = P1^5;
#define Quardrant0 1                                      //+iA,+iB       第一象限
#define Quardrant1 2                                        //-iA,+iB        第二象限
#define Quardrant2 3                                        //-iA,-iB          第三象限
#define Quardrant3 4                                        //+iA,-iB         第四象限
WorkInformation MotorWorking;
                                                                      //细分表
//0-360度的细分,128倍细分表,iA=255*cos(a),iB=255*sin(a)
SubdivideTable code MotorSubdividedTab[]={
       //第一象限,    +iA,    +iB
       Quardrant3,    255, 0,
       Quardrant0,    255, 3,
       Quardrant0,    255, 6,
       Quardrant0,    255, 9,
       Quardrant0,    255, 13,
       Quardrant0,    255, 16,
       Quardrant0,    254, 19,
       Quardrant0,    254, 22,
       Quardrant0,    254, 25,
       Quardrant0,    253, 28,
       Quardrant0,    253, 31,
       Quardrant0,    253, 34,
       Quardrant0,    252, 37,
       Quardrant0,    252, 41,
       Quardrant0,    251, 44,
       Quardrant0,    251, 47,
       Quardrant0,    250, 50,
       Quardrant0,    249, 53,
       Quardrant0,    249, 56,
       Quardrant0,    248, 59,
       Quardrant0,    247, 62,
       Quardrant0,    247, 65,
       Quardrant0,    246, 68,
       Quardrant0,    245, 71,
       Quardrant0,    244, 74,
       Quardrant0,    243, 77,
       Quardrant0,    242, 80,
       Quardrant0,    241, 83,
       Quardrant0,    240, 86,
       Quardrant0,    239, 89,
       Quardrant0,    238, 92,
       Quardrant0,    237, 95,
       Quardrant0,    236, 98,
       Quardrant0,    234, 100,
       Quardrant0,    233, 103,
       Quardrant0,    232, 106,
       Quardrant0,    231, 109,
       Quardrant0,    229, 112,
       Quardrant0,    228, 115,
       Quardrant0,    226, 117,
       Quardrant0,    225, 120,
       Quardrant0,    223, 123,
       Quardrant0,    222, 126,
       Quardrant0,    220, 128,
       Quardrant0,    219, 131,
       Quardrant0,    217, 134,
       Quardrant0,    215, 136,
       Quardrant0,    214, 139,
       Quardrant0,    212, 142,
       Quardrant0,    210, 144,
       Quardrant0,    208, 147,
       Quardrant0,    207, 149,
       Quardrant0,    205, 152,
       Quardrant0,    203, 154,
       Quardrant0,    201, 157,
       Quardrant0,    199, 159,
       Quardrant0,    197, 162,
       Quardrant0,    195, 164,
       Quardrant0,    193, 167,
       Quardrant0,    191, 169,
       Quardrant0,    189, 171,
       Quardrant0,    187, 174,
       Quardrant0,    185, 176,
       Quardrant0,    183, 178,
       Quardrant0,    180, 180,
       Quardrant0,    178, 183,
       Quardrant0,    176, 185,
       Quardrant0,    174, 187,
       Quardrant0,    171, 189,
       Quardrant0,    169, 191,
       Quardrant0,    167, 193,
       Quardrant0,    164, 195,
       Quardrant0,    162, 197,
       Quardrant0,    159, 199,
       Quardrant0,    157, 201,
       Quardrant0,    154, 203,
       Quardrant0,    152, 205,
       Quardrant0,    149, 207,
       Quardrant0,    147, 208,
       Quardrant0,    144, 210,
       Quardrant0,    142, 212,
       Quardrant0,    139, 214,
       Quardrant0,    136, 215,
       Quardrant0,    134, 217,
       Quardrant0,    131, 219,
       Quardrant0,    128, 220,
       Quardrant0,    126, 222,
       Quardrant0,    123, 223,
       Quardrant0,    120, 225,
       Quardrant0,    117, 226,
       Quardrant0,    115, 228,
       Quardrant0,    112, 229,
       Quardrant0,    109, 231,
       Quardrant0,    106, 232,
       Quardrant0,    103, 233,
       Quardrant0,    100, 234,
       Quardrant0,    98,   236,
       Quardrant0,    95,   237,
       Quardrant0,    92,   238,
       Quardrant0,    89,   239,
       Quardrant0,    86,   240,
       Quardrant0,    83,   241,
       Quardrant0,    80,   242,
       Quardrant0,    77,   243,
       Quardrant0,    74,   244,
       Quardrant0,    71,   245,
       Quardrant0,    68,   246,
       Quardrant0,    65,   247,
       Quardrant0,    62,   247,
       Quardrant0,    59,   248,
       Quardrant0,    56,   249,
       Quardrant0,    53,   249,
       Quardrant0,    50,   250,
       Quardrant0,    47,   251,
       Quardrant0,    44,   251,
       Quardrant0,    41,   252,
       Quardrant0,    37,   252,
       Quardrant0,    34,   253,
       Quardrant0,    31,   253,
       Quardrant0,    28,   253,
       Quardrant0,    25,   254,
       Quardrant0,    22,   254,
       Quardrant0,    19,   254,
       Quardrant0,    16,   255,
       Quardrant0,    13,   255,
       Quardrant0,    9,    255,
       Quardrant0,    6,    255,
       Quardrant0,    3,    255,
       //第二象限   -iA,  +iB
       Quardrant0,    0,    255,
       Quardrant1,    3,    255,
       Quardrant1,    6,    255,
       Quardrant1,    9,    255,
       Quardrant1,    13,   255,
       Quardrant1,    16,   255,
       Quardrant1,    19,   254,
       Quardrant1,    22,   254,
       Quardrant1,    25,   254,
       Quardrant1,    28,   253,
       Quardrant1,    31,   253,
       Quardrant1,    34,   253,
       Quardrant1,    37,   252,
       Quardrant1,    41,   252,
       Quardrant1,    44,   251,
       Quardrant1,    47,   251,
       Quardrant1,    50,   250,
       Quardrant1,    53,   249,
       Quardrant1,    56,   249,
       Quardrant1,    59,   248,
       Quardrant1,    62,   247,
       Quardrant1,    65,   247,
       Quardrant1,    68,   246,
       Quardrant1,    71,   245,
       Quardrant1,    74,   244,
       Quardrant1,    77,   243,
       Quardrant1,    80,   242,
       Quardrant1,    83,   241,
    &n

最新评论

我要评论

昵称:   

在线咨询

备案/许可证编号:粤ICP备 13069091号

粤公网安备 44030502003191号