This repository has been archived by the owner on Feb 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.0.0 for hardware-PWM on SAM_DUE boards
### Initial Releases v1.0.0 1. Initial coding to support **SAM_DUE**, etc. using [`Arduino SAM core`](https://github.com/arduino/ArduinoCore-sam)
- Loading branch information
1 parent
1d6ff63
commit a5ac09f
Showing
18 changed files
with
2,101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
## Contributing to SAMDUE_PWM | ||
|
||
### Reporting Bugs | ||
|
||
Please report bugs in SAMDUE_PWM if you find them. | ||
|
||
However, before reporting a bug please check through the following: | ||
|
||
* [Existing Open Issues](https://github.com/khoih-prog/SAMDUE_PWM/issues) - someone might have already encountered this. | ||
|
||
If you don't find anything, please [open a new issue](https://github.com/khoih-prog/SAMDUE_PWM/issues/new). | ||
|
||
### How to submit a bug report | ||
|
||
Please ensure to specify the following: | ||
|
||
* Arduino IDE version (e.g. 1.8.19) or Platform.io version | ||
* `SAMDUE` Core Version (e.g. Arduino SAMDUE_ core v1.6.12) | ||
* Contextual information (e.g. what you were trying to achieve) | ||
* Simplest possible steps to reproduce | ||
* Anything that might be relevant in your opinion, such as: | ||
* Operating system (Windows, Ubuntu, etc.) and the output of `uname -a` | ||
* Network configuration | ||
|
||
|
||
### Example | ||
|
||
``` | ||
Arduino IDE version: 1.8.19 | ||
Arduino SAMDUE Core Version 1.6.12 | ||
OS: Ubuntu 20.04 LTS | ||
Linux xy-Inspiron-3593 5.4.0-100-generic #113-Ubuntu SMP Thu Feb 3 18:43:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux | ||
Context: | ||
I encountered a crash while trying to use the Timer Interrupt. | ||
Steps to reproduce: | ||
1. ... | ||
2. ... | ||
3. ... | ||
4. ... | ||
``` | ||
|
||
|
||
|
||
### Additional context | ||
|
||
Add any other context about the problem here. | ||
|
||
--- | ||
|
||
### Sending Feature Requests | ||
|
||
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful. | ||
|
||
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/SAMDUE_PWM/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them. | ||
|
||
--- | ||
|
||
### Sending Pull Requests | ||
|
||
Pull Requests with changes and fixes are also welcome! | ||
|
||
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux) | ||
|
||
1. Change directory to the library GitHub | ||
|
||
``` | ||
xy@xy-Inspiron-3593:~$ cd Arduino/xy/SAMDUE_PWM_GitHub/ | ||
xy@xy-Inspiron-3593:~/Arduino/xy/SAMDUE_PWM_GitHub$ | ||
``` | ||
|
||
2. Issue astyle command | ||
|
||
``` | ||
xy@xy-Inspiron-3593:~/Arduino/xy/SAMDUE_PWM_GitHub$ bash utils/restyle.sh | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# SAMDUE_PWM Library | ||
|
||
[![arduino-library-badge](https://www.ardu-badge.com/badge/SAMDUE_PWM.svg?)](https://www.ardu-badge.com/SAMDUE_PWM) | ||
[![GitHub release](https://img.shields.io/github/release/khoih-prog/SAMDUE_PWM.svg)](https://github.com/khoih-prog/SAMDUE_PWM/releases) | ||
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/SAMDUE_PWM/blob/master/LICENSE) | ||
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) | ||
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/SAMDUE_PWM.svg)](http://github.com/khoih-prog/SAMDUE_PWM/issues) | ||
|
||
--- | ||
--- | ||
|
||
## Table of Contents | ||
|
||
* [Changelog](#changelog) | ||
* [Initial Releases v1.0.0](#Initial-Releases-v100) | ||
|
||
--- | ||
--- | ||
|
||
## Changelog | ||
|
||
### Initial Releases v1.0.0 | ||
|
||
1. Initial coding to support **SAM_DUE**, etc. using [`Arduino SAM core`](https://github.com/arduino/ArduinoCore-sam) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/**************************************************************************************************************************** | ||
PWM_Basic.ino | ||
For SAM_DUE boards using hardware-based PWM | ||
Written by Khoi Hoang | ||
Built by Khoi Hoang https://github.com/khoih-prog/SAMDUE_PWM | ||
Licensed under MIT license | ||
*****************************************************************************************************************************/ | ||
|
||
#define _PWM_LOGLEVEL_ 4 | ||
|
||
// Select false to use PWM | ||
#define USING_TIMER false //true | ||
|
||
#include "SAMDUE_PWM.h" | ||
|
||
// SAM_DUE: | ||
// PWM pins: 6, 7, 8, 9 | ||
// Timer pins: 2-5, 10-13. | ||
// pin2: TC0_CHA0, pin3: TC2_CHA7, pin4: TC2_CHB6, pin5: TC2_CHA6 | ||
// pin 10: TC2_CHB7, pin11: TC2_CHA8, pin12: TC2_CHB8, pin13: TC0_CHB0 | ||
|
||
#if USING_TIMER | ||
#define pinToUse 5 | ||
#else | ||
#define pinToUse 6 | ||
#endif | ||
|
||
//creates pwm instance | ||
SAMDUE_PWM* PWM_Instance; | ||
|
||
float frequency = 1000.0f; | ||
|
||
float dutyCycle = 0.0f; | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
|
||
while (!Serial && millis() < 5000); | ||
|
||
delay(500); | ||
|
||
#if USING_TIMER | ||
Serial.print(F("\nStarting PWM_Basic using Timer on ")); | ||
#else | ||
Serial.print(F("\nStarting PWM_Basic using PWM on ")); | ||
#endif | ||
|
||
Serial.println(BOARD_NAME); | ||
Serial.println(SAMDUE_PWM_VERSION); | ||
|
||
//assigns PWM frequency of 1.0 KHz and a duty cycle of 0% | ||
PWM_Instance = new SAMDUE_PWM(pinToUse, frequency, dutyCycle); | ||
|
||
if ( (!PWM_Instance) || !PWM_Instance->isPWMEnabled()) | ||
{ | ||
Serial.print(F("Stop here forever")); | ||
|
||
while (true) | ||
delay(10000); | ||
} | ||
} | ||
|
||
void loop() | ||
{ | ||
// You can change frequency here, anytime | ||
frequency = 2000.0f; | ||
dutyCycle = 20.0f; | ||
|
||
PWM_Instance->setPWM(pinToUse, frequency, dutyCycle); | ||
|
||
delay(10000); | ||
|
||
// You can change frequency here, anytime | ||
frequency = 5000.0f; | ||
dutyCycle = 90.0f; | ||
|
||
PWM_Instance->setPWM(pinToUse, frequency, dutyCycle); | ||
|
||
//while (1) | ||
delay(10000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/**************************************************************************************************************************** | ||
PWM_DynamicDutyCycle.ino | ||
For SAM_DUE boards using hardware-based PWM | ||
Written by Khoi Hoang | ||
Built by Khoi Hoang https://github.com/khoih-prog/SAMDUE_PWM | ||
Licensed under MIT license | ||
*****************************************************************************************************************************/ | ||
|
||
#define _PWM_LOGLEVEL_ 4 | ||
|
||
// Select false to use PWM | ||
#define USING_TIMER true | ||
|
||
#include "SAMDUE_PWM.h" | ||
|
||
// SAM_DUE: | ||
// PWM pins: 6, 7, 8, 9 | ||
// Timer pins: 2-5, 10-13. | ||
// pin2: TC0_CHA0, pin3: TC2_CHA7, pin4: TC2_CHB6, pin5: TC2_CHA6 | ||
// pin 10: TC2_CHB7, pin11: TC2_CHA8, pin12: TC2_CHB8, pin13: TC0_CHB0 | ||
|
||
#if USING_TIMER | ||
#define pinToUse 5 | ||
#else | ||
#define pinToUse 6 | ||
#endif | ||
|
||
//creates pwm instance | ||
SAMDUE_PWM* PWM_Instance; | ||
|
||
float frequency; | ||
float dutyCycle; | ||
|
||
char dashLine[] = "====================================================================================="; | ||
|
||
void printPWMInfo(SAMDUE_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); | ||
} | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
|
||
while (!Serial && millis() < 5000); | ||
|
||
delay(500); | ||
|
||
#if USING_TIMER | ||
Serial.print(F("\nStarting PWM_DynamicDutyCycle using Timer on ")); | ||
#else | ||
Serial.print(F("\nStarting PWM_DynamicDutyCycle using PWM on ")); | ||
#endif | ||
|
||
Serial.println(BOARD_NAME); | ||
Serial.println(SAMDUE_PWM_VERSION); | ||
|
||
frequency = 5000.0f; | ||
|
||
PWM_Instance = new SAMDUE_PWM(pinToUse, frequency, 0.0f); | ||
|
||
if ( (!PWM_Instance) || !PWM_Instance->isPWMEnabled()) | ||
{ | ||
Serial.print(F("Stop here forever")); | ||
|
||
while (true) | ||
delay(10000); | ||
} | ||
|
||
Serial.println(dashLine); | ||
} | ||
|
||
void loop() | ||
{ | ||
dutyCycle = 90.0f; | ||
|
||
Serial.print(F("Change PWM DutyCycle to ")); | ||
Serial.println(dutyCycle); | ||
PWM_Instance->setPWM(pinToUse, frequency, dutyCycle); | ||
|
||
printPWMInfo(PWM_Instance); | ||
|
||
delay(5000); | ||
dutyCycle = 20.0f; | ||
|
||
Serial.print(F("Change PWM DutyCycle to ")); | ||
Serial.println(dutyCycle); | ||
PWM_Instance->setPWM(pinToUse, frequency, dutyCycle); | ||
printPWMInfo(PWM_Instance); | ||
|
||
delay(5000); | ||
} |
Oops, something went wrong.