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
Compare Revisions
e9207f0563c36df419a167a2694ec8cf7dd2fe78...a7c47f54bedb46f1acffc0dc85dee0c94787a70c
Source
a7c47f54bedb46f1acffc0dc85dee0c94787a70c
Select Git revision
...
Target
e9207f0563c36df419a167a2694ec8cf7dd2fe78
Select Git revision
Compare
Commits (2)
Wiggle the line with a digital output
· 87cf858b
Erik Strand
authored
Dec 12, 2019
This makes it easier to sanity check what I'm reading.
87cf858b
Remove call to pinPeripheral
· a7c47f54
Erik Strand
authored
Dec 12, 2019
a7c47f54
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
12 deletions
+46
-12
adc/adc.ino
adc/adc.ino
+46
-12
No files found.
adc/adc.ino
View file @
a7c47f54
#include "wiring_private.h"
#define LED_GREEN 23
#define CHARGE_LINE_0 14
#define SENSE_LINE_0 2
int
value
;
...
...
@@ -24,14 +25,36 @@ static inline uint32_t mapResolution(uint32_t value, uint32_t from, uint32_t to)
return
value
<<
(
to
-
from
);
}
void
init_pin_adc
(
uint32_t
pin
)
{
uint8_t
const
pinPort
=
GetPort
(
pin
);
uint8_t
const
pinNum
=
GetPin
(
pin
);
// Preserve state of pullup/pulldown enable, clear the rest of the bits
uint8_t
pinCfg
=
(
PORT
->
Group
[
pinPort
].
PINCFG
[
pinNum
].
reg
&
PORT_PINCFG_PULLEN
);
if
(
pinNum
&
1
)
// is pin odd?
{
// Get whole current setup for both odd and even pins and remove odd one, then set new muxing
uint32_t
temp
=
(
PORT
->
Group
[
pinPort
].
PMUX
[
pinNum
>>
1
].
reg
)
&
PORT_PMUX_PMUXE
(
0xF
)
;
PORT
->
Group
[
pinPort
].
PMUX
[
pinNum
>>
1
].
reg
=
temp
|
PORT_PMUX_PMUXO
(
PER_ANALOG
)
;
}
else
// even pin
{
// Get whole current setup for both odd and even pins and remove even one, then set new muxing
uint32_t
temp
=
(
PORT
->
Group
[
pinPort
].
PMUX
[
pinNum
>>
1
].
reg
)
&
PORT_PMUX_PMUXO
(
0xF
)
;
PORT
->
Group
[
pinPort
].
PMUX
[
pinNum
>>
1
].
reg
=
temp
|
PORT_PMUX_PMUXE
(
PER_ANALOG
)
;
}
pinCfg
|=
PORT_PINCFG_PMUXEN
;
// Enable peripheral mux
// Set pin drive strength, enable/disable pull resistor, enable/disable INEN, and enable/disable the peripheral mux
PORT
->
Group
[
pinPort
].
PINCFG
[
pinNum
].
reg
=
(
uint8_t
)
pinCfg
;
}
uint32_t
bm_analogRead
(
uint32_t
pin
)
{
uint32_t
valueRead
=
0
;
// pinPeripheral now handles disabling the DAC (if active)
if
(
pinPeripheral
(
pin
,
PIO_ANALOG_ADC
)
==
RET_STATUS_OK
)
{
// Start conversion
ADC
->
SWTRIG
.
bit
.
START
=
1
;
syncADC
();
...
...
@@ -39,20 +62,24 @@ uint32_t bm_analogRead( uint32_t pin )
// Store the value
while
(
ADC
->
INTFLAG
.
bit
.
RESRDY
==
0
);
// Waiting for conversion to complete
valueRead
=
ADC
->
RESULT
.
reg
;
}
return
mapResolution
(
valueRead
,
_ADCResolution
,
_readResolution
);
}
void
setup
()
{
// put your setup code here, to run once:
Serial
.
begin
(
9600
);
pinMode
(
LED_GREEN
,
OUTPUT
);
pinMode
(
CHARGE_LINE_0
,
OUTPUT
);
digitalWrite
(
CHARGE_LINE_0
,
LOW
);
// Initialize the ADC
initADC
();
// Everything seems to function if I don't do this, but I'm leaving it in until I have a chance
// to investigate what's happening.
init_pin_adc
(
SENSE_LINE_0
);
// Selection for the positive ADC input
ADC
->
INPUTCTRL
.
bit
.
MUXPOS
=
GetADC
(
SENSE_LINE_0
);
syncADC
();
...
...
@@ -63,8 +90,15 @@ void setup() {
}
void
loop
()
{
// put your main code here, to run repeatedly:
digitalWrite
(
CHARGE_LINE_0
,
LOW
);
delay
(
1000
);
value
=
bm_analogRead
(
SENSE_LINE_0
);
Serial
.
println
(
value
);
digitalWrite
(
CHARGE_LINE_0
,
HIGH
);
delay
(
1000
);
value
=
bm_analogRead
(
SENSE_LINE_0
);
Serial
.
println
(
value
);
}