Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
Update README.md and use allman astyle
Browse files Browse the repository at this point in the history
  • Loading branch information
khoih-prog authored Nov 22, 2022
1 parent 71d9c04 commit 49dd0c0
Show file tree
Hide file tree
Showing 18 changed files with 675 additions and 494 deletions.
25 changes: 22 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
Please ensure to specify the following:

* Arduino IDE version (e.g. 1.8.19) or Platform.io version
* `DxCore` or `megaTinyCore` Core Version (e.g. Arduino DxCore core v1.4.10 or megaTinyCore core v2.5.11)
* `DxCore` or `megaTinyCore` Core Version (e.g. Arduino DxCore core v1.4.10)
* Board (e.g. AVR128DA64, AVR128DB48, AVR64DB32, etc.)
* Contextual information (e.g. what you were trying to achieve)
* Simplest possible steps to reproduce
Expand All @@ -31,25 +31,44 @@ Arduino IDE version: 1.8.19
Arduino DxCore core v1.4.10
OS: Ubuntu 20.04 LTS
Board: Curiosity AVR128DB48
Linux xy-Inspiron-3593 5.15.0-46-generic #49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Context:
I encountered a crash while trying to use the Timer Interrupt.
I encountered a crash while using this library
Steps to reproduce:
1. ...
2. ...
3. ...
4. ...
```

---

### 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/Dx_Slow_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/Dx_Slow_PWM_GitHub/
xy@xy-Inspiron-3593:~/Arduino/xy/Dx_Slow_PWM_GitHub$
```

2. Issue astyle command

```
xy@xy-Inspiron-3593:~/Arduino/xy/Dx_Slow_PWM_GitHub$ bash utils/restyle.sh
```

33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/Dx_Slow_PWM.svg)](http://github.com/khoih-prog/Dx_Slow_PWM/issues)


<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
<a href="https://profile-counter.glitch.me/khoih-prog/count.svg" title="Total khoih-prog Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog/count.svg" style="height: 30px;width: 200px;"></a>
<a href="https://profile-counter.glitch.me/khoih-prog-Dx_Slow_PWM/count.svg" title="Dx_Slow_PWM Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-Dx_Slow_PWM/count.svg" style="height: 30px;width: 200px;"></a>


---
Expand Down Expand Up @@ -98,15 +101,15 @@ For example, to run [Change_Interval example](https://github.com/khoih-prog/Dx_T


<p align="center">
<img src="https://github.com/khoih-prog/Dx_TimerInterrupt/blob/main/pics/Change_Interval.png">
<img src="https://github.com/khoih-prog/Dx_TimerInterrupt/raw/main/pics/Change_Interval.png">
</p>


After drag-and-drop the `Change_Interval.ino.hex` into `CURIOSITY` virtual drive, the code will run immediately if successfully loaded (LED blinks **slowly**)


<p align="center">
<img src="https://github.com/khoih-prog/Dx_TimerInterrupt/blob/main/pics/CURIOSITY_drive.png">
<img src="https://github.com/khoih-prog/Dx_TimerInterrupt/raw/main/pics/CURIOSITY_drive.png">
</p>


Expand Down Expand Up @@ -165,14 +168,14 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),
- **AVRDA-based boards (AVR128DA, AVR64DA, AVR32DA, etc.) using DxCore**

<p align="center">
<img src="https://github.com/khoih-prog/Dx_TimerInterrupt/blob/main/pics/Curiosity_AVR128DA48.png">
<img src="https://github.com/khoih-prog/Dx_TimerInterrupt/raw/main/pics/Curiosity_AVR128DA48.png">
</p>


- **AVRDB-based boards (AVR128DB, AVR64DB, AVR32DB, etc.) using DxCore**

<p align="center">
<img src="https://github.com/khoih-prog/Dx_TimerInterrupt/blob/main/pics/Curiosity_AVR128DB48.png">
<img src="https://github.com/khoih-prog/Dx_TimerInterrupt/raw/main/pics/Curiosity_AVR128DB48.png">
</p>


Expand All @@ -183,7 +186,7 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),
- **tinyAVR boards using megaTinyCore**

<p align="center">
<img src="https://github.com/khoih-prog/Dx_TimerInterrupt/blob/main/pics/Curiosity_ATtiny3217.png">
<img src="https://github.com/khoih-prog/Dx_TimerInterrupt/raw/main/pics/Curiosity_ATtiny3217.png">
</p>

---
Expand Down Expand Up @@ -245,14 +248,14 @@ The current library implementation, using `xyz-Impl.h` instead of standard `xyz.

You can include this `.hpp` file

```
```cpp
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
#include "Dx_Slow_PWM.hpp" //https://github.com/khoih-prog/Dx_Slow_PWM
```

in many files. But be sure to use the following `.h` file **in just 1 `.h`, `.cpp` or `.ino` file**, which must **not be included in any other file**, to avoid `Multiple Definitions` Linker Error

