Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Arduino Core for SAMD21 CPU
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
josc941e
Arduino Core for SAMD21 CPU
Commits
74f76e9d
Commit
74f76e9d
authored
10 years ago
by
Cristian Maglie
Committed by
Cristian Maglie
10 years ago
Browse files
Options
Downloads
Plain Diff
Merge branch 'adc-write-res-fix' into zero
Conflicts: hardware/arduino/samd/cores/arduino/wiring_analog.c
parents
6c33c5d7
7c845895
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cores/arduino/wiring_analog.c
+29
-31
29 additions, 31 deletions
cores/arduino/wiring_analog.c
with
29 additions
and
31 deletions
cores/arduino/wiring_analog.c
+
29
−
31
View file @
74f76e9d
...
...
@@ -25,7 +25,8 @@ extern "C" {
#endif
static
int
_readResolution
=
10
;
static
int
_writeResolution
=
10
;
static
int
_ADCResolution
=
10
;
static
int
_writeResolution
=
8
;
// Wait for synchronization of registers between the clock domains
static
__inline__
void
syncADC
()
__attribute__
((
always_inline
,
unused
));
...
...
@@ -43,20 +44,23 @@ static void syncDAC() {
void
analogReadResolution
(
int
res
)
{
_readResolution
=
res
;
syncADC
();
switch
(
res
)
if
(
res
>
10
)
{
case
12
:
ADC
->
CTRLB
.
bit
.
RESSEL
=
ADC_CTRLB_RESSEL_12BIT_Val
;
break
;
case
8
:
ADC
->
CTRLB
.
bit
.
RESSEL
=
ADC_CTRLB_RESSEL_8BIT_Val
;
break
;
default:
ADC
->
CTRLB
.
bit
.
RESSEL
=
ADC_CTRLB_RESSEL_10BIT_Val
;
break
;
ADC
->
CTRLB
.
bit
.
RESSEL
=
ADC_CTRLB_RESSEL_12BIT_Val
;
_ADCResolution
=
12
;
}
else
if
(
res
>
8
)
{
ADC
->
CTRLB
.
bit
.
RESSEL
=
ADC_CTRLB_RESSEL_10BIT_Val
;
_ADCResolution
=
10
;
}
else
{
ADC
->
CTRLB
.
bit
.
RESSEL
=
ADC_CTRLB_RESSEL_8BIT_Val
;
_ADCResolution
=
8
;
}
_readResolution
=
res
;
}
void
analogWriteResolution
(
int
res
)
...
...
@@ -179,7 +183,7 @@ uint32_t analogRead( uint32_t ulPin )
ADC
->
CTRLA
.
bit
.
ENABLE
=
0x00
;
// Disable ADC
syncADC
();
return
valueRead
;
return
mapResolution
(
valueRead
,
_ADCResolution
,
_readResolution
)
;
}
...
...
@@ -190,11 +194,6 @@ uint32_t analogRead( uint32_t ulPin )
void
analogWrite
(
uint32_t
ulPin
,
uint32_t
ulValue
)
{
uint32_t
attr
=
g_APinDescription
[
ulPin
].
ulPinAttribute
;
// uint32_t pwm_name = g_APinDescription[ulPin].ulTCChannel ;
uint8_t
isTC
=
0
;
uint8_t
Channelx
;
Tc
*
TCx
=
0
;
Tcc
*
TCCx
=
0
;
if
(
(
attr
&
PIN_ATTR_ANALOG
)
==
PIN_ATTR_ANALOG
)
{
...
...
@@ -203,10 +202,12 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue )
return
;
}
ulValue
=
mapResolution
(
ulValue
,
_writeResolution
,
10
);
syncDAC
();
DAC
->
DATA
.
reg
=
ulValue
&
0x3FF
;
// DAC on 10 bits.
syncDAC
();
DAC
->
CTRLA
.
bit
.
ENABLE
=
0x01
;
//Enable
A
DC
DAC
->
CTRLA
.
bit
.
ENABLE
=
0x01
;
//
Enable D
A
C
syncDAC
();
return
;
}
...
...
@@ -218,15 +219,15 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue )
pinPeripheral
(
ulPin
,
g_APinDescription
[
ulPin
].
ulPinType
)
;
}
Channelx
=
GetTCChannelNumber
(
g_APinDescription
[
ulPin
].
ulPWMChannel
)
;
Tc
*
TCx
=
0
;
Tcc
*
TCCx
=
0
;
uint8_t
Channelx
=
GetTCChannelNumber
(
g_APinDescription
[
ulPin
].
ulPWMChannel
)
;
if
(
GetTCNumber
(
g_APinDescription
[
ulPin
].
ulPWMChannel
)
>=
TCC_INST_NUM
)
{
isTC
=
1
;
TCx
=
(
Tc
*
)
GetTC
(
g_APinDescription
[
ulPin
].
ulPWMChannel
)
;
}
else
{
isTC
=
0
;
TCCx
=
(
Tcc
*
)
GetTC
(
g_APinDescription
[
ulPin
].
ulPWMChannel
)
;
}
...
...
@@ -263,12 +264,12 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue )
ulValue
=
mapResolution
(
ulValue
,
_writeResolution
,
8
);
// Set PORT
if
(
is
TC
)
if
(
TC
x
)
{
// -- Configure TC
// D
ISABLE
TCx
TCx
->
COUNT8
.
CTRLA
.
reg
&=~
(
TC_CTRLA_ENABLE
)
;
// D
isable
TCx
TCx
->
COUNT8
.
CTRLA
.
reg
&=
~
TC_CTRLA_ENABLE
;
// Set Timer counter Mode to 8 bits
TCx
->
COUNT8
.
CTRLA
.
reg
|=
TC_CTRLA_MODE_COUNT8
;
// Set TCx as normal PWM
...
...
@@ -283,16 +284,15 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue )
else
{
// -- Configure TCC
// DISABLE TCCx
TCCx
->
CTRLA
.
reg
&=~
(
TCC_CTRLA_ENABLE
);
// Disable TCCx
TCCx
->
CTRLA
.
reg
&=
~
TCC_CTRLA_ENABLE
;
// Set TCx as normal PWM
TCCx
->
WAVE
.
reg
|=
TCC_WAVE_WAVEGEN_NPWM
;
// Set TCx in waveform mode Normal PWM
TCCx
->
CC
[
Channelx
].
reg
=
(
uint32_t
)
ulValue
;
// Set PER to maximum counter value (resolution : 0xFF)
TCCx
->
PER
.
reg
=
0xFF
;
// E
NABLE
TCCx
// E
nable
TCCx
TCCx
->
CTRLA
.
reg
|=
TCC_CTRLA_ENABLE
;
}
...
...
@@ -301,9 +301,7 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue )
// -- Defaults to digital write
pinMode
(
ulPin
,
OUTPUT
)
;
ulValue
=
mapResolution
(
ulValue
,
_writeResolution
,
8
);
if
(
ulValue
<
128
)
{
digitalWrite
(
ulPin
,
LOW
)
;
...
...
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