[Ovmsdev] Tick math

Mark Webb-Johnson mark at webb-johnson.net
Thu Oct 23 13:31:25 HKT 2014


Brian,

Thanks for this. I've updated the source code with your comments, for historical record. With this confirmed, I think we should be good to go. I'll do some further testing over the next few nights (perhaps turning off the GSM sync and seeing how badly/well it drifts).

Regarding the clock speed, I think it is fast enough now (as other than the CAN handling, there is little else going on), and presumably we gain a small power advantage from running at FOSC=20MHz (vs 40MHz).

Regards, Mark.

On 23 Oct, 2014, at 1:00 pm, HONDA S-2000 <s2000 at audiobanshee.com> wrote:

> Hi guys,
> 
> I just started looking at the OVMS again after a long time away, so forgive me if I get some details wrong.
> 
> Looking at the Eagle schematic, I see the crystal specified as 20 MHz. In HS mode, that would make the main oscillator run at FOSC = 20 MHz. But if you're using the HSPLL, you could be running at the maximum FOSC = 40 MHz. The latter option would obviously cut the period in half. A quick check of the firmware source shows #pragma config OSC = HS, so you might consider doubling this using HSPLL and the remaining appropriate config changes.
> 
> Anyway, starting with 20 MHz, FOSC/4 = 5 MHz, which is probably where that 5 MHz comment comes from below.
> The 1:8 prescaler takes that down to 625 kHz
> TMR1H:TMR1L of 0x0000 is effectively 0x10000, or 65,536, bringing the frequency down to 9.5367431640625 Hz.
> 
> The reciprocal is exactly 104.8576 ms.
> 
> If you double the PIC speed to its rated maximum using the High Speed Phase Locked Loop (and use a multiplier of 2, not the example of 4 in the data sheet which would bring a 10 MHz crystal up to the 40 MHz maximum), then the period would be 52.4288 ms, but I think you could use the exact same technique that Tom mentioned to adjust for seconds without too much error. You'd just need to alter the values by a factor of two.
> 
> Brian Willoughby
> Sound Consulting
> 
> 
> On Oct 22, 2014, at 8:30 PM, Mark Webb-Johnson <mark at webb-johnson.net> wrote:
>> Looks good.
>> 
>> (45681/4790)*104.8576 = 1000.0000053411
>> 
>> I've committed that, and will carry on testing tonight.
>> 
>> Now, of course this depends on the calculation of 104.8576ms per timer1 interrupt. I have no idea where that figure originally came from, or if it is correct. It does looks like the LED count counts 10 of these to get 1 flash a second, so it seems correct. The initialisation for timer1 is:
>> 
>>   // Timer 1 enabled, Fosc/4, 16 bit mode, prescaler 1:8
>>   T1CON = 0b10110101; // @ 5Mhz => 51.2uS / 256
>>   IPR1bits.TMR1IP = 0; // Low priority interrupt
>>   PIE1bits.TMR1IE = 1; // Enable interrupt
>>   TMR1L = 0;
>>   TMR1H = 0;
>> 
>> but the @5Mhz comment is incorrect because that is not what our oscillator runs at.
>> 
>> Regards, Mark.
> 
> _______________________________________________
> OvmsDev mailing list
> OvmsDev at lists.teslaclub.hk
> http://lists.teslaclub.hk/mailman/listinfo/ovmsdev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.teslaclub.hk/pipermail/ovmsdev/attachments/20141023/582fac08/attachment.html>


More information about the OvmsDev mailing list