-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[example] Add SAMV71 Xplained Ultra timer example
- Loading branch information
1 parent
f642135
commit 95713ee
Showing
2 changed files
with
82 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,72 @@ | ||
/* | ||
* Copyright (c) 2023, Christopher Durand | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include <modm/board.hpp> | ||
#include <modm/platform/timer/timer_channel_0.hpp> | ||
#include <modm/platform/timer/timer_channel_10.hpp> | ||
|
||
using namespace Board; | ||
|
||
// use timer channel 10 to toggle led | ||
MODM_ISR(TC10) | ||
{ | ||
// clear interrupt flags by reading | ||
(void) TimerChannel10::getInterruptFlags(); | ||
Led0::toggle(); | ||
} | ||
|
||
using Tioa0 = GpioA0; | ||
|
||
|
||
int main() | ||
{ | ||
Board::initialize(); | ||
|
||
MODM_LOG_INFO << "Timer / Counter Test" << modm::endl; | ||
|
||
// generate 25% duty-cycle 100 kHz PWM waveform on TIOA0 output (GpioA0, output labeled D3 on board) | ||
TimerChannel0::initialize(); | ||
TimerChannel0::connect<Tioa0::Tioa>(); | ||
|
||
TimerChannel0::setClockSource(TimerChannel0::ClockSource::Mck); | ||
TimerChannel0::setWaveformMode(true); | ||
// Up-counter, reset on register C compare match | ||
TimerChannel0::setWaveformSelection(TimerChannel0::WavSel::Up_Rc); | ||
|
||
// Clear output on register A match, set on register C match | ||
TimerChannel0::setTioaEffects(TimerChannel0::TioEffect::Clear, TimerChannel0::TioEffect::Set); | ||
// period MCLK = 150 MHz / 1500 = 100 kHz | ||
// duty-cycle 375 / 1500 = 25% | ||
TimerChannel0::setRegA(375); | ||
TimerChannel0::setRegC(1500); | ||
TimerChannel0::enable(); | ||
TimerChannel0::start(); | ||
|
||
// setup timer channel 10 to run interrupt at ~1 Hz from ~32 kHz internal slow clock | ||
TimerChannel10::initialize(); | ||
TimerChannel10::setClockSource(TimerChannel10::ClockSource::Slck); | ||
// Toggle every 16384 / 32768 kHz = 0.5s => 1 Hz period | ||
TimerChannel10::setRegC(16384); | ||
TimerChannel10::setWaveformMode(true); | ||
TimerChannel10::setWaveformSelection(TimerChannel10::WavSel::Up_Rc); | ||
TimerChannel10::enableInterruptVector(true); | ||
TimerChannel10::enableInterrupt(TimerChannel10::Interrupt::RcCompare); | ||
TimerChannel10::enable(); | ||
TimerChannel10::start(); | ||
|
||
while (true) | ||
{ | ||
Led1::toggle(); | ||
modm::delay(500ms); | ||
} | ||
|
||
return 0; | ||
} |
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,10 @@ | ||
<library> | ||
<extends>modm:samv71-xplained-ultra</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/samv71_xplained_ultra/timer</option> | ||
</options> | ||
<modules> | ||
<module>modm:build:scons</module> | ||
<module>modm:platform:timer:*</module> | ||
</modules> | ||
</library> |