Thanks for that. I'd be interested to know what speeds you can reach with the PIC running at 64MHz, with the MSSP at spiOscDiv4. If you get the chance to try the following benchmark code, I'd be interested to hear your results.
Kind regards,
Steve
Code: Select all
{
*****************************************************************************
* Name : BENCHMARK.BAS *
* Author : S Wright *
* Notice : Copyright (c) 2007 S Wright *
* : All Rights Reserved *
* Date : 25/10/2007 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
Device = 18F4620
Clock = 40
Config OSC = HSPLL
// Uses USART, SDFileSystem, Convert and String libraries...
#option SD_SPI = MSSP
#option SD_SPI_SPEED = spiOscDiv4
#option SD_SUPPORT_SUB_DIRECTORIES = True
#option SD_SUPPORT_MULTIPLE_FILES = True
Include "USART.bas"
Include "SDFileSystem.bas"
Include "String.bas"
Include "Convert.bas"
Const ClockDiv = _clock * 1000000
Dim Timer As TMR1L.AsWord // Alias to Timer1
Dim TimerOn As T1CON.Booleans(0) // Start and stop
Dim TimerInterruptsEnabled As PIE1.Booleans(0) // Enable interrupts
Dim Counter As LongWord
Dim CounterUpper As Counter.Word1
Dim Index1 As Byte
Dim Index2 As Word
Dim ReadOK As Boolean
Dim SerialNum As LongWord
Dim Response As Byte
Dim InitOK As Boolean
// Timer interrupt handler - every time Timer1 overflows, we
// need to increment the upper word of our big 32 bit counter...
Interrupt OnTimer()
Inc(CounterUpper)
PIR1.0 = 0
End Interrupt
Sub TimerStart()
Timer = 0 // Clear timer one
CounterUpper = 0 // Clear upper count value
TimerOn = True // Start timer
End Sub
Sub TimerStop()
TimerOn = False // Timer off
Counter.Word0 = Timer // Save what's left in timer one
End Sub
// Display time
Sub DisplayTime()
Dim Time As Float
Time = 4 * Counter / ClockDiv
USART.Write("Time Taken: ", FloatToStr(Time, 4, 2), " sec", 13, 10)
End Sub
// Main program...
SetBaudrate(br19200)
USART.ReadTerminator = #13
DelayMS(100)
TimerInterruptsEnabled = True // Enable timer interrupts
Enable(OnTimer) // Assign the interrupt handler
Repeat
InitOK = False
USART.Write("Insert SD/MMC:", 13, 10)
Repeat
Response = SD.Init
Until Response <> errNoResponse
If Response = errOK Then
USART.Write("Init Successful - Card Pre-formatted", 13, 10)
USART.Write("Quick Formatting:", 13, 10)
InitOK = SD.QuickFormat
If InitOK Then
USART.Write("QuickFormat Successful", 13, 10)
Else
USART.Write("QuickFormat Not Successful", 13, 10)
EndIf
ElseIf Response = errInvalidFormat Then
USART.Write("Init Failed - Card Not Formatted", 13, 10)
USART.Write("Formatting Now:", 13, 10)
{ If SD.Format(1) = errOK Then
USART.Write("Format Successful", 13, 10)
InitOK = True
Else
USART.Write("Format Not Successful", 13, 10)
EndIf }
EndIf
If InitOK Then
SerialNum = SD.SerialNumber
USART.Write("Serial Number: ", HexToStr(SerialNum, 8))
Select SerialNum
Case $00260010 USART.Write(" (IT Works 64MB MMC)", 13, 10)
Case $010366FE USART.Write(" (IT Works 64MB SD)", 13, 10)
Case $407CA4F6 USART.Write(" (ByteStor 128MB SD)", 13, 10)
Case $5048B63C USART.Write(" (Integral 128MB SD)", 13, 10)
Case $81B7762D USART.Write(" (Toshiba 512MB SD)", 13, 10)
Case $239005B8 USART.Write(" (Kingston 1GB SD)", 13, 10)
Case $0008C724 USART.Write(" (Sandisk UltraII 4GB SD)", 13, 10)
Else USART.Write(13, 10)
EndSelect
USART.Write("FAT Type: ")
Select SD.FATType
Case sdFAT16 USART.Write("FAT16", 13, 10)
Case sdFAT32 USART.Write("FAT32", 13, 10)
EndSelect
SD.MkDir("FOLDER")
SD.ChDir("FOLDER")
USART.Write("Opening New File:", 13, 10)
SD.NewFile(0, "TEST0001.TXT")
USART.Write("1MB Write Started:", 13, 10)
TimerStart()
Index2 = 0
Repeat
Index1 = 0
Repeat
SD.Write(0, Index1)
Inc(Index1)
Until Index1 = $00
Inc(Index2)
Until Index2 = $1000
TimerStop()
SD.CloseFile(0)
USART.Write("1MB Write Completed", 13, 10)
DisplayTime()
If Not SD.RWError Then
USART.Write("Write OK - No RWErrors", 13, 10)
Else
USART.Write("WARNING - Write RWErrors Encountered!", 13, 10)
EndIf
USART.Write("Opening File:", 13, 10)
SD.OpenFile(0, "TEST0001.TXT")
USART.Write("1MB Read Started:", 13, 10)
ReadOK = True
TimerStart()
Index2 = 0
Repeat
Index1 = 0
Repeat
If SD.ReadByte(0) <> Index1 Then
ReadOK = False
EndIf
Inc(Index1)
Until Index1 = $00
Inc(Index2)
Until Index2 = $1000
TimerStop()
SD.CloseFile(0)
USART.Write("1MB Read Completed", 13, 10)
DisplayTime()
If ReadOK Then
USART.Write("Read OK - Readback Identical", 13, 10)
Else
USART.Write("WARNING - Read Errors Encountered - Readback Not Identical!", 13, 10)
EndIf
If Not SD.RWError Then
USART.Write("Read OK - No RWErrors", 13, 10)
Else
USART.Write("WARNING - Read RWErrors Encountered!", 13, 10)
EndIf
EndIf
USART.Write("------------------------------------------------------------", 13, 10)
Repeat
Until Not SD.DiskMounted
Until False