Shop OBEX P1 Docs P2 Docs Learn Events
Trying to make a Object that will let you see the state of a input / output pins only — Parallax Forums

Trying to make a Object that will let you see the state of a input / output pins only

sam_sam_samsam_sam_sam Posts: 2,286
edited 2011-02-19 17:03 in Propeller 1
Using the Parallax Serial Terminal object with the Parallax Serial Terminal if there is one in Spin

Can some one give me a link to it

Thanks

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-02-18 18:15
    That description is rather vague. Would a simple 32bit vector display be what you want?
    CON
      _clkmode = XTAL1|PLL16X
      _xinfreq = 5_000_000
    
    OBJ
      serial: "Parallax Serial Terminal"
    
    VAR
      long  stack[32]
      
    PUB null
    
      cognew(monitor, @stack{0})                            ' start monitor
    
      dira[16..23]~~
      repeat                                                ' make some pin noise
        outa[16..23]++
        waitcnt(clkfreq + cnt)
    
    PRI monitor
    
      serial.Start(115200)                                  ' initialise serial driver
      waitcnt(clkfreq + cnt)                                ' cover startup delay
    
      repeat
        serial.Char(serial#HM)                              ' HOME
        serial.Bin(ina, 32)                                 ' send ina vector as binary
        waitcnt(clkfreq/10 + cnt)                           ' don't run at full speed
    
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-02-19 01:22
    Hi 3xSam,

    Hanno Sander has created a PC-Tool that transferes values of variables at a high speed into a PC-app

    One seprate cog is used to transfer the variable values. So all you have to do is assign the value of the IO-register
    to a variable inside of your main-code.

    you can download it here

    http://hannoware.com/ezlog/

    Follow the instructions given in the example-files
    If you have problems to get it running come back with a detailed description what you want to do
    and your COMPLETE source-code as a propeller-tool-zip-archive


    Anyway if you want to debug code I recommend adding titled debug-output to you code and using PST.EXE.

    If the values are titled with fixed coded text you just read the deub-output
    You don't have to think about what is bit no 17 and what does it mean if it has value 1 at this part of the code
    You put this information into the title of debug-output

    best regards

    Stefan
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-02-19 05:19
    kuroneko
    Thank you for your reply
    If not to much trouble could you show me how to use this in this code demo
    ''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: ButtonToLed.spin
    '' Led mirrors pushbutton state.
    
    PUB ButtonLed                                ' Pushbutton/Led Method
    
        dira[6]  := 1                            ' P6  → output
        dira[9] := 0                            ' P21 → input (this command is redundant)
                                                 
        repeat                                   ' Endless loop
    
           outa[6] := ina[9]                    ' Copy P21 input to P6 ouput
    

    Thanks for your help
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-02-19 05:25
    Stefan
    Thank you for your reply

    If it is not to much trouble could you show me how to use this in this code demo above

    Anyway if you want to debug code I recommend adding titled debug-output to you code and using PST.EXE.

    Please example this more

    Thanks for your help
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-02-19 07:05
    I have been working with one which is half of what I am looking for it show the state of the input pin
    But I have not found a simple one for the output pins status
    ''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).
    ''
    {{ DisplayPushbuttons.spin
    Display pushbutton states with Parallax Serial Terminal.
    
    Pushbuttons                                            
    ─────────────────────────────────────────────────────────────────── 
            3.3 V                  3.3 V                  3.3 V         
                                                                     
              │                      │                      │           
             ┤Pushbutton           ┤Pushbutton           ┤Pushbutton 
              │                      │                      │           
    P11 ───┫            P10 ───┫            P09 ───┫           
         100 Ω│                 100 Ω│                 100 Ω│           
              │                      │                      │           
               10 kΩ                 10 kΩ                 10 kΩ     
              │                      │                      │           
                                                                     
             GND                    GND                    GND          
    ───────────────────────────────────────────────────────────────────
    }}
    
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    OBJ
      pst : "Parallax Serial Terminal"  
       
    PUB TerminalPushbuttonDisplay
    
      ''Read P11 through P09 pushbutton states and display with Parallax Serial Terminal.
     
      pst.Start(115_200)
    
      pst.Char(pst#CS)
      pst.Str(String("Pushbutton States", pst#NL))
      pst.Str(String("-----------------", pst#NL))
    
      repeat
        pst.PositionX(0)
        pst.Bin(ina[11..9], 3)
        waitcnt(clkfreq/100 + cnt)
    
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-02-19 07:30
    I have the first half of what I want to see and that is the status of the button in code this routine
    What would I need to add to this routine to see the output status in this example

    Thanks
    ''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).
    ''
    {{ DisplayPushbuttons.spin
    Display pushbutton states with Parallax Serial Terminal.
    
    Pushbuttons                                            
    ─────────────────────────────────────────────────────────────────── 
            3.3 V                  3.3 V                  3.3 V         
                                                                     
              │                      │                      │           
             ┤Pushbutton           ┤Pushbutton           ┤Pushbutton 
              │                      │                      │           
    P11 ───┫            P10 ───┫            P09 ───┫           
         100 Ω│                 100 Ω│                 100 Ω│           
              │                      │                      │           
               10 kΩ                 10 kΩ                 10 kΩ     
              │                      │                      │           
                                                                     
             GND                    GND                    GND          
    ───────────────────────────────────────────────────────────────────
    }}
    
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    OBJ
      pst : "Parallax Serial Terminal"  
       
    PUB TerminalPushbuttonDisplay
    
      ''Read P11 through P09 pushbutton states and display with Parallax Serial Terminal.
     
      pst.Start(115_200)
    
      pst.Char(pst#CS)
      pst.Str(String("Pushbutton States", pst#NL))
      pst.Str(String("-----------------", pst#NL))
    
      dira[6]  := 1                            ' P6  → output
      dira[9]  := 0                            ' P09 → input (this command is redundant)
    
      repeat
        pst.PositionX(0)
        pst.Bin(ina[11..9], 3)
        waitcnt(clkfreq/100 + cnt)
        outa[6] := ina[9]                    ' Copy P21 input to P6 ouput    
    
  • John AbshierJohn Abshier Posts: 1,116
    edited 2011-02-19 07:42
    Open the propeller manual. Search for outa. And find the following:

    Normally OUTA is only written to but it can also be read from to retrieve the current I/O pin output latch states. This is ONLY the cog’s output latch states, not necessarily the actual output states of the Propeller chip’s I/O pins, as they can be further affected by other cogs or even this cog’s other I/O hardware (Video Generator, Count A, etc.). The following assumes Temp is a variable created elsewhere:
    Temp := OUTA[15..13] 'Get output latch state of P15 to P13
    The above sets Temp equal to OUTA bits 15, 14, and 13; i.e.: the lower 3 bits of Temp are now equal to OUTA15:13 and the other bits of Temp are cleared to zero.

    John Abshier
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-02-19 08:21
    How can I display the data this on one line pst.Bin(ina[11..9], 3) and this on the next line pst.Bin(outa[8..4], 4) It work right if I have one line or the other line commet out

    I am learing allot but I still new to this
    I am using the Propeller Professional Development Board
    This might not be the best example to use but this is a simple one for me to learn from
    Also this might not be the best way to write this code But I am looking for something simple one for me to learn from
    Feel free to write this a better way but still use this part as the main thing you are going by outa[6] := ina[9] ' Copy P9 input to P6 ouput and using the
    Parallax Serial Terminal so I can see both Input and output satus at the same time


    Thanks


    repeat
        pst.PositionX(0)   
        pst.Bin(ina[11..9], 3)
        pst.Bin(outa[8..4], 4)  
        waitcnt(clkfreq/100 + cnt)
        outa[6] := ina[9]                        ' Copy P9 input to P6 ouput
    

    Here all of the code routine
    ''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).
    ''
    {{ DisplayPushbuttons.spin
    Display pushbutton states with Parallax Serial Terminal.
    
    Pushbuttons                                            
    ─────────────────────────────────────────────────────────────────── 
            3.3 V                  3.3 V                  3.3 V         
                                                                     
              │                      │                      │           
             ┤Pushbutton           ┤Pushbutton           ┤Pushbutton 
              │                      │                      │           
    P11 ───┫            P10 ───┫            P09 ───┫           
         100 Ω│                 100 Ω│                 100 Ω│           
              │                      │                      │           
               10 kΩ                 10 kΩ                 10 kΩ     
              │                      │                      │           
                                                                     
             GND                    GND                    GND          
    ───────────────────────────────────────────────────────────────────
    }}
    
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    OBJ
      pst : "Parallax Serial Terminal"  
       
    PUB TerminalPushbuttonDisplay
    
      ''Read P11 through P09 pushbutton states and display with Parallax Serial Terminal.
     
      pst.Start(115_200)
    
      pst.Char(pst#CS)
      pst.Str(String("Pushbutton States", pst#NL))
      pst.Str(String("-----------------", pst#NL))
      'dira[9..11]~~  
    
      dira[6]  := 1                            ' P6  → output
      dira[9]  := 0                            ' P09 → input (this command is redundant)
    
      repeat
        pst.PositionX(0)   
       ' pst.Bin(ina[11..9], 3)
        pst.Bin(outa[8..4], 4)  
        waitcnt(clkfreq/100 + cnt)
        outa[6] := ina[9]                        ' Copy P9 input to P6 ouput    
    
  • Mike GMike G Posts: 2,702
    edited 2011-02-19 08:52
    pst.char(13) creates a new line using the Parallax Serial Terminal object. I think that's what you're asking? Anyway, open the Parallax Serial Terminal object and read the code comments at the top for terminal commands.
    CON
    ''
    ''     Parallax Serial Terminal
    ''    Control Character Constants
    ''─────────────────────────────────────
      CS = 16  ''CS: Clear Screen      
      CE = 11  ''CE: Clear to End of line     
      CB = 12  ''CB: Clear lines Below 
    
      HM =  1  ''HM: HoMe cursor       
      PC =  2  ''PC: Position Cursor in x,y          
      PX = 14  ''PX: Position cursor in X         
      PY = 15  ''PY: Position cursor in Y         
    
      NL = 13  ''NL: New Line        
      LF = 10  ''LF: Line Feed       
      ML =  3  ''ML: Move cursor Left          
      MR =  4  ''MR: Move cursor Right         
      MU =  5  ''MU: Move cursor Up          
      MD =  6  ''MD: Move cursor Down
      TB =  9  ''TB: TaB          
      BS =  8  ''BS: BackSpace          
               
      BP =  7  ''BP: BeeP speaker 
    
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-02-19 12:05
    This is working code I do not how well written it is but here it is
    ''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).
    ''
    {{ DisplayPushbuttons.spin
    Display pushbutton states with Parallax Serial Terminal.
    
    Pushbuttons                                            
    ─────────────────────────────────────────────────────────────────── 
            3.3 V                  3.3 V                  3.3 V         
                                                                     
              │                      │                      │           
             ┤Pushbutton           ┤Pushbutton           ┤Pushbutton 
              │                      │                      │           
    P11 ───┫            P10 ───┫            P09 ───┫           
         100 Ω│                 100 Ω│                 100 Ω│           
              │                      │                      │           
               10 kΩ                 10 kΩ                 10 kΩ     
              │                      │                      │           
                                                                     
             GND                    GND                    GND          
    ───────────────────────────────────────────────────────────────────
    }}
    
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    OBJ
      pst : "Parallax Serial Terminal"  
       
    PUB TerminalPushbuttonDisplay
    
      ''Read P11 through P09 pushbutton states and display with Parallax Serial Terminal.
     
      pst.Start(115_200)
    
      pst.Char(pst#CS)
      pst.Str(String("Pushbutton States", pst#NL))
      pst.Str(String("Input..... Output", pst#NL))
       
    
      dira[6]  := 1                            ' P6  → output
      dira[9]  := 0                            ' P09 → input (this command is redundant)
    
      repeat
        pst.PositionX(0)   
        pst.Bin(ina[12..9], 4)
        pst.PositionX(12)  
        pst.Bin(outa[8..4], 4)  
        waitcnt(clkfreq/100 + cnt)
        outa[6] := ina[9]                        ' Copy P9 input to P6 ouput
    


    What do I need to add or change to make this a stand a lone object
    I want to able to look at any pin whether it is an input pin or a output pin and how to call up the that part of routine



    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    OBJ
      pst : "Parallax Serial Terminal"  
       
    PUB InputOutputDisplay
    
      ''Read   pushbuttons and there states and display with Parallax Serial Terminal.
     
      pst.Start(115_200)
    
      pst.Char(pst#CS)
      pst.Str(String("Pushbutton States", pst#NL))
      pst.Str(String("Input..... Output", pst#NL))
       
    
         repeat
        pst.PositionX(0)   
        pst.Bin(ina[12..9], 4)
        pst.PositionX(12)  
        pst.Bin(outa[8..4], 4)  
        waitcnt(clkfreq/100 + cnt)
    

    Should have the Input as one routine and the output as another routine
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    OBJ
      pst : "Parallax Serial Terminal"  
       
    PUB TerminalPushbuttonDisplay
    
      ''Read pushbutton states and display with Parallax Serial Terminal.
     
      pst.Start(115_200)
    
      pst.Char(pst#CS)
      pst.Str(String("Pushbutton States", pst#NL))
      pst.Str(String(".........Input....,.....", pst#NL))
       
    
       
    
      repeat
        pst.PositionX(0)   
        pst.Bin(ina[12..9], 4)          ' What need to be change to make it what ever Pin
        waitcnt(clkfreq/100 + cnt)
    
          
         
    PUB TerminalOutputDisplay
    
      ''Read output states and display with Parallax Serial Terminal.
     
      pst.Start(115_200)
    
      pst.Char(pst#CS)
      pst.Str(String("Pushbutton States", pst#NL))
      pst.Str(String("........Output...,.....", pst#NL))
    
      
      repeat
        pst.PositionX(0)  
        pst.Bin(outa[8..4], 4)        ' What need to be change to make it what ever Pin
        waitcnt(clkfreq/100 + cnt)
    

    Here is the same code but with two button and two LEDs
    ''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).
    ''
    {{ DisplayPushbuttons.spin
    Display pushbutton states with Parallax Serial Terminal.
    
    Pushbuttons                                            
    ─────────────────────────────────────────────────────────────────── 
            3.3 V                  3.3 V                  3.3 V         
                                                                     
              │                      │                      │           
             ┤Pushbutton           ┤Pushbutton           ┤Pushbutton 
              │                      │                      │           
    P11 ───┫            P10 ───┫            P09 ───┫           
         100 Ω│                 100 Ω│                 100 Ω│           
              │                      │                      │           
               10 kΩ                 10 kΩ                 10 kΩ     
              │                      │                      │           
                                                                     
             GND                    GND                    GND          
    ───────────────────────────────────────────────────────────────────
    }}
    
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    OBJ
      pst : "Parallax Serial Terminal"  
       
    PUB TerminalPushbuttonDisplay
    
      ''Read P11 through P09 pushbutton states and display with Parallax Serial Terminal.
     
      pst.Start(115_200)
    
      pst.Char(pst#CS)
      pst.Str(String("Pushbutton States", pst#NL))
      pst.Str(String("Input......Output", pst#NL))
       
    
      dira[6]  := 1                            ' P6  → output
      dira[7]  := 1
     ' dira[10..8] := 0                         ' P09 → input (this command is redundant)
    
      repeat
        pst.PositionX(0)
        pst.Bin(ina[10..8], 2)
        pst.PositionX(12)
        pst.Bin(outa[7..6], 2)
       ' pst.NewLine   
        waitcnt(clkfreq/100 + cnt)
        outa[6] := ina[9]                        ' Copy P9 input to P6 ouput
        outa[7] := ina[8]                        ' Copy P9 input to P6 ouput 
    
  • Mike GMike G Posts: 2,702
    edited 2011-02-19 17:02
    Your code repeats forever so I'm not sure what your end end goal is... Debug??? The DIRA, INA, and OUTA register contain the current state of the I/O pins. See page 118 in the Propeller manual.
    What do I need to add or change to make this a stand a lone object
    Read chapter 6 in the Propeller Education Kit Lab - Fundamentals. You can open the manual form the Propeller Tool - Help - Propeller Education Kit.
  • kuronekokuroneko Posts: 3,623
    edited 2011-02-19 17:03
    If not to much trouble could you show me how to use this in this code demo
    I know it's probably not easy for you but you really should get your head around the multi-cog concept. Then it all falls into place. The monitor approach I suggested is nothing but an independent cog running in the background monitoring all pin states. HTH
    ''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: ButtonToLed.spin
    '' Led mirrors pushbutton state.
    ''
    [COLOR="red"]CON
      _clkmode = XTAL1|PLL16X
      _xinfreq = 5_000_000
    
    OBJ
      serial: "Parallax Serial Terminal"
    
    VAR
      long  stack[32]
    [/COLOR]
    PUB ButtonLed                                           ' Pushbutton/Led Method
    
      [COLOR="red"]cognew(monitor, @stack{0})                            ' start monitor
    [/COLOR]
      dira[6] := 1                                          ' P6 → output
      dira[9] := 0                                          ' P9 → input (this command is redundant)
                                                 
      repeat                                                ' Endless loop
        outa[6] := ina[9]                                   ' Copy P9 input to P6 ouput
    
    [COLOR="red"]PRI monitor
    
      serial.Start(115200)                                  ' initialise serial driver
      waitcnt(clkfreq + cnt)                                ' cover startup delay
    
      repeat
        serial.Char(serial#HM)                              ' HOME
        serial.Bin(ina, 32)                                 ' send ina vector as binary
        waitcnt(clkfreq/10 + cnt)                           ' don't run at full speed[/COLOR]
    
Sign In or Register to comment.