<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 51單片機實現(xiàn)直流電機的調(diào)速控制

          51單片機實現(xiàn)直流電機的調(diào)速控制

          作者: 時間:2016-11-26 來源:網(wǎng)絡(luò) 收藏
          前一段時間一直拿一個開發(fā)板練習(xí)51,覺得對AD還不是很熟練,就想單獨畫一塊板子,圖都做完了一查價錢,小小的一個樣板就要上百,實在有點舍不得,就先再proteus上仿真了一下,然后準(zhǔn)備在萬用板上搭電路。

          電路圖如下

          本文引用地址:http://www.ex-cimer.com/article/201611/321819.htm



          占空比18%-82%連續(xù)可調(diào),通過調(diào)節(jié)電路中的電位器實現(xiàn)。

          做了單定時器控制和雙定時器控制兩個程序,電路圖一樣。

          單定時器控制程序

          #include //
          #include
          int count0=1000;
          bit A=0;
          sbit IN1=P3^4;
          sbit IN2=P3^5;
          sbit INTR=P3^2;
          sbit wr=P3^6;
          sbit rd=P3^7;
          sbit PB1=P3^0;
          int T0_H,T0_L;
          char TAB[11]={0xc0,0xf9,0xa4,0xb0,0x99,
          0x92,0x82,0xf8,0x80,0x90,0xff};
          void delay(int);
          void display(void);
          main()
          {int i,DATA;
          IE=0x82;
          TMOD=0x01;
          T0_H=(65535-count0)/256;
          T0_L=(65535-count0)%6;
          TH0=T0_H;
          TL0=T0_L;
          IN1=0;
          IN2=1;
          TR0=1;
          P2=0xff;
          while(1)
          {INTR=1;
          wr=1;
          rd=1;
          P0=0xff;
          PB1=1;
          wr=0;
          _nop_();
          wr=1;
          _nop_();
          while(INTR==1);
          for(i=0;i<10;i++)
          {_nop_();}
          rd=0;
          _nop_();
          DATA=P0;
          wr=1;
          DATA=DATA<<5;
          count0=1000+DATA;
          display();
          }
          }

          void t0(void)interrupt 1
          {if(A==0)
          {
          T0_H=(65535-count0)/256;
          T0_L=(65535-count0)%6;
          TH0=T0_H;
          TL0=T0_L;
          IN1=~IN1;IN2=0;
          A=1;
          }
          else
          {
          T0_H=(55535+count0)/256;
          T0_L=(55535+count0)%6;
          TH0=T0_H;
          TL0=T0_L;
          IN1=~IN1;IN2=0;
          A=0;
          }

          }

          void display(void)
          {int i,j,per,scan;
          per=count0;
          if(per<2700)per=per+650;
          else if((per>2700)&(per<4400))per=per+250;
          else if((per>5800)&(per<6700))per=per-250;
          else if(per>6700)per=per-650;
          scan=0x03;
          for(i=0;i<4;i++)
          {j=per;
          P1=scan;
          P2=TAB[j];
          delay(4);
          per=per/10;
          scan=scan-1;
          }
          }
          void delay(int x)
          {int i,j;
          for(i=0;ifor(j=0;j<120;j++);
          }

          雙定時器控制的程序

          #include //
          #include
          #define LED P2
          int count1=0;
          int count0=10000;
          #define T0_H (65535-count0)/256
          #define T0_L (65535-count0)%6
          #define T1_H (65535-count1)/256
          #define T1_L (65535-count1)%6
          sbit IN1=P3^4;
          sbit IN2=P3^5;
          sbit INTR=P3^2;
          sbit wr=P3^6;
          sbit rd=P3^7;
          char TAB[11]={0xc0,0xf9,0xa4,0xb0,0x99,
          0x92,0x82,0xf8,0x80,0x90,0xff};
          void delay(int);//1ms
          void display(void);
          void T(int);
          main()
          {int i;
          unsigned char DATA;
          IE=0x8a;
          TMOD=0x11;
          TH0=T0_H;TL0=T0_L;
          TH1=T1_H;TL1=T1_L;
          TR0=0;
          TR1=1;
          IN1=1;
          IN2=0;
          P2=0xff;
          while(1)
          {INTR=1;wr=1;rd=1;
          P0=0xff;
          wr=0;
          _nop_();
          wr=1;
          _nop_();
          _nop_();
          while(INTR==1);
          for(i=0;i<10;i++)
          {_nop_();}
          rd=0;
          _nop_();
          _nop_();
          DATA=P0;
          wr=1;
          T(DATA);
          display();
          }
          }
          void t1(void)interrupt 3
          {TH1=T1_H;TL1=T1_L;
          IN1=0;
          TR0=1;
          TR1=0;
          }
          void t0(void)interrupt 1
          {count0=10000-count1;
          TH0=T0_H;TL0=T0_L;
          IN1=1;
          TR1=1;
          TR0=0;
          }
          void T(int Tw)
          { Tw=Tw<<5;
          count1=1000+Tw;
          }
          void display(void)
          {int i,j,per,scan;
          per=count1;
          if(per<2650)per=per+300;
          else if(per>5890)per=per-300;
          scan=0x03;
          for(i=0;i<4;i++)
          {j=per;
          P1=scan;
          LED=TAB[j];
          delay(4);
          per=per/10;
          scan=scan-1;
          }
          }
          void delay(int x)
          {int i,j;
          for(i=0;ifor(j=0;j<120;j++);
          }
          不足之處:這兩種方法實現(xiàn)都有一個問題,輸出PWM波的周期時長與期望有一定相差,期望一周期10ms,仿真后得到波形周期為12.5ms左右,具體的解決辦法不是很清楚,希望有高人路過,不吝賜教!



          評論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();