Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moved the implementation of 'getMaxDuty()' into the cpp file for all … #2903

Closed
wants to merge 2 commits into from

Conversation

pljakobs
Copy link
Contributor

…architectures. Before, for esp32c3, the function in header would always return 0.

…architectures. Before, for esp32c3, the function in header would always return 0.
Copy link

what-the-diff bot commented Oct 30, 2024

PR Summary

  • Introduction of getMaxDuty() function:
    • This new function has been added in the program that different hardware architectures (Esp32, Esp8266, Host, and Rp2040) utilize. The purpose of this function is to find out the highest duty cycle possible.
  • Modification to HardwarePWM.h file:
    • getMaxDuty() has been defined in a different way than before. Previously, it was fully written out in this file, but with this update, only its blueprint (or 'function prototype') is present here, meaning the details of how this function works are written in another file. This approach helps to keep code organized and easier to maintain.

Copy link
Contributor

@mikee47 mikee47 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With #2904 presumably this PR is no longer required?

@pljakobs
Copy link
Contributor Author

this one is about moving the getMaxDuty() from the header file into the implementation.
I don't quite understand why the simple return maxduty from the header didn't work for ARCH Esp32 but for Esp8266. It works for both when the function is implemented in the .cpp file.
#2904 just adds an assert() for max_channels - has nothing to do with this one. I hope I managed to properly untangle the two changes.

@mikee47
Copy link
Contributor

mikee47 commented Oct 31, 2024

I don't quite understand why the simple return maxduty from the header

That's my concern. I can see no logical reason why this PR is necessary so something else is clearly going on.

@pljakobs
Copy link
Contributor Author

pljakobs commented Oct 31, 2024

I share the concern, but:
I added a HardwarePWM::myMaxDuty() function that just did the same thing, return maxduty, the only difference was that it was implemented in the .cpp file and only the prototype was in the header.
Calling both functions in the test app one after the other returned 0 for the original getMaxDuty() and the correct 1023 from myGetDuty(). I could not see any reason for this, but I would be very happy to find one.

it's correct that, if the HardwarePWM::HardwarePWM constructor is called with more than max_channels pins, the constructor in the old version would silently fail and therefore maxduty would not be set and remain 0 - but in the tests I did, that was not the case.

@mikee47
Copy link
Contributor

mikee47 commented Oct 31, 2024

I've spun up the Basic_HwPWM sample for the esp32c3 to check this. This is what I found:

  1. Remove COMPONENT_SOC definition from component.mk to allow sample to build for other architectures.
  2. Add debug statement in init to verify maxDuty.
  3. Flash to esp32c3. This produces a boot-loop:
HW PWM maxDuty = 0
E (292) ledc: ledc_set_duty(805): LEDC is not initialized
  1. The esp32c3 only has six PWM channels. Change pins to LED_PIN, 4, 5, 0, and application starts OK:
HW PWM maxDuty = 1023
PWM output set on all 8 Pins. Kindly check...
Now LED_PIN will go from 0 to VCC to 0 in cycles.

@pljakobs
Copy link
Contributor Author

I've spun up the Basic_HwPWM sample for the esp32c3 to check this. This is what I found:

1. Remove `COMPONENT_SOC` definition from `component.mk` to allow sample to build for other architectures.

2. Add debug statement in `init` to verify `maxDuty`.

3. Flash to esp32c3. This produces a boot-loop:
HW PWM maxDuty = 0
E (292) ledc: ledc_set_duty(805): LEDC is not initialized
4. The esp32c3 only has _six_ PWM channels.  Change `pins` to `LED_PIN, 4, 5, 0,` and application starts OK:
HW PWM maxDuty = 1023
PWM output set on all 8 Pins. Kindly check...
Now LED_PIN will go from 0 to VCC to 0 in cycles.

are you saying you're getting this result with the getMaxDuty() implemented in the .h file?
I need to re-test this, but I had both issues independently from each other.

@pljakobs
Copy link
Contributor Author

okay, I think I can confirm this.
I don't quite understand it, though.

@pljakobs pljakobs closed this Oct 31, 2024
@mikee47
Copy link
Contributor

mikee47 commented Oct 31, 2024

Bear in mind that the sample statically initialises the HardwarePWM instance, so that happens before the UART has been initialised for debug output.

@mikee47
Copy link
Contributor

mikee47 commented Oct 31, 2024

It's a pity that HardwarePWM doesn't follow the usual model where initialisation occurs in a begin() method, rather than in the constructor.

@mikee47
Copy link
Contributor

mikee47 commented Oct 31, 2024

are you saying you're getting this result with the getMaxDuty() implemented in the .h file?

Yes. I saw exactly what I expected to see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants