Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-esp32
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-esp32
Commits
dbeae948
Unverified
Commit
dbeae948
authored
Dec 08, 2022
by
Jan Procházka
Committed by
GitHub
Dec 08, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AnalogWrite - frequency and resolution log errors + returns (#7471)
* Added log errors + returns * Update LEDC docs
parent
394f7218
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
4 deletions
+35
-4
cores/esp32/esp32-hal-ledc.c
cores/esp32/esp32-hal-ledc.c
+13
-4
docs/source/api/ledc.rst
docs/source/api/ledc.rst
+22
-0
No files found.
cores/esp32/esp32-hal-ledc.c
View file @
dbeae948
...
...
@@ -222,9 +222,12 @@ void analogWrite(uint8_t pin, int value) {
log_e
(
"No more analogWrite channels available! You can have maximum %u"
,
LEDC_CHANNELS
);
return
;
}
if
(
ledcSetup
(
cnt_channel
-
1
,
analog_frequency
,
analog_resolution
)
==
0
){
log_e
(
"analogWrite setup failed (freq = %u, resolution = %u). Try setting different resolution or frequency"
);
return
;
}
ledcAttachPin
(
pin
,
cnt_channel
-
1
);
pin_to_channel
[
pin
]
=
cnt_channel
--
;
ledcSetup
(
cnt_channel
,
analog_frequency
,
analog_resolution
);
ledcAttachPin
(
pin
,
cnt_channel
);
}
ledcWrite
(
pin_to_channel
[
pin
]
-
1
,
value
);
}
...
...
@@ -237,7 +240,10 @@ int8_t analogGetChannel(uint8_t pin) {
void
analogWriteFrequency
(
uint32_t
freq
)
{
if
(
cnt_channel
!=
LEDC_CHANNELS
)
{
for
(
int
channel
=
LEDC_CHANNELS
-
1
;
channel
>=
cnt_channel
;
channel
--
)
{
ledcChangeFrequency
(
channel
,
freq
,
analog_resolution
);
if
(
ledcChangeFrequency
(
channel
,
freq
,
analog_resolution
)
==
0
){
log_e
(
"analogWrite frequency cant be set due to selected resolution! Try to adjust resolution first"
);
return
;
}
}
}
analog_frequency
=
freq
;
...
...
@@ -250,7 +256,10 @@ void analogWriteResolution(uint8_t bits) {
}
if
(
cnt_channel
!=
LEDC_CHANNELS
)
{
for
(
int
channel
=
LEDC_CHANNELS
-
1
;
channel
>=
cnt_channel
;
channel
--
)
{
ledcChangeFrequency
(
channel
,
analog_frequency
,
bits
);
if
(
ledcChangeFrequency
(
channel
,
analog_frequency
,
bits
)
==
0
){
log_e
(
"analogWrite resolution cant be set due to selected frequency! Try to adjust frequency first"
);
return
;
}
}
}
analog_resolution
=
bits
;
...
...
docs/source/api/ledc.rst
View file @
dbeae948
...
...
@@ -169,6 +169,28 @@ It is compatible with Arduinos analogWrite function.
* ``value`` select the duty cycle of pwm.
* range is from 0 (always off) to 255 (always on).
analogWriteResolution
*********************
This function is used to set resolution for all analogWrite channels.
.. code-block:: arduino
void analogWriteResolution(uint8_t bits);
* ``bits`` select resolution for analog channels.
analogWriteFrequency
********************
This function is used to set frequency for all analogWrite channels.
.. code-block:: arduino
void analogWriteFrequency(uint32_t freq);
* ``freq`` select frequency of pwm.
Example Applications
********************
...
...
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