اطلاعیه

Collapse
No announcement yet.

موج PWM برای تایمر یک

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    موج PWM برای تایمر یک

    سلام
    من برنامه زیر رو برای FAST PWM تایمر یک نوشتم اما کار نمیکنه میشه لطفا ایرادشو بگین
    کد:
    
    #include <mega32.h>
    
    // Declare your global variables here
    
    void main(void)
    {
    // Declare your local variables here
    
    // Input/Output Ports initialization
    // Port A initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTA=0x00;
    DDRA=0x00;
    
    // Port B initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTB=0x00;
    DDRB=0xFF;
    
    // Port C initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTC=0x00;
    DDRC=0x00;
    
    // Port D initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTD=0xFF;
    DDRD=0xFF;
    
    // Timer/Counter 0 initialization
    // Clock source: System Clock
    // Clock value: Timer 0 Stopped
    // Mode: Normal top=0xFF
    // OC0 output: Disconnected
    TCCR0=0x00;
    TCNT0=0x00;
    OCR0=0x00;
    
    // Timer/Counter 1 initialization
    // Clock source: System Clock
    // Clock value: 7.813 kHz
    // Mode: Fast PWM top=0x00FF
    // OC1A output: Discon.
    // OC1B output: Discon.
    // Noise Canceler: Off
    // Input Capture on Falling Edge
    // Timer1 Overflow Interrupt: Off
    // Input Capture Interrupt: Off
    // Compare A Match Interrupt: Off
    // Compare B Match Interrupt: Off
    TCCR1A=0x01;
    TCCR1B=0x0D;
    TCNT1H=0x00;
    TCNT1L=0x00;
    ICR1H=0x00;
    ICR1L=0x00;
    OCR1AH=0x00;
    OCR1AL=0x00;
    OCR1BH=0x00;
    OCR1BL=0x00;
    
    // Timer/Counter 2 initialization
    // Clock source: System Clock
    // Clock value: Timer2 Stopped
    // Mode: Normal top=0xFF
    // OC2 output: Disconnected
    ASSR=0x00;
    TCCR2=0x00;
    TCNT2=0x00;
    OCR2=0x00;
    
    // External Interrupt(s) initialization
    // INT0: Off
    // INT1: Off
    // INT2: Off
    MCUCR=0x00;
    MCUCSR=0x00;
    
    // Timer(s)/Counter(s) Interrupt(s) initialization
    TIMSK=0x00;
    
    // USART initialization
    // USART disabled
    UCSRB=0x00;
    
    // Analog Comparator initialization
    // Analog Comparator: Off
    // Analog Comparator Input Capture by Timer/Counter 1: Off
    ACSR=0x80;
    SFIOR=0x00;
    
    // ADC initialization
    // ADC disabled
    ADCSRA=0x00;
    
    // SPI initialization
    // SPI disabled
    SPCR=0x00;
    
    // TWI initialization
    // TWI disabled
    TWCR=0x00;
    
    while (1)
       {
    
    
    OCR1AL=90; // 20% Duty Cycle on PD.5
    OCR1BL=255; //100% Duty Cycle on PD.4
       }
    }

    #2
    پاسخ : موج PWM برای تایمر یک

    مشکلش دقیقا چیه ؟ کلا نشون نمیده یا غلط نشون میده ؟
    فایل سورس و شبیه سازی رو بزار تا یه نگاه منم
    اگه بلد باشم حتما کمک میکنم
    *****برای آدمی بهتر است که اصلا به دنیا نیاید تا اینکه بیایدو هیچ تاثیری نگذارد *****
    ناپلئون بناپارت

    دیدگاه


      #3
      پاسخ : موج PWM برای تایمر یک

      سلام
      مشکلتون اینه که خروجی ها رو تعیین نکردید ...
      توی کدویزارد باید OutA , OutB را خروجی کنید و تعیین کنید که خروجی معکوس گر باشد یا غیر معکوس گر (عادی)
      کدتون اینه ...
      کد:
      #include <mega328.h>
      
      // Declare your global variables here
      
      void main(void)
      {
      // Declare your local variables here
      
      // Crystal Oscillator division factor: 1
      #pragma optsize-
      CLKPR=0x80;
      CLKPR=0x00;
      #ifdef _OPTIMIZE_SIZE_
      #pragma optsize+
      #endif
      
      // Input/Output Ports initialization
      // Port B initialization
      // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=Out Func1=Out Func0=In 
      // State7=T State6=T State5=T State4=T State3=T State2=0 State1=0 State0=T 
      PORTB=0x00;
      DDRB=0x06;
      
      // Port C initialization
      // Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
      // State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
      PORTC=0x00;
      DDRC=0x00;
      
      // Port D initialization
      // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
      // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
      PORTD=0x00;
      DDRD=0x00;
      
      // Timer/Counter 0 initialization
      // Clock source: System Clock
      // Clock value: Timer 0 Stopped
      // Mode: Normal top=0xFF
      // OC0A output: Disconnected
      // OC0B output: Disconnected
      TCCR0A=0x00;
      TCCR0B=0x00;
      TCNT0=0x00;
      OCR0A=0x00;
      OCR0B=0x00;
      
      // Timer/Counter 1 initialization
      // Clock source: System Clock
      // Clock value: 0.977 kHz
      // Mode: Fast PWM top=0x00FF
      // OC1A output: Non-Inv.
      // OC1B output: Non-Inv.
      // Noise Canceler: Off
      // Input Capture on Falling Edge
      // Timer1 Overflow Interrupt: Off
      // Input Capture Interrupt: Off
      // Compare A Match Interrupt: Off
      // Compare B Match Interrupt: Off
      TCCR1A=0xA1;
      TCCR1B=0x0D;
      TCNT1H=0x00;
      TCNT1L=0x00;
      ICR1H=0x00;
      ICR1L=0x00;
      OCR1AH=0x00;
      OCR1AL=0x00;
      OCR1BH=0x00;
      OCR1BL=0x00;
      
      // Timer/Counter 2 initialization
      // Clock source: System Clock
      // Clock value: Timer2 Stopped
      // Mode: Normal top=0xFF
      // OC2A output: Disconnected
      // OC2B output: Disconnected
      ASSR=0x00;
      TCCR2A=0x00;
      TCCR2B=0x00;
      TCNT2=0x00;
      OCR2A=0x00;
      OCR2B=0x00;
      
      // External Interrupt(s) initialization
      // INT0: Off
      // INT1: Off
      // Interrupt on any change on pins PCINT0-7: Off
      // Interrupt on any change on pins PCINT8-14: Off
      // Interrupt on any change on pins PCINT16-23: Off
      EICRA=0x00;
      EIMSK=0x00;
      PCICR=0x00;
      
      // Timer/Counter 0 Interrupt(s) initialization
      TIMSK0=0x00;
      
      // Timer/Counter 1 Interrupt(s) initialization
      TIMSK1=0x00;
      
      // Timer/Counter 2 Interrupt(s) initialization
      TIMSK2=0x00;
      
      // USART initialization
      // USART disabled
      UCSR0B=0x00;
      
      // Analog Comparator initialization
      // Analog Comparator: Off
      // Analog Comparator Input Capture by Timer/Counter 1: Off
      ACSR=0x80;
      ADCSRB=0x00;
      DIDR1=0x00;
      
      // ADC initialization
      // ADC disabled
      ADCSRA=0x00;
      
      // SPI initialization
      // SPI disabled
      SPCR=0x00;
      
      // TWI initialization
      // TWI disabled
      TWCR=0x00;
      
      while (1)
         {
      OCR1AL=90; // 20% Duty Cycle on PD.5
      OCR1BL=255; //100% Duty Cycle on PD.4
      
         }
      در ضمن خروجی های شما B.1 و B.2 هست نه D.4 و D.5 !!!

      موفق باشید
      [b]چگونه همه پایه های میکروکنترلر AVR را PWM کنیم؟
      معرفی نرم افزارEasy 7segment (برای راه اندازی آسانتر 7segment )
      معرفی نرم افزار Codewizard PWM
      با من بیشتر آشنا شوید

      دیدگاه

      لطفا صبر کنید...
      X