element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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
The World in Motion
  • Challenges & Projects
  • Project14
  • The World in Motion
  • More
  • Cancel
The World in Motion
Blog Pulse Width Modulation a Speed Equalizer(4): Theory at the bench
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join The World in Motion to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: colporteur
  • Date Created: 30 Jul 2022 9:12 PM Date Created
  • Views 1477 views
  • Likes 8 likes
  • Comments 6 comments
  • motor projects
  • worldinmotionch
  • pwm
Related
Recommended

Pulse Width Modulation a Speed Equalizer(4): Theory at the bench

colporteur
colporteur
30 Jul 2022

The third blog installment for this challenge presented the theory for pulse width modulation. The post talked about the concept of duty cycle and provided static waveform drawings to reinforce the concept. This post further enforces the PWM theory by providing a bench demonstration of the operation using some basic Arduino code and an oscilloscope.

The L298N driver library for the Arduino supports a method of setting the speed of a motor.
The speed range is from 0 to 255.

  // Change speed
  motor.setSpeed(45);

Three different speed values were tested 45, 127 & 254. An oscilloscope sample was taken at each value.

The oscilloscope was attached to the Arduino output that produces the PWM signal to the L298N module.

As the value in the code changed so did the width of the pulse change as seen on the oscilloscope. As the value in the code changed so did the duty cycle of the waveform change. As the value in the code changed so does the motor speed change.

{gallery}Oscilloscope PWM Outputs

image

setSpeed(45): 17% duty cycle

image

setSpeed(127): 49% duty cycle

image

setSpeed(254): 99% duty cycle

 

The value of 45 in the code was the first entry that resulted in any movement for the motor. The value of 127 is half of the maximum value of 255. The value of 254 is the maximum that could be set and the oscilloscope still displays the waveform. This testing was done with a 12VDC motor. The code value to establish the required train speed will need to be determined on the track.

Well, that completes the bench work. I'm reasonably confident I have everything that I need to now start testing with a locomotive.

  • Sign in to reply
  • colporteur
    colporteur over 2 years ago in reply to DAB

    I agree! After today's tests I have some obstacles to overcome. Details in blog post 5.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 2 years ago

    Introducing new technology always leads to function creep.

    Just keep to your original build until you have it working.

    Then you can sit down and assess all of the other potentials and determine which are worth the time and effort to implement.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • colporteur
    colporteur over 2 years ago in reply to fmilburn

    I'm not sure customizing a locomotive motor is applicable for this group. I continue to run into "that is not the way we do it". The approach that has been successful is making changes that are non-intrusive. The focus is how to modify the layout and not the train stuff. It starts with a switch that returns the layout to manual control or enables the automatic sequence. The sequence part has created some challenges as the electronics I introduce can create problems if not isolated effectively.

    Keep the suggestion coming. I like thinking through them to find something applicable.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fmilburn
    fmilburn over 2 years ago in reply to colporteur

    Encoders like those in the link that Shabaz provided combined with feedback such as PID control give excellent speed control even with changing loads and other circumstances. There is an excellent Arduino PID library if that sort of thing is important to your project. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • colporteur
    colporteur over 2 years ago in reply to shabaz

    The more I invest in this project the more it suffers from scope creep.

    This was one of those "yeah I think I can do that" offers that morphed into much more. The code written so far is not pretty. It works but really could use someone with programming skills to streamline it. If I was to do it again (I'm thinking about it), I would use a Raspberry Pi as the controller. I would feel more comfortable working in python rather than in Arduino code.

    I wish there was someone in my area that had a similar interest. I'm responsible for all the tasks and don't have anyone to delegate to. The more options I include the more I have to discover "so how the H E double hockey sticks am I going to do that!"

    Thanks for the link. Always like to explore possibilities.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
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