18F26K20 SD Testing

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Sat Apr 25, 2009 6:22 am

Hi RD,

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

RDHeiliger
Registered User
Registered User
Posts: 26
Joined: Sun Oct 12, 2008 11:21 pm
Location: Utah

SDFileSystem Benchmark for 18F46K20

Post by RDHeiliger » Sat Apr 25, 2009 5:10 pm

Results of above benchmark test.
All tests done with internal oscilator.
PLL used to get 32 and 64 MHz
PIC18F46K20-I/P

Failed to format card at 64 MHz and div 4
passed at 64MHz and div 16.

Code: Select all

Device = 18F46K20
Clock = 8
Config
   FOSC = INTIO67,
   WDTEN = OFF,   
   BOREN = OFF
#option SD_SPI = MSSP 
#option SD_SPI_SPEED = spiOscDiv4
OSCCON = %01100000   
OSCTUNE = %10000000
  
Insert SD/MMC:
Init Successful - Card Pre-formatted
Quick Formatting:
QuickFormat Successful
Serial Number: B19458DA
FAT Type: FAT16
Opening New File:
1MB Write Started:
1MB Write Completed
Time Taken: 0088.34 sec
Write OK - No RWErrors
Opening File:
1MB Read Started:
1MB Read Completed
Time Taken: 0057.14 sec
Read OK - Readback Identical
Read OK - No RWErrors
------------------------------------------------------------

Device = 18F46K20
Clock = 16
Config
   FOSC = INTIO67,
   WDTEN = OFF,   
   BOREN = OFF
#option SD_SPI = MSSP 
#option SD_SPI_SPEED = spiOscDiv4
OSCCON = %01110000   
OSCTUNE = %10000000  

Insert SD/MMC:
Init Successful - Card Pre-formatted
Quick Formatting:
QuickFormat Successful
Serial Number: B19458DA
FAT Type: FAT16
Opening New File:
1MB Write Started:
1MB Write Completed
Time Taken: 0047.19 sec
Write OK - No RWErrors
Opening File:
1MB Read Started:
1MB Read Completed
Time Taken: 0028.77 sec
Read OK - Readback Identical
Read OK - No RWErrors
------------------------------------------------------------

Device = 18F46K20
Clock = 32
Config
   FOSC = INTIO67,
   WDTEN = OFF,   
   BOREN = OFF
#option SD_SPI = MSSP
#option SD_SPI_SPEED = spiOscDiv4
OSCCON = %01100000   
OSCTUNE = %11000000 

Insert SD/MMC:
Init Successful - Card Pre-formatted
Quick Formatting:
QuickFormat Successful
Serial Number: B19458DA
FAT Type: FAT16
Opening New File:
1MB Write Started:
1MB Write Completed
Time Taken: 0026.93 sec
Write OK - No RWErrors
Opening File:
1MB Read Started:
1MB Read Completed
Time Taken: 0014.59 sec
Read OK - Readback Identical
Read OK - No RWErrors
------------------------------------------------------------

Device = 18F46K20
Clock = 64
Config
   FOSC = INTIO67,
   WDTEN = OFF,   
   BOREN = OFF
#option SD_SPI = MSSP
#option SD_SPI_SPEED = spiOscDiv4
OSCCON = %01110000   'set sleep not idle,use 16MHz internal freq,use primary clock
OSCTUNE = %11000000 

Insert SD/MMC:
Init Successful - Card Pre-formatted
Quick Formatting:
Insert SD/MMC:
Insert SD/MMC:
Init Failed - Card Not Formatted
Formatting Now:
------------------------------------------------------------

Device = 18F46K20
Clock = 64
Config
   FOSC = INTIO67,
   WDTEN = OFF,   
   BOREN = OFF
#option SD_SPI = MSSP
#option SD_SPI_SPEED = spiOscDiv16
OSCCON = %01110000   
OSCTUNE = %11000000 

Insert SD/MMC:
Init Successful - Card Pre-formatted
Quick Formatting:
QuickFormat Successful
Serial Number: B19458DA
FAT Type: FAT16
Opening New File:
1MB Write Started:
1MB Write Completed
Time Taken: 0019.87 sec
Write OK - No RWErrors
Opening File:
1MB Read Started:
1MB Read Completed
Time Taken: 0009.16 sec
Read OK - Readback Identical
Read OK - No RWErrors
------------------------------------------------------------

Note that it is significantly faster at 64Mhz div16 than 32MHz div 4

Done on a "Techtron 1GB" card. Picked up on ebay for $1.00

enjoy!

RD

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Sun Apr 26, 2009 12:29 pm

