If possible I'd suggest selecting a microcontroller that supports a counter operation using the timer inputs; rather than manually incrementing a counter inside an ISR (which at high frequencies quickly ends up saturating the microcontroller activity) you allow the hardware to handle the counting. At this point your code simply becomes a matter of waiting for your periodic interrupt then calculating the frequency.

To extend the range and make the frequency counter more generalised (removing the need for multiple ranges at the expense of a little more work for the MCU) you could use the following technique.

Select a periodic interrupt rate that allows for measurement accuracy at the highest input frequency; this should take into account your counter size (you need to select the timer period such that the timer counter will not overflow at the maximum input frequency). For this example I'll assume that the input counter value can be read from the variable "timer_input_ctr".

Include a variable for counting periodic interrupts (should be initialised to 0 at startup); for this example I'll refer to this variable as "isr_count". The interrupt period is contained in the constant "isr_period".

Your periodic interrupt should be implemented as (C pseudo-code):

```
void timer_isr()
{
isr_count++;
if (timer_input_ctr > 0)
{
frequency = timer_input_ctr / (isr_count * isr_period).
timer_input_ctr = 0;
isr_count = 0;
}
}
```

Obviously this rough example relies on some floating point math that may not be compatible for low-end microcontrollers, there are techniques to overcome this but they are outside of the scope of this answer.

Here's an alternative way to resolve your problem or figure out if your problem is physical or mathematical. Lets look at the problem from another angle and see if your measurements give the same result or a different one.

Your physical model is, you have a single heat source and a fixed path from that source to the environment, with a fixed thermal mass. Throw away all the details of the properties of aluminum, your preliminary measurement of the heat sink thermal resistance etc. With your simple (e.g. lumped-element) model, the response to turning on the heat source will be a curve like

\$T(t) = T_\infty - (T_\infty-T_0) \exp(-t/\tau)\$.

First, this shows you will need three measurements to work out the curve because you have three unknowns: \$\tau\$, \$T_\infty\$, and \$T_0\$. Of course one of these measurements can be done before the experiment starts to give you \$T_0\$ directly.

If you know \$T_0\$ and you take two measurements, you'll have

\$T_1 = T_\infty - (T_\infty-T_0) \exp(-t_1/\tau)\$

\$T_2 = T_\infty - (T_\infty-T_0) \exp(-t_2/\tau)\$

and in principle you can solve for your two remaining unknowns. Unfortunately I don't believe these equations can be solved algebraicly, so you'll have to plug them in to a nonlinear solver of some kind. Probably there's a way to do that directly in Excel, although for me it would be easier to do in SciLab, Matlab, Mathematica, or something like that.

So my point is, if you solve the problem this way, and you still get the same answer as you've already gotten, you know there is something wrong with your physical model --- an alternate thermal path, a nonlinear behavior, etc.

If you solve it this way and you get an answer that matches the physical behavior, then you know you made some algebraic or calculation error in your previous analysis. You can either track it down or just use this simplified model and move on.

*Additional comment:* If you do decide to just use this phenomenological model to solve your problem, consider taking more than two measurements before trying to predict the equilibrium temperature. If you have just two measurements, measurement noise is likely to cause some noticeable prediction errors. With additional measurements, you can find a least-squares solution that'll be less affected by measurement noise.

**Edit**
Using your data, I tried two different fits:

The red curve was for a single exponential response, fitted as

\$T(t) = 33.4 - 38.6\exp(-t/81.96)\$

The green curve was for a sum of two exponentials, fitted as

\$T(t) = 36.86 - 35.82\exp(-t/81.83) - 5.42\exp(-t/383.6)\$.

You can see that both forms fit the data nearly equally for the first 100 s or so, but after about 200 s the green curve is clearly a better fit. The red curve is very nearly flattened out at the end, whereas the green curve still shows a slight upward slope, which is also apparent in the data.

I think this implies

You need a slightly more complex model to get a good match for your data, particularly in the tail, which is exactly what you're trying to characterize. The extra term in the model probably comes from a second thermal path out of your device.

It will be very difficult for a fitter to distinguish the part of the response due to the main path from the part due to the secondary path, using only, say, the first 100 s of data.

## Best Answer

I don't know of any particular name for this kind of controller.

The advantages of a fixed-slope system are great simplicity and inherent stability in most cases. As long as the output has settled a good way to the new steady steady state each loop iteration, the system will be stable and it won't overshoot. The drawback is that response is slow compared to more sophisticated control methods using the same plant.

The hysteresis prevents the system from "hunting" around the setpoint and avoids constant small tweaks.

This kind of controller is useful when the thing being controlled and the input signal are largely intended to be fixed. The controller is then compensating for variations due to temperature, wear, and the like, not actively trying to put a specific "signal" on the output.

Note that this system is NOT a integrator. A real integrator adds a fraction of the offset (desired - actual) to the control signal each iteration. This system adds a constant regardless of how far off the output is from the desired level.