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 |
|---|---|---|---|---|
|
|
Vishay Dale IFSC1515AHER470M01 Marking Problem | Test & Measurement | 0 | |
| A | How do I solve this problem using Kirchhoff's laws, everyone? | Homework Help | 17 | |
|
|
Bosch oven problem | Technical Repair | 4 | |
|
|
Problem with powering DIY boost converter | Power Electronics | 7 | |
|
|
Toy car circuit problem | General Electronics Chat | 17 |