Skip to content

Commit fd44c36

Browse files
committed
[example] Add injected conversion ADC example for Nucleo H723ZG
1 parent 88b2be0 commit fd44c36

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2023, Christopher Durand
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#include <cstdint>
12+
#include <modm/board.hpp>
13+
14+
using namespace Board;
15+
16+
int main()
17+
{
18+
Board::initialize();
19+
20+
Adc1::connect<A0::Inp15, A1::Inp10>();
21+
Adc1::initialize(Adc1::ClockMode::SynchronousPrescaler4,
22+
Adc1::ClockSource::NoClock,
23+
Adc1::Prescaler::Disabled,
24+
Adc1::CalibrationMode::SingleEndedInputsMode);
25+
26+
MODM_LOG_INFO << "ADC Injected Conversion Test\n";
27+
28+
Adc1::setInjectedConversionSequenceLength(4);
29+
Adc1::setInjectedConversionChannel<A0>(0, Adc1::SampleTime::Cycles17);
30+
Adc1::setInjectedConversionChannel<A1>(1, Adc1::SampleTime::Cycles17);
31+
Adc1::setInjectedConversionChannel<A0>(2, Adc1::SampleTime::Cycles17);
32+
Adc1::setInjectedConversionChannel<A1>(3, Adc1::SampleTime::Cycles17);
33+
34+
while (true) {
35+
// start regular conversion
36+
Adc1::setPinChannel<A1>(Adc1::SampleTime::Cycles17);
37+
Adc1::startConversion();
38+
39+
Adc1::startInjectedConversionSequence();
40+
while (!Adc1::isInjectedConversionFinished());
41+
42+
MODM_LOG_INFO << "ADC1 CH15 (injected): " << Adc1::getInjectedConversionValue(0) << '\n';
43+
MODM_LOG_INFO << "ADC1 CH15 (injected): " << Adc1::getInjectedConversionValue(2) << '\n';
44+
MODM_LOG_INFO << "ADC1 CH10 (injected): " << Adc1::getInjectedConversionValue(1) << '\n';
45+
MODM_LOG_INFO << "ADC1 CH10 (injected): " << Adc1::getInjectedConversionValue(3) << '\n';
46+
47+
// wait for regular conversion to finish
48+
while (!Adc1::isConversionFinished());
49+
MODM_LOG_INFO << "ADC1 CH10 (regular): " << Adc1::getValue() << "\n\n";
50+
51+
Leds::toggle();
52+
modm::delay_ms(500);
53+
}
54+
55+
return 0;
56+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<library>
2+
<extends>modm:nucleo-h723zg</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/nucleo_h723zg/adc_injected_conversion</option>
5+
</options>
6+
<modules>
7+
<module>modm:build:scons</module>
8+
<module>modm:platform:adc:1</module>
9+
</modules>
10+
</library>

0 commit comments

Comments
 (0)