Skip to content

Commit

Permalink
[example] Add injected conversion ADC example for Nucleo H723ZG
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand committed Jul 27, 2023
1 parent 384dd9c commit 4d69227
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
56 changes: 56 additions & 0 deletions examples/nucleo_h723zg/adc_injected_conversion/main.cpp
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 examples/nucleo_h723zg/adc_injected_conversion/project.xml
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>

0 comments on commit 4d69227

Please sign in to comment.