-
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 PWM example
- Loading branch information
1 parent
3534ba3
commit 190bc78
Showing
2 changed files
with
76 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,66 @@ | ||
/* | ||
* 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> | ||
|
||
using namespace Board; | ||
|
||
// Complementary output on PWM0 Channel2 High / Low outputs | ||
using OutH2 = GpioC19; | ||
using OutL2 = GpioD26; | ||
|
||
int main() | ||
{ | ||
Board::initialize(); | ||
|
||
MODM_LOG_INFO << "PWM Test" << modm::endl; | ||
|
||
Pwm0::connect<OutH2::PwmH2, OutL2::PwmL2>(); | ||
|
||
Pwm0::initialize(); | ||
// Period 1500 => MCLK / 1500 = 100 kHz | ||
Pwm0::setPeriod(Pwm0::Channel::Ch2, 1500); | ||
// 500/1500 = 33.3% duty-cycle | ||
Pwm0::setDutyCycle(Pwm0::Channel::Ch2, 500); | ||
|
||
constexpr auto mode = Pwm0::ChannelMode() | ||
.setClock(Pwm0::ChannelClock::Mck) | ||
.setDeadTimeGeneration(Pwm0::DeadTimeGeneration::Enabled); | ||
|
||
Pwm0::setChannelMode(Pwm0::Channel::Ch2, mode); | ||
|
||
// Set 50 ticks dead-time for both high and low output | ||
const auto deadTimeL = 50; // ticks | ||
const auto deadTimeH = 50; // ticks | ||
Pwm0::setDeadTime(Pwm0::Channel::Ch2, deadTimeL, deadTimeH); | ||
|
||
// Set all outputs to low in override mode | ||
Pwm0::configureOutputOverrideValues(Pwm0::Outputs_t{}); | ||
|
||
Pwm0::enableChannelOutput(Pwm0::Channels::Ch2); | ||
|
||
while (true) | ||
{ | ||
Led0::toggle(); | ||
Led1::toggle(); | ||
modm::delay(500ms); | ||
|
||
// Activate override mode to force outputs to low when button is pressed | ||
const auto outputs = Pwm0::Outputs::Ch2PwmH | Pwm0::Outputs::Ch2PwmL; | ||
if (ButtonSW0::read()) | ||
Pwm0::setOutputOverride(outputs, false); | ||
else | ||
Pwm0::clearOutputOverride(outputs, false); | ||
|
||
} | ||
|
||
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/pwm</option> | ||
</options> | ||
<modules> | ||
<module>modm:build:scons</module> | ||
<module>modm:platform:pwm:*</module> | ||
</modules> | ||
</library> |