Library work¶
Work going on on the library.
As of 3/2009, I am doing some reorganization work on the library. This page serves as a scratch space for listing subtasks, making plans, taking notes.
All work is done in the library_refactor
branch.
Motivation¶
Some issues with the library:- Much time spent in interrupt handlers
- Encoder interrupt: 40%
- Other interrupt handlers are also quite long
- Interdependencies between modules
- For example, orbs stop working when the RTC is enabled
- Orb s
- Weird behavior (for example: call to
orb_set
working, but call toorb1_set
/orb2_set
not working, even with the same color and althoughorb_set
just callsorb1_set
andorb2_set
) - Flickering
- 0,0,0 is not off
- Weird behavior (for example: call to
Goals¶
- Hard requirements
- Have proper synchronization (difficult-to-debug problems may result else; improper synchronization is to be considered a bug)
- atomic operations
volatile
variables- All multibyte variables may have to be synchronized!
- Have proper synchronization (difficult-to-debug problems may result else; improper synchronization is to be considered a bug)
- Soft requirements
- Spend as little total time in interrupt handlers as reasonably possible
- Spend as little total time in synchronized code as reasonably possible
- Spend as little time in one invocation of an interrupt handler/synchronized block as reasonably possible
- Introduce double buffering if beneficial
- Use resources (especially timers) as economically as possible
- Use timers for multiple tasks
- PWM and Overflow/OC interrupts are independent, that is, interrupts don't effect the PWM at all.
- Use timers for multiple tasks
- Avoid multibyte variables
- Functionality
- Leave one timer free for application specific tasks, if possible
- Preferable TC3, because it has 16 bit resolution and 3 free PWM pins
- Have a time base with at least 10ms resolution
- 1ms would be better, if processing time allows
- Leave one timer free for application specific tasks, if possible
Random notes
- Current motor frequency is 32 us/30 KHz
- AVR suckage: there is not timer mode with immediate OCR update and overflow interrupt at TOP (CTC value)
- AVR suckage: Set on compare match/Clear on overflow not available with non-PWM modes (especially not with immediate OCR update)
Timer reorganization¶
See also Timers.
Orbs¶
Old values: timer interval 65ms (15Hz) (???), 0.5%...4% interrupt time
Work left to do:- Fix synchronization
- Thread-safe lights setting
- Documentation
- Doxygen
- Description of tripe buffering, thread safety
- Optimization
- Sorting
- Try rolling out the loops
- Try using pointers
- OC-Interrupt
- Try using pointers
- Sorting
- Bugfixes
- ACL bug
- Performance evaluation
- Check time spent in interrupt handler
- Check robustness against long synchronized periods
- Misc
- TODOs in file
- Format file according to ReferenceCoding_Style_Guidelines
- Implement missing functions
- faster sorting algorithm
- improve interrupt handlers
Time base¶
Currently:- RTC with one callback function
- Only 4, 2, 1, 1/4, 1/8, 1/16 seconds
- 1/16s=62.5 ms
- Frequency is good enough for most applications
- Reslution may not be, for example, 80ms is not possible.
- Have a time variable
- To determine how much time passed since some event/action
- Multiple callbacks at different intervals?
- Use CTC feature
- Which timer to reuse?
- buzzer => doesn't work because of varying frequency
- motors => possible? would trigger often (?)
- lights => must put lights on 16 bit timer (no OCR left)