BS2 Functions Library
Marena
Posts: 3
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
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
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: This puts in a 1 second delay that repeats indefinitely.
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?
Thanky you Mike for quick reply and explanation!
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.