Shop OBEX P1 Docs P2 Docs Learn Events
40hz to 400hz PWM ? — Parallax Forums

40hz to 400hz PWM ?

bennettdanbennettdan Posts: 614
edited 2010-05-27 01:52 in Propeller 1
Hello Forum
··
··· I am new to Prop and i am trying to output a single 40hz to 400hz square wave with 1-99% duty cycle and i can not seem to find info on how to do this. I have looked through the OBEX and found that the code examples are hard for me to follow being new to the Prop. Thanks

Comments

  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2010-05-26 16:55
    Try this (attached). I use it all the time. It uses a cog, which is a bit of a waste (there may be ways to do it with the counters), but it does the job.

    All you need to do is include the object in your project then call the start method with your pin, frequency, and duty (misspelled dudy).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    April, 2008: when I discovered the answers to all my micro-computational-botherations!

    Some of my objects:
    MCP3X0X ADC Driver - Programmable Schmitt inputs, frequency reading, and more!
    Simple Propeller-based Database - Making life easier and more readable for all your EEPROM storage needs.
    String Manipulation Library - Don't allow strings to be the bane of the Propeller, bend them to your will!
    Fast Inter-Propeller Comm - Fast communication between two propellers (1.37MB/s @100MHz)!
  • hover1hover1 Posts: 1,929
    edited 2010-05-26 17:09
    If you want to explore PWM using counters, The Propeller Education Kit Labs has a good section on PWM, chapter 7:

    ·http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/PELabsFunBook-v1.1.pdf

    Also the Application note AN001 on this page:

    ·http://www.parallax.com/tabid/832/Default.aspx

    is a good read.

    Jim
  • bennettdanbennettdan Posts: 614
    edited 2010-05-26 18:01
    Thanks for the code.... Bobb

    I will read the Propeller Education Kit Lab ...Jim
  • pjvpjv Posts: 1,903
    edited 2010-05-26 18:06
    bennettdan;

    I believe Hanno's "12 Blocks" is a very good canidate for this. Download it and you'll be up and running in less than 5 minutes...... it's THAT intuitive!

    Cheers,

    Peter (pjv)
  • hover1hover1 Posts: 1,929
    edited 2010-05-26 18:22
    Peter,

    I was going to suggest 12Blocks also, but I didn't think there was a trial period, but there is! 30 days.

    2nd the 12 Blocks!!

    Jim
    pjv said...
    bennettdan;

    I believe Hanno's "12 Blocks" is a very good canidate for this. Download it and you'll be up and running in less than 5 minutes...... it's THAT intuitive!

    Cheers,

    Peter (pjv)
  • bennettdanbennettdan Posts: 614
    edited 2010-05-27 01:33
    Bobb,

    Start (1,50,400)

    Would this be a 50% duty cycle 400 hz PWM signal on Pin 1 if I understand your obj.
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2010-05-27 01:52
    The order is pin, frequency, then duty.

    So what you want is
    start(1, 400, 50)
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    April, 2008: when I discovered the answers to all my micro-computational-botherations!

    Some of my objects:
    MCP3X0X ADC Driver - Programmable Schmitt inputs, frequency reading, and more!
    Simple Propeller-based Database - Making life easier and more readable for all your EEPROM storage needs.
    String Manipulation Library - Don't allow strings to be the bane of the Propeller, bend them to your will!
    Fast Inter-Propeller Comm - Fast communication between two propellers (1.37MB/s @100MHz)!
Sign In or Register to comment.