BS2 Library Testing
Martin Hebel
Posts: 1,239
I've been playing around making a BS2 Library, so far with PULSOUT, PULSIN, FREQOUT, PAUSE and RCTime. Here's some sample code to use it. One cog is reading RCTime on a PhotoR and another Cog is using that data to sound a tone on a buzzer. They share a common global variable so they can both be doing their own thang simultaneously:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Perform a Survey of Electronic Technology Employers - Click here!
Personal Links with plenty of BASIC Stamp info
and SelmaWare Solutions - StampPlot - Graphical Data Acquisition and Control
Post Edited (Martin Hebel) : 3/3/2006 3:57:24 PM GMT
{{ ____________________________________________________________________ Test of BS Function Library This test reads RC Time of Cap & Photoresistor on A4 on one cog and plays frequency of RCTime value on another cog from A0 for multiprocessor BS2. Data is passed using global variable. ___________________________________________________________________ }} CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 VAR Long RC_Val, stack1[noparse][[/noparse]50], Stack2[noparse][[/noparse]50] CON ' Set Pins Buzzer = 0 ' Speaker PhotoR = 4 OBJ BS2 : "BS2_Functions" ' Create BS2 Object PUB Start BS2.start ' Initialize BS2 library cognew(GetTime,@stack1) ' Start a cog to run RCTime routine cognew(SoundTime,@stack2) ' Start a cog to run FREQOUT routine 'cognew(SoundTime2,@stack2) ' Start a cog to run FREQOUT_SET routine - Use this instead one for smoother tone PUB GetTime '' Routine to read RCTime and store in global RC_Val repeat dira[noparse][[/noparse]PhotoR]~~ ' set to output outa[noparse][[/noparse]PhotoR]:=1 ' set high BS2.Pause(10) ' allow to charge for 10mS RC_Val:= BS2.RCTime(PhotoR,1) ' read RCTime and store in RC_Val BS2.Pause(500) ' Pause this routine for 1/2 second to prove other still runs PUB SoundTime '' Routine to sound frequency repeat BS2.Freqout(Buzzer,100,RC_Val) ' Continually sound buzzer at RC_Val value PUB SoundTime2 '' Uses modified FREQOUT_SET Command '' Sounds tone continually, only updates when new value Repeat BS2.Freqout_SET(Buzzer,RC_Val)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Perform a Survey of Electronic Technology Employers - Click here!
Personal Links with plenty of BASIC Stamp info
and SelmaWare Solutions - StampPlot - Graphical Data Acquisition and Control
Post Edited (Martin Hebel) : 3/3/2006 3:57:24 PM GMT
Comments
#1: PUB Start is a "key word" routine, or event?· If so, are there other "key" routines / events ?
#2: Reading the CogNew command, I can see you specify the PUB (or PRI?) routine for that cog to run, and it's stack space.· Can you pass paramiters?
#3: The VAR RC_Val, definded at the top of the file indicates the VAR is globally accessable;·
····· To be private, I would have declared them in the PUB or PRI routine?
#4: Seeing the PUB GetTime, it doesn't use any VARs, but it requires·VAR space ( ie: @Stack1 in the command ) ?
#5: What would be the difference in declaring PUB GetTime or PRI GetTime ?·
Oh, and one last one...
So, a PUB Routine_Name would indicate a Global level Routine, ... Ok... hang on a second... I think someone just turned on the lights...
Does the compiler looks at things like this:· ( this is a question...)
If this is getting too detailed then skip it, I'll wait for the docs to be published.·
THis code is very is easy·to read and understand.
Thanks for posting it!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
·
PUB Routine_Name(arg0, arg1, arg2):return_value | local_variable1, local_variable2
A private function (a routine only called by routines within the object) is declared the same way but with PRI instead of PUB.
The arguments, return value and local (private) variables are all optional so you can get functions that look like:
PUB Routine1
PUB Routine2(pin1, pin2)
PUB Status_Check:OK
PRI Do_something | i, t
PRI Do_something_else:Status | h,k
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
#1: PUB Start is a "key word" routine, or event?· If so, are there other "key" routines / events ?
PUB is a public function/method/subroutine (or whatever you care to name it, haven't read the full docs yet to see conventions)· This means if the program you see was used as an object for another file, those functions would be accessible.· If they were PRI, they wouldn't be.
#2: Reading the CogNew command, I can see you specify the PUB (or PRI?) routine for that cog to run, and it's stack space.· Can you pass paramiters?
When the stack space is address is passed, both programs can have access to the same memory locations, meaning you can write in one and read in another.· When starting an Assembler COG, the pointer is passed also so it can be shared through the ASM code as well!· Potent, huh?
#3: The VAR RC_Val, definded at the top of the file indicates the VAR is globally accessable;·
····· To be private, I would have declared them in the PUB or PRI routine?
Yes, it is global to all the functions, not matter which cog it's in.· To be private and local, it would be declared in the function:
PUB· ReadMe (passed1, passed2) | mylocal1, mylocal2
#4: Seeing the PUB GetTime, it doesn't use any VARs, but it requires·VAR space ( ie: @Stack1 in the command ) ?
Yes, not an expert at this yet, still learning, but the functions that routine calls needs stack space for the variables it may use.· This part gets tricky on how much to allocate.
#5: What would be the difference in declaring PUB GetTime or PRI GetTime ?·
I think I answered this in #1
Oh, and one last one...
So, a PUB Routine_Name would indicate a Global level Routine, ... Ok... hang on a second... I think someone just turned on the lights...
The BS2_Functions spin file uses PUBs like RCTIme so they can be accessed as object function in the code you·see.· It may also have PRI functions that would NOT be accessible to the test code you see.
Maybe I should post my BS2_Functions code as well later.
I'll have to take a closer look at the code you wrote later in depth.· Duty calls.
Glad it helped light some lights [noparse]:)[/noparse]
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Perform a Survey of Electronic Technology Employers - Click here!
Personal Links with plenty of BASIC Stamp info
and SelmaWare Solutions - StampPlot - Graphical Data Acquisition and Control
Also note the documentation the Spin IDE makes from the code above: (Ok, still learning here, so may be better ways, but....)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Perform a Survey of Electronic Technology Employers - Click here!
Personal Links with plenty of BASIC Stamp info
and SelmaWare Solutions - StampPlot - Graphical Data Acquisition and Control
What about SERIN/SEROUT ?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Thanks inaki,
Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Perform a Survey of Electronic Technology Employers - Click here!
Personal Links with plenty of BASIC Stamp info
and SelmaWare Solutions - StampPlot - Graphical Data Acquisition and Control
Martin, so you are doing SHIFTIN/OUT in spin? I found spin·to woefully inadequate for high speeds, Ive tossed the spin version and am presently working on ASM to define them with spin wrapper functions. Im following the full_duplex model in it's operation. Though you may find a speedier way to do it in spin than my first attempt.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 3/3/2006 5:34:28 PM GMT
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Perform a Survey of Electronic Technology Employers - Click here!
Personal Links with plenty of BASIC Stamp info
and SelmaWare Solutions - StampPlot - Graphical Data Acquisition and Control
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Perform a Survey of Electronic Technology Employers - Click here!
Personal Links with plenty of BASIC Stamp info
and SelmaWare Solutions - StampPlot - Graphical Data Acquisition and Control
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
This is resembling something like a 3G IDE... (Like the functionality of the vb 6 IDE)..
Martin, thanks a lot for explaining, and with your answers (and the code!), it makes a whole lot more sence.
I like the way the code 'reads'.... easy to follow and understand...
Very memory effencant (sp!)...
Ya, the lights are getting bright... I'll get my shades and continue on...
I cant wait...
I have been a VB programmer sence VB DOS (ver 1.0), and all the way up through .net 2005... so, what your building with the objects, and the modeling
is very much like class and oop in VB... very VERY simular... issues are... no GIU (Ok, I can live with that... make one out of LCD and some buttons...)
No "canned" events... (you would make events from watching pins...)
The way you are calling things objects are VERY simular to VB's classes... public and private functions and subs... delercations and returns...
Still, if you know VB classes, then the only thing to do here is learn the syntax of the language and to program within it's memory limits.
Still, not much of an issue...
Man, this is exciting. I can see dozens of usages...
I will add, your code examples are awesome to read. I can actually understand without know the language syntax, what your are doing.. (I guess your style helps !).
April isn't gonna get here fast enough!.
Questions about the IDE folks:
#1: Can it PLEASE compile without the propeller dev board attached?
#2: Does it have a object explorer ??
#3: Project based, not file based? (IE, A project can have a number of files with it.)
#4: Proper casing of declared vars. IE, if you delcare VAR Ddiksoak, type in ddiksoak, it will change it to Ddiksoak
#5: Printer support (for printing out code!)
Lastly, do you believe you will support the tokenizer so others can make custom IDE's ?
Ok, I know I'm ranting here, but I'm excited...
I.. I.. Ok, I'll park it...
THanks again for all the information, the code (espically the code) and the help!
...
One humbled kidd, Kaos Kidd that is
...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
·
·1+1=10
Yes, in color if you wish.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 3/3/2006 10:27:43 PM GMT
THanks guys, really.
...
I can't wait!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
·
Am I to understand that·a Spin function/procedure cannot have in-line assembly?
Does any assembly routine require its isolated COG to execute in?
I just reread the documents on the propeller product page, and apparently there no provision for in-line assembly.· For sume reason, I just assumed that there would be.
Should I assume that starting an assembly routine in a COG is transparent to the Spin programmer, for does the Spin programmer need to pay attention to the typical details of multi-processor/multi-task interactions?
Daniel
·
The Spin interpreter takes up the entire cog.· To have any assembly requires a different cog to run it in.· Also, unlike ASM, C or SX/B which are compiled, Spin is in an interpreted language using tokens (byte codes), so in-line assembly is not possible.
Now, if you have multiple jobs for assembly, data can be shared between a Spin cog and a pASM cog to trigger events or simply for data sharing.
Starting an assembly cog is just a matter of starting a new cog and declaring the assembly orgin to use (though I haven't gotten to playing with assembly programming yet on the Propeller).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Perform an Employer's Survey of Electronic Technologies Graduates· - Click here!
Personal Links with plenty of BASIC Stamp info
and SelmaWare Solutions - StampPlot - Graphical Data Acquisition and Control
I have just posted a "Propeller Overview" section that I believe answers your questions.
Cheers,
Peter (pjv)