logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

[ATmega8][Bascom] PWM na wyjściu oc2.

nouki 27 Maj 2008 20:07 6353 15
REKLAMA
  • #1 5187765
    nouki
    Poziom 25  
    Cześć

    Może banalne pytanie dla niektórych ale mam problem z uruchomieniem pwm na nodze b.3 -Oc2 jak wpisuje pwm2 jest błąd jak wpisze pwm2a tez więc jak skonfigurować to by było ok
    W pomocy znalazłem ze powinno być pwm2 ale jakoś .....

    p.s
    To oczywiście w bascomie bo w tym jest program
    Inne nogi(pwm 1a,1b ) steruja juz czyms innym więc to nie rozwiązanie

    Poprawiłem tytuł:
    https://www.elektroda.pl/rtvforum/topic1015361.html
    [c_p]
  • REKLAMA
  • REKLAMA
  • #3 5187789
    don diego
    Poziom 32  
    To może pokaż program i napisz dokładnie co to za błąd. Wróżek tutaj aktualnie chyba nie ma.
  • #4 5187822
    nouki
    Poziom 25  
     
    $regfile = "m8def.dat" 
    Dim Wartosc As Word 
    ... 
    .. 
    ... 
    
    Do 
    
    Wartosc = Getadc(4) 
    
    If Wartosc > Pwm2 Then 
    Waitms 1 
    Incr Pwm2 
    Elseif Wartosc < Pwm2 Then 
    Waitms 1 
    Decr Pwm2 
    End If 
    ....
    
    


    niby nie ma błędów tak
    
    
    
    $crystal = 8000000
    $regfile = "m8def.dat"
    Dim Wartosc As Word
    Dim Zadany As Word
    Config Timer1 = Pwm , Pwm = 10 , Prescale = 8 , Compare A Pwm = Clear Down       
    Config Timer2 = Pwm , Prescale = 1 , Pwm = On , Compare Pwm = Clear Up
    Config Adc = Free , Prescaler = Auto , Reference = Avcc
    Start Adc
    
    Enable Interrupts
    Enable Timer2
    Enable Timer1
    
    Config Portb.1 = Output
    Config Portb.2 = Output
    Config Portb.3 = Output
    Config Portb.5 = Output
    
    Set Pind.0
    Set Pind.1
    Set Pind.3
    Set Pind.4
    Set Pinb.7
    
    Reset Portb.5
    Wait 1
    Set Portb.5
    Wait 1
    Reset Portb.5
    
    
    Home:
    
    Reset Portb.5
    1:
    Do
    
    
    If Pind.0 = 0 And Pind.1 = 0 Then Zadany = 20
    If Pind.0 = 0 And Pind.3 = 0 Then Zadany = 50
    If Pind.0 = 0 And Pind.4 = 0 Then Zadany = 100
    
    If Pind.1 = 0 And Pind.3 = 0 Then Zadany = 150
    If Pind.1 = 0 And Pind.4 = 0 Then Zadany = 200
    
    If Pind.0 = 2 And Pind.1 = 0 Then Zadany = 250
    If Pind.0 = 2 And Pind.2 = 0 Then Zadany = 300
    If Pind.0 = 2 And Pind.3 = 0 Then Zadany = 350
    
    If Pind.0 = 3 And Pind.4 = 4 Then Zadany = 400
    If Pind.0 = 0 And Pind.4 = 0 Then Zadany = 450
    If Pind.1 = 0 Then Zadany = 500
    If Pind.3 = 0 Then Zadany = 600
    If Pind.4 = 0 Then Zadany = 0
    
    
    If Pinb.7 = 0 Then
    Set Portb.0
    Set Portb.5
    
    
    Wait 1
    Reset Portb.5
    Goto Przoda:
    End If
    
    If Pind.5 = 0 Then
    Set Portd.7
    Set Portb.5
    
    
    Wait 1
    Reset Portb.5
    Goto Tyla:
    End If
    
    Loop
    
    
    Przoda:
    Wartosc = Getadc(4)
    If Zadany < Wartosc Then
    Goto Przod:
    End If
    Set Portb.5
    Waitms 200
    Goto Home
    
    Tyla:
    Wartosc = Getadc(4)
    If Zadany < Wartosc Then
    Goto Tyl:
    End If
    Set Portb.5
    Waitms 200
    Goto Home
    
    
    Przod:
    
      
    Do
      Set Portb.5
       Wartosc = Getadc(4)
       Wartosc = Wartosc / 5
       Wartosc = Wartosca
    
       If Wartosca > Ocr2 Then
             Waitms 1
             Incr Ocr2
          Elseif Wartosca < Pwm2 Then
             Waitms 1
             Decr Ocr2
          End If
    
           Wartosc = Getadc(4)
          If Wartosc > Pwm1b Then
             Waitms 1
             Incr Pwm1b
          Elseif Wartosc < Pwm1b Then
             Waitms 1
             Decr Pwm1b
          End If
    
     If Pinb.7 = 1 Then
    Reset Portb.0
    Pwm1b = 0
    Ocr2 = 0
    Reset Portb.5
    Goto Home
    End If
    
    Loop
    
    Tyl:
    
    Do
    
    Set Portb.5
    
      Wartosc = Getadc(4)
          If Wartosc > Pwm1b Then
             Waitms 1
             Incr Pwm1b
          Elseif Wartosc < Pwm1b Then
             Waitms 1
             Decr Pwm1b
          End If
       Wartosc = Getadc(4)
    
       If Wartosc > Pwm1a Then
             Waitms 1
             Incr Pwm1a
          Elseif Wartosc < Pwm1a Then
             Waitms 1
             Decr Pwm1a
           End If
    
    
    
     If Pind.5 = 1 Then
    Reset Portd.7
    Reset Portd.5
    Pwm1b = 0
    Pwm1a = 0
    Goto Home
    End If
    Loop
    
    


    Problem jest dalej a mianowicie (pwm2-)napięcie rosnie i spada i tak w kolo. Zdaje mi sie ze adc jest 10bit a timer2 8 tu jest problem.
    Inna sprawa to ze na pwm1b nic sie nie dzieje ciagle jest zero.

    Jakies sugestie??
  • #6 5190903
    nouki
    Poziom 25  
    bez tego tez nie działa .
    Skoro ADc dziala w 10 bitach czy jak podziele jak w programie przez 4 to wystarczy dla pwm2-ocr2??
  • REKLAMA
  • #8 5191231
    nouki
    Poziom 25  
    Nic nie zmienia pwm1a i b działają juz ok a tu dalej tak samo rosnie i spada nawet jesli wartosc adc(4)=0 dzieje sie tak samo czyli wystarczy ze dam więcej niz 0 a zmienia się w koło.
  • REKLAMA
  • #9 5191327
    zumek
    Poziom 39  
    nouki napisał:
    Nic nie zmienia pwm1a i b działają juz ok a tu dalej tak samo rosnie i spada nawet jesli wartosc adc(4)=0 dzieje sie tak samo czyli wystarczy ze dam więcej niz 0 a zmienia się w koło.

    A co to za zmienna/stała Wartosca i co soba reprezentuje :?:

    Piotrek
  • #10 5191335
    nouki
    Poziom 25  
    Dim Wartosc As Word
    Dim Wartosca As Word
    Dim Zadany As Word
    .
    .
    .
    Do
    Set Portb.5
    Wartosc = Getadc(4)
    Wartosc = Wartosc / 5
    Wartosc = Wartosca

    .
    .
  • #11 5191379
    zumek
    Poziom 39  
    Nie widzę byś gdziekolwiek w kodzie , przypisywał jakąś wartość tej zmiennej.A skoro tak to wygląda jak wygląda , to ta zmienna jest równa zero.
    Zapewne tak powinno to wyglądać
      Set Portb.5
    Wartosc = Getadc(4)
    Wartosc = Wartosc / 5
    Wartosca = Wartosc
    
      If Wartosca > Ocr2 Then
    '...
    


    Piotrek
  • #12 5191385
    nouki
    Poziom 25  
    i tak wyglada tylko nie z tego programu skopiowalem:) ale i tak nie dziala czy jest dzielone przez 4 czy tego nie ma

    wkleje cały kod bedzie prościej

    
    
    
    
    $crystal = 8000000
    $regfile = "m8def.dat"
    Dim Wartosc As Word
    Dim Wartosca As Word
    Dim Zadany As Word
    Config Timer1 = Pwm , Pwm = 10 , Prescale = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down       'Konfiguracja Timera
    Config Timer2 = Pwm , Prescale = 1 , Pwm = On , Compare Pwm = Clear Up
    'Tccr2 = &B01110100
    Config Adc = Free , Prescaler = Auto , Reference = Avcc
    Start Adc
    
    Enable Interrupts
    
    
    Config Portb.1 = Output
    Config Portb.2 = Output
    Config Portb.3 = Output
    Config Portb.5 = Output
    
    Set Pind.0
    Set Pind.1
    Set Pind.3
    Set Pind.4
    Set Pinb.7
    
    Reset Portb.5
    Wait 1
    Set Portb.5
    Wait 1
    Reset Portb.5
    
    
    Home:
    
    Reset Portb.5
    1:
    Do
    
    
    If Pind.0 = 0 And Pind.1 = 0 Then Zadany = 20
    If Pind.0 = 0 And Pind.3 = 0 Then Zadany = 50
    If Pind.0 = 0 And Pind.4 = 0 Then Zadany = 100
    
    If Pind.1 = 0 And Pind.3 = 0 Then Zadany = 150
    If Pind.1 = 0 And Pind.4 = 0 Then Zadany = 200
    
    If Pind.0 = 2 And Pind.1 = 0 Then Zadany = 250
    If Pind.0 = 2 And Pind.2 = 0 Then Zadany = 300
    If Pind.0 = 2 And Pind.3 = 0 Then Zadany = 350
    
    If Pind.0 = 3 And Pind.4 = 4 Then Zadany = 400
    If Pind.0 = 0 And Pind.4 = 0 Then Zadany = 450
    
    If Pind.0 = 0 Then Zadany = 500
    If Pind.1 = 0 Then Zadany = 600
    If Pind.3 = 0 Then Zadany = 700
    If Pind.4 = 0 Then Zadany = 0
    
    
    If Pinb.7 = 0 Then
    Set Portb.0
    Set Portb.5
    
    
    Wait 1
    Reset Portb.5
    Goto Przoda:
    End If
    
    If Pind.5 = 0 Then
    Set Portd.7
    Set Portb.5
    
    
    Wait 1
    Reset Portb.5
    Goto Tyla:
    End If
    
    Loop
    
    
    Przoda:
    Wartosc = Getadc(4)
    If Zadany < Wartosc Then
    Goto Przod:
    End If
    Set Portb.5
    Waitms 500
    Goto Home
    
    Tyla:
    Wartosc = Getadc(4)
    If Zadany < Wartosc Then
    Goto Tyl:
    End If
    Set Portb.5
    Waitms 500
    Goto Home
    
    
    Przod:
    
    Do
      Set Portb.5
      Wartosc = Getadc(4)
       Wartosc = Wartosc / 5
       Wartosc = Wartosca
    
       If Wartosca > Ocr2 Then
             Waitms 1
             Incr Ocr2
          Elseif Wartosca < Ocr2 Then
             Waitms 1
             Decr Ocr2
          End If
    
           Wartosc = Getadc(4)
          If Wartosc > Pwm1b Then
             Waitms 1
             Incr Pwm1b
          Elseif Wartosc < Pwm1b Then
             Waitms 1
             Decr Pwm1b
          End If
    
     If Pinb.7 = 1 Then
    Reset Portb.0
    Pwm1b = 0
    Ocr2 = 0
    Reset Portb.5
    Goto Home
    End If
    
    Loop
    
    Tyl:
    
    Do
    
    Set Portb.5
        Wartosc = Getadc(4)
      If Wartosc > Pwm1a Then
    
             Incr Pwm1a
          Elseif Wartosc < Pwm1a Then
    
             Decr Pwm1a
           End If
    
         Wartosc = Getadc(4)
          If Wartosc > Pwm1b Then
    
             Incr Pwm1b
          Elseif Wartosc < Pwm1b Then
    
             Decr Pwm1b
          End If
    
    
     If Pind.5 = 1 Then
    Reset Portd.7
    Reset Portd.5
    Pwm1b = 0
    Pwm1a = 0
    Goto Home
    End If
    Loop
    
    
    
    
    
    
  • Pomocny post
    #13 5191416
    zumek
    Poziom 39  
    Ja nadal widzę , ten sam błąd w Twoim kodzie

    Piotrek
  • #14 5191431
    nouki
    Poziom 25  
    Wartosc = Getadc(4)
    Wartosca = Wartosc / 5


    :) chyba kupie okulary ale skoro jej nie przypisalem a zmieniajac adc z 0 na cos innego wypelnienie roslo od 0 do 100 i tak w kolo.
REKLAMA