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

Timer: Implement Input Capture #125

Open
urish opened this issue May 2, 2022 · 3 comments
Open

Timer: Implement Input Capture #125

urish opened this issue May 2, 2022 · 3 comments
Assignees

Comments

@urish
Copy link
Contributor

urish commented May 2, 2022

see wokwi/wokwi-features#352 for details

@drf5n
Copy link

drf5n commented Apr 19, 2023

I see that input capture is mentioned on:

https://docs.wokwi.com/parts/wokwi-arduino-mega

@urish
Copy link
Contributor Author

urish commented Apr 19, 2023

Yes :)

@drf5n
Copy link

drf5n commented Jun 26, 2024

The missing Input Capture Interrupt infrastructure seems to cause the CTC modes that use ICRx as TOP to not be able to trigger the TIMERn_CAPT_vect at TOP.

Per https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf page 101:

An interrupt can be generated at each time the counter value reaches the TOP value by either using the OCF1A or ICF1 flag according to the register used to define the TOP value. If the interrupt is enabled, the interrupt handler routine can be used for updating the TOP value. However, changing the TOP to a value close to BOTTOM when the counter is running with none or a low prescaler value must be done with care since the CTC mode does not have the double buffering feature. If the new value written to OCR1A or ICR1 is lower than the current value of TCNT1, the counter will miss the compare match. The counter will then have to count to its maximum value (0xFFFF) and wrap around starting at 0x0000 before the compare
match can occur. In many cases this feature is not desirable. An alternative will then be to use the fast PWM mode using OCR1A for defining TOP (WGM13:0 = 15) since the OCR1A then will be double buffered.

I think part of the missing bits might be around:

// Interrupts
private OVF: AVRInterruptConfig = {
address: this.config.ovfInterrupt,
flagRegister: this.config.TIFR,
flagMask: this.config.TOV,
enableRegister: this.config.TIMSK,
enableMask: this.config.TOIE,
};
private OCFA: AVRInterruptConfig = {
address: this.config.compAInterrupt,
flagRegister: this.config.TIFR,
flagMask: this.config.OCFA,
enableRegister: this.config.TIMSK,
enableMask: this.config.OCIEA,
};
private OCFB: AVRInterruptConfig = {
address: this.config.compBInterrupt,
flagRegister: this.config.TIFR,
flagMask: this.config.OCFB,
enableRegister: this.config.TIMSK,
enableMask: this.config.OCIEB,
};
private OCFC: AVRInterruptConfig = {
address: this.config.compCInterrupt,
flagRegister: this.config.TIFR,
flagMask: this.config.OCFC,
enableRegister: this.config.TIMSK,
enableMask: this.config.OCIEC,
};

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

No branches or pull requests

2 participants