Shop OBEX P1 Docs P2 Docs Learn Events
BS2 Functions Library — Parallax Forums

BS2 Functions Library

MarenaMarena Posts: 3
edited 2011-03-21 11:00 in Propeller 1
Hello guys!!

Have you ever used BS2_Function Library?
I´m trying to set PWM on pin 0, but it doesn´t work.
Compilation is successful, but nothing there on pin0!? :(

My code:

CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

OBJ
BS2 : "BS2_Functions" ' Create BS2 Object
PUB Start
BS2.start (31,30) ' Initialize BS2 Object timing, Rx and Tx pins for DEBUG
BS2.PWM_Set(0,500,10)

Something is missing? No more is recomended in BS2 :(

Thaks for help

Mark

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-21 10:19
    Your problem is that you're starting up the PWM, then immediately stopping it.

    When you do the BS2.PWM_Set call, you're just initiating the PWM output. This continues until you stop it with another call to one of the PWM functions or until the cog stops running. When the Propeller starts up your program, it calls the first method in the main program. If that method ever returns, it's to an implied COGSTOP which stops that cog and resets everything in the cog including any PWM being generated.

    Your answer is to put some kind of delay or even an infinite loop there, something like:
    BS2.PWM_Set(0,500,10)
    repeat
       waitcnt(clkfreq+cnt)
    
    This puts in a 1 second delay that repeats indefinitely.
  • MarenaMarena Posts: 3
    edited 2011-03-21 10:24
    Ok!
    If I put parametr 500 in PWM_Set, I have to do loop with for example repeat.
    But frequency is too high!
    Is it possible to decrease frequency, even if I use cntra register in cog?
  • MarenaMarena Posts: 3
    edited 2011-03-21 10:56
    There is an answer already!?
    Thanky you Mike for quick reply and explanation!
  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-21 11:00
    Try changing the resolution to change the frequency.
    BS2.PWM_Set(0,1000,11)
    BS2.PWM_Set(0,2000,12)
    BS2.PWM_Set(0,4000,13)
    BS2.PWM_Set(0,8000,14)
    These should all give you the same proportion of on / off time doubling the cycle time with each change of 1 bit in resolution.

    If you have further questions about how this works, read the PEK (Propeller Education Kit) lab on the counters here.
Sign In or Register to comment.