Shop OBEX P1 Docs P2 Docs Learn Events
propeller calculate speed probelm — Parallax Forums

propeller calculate speed probelm

ggg558877ggg558877 Posts: 40
edited 2012-12-29 09:29 in Propeller 1
hello everyone
now i diy a encoder and want to get the wind speed value
my encoder just like this video
http://www.youtube.com/watch?v=ytOfofCJjGg&feature=player_embedded

and i use
 waitpne(0, |< Pin, 0)                                                         
  cnt1 := cnt                                                                  
  waitpeq(0, |< Pin, 0)                                                         
  cnt2 := cnt                                                                 
  Microseconds := (||(cnt1 - cnt2) / (clkfreq / 1_000_000))
to calculate microseconds
but the output always have value 0
ex:
0
551
0
196
0
229
0
147
0
190
0
176
0
90

and if the wind speed sensor no rotate
it dosen't have value transmitted

and i want is
if wind speed sensor rotate
it transmitte
ex
551
196
229
147
190
176
90
and on rotate
it transmitte
ex
0
0
0
0
0
0

how can i slove my problem
thanks

Comments

  • BeanBean Posts: 8,129
    edited 2012-12-26 20:00
    There is no way to make WAITPNE or WAITPEQ to quit unless the pin actually changes.

    I think you would be better off to use the hardware counter to count the pulses.

    Bean
  • JonnyMacJonnyMac Posts: 9,108
    edited 2012-12-26 20:48
    I'm with Bean. You could easily setup a cog that monitors the anemometer input for some specified period and reports the transitions for that period to the variable of your choice.
    pri anemometer(pin, period, p_count) | t                        ' launch with cognew
    
    '' Report anemometer counts on pin every period
    '' -- pin is input
    '' -- period is duration for count in system ticks
    '' -- p_count is a pointer to the desired result variable (long)
    
      ctra := (%01010 << 26) | pins                                 ' set to POSEDGE mode
      frqa := 1                                                     ' add 1 per edge detected
      
      t := cnt                                                      ' sync period timer
      repeat
        phsa := 0                                                   ' clear pulse count
        waitcnt(t += period)                                        ' let period expired
        long[p_count] := phsa                                       ' report count
    
  • ggg558877ggg558877 Posts: 40
    edited 2012-12-26 22:34
    JonnyMac wrote: »
    I'm with Bean. You could easily setup a cog that monitors the anemometer input for some specified period and reports the transitions for that period to the variable of your choice.
    thanks Bean and JonnyMac
    so i must add something on my wind speed sensor ?
    or only use software to solve this problem?
  • jmgjmg Posts: 15,173
    edited 2012-12-26 23:56
    ggg558877 wrote: »
    so i must add something on my wind speed sensor ?
    or only use software to solve this problem?

    The example in #3 is only software, to solve the issue of no reading on static sensor.
    It configures a counter to increment on every sensor _/= and then reads that at some slow but precise rate.

    These number are 32 bit precision, so you can read every 100ms for example to get a rapid speed display of moderate precision, good for peak readings, but also do a every-100-seconds-update, to get a nicely averaged and high precision wind speed display.

    If we guess a 500us sensor speed, then a 100ms sample/refresh rate [Period in #3] can display to 0.5%, and a 100 second sample/refresh could display to 1000 times better precision (but you may choose to limit the displayed digits, to something practical )


    If you want highest precision, you could apply Reciprocal Frequency Counter techniques, but whether that was worth doing, would depend on the jitter on each pulse edge of your sensor..
    Sensors are always the weakest link.
  • ggg558877ggg558877 Posts: 40
    edited 2012-12-27 06:33
    thanks jmg
    so i can use example in #3 to count the the number of pulses
    and count the the number of pulses in 1s to convert rps?
  • JonnyMacJonnyMac Posts: 9,108
    edited 2012-12-27 13:22
    so i must add something on my wind speed sensor ?

    As with any home-built sensor, you will have to calibrate it. I'm sure there are lots of YouTube videos on this process. It would be a good idea to have a calibrated device for comparison.
  • ggg558877ggg558877 Posts: 40
    edited 2012-12-28 00:07
    Hi JonnyMac
    in your code in #3
    if I want to count the the number of pulses in 1s the period must set in one second ?
    and long[p_count] value is pulse/s ?
  • JonnyMacJonnyMac Posts: 9,108
    edited 2012-12-28 00:27
    Sorry, I was counting on you knowing how to launch a Spin method into its own cog. You'll need some varables
    var
    
      long  cstack[16]
      long  counts
    


    The array provides stack space for the Spin interpreter running the code. The other variable is what you will access in raw counts. Let's say that you want to count your inputs on P0 and accumualte every second. You would launch the Spin cog like this:
    cognew(anemometer(0, clkfreq, @counts), @cstack)
    

    and long[p_count] value is pulse/s ?


    No, that line is updating the long at the address you specify in the call. I use "p_" to designate a pointer (address of a variable).


    Easy-peazy.
  • ggg558877ggg558877 Posts: 40
    edited 2012-12-28 00:51
    thanks JonnyMac
    so the value i want is counts
    pub main
        cognew(anemometer(0, clkfreq, @counts), @cstack)
        repeat
           pst.dec(counts)                  
           pst.tx(13)
           WaitCnt(ClkFreq+ Cnt) 
    
    
    is that right?
  • JonnyMacJonnyMac Posts: 9,108
    edited 2012-12-28 01:24
    It will work, but you really should learn to use a synchronized loop (this is covered in the manual, and you'll see it in the attached demo).

    In my code, you'll see that I'm setting one of the Propeller's counters to use the same pin as I'm declaring as an input for the anemometer -- this lets the Propeller test itself without any hardware connected. Always a good idea to know code is working before connecting new hardware.

    I added the code suggestions to my standard template, so there's lots of stuff there that you may want to save for other projects, even if they aren't used in this one.
  • ggg558877ggg558877 Posts: 40
    edited 2012-12-28 02:01
    thanks JonnyMac
    I'll try to learn it
    can you explain
    con 
      #(-1), IS_ON, IS_OFF
      #0, LSBFIRST, MSBFIRST  
    con
       #1, HOME, GOTOXY, #8, BKSP, TAB, LF, CLREOL, CLRDN, CR       ' PST formmatting control
      #14, GOTOX, GOTOY, CLS
    
    i can't understand these line
    what #(-1),#0,#1,#8,#14 ,#1 doing?
    thanks a lot
  • JonnyMacJonnyMac Posts: 9,108
    edited 2012-12-28 18:51
    Look, I'm that last person you want to ask for hand-holding (especially after I wrote a whole, working program for you); if you need it, call me and pay my customary programming rate for the number of hours you want me to hold your hand. :)

    Please ... there are plenty of materials available that explain Spin programming basics -- you can find good material as close as the Help menu in the Propeller Tool. Toward the bottom of page 88 in the manual you'll find an explanation about changing an enumerated CON block.

    I don't mean to seem impatient, but YOU have some responsibility for study beyond the forums if you really want to become a good Propeller programmer.
  • ggg558877ggg558877 Posts: 40
    edited 2012-12-28 20:58
    thanks JonnyMac
    sorry i ask a stupid problem
    and i found the answer in the manual:tongue:
    thanks for your help a lot :smile:
  • JonnyMacJonnyMac Posts: 9,108
    edited 2012-12-29 09:29
    You're welcome.
Sign In or Register to comment.