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
7c845895
Commit
7c845895
authored
10 years ago
by
Cristian Maglie
Committed by
Cristian Maglie
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fixed analogWriteResolution behaviour
parent
daf34ae9
No related branches found
Branches containing commit
No related tags found
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
+14
-18
14 additions, 18 deletions
cores/arduino/wiring_analog.c
with
14 additions
and
18 deletions
cores/arduino/wiring_analog.c
+
14
−
18
View file @
7c845895
...
...
@@ -194,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
)
{
...
...
@@ -207,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
;
}
...
...
@@ -222,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
)
;
}
...
...
@@ -264,12 +261,14 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue )
break
;
}
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
...
...
@@ -284,16 +283,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
;
}
...
...
@@ -302,9 +300,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