SPIN CODE EXAMPLES FOR THE BEGINNER (Public Version)

124678

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-16 - 03:23:04
    Excellent!· I hope everyone walked away with some understanding of what they can accomplish in Robotics with the Propeller.· Looking forward to seeing what you come up with.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    [url=mailto:csavage@parallax.com]csavage@parallax.com[/url]
    Chris Savage | Engineering Tech | Main Office: (916) 624-8333 | Direct to Tech Support: (888) 997-8267 | Website | Twitter | Google+
  • Dave ScanlanDave Scanlan Posts: 160
    edited 2006-04-17 - 05:02:51
    attachment.php?attachmentid=41281

    EXAMPLE 12
    PROXIMITY DETECTION USING THE SHARP GP2D12·
    '                                           EXAMPLE 12
    '
    '                          PROXIMITY DETECTION USING THE SHARP GP2D12                         
    '*************************************************************************************************
    'IMPORTANT: This example may require an understanding of Example 01
    '*************************************************************************************************
    'WHAT'S NEW IN THIS EXAMPLE:
    '
    '  CONCEPT NAME: Proximity Detection
    '                - This program uses the Sharp GP2D12 which will detect objects at a range
    '                  of 10 to 80 cm. The device uses IR for object detection.
    '                  -  This device is often used in robotics to sense the presence of objects.
    '                  -  This device is inexpensive, but it is non-linear.  See resource below.
    '                  -  Resource: [url=http://www.acroname.com/robotics/info/articles/sharp/sharp.html#s1]www.acroname.com/robotics/info/articles/sharp/sharp.html#s1[/url]
    '                  -  Refer to the schematic above for the physical interface of the
    '                     Sharp GP2D12 to the Propeller.
    '*************************************************************************************************
    'DIFFICULTY LEVEL:  Very Easy
    '
    'PURPOSE:  The purpose of this program is to show how to connect a proximity detector to
    '          Propeller and how to write the code for the interface.  
    '     
    'Submitted by Dave Scanlan, April 17, 2006         
    'File: Example12_IR.spin
    '*************************************************************************************************
    'CORRECT OUTPUT:  When an object is detected, the LED at A16 will turn on, and it will stay on
    '                 until the object is no longer detected.
    '*************************************************************************************************
    CON
      _clkmode      = xtal1 + pll16x
      _xinfreq      = 5_000_000
    '
      High = 1                         
      Low  = 0                         
      Out = %1
      In = %0
    ' 
    VAR
      Byte Pin
    '
    PUB Start
      ProximitySensor
    '
    PRI ProximitySensor
      Pin := 16                           'LED's location is A16.
      DirA[noparse][[/noparse]Pin] := Out
      Pin := 1                            'The input from LM339 (voltage comparitor). 
      DirA[noparse][[/noparse]Pin] := In  
    '
      Repeat                              'Infinite loop
        If InA[noparse][[/noparse]1] == High
          OutA[noparse][[/noparse]16] := High
        else
          OutA[noparse][[/noparse]16] := Low
          
    '*************************************************************************************************
    'ADDITIONAL INFORMATION:
    '  -- Set the variable resistor about midway and it will detect an object at
    '     a distance of about 14 cm. Experiment with other settings to get the
    '     detection distance you want.
    '  -- The Sharp GP2D120 will allow for detection closer to the sensor.  The
    '     range is 4 to 30 cm. This program and hookup will work fine for this sensor, also.  
    

    '                                   FEWER COMMENTS (EASIER TO READ)
    '                                              EXAMPLE 12
    '
    '                          PROXIMITY DETECTION USING THE SHARP GD2D12 OR GD2D120              
    '*************************************************************************************************
    'IMPORTANT: This example may require an understanding of Example 01
    '*************************************************************************************************
    'DIFFICULTY LEVEL:  Very Easy
    '*************************************************************************************************
    'CORRECT OUTPUT:  When an object is detected, the LED at A16 will turn on, and it will stay on
    '                 until the object is no longer detected.
    'Submitted by Dave Scanlan, April 17, 2006         
    'File: Example12_FewerComments.spin
    '*************************************************************************************************
    CON
      _clkmode      = xtal1 + pll16x
      _xinfreq      = 5_000_000
    '
      High = 1                         
      Low  = 0                         
      Out = %1
      In = %0
    ' 
    VAR
      Byte Pin
    '
    PUB Start
      ProximitySensor
    '
    PRI ProximitySensor
      Pin := 16                           'LED's location
      DirA[noparse][[/noparse]Pin] := Out
      Pin := 1                            'The input from LM339                       
      DirA[noparse][[/noparse]Pin] := In  
    '
      Repeat                              
        If InA[noparse][[/noparse]1] == High
          OutA[noparse][[/noparse]16] := High
        else
          OutA[noparse][[/noparse]16] := Low
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··

    Post Edited (Dave Scanlan) : 4/18/2006 5:19:20 AM GMT
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-04-17 - 14:33:35
    Nice Dave.
    And, Like you said: Simple...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Just tossing my two bits worth into the bit bucket


    KK
    ·
  • Dave ScanlanDave Scanlan Posts: 160
    edited 2006-04-17 - 18:59:23
    Kaos Kidd said...
    Nice Dave.
    And, Like you said: Simple...

    Hi Kaos kidd,

    The next example will show how to interface a Parallax 4x20 LCD·(with backlight) to the Propeller.

    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-17 - 19:43:39
    I've been using our LCD (as well as the SEETRON BPI-216) as an output device for a couple weeks now -- perhaps I can save you some time.
    '' Debug_Lcd Test (4x20 LCD)
    '' -- Jon Williams, Parallax
    '' -- 28 MAR 2006
    ''
    ''
    '' Uses the Parallax 4x20 serial LCD to display a counter in decimal, hex, and
    '' binary formats.
    
    CON
    
    
      _clkmode = xtal1 + pll16x                             ' use crystal x 16
      _xinfreq = 5_000_000
    
    
      LCD_PIN   = 0                                         ' for Parallax 4x20 serial LCD on A0
      LCD_BAUD  = 19_200
      LCD_LINES = 4    
     
    
    OBJ
    
     
      lcd : "debug_lcd"
     
    
    PUB main | idx
     
      if lcd.start(LCD_PIN, LCD_BAUD, LCD_LINES)            ' start lcd
        lcd.cursor(0)                                       ' cursor off
        lcd.backLight(true)                                 ' backlight on (if available)
        lcd.custom(0, @Bullet)                              ' create custom character 0
        lcd.cls                                             ' clear the lcd
        lcd.str(string("LCD DEBUG", 13))
        lcd.putc(0)                                         ' display custom bullet character
        lcd.str(string(" Dec", 13))
        lcd.putc(0)
        lcd.str(string(" Hex", 13)) 
        lcd.putc(0)
        lcd.str(string(" Bin"))  
       
        repeat
          repeat idx from 0 to 255                          ' count up
            updateLcd(idx)
            waitcnt(clkfreq / 10 + cnt)                     ' pad with 1/10 sec
     
          repeat idx from -255 to 0                         ' count down
            updatelcd(idx)
            waitcnt(clkfreq / 10 + cnt)
     
            
    PRI updateLcd(value)
     
      lcd.gotoxy(12, 1)
      lcd.decf(value, 8)                                    ' print right-justified decimal value
      lcd.gotoxy(11, 2)
      lcd.ihex(value, 8)                                    ' print indicated (with $) hex
      lcd.gotoxy(7, 3)
      lcd.ibin(value, 12)                                   ' print indicated (with %) binary                
                    
          
    DAT
     
      Bullet      byte      $00, $04, $0E, $1F, $0E, $04, $00, $00
     
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-04-17 - 20:28:42
    Ya know... with all these nifty little objects you all are creating, now I'm gonna have to go out and git me some of these goodies you guys are playing with! [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Just tossing my two bits worth into the bit bucket


    KK
    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-18 - 00:15:32
    I recently obtained Jon's LCD object and find it quite useful when I don't have the LCD TV handy.

    Dave, I find your most recent example interesting considering the project I brought to the Robotics Group.· =)


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    [url=mailto:csavage@parallax.com]csavage@parallax.com[/url]
    Chris Savage | Engineering Tech | Main Office: (916) 624-8333 | Direct to Tech Support: (888) 997-8267 | Website | Twitter | Google+
  • Dave ScanlanDave Scanlan Posts: 160
    edited 2006-04-18 - 00:37:55
    Hi Chris,

    I have two of the GP2D12's on one of my robots.· If I had it to do over again, I would have used the GP2D120.· It has the range I most often use.

    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-04-18 - 06:04:13
    Dave -

    You have obviously been able to select the most appropriate Sharp I/R Ranger for your needs. For others who may be in that quandry and don't have a simple resource for determining which is the best Sharp I/R Ranger for their needs, I attach a Sharp I/R Ranger Sensor Guide, courtesy of the folks at Accroname.

    Regards,

    Bruce Bates


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Dave ScanlanDave Scanlan Posts: 160
    edited 2006-04-18 - 13:30:00
    Bruce Bates said...

    Dave -

    You have obviously been able to select the most appropriate Sharp I/R Ranger for your needs. For others who may be in that quandry and don't have a simple resource for determining which is the best Sharp I/R Ranger for their needs, I attach a Sharp I/R Ranger Sensor Guide, courtesy of the folks at Accroname.

    Regards,

    Bruce Bates


    Hi Bruce,
    The comparison chart is very useful.· If you follow the reference I included in my example, you will find a URL to this chart at·the very end, in·the Conclusion.
    Thanks for drawing folks attention to it.· As you may have noticed, I try to keep my examples narrowly focused to a single concept.· I make every effort to keep these examples at a "hello world" level.· Thus, I avoid adding a lot of bell-and-whistles.
    I was wondering if you would do a post with an actual picture of the chart and with three or more references?
    Please keep adding more great ideas to this thread.
    Dave



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··

    Post Edited (Dave Scanlan) : 4/18/2006 1:34:42 PM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-04-18 - 14:11:19
    Dave -

    If I knew how to do that, or had the tools to break down a PDF, I'd be happy to do so, but unfortunately I do not. I have few graphics or DTP tools at all.

    If feel fortunate that I've even figured out how to reply on this web based system. A web programming "manic" I am not, sorry.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Dave ScanlanDave Scanlan Posts: 160
    edited 2006-04-18 - 14:30:20
    Bruce Bates said...
    Dave -

    If I knew how to do that, or had the tools to break down a PDF, I'd be happy to do so, but unfortunately I do not. I have few graphics or DTP tools at all.

    If feel fortunate that I've even figured out how to reply on this web based system. A web programming "manic" I am not, sorry.

    Regards,

    Bruce Bates

    Hi Bruce,

    I understand·from where you are coming.· It took a lot of trial-and-error for me to post·a picture of the schematic of the Sharp IR sensor circuit. When I get a chance I will add this chart to my example.

    The only reason I used the Sharp GP2D12 was because it came with a robot I built about two years ago.· This was the only sensor of its type I·had on which to test the circuit.

    Bests,

    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-04-18 - 14:57:23
    Dave -

    At the possible risk of seeming to go off topic slightly, I wish Adobe or someone would publish just some simple tools, not unlike what Microsoft has done, to do minimal manipulation of their PDF files. The universality of the format is well respected in most quarters, but once they're "locked in", you need deeper pockets than I have, to get the information back out, unless you're just looking to extract some simple text, or a single graphic or two which is not "protected" <sigh>.

    Just to bring this back on topic, nothing would please me more, than if I had access to just such a program so that I could take all of these marvelous Propeller examples (THANKS Dave and others!), Propeller tips, tricks, and hints, and the Parallax prepared Propeller documentation, etc. and build my own personal Propeller Notebook. The REALLY nice thing about something like that is you could make personal notations therein, as to who the "experts" are in all the various application-specific areas which have been mentioned on this Propeller Forum, for possible future reference, without having to re-scan all the messages to find those gurus!

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Dave ScanlanDave Scanlan Posts: 160
    edited 2006-04-18 - 15:43:53
    Bruce Bates said...
    Dave -

    At the possible risk of seeming to go off topic slightly, I wish Adobe or someone would publish just some simple tools, not unlike what Microsoft has done, to do minimal manipulation of their PDF files. The universality of the format is well respected in most quarters, but once they're "locked in", you need deeper pockets than I have, to get the information back out, unless you're just looking to extract some simple text, or a single graphic or two which is not "protected" <sigh>.

    Just to bring this back on topic, nothing would please me more, than if I had access to just such a program so that I could take all of these marvelous Propeller examples (THANKS Dave and others!), Propeller tips, tricks, and hints, and the Parallax prepared Propeller documentation, etc. and build my own personal Propeller Notebook. The REALLY nice thing about something like that is you could make personal notations therein, as to who the "experts" are in all the various application-specific areas which have been mentioned on this Propeller Forum, for possible future reference, without having to re-scan all the messages to find those gurus!

    Regards,

    Bruce Bates

    Bruce,
    Great suggestion.··I have a feeling that once you folks get access to the documentation and the Propeller chip, there will be a multitude of experts...including yourself.
    I appreciate yours and others' nice comments about the examples we all post to this thread.
    Bests,
    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··

    Post Edited (Dave Scanlan) : 4/18/2006 4:03:41 PM GMT
  • Don DDon D Posts: 27
    edited 2006-04-19 - 17:45:25
    Request to Parallax/Spin Authors:

    Would it be possible to include a memory usage report with listings? I'm really excited about the TV and other objects/examples submitted, but what is their cost in Propeller resources??

    If not already there, a running counter in the editor while coding would be a good thing.
  • Dave ScanlanDave Scanlan Posts: 160
    edited 2006-04-19 - 18:35:45
    Don D said...
    Request to Parallax/Spin Authors:

    Would it be possible to include a memory usage report with listings? I'm really excited about the TV and other objects/examples submitted, but what is their cost in Propeller resources??

    If not already there, a running counter in the editor while coding would be a good thing.
    Hi Don,
    The first request is not a problem.· I will remember to include it in my next example.
    The second request is a·good idea, but the editor supplies all this information. All you need to do is press F8 to get the window.· I know...you said, "running counter."· Parallax, what do you think about this request?
    Dave


    Post Edited (Dave Scanlan) : 4/19/2006 6:47:08 PM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-19 - 20:50:17
    I believe a "running" counter would require the IDE to recompile everything with each new line and would just get in the way of IDE performance.· As Dave points out, one simply needs to press [noparse][[/noparse]F8] to get a current memeory usage report.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • arnoarno Posts: 43
    edited 2006-04-20 - 08:59:19
    Hello All,
    Very interesting stuff.

    But two quick question comme to my mind, how can you declar multiple local variable ?
    in all example you have just: | Pin added to the function

    If I need two ore more value does I have to do | Pin | Value1 etc

    Also you said WaitPeriod_Par are the argument in sample 5, but what type is it (word, long) ? does that matter ?
    Or it's an 'heritage' of the type you have when you call the function ? (so no more wrong type like in C or C++)
  • arnoarno Posts: 43
    edited 2006-04-20 - 09:34:18
    Okay I find the answer to my first question on sample 10, sorry I miss some page.
  • Dave ScanlanDave Scanlan Posts: 160
    edited 2006-04-20 - 13:53:01
    arno said...
    Hello All,
    Very interesting stuff.

    But two quick question comme to my mind, how can you declar multiple local variable ?
    in all example you have just: | Pin added to the function

    If I need two ore more value does I have to do | Pin | Value1 etc

    Also you said WaitPeriod_Par are the argument in sample 5, but what type is it (word, long) ? does that matter ?
    Or it's an 'heritage' of the type you have when you call the function ? (so no more wrong type like in C or C++)
    Hi Arno,

    A series of local variables are declared like this: | Var1, Var2, Var3...
    Both parameters and local variables are of the data type: long, which is 32 bits.
    The default is long for these two items and you do not have the option to change this in Spin.

    Also, WaitPeriod_Par is a parameter and WaitPeriod_Arg is an argument.·

    Dave






    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··

    Post Edited (Dave Scanlan) : 4/20/2006 2:00:28 PM GMT
  • Dave ScanlanDave Scanlan Posts: 160
    edited 2006-04-22 - 09:54:43
    attachment.php?attachmentid=41366
    ·(Serial LCD used in this example)
    EXAMPLE 13
    USING AN LCD TO DISPLAY COG NUMBER, CLOCK FREQUENCY, AND CTN VALUES
    
    '                                      EXAMPLE 13
    '
    '      USING AN LCD TO DISPLAY COG NUMBER, CLOCK FREQUENCY, AND CTN VALUE                     
    '**********************************************************************************
    'IMPORTANT: This example will require an understanding of example 01
    '********************************************************************************** 
    'WHAT'S NEW IN THIS EXAMPLE:
    '   GOGID:   Returns the current COG's ID (0-7)
    '   CLKFREQ: Returns the current system's clock frequency
    '   CNT:     Returns the current 32-bit System Counter Register value.  CNT is the
    '            system counter that is incremented once every clock cycle.  In this
    '            example, it is incremented 80 million times each second, and updated
    '            on the LCD display every second.
    '   LCD:     This example was tested on Parallax's serial 4x20
    '            (4 lines by 20 characters) display with a backlight. (Stock#: 27979)
    '********************************************************************************** 
    'DIFFICULTY LEVEL: VERY EASY    
    '********************************************************************************** 
    'PURPOSE:
    '  -- The purpose of this example is to display "some" of the system values on a
    '     4x20 LCD module. These values are: GOGID, CLKFREQ, and CNT.
    '
    'Submitted by Dave Scanlan, April 22, 2006         
    'File: Example13_DisplaySystemValues
    '********************************************************************************** 
    'CORRECT OUTPUT: The LCD will display a title, the current cog's ID, the clock
    '                frequency, and the CNT(System Counter Register value).
    '                Note: The CNT value changes 80 million times each second. Its
    '                      current value will be updated on the LCD panel after a
    '                      one-second delay. See the LCD format below:
    '
    '                                      4x20 LCD Module
    '                               &#9474;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#9474;
    '                               &#9474;      SYSTEM VALUES       &#9474;
    '                               &#9474;  GOG ID:X                &#9474;
    '                               &#9474;  CLK FREQ:XXXXXXXX       &#9474;
    '                               &#9474;  COUNTER:XXXXXXXXXXX     &#9474;
    '                               &#9474;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#9474;
    '
    '********************************************************************************** 
    CON
      _clkmode      = xtal1 + pll16x
      _xinfreq      = 5_000_000
    '
      LCD_Pin   = 0                           'The LCD is connected to pin A0.
      LCD_Baud  = 19_200                      'Baud
      LCD_Lines = 4                           'The number of lines on this LCD
    ' 
      Off  = 0
      On   = 1
    '
    OBJ
      LCD: "debug_lcd"                        'Creates the object LCD from "debug_lcd"
    '
    VAR
    'No Global Variables                    
    '
    PUB Start
      DisplaySystemValues
    '
    PRI DisplaySystemValues
    ' 
      If LCD.Start(LCD_Pin, LCD_Baud, LCD_Lines)'Initialize the LCD object
        LCD.Cursor(Off)                         'Set cursor off
        LCD.Backlight(On)                       'Set backlight on
        LCD.Cls                                 'Clear the LCD screen
    '   
        LCD.Str(string("   SYSTEM VALUES"))     'Print string on LCD
        LCD.NewLine                             'Start on the next line
        LCD.Str(string("COG ID:"))              'Print string on LCD 
        LCD.Gotoxy(7, 1)                        'Send cursor to col 7 line 1
        LCD.DecF(COGID, 1)                      'Print GOGID as a signed decimal
        LCD.NewLine    
        LCD.Str(string("CLK FREQ:"))         
        LCD.Gotoxy(9, 2)
        LCD.DecF(CLKFREQ, 8)                    'Print CLKFREQ as a signed decimal
        LCD.NewLine
        LCD.Str(String("COUNTER:"))
    '   
        Repeat                                  'Infinite loop
          LCD.Gotoxy(8, 3)
          LCD.DecF(CNT, 11)                      'Print current value of CNT
          WaitCNT(80_000_000 + CNT)             'Wait one second
    '**********************************************************************************
    'ADDITIONAL INFORMATION:
    'See Jon William's example (Debug_Lcd Test (4x20 LCD))on this thread for more serial
    'LCD options.
    'Price of this LCD: $39.95
    'On an LCD panel, the top line is line 0 and beginning column is column 0.
    '  
    'FORMAT FOR DecF    
    ' DecF(Value, Width) 
    '  Prints signed decimal value in fixed-width field
    'MEMORY USAGE:
    '   Program: 308 Longs
    '   Variables: 19 Longs
    '   Stack/Free: 7,861 Longs
    



    FEWER COMMENTS (EASIER TO READ)

    '
    '                           FEWER COMMENTS (EASIER TO READ)
    '
    '                                      EXAMPLE 13
    '
    '      USING AN LCD TO DISPLAY COG NUMBER, CLOCK FREQUENCY, AND CTN VALUE                     
    '**********************************************************************************
    'IMPORTANT: This example will require an understanding of example 01
    '********************************************************************************** 
    'DIFFICULTY LEVEL: VERY EASY    
    '********************************************************************************** 
    'CORRECT OUTPUT: The LCD will display a title, the current cog's ID, the clock
    '                frequency, and the CNT(System Counter Register value).
    '                Note: The CNT value changes 80 million times each second. Its
    '                      current value will be updated on the LCD panel after a
    '                      one-second delay. See the LCD format below:
    '
    '                                      4x20 LCD Module
    '                               &#9474;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#9474;
    '                               &#9474;      SYSTEM VALUES       &#9474;
    '                               &#9474;  GOG ID:X                &#9474;
    '                               &#9474;  CLK FREQ:XXXXXXXX       &#9474;
    '                               &#9474;  COUNTER:XXXXXXXXXXX     &#9474;
    '                               &#9474;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#9474;
    '
    'Submitted by Dave Scanlan, April 22, 2006         
    'File: Example13_DisplaySystemValues
    '********************************************************************************** 
    CON
      _clkmode      = xtal1 + pll16x
      _xinfreq      = 5_000_000
    '
      LCD_Pin   = 0                           'The LCD is connected to pin A0.
      LCD_Baud  = 19_200                      'Baud
      LCD_Lines = 4                           'The number of lines on this LCD
    ' 
      Off  = 0
      On   = 1
    '
    OBJ
      LCD: "debug_lcd"                        
    '
    VAR
    'No Global Variables                    
    '
    PUB Start
      DisplaySystemValues
    '
    PRI DisplaySystemValues
    ' 
      If LCD.Start(LCD_Pin, LCD_Baud, LCD_Lines)
        LCD.Cursor(Off)                         
        LCD.Backlight(On)                       
        LCD.Cls                                 
    '   
        LCD.Str(string("   SYSTEM VALUES"))     
        LCD.NewLine                             
        LCD.Str(string("COG ID:"))              
        LCD.Gotoxy(7, 1)                        
        LCD.DecF(COGID, 1)                      
        LCD.NewLine    
        LCD.Str(string("CLK FREQ:"))         
        LCD.Gotoxy(9, 2)
        LCD.DecF(CLKFREQ, 8)                    
        LCD.NewLine
        LCD.Str(String("COUNTER:"))
    '   
        Repeat                                  
          LCD.Gotoxy(8, 3)
          LCD.DecF(CNT, 11)                      
          WaitCNT(80_000_000 + CNT)             
    
    

    Post Edited (Dave Scanlan) : 4/23/2006 3:27:42 PM GMT
  • Dave ScanlanDave Scanlan Posts: 160
    edited 2006-04-23 - 15:38:59
    Don D said...
    Request to Parallax/Spin Authors:

    Would it be possible to include a memory usage report with listings? I'm really excited about the TV and other objects/examples submitted, but what is their cost in Propeller resources??

    If not already there, a running counter in the editor while coding would be a good thing.
    Hi Don,

    The memory usage report has been included in Example 13.· Good suggestion.

    Dave


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··
  • Don DDon D Posts: 27
    edited 2006-04-24 - 13:31:48
    Thanks, maybe good suggestion if not too cumbersome.

    Memory usage is handy to see when we don't have access to props or tools. Thanks for complying.

    Jon, could [noparse][[/noparse]F8] and/or print,save, select all, etc functions update comment lines without intervention?
  • David BDavid B Posts: 570
    edited 2006-04-25 - 00:17:10
    Is this thread intended to be for examples of SPIN only? Could some Propeller assembly language examples also be posted?
  • El PaisaEl Paisa Posts: 375
    edited 2006-04-25 - 01:26:03
    Question:
    The program BPI-216.spin could be modified to select between 9600 and 115200 baud?
  • Dave ScanlanDave Scanlan Posts: 160
    edited 2006-04-25 - 03:21:38
    David B said...
    Is this thread intended to be for examples of SPIN only? Could some Propeller assembly language examples also be posted?
    Hi David,
    Yes, there is a need for assembly language tutorials, but this thread is for Spin code only.· It is specifically for beginners.
    I have suggested that a separate thread for assembly language be started, but so far, no takers.· I have also suggested that a thread for Spin code for intermediate-level programmers be started.· Again, no takers.· Give it time, these·thread-topics are likely to evolve.
    Dave
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-25 - 03:27:32
    The BPI-216 supports two baud rates: 2400 and 9600, hence the code is designed to allow just those two selections -- this is to preven programming errors.· If you do find an LCD that can run up to 115.2k you'll need to use an assembly driver; at 19.2k and below you can use Spin and save a cog.
    El Paisa said...
    Question:
    The program BPI-216.spin could be modified to select between 9600 and 115200 baud?
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • El PaisaEl Paisa Posts: 375
    edited 2006-04-25 - 15:17:55
    Thanks Jon:

    Could you give an example ?

    Thanks.
  • parskoparsko Posts: 501
    edited 2006-04-25 - 15:35:20
    Jon,

    "at 19.2k and below you can use Spin and save a cog"

    Does this mean that the fastest baud rate with one COG is 19.2k?

    Higher baud rates require two cogs?

    -Parsko
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-25 - 15:49:26
    High baud rates require the serial tx/rx routines to be coded in assembly, and that means launching them into their own cog.· If you're using 19.2k or lower you can link the tx/rx code (not buffered) into you Spin code.· I've attached am object called simple_serial.spin that handles tx/rx in Spin.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.