element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum PWM in arduino
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 4 replies
  • Subscribers 393 subscribers
  • Views 390 views
  • Users 0 members are here
  • arduino
Related

PWM in arduino

tejaswivarma
tejaswivarma over 12 years ago

Hi,

      I am Varma from India. I am working on arduino. i want to generate a PWM signal with time of 40 mSec. how should I change the time ????

  • Sign in to reply
  • Cancel

Top Replies

  • Former Member
    Former Member over 12 years ago +1
    http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM It seems you might have to do some calculations to see if you can get that value out of an arduino. Good luck.
Parents
  • deeps
    deeps over 10 years ago

    Hi

    u want 40ms time period in your pwm

    But what duty cycle do u want?

    see time period is on time + off time

    I think u want 50% duty cycle

    so 20ms on time

    and 20ms off time

    you can simply use digital write and delay

    similar to blink program but your delay will be according to on time and off time

    the delay after writing high in the pin is your on time

    and that after writing low is your off time

    Hope it helped

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Robert Peter Oakes
    Robert Peter Oakes over 10 years ago in reply to deeps

    I would suggest you use the pwm library for this purpose as using delay() will cause all processing to suspend while the delay is going on, this is ok if the only think you want the Arduino to do is output the PWM signal but is now good once you want to do other things

     

     

     

    The PWM library allows you do do other things and makes setting the parameters much simpler

     

     

     

     

     

    See http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM

     

    And

     

    https://code.google.com/p/arduino-pwm-frequency-library/

     

     

     

    Hope this helps

     

     

     

    Peter

    Attachments:
    image
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • deeps
    deeps over 10 years ago in reply to Robert Peter Oakes

    Well a solution to the problem with delay

    is with using milllis()

     

    https://learn.adafruit.com/multi-tasking-the-arduino-part-1/now-for-two-at-once

    With this we can multi thread arduino (kindof)

    and prevent arduino from suspending when delay is required

    and with all due respect sir

    I dont like using libraries too much

    1 they consume lots of space the functions that you may not require too come into rom

    2 It makes it hard to optimize your system which is first priority of modern embedded system design

    3 you are unable to understand the details of what is happening for example lcd seems easy but study how its to be done in ALP and than see the library of lcd and you will start to understand the details which the library was hiding from you

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • deeps
    deeps over 10 years ago in reply to Robert Peter Oakes

    Well a solution to the problem with delay

    is with using milllis()

     

    https://learn.adafruit.com/multi-tasking-the-arduino-part-1/now-for-two-at-once

    With this we can multi thread arduino (kindof)

    and prevent arduino from suspending when delay is required

    and with all due respect sir

    I dont like using libraries too much

    1 they consume lots of space the functions that you may not require too come into rom

    2 It makes it hard to optimize your system which is first priority of modern embedded system design

    3 you are unable to understand the details of what is happening for example lcd seems easy but study how its to be done in ALP and than see the library of lcd and you will start to understand the details which the library was hiding from you

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube