Skip to content

Commit

Permalink
update build-CI, readme, badges (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart authored Nov 14, 2021
1 parent 3e4f0a7 commit 5d16007
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 38 deletions.
6 changes: 5 additions & 1 deletion .arduino-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
# - due
# - zero
- leonardo
# - m4
# - esp32
# - esp8266
- mega2560
10 changes: 7 additions & 3 deletions .github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ name: Arduino CI
on: [push, pull_request]

jobs:
arduino_ci:
runTest:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: Arduino-CI/action@master
# Arduino-CI/action@v0.1.1
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb
10 changes: 10 additions & 0 deletions PulsePattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ISR(TIMER1_COMPA_vect)
PPGenerator.worker();
}


PulsePattern::PulsePattern()
{
_size = 0;
Expand All @@ -42,6 +43,7 @@ PulsePattern::PulsePattern()
_pin = 0;
}


void PulsePattern::init(const uint8_t pin, const uint16_t * ar, const uint8_t size,
const uint8_t level, const uint8_t prescaler)
{
Expand All @@ -64,13 +66,15 @@ const uint8_t level, const uint8_t prescaler)
_pinbit = digitalPinToBitMask(_pin);
}


void PulsePattern::start()
{
if (_state == RUNNING) return; // no restart
_cnt = 0; // start from begin
cont();
}


void PulsePattern::cont()
{
if (_state == RUNNING) return; // no continue
Expand All @@ -79,6 +83,7 @@ void PulsePattern::cont()
_state = RUNNING;
}


void PulsePattern::stop()
{
stopTimer();
Expand All @@ -87,6 +92,7 @@ void PulsePattern::stop()
digitalWrite(_pin, _level);
}


void PulsePattern::worker()
{
if (_state != RUNNING) return;
Expand All @@ -109,13 +115,15 @@ void PulsePattern::worker()
if (_cnt >= _size) _cnt = 0; // repeat pattern
}


// TIMER code based upon - http://www.gammon.com.au/forum/?id=11504
void PulsePattern::stopTimer()
{
TCCR1A = 0; // reset timer 1
TCCR1B = 0;
}


void PulsePattern::setTimer(const uint16_t cc) const
{
TCCR1A = 0; // stop timer first
Expand All @@ -132,4 +140,6 @@ void PulsePattern::setTimer(const uint16_t cc) const
TIMSK1 = _BV (OCIE1A); // interrupt on Compare A Match
}


// -- END OF FILE --

1 change: 1 addition & 0 deletions PulsePattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ class PulsePattern

extern PulsePattern PPGenerator;


// -- END OF FILE --
60 changes: 34 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@

[![Arduino CI](https://github.com/RobTillaart/PulsePattern/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/PulsePattern/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/PulsePattern/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/PulsePattern/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/PulsePattern/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/PulsePattern/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/PulsePattern.svg?maxAge=3600)](https://github.com/RobTillaart/PulsePattern/releases)


# PulsePattern

Arduino Library to generate repeating pulse patterns **AVR ONLY**
Arduino Library to generate repeating pulse patterns **AVR ONLY**.


## Description

Expand All @@ -15,8 +18,8 @@ As the library uses **AVR hardware timers** it is definitely **NOT** working for
or other non-AVR processors.

The library uses timer1 for the timing of the pulses.
Therefor the class is implemented with a static instance called PPO.
Still by calling init() one can change all parameters of the process.
Therefore the class is implemented with a static instance called PPO.
Still by calling **init()** one can change all parameters of the process.
One should note that calling init() forces the timer to stop.

The timer code is based upon the website of Nick Gammon which
Expand All @@ -25,46 +28,51 @@ https://gammon.com.au/forum/bbshowpost.php?bbtopic_id=123

Use with care.

(there is no active development)


## Interface

- **PulsePattern()** constructor
- **init(pin, \*ar, size, level, prescaler)** initializer of the Timer1
- **void init(uint8_t pin, uint16_t\*ar, uint8_t size, luint8_t evel, uint8_t prescaler)** initializer of the Timer1
- pin that outputs the pattern
- array of durations
- size (or part) of the array to be used
- starting level HIGH/LOW
- prescaler, one of the 5 defines from .h file (table below)
- **setFactor(perc)** percentage = factor to correct timing (relative).
- **getFactor()** get the internal used factor. Due to rounding it can be slightly different.
- **stop()** stop the pattern generator
- **start()** start the pattern generator
- **cont()** continue the pattern generator from the last stopped place (approx).
- **isRunning()** status indicator
- **worker()** must be public otherwise the ISR cannot call it.
- **void setFactor(float perc)** percentage = factor to correct timing (relative).
- **float getFactor()** get the internal used factor. Due to rounding it can be slightly different.
- **void stop()** stop the pattern generator
- **void start()** start the pattern generator
- **void cont()** continue the pattern generator from the last stopped place (approx).
- **bool isRunning()** status indicator
- **void worker()** must be public otherwise the ISR cannot call it.

There is some bad understood __vector_11() error when worker() is private.


## Prescaler constants

| Value | Prescaler | Timer1 | notes |
|:----:|:----|:----|:----:|
| 0 | NO_CLOCK | timer off | |
| 1 | PRESCALE_1 | clk / 1 | |
| 2 | PRESCALE_8 | clk / 8 | |
| 3 | PRESCALE_64 | clk / 64 | |
| 4 | PRESCALE_256 | clk / 250 | |
| 5 | PRESCALE_1024 | clk / 1024 | about 1 ms / pulse |
| 6 | EXT_T1_FALLING | T1 = pin 5 | not tested |
| 7 | EXT_T2_RISING | | not tested |
| Value | Prescaler | Timer1 | Notes |
|:-----:|:---------------|:-----------|:-----------:|
| 0 | NO_CLOCK | timer off |
| 1 | PRESCALE_1 | clk / 1 |
| 2 | PRESCALE_8 | clk / 8 |
| 3 | PRESCALE_64 | clk / 64 |
| 4 | PRESCALE_256 | clk / 250 |
| 5 | PRESCALE_1024 | clk / 1024 | about 1 ms / pulse
| 6 | EXT_T1_FALLING | T1 = pin 5 | not tested
| 7 | EXT_T2_RISING | | not tested


# Operation

See examples.


## Future

- ESP32 variant of this class (baseclass -> AVR -> ESP class)
- ESP32 variant of this class (base class -> AVR -> ESP class)
- pulse recorder class to record / generate patterns

if time permits ...

# Operation

See example
9 changes: 8 additions & 1 deletion examples/SOS_demo2/SOS_demo2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
// AUTHOR: Rob Tillaart
// DATE: 2012-11-23
//
// PUPROSE: demo of the PulsePattern Library
// PURPOSE: demo of the PulsePattern Library
// uses timer1


#include "PulsePattern.h"


// a pattern consists of durations of LOW and HIGH periods
// so the first line of the SOSpattern is
// 500 units LOW, 500 units HIGH etc
Expand All @@ -22,9 +23,11 @@ uint16_t SOSpattern[] =
500,500,500,500,500,1500
};


uint8_t patternSize = 18;
uint8_t startLevel = LOW;


void setup()
{
Serial.begin(115200);
Expand All @@ -36,10 +39,14 @@ void setup()
PPGenerator.start();
}


void loop()
{
// dummy code
Serial.println(millis());
delay(1000);
}


// -- END OF FILE --

7 changes: 7 additions & 0 deletions examples/pattern_recorder/pattern_recorder.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@
// PURPOSE: records and writes a pattern to serial
// DATE: 2020-07-25


#include "Arduino.h"


uint8_t pin = 4;
uint16_t minDuration = 50;
uint16_t units = 10;
uint32_t counter = 0;
uint32_t sum = 0;


void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
}


