Shop OBEX P1 Docs P2 Docs Learn Events
Need some code help for PST - Lost little lamb... — Parallax Forums

Need some code help for PST - Lost little lamb...

Hello,

I'm working on a personal Propeller project that uses two sensors to measure a fan blade track path, (right now ceiling fan). Plan to measure via triangulation by knowing the times the blades are between beams. I'm currently stuck in that I can seem to properly grasp how to make a line cascade downward in PST. I want to take a reading "BeamTime(nS)" and make 5 columns of data and have it append once for each full revolution of the fan. (Five blades = 5 timing events per revolution). I've been able to modify xTach by Mark Owen to get to a really good starting point but stuck with displaying the times. I could use a little code help in getting over the hump, any help is much appreciated. I've attached the spin files and a screen shot of what I currently want to display on PST.

Couple of questions:

1. How can I make data row one in the screen cascaded down with each value update? I know its simple but I've not been able to figure that out.
2. As stated above I'd also like to just have the second data row (Blade#1-n) cascade down with each update. I"ve tried #NL commands and other options, I know it must be simple...

{{

Developed from:
┌───────────────────────────────────────────────────┐
│ xTachTest.spin version 1.0.0                      │
├───────────────────────────────────────────────────┤
│                                                   │               
│ Author: Mark M. Owen                              │
│                                                   │                 
│ Copyright (C)2014 Mark M. Owen                    │               
│ MIT License - see end of file for terms of use.   │                
└───────────────────────────────────────────────────┘

Description:
  Demonstrates usage of the xTach methods for determining the activity
  on an input pin:
        Pulse width in system clock ticks
        Pulse frequency in Hz (cycles per second)
        Pulses per minute
        Revolutions per minute

  Uses the Parallax Serial Terminal for output at 115,200 baud for output.
  
  Written as a means of circumventing jitter found to be present when using
  assembly language frequency counters for low frequency signals (in my case
  a belt driven aircraft prpeller with 39 teeth per revolution on the main
  drive pully which runs at a maximum of 3600 revolutions per minute).

  Has been tested using a signal generator from 1Hz to 50kHz and found to be
  accurate to better than 98% over the range tested with the largest errors at
  frequencies less than 30Hz (2%).

Revision History:
  Initial version               2014-10-16 MMOwen
  Added Decay function          2014-10-18 MMOwen

}}
CON
  _clkmode = xtal1 + pll16x                  ' System clock → 80 MHz
  _xinfreq = 5_000_000                       ' external crystal 5MHz


  TACH_PULSES_PER_REVOLUTION    = 5

  ColPos = 8
                                                 
OBJ
  TACH          : "xTrack"
  pst           : "Parallax Serial Terminal" 

VAR

  long Blade[6] 
  long Buff[6]
    
PUB Main 
  EnablePST
 
  TACH.Start(8)

  pst.Position(0,0)
  pst.Str(string("PkPkTicks"))
  pst.Position(15,0)
  pst.Str(string("Hz"))
  pst.Position(30,0)
  pst.Str(string("Pulses/Min"))
  pst.Position(45,0)
  pst.Str(string("RPM"))
  pst.Position(60,0)
  pst.Str(string("BeamTime(nS)"))
  pst.Position(30,5)
  pst.Str(string("Blade Timeing"))
  pst.Position(0,6)
  pst.Str(string("Blade#1"))
  pst.Position(15,6)
  pst.Str(string("Blade#2"))
  pst.Position(30,6)
  pst.Str(string("Blade#3"))
  pst.Position(45,6)
  pst.Str(string("Blade#4"))
  pst.Position(60,6)
  pst.Str(string("Blade#5"))
  
  repeat 
    pst.Position(0,1)
    pst.ClearEnd
    pst.Dec(TACH.PulsePktoPkTicks)
    pst.Position(15,1)
    pst.Dec(TACH.Hz)
    pst.Position(30,1)
    pst.Dec(TACH.PulsesPerMinute)
    pst.Position(45,1)
    pst.Dec(TACH.RevolutionsPerMinute(TACH_PULSES_PER_REVOLUTION))
    pst.Position(60,1)
    pst.Dec(TACH.BeamTime)
    pst.Position(0,7)
    pst.dec(Blade[1])
    pst.str(string("  ",8))
    pst.Position(15,7)
    pst.dec(Blade[2])
    pst.str(string("  ",8))
    pst.Position(30,7)
    pst.dec(Blade[3])
    pst.str(string("  ",8))
    pst.Position(45,7)
    pst.dec(Blade[4])
    pst.str(string("  ",8))
    pst.Position(60,7)
    pst.dec(Blade[5])
    pst.str(string("  ",8))  
    TACH.Decay
    waitcnt(clkfreq/5+cnt)
    
  

