Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

DutyCycle to be updated at the end current PWM period #2

Closed
khoih-prog opened this issue Jan 30, 2022 · 9 comments
Closed

DutyCycle to be updated at the end current PWM period #2

khoih-prog opened this issue Jan 30, 2022 · 9 comments

Comments

@khoih-prog
Copy link
Owner

Original post from @ggmichael in Change Duty Cycle #1

Thanks for this! Your library has fixed a problem I was having with inconsistent calibration, which I now think arose from the changing timing of the analogWrite pwm.

One more feature that would be nice would be to be able to command a duty cycle update to occur at the end of the next full period instead of immediately (as I think happens now). If you're trying to create a continuously variable mean output voltage, resetting the channel at a frequency that approaches the PWM frequency causes a bias towards whichever part of the duty cycle comes first. This wouldn't happen if the update occurred at the end of the cycle. It may be that there are other applications (long cycles) where you would prefer the update straight away. So perhaps a flag to set either mode.

@khoih-prog
Copy link
Owner Author

HI @ggmichael

I'll publish a new release to add this enhancement within half an hour for you to test the new feature. Be ready.

Regards,

khoih-prog added a commit that referenced this issue Jan 30, 2022
### Releases v1.2.2

1. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](#2)
khoih-prog added a commit that referenced this issue Jan 30, 2022
### Releases v1.2.2

1. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](#2)
@khoih-prog
Copy link
Owner Author

Hi @ggmichael

The new ESP8266_PWM releases v1.2.2 has just been published. Your contribution is noted in Contributions and Thanks. Please test and verify the new feature is supported and working OK now.

The library is better and better everyday, thanks to contributing users like you, who spot bugs, test and request enhancements. We, the library writers, normally can't never have enough time, knowledge and experience to know all the use-cases in the world to add the new features.

Best Regards,


Releases v1.2.2

  1. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check DutyCycle to be updated at the end current PWM period #2

khoih-prog added a commit to khoih-prog/ESP32_PWM that referenced this issue Jan 30, 2022
### Releases v1.2.1

1. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
khoih-prog added a commit to khoih-prog/AVR_Slow_PWM that referenced this issue Jan 30, 2022
### Releases v1.2.1

1. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
khoih-prog added a commit to khoih-prog/STM32_Slow_PWM that referenced this issue Jan 30, 2022
### Releases v1.2.1

1. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
@ggmichael
Copy link

I can confirm that the new code gets rid of the 'glitch' on changing duty cycle - that's great - thanks. I think you're right that analogWrite() doesn't do this, but there's no harm in having a better implementation. (However, something is now causing the ESP8266 to reboot periodically - I have to check over my integration of the library)

khoih-prog added a commit to khoih-prog/SAMD_Slow_PWM that referenced this issue Feb 1, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
3. Add examples [SAMD21 multiFileProject](examples/SAMD21/multiFileProject) and [SAMD51 multiFileProject](examples/SAMD51/multiFileProject)to demo for multiple-file project
4. Improve accuracy by using `double`, instead of `uint32_t` for `dutycycle`, `period`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
5. Optimize library code by using `reference-passing` instead of `value-passing`
6. Add support to many more boards, such as `SAMD21E1xA`, `SAMD21G1xA` and`SAMD21J1xA`
7. Update examples accordingly
8. Update `Packages' Patches`
khoih-prog added a commit to khoih-prog/SAMDUE_Slow_PWM that referenced this issue Feb 1, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
3. Add examples [multiFileProject](examples/multiFileProject) to demo for multiple-file project
4. Improve accuracy by using `double`, instead of `uint32_t` for `dutycycle`, `period`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
5. Optimize library code by using `reference-passing` instead of `value-passing`
6. Update examples accordingly
khoih-prog added a commit to khoih-prog/SAMDUE_Slow_PWM that referenced this issue Feb 1, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
3. Add examples [multiFileProject](examples/multiFileProject) to demo for multiple-file project
4. Improve accuracy by using `double`, instead of `uint32_t` for `dutycycle`, `period`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
5. Optimize library code by using `reference-passing` instead of `value-passing`
6. Update examples accordingly
@khoih-prog
Copy link
Owner Author

HI @ggmichael

However, something is now causing the ESP8266 to reboot periodically - I have to check over my integration of the library

If you still have that problem, I suggest you try these mods to see if it's any better

  1. Increase ESP8266 clock to 160MHz from 80MHz, if not yet
  2. Increase the HW_TIMER_INTERVAL_US from 20uS to higher, such as 30, 50, 100uS. For example
    ISR_Modify_PWM.ino#L46
#define HW_TIMER_INTERVAL_US      50L

The reason is the ISR-based function run() now take more time to process (double accuracy, dutycycle check, etc.)

I'm thinking, in future releases, about letting users optionally select double, float or uint32_t for dutycycle / frequency / period, depending on the use-case.

@ggmichael
Copy link

ggmichael commented Feb 1, 2022 via email

@khoih-prog
Copy link
Owner Author

I did use floats for the duty cycle instead of double (I think double is more precision than you could ever need). The period remained uint32_t (this also makes sense to me, since this is the actual count). Frequency could also be a float, since it is always converted.

I agree with you and will make float for DC and Freq, period uint32_t. Sorry for to be too unreasonably aggressive.

Will have a new release within today.

@khoih-prog
Copy link
Owner Author

Hi @ggmichael

Please test the new ESP8266_PWM releases v1.2.3


Releases v1.2.3

  1. Use float for DutyCycle and Freq, uint32_t for period.
  2. Optimize code by not calculation in ISR

khoih-prog added a commit to khoih-prog/RP2040_Slow_PWM that referenced this issue Feb 2, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
3. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
6. Update examples accordingly
khoih-prog added a commit to khoih-prog/RP2040_Slow_PWM that referenced this issue Feb 2, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
3. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
6. Update examples accordingly
khoih-prog added a commit to khoih-prog/RP2040_Slow_PWM that referenced this issue Feb 2, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
3. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
6. Update examples accordingly
khoih-prog added a commit to khoih-prog/MBED_RP2040_Slow_PWM that referenced this issue Feb 2, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
3. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
6. Update examples accordingly
@ggmichael
Copy link

I confirm that update works, and also fixes the reboot problem.

@khoih-prog
Copy link
Owner Author

Glad to know it's working better now, thanks to your contribution anyway.

khoih-prog added a commit to khoih-prog/megaAVR_Slow_PWM that referenced this issue Feb 7, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Add support to `MegaCoreX` core, including ATmega4809, ATmega4808, ATmega3209, ATmega3208, ATmega1609, ATmega1608, ATmega809 and ATmega808
3. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
4. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
5. Optimize library code by using `reference-passing` instead of `value-passing`
6. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
7. Update examples accordingly
khoih-prog added a commit to khoih-prog/megaAVR_Slow_PWM that referenced this issue Feb 7, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Add support to `MegaCoreX` core, including ATmega4809, ATmega4808, ATmega3209, ATmega3208, ATmega1609, ATmega1608, ATmega809 and ATmega808
3. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
4. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
5. Optimize library code by using `reference-passing` instead of `value-passing`
6. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
7. Update examples accordingly
khoih-prog added a commit to khoih-prog/megaAVR_Slow_PWM that referenced this issue Feb 7, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Add support to `MegaCoreX` core, including ATmega4809, ATmega4808, ATmega3209, ATmega3208, ATmega1609, ATmega1608, ATmega809 and ATmega808
3. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
4. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
5. Optimize library code by using `reference-passing` instead of `value-passing`
6. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
7. Update examples accordingly
khoih-prog added a commit to khoih-prog/megaAVR_Slow_PWM that referenced this issue Feb 7, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Add support to `MegaCoreX` core, including ATmega4809, ATmega4808, ATmega3209, ATmega3208, ATmega1609, ATmega1608, ATmega809 and ATmega808
3. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
4. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
5. Optimize library code by using `reference-passing` instead of `value-passing`
6. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
7. Update examples accordingly
khoih-prog added a commit to khoih-prog/Portenta_H7_Slow_PWM that referenced this issue Feb 7, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
3. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
6. Fix bug
7. Update examples accordingly
8. Update `Packages_Patches`
khoih-prog added a commit to khoih-prog/Portenta_H7_Slow_PWM that referenced this issue Feb 7, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
3. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
6. Fix bug
7. Update examples accordingly
8. Update `Packages_Patches`
khoih-prog added a commit to khoih-prog/nRF52_MBED_Slow_PWM that referenced this issue Feb 7, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
3. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
6. Update examples accordingly
khoih-prog added a commit to khoih-prog/nRF52_MBED_Slow_PWM that referenced this issue Feb 7, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
3. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
6. Update examples accordingly
khoih-prog added a commit to khoih-prog/nRF52_MBED_Slow_PWM that referenced this issue Feb 8, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
3. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
6. Update examples accordingly
khoih-prog added a commit to khoih-prog/nRF52_Slow_PWM that referenced this issue Feb 8, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
3. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
6. Update examples accordingly
7. Update `Packages_Patches`
khoih-prog added a commit to khoih-prog/Teensy_Slow_PWM that referenced this issue Feb 8, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Improve accuracy by using `float`, instead of `uint32_t` for `dutycycle`. Check [Change Duty Cycle #1](khoih-prog/ESP8266_PWM#1 (comment))
3. DutyCycle to be optionally updated at the end current PWM period instead of immediately. Check [DutyCycle to be updated at the end current PWM period #2](khoih-prog/ESP8266_PWM#2)
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
6. Update examples accordingly
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants