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

ATMEGA[BASCOM] Najprostsze odtwarzanie Wav .

adambehnke 29 Gru 2009 15:21 96483 328
  • #1 7452811
    adambehnke
    Poziom 24  
    Witam

    Kontynuuję tworzenie swojego sterownika i teraz przyszedł czas na dźwięki.
    Otóż w moim urządzeniu muszę zrobić możliwie najprostsze ( mam niewiele wolnego miejsca na pcb) , odtwarzanie plików dźwiękowych.
    Będą to krótkie max 3 sekundowe pliki. Nagrane wcześniej na kartę SD pliki ( dokładnie w takim pliku nagrany będzie głos "lektora") , mam zamiar odtworzyć poprzez jakiś wbudowany w urządzenie mini głośniczek. Oczywiście na PCB znajdzie się miejsce na jakiś ewentualny wzmacniacz.
    Mój projekt oparłem na atmega 2560 ale procedury związane z dźwiękiem raczej powierzę kolejnemu prockowi (atmega 8 ,16,32,128).
    Fajnie by było abym nie musiał do odczytu takiego pliku korzystać z avr-dos.bas , tylko rozwiązać to maksymalnie prosto. Ale oczywiście system plików także się zmieści o ile będzie potrzebny na Mega32. Ważne jest to abym mógł z poziomu PC dorzucać nowe pliki, więc przyjmijmy że system plików jest niezbędny.
    Niezwykle dla mnie ważne jest aby odtwarzany głos był wyraźny-zrozumiały (oczywiscie monofoniczny).
    Bawiłem się kodem który otrzymałem tu od kolegi z forum lecz jakość jest bardzo kiepska.

    Głośnik podłączałem bezpośrednio do portu atmegi32 pod pwm poprzez rezystor 10k i kondensator 100nF.

    Dodam że już od dłuższego czasu próbuję coś sklecić lecz z marnym skutkiem.Przeszukiwałem forum i net i natrafiłem albo na bardzo rozbudowane projekty albo kod pisany w C. Dla mnie ważne aby było to w Bascomie i przy uzyciu minimalnej ilości części . Chyba że można zastosować w łatwy sposób jakiś dedykowany do tego układ .
    Oczywiście jeśli chodzi o format plików to nie muszą być to Wav-y. Widziałem w necie projekt w którym konwertowano pliki w programie RC_ENCODER ale on przerabia Wav-y na pliki asm,c,bin. A nie wiem jak tego użyć aby czytało to z karty.
    Mi chodzi o taki sposób odczytu że podaję w jakiejś zmiennej nazwę pliku do odczytania z SD i bezpośrednio odtworzenie tego. Plików będzie pewnie około 40-50 więc karta SD musi być i nie mogę umieścić plików w jakimś epromie.

    oto kod na jakim testuję to:

    
    $regfile = "M32Def.dat"
    $crystal = 16000000
    $external Waitms
    
    'Const Xramdrive = 0
    
    Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Prescale = 1
    Pwm1a = 0
    Start Timer1
    Config Date = Dmy , Separator = .
    Config Clock = Soft
    
    Enable Interrupts
    
    Dim Co_2 As Bit
    
    
    
    Dim Bufor As Byte
    
    Dim B As Byte
    Dim S As String * 96
    '(Config Int0 = Falling
    On Int0 Ainit
    Portd.2 = 1
    sei
    Enable Int0
    ')
    $include "Config_MMC.bas"
    $include "CONFIG_AVR-DOS.Bas"
    Gosub Ainit
    Do
    Loop
    
    Ainit:
    cli
    
    B = Drivecheck()                                            'u mnie te drivechecki itp. nigdy nie dawały errora ale dałem, żeby było
    If B = 0 Then
    
       Gbdriveerror = Driveinit()
    Else
    Cls
      '  Lcd "Card not inserted, check Card!"
        End
    End If
    
    
    B = Initfilesystem(1)
    Cls
    If B > 0 Then
      ' Lcd "Error: " ; B
       End
    Else
       'Lcd "Disksize: " ; Disksize()
       Lowerline
       'Lcd "Disk free: " ; Diskfree()
    End If
    Wait 1
    
    S = Dir( "wav.wav")
    While Len(s) > 0
       Cls
       Lcd S ; " " ; Filedate()
       Lowerline
       s = "wav.wav"
     '  Lcd Filetime() ; "  " ; Filelen()
       Open S For Binary As #2
    
    
    Play:
    Do
    Get #2 , Bufor
    Pwm1a = Bufor
                              'o tu -------|
    Loop Until Eof(#2) <> 0
                          '                |  bez return - sam przeskakuje do next
    'trzeba dodać obsługę przycisku + skok-|
    Wait 10
    
    
    
    Nex_t:
    Pwm1a = 0
    Close #2
    
    
       S = Dir()
    
    
    Gosub Play
    
    
    Wend



    schemat (pominęłem celowo resztę podzespołów jak karta SD itp.)

    ATMEGA[BASCOM] Najprostsze odtwarzanie Wav .
  • Pomocny post
    #2 7453010
    Konto nie istnieje
    Poziom 1  
  • #3 7453098
    adambehnke
    Poziom 24  
    Przerobię kodzik i zobaczymy jak zagra , chociaż nie bardzo mam pojęcie jak to do końca zrobić :). A może jest do tego celu jakiś zewnętrzny układ aby mieć od razu w jednym także mini wzmacniacz. Ale aby móc go zasilić z 5 lub 12V (żeby nie kombinować z dziwnymi napięciami ujemnymi itp.)
    i aby móc podłączyć jakiś głośniczek ~ 8 -16Ohm.
  • Pomocny post
    #4 7453125
    tmf
    VIP Zasłużony dla elektroda
    No jest, VS1011 i pochodne. Zobacz generalnie projekt yampp. On odtwarza tez mp3, wiec jakosc dzwieku poprawila by sie dramatycznie, a zajetosc pamieci zmniejszyla. Poza tym zamiast karty SD mozesz wrzucic DataFLASH, 8-32Mbity kupisz w obudowie 8-nozkowej, a sterowanie prosciutkie. No i ze wszystkim wyrobilby sie jeden maly procesorek. Kody sa powszechnie dostepne. Z drugiej strony jesli obstajesz przy PWM i wav to proponuje przejsc na XMega - masz tam DMA, ktore mozesz wykorzystac do generowania dzwieku, co odciazy znaczaco procesor.
  • Pomocny post
    #5 7453149
    Konto nie istnieje
    Poziom 1  
  • #6 7453650
    adambehnke
    Poziom 24  
    Ale mam za mało SRAM : OUT OF SRAM SPACE

    Dodałem avr_dos i zabrakło pamięci w mega 32.
    Zrobiłem do testu bufor 256 zamiast 512.


    Mam taki oto kod ale słychać tylko cykliczne cykanie:

    
    $regfile = "M32Def.dat"
    $crystal = 16000000
    '$external Waitms
    
    
    
    
    
    
    
    
    
    
    Dim Timer1_licznik As Byte
    Dim Buffer(256) As Byte
    Dim Write_position As Word
    Dim Read_position As Word
    Dim S As String * 10
    Dim B As Byte
    
    Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Prescale = 1
    Pwm1a = 0
    
    
    Enable Interrupts
    
    
    
    
    
    On Timer1 Timer1_handler
    $include "Config_MMC.bas"
    $include "CONFIG_AVR-DOS.Bas"
    
    
    B = Drivecheck()
    Gbdriveerror = Driveinit()
    B = Initfilesystem()
    
    
    S = Dir( "wav.wav")
    
    
    
    
    Open S For Binary As #2
    
    For Write_position = 1 to 256
      Get #2 , Buffer(Write_position)
    Next Write_position
    
    Write_position = 0
    Enable Timer1
    
    
    
    Do
        If Write_position <> Read_position Then
            Write_position = Write_position + 1
            Get #2 , Buffer(Write_position)
            Write_position = Write_position And &H01FF
        End If
    Loop Until Eof(#2) <> 0
    
    Do
    Loop
    '---------------------------------------------------------
    Timer1_handler:
      Timer1_licznik = Timer1_licznik + 1
    
      If Timer1_licznik >= 3 Then
          Read_position = Read_position + 1
          Pwm1a = Buffer(Read_position)
          Read_position = Read_position And &H01FF
    
          Timer1_licznik = 0
      End If
    Return
    '--------
  • Pomocny post
    #7 7453779
    PiotrEtenM500
    Poziom 19  
    Zrób dzwięk na osobnym uC
    fajny projekt jest w ostanim nr EP12/2009


    zrealizowany na Atmedze 8 zrealizowany na Atmedze 8
  • Pomocny post
    #9 7453866
    PiotrEtenM500
    Poziom 19  
    Duzo ma być dzieku?
  • #11 7453900
    PiotrEtenM500
    Poziom 19  
    może szkoda sie bawić jak masz gotowca za 49 złLink

    4 minuty nagrania
  • #13 7453939
    Konto nie istnieje
    Poziom 1  
  • #14 7453945
    PiotrEtenM500
    Poziom 19  
    w dataflesha wgrywasz dziwęk przez stk200/300 sofetm Kolegi Dybowskiego
    zresztą w miejsce tego układu wstawiasz SD i działa;) minimalna korekta softu
    ale jak mus to mus. Rób swoje ;)
  • #15 7454279
    adambehnke
    Poziom 24  
    Są jakieś reakcje.Słychać co prawda same trzaski a potem pisk ale idzie rozróżnić początek nagrania (tzn przerwy pomiędzy słowami).Czy problemem nie jest czasem konfiguracja timera?

    kod:
    
    
    $regfile = "M32Def.dat"
    $crystal = 16000000
    $external Waitms
    
    
    
    
    
    
    
    
    
    
    Dim Timer1_licznik As Byte
    Dim Buffer(256) As Byte
    Dim Write_position As Word
    Dim Read_position As Word
    Dim S As String * 36
    Dim B As Byte
    
    Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Prescale = 1
    Pwm1a = 0
    
    Config Clock = soft
    
    
    
    
    
    
    On Timer1 Timer1_handler
    Enable Interrupts
    $include "Config_MMC.bas"
    $include "CONFIG_AVR-DOS.Bas"
    
    B = Drivecheck()                                            'u mnie te drivechecki itp. nigdy nie dawały errora ale dałem, żeby było
    
    
       Gbdriveerror = Driveinit()
    
    
    
    
    
    B = Initfilesystem(1)
    
    
    S = Dir( "wav.wav")
    
     S = "wav.wav"
    
    
    Open S For Binary As #2
    
    
    
    For Write_position = 1 to 256
      Get #2 , Buffer(Write_position)
    Next Write_position
    
    Write_position = 0
    Enable Timer1
    
    
    
    Do
       If Write_position <> Read_position Then
            Write_position = Write_position + 1
            Get #2 , Buffer(Write_position)
            Write_position = Write_position And &HFF
        End If
    Loop Until Eof(#2) <> 0
    
    Do
    Loop
    '---------------------------------------------------------
    Timer1_handler:
      Timer1_licznik = Timer1_licznik + 1
    
      If Timer1_licznik >= 3 Then
          Read_position = Read_position + 1
          Pwm1a = Buffer(Read_position)
          Read_position = Read_position And &HFF
    
          Timer1_licznik = 0
      End If
    Return
    '---------------------------------------------------------
  • Pomocny post
    #16 7454472
    Konto nie istnieje
    Poziom 1  
  • Pomocny post
    #17 7454679
    tmf
    VIP Zasłużony dla elektroda
    Takie dwa pytania, jestes pewien, ze wav jest kodowany jako PCM? I drugie, co z wewnetrzna struktura pliku? To przeciez nie jest tylko ciag bajtow z sampla.
  • Pomocny post
    #18 7454836
    grysek
    Poziom 19  
    Ja Timer ustawiłem na FAST PWM i nie słychać wtedy pisku. A trzaski hmm jeśli masz wav zapisany jako stereo to musisz wczytywać co drugą próbkę, albo zapisac go na mono :D
  • #19 7454853
    adambehnke
    Poziom 24  
    plik przerobiłem w programie fleximusic na 8bit ,mono 24khz.
    Nie mam pod ręką 100% pewnego i odpowiedniego pliku aby przetestować.


    Timera0 nie mogę skonfigurować bo nie ma PWM a timer2 wyrzuca błąd w linii ON TIMER2 TIMER2_handler.
  • Pomocny post
    #20 7454883
    grysek
    Poziom 19  
    Pmiętaj że wave musisz zapisać jako unsigned 8-bit
  • Pomocny post
    #22 7455070
    d.d
    Poziom 20  
    Jak masz Winampa to : Preferencje->wtyczki->wyjściowe->zapisywanie na dysku zaznaczasz konwertuj do formatu i wybierasz ile kHz PCM 8-bit Mono i jeszcze typ pliku wyjściowego - wymuś dane RAW .
  • #23 7455206
    adambehnke
    Poziom 24  
    Niestety nadal pisk w głosniku

    Kod:

    
    
    $regfile = "M32Def.dat"
    $crystal = 16000000
    $external Waitms
    
    
    
    Const Cmmc_soft = 0
    
    #if Cmmc_soft = 0
    
    ' --------- Start of Section for HW-SPI ----------------------------------------
    
       ' define Chip-Select Pin
       Config Pinb.4 = Output                                   ' define here Pin for CS of MMC/SD Card
       Mmc_cs Alias Portb.4
       Set Mmc_cs
    
       ' Define here SS Pin of HW-SPI of the CPU (f.e. Pinb.0 on M128)
       Config Pinb.4 = Output                                   ' define here Pin of SPI SS
       Spi_ss Alias Portb.4
       Set Spi_ss                                               ' Set SPI-SS to Output and High por Proper work of
                                                      ' SPI as Master
    
       ' HW-SPI is configured to highest Speed
      Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1       'Config Spi = Soft , Din = Pinb.3 , Dout = Portb.2 , Ss = Portb.0 , Clock = Portb.1
       Spsr.0 = 1                                               ' Double speed on ATMega128
       Spiinit                                                  ' Init SPI
    
    ' --------- End of Section for HW-SPI ------------------------------------------
    
    #else                                                       ' Config here SPI pins, if not using HW SPI
    
    ' --------- Start of Section for Soft-SPI --------------------------------------
    
       ' Chip Select Pin  => Pin 1 of MMC/SD
       Config Pinb.4 = Output
       Mmc_cs Alias Portb.4
       Set Mmc_cs
    
       ' MOSI - Pin  => Pin 2 of MMC/SD
       Config Pinb.5 = Output
       Set Pinb.5
       Mmc_portmosi Alias Portb
       Bmmc_mosi Alias 5
    
       ' MISO - Pin  => Pin 7 of MMC/SD
       Config Pinb.6 = Input
       Mmc_portmiso Alias Pinb
       Bmmc_miso Alias 6
    
       ' SCK - Pin  => Pin 5 of MMC/SD
       Config Pinb.7 = Output
       Set Pinb.7
       Mmc_portsck Alias Portb
       Bmmc_sck Alias 7
    
    ' --------- End of Section for Soft-SPI ----------------------------------------
    
    #endif
    
    ' ========== End of user definable range =======================================
    
    Spiinit
    ' Error
    Const Cperrdrivereset = 225                                 ' Error response Byte at Reset command
    Const Cperrdriveinit = 226                                  ' Error response Byte at Init Command
    Const Cperrdrivereadcommand = 227                           ' Error response Byte at Read Command
    Const Cperrdrivewritecommand = 228                          ' Error response Byte at Write Command
    Const Cperrdrivereadresponse = 229                          ' No Data response Byte from MMC at Read
    Const Cperrdrivewriteresponse = 230                         ' No Data response Byte from MMC at Write
    Const Cperrdrive = 231
    Const Cperrdrivenotsupported = 232                          ' return code for DriveGetIdentity, not supported yet
    
    Waitms 1                                                    ' Wait some time before initialising MMC/SD
    Dim Gbdriveerror As Byte                                    ' General Driver Error register
    Dim Gbdriveerrorreg As Byte                                 ' Driver load Error-Register of HD in case of error
    Dim Gbdrivestatusreg As Byte                                ' Driver load Status-Register of HD on case of error
    Dim Gbdrivedebug As Byte
    $lib "MMC.LIB"                                              ' link driver library
    $external _mmc
    Gbdriveerror = Driveinit()                                  ' Init MMC/SD Card
    
    
    
    
    
    
    
    Dim Timer1_licznik As Byte
    Dim Buffer(256) As Byte
    Dim Write_position As Word
    Dim Read_position As Word
    Dim S As String * 36
    Dim B As Byte
    Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Prescale = 1
    Pwm1a = 0
    
    Config Clock = soft
    
    
    
    
    
    
    On Timer1 Timer1_handler
    
    Enable Interrupts
    '$include "Config_MMC.bas"
    $include "CONFIG_AVR-DOS.Bas"
    
    B = Drivecheck()                                            'u mnie te drivechecki itp. nigdy nie dawały errora ale dałem, żeby było
    
    
       Gbdriveerror = Driveinit()
    
    
    
    
    
    B = Initfilesystem(1)
    
    
    S = Dir( "wav.wav")
    
     S = "wav.wav"
    
    
    Open S For Binary As #2
    
    
    
    For Write_position = 1 to 256
      Get #2 , Buffer(Write_position)
    Next Write_position
    
    Write_position = 0
    Enable Timer1
    
    
    
    Do
       If Write_position <> Read_position Then
            Write_position = Write_position + 1
            Get #2 , Buffer(Write_position)
            Write_position = Write_position And &HFF
        End If
    Loop Until Eof(#2) <> 0
    
    Do
    Loop
    '---------------------------------------------------------
    Timer1_handler:
      Timer1_licznik = Timer1_licznik + 1
    
      If Timer1_licznik >= 3 Then
          Read_position = Read_position + 1
          Pwm1a = Buffer(Read_position)
          Read_position = Read_position And &HFF
    
          Timer1_licznik = 0
      End If
    Return
    '-------------------







    a w tym kodzie gra ale charczy okrutnie:

    
    $regfile = "M32Def.dat"
    $crystal = 16000000
    $external Waitms
    
    'Const Xramdrive = 0
    
    Const Cmmc_soft = 0
    
    #if Cmmc_soft = 0
    
    ' --------- Start of Section for HW-SPI ----------------------------------------
    
       ' define Chip-Select Pin
       Config Pinb.4 = Output                                   ' define here Pin for CS of MMC/SD Card
       Mmc_cs Alias Portb.4
       Set Mmc_cs
    
       ' Define here SS Pin of HW-SPI of the CPU (f.e. Pinb.0 on M128)
       Config Pinb.7 = Output                                   ' define here Pin of SPI SS
       Spi_ss Alias Portb.7
       Set Spi_ss                                               ' Set SPI-SS to Output and High por Proper work of
                                                      ' SPI as Master
    
       ' HW-SPI is configured to highest Speed
      Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1       'Config Spi = Soft , Din = Pinb.3 , Dout = Portb.2 , Ss = Portb.0 , Clock = Portb.1
       Spsr.0 = 1                                               ' Double speed on ATMega128
       Spiinit                                                  ' Init SPI
    
    ' --------- End of Section for HW-SPI ------------------------------------------
    
    #else                                                       ' Config here SPI pins, if not using HW SPI
    
    ' --------- Start of Section for Soft-SPI --------------------------------------
    
       ' Chip Select Pin  => Pin 1 of MMC/SD
       Config Pinb.4 = Output
       Mmc_cs Alias Portb.4
       Set Mmc_cs
    
       ' MOSI - Pin  => Pin 2 of MMC/SD
       Config Pinb.5 = Output
       Set Pinb.5
       Mmc_portmosi Alias Portb
       Bmmc_mosi Alias 5
    
       ' MISO - Pin  => Pin 7 of MMC/SD
       Config Pinb.6 = Input
       Mmc_portmiso Alias Pinb
       Bmmc_miso Alias 6
    
       ' SCK - Pin  => Pin 5 of MMC/SD
       Config Pinb.7 = Output
       Set Pinb.7
       Mmc_portsck Alias Portb
       Bmmc_sck Alias 7
    
    ' --------- End of Section for Soft-SPI ----------------------------------------
    
    #endif
    
    ' ========== End of user definable range =======================================
    
    Spiinit
    ' Error
    Const Cperrdrivereset = 225                                 ' Error response Byte at Reset command
    Const Cperrdriveinit = 226                                  ' Error response Byte at Init Command
    Const Cperrdrivereadcommand = 227                           ' Error response Byte at Read Command
    Const Cperrdrivewritecommand = 228                          ' Error response Byte at Write Command
    Const Cperrdrivereadresponse = 229                          ' No Data response Byte from MMC at Read
    Const Cperrdrivewriteresponse = 230                         ' No Data response Byte from MMC at Write
    Const Cperrdrive = 231
    Const Cperrdrivenotsupported = 232                          ' return code for DriveGetIdentity, not supported yet
    
    Waitms 1                                                    ' Wait some time before initialising MMC/SD
    Dim Gbdriveerror As Byte                                    ' General Driver Error register
    Dim Gbdriveerrorreg As Byte                                 ' Driver load Error-Register of HD in case of error
    Dim Gbdrivestatusreg As Byte                                ' Driver load Status-Register of HD on case of error
    Dim Gbdrivedebug As Byte
    $lib "MMC.LIB"                                              ' link driver library
    $external _mmc
    Gbdriveerror = Driveinit()                                  ' Init MMC/SD Card
    
    
    Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Prescale = 1
    
    Pwm1a = 0
    Start Timer1
    'Config Date = Dmy , Separator = .
    Config Clock = soft
    Enable Interrupts
    Dim Co_2 As Bit
    
    Dim Bufor As Byte
    
    Dim B As Byte
    Dim S As String * 36
    
    '$include "Config_MMC.bas"
    $include "CONFIG_AVR-DOS.Bas"
    
    
    
    Gosub Ainit
    Do
    Loop
    
    Ainit:
    cli
    
    B = Drivecheck()                                            'u mnie te drivechecki itp. nigdy nie dawały errora ale dałem, żeby było
    
    
      ' Gbdriveerror = Driveinit()
    
    
    
    
    
    B = Initfilesystem(1)
    
    
    S = Dir( "wav.wav")
    While Len(s) > 0
    
    
       S = "wav.wav"
    
       Open S For Binary As #2
    Play:
    Do
    Get #2 , Bufor
    Pwm1a = Bufor
                              'o tu -------|
    Loop Until Eof(#2) <> 0
                          '                |  bez return - sam przeskakuje do next
    'trzeba dodać obsługę przycisku + skok-|
    Nex_t:
    Pwm1a = 0
    Close #2
    
    
       S = Dir()
    
    
    Gosub Play
    '(
    
    S = Dir( "ściągi.")
    If Len(s) = 0 Then
    Mkdir "ściągi"
    End If
    Chdir S
    Wait 2
    ')
    wend
    Return
  • Pomocny post
    #24 7455299
    Konto nie istnieje
    Poziom 1  
  • #25 7455427
    adambehnke
    Poziom 24  
    to jest takie brzęczenie cos koło 50Hz stałe i ciągłe.
    Nie mam za bardzo jak tego nagrać.
    Pliki próbowałem różne nawet 8khz. i ciagle tak samo.
    Jedynie jak wyciagne karte SD to milczy. Tak więc kart się inicjuje i widać że czyta.

    Dodano po 29 [minuty]:

    Atom , ale jeśli chodzi o ten mój kod to wszystko w sumie gra (zgadza się dosyć tempo) ,chodzą pliki 8bit/mono/24khz. Ale czy jest jakaś szansa aby poprawić jakość?
    czy można poprawić to jakoś już na zewnątrz? Teraz używam tylko rezystora 10k i kondensatora 100nF.
  • Pomocny post
    #26 7455706
    grysek
    Poziom 19  
    Który kod jest Twoj? Spróbuj ustawić fast PWM. Czyli aby wybrać tą opcję musisz ustawic bity WGM12 i WGM10 w rejestrze TCCR1A, datasheet strona 107 :D

    Mi sie udało obsłużyć wav 44100Hz stereo na Atmega88, zegarze 8Mhz i nawet nie najgorzej gra ale na Fast PWM bo na zwykłym strasznie piszczało i charczało ;p na wyjsciu mam tylko jeden tranzystor żeby nie upalić procka :D
  • #27 7455767
    adambehnke
    Poziom 24  
    ten kod gra ale kiepsko:

    $regfile = "M32Def.dat"
    $crystal = 16000000
    $external Waitms
    
    'Const Xramdrive = 0
    
    Const Cmmc_soft = 0
    
    #if Cmmc_soft = 0
    
    ' --------- Start of Section for HW-SPI ----------------------------------------
    
       ' define Chip-Select Pin
       Config Pinb.4 = Output                                   ' define here Pin for CS of MMC/SD Card
       Mmc_cs Alias Portb.4
       Set Mmc_cs
    
       ' Define here SS Pin of HW-SPI of the CPU (f.e. Pinb.0 on M128)
       Config Pinb.7 = Output                                   ' define here Pin of SPI SS
       Spi_ss Alias Portb.7
       Set Spi_ss                                               ' Set SPI-SS to Output and High por Proper work of
                                                      ' SPI as Master
    
       ' HW-SPI is configured to highest Speed
      Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1       'Config Spi = Soft , Din = Pinb.3 , Dout = Portb.2 , Ss = Portb.0 , Clock = Portb.1
       Spsr.0 = 1                                               ' Double speed on ATMega128
       Spiinit                                                  ' Init SPI
    
    ' --------- End of Section for HW-SPI ------------------------------------------
    
    #else                                                       ' Config here SPI pins, if not using HW SPI
    
    ' --------- Start of Section for Soft-SPI --------------------------------------
    
       ' Chip Select Pin  => Pin 1 of MMC/SD
       Config Pinb.4 = Output
       Mmc_cs Alias Portb.4
       Set Mmc_cs
    
       ' MOSI - Pin  => Pin 2 of MMC/SD
       Config Pinb.5 = Output
       Set Pinb.5
       Mmc_portmosi Alias Portb
       Bmmc_mosi Alias 5
    
       ' MISO - Pin  => Pin 7 of MMC/SD
       Config Pinb.6 = Input
       Mmc_portmiso Alias Pinb
       Bmmc_miso Alias 6
    
       ' SCK - Pin  => Pin 5 of MMC/SD
       Config Pinb.7 = Output
       Set Pinb.7
       Mmc_portsck Alias Portb
       Bmmc_sck Alias 7
    
    ' --------- End of Section for Soft-SPI ----------------------------------------
    
    #endif
    
    ' ========== End of user definable range =======================================
    
    Spiinit
    ' Error
    Const Cperrdrivereset = 225                                 ' Error response Byte at Reset command
    Const Cperrdriveinit = 226                                  ' Error response Byte at Init Command
    Const Cperrdrivereadcommand = 227                           ' Error response Byte at Read Command
    Const Cperrdrivewritecommand = 228                          ' Error response Byte at Write Command
    Const Cperrdrivereadresponse = 229                          ' No Data response Byte from MMC at Read
    Const Cperrdrivewriteresponse = 230                         ' No Data response Byte from MMC at Write
    Const Cperrdrive = 231
    Const Cperrdrivenotsupported = 232                          ' return code for DriveGetIdentity, not supported yet
    
    Waitms 1                                                    ' Wait some time before initialising MMC/SD
    Dim Gbdriveerror As Byte                                    ' General Driver Error register
    Dim Gbdriveerrorreg As Byte                                 ' Driver load Error-Register of HD in case of error
    Dim Gbdrivestatusreg As Byte                                ' Driver load Status-Register of HD on case of error
    Dim Gbdrivedebug As Byte
    $lib "MMC.LIB"                                              ' link driver library
    $external _mmc
    Gbdriveerror = Driveinit()                                  ' Init MMC/SD Card
    
    
    Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Prescale = 1
    
    Pwm1a = 0
    Start Timer1
    'Config Date = Dmy , Separator = .
    Config Clock = soft
    Enable Interrupts
    Dim Co_2 As Bit
    
    Dim Bufor As Byte
    
    Dim B As Byte
    Dim S As String * 36
    
    '$include "Config_MMC.bas"
    $include "CONFIG_AVR-DOS.Bas"
    
    
    
    Gosub Ainit
    Do
    Loop
    
    Ainit:
    cli
    
    B = Drivecheck()                                            'u mnie te drivechecki itp. nigdy nie dawały errora ale dałem, żeby było
    
    
      ' Gbdriveerror = Driveinit()
    
    
    
    
    
    B = Initfilesystem(1)
    
    
    S = Dir( "wav.wav")
    While Len(s) > 0
    
    
       S = "wav.wav"
    
       Open S For Binary As #2
    Play:
    Do
    Get #2 , Bufor
    Pwm1a = Bufor
                              'o tu -------|
    Loop Until Eof(#2) <> 0
                          '                |  bez return - sam przeskakuje do next
    'trzeba dodać obsługę przycisku + skok-|
    Nex_t:
    Pwm1a = 0
    Close #2
    
    
       S = Dir()
    
    
    Gosub Play
    '(
    
    S = Dir( "ściągi.")
    If Len(s) = 0 Then
    Mkdir "ściągi"
    End If
    Chdir S
    Wait 2
    ')
    wend
    Return
    
    


    Fast PWM ? A jak to ustawić?
  • #28 7455823
    grysek
    Poziom 19  
    Nie wiem jak to bedzie po BASCOMowemu, najprościej chyba ustawić bity bezpośrednio w rejestrze :D
  • #29 7456600
    adambehnke
    Poziom 24  
    A więc tak oto wygląda końcowy działający kod (przykład do dalszej rozbudowy).
    Bez problemu odtwarza 32khz / 8 bit / mono / wav.
    Zastosowałem sterowanie odtwarzaniem poprzez UART ,tak więc mogę się bez problemu połączyć z innym prockiem.
    Mogłem zastosować "serialin" ale nie chciało mi się już bawić. Co prawda pewnie to dorobię , przynajmniej dodam opcję nagłego zatrzymnia odtwarzania-co może być przydatne przy odtwarzaniu dłuższych wav-ów.

    'dźwięk 32khz / 8 bit / mono / wav
    'do każdego nagranego pliku dodać z przodu pliku 10% czasu utworu ciszy potrzebej na załadowanie pliku.
    
    
    $regfile = "M32Def.dat"
    $crystal = 16000000
    $external Waitms
    $baud = 9600
    
    Const Cmmc_soft = 0                                         'SPI HARDWARE
    
    #if Cmmc_soft = 0
    
    ' --------- Start of Section for HW-SPI ----------------------------------------
    
       ' define Chip-Select Pin
       Config Pinb.4 = Output                                   ' define here Pin for CS of MMC/SD Card
       Mmc_cs Alias Portb.4
       Set Mmc_cs
    
       ' Define here SS Pin of HW-SPI of the CPU (f.e. Pinb.0 on M128)
       Config Pinb.7 = Output                                   ' define here Pin of SPI SS
       Spi_ss Alias Portb.7
       Set Spi_ss                                               ' Set SPI-SS to Output and High por Proper work of
                                                      ' SPI as Master
    
       ' HW-SPI is configured to highest Speed
      Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1       'Config Spi = Soft , Din = Pinb.3 , Dout = Portb.2 , Ss = Portb.0 , Clock = Portb.1
       'Spsr.0 = 1                                               ' Double speed on ATMega128
       Spiinit                                                  ' Init SPI
    
    ' --------- End of Section for HW-SPI ------------------------------------------
    
    #else                                                       ' Config here SPI pins, if not using HW SPI
    
    ' --------- Start of Section for Soft-SPI --------------------------------------
    
       ' Chip Select Pin  => Pin 1 of MMC/SD
       Config Pinb.4 = Output
       Mmc_cs Alias Portb.4
       Set Mmc_cs
    
       ' MOSI - Pin  => Pin 2 of MMC/SD
       Config Pinb.5 = Output
       Set Pinb.5
       Mmc_portmosi Alias Portb
       Bmmc_mosi Alias 5
    
       ' MISO - Pin  => Pin 7 of MMC/SD
       Config Pinb.6 = Input
       Mmc_portmiso Alias Pinb
       Bmmc_miso Alias 6
    
       ' SCK - Pin  => Pin 5 of MMC/SD
       Config Pinb.7 = Output
       Set Pinb.7
       Mmc_portsck Alias Portb
       Bmmc_sck Alias 7
    
    ' --------- End of Section for Soft-SPI ----------------------------------------
    
    #endif
    
    ' ========== End of user definable range =======================================
    
    Spiinit
    ' Error
    Const Cperrdrivereset = 225                                 ' Error response Byte at Reset command
    Const Cperrdriveinit = 226                                  ' Error response Byte at Init Command
    Const Cperrdrivereadcommand = 227                           ' Error response Byte at Read Command
    Const Cperrdrivewritecommand = 228                          ' Error response Byte at Write Command
    Const Cperrdrivereadresponse = 229                          ' No Data response Byte from MMC at Read
    Const Cperrdrivewriteresponse = 230                         ' No Data response Byte from MMC at Write
    Const Cperrdrive = 231
    Const Cperrdrivenotsupported = 232                          ' return code for DriveGetIdentity, not supported yet
    Waitms 1                                                    ' Wait some time before initialising MMC/SD
    Dim Gbdriveerror As Byte                                    ' General Driver Error register
    Dim Gbdriveerrorreg As Byte                                 ' Driver load Error-Register of HD in case of error
    Dim Gbdrivestatusreg As Byte                                ' Driver load Status-Register of HD on case of error
    Dim Gbdrivedebug As Byte
    $lib "MMC.LIB"                                              ' link driver library
    $external _mmc
    Gbdriveerror = Driveinit()                                  ' Init MMC/SD Card
    
    
    Dim Bufor As Byte
    Dim B As Byte
    Dim S As String * 8
    Dim Utwor As String * 5
    
    
    Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Prescale = 1
    
    Pwm1a = 0
    Start Timer1
    
    Config Clock = soft
    Enable Interrupts
    
    $include "CONFIG_AVR-DOS.Bas"
    
    
    
    
    
    cli
    B = Drivecheck()
    ' Gbdriveerror = Driveinit()
    B = Initfilesystem(1)
    S = Dir( "*.wav")
    
    'Open "COM1:" For Binary As #5                               'otwarcie uart
    
    
    
    
    
    'Pętla główna programu
    Do
    
    Utwor = Inkey()
    Utwor = Chr(utwor)
    
    
      If Utwor = "a" Then
      S = "1.wav"
      Gosub Play
      End If
    
      If Utwor = "b" Then
      S = "2.wav"
      Gosub Play
      End If
    
      If Utwor = "c" Then
      S = "3.wav"
      Gosub Play
      End If
    
      If Utwor = "d" Then
      S = "4.wav"
      Gosub Play
      End If
    
      If Utwor = "e" Then
      S = "5.wav"
      Gosub Play
      End If
    
      'itd  , itd
    
    
    
    Loop
    
    
    
    
    
    Play:
    
       If Len(s) < 3 Then Return
    
       Pwm1a = 0
    
       Open S For Binary As #2
         Waitms 1
    
            Do
    
              Get #2 , Bufor
              Pwm1a = Bufor
    
    
    
            Loop Until Eof(#2) <> 0
    
    
    
    
            Pwm1a = 0
            Close #2
            S = ""
    
    Return
    
  • Pomocny post
    #30 7457994
    PiotrEtenM500
    Poziom 19  
    No, świetne

    Szkada tylko, że potrzeba 2KB SRAM, mogło by to działać na niźszych uC
REKLAMA