I have the following code in a header file for an AVR32 program I'm writing:
#define PULSE_FREQ 150
#define TC_FREQ (60000000 / 8)
#define PULSE_PER (1 / PULSE_FREQ)
#define TC_PER (1 / TC_FREQ)
#define TTC ((PULSE_PER / TC_PER) - 1)
The goal is to be able to give a frequency and calculate the constant timer count value given by this formula:
Target Count = ((1 / Target Frequency) / (1 / Timer Frequency)) - 1
For example, for a timer frequency of 150Hz, a timer count value of 49999 is required. When manually entering that value for the timer, it works and gives a frequency of 150Hz. However, when using the code above, I get a frequency of 57Hz.
I'm also getting warnings about a division by zero, could the numbers in the constants be so small that they're getting chopped off to zero?
Would it be better to go about this at runtime instead of with #define
macros?