Shop OBEX P1 Docs P2 Docs Learn Events
Do I have the right idea in the way I am commenting on the code commands.more to come — Parallax Forums

Do I have the right idea in the way I am commenting on the code commands.more to come

sam_sam_samsam_sam_sam Posts: 2,286
edited 2011-02-13 17:42 in Propeller 1
''A .pdf copy of the book is available from www.parallax.com, and also through
''the Propeller Tool software's Help menu (v1.2.6 or newer).
''
''File: LedsOnOff50PercentAgain.spin
''Leds alternate on/off 50% of
''the time with the ! operator.

PUB BlinkLeds


    dira[4..9]~~   '                  (~~)              Post Set / sign-extend from bit 15    
                   '
                   
    outa[4..9] := %100001 '           ( %100001 )       1 = set or ON and 0 = clear or OFF
                          '
                          '           ( [ ..] )         equal to the value of the symbol or
                          '                             expression to the right of
                          '                             the of the operator         

    repeat
    
        !outa[4..9]              '  ( !outa[4..9] )       invert pin direction state bits [x..y]
                                    '                   ........ this is what mean  " ! "    by solo  
        waitcnt(clkfreq/4 + cnt) '                      wait 1/4 of a second

Comments

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2011-02-13 11:35
    codecomments.PNG


    Looks good from here..

    OBC
    827 x 390 - 16K
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-02-13 11:37
    Thanks........
  • potatoheadpotatohead Posts: 10,261
    edited 2011-02-13 11:40
    If I read, "this is solo", I think I would be confused.

    Personally, I would say "invert pin direction state bits [x..y]", just because it speaks to exactly what is happening.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-02-13 13:06
    Oldbitcollector

    Is this any better I changed above
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2011-02-13 13:09
    Good adjustment!

    OBC
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-02-13 13:12
    Thanks

    Just to let you by me doing this I am being to understand this a little more and I am VERY sure that will many more question like this as I go a long
  • potatoheadpotatohead Posts: 10,261
    edited 2011-02-13 13:15
    One thing I have found helpful in code commenting is to write it to somebody you know. Sounds silly, but it helps me a lot. If it's video, I think of Kye, or Eric or Baggers when I write comments, for example, mostly because I've come to understand theirs. That gets some good comments rolling, and then questions from others flesh it out.

    If I do calculations, often I'll stuff those in there just as notes. They help me later when I go to change something that isn't programmed to happen automatically, like "magic numbers" in that I can see what the heck I did!

    And I'm not the best commenter, but getting better.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-02-13 13:56
    My problem is that I do not know any one where I live that programing Propeller Chip The only Place that I can do this on this forum


    When I first start writing P-basic code when I went through

    What is a Micro Controller

    I did not have to comment very much of it because I understood most of the basic code command there still some commands I do not understand how to write them or understand how they work but that very few

    But now going through

    Propeller Education Kit Lab


    With Spin this a hole another story

    To me the command are very different
    Some of the basic command are hard for me to understand
    The reason why something it is written the way it is .
  • jazzedjazzed Posts: 11,803
    edited 2011-02-13 14:07
    Just one thing to consider. You have one big multi-line comment that is indented way over on the side of the page; many people put such comments above the line or section of code the comment is describing.

    Some people decorate such blocks with special character sequences to make them stand out. Such special decorations to make it easy to spot where key things like methods and routines start in the code. Be creative if you like, but don't over do it.

    Just my .02
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-02-13 14:11
    Thanks I keep that in mind

    These for now are just outline for me to learn from but at some point I do want to clean them up so that other people can use them


    I have one thing to ask is there any one out there that would be willing to help clean these comment up as I go along
    Because I can see that this seem to be the best way for me to learn these command and how to use them

    and

    I wonder how many other people on this forum feel the same way comment are welcome
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-02-13 14:28
    Is this any better

    Please keep in mind that I want to have the comment so that a beginner can understand them
    I want beginner and experts to Please leave there comments thanks

    ''This code example is from Propeller Education Kit Labs: Fundamentals, v1.2.
    ''A .pdf copy of the book is available from [url]www.parallax.com[/url], and also through
    ''the Propeller Tool software's Help menu (v1.2.6 or newer).
    ''
    ''File: LedsOnOff.spin
    ''All LEDS on for 1/4 s and off ''for 3/4 s.
    
    
    
    PUB BlinkLeds
    
        ''  PUB  = Public Method Block meaning that code routine are accessible inside and outside of the object
        ''
        ''  BlinkLed = name of routine 
        ''
        ''  dira = Direction Register for I/O pins meaning that it is an output or input 
        ''
        ''
        ''       ( [ ..] )        equal to the value of the symbol or expression to the right of
        ''                        the of the operator
        ''
        ''        ( := )          It sets the symbol to the left of the operator equal to the value 
        ''                        of the symbol or expression to the right of the operator 
        '' 
        ''       (:= %111111)     will set bit to outputs pins 4 to 9  1 = output / 0 = input
        ''
        ''  outa  = Output State Register  meaning that the output pin is set or clears /   1 = high / 0 =  low or ON /OFF
        ''
        ''        (:= %101010)     set P4,clears P5, set P6,clears P7
        ''                         and so on to pin 9
        ''
        '' 
        ''
        '' cnt -                   a register that counts system clock ticks
        ''
        '' clkfreq -               a command that returns system clock frequency in Hz clock or  
        ''                         a value that stores system clock ticks in one second
        ''
        '' waitcnt -               a command that waits for the the cnt register to get
        ''                         to a certain value
    
        dira[4..9] := %111111  
        
        
        repeat
    
            outa[4..9] := %111111       '(:= %111111)  will set bit to outputs pins 4 to 9 
            waitcnt(clkfreq/4 + cnt)    '( clkfreq/4)  wait 1/4 of a second
            outa[4..9] := %000000       '(:= %101010)  set P4,clears P5, set P6,clears P7 and so on to pin 9                                                  
            waitcnt(clkfreq/4*3 + cnt)  '(clkfreq/4*3) wait 3/4ths of a second
    
  • potatoheadpotatohead Posts: 10,261
    edited 2011-02-13 15:04
    Another option you've got is the bracket comments. These are really cool, because you can define a block to be a comment. Good for tables and such.

    I like to use big special character comments like this too:

    '
    ' Setup the counters
    '

    mov A, B 'prepare to calculate frequency
    add A, C 'add delta to base value
    shl A, #2 'Multiply by 4

    ...etc.

    Lots of ways to do it. It is good to work on how you do it, whatever that is, and just keep working to make it more consistent. That helps a lot because other people can pick up on the different formats and learn what programmers were trying to say.

    And yes! You have exactly the right idea, BTW.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-02-13 15:20
    I will post them as I do them if any thing need to be changed Please let me know Thank for the feed back
    ''This code example is from Propeller Education Kit Labs: Fundamentals, v1.2.
    ''A .pdf copy of the book is available from www.parallax.com, and also through
    ''the Propeller Tool software's Help menu (v1.2.6 or newer).
    ''
    ''File: LedsOnOff50PercentAgain.spin
    ''Leds alternate on/off 50% of
    ''the time with the ! operator.
    
    PUB BlinkLeds
    
        ''  PUB  = Public Method Block meaning that code routine are accessible inside and outside of the object
        ''
        ''  BlinkLed = name of routine 
        ''
        ''  dira = Direction Register for I/O pins meaning that it is an output or input 
        ''
        ''
        ''
        dira[4..9]~~          '           (~~)              Post Set /   set bits as outputs. 
                              '
                              '
        outa[4..9] := %100001 '           ( %100001 )       1 = set or ON and 0 = clear or OFF
                              '
                              '           ( [ ..] )         equal to the value of the symbol or
                              '                             expression to the right of
                              '                             the of the operator
                              '         
    
        repeat
        
            !outa[4..9]       '         ( !outa[4..9] )         invert pin direction state bits [x..y]...
                              '                             ... this is what mean  " ! "    by solo
    
        '' cnt -                   a register that counts system clock ticks
        ''
        '' clkfreq -               a command that returns system clock frequency in Hz clock or  
        ''                         a value that stores system clock ticks in one second
        ''
        '' waitcnt -               a command that waits for the the cnt register to get
        ''                         to a certain value                                 
        ''
        ''
            waitcnt(clkfreq/4 + cnt) '                      wait 1/4 of a second
    



    ''This code example is from Propeller Education Kit Labs: Fundamentals, v1.2.
    ''A .pdf copy of the book is available from www.parallax.com, and also through
    ''the Propeller Tool software's Help menu (v1.2.6 or newer).
    ''
    ''File: LedsOnOff50Percent.spin
    ''Leds alternate on/off 50% of
    ''the time.
    
    PUB BlinkLeds
    
      ''  PUB  = Public Method Block meaning that code routine are accessible inside and outside of the object
        ''
        ''  BlinkLed = name of routine 
        ''
        ''  dira = Direction Register for I/O pins meaning that it is an output or input
        ''
        ''
        ''
        ''       ( [ ..] )        equal to the value of the symbol or expression to the right of
        ''                        the of the operator
        ''
        ''        (~~)            Post Set / sign-extend from bit 15 
        ''
        ''        ( := )          It sets the symbol to the left of the operator equal to the value 
        ''                        of the symbol or expression to the right of the operator 
        '' 
        ''       (:= %111111)     will set bit to outputs pins 4 to 9  1 = output / 0 = input
        ''
        ''  outa                  Output State Register  meaning that the output pin is set or clears 
        ''                        1 = high / 0 =  low or ON /OFF or set = 1 clear = 0
        ''
        ''        (:= %101010)     set P4,clears P5, set P6,clears P7
        ''                         and so on to pin 9
        ''
        '' 
        ''
        '' cnt -                   a register that counts system clock ticks
        ''
        '' clkfreq -               a command that returns system clock frequency in Hz clock or  
        ''                         a value that stores system clock ticks in one second
        ''
        '' waitcnt -               a command that waits for the the cnt register to get
        ''                         to a certain value
        
                                    
    
        dira[4..9]~~  '  (~~)      Post Set /   set bits as outputs.
        repeat
    
            outa[4..9] := %100001    '(:= %111111)  will set bit to outputs pins 4 to 9     
            waitcnt(clkfreq/4 + cnt) '( clkfreq/4)  wait 1/4 of a second  
            outa[4..9] := %011110    '(:= %011110)  set P4,clears P5, set P6,clears P7 and so on to pin 9  
            waitcnt(clkfreq/4 + cnt) '( clkfreq/4)  wait 1/4 of a second
    
  • jazzedjazzed Posts: 11,803
    edited 2011-02-13 16:44
    Until you've refined your own style, it's probably best to look at others code and copy something that you like. There are many, many things you can learn by reading other's code. The PEK labs is just one example of many and may or may not be the best. Good luck on your quest.
  • kuronekokuroneko Posts: 3,623
    edited 2011-02-13 16:47
    dira[4..9]~~  '  (~~)      Post Set / [COLOR="blue"]sign-extend from bit 15[/COLOR]
    
    This may be confusing to some people. ~~ is used as post-operator, so why do you mention the sign extension (~~value)? It's not relevant in this context.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-02-13 16:51
    Can you post a link to other style so I can get some idea that are for the Propeller thanks

    I want to put something for ~~ I just asking what would be relevant in this context.
    Please put something for a beginner to understand thanks

    So far I have not anything in Propeller Education Kit Lab text that I have read so far
  • kuronekokuroneko Posts: 3,623
    edited 2011-02-13 16:58
    Propeller Manual p. 157. All I was trying to say was that the comment should just read post set or even better set bits as outputs.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-02-13 17:42
    Thanks that will work
Sign In or Register to comment.