void loop()
{
uint32_t duration = recordPulse(pin, units, minDuration);
Expand All @@ -29,6 +33,7 @@ void loop()
Serial.println(sum/counter);
}


uint32_t recordPulse(uint8_t pin, uint16_t unit, uint16_t minperiod)
{
static uint8_t state;
Expand Down Expand Up @@ -57,4 +62,6 @@ uint32_t recordPulse(uint8_t pin, uint16_t unit, uint16_t minperiod)
return duration;
}


// -- END OF FILE --

3 changes: 3 additions & 0 deletions examples/pulse_measure/pulse_measure.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// - generate with one Arduino a pulse of 1000 ms
// - measure it with this sketch to determine the correction percentage


#include "Arduino.h"

// measure pin = A5 on UNO
Expand Down Expand Up @@ -78,4 +79,6 @@ uint32_t recordPulse(uint8_t pin, uint16_t unit, uint16_t minperiod)
return duration;
}


// -- END OF FILE --

10 changes: 7 additions & 3 deletions examples/pulse_sender/pulse_sender.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// AUTHOR: Rob Tillaart
// DATE: 2020-08-08
//
// PUPROSE: for callibrating the pulselength
// PURPOSE: for calibrating the pulse length
// uses timer1
//

// This sketch sends a testpattern of 1000 ms LOW and 1000 ms HIGH ==> Duty Cycle = 50%
// This sketch sends a test pattern of 1000 ms LOW and 1000 ms HIGH ==> Duty Cycle = 50%
// From measuring the duration of the pulses one can derive the correction factor to adjust the timing.
//
// Pulse sender used an UNO R3 board.
Expand All @@ -17,7 +17,7 @@
// 2: Saleae Logic analyzer 2.3.4 Alpha
//
// The correction factor was not identical but close -2.46% vs -2.78%
// The Saleae gave a pulselength after correction of 999.99 mSec so pretty good for UNO.
// The Saleae gave a pulse length after correction of 999.99 mSec so pretty good for UNO.
// Currently the correction factor is in steps of 1/4096, to get in the order of 0.1% accuracy


Expand All @@ -26,6 +26,7 @@
// CODE STARTS HERE
//


#include "PulsePattern.h"

// uint16_t test_pattern[] = { 1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100,200,300,400,500,600,700,800,900,1000,2000,3000,4000,5000};
Expand Down Expand Up @@ -55,8 +56,11 @@ void setup()
PPGenerator.start();
}


void loop()
{
}


// -- END OF FILE --

8 changes: 7 additions & 1 deletion examples/random_pattern/random_pattern.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
// AUTHOR: Rob Tillaart
// DATE: 2020-07-04
//
// PUPROSE: demo of the PulsePattern Library
// PURPOSE: demo of the PulsePattern Library
// uses timer1
//


#include "PulsePattern.h"


// a pattern constants of durations of LOW and HIGH periods
// so the first line of the SOSpattern

Expand All @@ -20,6 +22,7 @@ uint16_t random_pattern[] = { 500, 500 };
uint8_t patternSize = 2;
uint8_t startLevel = LOW;


void setup()
{
Serial.begin(115200);
Expand All @@ -31,6 +34,7 @@ void setup()
PPGenerator.start();
}


void loop()
{
random_pattern[0] = 100 + millis() % 1000;
Expand All @@ -46,4 +50,6 @@ void loop()
delay(5000);
}


// -- END OF FILE --

Loading

0 comments on commit 5d16007

Please sign in to comment.