Shop OBEX P1 Docs P2 Docs Learn Events
Help with the BS2 Functions Library........... — Parallax Forums

Help with the BS2 Functions Library...........

jknightandkarrjknightandkarr Posts: 234
edited 2009-11-28 07:44 in Propeller 1
I've been looking over the codes in the BS2 Functions Library

Such as
PUB COUNT (Pin, Duration) : Value
{{
  Counts rising-edge pulses on Pin for Duration in mS
  Maximum count is around 30MHz
  Example Code:
    x := BS2.count(5,100)                ' Measure count for 100 mSec
    BS2.Debug_Dec(x)                     ' DEBUG value
    BS2.Debug_Char(13)                   ' CR
}}

       dira[noparse][[/noparse]PIN]~                                          ' Set as input
       ctra := 0                                           ' Clear any value in ctrb
                                                           ' set up counter, pos edge trigger
       ctra := (%01010 << 26 ) | (%001 << 23) | (0 << 9) | (PIN)  
       frqa := 1                                           ' 1 count/trigger
       phsa := 0                                           ' Clear phase - holds accumulated count
       pause(duration)                                     ' Allow to count for duration in mS
       Value := phsa                                       ' Return total count
       ctra := 0                                           ' clear counter mode



Now other then setting my pin & duration & adding the pause like waitcnt(clkfreq/4+cnt) is there any other configuring to do?

PUB FREQOUT(Pin,Duration, Frequency) 
{{
  Plays frequency defines on pin for duration in mS, does NOT support dual frequencies.
    BS2.Freqout(5,500,2500)    ' Produces 2500Hz on Pin 5 for 500 mSec
}}
   Update(Pin,Frequency,0)                                 ' Set tone using FREQOUT_Set
   Pause(Duration)                                         ' duration pause
   Update(Pin,0,0)                                         ' stop tone



This one I'm just lost totally on. I don't see any command called update & the propeller tool don't show that as a command. I need this one explained. Thanks.

Joe

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm going insaine. It's SOOOOOO much fun. lol

Comments

  • SamMishalSamMishal Posts: 468
    edited 2009-11-28 07:35
    The Freqout() function calls the Update() function.

    If you look a few lines down you will find the function (method)
    ··· Pub Update(pin, freq, ch)

    It is not a SPIN function or command. It is a user made function (method) that is
    part of the suite of methods in the BS2 object.....just scroll down a bit and you will see it.


    >>Now other then setting my pin & duration & adding the pause like waitcnt(clkfreq/4+cnt) is there any other configuring to do?

    You do not need to use the WaitCnt() to use the Count() method. If you look inside it carefully you will find a Pause() method
    call. This actually is another method in the Object and it does the work of waiting as the method Count() requires.

    Just make a call to the method and it won't return until it is finished....you do not need a waitcnt().



    Samuel
  • jknightandkarrjknightandkarr Posts: 234
    edited 2009-11-28 07:44
    Cool! Thanks, that makes it alot easyier to understand

    Joe

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm going insaine. It's SOOOOOO much fun. lol
Sign In or Register to comment.