-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmulti_adc.cpp
More file actions
51 lines (42 loc) · 1.99 KB
/
Copy pathmulti_adc.cpp
File metadata and controls
51 lines (42 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* This example shows off the use of the ADC. Two pins are setup for ADC
* functionality and the values are continuously read in and printed over
* UART.
*/
#include <core/io/ADC.hpp>
#include <core/io/UART.hpp>
#include <core/manager.hpp>
#include <core/utils/log.hpp>
#include <core/utils/time.hpp>
namespace io = core::io;
namespace time = core::time;
int main() {
// Initialize system
core::platform::init();
io::UART& uart = io::getUART<io::Pin::UART_TX, io::Pin::UART_RX>(9600);
// Set up the logger to catch errors in ADC creation
core::log::LOGGER.setUART(&uart);
core::log::LOGGER.setLogLevel(core::log::Logger::LogLevel::INFO);
uart.printf("Starting ADC test\r\n");
time::wait(500);
io::ADC& adc0 = io::getADC<io::Pin::PA_0, io::ADCPeriph::ONE>();
io::ADC& adc1 = io::getADC<io::Pin::PC_4, io::ADCPeriph::ONE>();
// Optional: Set custom VREF voltage (default is 3.3V)
// adc0.setVref(5.0f); // For 5V reference
// adc1.setVref(1.8f); // For 1.8V reference
while (1) {
core::log::LOGGER.log(core::log::Logger::LogLevel::INFO, "--------------------");
core::log::LOGGER.log(
core::log::Logger::LogLevel::INFO, "ADC0 : %d mV", static_cast<uint32_t>(adc0.read() * 1000));
core::log::LOGGER.log(
core::log::Logger::LogLevel::INFO, "ADC0: %d%%", static_cast<uint32_t>(adc0.readPercentage() * 100));
core::log::LOGGER.log(core::log::Logger::LogLevel::INFO, "ADC0 raw: %d", adc0.readRaw());
core::log::LOGGER.log(
core::log::Logger::LogLevel::INFO, "ADC1 : %d mV", static_cast<uint32_t>(adc1.read() * 1000));
core::log::LOGGER.log(
core::log::Logger::LogLevel::INFO, "ADC1: %d%%", static_cast<uint32_t>(adc1.readPercentage() * 100));
core::log::LOGGER.log(core::log::Logger::LogLevel::INFO, "ADC1 raw: %d", adc1.readRaw());
core::log::LOGGER.log(core::log::Logger::LogLevel::INFO, "--------------------\r\n");
time::wait(500);
}
}