[Ovmsdev] SIM808/SIM908 GPS accuracy
Edward Cheeseman
cheesemanedward at gmail.com
Tue Feb 7 20:30:47 HKT 2017
> On 7/02/2017, at 8:21 PM, HONDA S-2000 wrote:
> On Feb 6, 2017, at 10:43 PM, Edward Cheeseman wrote:
>>
>> Seconds * 3600 = degrees. So native units would be degrees * 3600 * 2048.
>
> I see. While intermediate values are calculated in float, the return value is a fixed-point, signed 32-bit long value (a.k.a. Q19.11).
> That allows for a maximum of ±145 degrees (?).
I think its more like Q20.11? One bit sign, 11 bits of fractions of a second, 20bits of seconds/3600 = +/-291 degrees
> Is there a way to separate the math into a generic function, and then rewrite the main function to use more readable function-based code?
Yes, but I’ve been told that the stack is very limited and that everything should be inlined where possible. I’ve also been hitting the (very mediocre) limits of the C preprocessor.
Where normally I’d #define a constant with all its glorious minutes and seconds spelled out, C18 can silently just ignore half of it. I wanted to use +(1<<7) to make clear I was rounding for the >>8 divide.
It totally ignored that. +128 however did work. I only found that running the MPLAB simulator feeding in values and comparing to a spreadsheet.
Oh, Libre Office appears to use double precision floats. My guess is Excel would be the same.
I came to the conclusion the only thing we get for free in the compiler is comments so I wrote a bit of a novel explaining what I was up to. I boiled it down to the simplest C and that seems to work.
I was pretty close to breaking out assembly but when I found out the pain required in multiplying anything that wasn’t 8x8bit I decided it was better to stick with what help C18 can give.
> Again, I suggest that a decimal math library might be able to directly handle the DDDMM.MMMMMM format without using float as an intermediate. If the decimal math library can convert directly to Q19.11 then it would be a sure win. Only problem is that I've never used a multi-digit decimal math library, so I wouldn't know where to point you for starters.
In anything more capable I would agree. I’ve used TI’s IQ math library and it is reasonable to read.
More information about the OvmsDev
mailing list