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

[atmega88][Bascom] dźwięk ze "zwykłego" portu

saycomp 22 Sty 2010 22:41 1548 4
REKLAMA
  • #1 7576388
    saycomp
    Poziom 12  
    Witam

    Mam mały problem. Wykorzystałem ATmega88 do zbierania informacji z dwóch czujników. Te czujniki dają sygnał w postaci cyfrowej w funkcji częstotliwości. Jako, że pomiar ma się odbywać jednocześnie, wykorzystałem wbudowane w procesor dwa timery do pomiaru częstotliwości a trzeci służy jako wzorzec czasu. Chciałem dołożyć do programu dźwiękową opcję powiadamiania o różnicach wskazań. Próbowałem użyć komendy "sound" ale niestety na czas wykonywania polecenia procesor zatrzymuje wykonywanie innych poleceń (nie powinien tego robić)... Wysokość dźwięku powinna być zmienna (zależna od różnicy wskazań), dlatego odpada prosta sygnalizacja zero-jedynkowa. Mam do dyspozycji jeden wolny port i chciałem poprosić Was o podpowiedź, może ktoś z Was wpadnie na jakiś niekonwencjonalny pomysł? :-)
  • REKLAMA
  • #2 7576397
    Konto nie istnieje
    Konto nie istnieje  
  • REKLAMA
  • #3 7576440
    saycomp
    Poziom 12  
    Ten kod jest wersją maksymalnie testową. Zawiera kupę niepotrzebnych rzeczy i jest w nim nieziemski bałagan - przepraszam. Jestem bardzo początkujący i próbuję pisać posługując się najprostszą składnią. Był pisany "na szybko", aby stwierdzić czy ta idea zadziała. I generalnia działa.

    
    
    Config Lcd = 16 * 2
    $crystal = 1382400                                          ' fusebit ustaw xtal full swing
    $baud = 9600
    $hwstack = 32
    $swstack = 10
    $framesize = 40
    Cls
    
    
    Deflcdchar 1 , 14 , 31 , 31 , 31 , 31 , 31 , 31 , 31        ' bat full
    Deflcdchar 2 , 14 , 17 , 17 , 25 , 29 , 31 , 31 , 31        ' bat haf
    Deflcdchar 3 , 14 , 17 , 17 , 17 , 17 , 17 , 17 , 31        ' bat empty
    
    Cursor Off
    
    Config Portd.6 = Input
    Config Portd.7 = Input
    Config Portb.2 = Input
    Config Portb.1 = Input
    Config Portb.1 = Input                                      ' sound on
    
    Config Portd.4 = Input                                      ' fgm-3
    Config Portd.5 = Input                                      'fgm-3
    Config Portc.5 = Input                                      ' batt indicator
    
    
    Config Timer0 = Counter , Edge = Falling
    Config Timer1 = Counter , Edge = Falling ,
    Config Timer2 = Timer , Gate = Internal , Prescale = 8
    
    Dim F0 As single
    Dim F1 As single
    Dim Fx As single
    Dim F0min As single
    Dim F0max As single
    Dim F1min As single
    Dim F1max As single
    Dim F1calib As single
    Dim F1offset As single
    Dim Fus As long
    
    Dim Initf As Byte
    
    Dim Temp0 As single
    Dim Temp1 As single
    
    Dim Tt0 As single
    Dim Tt1 As single
    
    Dim Factormin As single
    Dim Factormax As single
    
    Dim Tempf1 As single
    Dim Tempf2 As single
    Dim Tempf3 As single
    
    'dim duration as integer
    
    
    Dim Kalibracja As Bit
    Dim Skalibrowany As Bit
    
    Dim Counts As Long
    Declare Sub Czas1
    
    
    Dim Sampling As Integer
    
    On Timer0 Przepelnienie0
    On Timer1 Przepelnienie1
    On Timer2 Timer2_int
    
    Cursor Off
    Enable Interrupts
    Enable Timer0
    Enable Timer1
    Enable Timer2
    Cls
    
    
    
    Config Adc = Single , Prescaler = Auto , Reference = avcc
    Start Adc
    Dim batt As Word , Channel As Byte
    'channel = 5
                                                                                             l
    
    Lcd "    FLUXGATE"
    Lowerline
    Lcd "  GRADIOMETER"
    'Wait 1
    
    
    Temp0 = 0
    Temp1 = 0
    Tt0 = 0
    Tt1 = 0
    Kalibracja = 0
    Skalibrowany = 0
    F0min = 0
    F0max = 0
    F1min = 0
    F1max = 0
    
    Sampling = 454
    Cls
    
    
    Do
    
    If Pind.6 = 0 Then Sampling = 454
    If Pind.7 = 0 Then Sampling = 227
    If Pinb.2 = 0 Then Sampling = 45
    
    
    If Pinb.1 = 0 And Kalibracja = 1 Then
    Kalibracja = 0
    F0min = F0
    F0max = F0
    F1min = F1
    F1max = F1
    Bitwait Pinb.1 , Set
    Delay
    
    
    
    
    Skalibrowany = 1
    Goto Pomiar
    End If
    
    
    If Pinb.1 = 0 And Kalibracja = 0 Then
    Kalibracja = 1
    Cls
    Lcd "   Calibration"
    Bitwait Pinb.1 , Set
    'Wait 1
    Cls
    Lcd "  very slowly"
    Lowerline
    Lcd " rotate sensor"
    'Wait 1
    Cls
    Lcd "  on magnetic"
    Lowerline
    Lcd "inclinat. plane"
    'Wait 1
    
    Goto Kalibracja
    End If
    
    If Kalibracja = 0 Then Goto Pomiar
    
    If Initf = 0 and Sampling = 454 Then
    Initf = 1
    F0min = F0
    F0max = F0
    F1min = F1
    F1max = F1
    End If
    
    
    If Sampling = 227 Then
     Sampling = 454
     Goto Pomiar
     End If
    
    If Sampling = 45 Then
     Sampling = 454
     Goto Pomiar
     End If
    
    Sampling = 454
    
    Kalibracja:
    If F0 < F0min Then
    F0min = F0
    F1min = F1
    End If
    If F0 > F0max Then
    F0max = F0
    F1max = F1
    End If
    'Print "F0min = " ; F0min
    'Print "F0max = " ; F0max
    'Print "F1min = " ; F1min
    'Print "F1max = " ; F1max
    
    
    Tempf1 = F0max / F1max
    'print "tempf1 = " ; Tempf1
    Tempf2 = Tempf1 * F1min
    'Print "f0 / Tempf2 = " ; F0min ; " / " ; Tempf2
    
    
    Pomiar:
    If Skalibrowany = 0 And Kalibracja = 0 Then
    Cls
    fus = f0
    Lcd Fus
    Locate 1 , 8
    fus = f1
    Lcd "* " ; Fus
    Fx = F0 - F1
    Lowerline
    fus = Fx
    Lcd Fus
    batt = Getadc(5)
    Print batt
    Locate 2 , 16
    if batt > 800 then lcd chr(1)
    if batt >= 600 and batt <= 800 then lcd chr(2)
    if batt < 600 then lcd chr(3)
    Locate 2 , 12
    If Sampling = 454 And Kalibracja = 0 Then Lcd "1s"
    If Sampling = 227 And Kalibracja = 0 Then Lcd "0.5s"
    If Sampling = 45 And Kalibracja = 0 Then Lcd "0.1s"
    End If
    
    If Skalibrowany = 0 And Kalibracja = 1 Then
    Cls
    fus = F0
    Lcd fus
    Locate 1 , 8
    fus = f1
    Lcd "* " ; fus
    Fx = F0 - F1
    Lowerline
    fus = fx
    Lcd Fus
    Locate 2 , 6
    Lcd "calibration"
    End If
    
    If Skalibrowany = 1 And Kalibracja = 0 Then
    Cls
    fus = f0
    Lcd fus
    Locate 1 , 8
    Factormax = F0max / F1max
    'Print "factormax = " ; Factormax
    F1calib = Factormax * F1
    fus = f1calib
    Lcd "* " ; Fus
    Fx = F0 - F1calib
    Lowerline
    fus = fx
    Lcd Fus
    
    batt = Getadc(5)
    Print batt
    
    Locate 2 , 16
    if batt > 800 then lcd chr(1)
    if batt >= 600 and batt <= 800 then lcd chr(2)
    if batt < 600 then lcd chr(3)
    
    locate 2 , 8
    lcd "cal"
    
    Locate 2 , 12
    If Sampling = 454 And Kalibracja = 0 Then Lcd "1s"
    If Sampling = 227 And Kalibracja = 0 Then Lcd "0.5s"
    If Sampling = 45 And Kalibracja = 0 Then Lcd "0.1s"
    End If
    
    
    If Skalibrowany = 1 And Kalibracja = 1 Then
    Cls
    fus = f0
    Lcd Fus
    Locate 1 , 8
    fus = f1
    Lcd "* " ; Fus
    Fx = F0 - F1
    Lowerline
    fus = fx
    Lcd Fus
    Locate 2 , 6
    Lcd "calibration"
    End If
    
    
    F0 = 0
    F1 = 0
    
    Counter0 = 0
    Counter1 = 0
    Temp0 = 0
    Temp1 = 0
    Call Czas1
    
    Stop Counter0
    Stop Counter1
    
    F0 = 256 * Temp0
    F1 = 65535 * Temp1
    Tt0 = Counter0
    Tt1 = Counter1
    F0 = F0 + Tt0
    F1 = F1 + Tt1
    Loop
    
    
    Sub Czas1
    Counts = 0
    Counter2 = 0
    Start Timer2
    Start Timer0
    Start Timer1
    Do
    If Counts = Sampling Then
    Stop Timer2
    Stop Timer0
    Stop Timer1
    Exit Do
    End If
    Loop
    End Sub
    
    
    Timer2_int:
    Counter2 = 0
    Start Timer2
    Incr Counts
    Return
    
    Przepelnienie0:
    Incr Temp0
    Return
    
    Przepelnienie1:
    Incr Temp1
    
    Return
    
  • REKLAMA
  • #4 7576540
    Konto nie istnieje
    Konto nie istnieje  
  • #5 7577509
    saycomp
    Poziom 12  
    Witam

    Czy dobrze myślę, że musiał bym wtedy zatrzymać pomiar? Jeśli tak, to ten sposób odpada. Wpadłem na inny pomysł - wolny port skonfigurować jako 1wire i z niego wypuścić instrukcje na osobny DAC. A dalej to już proste. :-)

    pozdrawiam serdecznie
REKLAMA