2 unstable releases
0.2.0 | Mar 16, 2020 |
---|---|
0.1.0 | Mar 8, 2020 |
#1812 in Embedded development
70KB
1.5K
SLoC
SAMD Timer
High-level API for the TCC/TC peripherals found on the Microchip SAMD and SAME MCUs.
This library is usable (as in I use it), but could contain bugs. USE AT YOUR OWN RISK.
This library provides the Timer
and ControlTimer
types for working safely with TC
and TCC
peripherals respectively. Full support for waveform generation capabilities, double buffering, and capture modes.
Provides finer grain control over your timers than the abstraction used by atsamd-hal
. Simply drop in the library; it works with the atsamd-hal
clock system.
Usage
Add the following line to your Cargo.toml
.
samd-timer = "0.2.0"
The following feature flags control which MCU variant you are targetting.
Name | # TC | # TCC | Boards |
---|---|---|---|
samd21g18a | 3 | 3 | Circuit Playground Express, Feather M0, Metro M0, MKR ZERO, SAMD21 Mini, SODAQ ONE |
samd21e18a | 3 | 3 | Gemma M0, Trinket M0, Serpente |
samd21j18a | 5 | 3 | SODAQ SARA AFF |
samd51j19a | 6 | 5 | EdgeBadge, Feather M4, Metro M4 |
samd51j20a | 6 | 5 | PyPortal |
samd51g19a | 4 | 3 | ItsyBitsy M4, Trellis M4 |
same54p20a | 8 | 5 | PathfinderZA Proto1 |
Example
use atsamd_hal::target_device::Peripherals;
use atsamd_hal::clock::GenericClockController;
use samd_timer::{TimerConfig, Timer, Prescaler, Synchronization, TimerWaveGen};
fn main() {
let mut peri = Peripherals.take().unwrap();
let mut clocks = GenericClockController::with_internal_32kosc(
peri.GCLCK,
&mut peri.MCLK,
&mut peri.OSC32KCTRL,
&mut peri.OSCCTRL,
&mut peri.NVMCTRL
);
let timer_clock = clocks.gclk1();
let tc_clock = clocks.tc0_tc1(&timer_clock).unwrap();
/// Create a 8-bit width timer configuration.
let mut config = TimerConfig::count8();
config.prescaler(Prescaler::Div64)
.sync(Synchronization::Prescaler)
.wave_gen(TimerWaveGen::NPWM);
/// Initialise the timer instance.
let mut timer = config.tc0(&mut peri.MCLK, &tc_clock, peri.TC0);
// Output a PWM wave with a period of 2 secs and duty cycle of 50%
timer.set_period(999);
timer.set_cc0(499);
timer.enable();
}
Features
TCC
- One-Shot Operation
- Interrupt Control
- Direction changing
- Waveform Generation
- Waveform Output Inversion
- Dithering
- Dead-time Insertion Generator
- Output Matrixing
- Pattern Generation
- Fault Control
- Event Control
- Master-Slave Operation
- Double Buffering
TC
- 8-bit mode (incl. PER register)
- 16-bit mode
- 32-bit mode
- Interrupt Control
- One-Shot Operation
- Direction changing
- Waveform Generation
- Waveform Output Inversion
- Capture Channels
- Event Control
- Double Buffering (SAMx5x)
- Capture Modes (SAMx5x)
- Capture on Pin (SAMx5x)
License
samd-timer
is distributed under the MIT license. See the LICENSE file for the full text of the license.
Dependencies
~3.5–9MB
~244K SLoC