Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
atsamd11
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pub
hello-world
atsamd11
Commits
aadc0347
Commit
aadc0347
authored
Dec 12, 2019
by
Erik Strand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expand analogRead
parent
641537e0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
1 deletion
+73
-1
adc/adc.ino
adc/adc.ino
+73
-1
No files found.
adc/adc.ino
View file @
aadc0347
#include "wiring_private.h"
#define LED_GREEN 23
#define SENSE_LINE_0 2
int
value
;
// Note that these values need to be kept in sync with the originals in analog_wiring.c.
static
int
_readResolution
=
10
;
static
int
_ADCResolution
=
10
;
// Wait for synchronization of registers between the clock domains
static
__inline__
void
syncADC
()
__attribute__
((
always_inline
,
unused
));
static
void
syncADC
()
{
while
(
ADC
->
STATUS
.
bit
.
SYNCBUSY
==
1
);
}
static
inline
uint32_t
mapResolution
(
uint32_t
value
,
uint32_t
from
,
uint32_t
to
)
{
if
(
from
==
to
)
{
return
value
;
}
if
(
from
>
to
)
{
return
value
>>
(
from
-
to
);
}
return
value
<<
(
to
-
from
);
}
uint32_t
bm_analogRead
(
uint32_t
pin
)
{
uint32_t
valueRead
=
0
;
// Uses a variable outside this translation unit
//if (!ADCinitialized) {
// initADC();
//}
#if defined(REMAP_ANALOG_PIN_ID)
REMAP_ANALOG_PIN_ID
(
pin
);
#endif
#if (SAMC21 || SAMD51)
Adc
*
ADC
;
if
(
(
g_APinDescription
[
pin
].
ulPeripheralAttribute
&
PER_ATTR_ADC_MASK
)
==
PER_ATTR_ADC_ALT
)
{
ADC
=
ADC1
;
}
else
{
ADC
=
ADC0
;
}
#endif
// pinPeripheral now handles disabling the DAC (if active)
if
(
pinPeripheral
(
pin
,
PIO_ANALOG_ADC
)
==
RET_STATUS_OK
)
{
ADC
->
INPUTCTRL
.
bit
.
MUXPOS
=
GetADC
(
pin
);
// Selection for the positive ADC input
syncADC
();
ADC
->
CTRLA
.
bit
.
ENABLE
=
0x01
;
// Enable ADC
syncADC
();
// Start conversion
ADC
->
SWTRIG
.
bit
.
START
=
1
;
syncADC
();
// Store the value
while
(
ADC
->
INTFLAG
.
bit
.
RESRDY
==
0
);
// Waiting for conversion to complete
valueRead
=
ADC
->
RESULT
.
reg
;
ADC
->
CTRLA
.
bit
.
ENABLE
=
0x00
;
// Disable ADC
syncADC
();
}
return
mapResolution
(
valueRead
,
_ADCResolution
,
_readResolution
);
}
void
setup
()
{
// put your setup code here, to run once:
Serial
.
begin
(
9600
);
pinMode
(
LED_GREEN
,
OUTPUT
);
// Calling the regular method once ensures that the ADC does get initialized.
analogRead
(
SENSE_LINE_0
);
}
void
loop
()
{
// put your main code here, to run repeatedly:
value
=
analogRead
(
SENSE_LINE_0
);
value
=
bm_
analogRead
(
SENSE_LINE_0
);
Serial
.
println
(
value
);
delay
(
1000
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment