VS1001a module help

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

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

VS1001a module help

Post by qwall » Sat Jan 03, 2009 12:28 am

I am trying to use the VS1001a module but I get an error in the module. When I try to compile I get "[Error] vs1001a.bas(35): END expected". I am using the module as well as the example code provided. I am new to Swordfish coming from many years of using Proton so it is not apparent to me where the problem is. I am sure there is something obvious I am missing. Any help pointing me in the right direction would be appreciated.

Thanks,
qwall

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

Post by Doj » Sat Jan 03, 2009 3:45 pm

hello quall,
This error can occur for several reasons.
1, an IF-THEN without ENDIF
2, a WHILE without WEND
3, a CONST or DIM declaration which has several lines and the final one has a comma where it should not.

There could be others but its a bit hard to know without running the code.

If you are not able to find it easily then the best way to see where the error is then comment chunks of code out(using { and }), start with a great big lump then slowly reduce it until you find the issue.

If you still have issues tell us more about the code(is it on the WiKi?) and where to download it and I might get 5 mins to look myself.

I also have been using PDS for a very long time, and a very fine compiler it is, but write code exclusively with SF these days out of preference rather than any technical reasons.

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

Post by qwall » Sat Jan 03, 2009 5:04 pm

Doj,

Thanks for the reply. The module I am using is indeed on the wiki at http://www.sfcompiler.co.uk/wiki/pmwiki ... ser.VS1001 The error is at the first DIM statement. I actually did comment out chunks of code, but the error continued to move down the module. I will take another look.

Thanks,
qwall

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

Post by Doj » Sat Jan 03, 2009 9:09 pm

ok quall, I have it compiled.
There is an error, just a tiny one and it is one of those I mentioned.
The line "RegVolume = 11" has a comma missing from its end.
when using CONST you can write:-

Code: Select all

CONST OpRead = 3
CONST OpWrite = 2
CONST RegMode = 0
Or to make less typing you can us a single instance of CONST and separate the values with commas, the last one does not use a comma as that indicates the last value in this code section:-

Code: Select all

Const 
      OpRead = 3,
      OpWrite = 2,
      RegMode = 0
This is also exactly the same, SF ignores all the whitespace:-

Code: Select all

Const OpRead = 3, OpWrite = 2, RegMode = 0
Its all in the help file(which is very good).

Also if it is not clear the way to use the code on the wiki is to copy the part below(and including) the line "Module VS1001a" into a new file in the SF IDE.
Now save is as "VS1001a.bas", this is now a MODULE type of file(although saved as .BAS, it is not the place to write your main code, it is effectively a depository for a group of subroutines(how I think of it)).

Your main code should be a separate file opened in the SF IDE and headed with "PROGRAM ....." like this:-

Code: Select all

Program test_vs1001

Device=18f452
Clock=16
#option SD_SPI = MSSP
#option SD_CS = PORTC.0                     // SPI CS To SD CS (SD pin 1)
#option SD_SUPPORT_SUB_DIRECTORIES = false
#option SD_SUPPORT_MULTIPLE_FILES = false
#option SD_REINIT_SPI = false
#option SD_SPI_SPEED = spiOscDiv64               ' 4,16,64
Include "SDFileSystem.bas"

Include "vs1001a.bas"

// main ------------------------------------
VS1001a.Initialize(25000)
Repeat
Until SD.Init()=errOK

If SD.OpenFile("seq_01.mp3") = errOK Then
  VS1001a.Reset(false)
  While Not SD.EOF
    SD.ReadNBytes(junk,32)
    For i=0 To 31
      VS1001a.WriteByte(junk(i))
    Next
  Wend
  SD.CloseFile
EndIf
Save it as a convenient name such as "test_vs1001.bas".
Whenever you compile you must do it from this "Program" file, all other code can be in the "Module" types as long as you "Include" them, they must be in the correct location or you can put the path name in the include, and do not forget about "SCOPE"!!!, that willl bite you sometime.

As the sample code is above it does not compile unless you comment out some parts that need looking into, or I do not have all the correct includes on my machine, but you should now be able to get help from someone who knows more about this module(I have never seen it before!)

This compiles ok(with warnings), it is the same as above just bits commented out:-

Code: Select all

Program test_vs1001

Device=18f452
Clock=16
#option SD_SPI = MSSP
#option SD_CS = PORTC.0                     // SPI CS To SD CS (SD pin 1)
#option SD_SUPPORT_SUB_DIRECTORIES = false
#option SD_SUPPORT_MULTIPLE_FILES = false
#option SD_REINIT_SPI = false
#option SD_SPI_SPEED = spiOscDiv64               ' 4,16,64
Include "SDFileSystem.bas"

Include "vs1001a.bas"

// main ------------------------------------
VS1001a.Initialize(25000)
'Repeat
'Until SD.Init()=errOK

If SD.OpenFile("seq_01.mp3") = errOK Then
  VS1001a.Reset(false)
  While Not SD.EOF
    'SD.ReadNBytes(junk,32)
    For i=0 To 31
      'VS1001a.WriteByte(junk(i))
    Next
  Wend
  SD.CloseFile
EndIf

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

Post by qwall » Sun Jan 04, 2009 1:59 am

Doj,

Thank you for taking the time to write such an extensive explanation. I did have another look at the module and found the error thanks to your suggestions. Sorry I didn't have a chance to post a reply earlier. The implementation of the module looks to be very straight forward. However, I think I still have much to learn about Swordfish. Thanks again.

qwall

Post Reply