Let’s walk through an example of outputting a 1 MHz square wave on pin PA18. We can connect and configure different peripherals in many, many different ways (thanks to all this multiplexing of clock signals!). While this might seem extremely complicated, the upside is that the SAMD21 is an extremely powerful chip. Once we have our peripheral configured (TCC, in this case), we then want to connect that to a hardware pin so that we get an actual waveform to appear. The SAMD21 also has a Timer/Counter peripheral (TC), but from what I could grasp, it’s “TCC lite” (i.e. In the example below, we’ll be using the Timer/Counter for Control Applications (TCC). Then, we connect our generator to the peripheral we want. We can configure each generator to have its own divider and mask (so that we can run various peripherals off different speeds thanks to having separate clock generators). The SAMD21 has 9 different generators we can use. The basic idea is to select a clock source from SYSCTRL (such as the 48 MHz system clock) and connect it to a Generic Clock Generator. To configure a pin for PWM requires a good bit of effort. The best description I can find for how this works is from section 14.3 (page 95) in the datasheet: If you think I missed something or got something wrong, please let me know in the comments! ![]() Please note that I am just beginning to understand how the SAMD21 works, and this article is simply a chronicle of my learning journey. In reality, it requires a good amount of code to perform this simple action. On the surface, it’s not too bad: you just need to set some values in some registers to get a pin to output a square wave. I’ve spent the last few days digging through the SAMD21 datasheet and online examples to get some insight into using CMSIS. Here’s the problem: when it comes to manually configuring registers for 32-bit ARM microcontrollers, it’s vastly more difficult than it is for most other 8- or 16-bit architectures. Not that there is anything wrong with ASF, I just like to learn about the low-level stuff. If you’re like me, you want to know what’s going on at the register level. Many professional developers swear by the vendor-provided abstraction layer (e.g. Microchip’s abstraction layer is known as the Advanced Software Framework (ASF). ![]() In some cases, this can make setting up registers easy (especially if there is a slick GUI program that generates code for you, like STMicro’s STM32CubeMX). Some vendors have decided to include their own abstraction layer on top of CMSIS to help people configure and use their parts. Ideally, you should be able to use CMSIS regardless of the manufacturer of the chip (e.g. This is a set of firmware libraries that provide an interface to the registers along with some other functions. Almost all modern implementations of the ARM Cortex architectures can use the Cortex Microcontroller Software Interface Standard (CMSIS). For the average user, this is not a bad thing, considering it hides all the ugliness (or beauty, depending on your perspective) of manually setting registers.įor those of us that want to dig deeper into the SAMD21, there are a few options. Arduino has a habit of making pulse width modulation (PWM) pins with a set frequency (or limited frequency options).
0 Comments
Leave a Reply. |