-
Notifications
You must be signed in to change notification settings - Fork 28
bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19
bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19
Conversation
Now I can control stepper driver faster and more precisely within my project based on esphhome. Thank you! |
Hi @RushOnline Thanks for the bug-fixing PR. It's so good that you figure out the bug, as
I should have stored |
I've do it this way to minify changes only. To save a memory we can do following changes: diff --git a/src/ESP8266TimerInterrupt.h b/src/ESP8266TimerInterrupt.h
index 06f941f..d2409d2 100644
--- a/src/ESP8266TimerInterrupt.h
+++ b/src/ESP8266TimerInterrupt.h
@@ -102,14 +102,12 @@ class ESP8266TimerInterrupt
private:
timer_callback _callback; // pointer to the callback function
float _frequency; // Timer frequency
- uint32_t _timerCount; // count to activate timer
public:
ESP8266TimerInterrupt()
{
_frequency = 0;
- _timerCount = 0;
_callback = NULL;
};
@@ -121,10 +119,10 @@ class ESP8266TimerInterrupt
// ESP8266 only has one usable timer1, max count is only 8,388,607. So to get longer time, we use max available 256 divider
// Will use later if very low frequency is needed.
- _frequency = 80000000 / 256;
- _timerCount = (uint32_t) _frequency / frequency;
+ _frequency = frequency;
_callback = callback;
+ uint32_t _timerCount = (uint32_t) 80000000 / 256 / _frequency;
if ( _timerCount > MAX_ESP8266_COUNT)
{
_timerCount = MAX_ESP8266_COUNT;
@@ -179,8 +177,8 @@ class ESP8266TimerInterrupt
// Duration (in milliseconds). Duration = 0 or not specified => run indefinitely
void reattachInterrupt()
{
- if ( (_frequency != 0) && (_timerCount != 0) && (_callback != NULL) )
- setFrequency(_frequency / _timerCount, _callback);
+ if ( (_frequency != 0) && (_callback != NULL) )
+ setFrequency(_frequency, _callback);
}
// Duration (in milliseconds). Duration = 0 or not specified => run indefinitely |
Warning: this patch is not tested yet. Local time is 00:39 and my rollerblinds must be closed :) |
I've just already rewritten the library to add more features and fix that issue. Will release within several hours. |
### Releases v1.5.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](#19)
### Releases v1.5.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](#19) 4. Update examples
### Releases v1.5.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](#19) 4. Update examples
Hi @RushOnline The new ESP8266TimerInterrupt releases v1.5.0 has just been published. Your contribution is noted in Contributions and Thanks Please test the new feature and check if there is any more and new bug.
Best Regards, Releases v1.5.0
|
### Releases v1.3.0 1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories 2. Fix reattachInterrupt() bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](khoih-prog/ESP8266TimerInterrupt#19) 3. Update `Packages_Patches`
### Releases v1.4.0 1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories 2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project. 3. Fix `reattachInterrupt()` bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](khoih-prog/ESP8266TimerInterrupt#19) 4. Add support to Adafruit `NRF52840_LED_GLASSES` 5. Optimize library code by using `reference-passing` instead of `value-passing` 6. Update all examples 7. Update `Packages_Patches`
### Releases v1.4.0 1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories 2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project. 3. Fix `reattachInterrupt()` bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](khoih-prog/ESP8266TimerInterrupt#19) 4. Add support to Adafruit `NRF52840_LED_GLASSES` 5. Optimize library code by using `reference-passing` instead of `value-passing` 6. Update all examples 7. Update `Packages_Patches`
### Releases v1.4.0 1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories 2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project. 3. Fix `reattachInterrupt()` bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](khoih-prog/ESP8266TimerInterrupt#19) 4. Optimize library code by using `reference-passing` instead of `value-passing` 5. Update all examples
### Releases v1.4.0 1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories 2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project. 3. Fix `reattachInterrupt()` bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](khoih-prog/ESP8266TimerInterrupt#19) 4. Optimize library code by using `reference-passing` instead of `value-passing` 5. Update all examples
### Releases v1.4.0 1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories 2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project. 3. Fix `reattachInterrupt()` bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](khoih-prog/ESP8266TimerInterrupt#19) 4. Optimize library code by using `reference-passing` instead of `value-passing` 5. Update all examples
### Releases v1.4.0 1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories 2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project. 3. Fix `reattachInterrupt()` bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](khoih-prog/ESP8266TimerInterrupt#19) 4. Optimize library code by using `reference-passing` instead of `value-passing` 5. Update all examples 6. Update `Packages_Patches`
### Releases v1.4.0 1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories 2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project. 3. Fix `reattachInterrupt()` bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](khoih-prog/ESP8266TimerInterrupt#19) 4. Optimize library code by using `reference-passing` instead of `value-passing` 5. Update all examples 6. Update `Packages_Patches`
### 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
### 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
### 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
### 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
### Releases v1.2.0 1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories 2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project 3. Improve accuracy by using `double`, instead of `uint32_t` for `dutycycle`, `period` 4. Optimize library code by using `reference-passing` instead of `value-passing` 5. Fix reattachInterrupt() bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](khoih-prog/ESP8266TimerInterrupt#19) 6. Update examples accordingly
Signed-off-by: Evgeniy Nepomniashchiy rush.zlo@gmail.com