Shop Learn
SPIN CODE EXAMPLES FOR THE BEGINNER (Public Version) - Page 8 — Parallax Forums




  • rjo_rjo_ Posts: 1,825
    edited 2007-04-21 13:05

    And the fact that there is a require waitcnt... seems to imply that this is coming from the spin code interpreter... and there is an error in the memory move routine.

  • rjo_rjo_ Posts: 1,825
    edited 2007-04-21 13:10

    AND if that is the case, then there would be a debate about what to do...

    I certainly wouldn't change the interpreter... I would just put an expansive series of examples in the tricks and traps sticky.

  • Beau SchwabeBeau Schwabe Posts: 6,480
    edited 2007-04-21 16:55
    rjo_ and all,
    Sorry for the confusion..... This is not an issue with the spin code interpreter, and there is not an error in the memory move routine.

    This is a result of a 2-dimentional way of previous thinking and getting used to the 3-dimentional approach the Propeller uses. Basically what I am saying is that this is my fault.

    Then what is going on with this code? ...and why does the waitcnt seem to work?

    Since the Propeller is a true multiprocessor, what happens is that when you launch a new cog to perform a function on a separate processor, the initial cog or processor continues and
    reads a value BEFORE the second cog has had a chance to write to it.

    The simple fix is to place a delay in the first cog, so that you give the second cog a chance to update the correct value.

    The correct or most efficient fix is to utilize a 'Flag' variable that is monitored by the first cog, but is updated by the second cog.

    I hope this makes some sense, and again I apologize for the confusion.

    [b]PUB[/b] AddNums(Num1,Num2):Flag
        Num1_ := Num1
        Num2_ := Num2
        [b]cognew[/b](@entry, @Num1)
        'return Flag
        [b]repeat[/b] [b]while[/b] Flag == 0
        [b]return[/b] Num1
                            [b]mov[/b]     t1,   [b]par[/b]       ' Move argument address into t1
                            [b]add[/b]     t1,   #8        ' Point to 3rd argument ( In this case 'Flag' )
                            [b]wrlong[/b]  Zero, t1        ' Clear 'Flag before we start'
                            [b]add[/b]     Num1_,Num2_     ' Add Num1 to Num2
                            [b]wrlong[/b]  Num1_, [b]par[/b]      ' Return result to Num1
                            [b]wrlong[/b]  One, t1         ' Set 'Flag when we are done'
                            [b]CogId[/b]   CogNum          ' Get COG ID
                            [b]CogStop[/b] CogNum          ' Stop this COG
    CogNum                  [b]long[/b]    0               ' Reserved variables
    Num1_                   [b]long[/b]    0
    Num2_                   [b]long[/b]    0
    Zero                    [b]long[/b]    0
    One                     [b]long[/b]    1
    t1                      [b]res[/b]     1

    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • rjo_rjo_ Posts: 1,825
    edited 2007-04-21 17:09

    You aren't guilty of anything... there is a whole bunch of info on the proper use of flags... and even Graham has put questions in on this exact question...
    I just hadn't figured it all out yet... and I honestly hadn't gotten far enough with my own thinking to see the connection.

    Nice try...from a nice guy... but this was all me... again!!![noparse]:)[/noparse]

    I'm going to try to create a bunch of examples from different points of view... just haven't gotten that far yet[noparse]:)[/noparse]

    AND... please feel free to be just a little more liberal with me... if I missed something... then don't you take the blame for it.

  • Beau SchwabeBeau Schwabe Posts: 6,480
    edited 2007-04-21 17:17

    We are all in the learning curve of this New Chip, and I am guilty for not having my head around the problem prior to releasing code in the first place.
    I take criticism very constructively, and if there is a problem it needs to be addressed so that others may benifit.

    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • mynet43mynet43 Posts: 644
    edited 2007-04-21 18:54
    Any chance this post can get back to the original topic?

    I was enjoying the code examples[noparse]:)[/noparse]
  • rjo_rjo_ Posts: 1,825
    edited 2007-04-21 20:25
    We're trying[noparse]:)[/noparse]
  • floodhoundfloodhound Posts: 45
    edited 2007-08-17 18:10
    Beau Schwabe Nice code. I am becoming more impressed with this processor.

    My web site -- > <-- take a look if you like
  • ChristophChristoph Posts: 13
    edited 2007-09-02 21:46
    Dave Scanlan said...

    ' EXAMPLE 20
    'IMPORTANT: This example may require an understanding of examples 6 & 9

    [noparse][[/noparse]STUFF DELETED!!]

    VideoDisplay: "TV_Terminal"
    PUB Start

    Mind You, me <- beginner [noparse]:)[/noparse]

    Your code doesn't compile for me like above (Error: Expected "(" with the cursor after "VideoDisplay.Start)

    By trial and error I found out that by changing code to VideoDisplay.Start(12) everything seems to work fine.
    I should add that I'm using a "Parallax Demo Board Rev.F".

    Can You explain?

  • Mike GreenMike Green Posts: 23,064
    edited 2007-09-02 23:36
    The TV Terminal driver requires a single parameter ... the lowest pin number of the block of 4 pins used for video output. This actually has to be a multiple of 4. I don't know why it wasn't mentioned in the original source. You may notice that pretty much everyone's posted example has this parameter supplied.
  • t2nt2nt2nt2n Posts: 21
    edited 2007-09-18 10:11
    I am looking about your example code.

    So, in the example 01 : i don't understand how / where is defined the function waitcnt and the variable cnt.

    If they are implemented system items, why don't you say ? I didn't read the manual, of course, so why I read this topic....

    What is the ratio light / shadow of each blink, for instance : I suppose that it's 1 : 1, but how long is each phase of the process ? 12.5ns ? Is it sufficient to see 5 flashs ?
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-09-18 10:27
    If you load the example into the propeller IDE tool, you will notice that reserved words are in bold letters. And that waitcnt and cnt are reserved.

    If you open the manual's pdf and search on these words you will quickly get up to speed on what they do and mean.

    In this particular example, the waitcnt pause is 1/2 second.

    If you read the more comments version of this file, you will see:

    ' -- The LED, at port A16, is on for 1/2 second and off for 1/2 second.
    ' -- The System Counter increments by one for every System Clock pulse. Thus, if the
    ' System Clock is running at 80MHz, the System Counter will increment 80 million times
    ' in one second; and every counter increment will take 12.5ns (1/80MHz).
    ' Each WaitCnt statement below is set to cause a 1/2 second wait:
    ' 40_000_000 counter increments * 12.5ns = 500ms (1/2 second)
  • t2nt2nt2nt2n Posts: 21
    edited 2007-09-18 11:21
    Tx for your reply.
    But before buying one propeller, and all accessories needed to run it, you surely understand that somebody is looking around what can be done, and what not. Particularly if a chip, the propeller in this case, is not so much hearded about in the country where this person is living, and particularly if the person don't know the spin language (but knows the C one) ...

    Of course you understand this, as this is explicitly said in the first pinned post of the examples.

    So I have not the propeller IDE tool, and I can't notice anything in bold letters.

    Furthermore, i don't read

    Somebody said...
    40_000_000 counter increments * 12.5ns = 500ms (1/2 second)

    in the example code, but
    Somebody said...
    40_000_000 + Cnt

    Now I understand a little more about the period of blink, but i don't understand what is the variable cnt, and why the sum to the 1/2 period blinking.

    If you say me where I can find the mythical manual's pdf (none pinned reference to this book), i surely will be able to search more about the cnt variable.

    Tx for your infos.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-09-18 12:41
    Click on the Paralax logo at the top of the page. Then find a link to the propeller pages. Look for "downloads" link. Download the one with the IDE tool and manual combined.
    Install the program.

    Or just click this and save:
  • t2nt2nt2nt2n Posts: 21
    edited 2007-09-18 13:19
    Tx a lot for your link.
    I will take a look at this document. The propeller seems really an excellent product.
    I am wondering why there is not more of infos about it in the robotic forums, and so on....
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-09-18 14:01
    It's new and still cutting teeth.
  • t2nt2nt2nt2n Posts: 21
    edited 2007-09-18 14:32
    OK, now the Cnt variable is more clear for me.

    But before go forward, with the example 04, I need to understand one point : why this mysterious 20, to size the stack, in the example 03 ?

    Why not 19 or 21 ?

    Sorry, but the manual talks for a long time with a stack sized with 9.

    And as examples are here to explain a bit, why 20 ?

    When a routine ends, is the stack free ?

    Or can we just do 20 calling of each routine ?

    Sorry for my dumbass questions, but the video monitor seems unextricable if I don't understand the example 03.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-09-18 15:11
    read the third ed kit lab, Methods and Cogs. It walks you through calculating stacks.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-04-02 14:36
    Martin, in a previous post a few pages back you mentioned having heard from Dave at that time. It appears he hasn't been on the forums in almost a year. I hope everything is okay with him.

    Chris Savage
    Parallax Tech Support
  • StefanL38StefanL38 Posts: 2,290
    edited 2008-10-06 01:32
    Hello Beginners,

    to have a feedback of your program for debugging you could use the FullDuplexSerial-object

    download the Propeller serial Terminal-Software "PST.EXE" here

    And here's is a little democode to show how FullDuplexSerial works on the serial connection
    you are using to program the chip (PINs30,31)

    'ATTENTION! You HAVE TO download the code to the EEPROM ! (Key F11)
    'opening the comport with PST.EXE causes a reset of the propeller
    'after reset, the propeller does its bootprocess that includes loading the content of the EEPROM
    'to the RAM. So last content of the RAM will you overwritten by the last content of the EEPROM
      _clkmode = xtal1 + pll16x 
      _xinfreq = 5_000_000
      debug  : "FullDuplexSerial"
       long X
    PUB main 
      debug.start(31, 30, 0, 9600)
      X := 0
        debug.str(string(" Hello World"))
        waitcnt(ClkFreq + cnt)


    This kind of debugging is SO EASY
    as it needs NOTHING MORE than any kind of PropBoard
    This democode should be delivered inside the manual AND as SPIN-File
    in the Library-demo-folder

    best regards


    Post Edited (StefanL38) : 10/6/2008 1:39:16 AM GMT
Sign In or Register to comment.