This hardware-based PWM library enables you to use Hardware-PWM on SAMD21/SAMD51 boards such as NANO_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 be 16-bit for better accuracy when using Timer TCCx. With Timer TCx, only 8-bit resolution is supported with lower accuracy.
This library is using the same or similar functions as other FastPWM sibling libraries, as follows, to enable you to port your PWM code easily between platforms
The most important feature is they’re purely hardware-based PWM channels. Therefore, their operations are not 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 using millis() or micros(). That’s necessary if you need to control external systems (Servo, etc.) requiring better accuracy.
New efficient setPWM_manual() function enables waveform creation using PWM.
The PWM_Multi example will demonstrate the usage of multichannel PWM using multiple Hardware-PWM blocks (Timer & Channel). The 4 independent Hardware-PWM channels are used to control 4 different PWM outputs, with totally independent frequencies and dutycycles on SAMD21/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.
Why using hardware-based PWM is better
Imagine you have a system with a mission-critical function, controlling a robot or doing something much more important. You normally use a software timer to poll, or even place the function in loop(). But what if another function is blocking the loop() or setup().
So your function might 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 use hardware-based PWM.
These hardware-based 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-based PWMs, using millis() or micros().
Functions using normal software-based PWMs, relying on loop() and calling millis(), won’t work if the loop() or setup() is blocked by certain operation. For example, certain function is blocking while it’s connecting to WiFi or some services.
The best and easiest way is to use Arduino Library Manager. Search for SAMD_PWM, then select / install the latest version.
You can also use this link for more detailed instructions.
Use included platformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at Project Configuration File
Packages’ Patches
1. For Arduino SAMD boards
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 whole Arduino SAMD Packages_Patches directory into Arduino SAMD directory (~/.arduino15/packages/arduino/hardware/samd/1.8.13).
For core version v1.8.10+
Supposing the Arduino SAMD version is 1.8.13. Now only one file must be copied into the directory:
...\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 the Arduino.h file anymore.
2. For Adafruit SAMD boards
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 in Adafruit 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:
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz
This file must be copied into the directory:
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 in Seeeduino 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:
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz
This file must be copied into the directory:
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 file SparkFun 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:
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz
This file must be copied into the directory:
4. Set or change PWM frequency and dutyCycle manually and efficiently in waveform creation
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);
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);
}
Debug Terminal Output Samples
1. PWM_DynamicDutyCycle on SAMD_NANO_33_IOT
The following is the sample terminal output when running example PWM_DynamicDutyCycle on SAMD21 SAMD_NANO_33_IOT, to demonstrate the ability to provide high PWM frequencies and ability to change DutyCycle on-the-fly using TCC timer for 16-bit PWM
The following is the sample terminal output when running example PWM_Multi on SAMD21 SAMD_NANO_33_IOT, to demonstrate the ability to provide high PWM frequencies on multiple PWM-capable pins using TCC timer for 16-bit PWM
The following is the sample terminal output when running example PWM_DynamicFreq on SAMD51 ITSYBITSY_M4, to demonstrate the ability to change dynamically PWM frequencies on SAMD51 using TCC timer for 16-bit PWM
The following is the sample terminal output when running example PWM_Waveform on SAMD51 ITSYBITSY_M4, to demonstrate how to use the setPWM_manual() function in wafeform creation using TCC timer for 16-bit PWM
The following is the sample terminal output when running example PWM_Basic on SAMD51 ITSYBITSY_M4, to demonstrate how to use the basic function, using TC timer for 8-bit PWM
The following is the sample terminal output when running example PWM_Basic on SAMD21 SAMD_NANO_33_IOT, to demonstrate how to use the basic function, using TC timer for 8-bit PWM
The following is the sample terminal output when running example PWM_manual on SAMD51 ITSYBITSY_M4, to demonstrate how to use the setPWM_manual() and setPWM_DCPercentage_manual() functions in wafeform creation
Starting PWM_manual on ITSYBITSY_M4
SAMD_PWM v1.2.0
Not USING_DC_PERCENT
=================================================================================================
Actual data: pin = 11, PWM DC = 0.00, PWMPeriod = 500.00, PWM Freq (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
=================================================================================================
...
8. PWM_SpeedTest on ITSYBITSY_M4
The following is the sample terminal output when running example PWM_SpeedTest on ITSYBITSY_M4, to demonstrate how to use new faster setPWM_manual() function in wafeform creation, The time is 1084 ns compared to 499,500 ns when using setPWM() function. The fastest is setPWM_DCPercentageInt_manual with 1067 ns, which is better to be used with pre-calculated values in array
USING_DC_PERCENT
Starting PWM_SpeedTest on ITSYBITSY_M4
SAMD_PWM v1.2.0
Average 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
...
USING_DC_PERCENT with extremely slow setPWM()
Starting PWM_SpeedTest on ITSYBITSY_M4
SAMD_PWM v1.2.0
Average 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
=======================================================
not USING_DC_PERCENT
Starting PWM_SpeedTest on ITSYBITSY_M4
SAMD_PWM v1.2.0
Average time of setPWM function not USING_DC_PERCENT
=================================================================================================
Actual data: pin = 11, PWM DC = 44.86, PWMPeriod = 500.00, PWM Freq (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
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
Troubleshooting
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.
Add example PWM_StepperControl to demo how to control Stepper Motor using PWM
Add example PWM_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_manual function to improve speed almost 500 times compared to setPWM
Add example PWM_SpeedTest to demo the better speed of new setPWM_DCPercentageInt_manual function
Breaking change: Modify setPWM_manual function to take 16-bit dutycycle instead from merely 0-100 for better accuracy
Modify example PWM_Waveform to adapt to breaking change of setPWM_manual function
Improve README.md so that links can be used in other sites, such as PIO
Contributions and Thanks
Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library.
This hardware-based PWM library enables you to use Hardware-PWM on SAMD21/SAMD51 boards such as NANO_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 be 16-bit for better accuracy when using Timer TCCx. With Timer TCx, only 8-bit resolution is supported with lower accuracy.
This library is using the same or similar functions as other FastPWM sibling libraries, as follows, to enable you to port your PWM code easily between platforms
The most important feature is they’re purely hardware-based PWM channels. Therefore, their operations are not 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 using millis() or micros(). That’s necessary if you need to control external systems (Servo, etc.) requiring better accuracy.
New efficient setPWM_manual() function enables waveform creation using PWM.
The PWM_Multi example will demonstrate the usage of multichannel PWM using multiple Hardware-PWM blocks (Timer & Channel). The 4 independent Hardware-PWM channels are used to control 4 different PWM outputs, with totally independent frequencies and dutycycles on SAMD21/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.
Why using hardware-based PWM is better
Imagine you have a system with a mission-critical function, controlling a robot or doing something much more important. You normally use a software timer to poll, or even place the function in loop(). But what if another function is blocking the loop() or setup().
So your function might 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 use hardware-based PWM.
These hardware-based 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-based PWMs, using millis() or micros().
Functions using normal software-based PWMs, relying on loop() and calling millis(), won’t work if the loop() or setup() is blocked by certain operation. For example, certain function is blocking while it’s connecting to WiFi or some services.
The best and easiest way is to use Arduino Library Manager. Search for SAMD_PWM, then select / install the latest version.
You can also use this link for more detailed instructions.
Use included platformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at Project Configuration File
Packages’ Patches
1. For Arduino SAMD boards
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 whole Arduino SAMD Packages_Patches directory into Arduino SAMD directory (~/.arduino15/packages/arduino/hardware/samd/1.8.13).
For core version v1.8.10+
Supposing the Arduino SAMD version is 1.8.13. Now only one file must be copied into the directory:
...\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 the Arduino.h file anymore.
2. For Adafruit SAMD boards
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 in Adafruit 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:
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz
This file must be copied into the directory:
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 in Seeeduino 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:
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz
This file must be copied into the directory:
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 file SparkFun 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:
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz
This file must be copied into the directory:
4. Set or change PWM frequency and dutyCycle manually and efficiently in waveform creation
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);
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);
}
Debug Terminal Output Samples
1. PWM_DynamicDutyCycle on SAMD_NANO_33_IOT
The following is the sample terminal output when running example PWM_DynamicDutyCycle on SAMD21 SAMD_NANO_33_IOT, to demonstrate the ability to provide high PWM frequencies and ability to change DutyCycle on-the-fly using TCC timer for 16-bit PWM
The following is the sample terminal output when running example PWM_Multi on SAMD21 SAMD_NANO_33_IOT, to demonstrate the ability to provide high PWM frequencies on multiple PWM-capable pins using TCC timer for 16-bit PWM
The following is the sample terminal output when running example PWM_DynamicFreq on SAMD51 ITSYBITSY_M4, to demonstrate the ability to change dynamically PWM frequencies on SAMD51 using TCC timer for 16-bit PWM
The following is the sample terminal output when running example PWM_Waveform on SAMD51 ITSYBITSY_M4, to demonstrate how to use the setPWM_manual() function in wafeform creation using TCC timer for 16-bit PWM
The following is the sample terminal output when running example PWM_Basic on SAMD51 ITSYBITSY_M4, to demonstrate how to use the basic function, using TC timer for 8-bit PWM
The following is the sample terminal output when running example PWM_Basic on SAMD21 SAMD_NANO_33_IOT, to demonstrate how to use the basic function, using TC timer for 8-bit PWM
The following is the sample terminal output when running example PWM_manual on SAMD51 ITSYBITSY_M4, to demonstrate how to use the setPWM_manual() and setPWM_DCPercentage_manual() functions in wafeform creation
Starting PWM_manual on ITSYBITSY_M4
SAMD_PWM v1.2.0
Not USING_DC_PERCENT
=================================================================================================
Actual data: pin = 11, PWM DC = 0.00, PWMPeriod = 500.00, PWM Freq (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
=================================================================================================
...
8. PWM_SpeedTest on ITSYBITSY_M4
The following is the sample terminal output when running example PWM_SpeedTest on ITSYBITSY_M4, to demonstrate how to use new faster setPWM_manual() function in wafeform creation, The time is 1084 ns compared to 499,500 ns when using setPWM() function. The fastest is setPWM_DCPercentageInt_manual with 1067 ns, which is better to be used with pre-calculated values in array
USING_DC_PERCENT
Starting PWM_SpeedTest on ITSYBITSY_M4
SAMD_PWM v1.2.0
Average 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
...
USING_DC_PERCENT with extremely slow setPWM()
Starting PWM_SpeedTest on ITSYBITSY_M4
SAMD_PWM v1.2.0
Average 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
=======================================================
not USING_DC_PERCENT
Starting PWM_SpeedTest on ITSYBITSY_M4
SAMD_PWM v1.2.0
Average time of setPWM function not USING_DC_PERCENT
=================================================================================================
Actual data: pin = 11, PWM DC = 44.86, PWMPeriod = 500.00, PWM Freq (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
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
Troubleshooting
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.
Add example PWM_StepperControl to demo how to control Stepper Motor using PWM
Add example PWM_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_manual function to improve speed almost 500 times compared to setPWM
Add example PWM_SpeedTest to demo the better speed of new setPWM_DCPercentageInt_manual function
Breaking change: Modify setPWM_manual function to take 16-bit dutycycle instead from merely 0-100 for better accuracy
Modify example PWM_Waveform to adapt to breaking change of setPWM_manual function
Improve README.md so that links can be used in other sites, such as PIO
Contributions and Thanks
Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library.
The topic covered here is Sentiment Analysis in texts written
in French language.
For that, we employ a Recurrent Neural Network that we build and run thru the Tensorflow / Keras framework.
The architecture of the model is based on dual bi-directionnal GRU cells
and it employs fastText word embeddings.
We train this model using tranfer learning from rated product reviews
that have been web-scrapped using the BeautifulSoup python library
(the web-scraping code is not provided,
but the collected data is).
The figure on the left shows the structure of this project.
There are two key points to notice :
A dedicated custom python package named my_NLP_RNN_fr_lib has been developped to serve this project.
There’s a whole sub-section to the herein project, detailled separately, on hyperparameters optimization,.
It can be found there .
Spoiler alert : we deal with random search first, then XGBoost + scikit-learn
are called to get an extra edge.
The French-Text Sentiment Analysis project we’re dealing with here is explained in details and accompagnied with full running python code
in a walkthrough Jupyter Notebook.
KEYWORDS :
Tensorflow, Keras,
GRU, RNN, NLP, fastText,
web-scraping, BeautifulSoup,
transfer learning, french sentiment analysis
Bytecode instruction set and stack based virtual machine.
Usage
Usage: bytecode <COMMAND>
Commands:
b2r ByteCode source code file -> RawBytes file [ByteCode -> RawBytes]
run Interpret RawBytes file [RawBytes -> Execution]
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
RawBytes is data consisting of raw bytecode instructions and data.
A small language exists to facilitate bytecode representation and is very simple to use.
opcode [operand] ; comment
push 2 ; Push 2 onto the stack.
push 0xFF ; Push 255 onto the stack.
Opcodes
Opcode
Hex
Operand
Stack
Description
Noop
0x00
Does nothing.
Push
0x01
value
[.., value]
Push value onto the stack.
Add
0x02
[.., A, B] -> [.., R]
Pop two values, add them. (A + B = R)
Sub
0x03
[.., A, B] -> [.., R]
Pop two values, subtract them. (A + B = R)
Mul
0x04
[.., A, B] -> [.., R]
Pop two values, multiply them. (A + B = R)
Div
0x05
[.., A, B] -> [.., R]
Pop two values, divide them. (A + B = R)
Mod
0x06
[.., A, B] -> [.., R]
Pop two values, modulo them. (A + B = R)
Jump
0x07
offset
[.., ptr] -> [..]
Jump to offset (pointer).
JumpIfFalse
0x08
offset
[.., ptr] -> [..]
If top of stack is 0, jump to offset.
GT
0x09
[.., A, B] -> [.., R]
Pop two values, push true(1) if first is greater, else false(0).
LT
0x0A
[.., A, B] -> [.., R]
Pop two values, push true(1) if first is less.
GTE
0x0B
[.., A, B] -> [.., R]
Pop two values, push true(1) if first is greater or equal.
LTE
0x0C
[.., A, B] -> [.., R]
Pop two values, push true(1) if first is less or equal.
EQ
0x0D
[.., A, B] -> [.., R]
Pop two values, push true(1) if equal.
Proc
0x0E
length
[.., ptr] -> [..]
Instruction to delimit a procedure. instructions after length are omitted.
Call
0x0F
offset
[.., ptr] -> [..]
Call procedure at offset.
Ret
0x10
Return from procedure. See procedures for more details.
Store
0x11
index
[.., value] -> [..]
Pop value and store it at index.
Load
0x12
index
[..] -> [.., value]
Load value at index and push it onto the stack.
0x13 ~ 0xFD
Not used.
Exit
0xFE
Exit the program.
Debug
0xFF
value
Description
Print the stack. -1 = pops all, value = pops value items.
Procedures
Proc opcode takes a length operand, which is the number of instructions to skip after the Proc opcode.
Then, after executing the procedure in the CallStack using the Call instruction, the offset(pointer) to return to is stored.
After that, Call jump to the first instruction in the procedure and executes the procedure.
Return jumps to the return pointer stored in the CallStack.
proc 2 ; 0, The 2 instructions below are omitted.
noop ; 1
return ; 2, Jump to the pointer (4) stored in the CallStack.
call 1 ; 3, After saving the pointer to return (4) to the CallStack, jump to the pointer 1 of the first instruction of the procedure.
noop ; 4, Executed after the procedure runs.
The-Hungry-Kitchen is a recipe search website that allows users to discover recipes based on their dietary preferences and health considerations. Built with EJS, SASS, JavaScript, Node.js, RecipeSearchAPI, Nodemailer, MongoDB, and Express, it offers a rich user experience with a functional and intuitive interface.
Features
Home page with popular meals and email sign-up section.
Recipe search functionality that displays recipes with details like calories, diet, and health labels.
Email notifications for updates and news via Nodemailer.
User email storage in MongoDB for future marketing and information dissemination.
Alfresco shell scripts for extracting user, groups, sites, data and metadata information from Alfresco repository. For the extraction of metadata information it is needed to deploy a webscript in Alfresco Repository.
For running the shell scripts we need curl, wget, sed and jq shell utilities on the command line. For using metadata extraction, we need to deploy all webscript files under in /Data Dictionary/Web Scripts/net/zylk and then, to refresh Webscripts in /alfresco/service/index page.
Environment vars
Originally each shell script was provided with parameters in the command line (-e -u -p ). For making the script execution easier, we provide exportENVARS.sh script that may be used according to your environment, every script invokes it.
The following two scripts (downloadSite.sh and getMetadata.sh) are needed to extract Alfresco documents and their corresponding metadata from repository. For running getMetadata.sh properly we need to deploy export-bulk-metadata webscript in Alfresco Server.
Note: A better approach is probably done with Alfresco Bulk Export Module but it only works from Alfresco 4.2 and above (JDK7 needed).
downloadSite.sh
It downloads a site (-s) or a given repository folder (-f) via wget using webdav,
The aim of this script is to obtain a template of permissions for a new user, with respect a given user. For example, I want to give user johndoe the same exact permissions of abeecher. With the following output (changing abeecher by johndoe) I would generate the input for set-perms.sh script.
This script may be useful for complex (local) permissions maps.
getFolders.sh
It provides a folder permission template under a rootpath (given by a noderef). It lists a complete folder list under a given node, normally when permissions are set.
Draw2Text is an innovative web application that recognizes numbers and letters drawn by users in the canvas. It uses advanced machine learning algorithms, including computer vision and deep learning, to segment the drawn image, predict the digit/letter label, and display the result to the user. The app also enables users to provide feedback, which can be used to fine-tune the model for better accuracy in future predictions.
How it works
The user draws a digit or letter on the provided canvas
The app uses OpenCV, an open-source computer vision library, to segment the canvas in digits images
The segmented image is then passed to a neural network created with Keras, which uses deep learning techniques to predict the digit label.
The predicted label is then displayed to the user.
The user can provide feedback to improve the model’s accuracy in future predictions.
graph TD
A["User Drawn Digit"] --> B["OpenCV Segmentation"]
B --> C["Keras Model"]
C --> D["Digit Label Prediction"]
D --> E["Display Predictions"]
E --> F["User Feedback for Future Tuning"]
F --> C
Loading
Getting Started
To run the app locally, please follow these steps: