![]() ![]() Thus for integer dividers, the highest frequency we can pass in is 42 MHz (with divider 2). If you take a look at the function PWMC_ConfigureClocks in pwmc.c, you will see that the highest PWM frequency can be accommodated as the function input is 42 MHz, this is because inside the function it calls FindClockConfiguration which in turn ensures that the frequency parameter passed in is less than the MCK frequency. The hardware PWM related functions are in /arduino-1.5.7/hardware/arduino/sam/system/libsam/source/pwmc.c, and the power management controller code are in /arduino-1.5.7/hardware/arduino/sam/system/libsam/source/pmc.c. ![]() Since the master clock (MCK) frequency is derived as (MUL+1)/DIV multiplied by the PLL frequency the result of the master clock frequency is 12*(13+1)/2=84 Mhz. SYS_BOARD_PLLAR defines the PLLA clock with a multiplier of 0xd (13). #define SYS_BOARD_MCKR (PMC_MCKR_PRES_CLK_2 | PMC_MCKR_CSS_PLLA_CLK) #define SYS_BOARD_PLLAR (CKGR_PLLAR_ONE \ In /arduino-1.5.7/hardware/arduino/sam/system/CMSIS/Device/ATMEL/sam3xa/source/system_sam3xa.c you will find the following definitions: They source code and binaries are located under /arduino-1.5.7/hardware/arduino/sam/system/ with the Arduino IDE distribution. Under the hood, Arduino IDE uses Atmel’s CMSIS compliant libraries. But before doing that, let’s take a look at how the the 84 Mhz clock frequency is obtained on the Due. via PWM controller) to generate our waveform rather than big-banging with software. We can do even better if we use the dedicated hardware (e.g. G_APinDescription.pPort -> PIO_CODR = g_APinDescription.ulPin G_APinDescription.pPort -> PIO_SODR = g_APinDescription.ulPin This is a huge improvement over the meager 200.7 kHz with digitalWrite. If we replace the digitalWrite with the following code, we will get an output square wave on pin 8 of roughly 16.8 Mhz. Of course, we can improve the code efficiency above quite a bit by using direct port manipulation. If the while loop is removed, the output frequency will drop to 145.4 kHz which is a 30% degradation from 200.7 kHz! But on Arduino Due, this difference is much more drastic. ![]() This overhead is not very noticeable on ATmega328p (116.9 kHz without the while loop versus 126.2 kHz with the loop). So if we did not use the while loop, extra instructions would be executed after outputting a LOW, causing the duty cycle to change and lowering the overall waveform frequency. By the way, the reason a while loop is used inside the loop() function is that the loop function has some extra instructions for checking the serial port. The Arduino code base is not very efficient and this code is actually not much faster than the same code on an ATmega328p (126.2 kHz for comparison, compiled with Arduino 1.0.5). For example, the following code on Due generates a 200.7 kHz square wave on pin 8 (compiled with Arduino 1.5.7): pin toggling), the highest achievable output frequency is actually quite abysmal. For an ATmega328p, the highest achievable PWM frequency is 8Mhz (square wave), so we should be able to generate much higher frequency signals on an Arduino Due. The processor core runs at 84 MHz, which is significantly faster than its 8-bit AVR counterpart ATmega328p which runs at 16 MHz. Arduino Due is based on Atmel’s ATSAM3x8E 32-bit ARM Cortext-M3 processor. While they were released almost two years ago, I have not really got a chance to look at these until quite recently. I just got myself a couple of Arduino Due boards. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |