打印

help:2407对称pwm波发的不正确

[复制链接]
2044|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
snakeemail|  楼主 | 2007-12-27 19:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
snakeemail|  楼主 | 2007-12-29 14:02 | 只看该作者

程序代码如下

设置的是Time1加减计数,下溢中断时取反一个引脚观察,结果发现Time1的pwm的脉冲不是和等腰三角形对称的,偏到了一边.从示波器上可以看到,PWM的脉宽时间是对的,下溢中断取反的引脚周期时间也是对的,就是不对称
void Timer1_Initializing()
{
        EVAIMRA = EVAIMRA | 0x0200;                // 允许定时器1的下溢中断 P265
/*     0000,0010,0000,0000 =0x0200
       0000 0~~~ ~~~~ ~~~~ [reserved]
        ~~~~ ~0~~ ~~~~ ~~~~ [T1OFINT ENABLE] 上溢中断
        ~~~~ ~~1~ ~~~~ ~~~~ [T1UFINT ENABLE] UnderFlow 下溢中断
        ~~~~ ~~~0 ~~~~ ~~~~ [T1CINT ENABLE] 定时器1比较
        ~~~~ ~~~~ 0~~~ ~~~~ [T1PINT ENABLE]1:允许定时器1的周期中断  
       ~~~~ ~~~~ ~000 ~~~~ [reserved]        
       ~~~~ ~~~~ ~~~~ 0~~~ [CMP3INT ENABLE] 
        ~~~~ ~~~~ ~~~~ ~0~~ [CMP2INT ENABLE]         
        ~~~~ ~~~~ ~~~~ ~~0~ [CMP1INT ENABLE]         
        ~~~~ ~~~~ ~~~~ ~~~0 [PDPINTA ENABLE] 
*/        

        EVAIFRA = EVAIFRA & 0x0200;                // 清除定时器1周期中断标志 P262
/*  0000,0010,1000,0000 =0x0080
        0000 0~~~ ~~~~ ~~~~ [reserved]
        ~~~~ ~0~~ ~~~~ ~~~~ [T1OFINT FLAG] 
        ~~~~ ~~1~ ~~~~ ~~~~ [T1UFINT FLAG] UnderFlow标志
        ~~~~ ~~~0 ~~~~ ~~~~ [T1CINT FLAG] 
        ~~~~ ~~~~ 1~~~ ~~~~ [T1PINT FLAG]1:清除定时器1周期中断标志
        ~~~~ ~~~~ ~000 ~~~~ [reserved]
        ~~~~ ~~~~ ~~~~ 0~~~ [CMP3INT FLAG] 
        ~~~~ ~~~~ ~~~~ ~0~~ [CMP2INT FLAG]         
        ~~~~ ~~~~ ~~~~ ~~0~ [CMP1INT FLAG]         
        ~~~~ ~~~~ ~~~~ ~~~0 [PDPINTA FLAG] 
*/        
        T1CON=0x080E;                //P277  Timer1为连续增/减计数模式,预分频值为1,使用内部时钟
/*  0000,1000,0000,0010 =0x170C
        00~~ ~~~~ ~~~~ ~~~~ [Free,Soft] 00:一旦仿真挂起后,定时器1立即停止
       ~~0~ ~~~~ ~~~~ ~~~~ [reserved] 
        ~~~0 1~~~ ~~~~ ~~~~ [TMODE1,TMODE0] 01:连续增/减计数模式 10: 连续增计数模式 
       ~~~~ ~000 ~~~~ ~~~~ [TPS2-TPS0] 111:预定标系数, x/128
        ~~~~ ~~~~ 0~~~ ~~~~ [T2SWT1] 0:定时器2使用自身的周期寄存器  
        ~~~~ ~~~~ ~0~~ ~~~~ [TENABLE] 0: 定时器1不工作
        ~~~~ ~~~~ ~~00 ~~~~ [ TCLKS1, TCLKS0] 00: 使用内部CPU时钟 
        ~~~~ ~~~~ ~~~~ 11~~ [TCLD1, TCLD0] 00: 当计数值为0,重装载, 11: 保留         
        ~~~~ ~~~~ ~~~~ ~~1~ [TECMPR] 0: 禁止定时器比较操作         
        ~~~~ ~~~~ ~~~~ ~~~0 [SELT1PR]0: 该位在定时器1中保留
*/
        
        T1PER = 800;                                // 周期寄存器值设为 800:32M,        

        T1CNT=0x000;                                        // Timer1的计数器清零

        GPTCONA = 0x004A;
//  0000 0000 0100 1010
//        0~~~ ~~~~ ~~~~ ~~~~ 保留
//        ~0~~ ~~~~ ~~~~ ~~~~ 定时器状态2
//        ~~0~ ~~~~ ~~~~ ~~~~ 定时器状态1
//        ~~~0 0~~~ ~~~~ ~~~~ 保留
//        ~~~~ ~00~ ~~~~ ~~~~ 00:不启动AD
//        ~~~~ ~~~0 0~~~ ~~~~ 00:不启动AD
//        ~~~~ ~~~~ ~1~~ ~~~~ 1:允许定时器的比较输出
//        ~~~~ ~~~~ ~~00 ~~~~ 保留
//        ~~~~ ~~~~ ~~~~ 10~~ 定时器2输出极性 10:高有效
//        ~~~~ ~~~~ ~~~~ ~~10 定时器1输出极性 10:高有效

        T1CMP = 64;
}

void interrupt INT2()
{

        switch(PIVR)        // 由外设中断向量寄存器PIVR判断
    {                                                        
          case 0x0029: //下溢中断
                                  EVAIFRA = EVAIFRA & 0x0200;//清中断标志
                           PFDATDIR = PFDATDIR ^ 0x0004;              //取反一个引脚,便于观察,
                          break;
            default: break;                 
                                                      
        }

}
相关链接:https://bbs.21ic.com/upfiles/img/200712/2007122914043500.zip

使用特权

评论回复
板凳
snakeemail|  楼主 | 2007-12-30 21:12 | 只看该作者

俺在想,是否和仿真有关系

因为事件比较器是硬件比较的,而我中断里面取反引脚是外部ram仿真运行的

使用特权

评论回复
地板
snakeemail|  楼主 | 2008-1-4 19:34 | 只看该作者

果然,烧到flash好多了,闻亭的仿真器有问题,下个星期继续

使用特权

评论回复
5
snakeemail|  楼主 | 2008-1-7 10:20 | 只看该作者

nnd

烧到flash里,现在倒是没有完全偏到一边了,但还是不和中心对称,还是延后了1us

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

547

主题

1910

帖子

8

粉丝