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 Arduino Zero / Adafruit Feather M0 - PWM Outputs
  • 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
  • State Verified Answer
  • Replies 7 replies
  • Answers 5 answers
  • Subscribers 391 subscribers
  • Views 1722 views
  • Users 0 members are here
  • atsamd21
  • arduino zero
  • feather m0
  • adafruit
Related

Arduino Zero / Adafruit Feather M0 - PWM Outputs

wallarug
wallarug over 6 years ago

Hi Arduino Community!

 

I am having an issue finding documentation that says what pins on the ATSAMD21G18 are PWM enabled.  The adafruit documentation says that only 7 pins have Pulse Width Modulation support while the Ardunio documentation says that all pins except 0, 1, 2 and 7 can do PWM.

 

I am looking for a third opinion on the topic from the community as you may have the knowledge / experience with this microprocessor.

 

 

Check out the Adafruit Documentation Here:

 

https://learn.adafruit.com/adafruit-feather-m0-adalogger/pinouts

 

 

This documentation states that 'most pins are pwm enabled'.  In the diagram it indicates that only 7 pins are pwm enabled. 

 

 

Could some please confirm with me which pins are pwm enabled for the board?

 

 

Thank you!!!

  • Sign in to reply
  • Cancel

Top Replies

  • fmilburn
    fmilburn over 6 years ago +7 verified
    Hi wallarug , This can be confusing. A good place to start is the datasheet which Adafruit has linked to at the top of the Downloads section of your link. Note that Adafruit is using the G variant (SAM…
  • fmilburn
    fmilburn over 6 years ago in reply to wallarug +3 suggested
    Good catch. What I stated above is factually correct but I read your question wrong / had a brain lapse and have misled you. I wish they wouldn't call PWM analogWrite. PWM is really about setting up the…
  • wallarug
    wallarug over 6 years ago in reply to fmilburn +2
    Hi Frank, Thank you for your very informative and helpful response. Just to confirm one final point... from the datasheet, the function to look for to indicate that the pin is PWM capable is ADC. From…
Parents
  • fmilburn
    0 fmilburn over 6 years ago

    Hi wallarug,

     

    This can be confusing.  A good place to start is the datasheet which Adafruit has linked to at the top of the Downloads section of your link.  Note that Adafruit is using the G variant (SAM D21G).  In the configuration summary on page 3 the datasheet states that there are 14 ADC channels.  Paging down to the pinout description on Page 15 the 14 ADC channels are shown next to their physical pins on the microcontroller along with the port / pin designation.  For example, physical pin 3 is connected to PA02.

     

    The pins can be multiplexed, i.e. assigned to different peripheral functions.  These capabilities are described in Section 10 which starts on Page 21.  Using physical pin 3 again as an example, we see it can be configured among other things as ADC AIN(0) using the Atmel nomenclature.  Note that not all of the ADC configurations are available for the G variant.

     

    So, now the capabilities are known, but it is necessary to look at what pins Adafruit (or Arduino) has brought out on their board for use and how they mapped it to the Arduino IDE.  Returning to the pinout map in your link.  Look for physical pin 3 again in the dark grey box nearest the representation of the board.  Note that it is labeled A0 on the board.  Next to the physical pin 3 box is an olive colored one that has PA02 in it - the same as in the datasheet.  We also see the other configurations from the datasheet.  In the furthest most box we see '14' and 'A0'.  The legend for the pinout tells us that these are the Arduino IDE designations.

     

    Adafruit has somewhat arbitrarily decided to bring PA02, located on physical pin 3 of the SAMD21G, and call it A0.  I count 7 pins which Adafruit has brought out and labeled as PWM on the pinout.  You can go through the same exercise with the Arduino Zero. 

     

    Frank

    • Cancel
    • Vote Up +7 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • wallarug
    0 wallarug over 6 years ago in reply to fmilburn

    Hi Frank,

     

    Thank you for your very informative and helpful response.

     

    Just to confirm one final point... from the datasheet, the function to look for to indicate that the pin is PWM capable is ADC.

     

    From the datasheet it appears that the following pins on the SAM D21G have this capability (if you had access to all pins):

     

    PhysicalI/O Pin
    3PA02
    4PA03
    7PB08
    8PB09
    9PA04
    10PA05
    11PA06
    12PA07
    13PA08
    14PA09
    15PA10
    16PA11
    47PB02
    48PB03

     

    Thank you very much for guiding me through this process. 

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • fmilburn
    0 fmilburn over 6 years ago in reply to wallarug

    Good catch.  What I stated above is factually correct but I read your question wrong / had a brain lapse and have misled you.  I wish they wouldn't call PWM analogWrite.  PWM is really about setting up the output from timers and is not analog.  It is possible of course to have PWM without any ADC capability.  Arduino uses the tilde (~) to designate PWM.  I am not really an Arduino user, have only just started using the Arduino MKR boards, and have not used the Adafruit.  Look on your board for the tilde and that is where you have PWM.  Those are the pins that they decided to map to the timers.  It is still a good idea to get familiar with the datasheet.  The timers are very flexible and powerful if used outside the Arduino IDE.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • fmilburn
    0 fmilburn over 6 years ago in reply to wallarug

    Also, the timer counters start with TC in the table and the discussion starts in section 29 on page 610!  I need to get more familiar with this microcontroller.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • fmilburn
    0 fmilburn over 6 years ago in reply to wallarug

    Also, the timer counters start with TC in the table and the discussion starts in section 29 on page 610!  I need to get more familiar with this microcontroller.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
  • wallarug
    0 wallarug over 6 years ago in reply to fmilburn

    I believe your new information invalidates some of the pins in this list above.  Do does this mean that more of the pins are capable of PWM than my list above?

     

    I guess an easier way of putting it is this... is the diagram on this website correct based on your knowledge of the datasheet?

     

    I'm still a bit bamboozled.   image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • fmilburn
    0 fmilburn over 6 years ago in reply to wallarug

    wallarug  wrote:

     

    I guess an easier way of putting it is this... is the diagram on this website correct based on your knowledge of the datasheet?

     

    I'm still a bit bamboozled.   image

    I am still learning this microcontroller myself and don't have the Adafruit board.  The honest answer is I don't know whether it is right or not for the Adafruit board.  One way to find out is to write a short sketch that tries to apply PWM to each pin you want to test and put a LED on it and see if it dims.

     

    It is worth remembering that Arduino purposely abstracts all this detail away to make it simple to use.  Once we need greater access to the capability that is hidden by the abstractions it is sometimes easier to use a more professional IDE from a clean slate and access the registers directly.

     

    Looking at the datasheet again, we find this snippet in the features that covers timers:

    image

    I take this to mean that there are three 24-bit timer/counters set up for explicit control of PWM which Atmel calls Timer/Counters for Control (TCC).  They are labeled TCC in column F of the multiplexing table.  Looking at this table and what pins are brought out would tell us where Adafruit could have chosen to use these timer/counters to control PWM.  You might try looking for the variant.cpp file for your board.

     

    PWM is pretty simple, if maybe somewhat tedious, to set using registers.  Basically choose a pin connected to a timer/counter and set up a clock to the timer/counter.  Set the registers for how long the pin is high and how long it is low.  Twiddle other bits as needed.  This is all done in hardware without interruption to the microcontroller.  But we could do it without that hardware support.  We could use any timer and set it to interrupt after say a certain interval high.  In the interrupt flip the pin low and set the time for the next interval.  Then flip the pin again and reset the interval.  Repeat over and over.  In this way, any GPIO could be used for PWM.  It may be possible to do either of these approaches within the Arduino IDE but I don't know what conflicts it might introduce.

     

    I know this can be confusing but hopefully helps.  If you test the pins as described above I would be interested in what you find.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • 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