Shop OBEX P1 Docs P2 Docs Learn Events
SD2.0 Full FAT32/16 File Sytem Driver - You there! Yes you, viewing this forum. - Page 9 — Parallax Forums

SD2.0 Full FAT32/16 File Sytem Driver - You there! Yes you, viewing this forum.

145679

Comments

  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-12-10 19:41
    Attached is the latest version of KyeDOS. Fixed a few bugs in the xmodem file transfer as it was not recovering from a corrupted packet. For files > about 100k, there seem to always be the odd corrupted packet, and now it can recover and resend the packet.

    The default baud rate has been changed to 115200. Some terminal programs cannot handle this speed, eg Teraterm. Shamcom (Shamrock Software) works fine. 115k is limited more by the speed of Spin than by the download rate.

    Re sd cards, I have a 22uF tantalum and a 0.1uF bypass cap right at the sd card power pins. Also I've found the sd card needs to be physically close to the propeller. Max 2cm track length.

    So far, every brand I have tried works with Kye's driver code.
  • MacTuxLinMacTuxLin Posts: 821
    edited 2010-12-11 00:38
    Hi Dr_Acula,
    May I know the extra 22uF tantalum cap is needed due to your application or its a better general practice? I only place a 0.1uF bypass cap & don't have any problem with trace more than 2cm.
    382 x 340 - 21K
  • KyeKye Posts: 2,200
    edited 2010-12-11 07:13
    Oh, hey all I should be done with the SD3.0 FatEngine by January.

    Pathing works now! Plus its twice as fast without read ahead and write behind implemented. It might be 4 times faster than the SD2.0 fatengine when I am done.

    (Pathing allows you to do stuff like "bin\stuff\code.spin" or stuff like "hello\..\hello\.\subHello\target.txt"
  • MacTuxLinMacTuxLin Posts: 821
    edited 2010-12-11 08:30
    Wow, super!
  • Dan EDan E Posts: 61
    edited 2010-12-11 09:35
    I would like to use this object to play a WAV file from the SD card, from what I've gathered so far I think the parts I need to call and/or modify pin selection are:

    - formatPartition and mountPartition, to access SD card

    - FATEngineStart, to assign pin selection for SD adapter

    -programPlayWavFile, to play Wav file

    I would appreciate some help in making this work properly, so that I can include audio in my school project Tuesday. I have a 16 Ohm, 200mW audio amplifer unit with speaker, for the output.

    Thank you,
    Dan E
  • KyeKye Posts: 2,200
    edited 2010-12-11 11:38
    If you have my DACEngine and FATEngine... then here is the code you need.
    PRI playWAV(fileName)
     
      if(playerID)
        cogstop(-1 + playerID~)
     
      playerDoneFlag := false
      playerID := (cognew(WAVPlayer(fileName), @WAVStack) + 1)
     
    PRI WAVPlayer(fileName)
     
      fat.mountPartition(0, 0)
      fat.openFile(fileName, 0)
     
      fat.changeFilePosition(22)
      dac.numberOfChannelsSetup(fat.readShort)
     
      dac.sampleRateSetup(playerSpeed := fat.readLong)
     
      fat.changeFilePosition(34)
      result := fat.readShort
     
      dac.bitsPerSampleSetup(result)
      dac.sampleSignSetup(result == 16)
     
      fat.changeFilePosition(40)
     
      dac.startPlayer
      repeat (fat.readLong >> 9)
        fat.readData(dac.transferData, 512)
     
      dac.clearData
      dac.stopPlayer
     
      fat.unmountPartition
      playerDoneFlag := true
      cogstop(cogid)
     
    DAT WAVDat
     
    playerSpeed        long 0
    playerID               byte 0
    playerDoneFlag     byte 0
    WAVStack           long 0[100] 
    
  • Dan EDan E Posts: 61
    edited 2010-12-11 12:05
    Thank you very much, this is extremly helpful, and exactly what I need.

    Is this how I would change LeftPinNumber and RightPinNumber in the DACengine object to work for my audio output?

    Example:

    Change
    result := ((leftPinNumber <# 31) #> 0)

    To
    result := ((6 <# 31) #> 0) ?

    In my case, pin 6 is my audio output, and I have one speaker, so I see I would make the inactive speaker in the code assigned -1.

    Thanks again,
    Dan E
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-12-11 12:12
    Dan E: Somewhere in the code LeftPinNumber will have been defined. It is best to change it there rather than what we call hard coding it in an instruction. It should be near the top of one of the files.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-12-11 14:17
    Hi Dr_Acula,
    May I know the extra 22uF tantalum cap is needed due to your application or its a better general practice? I only place a 0.1uF bypass cap & don't have any problem with trace more than 2cm.

    Maybe it isn't totally necessary, but I had a board that was unstable without it. It was also before Kye's code was written, so possibly it was the sd card brand, not the board. In any case, I tend to buy 0.1uF caps and 22uF tantalums in bulk, so they are very cheap.

    Another general reason is that any part that is using a lot of current and where that current is changing rapidly ought to have its own capacitor. This reduces noise on the supply lines. Things like the keyboard, mouse, LCD display and VGA display do use current but it is fairly constant. But the SD card uses a lot more when it is in use compared with idling.

    If money is tight, I might suggest that you could try leaving it out, but if you are designing a board, at least put the pads in.
    Oh, hey all I should be done with the SD3.0 FatEngine by January.

    That sounds great! As a general idea, how quick is a reboot of a binary file (ie the command that loads a binary file into ram and then runs it)?
  • KyeKye Posts: 2,200
    edited 2010-12-11 19:33
    2 seconds now, should be able to get it down to 1
  • Dan EDan E Posts: 61
    edited 2010-12-11 19:33
    Hi,
    I made an object to test using the code you supplied me, and I received an error due to my own input ofcourse, when I tried to assign my output pin.

    Not sure what the propeller tool is trying to tell me, but I assume its either a syntax error or I improperly used an operator.

    Attached here what is a print capture of what I added before your code and the error I received with the problem highlighted in white:

    Capture.PNG


    It seems like a simple fix, but I just don't understand what exactly my error was.

    Thanks for the help,
    Dan E
    586 x 524 - 48K
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-12-11 21:44
    One second? Yikes, the code I have is more like 5 seconds. One second reboots will be sweet.

    @Dan, := is for the PUB code, but within VAR statements try using =

    None of this is logical. I tend to copy existing code nearby.
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2010-12-11 21:59
    I want SD Card FAT16/32 code that can do more than one file at a time. I don't understand why no one has done it before...
  • Dan EDan E Posts: 61
    edited 2010-12-11 22:46
    Thanks, that fixed that error, plus I changed my pin selections to constants rather than variables, since they will be constant. Also, I included the objects used in the code, which I neglected to do previously.

    But now when I ran the file, I received an error saying " expected subroutine" when it calls the DACEngine, so I looked in that object, and it did include everything it called, for some reason that message came up each time, even if i commented out some lines.

    Maybe I could have included the wrong file?

    Attached below is the message and code:

    Capture2.PNG


    Thanks,
    Dan
    592 x 661 - 55K
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-12-12 02:01
    I'm not having much luck replicating that error. Any chance you could bundle up all the files into a zip and post them here? Cheers.
  • jmspaggijmspaggi Posts: 629
    edited 2010-12-12 06:09
    Roy Eltham wrote: »
    I want SD Card FAT16/32 code that can do more than one file at a time. I don't understand why no one has done it before...

    Kye's driver is doing that...

    I'm using with with 2 files at a time. I just have 2 FAT objects declared.

    JM
  • Dan EDan E Posts: 61
    edited 2010-12-12 06:30
    Dr_Acula wrote: »
    I'm not having much luck replicating that error. Any chance you could bundle up all the files into a zip and post them here? Cheers.
    ,

    When gathering thwe files in a folder, i realized there were other files in that folder that may have been conflicting, so I removed all other files from the folder, ran the program again, and it worked this time.

    Thanks,
    Dan
  • KyeKye Posts: 2,200
    edited 2010-12-12 06:49
    Multiple copies of the object allow for multiple files.
  • MacTuxLinMacTuxLin Posts: 821
    edited 2010-12-12 06:51
    Dr_Acula wrote: »
    Another general reason is that any part that is using a lot of current and where that current is changing rapidly ought to have its own capacitor. This reduces noise on the supply lines. Things like the keyboard, mouse, LCD display and VGA display do use current but it is fairly constant. But the SD card uses a lot more when it is in use compared with idling.

    If money is tight, I might suggest that you could try leaving it out, but if you are designing a board, at least put the pads in.

    Thanks. I'll definitely place that into my design in the next revision after I have it tested together with other changes. My app is servos (>16) per board so the board is practically populated by caps.
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2010-12-12 08:04
    Multiple copies, so multiple cogs? or what? Also, seems pretty expensive to have to bring in all that code multiple times...
  • Heater.Heater. Posts: 21,230
    edited 2010-12-12 08:32
    Roy,

    Instantiating multiple instances of an object in your code does not pull the compiled code in multiple times, only once.
    Also only one DAT section is created in the binary, shared among all instances.
    The VAR section IS duplicated for each of the instances.
    The result is that using a Spin object multiple times does not eat memory.

    Next up instantiating Spin objects does not necessarily mean you are using COGs. Perhaps the object only provides methods that are called.

    So hopefully Kye's file system can be instantiated multiple times without much expense in memory and COG use. On instance per open file required each using their own VAR space to maintain the file info.

    Also hopefully all instances can use the same single instance of the low level SD block driver.

    I have no idea if Kye has done things like this but I suspect he has. This issue has been discussed before.
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2010-12-12 10:47
    Heater,
    Ok, that's very good information that I wasn't fully aware of. I did know that it wasn't going to repeat the spin code parts, wasn't sure about the pasm/cog parts. I was mostly concerned with the cog usage. If it does share one instance of the low level driver in one cog between the different FAT engine instances, then that's great.
  • Dan EDan E Posts: 61
    edited 2010-12-12 11:52
    Hi, I tried asigning the name of my sample WAV file "Ten" to "fileName" so that it calls my file and that I don't replace your variable, but came up with an error, I belive its a syntax issue or that I'm declaring it at the wrong spot.

    Any suggestions on how to assign my file name to "fileName"?

    Here is what I put and the error:

    Capture3.PNG


    Thanks,
    Dan
    627 x 649 - 44K
  • Mike GMike G Posts: 2,702
    edited 2010-12-12 12:08
    @Dan, Why not just use a different constant name like FILE_NAME. That way you don't have the naming conflict.
  • KyeKye Posts: 2,200
    edited 2010-12-12 12:13
    @Roy - It works just like you want and think.
  • KyeKye Posts: 2,200
    edited 2010-12-12 12:15
    @Dan - Constants need to be a single number/digit/etc.

    They can't be a string. You need to declare a DAT section and make some strings in there.
  • Dan EDan E Posts: 61
    edited 2010-12-12 14:08
    Still not able to assign file to variable correctly
    Capture4.PNG

    I understand I can't have conflicting names, but what i am trying to do is make it so it calls my file.

    Also, in order to play my file, do I need to call it in my PUB or will it automatically play as the program reads this object?

    Thanks,
    Dan
    649 x 633 - 53K
  • KyeKye Posts: 2,200
    edited 2010-12-12 17:49
  • Mike GMike G Posts: 2,702
    edited 2010-12-12 18:37
    Oops Kye's right you need a DAT section for a string. Plus you want to zero terminate the string. See the Propeller manual.
  • Dan EDan E Posts: 61
    edited 2010-12-12 21:34
    Thanks, I noticed some things from your example that I was missing. It compiled fine after adding them, though nothing played through my speaker, so I think it may just be a hardware issue, and I will have to check my connections tomorrow.

    Capture5.PNG
    595 x 764 - 37K
Sign In or Register to comment.