-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[example] Add injected conversion ADC example for Nucleo H723ZG
- Loading branch information
1 parent
384dd9c
commit 4d69227
Showing
2 changed files
with
66 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,56 @@ | ||
/* | ||
* 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 <cstdint> | ||
#include <modm/board.hpp> | ||
|
||
using namespace Board; | ||
|
||
int main() | ||
{ | ||
Board::initialize(); | ||
|
||
Adc1::connect<A0::Inp15, A1::Inp10>(); | ||
Adc1::initialize(Adc1::ClockMode::SynchronousPrescaler4, | ||
Adc1::ClockSource::NoClock, | ||
Adc1::Prescaler::Disabled, | ||
Adc1::CalibrationMode::SingleEndedInputsMode); | ||
|
||
MODM_LOG_INFO << "ADC Injected Conversion Test\n"; | ||
|
||
Adc1::setInjectedConversionSequenceLength(4); | ||
Adc1::setInjectedConversionChannel<A0>(0, Adc1::SampleTime::Cycles17); | ||
Adc1::setInjectedConversionChannel<A1>(1, Adc1::SampleTime::Cycles17); | ||
Adc1::setInjectedConversionChannel<A0>(2, Adc1::SampleTime::Cycles17); | ||
Adc1::setInjectedConversionChannel<A1>(3, Adc1::SampleTime::Cycles17); | ||
|
||
while (true) { | ||
// start regular conversion | ||
Adc1::setPinChannel<A1>(Adc1::SampleTime::Cycles17); | ||
Adc1::startConversion(); | ||
|
||
Adc1::startInjectedConversionSequence(); | ||
while (!Adc1::isInjectedConversionFinished()); | ||
|
||
MODM_LOG_INFO << "ADC1 CH15 (injected): " << Adc1::getInjectedConversionValue(0) << '\n'; | ||
MODM_LOG_INFO << "ADC1 CH15 (injected): " << Adc1::getInjectedConversionValue(2) << '\n'; | ||
MODM_LOG_INFO << "ADC1 CH10 (injected): " << Adc1::getInjectedConversionValue(1) << '\n'; | ||
MODM_LOG_INFO << "ADC1 CH10 (injected): " << Adc1::getInjectedConversionValue(3) << '\n'; | ||
|
||
// wait for regular conversion to finish | ||
while (!Adc1::isConversionFinished()); | ||
MODM_LOG_INFO << "ADC1 CH10 (regular): " << Adc1::getValue() << "\n\n"; | ||
|
||
Leds::toggle(); | ||
modm::delay_ms(500); | ||
} | ||
|
||
return 0; | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/nucleo_h723zg/adc_injected_conversion/project.xml
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:nucleo-h723zg</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo_h723zg/adc_injected_conversion</option> | ||
</options> | ||
<modules> | ||
<module>modm:build:scons</module> | ||
<module>modm:platform:adc:1</module> | ||
</modules> | ||
</library> |