Skip to content

Commit 076162d

Browse files
committed
lpc1756 adc changes
1 parent 5c695a9 commit 076162d

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

targets/core/nxp/lpc175x/adc.hpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ namespace klib::core::lpc175x::io {
6060
target::io::power_control::enable<Adc>();
6161

6262
// make the adc operational by setting the pdn
63-
// bit. FreeRun enables burst mode. That will
64-
// allow conversions up to 200 kHz
63+
// bit.
64+
Adc::port->CR = (0x1 << 21);
65+
66+
// Configure the ADC FreeRun enables burst mode.
67+
// That will allow conversions up to 200 kHz
6568
Adc::port->CR = (
6669
(Divider << 8) | (0x1 << 21) | (FreeRun << 16)
6770
);
@@ -85,15 +88,27 @@ namespace klib::core::lpc175x::io {
8588
// switch the gpio to adc mode
8689
target::io::detail::pins::set_peripheral<typename pin::pin, typename pin::periph>();
8790

88-
// init the channel
89-
Adc::port->CR |= (0x1 << Pin::analog_number);
91+
// check if we are in burst/freerun mode. If we are we need
92+
// to register our channel during init
93+
if (Adc::port->CR & (0x1 << 16)) {
94+
// init the channel
95+
Adc::port->CR |= (0x1 << Pin::analog_number);
96+
}
9097
}
9198

9299
/**
93100
* @brief Do a sample request.
94101
*
95102
*/
96103
static void sample() {
104+
// check if we are in burst/freerun mode. If we are we
105+
// are not we need to clear any other channel before
106+
// starting a sample
107+
if (!(Adc::port->CR & (0x1 << 16))) {
108+
// init the channel and clear all the other channels
109+
Adc::port->CR = (Adc::port->CR & (~0xff)) | (0x1 << Pin::analog_number);
110+
}
111+
97112
// Note: we sample all the enabled channels with this request
98113
adc<Adc>::sample();
99114
}

0 commit comments

Comments
 (0)