??? 02/03/09 09:03 Modified: 02/03/09 09:11 Read: times |
#161979 - More advice. Responding to: ???'s previous message |
1. You're trying to implement a delay function in C. This is not going to work well (as in "result in a fixed time delay"), if it works at all (the delay function has no side effects, so the compiler has the freedom to remove it completely, resulting in no delay at all).
If you need a delay, either write the delay function in assembly (which the compiler can't touch, and which will give you a very precise delay at the cost of keeping the MCU busy), or, if you want to stay in C, use a timer. 2. The printf() function is a heavyweight for a small microcontroller like the '51. I think the full implementation uses several kilobytes of program memory. You may want to keep that in mind if you run into CPU load/power/program memory constraints. Also, it takes a long time to execute and I believe it is not reentrant. For these reasons, do not use it inside an interrupt service routine (right now it's commented out in your program, but it looks like you were trying or plan to do so), unless you're looking to give yourself some major headaches. 3. The same goes for the division operator and floating point operations in general. Usually, you want to average 2^n samples instead, since a division by a power of 2 becomes a simple bit shift instead of a very CPU intensive library call. Another side effect is that instead of floating point, you can use a fixed point format without losing information, and let the PC side (or whatever your micro is talking to) deal with the formatting. |
Topic | Author | Date |
ADUC845 Unable to stop ADC Interrupts | 01/01/70 00:00 | |
Your problem has _nothing_ to do with the ADC. | 01/01/70 00:00 | |
Excellent Advice![]() | 01/01/70 00:00 | |
More advice. | 01/01/70 00:00 |