I am using ATTiny816. I am attempting to capture a square wave and determine its timing. The signal is on pin PA5. It is usually 50% duty so I can capture the high pulse, low, or both, doesn't matter to me. Frequency range is fairly low - 10 Hz to 120 Hz range.
I would like to use Timer/counter D for this (called TCD in data sheet). The other two timers on the part are already in use.
I have done this before on other micros, trying to do the same here. I want to configure the peripheral so it automatically captures the timer value on either rising or falling, and automatically resets the timer and re-starts it. This way the peripheral will just run in the background, always being updated with the most recent capture duration, and any time I want to know the most recent capture duration, I want to read it from a capture register of some sort.
The configuration tree is fairly complicated. I haven't tried to write even pseudo code because I can't understand how to even begin to configure it. The DS is very sparse on how to do this very simple task. Section 184.108.40.206 "TCD Counter Capture" on pg 220 of the DS has brief notes, but doesn't tie them together in an example. The "Example" just tells me to capture Event A and Event B, and that one should be set to capture rising and one capture falling, but that's all it says. I can't see how I would configure them to rising/falling or how to configure the timer to do what I want.
I do see the part about writing '1' to the ACTION bit in the Event Control register, but that's all it says. Nothing about how to begin the next cycle, nothing explicitly telling me what happens. Section 220.127.116.11 "TCD Inputs" may hold the key, but it's not human readable. Table 22-4 doesn't seem to clearly show a selection doing what I'm looking for.
I tried to generate some basic config code with an Atmel Start project, but the little selection dialog for Timer D is overwhelming and doesn't seem to match what is being said in the DS. Also, both DS and Atmel Start talk about a "fault" condition, but never seems to define it.
I found a few examples in app notes, but they are generating outputs and doing really complicated things. I'm trying to do something IMO is very simple, and the entire purpose of having a Capture peripheral in the first place.
Would someone mind to write some basic configuration code, or even pseudo code telling me what registers to set how, or if this is even possible? I don't see any option to auto reset the capture.
Thanks in advance for any help!