Thanks very much RD. That's very helpful and I appreciate the careful results that you have posted. I'll have to get a K series PIC to try.

liak
Registered User
Registered User
Posts: 195
Joined: Fri Oct 05, 2007 12:26 am

Post by liak » Thu Apr 30, 2009 10:57 pm

Dear RD,

Great to hear that you have made such a breakthrough.! :D

I was held off from trying with my own K series earlier.
Now I have to go back and retry it.

Will need your help if I run into problem.

Regards,
Liak

RDHeiliger
Registered User
Registered User
Posts: 26
Joined: Sun Oct 12, 2008 11:21 pm
Location: Utah

Post by RDHeiliger » Fri May 01, 2009 3:01 am

I have put together another board with just 10K pullups on the DO and DI lines that works just fine. I also used just a single 1 amp 3.3 volt regulator with a 10uF electrolytic after to stabilize. The spec of 60 mA on read and write to the microSD card was a bit surprising and the major culprit in not being able to get the SDFileSystem to work. I also made the changes to the def files about the Ram sizes being wrong. Even tho I wasn't having a problem there.

The price alone is worth playing with the K series. I like the 64K of program and 4K of ram. The high speed internal oscillator is nice too. But the 1.2V internal voltage reference for A/D saves a lot of external circuitry too, especially on a 3.3V processor. I am using a battery backup for a real time clock on Timer1 and run the 3.3V thru an isolation diode to the uC. The internal reference then eliminates an external reference. It also allows one to use all 13 analog inputs.

I also found two different errata on the chip, one for the initial silicon and one for the B series silicon. The notes on the MSSP are different between the two. There is also a note on internal oscillator problems. Neither seems to be a problem tho. I think if you read the serial number out of the chip you have, the B in front of the serial number will tell you what silicon version you may have. Mine has a B in front.

Think the next chip to play with is the 25J50, with on board real time clock and capacitive switch input capability!

RD

qwall
Posts: 6
Joined: Fri Jan 02, 2009 11:28 pm

Post by qwall » Mon May 11, 2009 8:01 pm

I am hoping someone can help me out. I have been using Steven's SD file system on a 18F25K20 without any issues. I am trying to migrate to the 18F26K20 but I can't read from the SD card without errors. I have 2 identical boards, one with the 18F25K20 and the other with a 18F26K20.

I have run the benchmark.bas code on both and I always get the following error with the 26K20 part:

------------------------------------------------------------
Insert SD/MMC:
Init Successful - Card Pre-formatted
Quick Formatting:
QuickFormat Successful
Serial Number: 4072D0C7
FAT Type: FAT16
Opening New File:
1MB Write Started:
1MB Write Completed
Time Taken: 0016.20 sec
Write OK - No RWErrors
Opening File:
1MB Read Started:
1MB Read Completed
Time Taken: 0003.98 sec
WARNING - Read Errors Encountered - Readback Not Identical!
Read OK - No RWErrors
------------------------------------------------------------

I am running the chip at 64MHz (16MHz internal + PLL). I have tried using spiOscDiv16 & spiOscDiv64 and I have all the necessary pullup resistors. I am begining to think that it is a silicon issue. The 26K20 has a silicon revision of x09 but I am not sure how that relates to the errata revision. Any ideas would be greatly appreciated.

Dan

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Mon May 11, 2009 8:11 pm

Take a look at my thread to see if this solves the issue.
http://www.sfcompiler.co.uk/forum/viewt ... ight=46k20

qwall
Posts: 6
Joined: Fri Jan 02, 2009 11:28 pm

Post by qwall » Mon May 11, 2009 8:50 pm

Doj,

That solved it! I never once thought that is might be a compiler issue. Thank you for the quick reply and the solution.

Dan

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Mon May 11, 2009 11:24 pm

It is NOT A COMPILER ISSUE.
If you take a good look at the thread you will see the issue lies at Microchips door.
The configuration files are generated automatically using Microchip information which for some unknown reason has been published incorrectly in this instance (copied no doubt from a previous data set)

qwall
Posts: 6
Joined: Fri Jan 02, 2009 11:28 pm

Post by qwall » Tue May 12, 2009 5:38 am

Sorry, I did not read the whole thread. :oops:

User avatar
ohararp
Posts: 194
Joined: Tue Oct 03, 2006 11:29 pm
Location: Dayton, OH USA
Contact:

Post by ohararp » Sun Sep 27, 2009 2:35 pm

I have my gps logger up and running with the 18F26K20 now! Great stuff. I can now move to the smaller qfn package for a new iteration of this product.
Thanks Ryan
$25 SMT Stencils!!!
www.ohararp.com/Stencils.html

Post Reply