Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
multipass
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
derf
multipass
Commits
bf974ab8
Unverified
Commit
bf974ab8
authored
3 years ago
by
Birte Kristina Friesel
Browse files
Options
Downloads
Patches
Plain Diff
arduino nano adc: add getPin_mV function
parent
56dc720d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/arch/arduino-nano/driver/adc.h
+1
-0
1 addition, 0 deletions
include/arch/arduino-nano/driver/adc.h
src/arch/arduino-nano/driver/adc.cc
+36
-0
36 additions, 0 deletions
src/arch/arduino-nano/driver/adc.cc
with
37 additions
and
0 deletions
include/arch/arduino-nano/driver/adc.h
+
1
−
0
View file @
bf974ab8
...
...
@@ -17,6 +17,7 @@ class AVRADC {
int16_t
getTemp_mdegC
(
int16_t
offset
=
205
);
uint16_t
getVCC_mV
();
uint16_t
getPin_mV
(
uint8_t
pin
,
uint16_t
avcc
=
0
);
};
extern
AVRADC
adc
;
...
...
This diff is collapsed.
Click to expand it.
src/arch/arduino-nano/driver/adc.cc
+
36
−
0
View file @
bf974ab8
...
...
@@ -8,6 +8,42 @@
#include
"arch.h"
#include
"driver/adc.h"
uint16_t
AVRADC
::
getPin_mV
(
uint8_t
pin
,
uint16_t
avcc
)
{
if
(
avcc
)
{
// measure with AVCC reference
ADMUX
=
_BV
(
REFS0
)
|
pin
;
}
else
{
// measure with internal 1.1V bandgap refernce
ADMUX
=
_BV
(
REFS1
)
|
_BV
(
REFS0
)
|
pin
;
}
// Enable ADC with /64 prescaler
ADCSRA
=
_BV
(
ADEN
)
|
_BV
(
ADPS2
);
// Wait for bandgap to stabilise (70us according to datasheet table 28-3)
arch
.
delay_ms
(
1
);
// Start conversion
ADCSRA
|=
_BV
(
ADSC
);
// wait until conversion is complete
while
(
ADCSRA
&
_BV
(
ADSC
))
;
uint8_t
adcr_l
=
ADCL
;
uint8_t
adcr_h
=
ADCH
;
uint16_t
adcr
=
adcr_l
+
(
adcr_h
<<
8
);
// Disable ADC
ADCSRA
&=
~
_BV
(
ADEN
);
if
(
avcc
)
{
return
(
uint32_t
)
avcc
*
adcr
/
1023L
;
}
else
{
return
1100L
*
adcr
/
1023L
;
}
}
int16_t
AVRADC
::
getTemp_mdegC
(
int16_t
offset
)
{
// Measure temperature probe with 1.1V bandgap reference
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment