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

[Mega32][Bascom] Timer1 a Timer0 - Multiplexowanie i PWM

Gibol 25 Sie 2009 16:53 3455 4
REKLAMA
  • #1 6942064
    Gibol
    Poziom 17  
    Witam!

    Napisałem a właściwie złożyłem sobie taki programik termometru na Wyświetlaczach 7 segmentowych i działa ok (na Timer1).
    Jednak dodatkowo chciałbym użyć 3 kanałów pwm więc za Multiplexowanie musi odpowiadać Timer0. Próbowałem różne wartości prescale i load i nie chce mi to działać na Timer0.

    Działający kod na Timer1:
    
    $regfile = "m32def.dat"
    $crystal = 16000000
    
    Config Timer1 = Timer , Prescale = 256
    
    Config Porta = Output
    
    
    Config Portb = Output
    
    Config 1wire = Portc.0
    
    Portb = &B11111111
    Porta = &B11111110
    
    Dim A As Byte , B As Byte , C As Byte , A1 As Integer , B1 As Byte , B2 As Single , B3 As Single , C1 As Single
    Dim Opozniacz As Integer
    Dim I As Byte
    Dim T(2) As Byte
    Dim Temp As Single
    
    On Timer1 Wyswietlanie
    
    Enable Interrupts
    Enable Timer1
    
    Load Timer1 , 700
    
    Do
    Disable Interrupts
    
    1wreset
    1wwrite &HCC
    1wwrite &H44
    
    Enable Interrupts
    Waitms 750
    Disable Interrupts
    
    1wreset
    1wwrite &HCC
    1wwrite &HBE
    T(1) = 1wread()
    T(2) = 1wread()
    1wreset
    
    
      If T(2) = 0 Then
      Temp = T(1) / 2
      Reset Portb.7
      Else
      I = 256 - T(1)
      Temp = I / 2
      Set Portb.7
      End If
    
    C1 = Frac(temp)
    C = C1 * 10
    B1 = Temp - C1
    B2 = B1 / 10
    B2 = B2 + 0.000001
    B3 = Frac(b2)
    B = B3 * 10
    A1 = B1 - B
    A = A1 \ 10
     Enable Interrupts
    Waitms 1000
    Loop
    End
    
    
    
    Wyswietlanie:
    Load Timer1 , 700
    Porta = Lookup(a , Kody7seg)
    Portb.0 = 0
    Portb.1 = 1
    Portb.2 = 1
    Waitms 3
    Porta = Lookup(b , Kody7seg)
    Portb.0 = 1
    Portb.1 = 0
    Portb.2 = 1
    Waitms 3
    Porta = Lookup(c , Kody7seg)
    Portb.0 = 1
    Portb.1 = 1
    Portb.2 = 0
    Waitms 3
    Return
    
    Kody7seg:
    Data 64 , 121 , 36 , 48 , 25 , 18 , 2 , 120 , 0 , 16 , 127 , 28 , 255 
    
  • REKLAMA
  • #2 6942369
    ZbeeGin
    Poziom 39  
    To dlaczego pokazujesz nam działający program? Chcesz gotowca?
    Pokaż kod który nie działa. Bo w podchody się bawić nie będziemy...
  • REKLAMA
  • #3 6942519
    Gibol
    Poziom 17  
    Chodziło tylko o zamianę Timer1 na Timer0, ale ok mogę pokazać który nie działa... a właściwie który już działa... dobrałem wartości prescale i load całkowicie doświadczalnie... miałem nadzieje że ktoś wyjaśni co i jak z tym przy okazji ale ok...

    inne pytanie jeszcze... jak ten program się zachowa przy przeniesieniu na atmega8 (8mhz - internal)? (nie licząc portu A - to się zmieni)
    Jak wtedy dać prescale i load ?

    
    $regfile = "m32def.dat"
    
    $crystal = 16000000
    
    
    
    Config Timer0 = Timer , Prescale = 1024
    Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up , Prescale = 8
    Config Timer2 = Pwm , Pwm = On , Compare Pwm = Clear Up , Prescale = 8
    
    Config Porta = Output
    Config Portb = Output
    
    Config 1wire = Portc.0
    
     Kb Alias Compare1a
     Kr Alias Compare1b
     Kg Alias Ocr2
    
    Portb = &B11111111
    Porta = &B11111000
    
    Dim A As Byte , B As Byte , C As Byte , A1 As Integer , B1 As Byte , B2 As Single , B3 As Single , C1 As Single
    Dim I As Byte
    Dim T(2) As Byte
    Dim Temp As Single
    
    On Timer0 Wyswietlanie
    
    Enable Interrupts
    Enable Timer0
    
    Load Timer0 , 255
    
    
    
    
    
    
    
    Do
    
    Kr = 70
    Kg = 225
    Kb = 220
    
    Disable Interrupts
    
    
    
    
    1wreset
    1wwrite &HCC
    1wwrite &H44
    
    Enable Interrupts
    
    Waitms 750
    
    Disable Interrupts
    
    1wreset
    1wwrite &HCC
    1wwrite &HBE
    T(1) = 1wread()
    T(2) = 1wread()
    1wreset
    
    
      If T(2) = 0 Then
      Temp = T(1) / 2
      Reset Portb.7
      Else
      I = 256 - T(1)
      Temp = I / 2
      Set Portb.7
      End If
    
    
    
     C1 = Frac(temp)
    C = C1 * 10
    B1 = Temp - C1
    B2 = B1 / 10
    B2 = B2 + 0.000001
    B3 = Frac(b2)
    B = B3 * 10
    A1 = B1 - B
    A = A1 \ 10
    
    If C = 0 Then
    Set Portb.6
    Reset Portb.5
    Else
    Set Portb.5
    Reset Portb.6
    End If
    
     Enable Interrupts
    
    Waitms 750
    
    
    Loop
    End
    
    
    
    Wyswietlanie:
    
    Load Timer0 , 255
    
    Porta = Lookup(a , Kody7seg)
    Portb.0 = 0
    Portb.1 = 1
    
    
    Waitms 10
    Porta = Lookup(b , Kody7seg)
    Portb.0 = 1
    Portb.1 = 0
    
    
    Return
    
    
    Kody7seg:
    Data 64 , 121 , 36 , 48 , 25 , 18 , 2 , 120 , 0 , 16 , 127 , 28 , 255
    
  • REKLAMA
  • #4 6942559
    ZbeeGin
    Poziom 39  
    Proszę rzucić okiem na dokumentację ATMega32 w sekcji Timer0/Counter0 and Timer1/Counter1 Prescalers, rys. 39 i porównać sobie z rys. 31 w tej samej sekcji w dokumentacji ATMega8. Czy widać jakąś różnicę? A zatem 2x większe taktowanie wymusi całkowitą zmianę w programie.
  • Pomocny post
    #5 6944198
    Konto nie istnieje
    Poziom 1  
REKLAMA