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

Change Duty Cycle #1

Closed
AnselPeng2019 opened this issue Nov 6, 2021 · 7 comments
Closed

Change Duty Cycle #1

AnselPeng2019 opened this issue Nov 6, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@AnselPeng2019
Copy link

when I use this lib, after setup the PWM paras, the PWM works well. But I need to change the duty cycle in working, for example, the breathing led.

I have tried to use disable or delete function, but it looks not work, the PWM duty cycle do not change.

So, it would be great if there is a duty cycle set up function.

@khoih-prog
Copy link
Owner

Hi,

I just add an example ISR_Changing_PWM to show you how to change PWM freq and duty-cycle on-the-fly.

Anyway, I'll add option to make it easier to change the PWM freqs and duty-cycles, without having to delete and reinit the PWM channels in next release.

@khoih-prog
Copy link
Owner

Hi @AnselPeng2019

The new ESP8266_PWM releases v1.1.0 has just been published

Your contribution has been noted in Contributions and Thanks

Check the new

  1. ISR_Changing_PWM example
  2. ISR_Modify_PWM example

The library is definitely better and more useful now. Looking forward to receiving more enhancement requests from you.

Best Regards,

KH


Changelog

Releases v1.1.0

  1. Add functions to modify PWM settings on-the-fly
  2. Fix bug
  3. Add example to demo how to modify PWM settings on-the-fly

@khoih-prog khoih-prog added the enhancement New feature or request label Nov 7, 2021
@ggmichael
Copy link

I'm similarly trying to change the duty cycle with a fixed frequency. Since PWM_DutyCycle is a uint32_t , this can only be done in 100 steps. I suggest to have an alternative function where you can specify Period/OnTime to be able to get the full duty cycle resolution. Or change PWM_DutyCycle to a float (I think 0. to 1. would be easier to use than 0-100 if you do this).

@khoih-prog
Copy link
Owner

@ggmichael

Good idea. I'll rewrite the library to use float / double for PWM freqs, period and duty-cycles to have much better accuracy.

Regards,

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

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Add feature to select among highest, medium or lowest accuracy for Timers for shortest, medium or longest time
3. Fix reattachInterrupt() bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](khoih-prog/ESP8266TimerInterrupt#19)
4. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
5. Improve accuracy by using `double`, instead of `uint32_t` for `dutycycle`, `period`. Check [Change Duty Cycle #1](#1 (comment))
6. Update examples accordingly
khoih-prog added a commit that referenced this issue Jan 29, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Add feature to select among highest, medium or lowest accuracy for Timers for shortest, medium or longest time
3. Fix reattachInterrupt() bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](khoih-prog/ESP8266TimerInterrupt#19)
4. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
5. Improve accuracy by using `double`, instead of `uint32_t` for `dutycycle`, `period`. Check [Change Duty Cycle #1](#1 (comment))
6. Update examples accordingly
khoih-prog added a commit that referenced this issue Jan 29, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Add feature to select among highest, medium or lowest accuracy for Timers for shortest, medium or longest time
3. Fix reattachInterrupt() bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](khoih-prog/ESP8266TimerInterrupt#19)
4. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
5. Improve accuracy by using `double`, instead of `uint32_t` for `dutycycle`, `period`. Check [Change Duty Cycle #1](#1 (comment))
6. Update examples accordingly
khoih-prog added a commit that referenced this issue Jan 29, 2022
### Releases v1.2.0

1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
2. Add feature to select among highest, medium or lowest accuracy for Timers for shortest, medium or longest time
3. Fix reattachInterrupt() bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](khoih-prog/ESP8266TimerInterrupt#19)
4. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
5. Improve accuracy by using `double`, instead of `uint32_t` for `dutycycle`, `period`. Check [Change Duty Cycle #1](#1 (comment))
6. Update examples accordingly
@khoih-prog
Copy link
Owner

Hi @ggmichael

The new ESP8266_PWM releases v1.2.0 has just been published. Your contribution is noted in Contributions and Thanks

Best Regards,


Releases v1.2.0

  1. Fix multiple-definitions linker error. Drop src_cpp and src_h directories
  2. Add feature to select among highest, medium or lowest accuracy for Timers for shortest, medium or longest time
  3. Fix reattachInterrupt() bug. Check bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19
  4. Add example multiFileProject to demo for multiple-file project
  5. Improve accuracy by using double, instead of uint32_t for dutycycle, period. Check Change Duty Cycle #1
  6. Update examples accordingly

@ggmichael
Copy link

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

khoih-prog commented Jan 30, 2022

Hi @ggmichael

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)

It's nice-to-have and a little bit harder, but totally possible to address this issue, if there are many more users requesting the similar feature.

Can you start by creating a new enhancement request / issue, and also specify the use-case and how it'll be beneficial to have the new feature.

IMO, a short glitch can't affect anything (such as light, motor control, etc.). I also don't think analogWrite pwm has taken care of this issue.

Thanks,

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 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
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
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants