اطلاعیه

Collapse
No announcement yet.

علت error برنامه آردوینو

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

    علت error برنامه آردوینو

    سلام خدمت دوستان و اساتید
    برنامه زیر رو خط :
    TCCR2B | = (1<<CS21); // Prescaler at 8.
    error می ده دلیلش چی می تونه باشه؟ سپاس از پاسخ شما




     
    int f_signal=50; // Hz. Frequency desired for the output sine.
    int f_pwm=62500; // Hz. PWM frequency.
    // int TOP (int) (16000000/f_pwm)-1; // Top value for the resolution selected.
    int TOP= 255;
    //int n= (TOP * 2); // Length of the array.
    int n= 510;
    //int fs = n / 0.02; // Hz. Sampling frequency.
    int i=0; // Cursor 1
    int j= n/2. +1; // Cursor 2. The voltages must be 180 degrees shifted.
    int dutycycle [510]; // Array that contains the values for the dutycycle.
    // int dutycycle [n]; // It only works if the value is defined manually.
    void setup () {
    // PIN DEFINITION.
    pinMode (9, OUTPUT);
    pinMode (10, OUTPUT);
    for (i=0; i<=n; i++)
    {
    dutycycle[i] = (int) ( (1 + sin (2.* PI *i/n ))* (TOP/2) + 0.5);
    }
    cli ( ); // Deactivating global interruptions
    TCNT1= 0; // Initialize counter value to zero.
    TCCR1A = (1<<COM1A1) | (1<<COM1B1) | (1<<WGM11);
    // Non-inverting, fast PWM MODE. Clear OC1A/OC1B on Compare match. Mode 14.
    TCCR1B= (1<<WGM13) | (1<<WGM12) | (1<<CS10);
    // Counts from the bottom to the top and then decreases. No prescaling.
    // ICR1= (int) (16000000 / f_pwm)-1;
    // Overflow value. It sets the resolution of the PWM.
    ICR1=TOP;
    // In case another PWM frequency is desired, this value must be changed.
    OCR1A= dutycycle[i]; // Dutycycle for pin 9
    OCR1B= dutycycle[j]; // Dutycycle for pin 10
    TCCR2A=0; // Setting the entire registers to zero.
    TCCR2B=0;
    TCCR2A | = (1<<WGM21); // Turn on Comparing Output Mode, non PWM.
    TCCR2B | = (1<<CS21); // Prescaler at 8.
    // In case it is changed, the formula below must be changed to the new prescaler.
    //OCR2A = (byte) ((16000000 / (fs * 8) ) - 1);
    // Number of pulses it counts until the interruption is activated.
    OCR2A= 78;
    TIMSK2 |= (1 << OCIE2A); // Timer 2 Output Compare Match A Interrupt Enable
    sei ( ); // Global interruption activation
    } //setup
    void loop ( ) {
    }
    ISR (TIMER2_COMPA_vect) {
    if (i<= n-1)
    {
    OCR1A= dutycycle [i];
    i++;
    }
    else { i=0; } ;
    if ( j<= n-1)
    {
    OCR1B= dutycycle[j];
    j++;
    }
    else { j=0;}
    }

    #2
    پاسخ : علت error برنامه آردوینو

    نوشته اصلی توسط mohsen74 نمایش پست ها
    سلام خدمت دوستان و اساتید
    برنامه زیر رو خط :
    TCCR2B | = (1<<CS21); // Prescaler at 8.
    error می ده دلیلش چی می تونه باشه؟ سپاس از پاسخ شما
    خط 34 و 35
    سلام در دو جا اشتباهی به جای |= از | = استفاده کردید بین این دو تا علامت نباید فاصله باشه!!!!
    ارادت داریم!


    دیدگاه


      #3
      پاسخ : علت error برنامه آردوینو

      سپاس مهندس برنامه کامپایل می شه ولی اون قسمت

      [COLOR=#008200][FONT=Consolas]//int n= (TOP * 2);[/FONT][/COLOR]

      تو خط پنج رو باید بصورت بدون دابل بک اسلش بذارم تا برنامه خروجی درستی بده اما تو این حالت خط 6 error می ده دلیلش چی می تونه باشه؟
      برنامه:

      [COLOR=#28282B][FONT=Consolas]int f_signal=50; // Hz. Frequency desired for the output sine.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] int f_pwm=62500; // Hz. PWM frequency.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] // int TOP (int) (16000000/f_pwm)-1; // Top value for the resolution selected.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] int TOP= 255;[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas][COLOR=#008200]int n= (TOP * 2); // Length of the array.[/COLOR][/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] int n= 510;[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] //int fs = n / 0.02; // Hz. Sampling frequency.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] int i=0; // Cursor 1[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] int j= n/2. +1; // Cursor 2. The voltages must be 180 degrees shifted.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] int dutycycle [510]; // Array that contains the values for the dutycycle.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] // int dutycycle [n]; // It only works if the value is defined manually.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] void setup () {[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] // PIN DEFINITION.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] pinMode (9, OUTPUT);[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] pinMode (10, OUTPUT);[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] for (i=0; i<=n; i++)[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] {[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] dutycycle[i] = (int) ( (1 + sin (2.* PI *i/n ))* (TOP/2) + 0.5);[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] }[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] cli ( ); // Deactivating global interruptions[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] TCNT1= 0; // Initialize counter value to zero.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] TCCR1A = (1<<COM1A1) | (1<<COM1B1) | (1<<WGM11);[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] // Non-inverting, fast PWM MODE. Clear OC1A/OC1B on Compare match. Mode 14.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] TCCR1B= (1<<WGM13) | (1<<WGM12) | (1<<CS10);[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] // Counts from the bottom to the top and then decreases. No prescaling.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] // ICR1= (int) (16000000 / f_pwm)-1;[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] // Overflow value. It sets the resolution of the PWM.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] ICR1=TOP;[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] // In case another PWM frequency is desired, this value must be changed.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] OCR1A= dutycycle[i]; // Dutycycle for pin 9[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] OCR1B= dutycycle[j]; // Dutycycle for pin 10[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] TCCR2A=0; // Setting the entire registers to zero.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] TCCR2B=0;[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] TCCR2A | = (1<<WGM21); // Turn on Comparing Output Mode, non PWM.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] TCCR2B | = (1<<CS21); // Prescaler at 8.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] // In case it is changed, the formula below must be changed to the new prescaler.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] //OCR2A = (byte) ((16000000 / (fs * 8) ) - 1);[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] // Number of pulses it counts until the interruption is activated.[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] OCR2A= 78;[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] TIMSK2 |= (1 << OCIE2A); // Timer 2 Output Compare Match A Interrupt Enable[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] sei ( ); // Global interruption activation[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] } //setup[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] void loop ( ) {[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] }[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] ISR (TIMER2_COMPA_vect) { [/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] if (i<= n-1)[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] {[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] OCR1A= dutycycle [i];[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] i++;[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] }[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] else { i=0; } ;[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] if ( j<= n-1)[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] {[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] OCR1B= dutycycle[j];[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] j++;[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] }[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] else { j=0;}[/FONT][/COLOR]
      [COLOR=#28282B][FONT=Consolas] }[/FONT][/COLOR]

      دیدگاه


        #4
        پاسخ : علت error برنامه آردوینو

        نوشته اصلی توسط mohsen74 نمایش پست ها
        سپاس مهندس برنامه کامپایل می شه ولی اون قسمت
        سلامی دوباره!
        ما کوچیک شماییم...
        خب ببین داداش من... شما اومدی دوبار متغییری به اسم n رو تعریف کردی؟!؟!؟ خب به خاطر اینه که داره خطا می گیره!
        ارادت داریم!


        دیدگاه


          #5
          پاسخ : علت error برنامه آردوینو

          سلام خدمت دوستان و اساتید
          برنامه زیر رو خط :
          TCCR1 = 0 << PWM1A | 0 << COM1A0 | 1 << CS10;
          error می ده دلیلش چی می تونه باشه؟ سپاس از پاسخ شما
          کد:
          
          
          کد:
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL]  F_CPU 8000000
          int pwm = 1;
          int potinput = A2;
          int feedbackinput = A3;
          int potinputval;
          int feedbackinputval;
          int pwmval;
          
          
          void setup() {
            TCCR0A = 2 << COM0A0 | 2 << COM0B0 | 3 << WGM00;
            TCCR0B = 0 << WGM02 | 1 << CS00;
            TCCR1 = 0 << PWM1A | 0 << COM1A0 | 1 << CS10;
            GTCCR = 1 << PWM1B | 2 << COM1B0;
            pinMode(pwm, OUTPUT);
            pinMode(potinput, INPUT);
            pinMode(feedbackinput, INPUT);
            digitalWrite(pwm, LOW);
            pwmval = 0;
          }
          
          
          void loop() {
            potinputval = analogRead(potinput);
            potinputval = map(potinputval, 1023, 0, 255, 0);
            feedbackinputval = analogRead(feedbackinput);
            feedbackinputval = map(feedbackinputval, 1023, 0, 255, 0);
            while (potinputval > feedbackinputval) {
              if (pwmval == 230) {
                potinputval = analogRead(potinput);
                potinputval = map(potinputval, 1023, 0, 255, 0);
                feedbackinputval = analogRead(feedbackinput);
                feedbackinputval = map(feedbackinputval, 1023, 0, 255, 0);
              }
              else {
                pwmval = pwmval + 1;
                analogWrite(pwm, pwmval);
                potinputval = analogRead(potinput);
                potinputval = map(potinputval, 1023, 0, 255, 0);
                feedbackinputval = analogRead(feedbackinput);
                feedbackinputval = map(feedbackinputval, 1023, 0, 255, 0);
              }
            }
            while (potinputval < feedbackinputval) {
              if (pwmval == 0) {
                potinputval = analogRead(potinput);
                potinputval = map(potinputval, 1023, 0, 255, 0);
                feedbackinputval = analogRead(feedbackinput);
                feedbackinputval = map(feedbackinputval, 1023, 0, 255, 0);
              }
              else {
                pwmval = pwmval - 1;
                analogWrite(pwm, pwmval);
                potinputval = analogRead(potinput);
                potinputval = map(potinputval, 1023, 0, 255, 0);
                feedbackinputval = analogRead(feedbackinput);
                feedbackinputval = map(feedbackinputval, 1023, 0, 255, 0);
              }
            }
          }
          [RIGHT][COLOR=#28282B][FONT=Yekan][/FONT][/COLOR][/RIGHT]

          دیدگاه

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