```
```cpp
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "Dx_Slow_PWM.h" //https://github.com/khoih-prog/Dx_Slow_PWM
```
Expand Down Expand Up @@ -299,7 +302,7 @@ Before using any Timer, you have to make sure the Timer has not been used by any

#### 1. Init Hardware Timer

```
```cpp
// Select USING_FULL_CLOCK == true for 24/16MHz to Timer TCBx => shorter timer, but better accuracy
// Select USING_HALF_CLOCK == true for 12/ 8MHz to Timer TCBx => shorter timer, but better accuracy
// Select USING_250KHZ == true for 250KHz to Timer TCBx => longer timer, but worse accuracy
Expand Down Expand Up @@ -334,7 +337,7 @@ Dx_Slow_PWM ISR_PWM;

#### 2. Set PWM Frequency, dutycycle, attach irqCallbackStartFunc and irqCallbackStopFunc functions

```
```cpp
void irqCallbackStartFunc()
{

Expand Down Expand Up @@ -387,7 +390,7 @@ https://github.com/khoih-prog/Dx_Slow_PWM/blob/a4f6824724484cd522fc9c98fac4cd5c6
The following is the sample terminal output when running example [ISR_8_PWMs_Array_Complex](examples/ISR_8_PWMs_Array_Complex) **Curiosity Nano AVR128DB48** to demonstrate how to use multiple PWM channels with complex callback functions, the accuracy of ISR Hardware PWM-channels, **especially when system is very busy**. The ISR PWM-channels is **running exactly according to corresponding programmed periods and duty-cycles**


```
```cpp
Starting ISR_8_PWMs_Array_Complex on AVR128DB
Dx_Slow_PWM v1.0.2
CPU Frequency = 24 MHz
Expand Down Expand Up @@ -429,7 +432,7 @@ PWM Channel : 7, prog Period (ms): 125.00, actual : 125028, prog DutyCycle : 55,
The following is the sample terminal output when running example [**ISR_8_PWMs_Array**](examples/ISR_8_PWMs_Array) on **AVR128DB** to demonstrate how to use multiple PWM channels with simple callback functions.
```
```cpp
Starting ISR_8_PWMs_Array on AVR128DB
Dx_Slow_PWM v1.0.2
CPU Frequency = 24 MHz
Expand All @@ -443,7 +446,7 @@ Starting ITimer1 OK, micros() = 12894

The following is the sample terminal output when running example [**ISR_8_PWMs_Array_Simple**](examples/ISR_8_PWMs_Array_Simple) on **AVR128DB** to demonstrate how to use multiple PWM channels.

```
```cpp
Starting ISR_8_PWMs_Array_Simple on AVR128DB
Dx_Slow_PWM v1.0.2
CPU Frequency = 24 MHz
Expand All @@ -457,7 +460,7 @@ Starting ITimer1 OK, micros() = 14169
The following is the sample terminal output when running example [ISR_Modify_PWM](examples/ISR_Modify_PWM) on **AVR128DB** to demonstrate how to modify PWM settings on-the-fly without deleting the PWM channel
```
```cpp
Starting ISR_Modify_PWM on AVR128DB
Dx_Slow_PWM v1.0.2
CPU Frequency = 24 MHz
Expand All @@ -472,7 +475,7 @@ Using PWM Freq = 2.00, PWM DutyCycle = 10.00

The following is the sample terminal output when running example [ISR_Changing_PWM](examples/ISR_Changing_PWM) on **AVR128DB** to demonstrate how to modify PWM settings on-the-fly by deleting the PWM channel and reinit the PWM channel

```
```cpp
Starting ISR_Changing_PWM on AVR128DB
Dx_Slow_PWM v1.0.2
CPU Frequency = 24 MHz
Expand Down Expand Up @@ -582,6 +585,6 @@ If you want to contribute to this project:

## Copyright

Copyright 2022- Khoi Hoang
Copyright (c) 2022- Khoi Hoang


11 changes: 10 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
## Dx_Slow_PWM Library
## Library

[![arduino-library-badge](https://www.ardu-badge.com/badge/Dx_Slow_PWM.svg?)](https://www.ardu-badge.com/Dx_Slow_PWM)
[![GitHub release](https://img.shields.io/github/release/khoih-prog/Dx_Slow_PWM.svg)](https://github.com/khoih-prog/Dx_Slow_PWM/releases)
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/Dx_Slow_PWM/blob/main/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/Dx_Slow_PWM.svg)](http://github.com/khoih-prog/Dx_Slow_PWM/issues)


<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
<a href="https://profile-counter.glitch.me/khoih-prog/count.svg" title="Total khoih-prog Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog/count.svg" style="height: 30px;width: 200px;"></a>
<a href="https://profile-counter.glitch.me/khoih-prog-Dx_Slow_PWM/count.svg" title="Dx_Slow_PWM Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-Dx_Slow_PWM/count.svg" style="height: 30px;width: 200px;"></a>

---
---

## Table of Contents

* [Changelog](#changelog)
Expand Down
45 changes: 26 additions & 19 deletions examples/ISR_8_PWMs_Array/ISR_8_PWMs_Array.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Built by Khoi Hoang https://github.com/khoih-prog/Dx_Slow_PWM
Licensed under MIT license
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
unsigned long miliseconds), you just consume only one AVRDx-based timer and avoid conflicting with other cores' tasks.
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
Expand All @@ -25,9 +25,9 @@
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
#define _PWM_LOGLEVEL_ 1

#if defined(__AVR_AVR128DA48__)
#if defined(__AVR_AVR128DA48__)
#define SerialDebug Serial1
#elif defined(__AVR_AVR128DB48__)
#elif defined(__AVR_AVR128DB48__)
#define SerialDebug Serial3
#else
// standard Serial
Expand Down Expand Up @@ -64,7 +64,7 @@
#elif USE_TIMER_4
#define CurrentTimer ITimer4
#else
#error You must select one Timer
#error You must select one Timer
#endif

#define USING_MICROS_RESOLUTION true //false
Expand All @@ -83,9 +83,9 @@
// To modify according to your board
// For Curiosity Nano AVR128DA48 => PIN_PC6
// For Curiosity Nano AVR128DB48 => PIN_PB3
#if defined(__AVR_AVR128DA48__)
#if defined(__AVR_AVR128DA48__)
#define LED_BUILTIN PIN_PC6 // PIN_PB3, 13
#elif defined(__AVR_AVR128DB48__)
#elif defined(__AVR_AVR128DB48__)
#define LED_BUILTIN PIN_PB3 // PIN_PC6, 13
#else
// standard Arduino pin 13
Expand All @@ -107,7 +107,7 @@ DX_SLOW_PWM_ISR ISR_PWM;
//////////////////////////////////////////////////////

void TimerHandler()
{
{
ISR_PWM.run();
}

Expand Down Expand Up @@ -184,27 +184,32 @@ void doingSomething7()

irqCallback irqCallbackStartFunc[] =
{
doingSomething0, doingSomething1, doingSomething2, doingSomething3,
doingSomething0, doingSomething1, doingSomething2, doingSomething3,
doingSomething4, doingSomething5, doingSomething6, doingSomething7
};

////////////////////////////////////////////////

void setup()
{
{
SerialDebug.begin(115200);

while (!SerialDebug && millis() < 5000);

SerialDebug.print(F("\nStarting ISR_8_PWMs_Array on ")); SerialDebug.println(BOARD_NAME);
SerialDebug.print(F("\nStarting ISR_8_PWMs_Array on "));
SerialDebug.println(BOARD_NAME);
SerialDebug.println(DX_SLOW_PWM_VERSION);
SerialDebug.print(F("CPU Frequency = ")); SerialDebug.print(F_CPU / 1000000); SerialDebug.println(F(" MHz"));
SerialDebug.print(F("Max number PWM channels = ")); SerialDebug.println(MAX_NUMBER_CHANNELS);
SerialDebug.print(F("CPU Frequency = "));
SerialDebug.print(F_CPU / 1000000);
SerialDebug.println(F(" MHz"));
SerialDebug.print(F("Max number PWM channels = "));
SerialDebug.println(MAX_NUMBER_CHANNELS);

SerialDebug.print(F("TCB Clock Frequency = "));
SerialDebug.print(F("TCB Clock Frequency = "));

#if USING_FULL_CLOCK
#if USING_FULL_CLOCK
SerialDebug.println(F("Full clock (24/16MHz, etc) for highest accuracy"));
#elif USING_HALF_CLOCK
#elif USING_HALF_CLOCK
SerialDebug.println(F("Half clock (12/8MHz, etc.) for high accuracy"));
#else
SerialDebug.println(F("250KHz for lower accuracy but longer time"));
Expand All @@ -216,24 +221,26 @@ void setup()

if (CurrentTimer.attachInterruptInterval(HW_TIMER_INTERVAL_MS, TimerHandler))
{
SerialDebug.print(F("Starting ITimer1 OK, micros() = ")); SerialDebug.println(micros());
SerialDebug.print(F("Starting ITimer1 OK, micros() = "));
SerialDebug.println(micros());
}
else
SerialDebug.println(F("Can't set CurrentTimer. Select another freq. or timer"));

#else

CurrentTimer.init();

if (CurrentTimer.attachInterrupt(HW_TIMER_INTERVAL_FREQ, TimerHandler))
{
SerialDebug.print(F("Starting ITimer1 OK, micros() = ")); SerialDebug.println(micros());
SerialDebug.print(F("Starting ITimer1 OK, micros() = "));
SerialDebug.println(micros());
}
else
SerialDebug.println(F("Can't set CurrentTimer. Select another freq. or timer"));

#endif // USING_HW_TIMER_INTERVAL_MS


// Just to demonstrate, don't use too many ISR Timers if not absolutely necessary
// You can use up to 16 timer for each ISR_PWM
Expand Down
Loading

0 comments on commit 49dd0c0

Please sign in to comment.