On Fri, Jun 03, 2005 at 12:01:02AM -0400, wbounce wrote: > So you write all your own print to uart routines including things like > handling double? Yup. My own or lower-level canned routines. But many applications which seem to require floating point, don't. A recent example, an electric power meter's wheel typically rotates once per 7.2 Watt-hours of power consumption. So how does one convert that into kW-hr for billing? Knowing good old mechanical electric power meters get the job done with gears is enough hint that there is an integer relationship. 7.2 wh/rev is approximately 138.88888888 rev/kWh if doing floating point but exactly 125/9 (you may see "13 8/9" or "27 7/9" printed on your meter). So I added numerator and denominator calibration parameters and am covered for a wide range of variance. > Your statement about non-reentrant is a valid reason for keeping them > out of interupt service routines. > > Ripping a string to the Uart is pretty straight forward and I have done > that. Even converting integers is relatively easy but messing with > doubles (really floats) is not something I want to mess with. > > I have been burned with the time it takes to do a printf ( I did not > realize how long it character took until someone here pointed it out to > me ie 1 ms for each byte at 9600 which is why I now do 38k so at least > is is 4 per ms) and had to actually remove the printf to get a section > of code to work right. But that would be true if you use printf or roll > your own. Have not investigated the implementation of printf() in avr-libc but others I have looked at were terrible RAM hogs. Starts by allocating a huge buffer, say 1,000 bytes, then starts filling. Pretty printing numbers is tough. Doing it generically is tougher. Thats why printf() is so attractive. > I guess you could use something like dtostr to write a double to your > own buffer that you control but then dtostr would have the similar > problems of printf (probably not as bad though) > > So how do you handle doubles? Or don't you use doubles > I avoid them if I can by I am working on a latitude longitude that > requires them. Lat/Lon may not require floating point, a lot depends. I can almost always avoid float. > Some advice to the original poster: > Heed David's advice and only use printf when you need it. However once you pay the resource price and link it into the application, then go ahead and use it. But use care in knowing its doing a lot of work (which is why you are using it) and will take some time. -- David Kelly N4HHE, dkelly@HiWAAY.net ======================================================================== Whom computers would destroy, they must first drive mad.
Message
Re: [AVR-Chat] Re: Atmega16 Real time clock
2005-06-03 by David Kelly
Attachments
- No local attachments were found for this message.