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
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
S | School problem | Homework Help | 3 | |
T | Problem with UA741CP OP-AMP | PCB Layout , EDA & Simulations | 12 | |
M2-ATX Power Supply problem | Power Electronics | 0 | ||
Y | problem controlling variable DC-DC LTC1261LCS8-4 | PCB Layout , EDA & Simulations | 10 | |
G | A Theremin sound problem | General Electronics Chat | 26 |