So far, my sketch is fairly straight forward. Being 200 lines, I don't feel the need to post all of it here, but I'll include the necessary parts. It's basically a single line of math that is giving me an issue.
cycle_time = ((1/frequency)*1000000);
Where frequency is an int that ranges from 400 to 1024 and cycle_time is an int. I've tried splitting it into two lines so it looks like:
ct = 1/frequency;
cycle_time = ct*1000000;
I've tried changing variable types between int, float, and unsigned long between both ways of calculating this, and it always comes back 0. Even the ct line by itself returns 0 when set as a float. 6 or 7 decimal places is more that accurate enough for my needs. I've also tried using
cycle_time = pow(frequency, -1)*1000000
And broke that into two lines as well with the same result. I've verified that frequency is a valid number going in with a Serial.print. Any ideas?
int frequency, cycle_time;
cycle_time = 1000000UL / frequency;