void SetWGFreq(unsigned int freq)
freg2 = (unsigned long)freq*33.554432; //Number based on a MCLK of 8 MHz
// AND freq in Hz
freg2 = (freq * 33554432) / 1000000; //Number based on a MCLK of 8 MHz
// AND freq in Hz
I have small doubt i am using unsigned int for freq variable variable. If i want to set 125.3 Khz then what will happen, i think it exceeds the limit.It occurred to me that by eliminating the floating point arithmetic several complications drop away:
One could also add 500000 to the product (before division) to compute a rounded result.Rich (BB code):freg2 = (freq * 33554432) / 1000000; //Number based on a MCLK of 8 MHz // AND freq in Hz
Just insure the variables can handle the range. It is pretty big.
'125300*33554432=4190725159600/1000000
by Duane Benson
by Duane Benson
by Aaron Carman
by Duane Benson