乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      請教馬老師關(guān)于PWM輸出問題 中國電子開發(fā)網(wǎng)(www.ourdev.cn)

       ylw527 2010-11-02
      產(chǎn)生SPWM用于逆變器控制H橋,從而產(chǎn)生頻率和電壓幅值可變的正弦波輸出

      思路是:用MEGA16的定時器1產(chǎn)生SPWM輸出,每個采樣點時刻的占空比存入這個數(shù)組sin_temp[j]=0.5+0.5*M*sin(j*2*PI/N);如果采用pwm輸出模式8的話,則ICR1的值為TOP值,那么OCR1A,OCR1B中的寄存器值就為 (uint)(TOP*sin_temp[i]),我想在進(jìn)入比較匹配中斷的時候(或者溢出中斷的時候)改變OCR1A,OCR1B的值,這樣輸出就能產(chǎn)生兩路互補的SPWM波,其中ICR1的值改變載波頻率,M為調(diào)制度(用于改變電壓幅值),N為載波比(改變輸出電壓頻率)
      但是我調(diào)試了好久都是只輸出一個固定占空比的PWM

      這是我的調(diào)試程序:

      #include<iom16v.h>
      #include<macros.h>
      #include<math.h>

      #define uint unsigned int
      #define uchar unsigned char

      #define PI 3.1415926
      #define N 60   //載波比
      #define FS 50  //基波頻率
      #define M 0.5  //調(diào)制比
      #define FCLK 8000000//晶振
      #define DeadTime 16  //死區(qū)時間控制系數(shù)

      float sin_temp[N];//占空比
      uint TOP1;
      uint temp[N];
      uchar count=1;

      void port_init(void)
      {
        DDRD|=BIT(4)|BIT(5);// OC1A,OC1B互補輸出
      }

      void timer1_init(void)
      {    
         TCCR1A=0XB0;//1011 0000  OC1A,OC1B互補輸出
       //TCCR1A=0XB3;
       TCCR1B=0X10;//0001 0000,PWM模式8,關(guān)定時器
       //TIMSK|=BIT(TOIE1);  //開輸入捕捉中斷
       TIMSK|=BIT(OCIE1A)|BIT(OCIE1B);//比較匹配中斷
       //TIMSK|=BIT(TICIE1);//輸入捕獲中斷開
       ICR1=(uint)(FCLK/(2*N*FS));
       OCR1A=temp[0]-DeadTime;
       OCR1B=temp[0]+DeadTime;
      }

      /*#pragma interrupt_handler t1_capt: 6  // T/C1的輸入捕捉中斷
      void t1_capt(void)
      {
       
         OCR1A=(uint)(TOP1*sin_temp[count++])-DeadTime;
      OCR1B=(uint)(TOP1*sin_temp[count++])+DeadTime;
      PORTB^=BIT(3);

        if(count>N) count=0;  
      }

      #pragma interrupt_handler timer1_ovf:9 //T/C1的溢出中斷
      void timer1_ovf(void)
      {
           count++;
       if(count<=N)
       {
          //OCR1A=(uint)(TOP1*sin_temp[i])-DeadTime;
          //OCR1B=(uint)(TOP1*sin_temp[i])+DeadTime;
      OCR1A=temp[count]-DeadTime;
      OCR1B=temp[count]+DeadTime;
      PORTB^=BIT(3);

       }
       else
       count=0;
      }*/


      #pragma interrupt_handler timer1_compa:7//比較匹配A中斷
      void timer1_compa(void)
      {
       if(count<=N)
       {
      OCR1A=temp[count++]-DeadTime;
       }
       else
       count=0;
      }

      #pragma interrupt_handler timer1_compb:8//比較匹配B中斷
      void timer1_compb(void)
      {
       if(count<=N)
       {
      OCR1B=temp[count++]+DeadTime;
       }
       else
       count=0;
      }

      void main(void)
      {
         uchar j;
       CLI();
       TOP1=(uint)(FCLK/(2*N*FS));
       port_init();
       for(j=0;j<N;j++)
       {
          sin_temp[j]=0.5+0.5*M*sin(j*2*PI/N);//各采樣點的占空比
       temp[j]=(uint)(TOP1*sin_temp[j]);
       }
       
       timer1_init();
       TIFR=0;
       TCNT1=0;
       SEI();//開總中斷
       TCCR1B=0X11;//PWM模式8,開定時器
       DDRB|=BIT(3);
       PORTB&=~BIT(3);
       while(1);
      }

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多