mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.6 PulsePattern
This commit is contained in:
parent
91689da35e
commit
f51785194d
@ -1,5 +1,21 @@
|
||||
platforms:
|
||||
rpipico:
|
||||
board: rp2040:rp2040:rpipico
|
||||
package: rp2040:rp2040
|
||||
gcc:
|
||||
features:
|
||||
defines:
|
||||
- ARDUINO_ARCH_RP2040
|
||||
warnings:
|
||||
flags:
|
||||
|
||||
packages:
|
||||
rp2040:rp2040:
|
||||
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
|
||||
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
# selected only those that work
|
||||
platforms:
|
||||
- uno
|
||||
# - due
|
||||
@ -9,3 +25,4 @@ compile:
|
||||
# - esp32
|
||||
# - esp8266
|
||||
- mega2560
|
||||
# - rpipico
|
||||
|
61
libraries/PulsePattern/CHANGELOG.md
Normal file
61
libraries/PulsePattern/CHANGELOG.md
Normal file
@ -0,0 +1,61 @@
|
||||
# Change Log PulsePattern
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.6] - 2022-11-22
|
||||
- add changelog.md
|
||||
- add RP2040 to build-CI (commented as non AVR is not supported yet)
|
||||
|
||||
|
||||
## [0.1.5] - 2022-03-10
|
||||
- add times to start(), 0 = continuous mode
|
||||
|
||||
## [0.1.4] - 2021-12-24
|
||||
- update library.json, license, minor edits
|
||||
|
||||
## [0.1.3] - 2021-01-06
|
||||
- Arduino-CI (no unit test)
|
||||
|
||||
## [0.1.2] - 2020-08-07
|
||||
- speed up toggle pin
|
||||
- get/setFactor()
|
||||
|
||||
## [0.1.1] - 2020-07-04
|
||||
- add continue function
|
||||
- fix spaces.
|
||||
|
||||
## [0.1.0] - 2020-06-19
|
||||
- #pragma once
|
||||
- remove pre 1.0 support
|
||||
- refactor
|
||||
|
||||
----
|
||||
|
||||
## [0.0.8] - 2018-12-13
|
||||
- refactor -> remove some warnings
|
||||
|
||||
## [0.0.7] - 2017-07-16
|
||||
- refactor & review
|
||||
|
||||
## [0.0.6] - 2015-04-18
|
||||
- completed the state machine
|
||||
|
||||
## [0.0.5] - 2012-12-27
|
||||
- code clean up + comment
|
||||
|
||||
## [0.0.4] - 2012-12-27
|
||||
- code stable(?) enough to publish
|
||||
|
||||
## [0.0.3] - 2012-12-27
|
||||
- renamed to PulsePattern
|
||||
|
||||
## [0.0.2] - 2012-11-23
|
||||
- adapted a static PPO
|
||||
|
||||
## [0.0.1] - 2012-11-23
|
||||
- initial version
|
||||
|
@ -1,31 +1,16 @@
|
||||
//
|
||||
// FILE: PulsePattern.cpp
|
||||
// AUTHOR: Rob dot Tillaart at gmail dot com
|
||||
// VERSION: 0.1.5
|
||||
// VERSION: 0.1.6
|
||||
// DATE: 2012-11-23
|
||||
// PURPOSE: Arduino Library to generate repeating pulse patterns
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.0.1 2012-11-23 initial version
|
||||
// 0.0.2 2012-11-23 adapted a static PPO
|
||||
// 0.0.3 2012-12-27 renamed to PulsePattern
|
||||
// 0.0.4 2012-12-27 code stable(?) enough to publish
|
||||
// 0.0.5 2012-12-27 code clean up + comment
|
||||
// 0.0.6 2015-04-18 completed the state machine
|
||||
// 0.0.7 2017-07-16 refactor & review
|
||||
// 0.0.8 2018-12-13 refactor -> remove some warnings
|
||||
// 0.1.0 2020-06-19 #pragma once; remove pre 1.0 support; refactor
|
||||
// 0.1.1 2020-07-04 add continue function, fix spaces.
|
||||
// 0.1.2 2020-08-07 speed up toggle pin + get/setFactor()
|
||||
// 0.1.3 2021-01-06 Arduino-CI (no unit test)
|
||||
// 0.1.4 2021-12-24 update library.json, license, minor edits
|
||||
// 0.1.5 2022-03-10 add times to start(), 0 = continuous mode
|
||||
|
||||
|
||||
#include "PulsePattern.h"
|
||||
|
||||
|
||||
// Predefined generator (singleton)
|
||||
// Predefined generator (singleton)
|
||||
PulsePattern PPGenerator;
|
||||
|
||||
|
||||
@ -72,8 +57,8 @@ const uint8_t level, const uint8_t prescaler)
|
||||
|
||||
void PulsePattern::start(uint32_t times)
|
||||
{
|
||||
if (_state == RUNNING) return; // no restart
|
||||
_cnt = 0; // start from begin
|
||||
if (_state == RUNNING) return; // no restart
|
||||
_cnt = 0; // start from begin
|
||||
_times = times;
|
||||
cont();
|
||||
}
|
||||
@ -81,9 +66,9 @@ void PulsePattern::start(uint32_t times)
|
||||
|
||||
void PulsePattern::cont()
|
||||
{
|
||||
if (_state == RUNNING) return; // no continue
|
||||
if (_size == 0) return; // no pattern
|
||||
setTimer(1); // start asap
|
||||
if (_state == RUNNING) return; // no continue
|
||||
if (_size == 0) return; // no pattern
|
||||
setTimer(1); // start asap
|
||||
_state = RUNNING;
|
||||
}
|
||||
|
||||
@ -100,10 +85,10 @@ void PulsePattern::stop()
|
||||
void PulsePattern::worker()
|
||||
{
|
||||
if (_state != RUNNING) return;
|
||||
// set next period & flip signal
|
||||
// set next period & flip signal
|
||||
_level = !_level;
|
||||
// digitalWrite(_pin, _level);
|
||||
// direct port much faster
|
||||
// digitalWrite(_pin, _level);
|
||||
// direct port much faster
|
||||
if (_level == 0) *_pinout &= ~_pinbit;
|
||||
else *_pinout |= _pinbit;
|
||||
|
||||
@ -136,7 +121,7 @@ void PulsePattern::worker()
|
||||
}
|
||||
|
||||
|
||||
// TIMER code based upon - http://www.gammon.com.au/forum/?id=11504
|
||||
// TIMER code based upon - http://www.gammon.com.au/forum/?id=11504
|
||||
void PulsePattern::stopTimer()
|
||||
{
|
||||
TCCR1A = 0; // reset timer 1
|
||||
@ -146,20 +131,20 @@ void PulsePattern::stopTimer()
|
||||
|
||||
void PulsePattern::setTimer(const uint16_t cc) const
|
||||
{
|
||||
TCCR1A = 0; // stop timer first
|
||||
TCCR1A = 0; // stop timer first
|
||||
TCCR1B = 0;
|
||||
TCNT1 = 0; // reset counter
|
||||
OCR1A = cc * 16; // compare A register value;
|
||||
// * 16 makes max period 4095
|
||||
// min period 12?
|
||||
TCNT1 = 0; // reset counter
|
||||
OCR1A = cc * 16; // compare A register value;
|
||||
// * 16 makes max period 4095
|
||||
// min period 12?
|
||||
|
||||
// 4: CTC mode, top = OCR1A
|
||||
TCCR1A = _BV (COM1A1); // clear on compare
|
||||
// 4: CTC mode, top = OCR1A
|
||||
TCCR1A = _BV (COM1A1); // clear on compare
|
||||
TCCR1B = _BV (WGM12) | _prescaler;
|
||||
TIFR1 |= _BV (OCF1A); // clear interrupt flag
|
||||
TIMSK1 = _BV (OCIE1A); // interrupt on Compare A Match
|
||||
TIFR1 |= _BV (OCF1A); // clear interrupt flag
|
||||
TIMSK1 = _BV (OCIE1A); // interrupt on Compare A Match
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: PulsePattern.h
|
||||
// AUTHOR: Rob dot Tillaart at gmail dot com
|
||||
// VERSION: 0.1.5
|
||||
// VERSION: 0.1.6
|
||||
// DATE: 2012-11-23
|
||||
// PURPOSE: Arduino Library to generate repeating pulse patterns
|
||||
// sends a pulse pattern to a digital pin (continuously)
|
||||
@ -17,7 +17,7 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#define PULSEPATTERN_LIB_VERSION (F("0.1.5"))
|
||||
#define PULSEPATTERN_LIB_VERSION (F("0.1.6"))
|
||||
|
||||
// RUNNING STATES
|
||||
#define NOTINIT -1
|
||||
@ -25,14 +25,14 @@
|
||||
#define RUNNING 1
|
||||
|
||||
// PRESCALER CONSTANTS
|
||||
#define NO_CLOCK 0 // timer off
|
||||
#define NO_CLOCK 0 // timer off
|
||||
#define PRESCALE_1 1
|
||||
#define PRESCALE_8 2
|
||||
#define PRESCALE_64 3
|
||||
#define PRESCALE_256 4
|
||||
#define PRESCALE_1024 5
|
||||
#define EXT_T1_FALLING 6 // external clock
|
||||
#define EXT_T2_RISING 7 // external clock
|
||||
#define EXT_T1_FALLING 6 // external clock
|
||||
#define EXT_T2_RISING 7 // external clock
|
||||
|
||||
// RUNNING MODE
|
||||
#define PP_ONCE 1
|
||||
@ -78,4 +78,4 @@ private:
|
||||
extern PulsePattern PPGenerator;
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/PulsePattern.git"
|
||||
},
|
||||
"version": "0.1.5",
|
||||
"version": "0.1.6",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "avr",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=PulsePattern
|
||||
version=0.1.5
|
||||
version=0.1.6
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library to generate repeating pulse patterns. (AVR only)
|
||||
|
Loading…
Reference in New Issue
Block a user