- Notifications
You must be signed in to change notification settings - Fork3
This library enables you to use Hardware-based PWM channels on SAMD21/SAMD51-based boards to create and output PWM to pins. Using the same functions as other FastPWM libraries to enable you to port PWM code easily between platforms.
License
khoih-prog/SAMD_PWM
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
- Why do we need this SAMD_PWM library
- Changelog
- Prerequisites
- Installation
- Packages' Patches
- Usage
- Examples
- Example PWM_Multi
- Debug Terminal Output Samples
- Debug
- Troubleshooting
- Issues
- TO DO
- DONE
- Contributions and Thanks
- Contributing
- License
- Copyright
Why do we need thisSAMD_PWM library
This hardware-based PWM library enables you to use Hardware-PWM onSAMD21/SAMD51 boards such asNANO_33_IOT,ITSYBITSY_M4,SEEED_XIAO_M0,SparkFun SAMD51_Thing_Plus, etc., to create and output PWM. These purely hardware-based PWM channels can generate very high PWM frequencies, depending on CPU clock and acceptable accuracy. The maximum resolution can be16-bit for better accuracy when using TimerTCCx. With TimerTCx, only8-bit resolution is supported with lower accuracy.
This library is using thesame or similar functions as otherFastPWM sibling libraries, as follows, to enable you toport your PWM code easily between platforms
- RP2040_PWM
- AVR_PWM
- megaAVR_PWM
- ESP32_FastPWM
- SAMD_PWM
- SAMDUE_PWM
- nRF52_PWM
- Teensy_PWM
- ATtiny_PWM
- Dx_PWM
- Portenta_H7_PWM
- MBED_RP2040_PWM
- nRF52_MBED_PWM
- STM32_PWM
The most important feature is they're purely hardware-based PWM channels. Therefore, their operations arenot blocked by bad-behaving software functions / tasks.
This important feature is absolutely necessary for mission-critical tasks. These hardware PWM-channels, still work even if other software functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers usingmillis() ormicros(). That's necessary if you need to control external systems (Servo, etc.) requiring better accuracy.
New efficientsetPWM_manual() function enables waveform creation using PWM.
ThePWM_Multi example will demonstrate the usage of multichannel PWM using multiple Hardware-PWM blocks (Timer & Channel). The 4 independent Hardware-PWM channels are usedto control 4 different PWM outputs, with totally independent frequencies and dutycycles onSAMD21/SAMD51.
Being hardware-based PWM, their executions are not blocked by bad-behaving functions / tasks, such as connecting to WiFi, Internet or Blynk services.
This non-being-blocked important feature is absolutely necessary for mission-critical tasks.
Imagine you have a system with amission-critical function, controlling a robot or doing something much more important. You normally use a software timer to poll, or even place the function inloop(). But what if another function isblocking theloop() orsetup().
So your functionmight not be executed, and the result would be disastrous.
You'd prefer to have your function called, no matter what happening with other functions (busy loop, bug, etc.).
The correct choice is to usehardware-based PWM.
These hardware-based PWM channels still work even if other software functions are blocking. Moreover, they are much moreprecise (certainly depending on clock frequency accuracy) than other software-based PWMs, usingmillis() ormicros().
Functions using normal software-based PWMs, relying onloop() and callingmillis(), won't work if theloop() orsetup() is blocked by certain operation. For example, certain function is blocking while it's connecting to WiFi or some services.
- Arduino SAMD21 (ZERO, MKR, NANO_33_IOT, etc.).
- Adafruit SAM21 (Itsy-Bitsy M0, Metro M0, Feather M0, Gemma M0, etc.).
- Adafruit SAM51 (Itsy-Bitsy M4, Metro M4, Grand Central M4, Feather M4 Express, etc.).
- Seeeduino SAMD21/SAMD51 boards (SEEED_WIO_TERMINAL, SEEED_FEMTO_M0, SEEED_XIAO_M0, Wio_Lite_MG126, WIO_GPS_BOARD, SEEEDUINO_ZERO, SEEEDUINO_LORAWAN, SEEED_GROVE_UI_WIRELESS, etc.)
- Sparkfun SAMD21 boards such asSparkFun_RedBoard_Turbo, SparkFun_Qwiic_Micro, etc.
- Sparkfun SAMD51 boards such asSparkFun_SAMD51_Thing_Plus, SparkFun_SAMD51_MicroMod, etc.
Arduino IDE 1.8.19+for Arduino.Arduino SAMD core 1.8.13+for SAMD ARM Cortex-M0+ boards.Adafruit SAMD core 1.7.11+for SAMD ARM Cortex-M0+ and M4 boards (Nano 33 IoT, etc.).Seeeduino SAMD core 1.8.3+for SAMD21/SAMD51 boards (XIAO M0, Wio Terminal, etc.).Sparkfun SAMD core 1.8.3+for SAMD21/SAMD51 boards (SparkFun_RedBoard_Turbo, SparkFun_SAMD51_Thing_Plus, etc.)- Industruino SAMD core for SAMD21/SAMD51 boards
The best and easiest way is to useArduino Library Manager. Search forSAMD_PWM, then select / install the latest version.You can also use this link for more detailed instructions.
Another way to install is to:
- Navigate toSAMD_PWM page.
- Download the latest release
SAMD_PWM-main.zip. - Extract the zip file to
SAMD_PWM-maindirectory - Copy whole
SAMD_PWM-mainfolder to Arduino libraries' directory such as~/Arduino/libraries/.
- InstallVS Code
- InstallPlatformIO
- InstallSAMD_PWM library by usingLibrary Manager. Search forSAMD_PWM inPlatform.io Author's Libraries
- Use includedplatformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples atProject Configuration File
To be able to compile without error and automatically detect and display BOARD_NAME on Arduino SAMD (Nano-33-IoT, etc) boards, you have to copy the wholeArduino SAMD Packages_Patches directory into Arduino SAMD directory (~/.arduino15/packages/arduino/hardware/samd/1.8.13).
Supposing the Arduino SAMD version is 1.8.13. Now only one file must be copied into the directory:
~/.arduino15/packages/arduino/hardware/samd/1.8.13/platform.txt
Whenever a new version is installed, remember to copy this files into the new version directory. For example, new version is x.yy.zz
This file must be copied into the directory:
~/.arduino15/packages/arduino/hardware/samd/x.yy.zz/platform.txt
Supposing the Arduino SAMD version is 1.8.9. These files must be copied into the directory:
~/.arduino15/packages/arduino/hardware/samd/1.8.9/platform.txt~/.arduino15/packages/arduino/hardware/samd/1.8.9/cores/arduino/Arduino.h
Whenever a new version is installed, remember to copy these files into the new version directory. For example, new version is x.yy.z
These files must be copied into the directory:
~/.arduino15/packages/arduino/hardware/samd/x.yy.z/platform.txt~/.arduino15/packages/arduino/hardware/samd/x.yy.z/cores/arduino/Arduino.h
This is mandatory to fix thenotorious Arduino SAMD compiler error. SeeImprove Arduino compatibility with the STL (min and max macro)
...\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2 min(const _Tp& __a, const _Tp& __b, _Compare __comp)Whenever the above-mentioned compiler error issue is fixed with the new Arduino SAMD release, you don't need to copy theArduino.h file anymore.
To be able to compile without error and automatically detect and display BOARD_NAME on Adafruit SAMD (Itsy-Bitsy M4, etc) boards, you have to copy the files inAdafruit SAMD Packages_Patches into Adafruit samd directory (~/.arduino15/packages/adafruit/hardware/samd/1.7.11).
Supposing the Adafruit SAMD core version is 1.7.11. This file must be copied into the directory:
~/.arduino15/packages/adafruit/hardware/samd/1.7.11/platform.txt~/.arduino15/packages/adafruit/hardware/samd/1.7.11/cores/arduino/Print.h~/.arduino15/packages/adafruit/hardware/samd/1.7.11/cores/arduino/Print.cpp
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zzThis file must be copied into the directory:
~/.arduino15/packages/adafruit/hardware/samd/x.yy.zz/platform.txt~/.arduino15/packages/adafruit/hardware/samd/x.yy.zz/cores/arduino/Print.h~/.arduino15/packages/adafruit/hardware/samd/x.yy.zz/cores/arduino/Print.cpp
To be able to compile without error and automatically detect and display BOARD_NAME on Seeeduino SAMD (XIAO M0, Wio Terminal, etc) boards, you have to copy the files inSeeeduino SAMD Packages_Patches into Seeeduino samd directory (~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3).
Supposing the Seeeduino SAMD core version is 1.8.3. This file must be copied into the directory:
~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3/platform.txt~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3/cores/arduino/Arduino.h~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3/cores/arduino/Print.h~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3/cores/arduino/Print.cpp
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zzThis file must be copied into the directory:
~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/platform.txt~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/cores/arduino/Arduino.h~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/cores/arduino/Print.h~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/cores/arduino/Print.cpp
To be able to compile without error and automatically detect and display BOARD_NAME on SparkFun SAMD (XIAO SparkFun_RedBoard_Turbo, SparkFun_SAMD51_Thing_Plus, etc) boards, you have to copy the fileSparkFun SAMD Packages_Patches into SparkFun samd directory (~/.arduino15/packages/SparkFun/hardware/samd/1.8.3).
Supposing the SparkFun SAMD core version is 1.8.3. This file must be copied into the directory:
~/.arduino15/packages/SparkFun/hardware/samd/1.8.3/cores/arduino/Print.h~/.arduino15/packages/SparkFun/hardware/samd/1.8.3/cores/arduino/Print.cpp~/.arduino15/packages/SparkFun/hardware/samd/1.8.3/cores/arduino51/Print.h~/.arduino15/packages/SparkFun/hardware/samd/1.8.3/cores/arduino51/Print.cpp
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zzThis file must be copied into the directory:
~/.arduino15/packages/SparkFun/hardware/samd/x.yy.zz/cores/arduino/Print.h~/.arduino15/packages/SparkFun/hardware/samd/x.yy.zz/cores/arduino/Print.cpp~/.arduino15/packages/SparkFun/hardware/samd/x.yy.zz/cores/arduino51/Print.h~/.arduino15/packages/SparkFun/hardware/samd/x.yy.zz/cores/arduino51/Print.cpp
Before using any PWMTimer andchannel, you have to make sure theTimer andchannel has not been used by any other purpose.
// Not OK for Nano_33_IoT (0, 1, 7, 8, 13, 14, 15 )// OK for Nano_33_IoT (2, 3, 4, 5, 6, 9, 10, 11, 12, 16, 17)// TCC OK => pin 4, 5, 6, 8, 9, 10, 11, 16/A2, 17/A3// TC OK => pin 12// For ITSYBITSY_M4// 16-bit Higher accuracy, Lower Frequency, PWM Pin OK: TCCx: 0-2, 4, 5, 7, 9-13// 8-bit Lower accuracy, Hi Frequency, PWM Pin OK: TCx: 18-20, 24-25
1. Create PWM Instance with Pin, Frequency, dutycycle, channel (default = 0) and PWM_resolution (default = 16)
SAMD_PWM* PWM_Instance;PWM_Instance =new SAMD_PWM(pinToUse, frequency, dutyCycle, channel, PWM_resolution);if (PWM_Instance){ PWM_Instance->setPWM();}
To usefloat new_dutyCycle
PWM_Instance->setPWM(PWM_Pins, new_frequency, new_dutyCycle);such as
dutyCycle =10.0f; Serial.print(F("Change PWM DutyCycle to")); Serial.println(dutyCycle);PWM_Instance->setPWM(pinToUse, frequency, dutyCycle);
To useuint32_t new_dutyCycle =(real_dutyCycle * 65536) / 100
PWM_Instance->setPWM_Int(PWM_Pins, new_frequency, new_dutyCycle);such as forreal_dutyCycle = 50%
// 50% dutyCycle = (real_dutyCycle * 65536) / 100dutyCycle =32768;Serial.print(F("Change PWM DutyCycle to (%)"));Serial.println((float) dutyCycle *100 /65536);PWM_Instance->setPWM_Int(pinToUse, frequency, dutyCycle);
forreal_dutyCycle = 50%
// 20% dutyCycle = (real_dutyCycle * 65536) / 100dutyCycle =13107;Serial.print(F("Change PWM DutyCycle to (%)"));Serial.println((float) dutyCycle *100 /65536);PWM_Instance->setPWM_Int(pinToUse, frequency, dutyCycle);
Function prototype
// Must have same frequency// From v1.0.1-, DCValue = 0-100// From v1.2.0+, DCValue = 0-65535boolsetPWM_manual(constuint8_t& pin,constuint16_t& dutyCycle);// DCPercentage from 0.0f - 100.0fboolsetPWM_DCPercentage_manual(constuint8_t& pin,constfloat& DCPercentage);// DCPercentage from 0-65535 for 0.0f - 100.0fboolsetPWM_DCPercentageInt_manual(constuint8_t& pin,constuint16_t& DCPercentage);
Need to call only once for each pin
PWM_Instance->setPWM(PWM_Pins, frequency, dutyCycle);after that, if just changingdutyCycle /level, use thefaster
// dutycycle = 0-65535 for 0-100%// 1084 nsPWM_Instance->setPWM_manual(pinToUse, dutycycle);
or better and much easier to use, butslowest
// 1259 nsnew_DCPercentage =50.0f;PWM_Instance->setPWM_DCPercentage_manual(pinToUse, new_DCPercentage);
or thefastest
// dutycyclePercent = 0-65535 == 0-100%// 1067 nsdutycyclePercentInt =1 <<15;// 50%PWM_Instance->setPWM_DCPercentageInt_manual(pinToUse, dutycyclePercentInt);
Don't use the extremely inefficientsetPWM() for this purpose
// Very inefficient, don't use => 499251 ns, 500-time slower//PWM_Instance->setPWM(pinToUse, frequency, dutycyclePercent);
- PWM_Basic
- PWM_DynamicDutyCycle
- PWM_DynamicDutyCycle_Int
- PWM_DynamicFreq
- PWM_Multi
- PWM_MultiChannel
- PWM_Waveform
- PWM_StepperControlNew
- PWM_manualNew
- PWM_SpeedTestNew
ExamplePWM_Multi
SAMD_PWM/examples/PWM_Multi/PWM_Multi.ino
Lines 11 to 112 inaec5386
| #define_PWM_LOGLEVEL_4 | |
| #include"SAMD_PWM.h" | |
| // Not OK for Nano_33_IoT (0, 1, 7, 8, 13, 14, 15 ) | |
| // OK for Nano_33_IoT (2, 3, 4, 5, 6, 9, 10, 11, 12, 16, 17) | |
| // TCC OK => pin 4, 5, 6, 8, 9, 10, 11, 16/A2, 17/A3 | |
| // TC OK => pin 12 | |
| // For ITSYBITSY_M4 | |
| // 16-bit Higher accuracy, Lower Frequency, PWM Pin OK: TCCx: 0-2, 4, 5, 7, 9-13 | |
| // 8-bit Lower accuracy, Hi Frequency, PWM Pin OK: TCx: 18-20, 24-25 | |
| // Change to use the correct PWM pins from different TCx or TCCx, according to your boards | |
| #if defined(__SAMD51__) | |
| // Pin 5:TCC2_CH1, pin 7: TCC1_CH2, pin 11: TCC0_CH1, pin 25/MOSI: TC2_CH0 | |
| uint32_t PWM_Pins[] = {5,7,11,25 }; | |
| #else | |
| // pin 4: TCC1_CH1, Pin 5:TCC0_CH1, pin 11: TCC2_CH0, pin 12: TC3_CH1 | |
| uint32_t PWM_Pins[] = {4,5,11,12 }; | |
| #endif | |
| #defineNUM_OF_PINS (sizeof(PWM_Pins) /sizeof(uint32_t) ) | |
| float dutyCycle[] = {10.0f,30.0f,50.0f,90.0f }; | |
| float frequency[] = {2000.0f,3000.0f,4000.0f,8000.0f }; | |
| SAMD_PWM* PWM_Instance[NUM_OF_PINS]; | |
| char dashLine[] ="====================================================================================="; | |
| voidprintPWMInfo(SAMD_PWM* PWM_Instance) | |
| { | |
| Serial.println(dashLine); | |
| Serial.print("Actual data: pin ="); | |
| Serial.print(PWM_Instance->getPin()); | |
| Serial.print(", PWM DC ="); | |
| Serial.print(PWM_Instance->getActualDutyCycle()); | |
| Serial.print(", PWMPeriod ="); | |
| Serial.print(PWM_Instance->getPWMPeriod()); | |
| Serial.print(", PWM Freq (Hz) ="); | |
| Serial.println(PWM_Instance->getActualFreq(),4); | |
| Serial.println(dashLine); | |
| } | |
| voidsetup() | |
| { | |
| Serial.begin(115200); | |
| while (!Serial &&millis() <5000); | |
| delay(500); | |
| Serial.print(F("\nStarting PWM_Multi on")); | |
| Serial.println(BOARD_NAME); | |
| Serial.println(SAMD_PWM_VERSION); | |
| for (uint8_t index =0; index < NUM_OF_PINS; index++) | |
| { | |
| PWM_Instance[index] =newSAMD_PWM(PWM_Pins[index], frequency[index], dutyCycle[index]); | |
| if (PWM_Instance[index]) | |
| { | |
| PWM_Instance[index]->setPWM(); | |
| } | |
| } | |
| Serial.println(dashLine); | |
| Serial.println("Index\tPin\tPWM_freq\tDutyCycle\tActual Freq"); | |
| Serial.println(dashLine); | |
| for (uint8_t index =0; index < NUM_OF_PINS; index++) | |
| { | |
| if (PWM_Instance[index]) | |
| { | |
| Serial.print(index); | |
| Serial.print("\t"); | |
| Serial.print(PWM_Pins[index]); | |
| Serial.print("\t"); | |
| Serial.print(frequency[index]); | |
| Serial.print("\t\t"); | |
| Serial.print(dutyCycle[index]); | |
| Serial.print("\t\t"); | |
| Serial.println(PWM_Instance[index]->getActualFreq(),4); | |
| } | |
| else | |
| { | |
| Serial.println(); | |
| } | |
| } | |
| for (uint8_t index =0; index < NUM_OF_PINS; index++) | |
| { | |
| printPWMInfo(PWM_Instance[index]); | |
| } | |
| } | |
| voidloop() | |
| { | |
| //Long delay has no effect on the operation of hardware-based PWM channels | |
| delay(1000000); | |
| } |
The following is the sample terminal output when running examplePWM_DynamicDutyCycle onSAMD21 SAMD_NANO_33_IOT, to demonstrate the ability to provide high PWM frequencies and ability to change DutyCycleon-the-fly usingTCC timer for 16-bit PWM
Starting PWM_DynamicDutyCycle on SAMD_NANO_33_IOTSAMD_PWM v1.0.1[PWM] calcTCCPrescaler: OK pin =11 , period =200 , _prescaler =1 , F_CPU =48000000[PWM] calcTCCPrescaler: _dutycycle =32768 , frequency =5000.00 , _prescalerConfigBits =0 , _compareValue =9599[PWM] SAMD21 setPWM_Int: _tcNum =2 , _tcChannel =0 , _pinAttr =28[PWM] SAMD21 setPWM_Int: newDC =4799 , input dutycycle =32768 , _compareValue =9599 , frequency =5000.00[PWM] SAMD21 setPWM_Int: New TCC => newDC =4799 , input dutycycle =32768 , frequency =5000.00=====================================================================================Change PWM DutyCycle to90.00[PWM] setPWM: _dutycycle =58982 , frequency =5000.00[PWM] SAMD21 setPWM_Int: _tcNum =2 , _tcChannel =0 , _pinAttr =28[PWM] SAMD21 setPWM_Int: newDC =8639 , input dutycycle =58982 , _compareValue =9599 , frequency =5000.00[PWM] SAMD21 setPWM_Int: Old TCC => newDC =8639 , input dutycycle =58982 , frequency =5000.00=====================================================================================Actual data: pin =11, PWM DC =90.00, PWMPeriod =200.00, PWMFreq (Hz) = 5000.0000=====================================================================================Change PWM DutyCycle to 20.00[PWM] setPWM: _dutycycle = 13107 , frequency = 5000.00[PWM] SAMD21 setPWM_Int: _tcNum = 2 , _tcChannel = 0 , _pinAttr = 28[PWM] SAMD21 setPWM_Int: newDC = 1919 , input dutycycle = 13107 , _compareValue = 9599 , frequency = 5000.00[PWM] SAMD21 setPWM_Int: Old TCC => newDC = 1919 , input dutycycle = 13107 , frequency = 5000.00=====================================================================================Actual data: pin = 11, PWM DC = 20.00, PWMPeriod = 200.00, PWM Freq (Hz) = 5000.0000=====================================================================================Change PWM DutyCycle to 90.00[PWM] setPWM: _dutycycle = 58982 , frequency = 5000.00[PWM] SAMD21 setPWM_Int: _tcNum = 2 , _tcChannel = 0 , _pinAttr = 28[PWM] SAMD21 setPWM_Int: newDC = 8639 , input dutycycle = 58982 , _compareValue = 9599 , frequency = 5000.00[PWM] SAMD21 setPWM_Int: Old TCC => newDC = 8639 , input dutycycle = 58982 , frequency = 5000.00=====================================================================================Actual data: pin = 11, PWM DC = 90.00, PWMPeriod = 200.00, PWM Freq (Hz) = 5000.0000=====================================================================================
The following is the sample terminal output when running examplePWM_Multi onSAMD21 SAMD_NANO_33_IOT, to demonstrate the ability to provide high PWM frequencies on multiplePWM-capable pins usingTCC timer for 16-bit PWM
Starting PWM_Multi on SAMD_NANO_33_IOTSAMD_PWM v1.0.1[PWM] calcTCCPrescaler: OK pin =4 , period =500 , _prescaler =1 , F_CPU =48000000[PWM] calcTCCPrescaler: _dutycycle =6553 , frequency =2000.00 , _prescalerConfigBits =0 , _compareValue =23999[PWM] SAMD21 setPWM_Int: _tcNum =1 , _tcChannel =1 , _pinAttr =28[PWM] SAMD21 setPWM_Int: newDC =2399 , input dutycycle =6553 , _compareValue =23999 , frequency =2000.00[PWM] SAMD21 setPWM_Int: New TCC => newDC=2399 , input dutycycle =6553 , frequency =2000.00[PWM] calcTCCPrescaler: OK pin =5 , period =333 , _prescaler =1 , F_CPU =48000000[PWM] calcTCCPrescaler: _dutycycle =19660 , frequency =3000.00 , _prescalerConfigBits =0 , _compareValue =15983[PWM] SAMD21 setPWM_Int: _tcNum =0 , _tcChannel =1 , _pinAttr =28[PWM] SAMD21 setPWM_Int: newDC =4794 , input dutycycle =19660 , _compareValue =15983 , frequency =3000.00[PWM] SAMD21 setPWM_Int: New TCC => newDC=4794 , input dutycycle =19660 , frequency =3000.00[PWM] calcTCCPrescaler: OK pin =11 , period =250 , _prescaler =1 , F_CPU =48000000[PWM] calcTCCPrescaler: _dutycycle =32768 , frequency =4000.00 , _prescalerConfigBits =0 , _compareValue =11999[PWM] SAMD21 setPWM_Int: _tcNum =2 , _tcChannel =0 , _pinAttr =28[PWM] SAMD21 setPWM_Int: newDC =5999 , input dutycycle =32768 , _compareValue =11999 , frequency =4000.00[PWM] SAMD21 setPWM_Int: New TCC => newDC=5999 , input dutycycle =32768 , frequency =4000.00[PWM] calcTCPrescaler: OK pin =12 , period =125 , _prescaler =1 , F_CPU =48000000[PWM] calcTCPrescaler: _dutycycle =58982 , frequency =8000.00 , _prescalerConfigBits =0 , _compareValue =5999[PWM] SAMD21 setPWM_Int: _tcNum =3 , _tcChannel =1 , _pinAttr =28[PWM] SAMD21 setPWM_Int: newDC =5399 , input dutycycle =58982 , _compareValue =5999 , frequency =8000.00[PWM] SAMD21 setPWM_Int: New TC => newDC =21 , input dutycycle =58982 , _compareValue =23 , frequency =8000.00=====================================================================================IndexPinPWM_freqDutyCycleActual Freq=====================================================================================042000.0010.002000.0000153000.0030.003000.00002114000.0050.004000.00003128000.0090.008000.0000=====================================================================================Actual data: pin =4, PWM DC =10.00, PWMPeriod =500.00, PWMFreq (Hz) = 2000.0000==========================================================================================================================================================================Actual data: pin = 5, PWM DC = 30.00, PWMPeriod = 333.33, PWM Freq (Hz) = 3000.0000==========================================================================================================================================================================Actual data: pin = 11, PWM DC = 50.00, PWMPeriod = 250.00, PWM Freq (Hz) = 4000.0000==========================================================================================================================================================================Actual data: pin = 12, PWM DC = 90.00, PWMPeriod = 125.00, PWM Freq (Hz) = 8000.0000=====================================================================================
The following is the sample terminal output when running examplePWM_DynamicFreq onSAMD51 ITSYBITSY_M4, to demonstrate the ability to change dynamically PWM frequencies on SAMD51 usingTCC timer for 16-bit PWM
Starting PWM_DynamicFreq on ITSYBITSY_M4SAMD_PWM v1.0.1[PWM] calcTCCPrescaler: OK pin =11 , period =100 , _prescaler =1 , F_CPU =120000000[PWM] calcTCCPrescaler: _dutycycle =32768 , frequency =10000.00 , _prescalerConfigBits =0 , _compareValue =11999[PWM] SAMD51 setPWM_Int: _tcNum =0 , _tcChannel =1 , _pinAttr =512[PWM] SAMD51 setPWM_Int: newDC =5999 , input dutycycle =32768 , _compareValue =11999 , frequency =10000.00[PWM] SAMD51 setPWM_Int: New TCC => newDC =5999 , input dutycycle =32768 , _compareValue =11999 , frequency =10000.00=====================================================================================Change PWM Freq to20000.00[PWM] setPWM: _dutycycle =32768 , frequency =20000.00[PWM] setPWM_Int: change frequency to20000.00 from10000.00[PWM] calcTCCPrescaler: OK pin =11 , period =50 , _prescaler =1 , F_CPU =120000000[PWM] calcTCCPrescaler: _dutycycle =32768 , frequency =20000.00 , _prescalerConfigBits =0 , _compareValue =5999[PWM] SAMD51 setPWM_Int: _tcNum =0 , _tcChannel =1 , _pinAttr =512[PWM] SAMD51 setPWM_Int: newDC =2999 , input dutycycle =32768 , _compareValue =5999 , frequency =20000.00[PWM] SAMD51 setPWM_Int: New TCC => newDC =2999 , input dutycycle =32768 , _compareValue =5999 , frequency =20000.00=====================================================================================Actual data: pin =11, PWM DC =50.00, PWMPeriod =50.00, PWMFreq (Hz) = 20000.0000=====================================================================================Change PWM Freq to 10000.00[PWM] setPWM: _dutycycle = 32768 , frequency = 10000.00[PWM] setPWM_Int: change frequency to 10000.00 from 20000.00[PWM] calcTCCPrescaler: OK pin = 11 , period = 100 , _prescaler = 1 , F_CPU = 120000000[PWM] calcTCCPrescaler: _dutycycle = 32768 , frequency = 10000.00 , _prescalerConfigBits = 0 , _compareValue = 11999[PWM] SAMD51 setPWM_Int: _tcNum = 0 , _tcChannel = 1 , _pinAttr = 512[PWM] SAMD51 setPWM_Int: newDC = 5999 , input dutycycle = 32768 , _compareValue = 11999 , frequency = 10000.00[PWM] SAMD51 setPWM_Int: New TCC => newDC = 5999 , input dutycycle = 32768 , _compareValue = 11999 , frequency = 10000.00=====================================================================================Actual data: pin = 11, PWM DC = 50.00, PWMPeriod = 100.00, PWM Freq (Hz) = 10000.0000=====================================================================================
The following is the sample terminal output when running examplePWM_Waveform onSAMD51 ITSYBITSY_M4, to demonstrate how to use thesetPWM_manual() function in wafeform creation usingTCC timer for 16-bit PWM
Starting PWM_Waveform on ITSYBITSY_M4SAMD_PWM v1.0.1[PWM] calcTCCPrescaler: OK pin =11 , period =1000 , _prescaler =1 , F_CPU =120000000[PWM] calcTCCPrescaler: _dutycycle =0 , frequency =1000.00 , _prescalerConfigBits =0 , _compareValue =119999[PWM] setPWM: _dutycycle =655 , frequency =1000.00[PWM] SAMD51 setPWM_Int: _tcNum =0 , _tcChannel =1 , _pinAttr =512[PWM] SAMD51 setPWM_Int: newDC =1199 , input dutycycle =655 , _compareValue =119999 , frequency =1000.00[PWM] SAMD51 setPWM_Int: New TCC => newDC =1199 , input dutycycle =655 , _compareValue =119999 , frequency =1000.00============================================================================================Actual data: pin =11, PWM DutyCycle =0.00, PWMPeriod =1000.00, PWMFreq (Hz) = 1000.0000============================================================================================[PWM] setPWM_manual: DCValue = 0 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 0 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 5 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 5999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 10 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 11999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 15 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 17999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 20 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 23999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 25 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 29999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 30 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 35999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 35 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 41999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 40 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 47999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 45 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 53999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 50 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 59999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 55 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 65999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 60 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 71999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 65 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 77999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 70 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 83999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 75 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 89999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 80 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 95999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 85 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 101999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 90 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 107999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 95 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 113999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 100 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 119999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 95 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 113999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 90 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 107999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 85 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 101999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 80 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 95999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 75 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 89999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 70 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 83999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 65 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 77999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 60 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 71999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 55 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 65999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 50 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 59999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 45 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 53999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 40 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 47999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 35 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 41999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 30 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 35999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 25 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 29999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 20 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 23999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 15 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 17999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 10 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 11999 , _compareValue = 119999[PWM] setPWM_manual: DCValue = 5 , _frequency = 1000.00[PWM] setPWM_manual: New DCValue = 5999 , _compareValue = 119999
The following is the sample terminal output when running examplePWM_Basic onSAMD51 ITSYBITSY_M4, to demonstrate how to use the basic function, usingTC timer for 8-bit PWM
Starting PWM_Basic on ITSYBITSY_M4SAMD_PWM v1.0.1[PWM] calcTCPrescaler: OK pin =24 , period =1000 , _prescaler =1 , F_CPU =120000000[PWM] calcTCPrescaler: _dutycycle =0 , frequency =1000.00 , _prescalerConfigBits =0 , _compareValue =119999[PWM] setPWM: _dutycycle =13107 , frequency =2000.00[PWM] setPWM_Int: change frequency to2000.00 from1000.00[PWM] calcTCPrescaler: OK pin =24 , period =500 , _prescaler =1 , F_CPU =120000000[PWM] calcTCPrescaler: _dutycycle =13107 , frequency =2000.00 , _prescalerConfigBits =0 , _compareValue =59999[PWM] SAMD51 setPWM_Int: _tcNum =5 , _tcChannel =1 , _pinAttr =8[PWM] SAMD51 setPWM_Int: newDC =11999 , input dutycycle =13107 , _compareValue =59999 , frequency =2000.00[PWM] SAMD51 setPWM_Int: New TC => newDC =46 , input dutycycle =13107 , _compareValue =234 , frequency =2000.00[PWM] setPWM: _dutycycle =58982 , frequency =5000.00[PWM] setPWM_Int: change frequency to5000.00 from2000.00[PWM] calcTCPrescaler: OK pin =24 , period =200 , _prescaler =1 , F_CPU =120000000[PWM] calcTCPrescaler: _dutycycle =58982 , frequency =5000.00 , _prescalerConfigBits =0 , _compareValue =23999[PWM] SAMD51 setPWM_Int: _tcNum =5 , _tcChannel =1 , _pinAttr =8[PWM] SAMD51 setPWM_Int: newDC =21598 , input dutycycle =58982 , _compareValue =23999 , frequency =5000.00[PWM] SAMD51 setPWM_Int: New TC => newDC =84 , input dutycycle =58982 , _compareValue =93 , frequency =5000.00[PWM] setPWM: _dutycycle =13107 , frequency =2000.00[PWM] setPWM_Int: change frequency to2000.00 from5000.00[PWM] calcTCPrescaler: OK pin =24 , period =500 , _prescaler =1 , F_CPU =120000000[PWM] calcTCPrescaler: _dutycycle =13107 , frequency =2000.00 , _prescalerConfigBits =0 , _compareValue =59999[PWM] SAMD51 setPWM_Int: _tcNum =5 , _tcChannel =1 , _pinAttr =8[PWM] SAMD51 setPWM_Int: newDC =11999 , input dutycycle =13107 , _compareValue =59999 , frequency =2000.00[PWM] SAMD51 setPWM_Int: New TC => newDC =46 , input dutycycle =13107 , _compareValue =234 , frequency =2000.00[PWM] setPWM: _dutycycle =58982 , frequency =5000.00[PWM] setPWM_Int: change frequency to5000.00 from2000.00[PWM] calcTCPrescaler: OK pin =24 , period =200 , _prescaler =1 , F_CPU =120000000[PWM] calcTCPrescaler: _dutycycle =58982 , frequency =5000.00 , _prescalerConfigBits =0 , _compareValue =23999[PWM] SAMD51 setPWM_Int: _tcNum =5 , _tcChannel =1 , _pinAttr =8[PWM] SAMD51 setPWM_Int: newDC =21598 , input dutycycle =58982 , _compareValue =23999 , frequency =5000.00[PWM] SAMD51 setPWM_Int: New TC => newDC =84 , input dutycycle =58982 , _compareValue =93 , frequency =5000.00
The following is the sample terminal output when running examplePWM_Basic onSAMD21 SAMD_NANO_33_IOT, to demonstrate how to use the basic function, usingTC timer for 8-bit PWM
Starting PWM_Basic on SAMD_NANO_33_IOTSAMD_PWM v1.0.1[PWM] calcTCPrescaler: OK pin =12 , period =1000 , _prescaler =1 , F_CPU =48000000[PWM] calcTCPrescaler: _dutycycle =0 , frequency =1000.00 , _prescalerConfigBits =0 , _compareValue =47999[PWM] setPWM: _dutycycle =13107 , frequency =2000.00[PWM] setPWM_Int: change frequency to2000.00 from1000.00[PWM] calcTCPrescaler: OK pin =12 , period =500 , _prescaler =1 , F_CPU =48000000[PWM] calcTCPrescaler: _dutycycle =13107 , frequency =2000.00 , _prescalerConfigBits =0 , _compareValue =23999[PWM] SAMD21 setPWM_Int: _tcNum =3 , _tcChannel =1 , _pinAttr =28[PWM] SAMD21 setPWM_Int: newDC =4799 , input dutycycle =13107 , _compareValue =23999 , frequency =2000.00[PWM] SAMD21 setPWM_Int: New TC => newDC =18 , input dutycycle =13107 , _compareValue =93 , frequency =2000.00[PWM] setPWM: _dutycycle =58982 , frequency =5000.00[PWM] setPWM_Int: change frequency to5000.00 from2000.00[PWM] calcTCPrescaler: OK pin =12 , period =200 , _prescaler =1 , F_CPU =48000000[PWM] calcTCPrescaler: _dutycycle =58982 , frequency =5000.00 , _prescalerConfigBits =0 , _compareValue =9599[PWM] SAMD21 setPWM_Int: _tcNum =3 , _tcChannel =1 , _pinAttr =28[PWM] SAMD21 setPWM_Int: newDC =8639 , input dutycycle =58982 , _compareValue =9599 , frequency =5000.00[PWM] SAMD21 setPWM_Int: New TC => newDC =33 , input dutycycle =58982 , _compareValue =37 , frequency =5000.00[PWM] setPWM: _dutycycle =13107 , frequency =2000.00[PWM] setPWM_Int: change frequency to2000.00 from5000.00[PWM] calcTCPrescaler: OK pin =12 , period =500 , _prescaler =1 , F_CPU =48000000[PWM] calcTCPrescaler: _dutycycle =13107 , frequency =2000.00 , _prescalerConfigBits =0 , _compareValue =23999[PWM] SAMD21 setPWM_Int: _tcNum =3 , _tcChannel =1 , _pinAttr =28[PWM] SAMD21 setPWM_Int: newDC =4799 , input dutycycle =13107 , _compareValue =23999 , frequency =2000.00[PWM] SAMD21 setPWM_Int: New TC => newDC =18 , input dutycycle =13107 , _compareValue =93 , frequency =2000.00
The following is the sample terminal output when running examplePWM_manual onSAMD51 ITSYBITSY_M4, to demonstrate how to use thesetPWM_manual() andsetPWM_DCPercentage_manual() functions in wafeform creation
Starting PWM_manual on ITSYBITSY_M4SAMD_PWM v1.2.0Not USING_DC_PERCENT=================================================================================================Actual data: pin =11, PWM DC =0.00, PWMPeriod =500.00, PWMFreq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 5.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 10.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 15.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 20.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 25.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 30.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 35.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 40.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 45.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 50.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 55.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 60.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 65.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 70.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 75.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 80.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 85.01, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 90.01, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 95.01, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 100.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000==================================================================================================================================================================================================Actual data: pin = 11, PWM DC = 0.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000=================================================================================================...
The following is the sample terminal output when running examplePWM_SpeedTest onITSYBITSY_M4, to demonstrate how to use new fastersetPWM_manual() function in wafeform creation, The time is1084 ns compared to499,500 ns when usingsetPWM() function. The fastest issetPWM_DCPercentageInt_manual with1067 ns, which is better to be used with pre-calculated values in array
Starting PWM_SpeedTest on ITSYBITSY_M4SAMD_PWM v1.2.0Average time of setPWM function USING_DC_PERCENT=================================================================================================Actual data: pin = 11, PWM DC = 44.86, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000=================================================================================================count=937083, ns=1067=================================================================================================Actual data: pin = 11, PWM DC = 44.86, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000=================================================================================================count=936335, ns=1067=================================================================================================Actual data: pin = 11, PWM DC = 44.86, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000=================================================================================================count=936358, ns=1067=================================================================================================Actual data: pin = 11, PWM DC = 44.86, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000=================================================================================================count=936334, ns=1067...Starting PWM_SpeedTest on ITSYBITSY_M4SAMD_PWM v1.2.0Average time of setPWM function USING_DC_PERCENT=================================================================================================Actual data: pin = 11, PWM DC = 50.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000=================================================================================================count=2002, ns=499500=================================================================================================Actual data: pin = 11, PWM DC = 50.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000=================================================================================================count=2003, ns=499251=================================================================================================Actual data: pin = 11, PWM DC = 50.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000=================================================================================================count=2003, ns=499251=================================================================================================Actual data: pin = 11, PWM DC = 50.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000=================================================================================================count=2003, ns=499251=================================================================================================Actual data: pin = 11, PWM DC = 50.00, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000=======================================================Starting PWM_SpeedTest on ITSYBITSY_M4SAMD_PWM v1.2.0Average time of setPWM functionnot USING_DC_PERCENT=================================================================================================Actual data: pin =11, PWM DC =44.86, PWMPeriod =500.00, PWMFreq (Hz) = 2000.0000=================================================================================================count=922600, ns=1083=================================================================================================Actual data: pin = 11, PWM DC = 44.86, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000=================================================================================================count=921932, ns=1084=================================================================================================Actual data: pin = 11, PWM DC = 44.86, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000=================================================================================================count=921965, ns=1084=================================================================================================Actual data: pin = 11, PWM DC = 44.86, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000=================================================================================================count=921951, ns=1084=================================================================================================Actual data: pin = 11, PWM DC = 44.86, PWMPeriod = 500.00, PWM Freq (Hz) = 2000.0000=================================================================================================count=921942, ns=1084
Debug is enabled by default on Serial.
You can also change the debugging level_PWM_LOGLEVEL_ from 0 to 4
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.#define_PWM_LOGLEVEL_0
If you get compilation errors, more often than not, you may need to install a newer version of the core for Arduino boards.
Sometimes, the library will only work if you update the board core to the latest version because I am using newly added functions.
Submit issues to:SAMD_PWM issues
- Search for bug and improvement.
- Similar features for remaining Arduino boards
- Basic hardware PWM-channels forSAMD21/SAMD51 boards such as
NANO_33_IOT,ITSYBITSY_M4,SEEED_XIAO_M0,SparkFun SAMD51_Thing_Plus, etc. using
- Arduino SAMD core
- Adafruit SAMD core
- Seeed-Studio SAMD core
- Sparkfun SAMD core
- Industruino SAMD core
- Industruino SAMx core
- Add examplePWM_StepperControl to demo how to control Stepper Motor using PWM
- Add examplePWM_manual to demo how to correctly use PWM to generate waveform
- Add function
setPWM_DCPercentage_manual()to facilitate the setting PWM DC manually by using DCPercentage, instead of absolute DCValue depending on varying PWMPeriod - Optimize speed with new
setPWM_DCPercentageInt_manualfunction to improve speed almost 500 times compared tosetPWM - Add examplePWM_SpeedTest to demo the better speed of new
setPWM_DCPercentageInt_manualfunction - Breaking change: Modify
setPWM_manualfunction to take16-bitdutycycle instead from merely0-100for better accuracy - Modify examplePWM_Waveform to adapt to breaking change of
setPWM_manualfunction - Improve
README.mdso that links can be used in other sites, such asPIO
Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library.
- Thanks toPaul van Dinther for proposing new way to use PWM to drive Stepper-Motor inUsing PWM to step a stepper driver #16, leading to v2.0.3
![]() Paul van Dinther |
If you want to contribute to this project:
- Report bugs and errors
- Ask for enhancements
- Create issues and pull requests
- Tell other people about this library
- The library is licensed underMIT
Copyright (c) 2022- Khoi Hoang
About
This library enables you to use Hardware-based PWM channels on SAMD21/SAMD51-based boards to create and output PWM to pins. Using the same functions as other FastPWM libraries to enable you to port PWM code easily between platforms.
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases3
Packages0
Uh oh!
There was an error while loading.Please reload this page.

