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
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs PWM [micro:bit]
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: jc2048
  • Date Created: 22 Sep 2016 10:20 PM Date Created
  • Views 1236 views
  • Likes 3 likes
  • Comments 1 comment
  • micro:bit
  • big ideas
Related
Recommended

PWM [micro:bit]

jc2048
jc2048
22 Sep 2016

I was curious as to whether I could use the micro:bit to generate PWM [pulse-width modulation] signals. At first I thought

I'd have to find out how to control the processor's internal peripherals but it turned out that there was no need. Even

the block language has instructions to do PWM on the output pins, though it's disguised by calling it an 'analog write'

operation.

 

Here's a very simple program to set P0 to do PWM.

 

 

image

 

It works too. Here's what the oscilloscope sees as the waveform.

 

 

image

 

First problem, though, is that I asked for 256 microseconds as the period and it has given me 20mS. I'm obviously not too hot at this coding stuff.

 

Here's the single interval that the 'analog write' asks for in greater detail:

 

image

 

 

 

This is 23uS, which is about an 870th of the period. I suspect there's something here, too, that I'm not understanding.

 

Finally, here's the single interval with the oscilloscope's persistance set to infinity so that it accumulates multiple

pulses all overlaying each other.

 

image

 

You can immediately see why that's always a good test to do with any pulse generation.

 

Here the single pulse is most often 23uS, but just occasionally it extends to between 100uS and 120uS. That's very

characteristic of a software interrupt doing what interrupts do - interrupting.

  • Sign in to reply
  • jc2048
    jc2048 over 9 years ago

    Further to the experiment above, here's code that steps through 1 to 5 intervals.

     

    image

     

    From the accumulated scope trace, you can see that the interval is actually 20uS [most of the time] and there's a extra 3uS setup on the first one. Programmer's Wonky Modulation?

     

    image

    • 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