PRI EnablePST
  pst.start(115200)
  repeat 
    pst.Home
    pst.Clear
    pst.str(string("Start tests: press ."))
    pst.newline
    repeat while not pst.RxCount
      pst.Char("~")
      waitcnt(clkfreq+cnt)
    if pst.CharIn == "."
       quit
  pst.Home
  pst.Clear


Thanks in advance,

Chuck

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    Chuck,

    I'm not sure exactly what you're trying to do, but you can position the cursor at X/Y coordinates, so that would allow some flexibility over #NL.
  • JasonDorieJasonDorie Posts: 1,930
    edited 2017-01-03 21:48
    Just create a variable to track the current row, and pass that number to the position() function, like this:
    var yPos
    
    yPos := 0
    repeat
      PST.position( 15, 7 + yPos )
      PST.dec( blade[0] )
      yPos := (yPos + 1) % 5
    
  • Thanks Jason,

    Using your suggestion I was able to answer my question #1, though when I used the "%5" I get an "Invalid Binary #" error for that part of the code. I am able to cascade the values down the screen as they update, just in infinity...


    Jason/Chris,
    However for my question#2, I need help in getting the "BeamTime" object to fill in for each blade. I guess I'll need to make an array to fill those items in? What I'm trying to do is to fill in horizontally the beam time value for each blade and then start over again on a new line. So first value would start under "Blade#1" and the second on "Blade#2 and so on until it gets to "Blade#5 and then start a new line.

    Regards,

    Chuck
  • The % 5 was supposed to be the "modulo" operator. I think in Spin it's actually //, or two forward slashes in a row.
  • Still need a little guidance...

    What I'm currently trying to do is take the data output as "TACH.BeamTime" and display it in PST relative for each blade of the fan. There are five blades so five timing outputs for each revolution of the fan. I think what I needed to do is output "BeamTime" as a string and distribute that to each "BladeCounts"[0-4]. I just can't seem to understand how to accomplish this... Later on, I plan to add an additional optical sensor to mark each revolution of the fan so I can be assured that blade 1 is blade 1 and, blade 2 etc.

    Additionally, what is the "8" designating in "pst.str(string(" ",8))"
    Is this the # of bytes or "Y" axis plot?

    Thanks in advance,

    Chuck
    CON
      _clkmode = xtal1 + pll16x                  ' System clock → 80 MHz
      _xinfreq = 5_000_000                       ' external crystal 5MHz
    
    
      TACH_PULSES_PER_REVOLUTION    = 5
    
      
                                                     
    OBJ
      TACH          : "xTrack"
      pst           : "Parallax Serial Terminal" 
    
    VAR
    
      byte yPos
      long BladeCounts[6]
        
    PUB Main 
      EnablePST
     
      TACH.Start(8)
    
      pst.Position(0,0)
      pst.Str(string("PkPkTicks"))
      pst.Position(15,0)
      pst.Str(string("Hz"))
      pst.Position(30,0)
      pst.Str(string("Pulses/Min"))
      pst.Position(45,0)
      pst.Str(string("RPM"))
      pst.Position(60,0)
      pst.Str(string("BeamTime(nS)"))
      pst.Position(30,5)
      pst.Str(string("Blade Timeing"))
      pst.Position(0,6)
      pst.Str(string("Blade#1"))
      pst.Position(15,6)
      pst.Str(string("Blade#2"))
      pst.Position(30,6)
      pst.Str(string("Blade#3"))
      pst.Position(45,6)
      pst.Str(string("Blade#4"))
      pst.Position(60,6)
      pst.Str(string("Blade#5"))
    
      yPos := 0
      BladeCounts:=(Tach.BeamTime)
      
      BladeCounts:=0
      
      repeat 
        pst.Position(0,1)
        pst.ClearEnd
        pst.Dec(TACH.PulsePktoPkTicks)
        pst.Position(15,1)
        pst.Dec(TACH.Hz)
        pst.Position(30,1)
        pst.Dec(TACH.PulsesPerMinute)
        pst.Position(45,1)
        pst.Dec(TACH.RevolutionsPerMinute(TACH_PULSES_PER_REVOLUTION))
        pst.Position(60,1)
        pst.Dec(TACH.BeamTime)
        
        yPos :=(yPos+1)
        
        BladeCounts:=(BladeCounts+1)
         if BladeCounts >5
          BladeCounts=1
          
        pst.Position(0,7+yPos)
        pst.dec(BladeCounts[0])
        pst.str(string("  ",8))
        pst.Position(15,7+yPos)
        pst.dec(BladeCounts[1])
        pst.str(string("  ",8))
        pst.Position(30,7+yPos)
        pst.dec(BladeCounts[2])
        pst.str(string("  ",8))
        pst.Position(45,7+yPos)
        pst.dec(BladeCounts[3])
        pst.str(string("  ",8))
        pst.Position(60,7+yPos)
        pst.dec(BladeCounts[4])
        pst.str(string("  ",8))  
        TACH.Decay
        waitcnt(clkfreq/5+cnt)
        
      
    
    PRI EnablePST
      pst.start(115200)
      repeat 
        pst.Home
        pst.Clear
        pst.str(string("Start tests: press ."))
        pst.newline
        repeat while not pst.RxCount
          pst.Char("~")
          waitcnt(clkfreq+cnt)
        if pst.CharIn == "."
           quit
      pst.Home
      pst.Clear
    
  • kwinnkwinn Posts: 8,697
    Two ways to do that. First one is to have the blade times in a variable array and print them on the fly followed by a carriage return.
    pri blades  | i
    repeat i from 0 to 4
      blade[i] := bladetime
      pst.dec (blade[i])
      pst.str(string("  "))                  ' print spaces
    pst.NewLine
    
    var
    long    blade[5]
        
    

    The second would be to convert the time to ascii characters, store them as a dat string, and print the entire line.
    pri blades
      pst.str blade1
        
    dat
    blade1  byte  "1234", "  "
    blade2  byte  "1234", "  "
    blade3  byte  "1234", "  "
    blade4  byte  "1234", "  "  
    blade5  byte  "1234", 13, 0
    

  • kwinn,

    Attempted making changes using your version 1. Still no luck. New code is shown below. I also attached a screenshot of PST, showing that I'm getting the text plotted but the values aren't getting updated in the columns.

    TIA,

    Chuck
    CON
      _clkmode = xtal1 + pll16x                  ' System clock → 80 MHz
      _xinfreq = 5_000_000                       ' external crystal 5MHz
    
    
      TACH_PULSES_PER_REVOLUTION    = 5
    
      
                                                     
    OBJ
      TACH          : "xTrack"
      pst           : "Parallax Serial Terminal" 
    
    VAR
    
      byte yPos
      long BladeCounts[5]
    
    PRI  blades | i
        
       repeat i from 0 to 4
        BladeCounts[i]:= (TACH.BeamTime)
        
          
    PUB Main 
      EnablePST
     
      TACH.Start(8)
    
      pst.Position(0,0)
      pst.Str(string("PkPkTicks"))
      pst.Position(15,0)
      pst.Str(string("Hz"))
      pst.Position(30,0)
      pst.Str(string("Pulses/Min"))
      pst.Position(45,0)
      pst.Str(string("RPM"))
      pst.Position(60,0)
      pst.Str(string("BeamTime(nS)"))
      pst.Position(30,5)
      pst.Str(string("Blade Timeing"))
      pst.Position(0,6)
      pst.Str(string("Blade#1"))
      pst.Position(15,6)
      pst.Str(string("Blade#2"))
      pst.Position(30,6)
      pst.Str(string("Blade#3"))
      pst.Position(45,6)
      pst.Str(string("Blade#4"))
      pst.Position(60,6)
      pst.Str(string("Blade#5"))
    
      yPos := 0
    
      
      repeat 
        pst.Position(0,1)
        pst.ClearEnd
        pst.Dec(TACH.PulsePktoPkTicks)
        pst.Position(15,1)
        pst.Dec(TACH.Hz)
        pst.Position(30,1)
        pst.Dec(TACH.PulsesPerMinute)
        pst.Position(45,1)
        pst.Dec(TACH.RevolutionsPerMinute(TACH_PULSES_PER_REVOLUTION))
        pst.Position(60,1)
        pst.Dec(TACH.BeamTime)
       
        yPos :=(yPos+1)
    
        pst.Position(0,7+yPos)
        pst.dec(BladeCounts[0])
        pst.str(string("  "))
        pst.Position(15,7+yPos)
        pst.dec(BladeCounts[1])
        pst.str(string("  "))
        pst.Position(30,7+yPos)
        pst.dec(BladeCounts[2])
        pst.str(string("  "))
        pst.Position(45,7+yPos)
        pst.dec(BladeCounts[3])
        pst.str(string("  "))
        pst.Position(60,7+yPos)
        pst.dec(BladeCounts[4])
        pst.str(string("  "))  
        TACH.Decay
        waitcnt(clkfreq/5+cnt)
        
               
    
    PRI EnablePST
      pst.start(115200)
      repeat 
        pst.Home
        pst.Clear
        pst.str(string("Start tests: press ."))
        pst.newline
        repeat while not pst.RxCount
          pst.Char("~")
          waitcnt(clkfreq+cnt)
        if pst.CharIn == "."
           quit
      pst.Home
      pst.Clear
    
    4404 x 2296 - 255K
  • kwinnkwinn Posts: 8,697
    Sorry, I thought you had already stored the values and were just looking for a way to print them out in columns. I will take a look at this in the morning. Too tired to do anything tonight.
Sign In or Register to comment.