RandoSY / jallib

Automatically exported from code.google.com/p/jallib
0 stars 0 forks source link

more flexibility in rtc library for other frequencies #100

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The rtc_isr_tmr0 library contains some hard coded constants (hi,mid,lo) for
a specific oscillator frequency (20MHz).
This means that the user would have to change the library when using a
different oscillator frequency.
Request: the library should adapt itself automatically to the oscillator
speed. 

Original issue reported on code.google.com by robhamerling on 24 Oct 2009 at 8:06

GoogleCodeExporter commented 8 years ago
A quick fix could be to replace the hard coded values of hi,mid and lo by:

const  byte  hi  = (target_clock / 4) / 65536
const  byte  mid = (target_clock / 4) % 65536 / 256
const  byte  lo  = (target_clock / 4) % 256

This makes the library independent of the oscillator frequency.
However the working of the Interrupt service routine depends also on the proper
setting of OPTION_REG, in particular the PS and PSA bits. This is currently not
handled by this library and not mentioned in the comments/docs too.

Original comment by robhamerling on 24 Oct 2009 at 12:33

GoogleCodeExporter commented 8 years ago
This code-change has proven to be working correctly, but some more improvents 
may be
desired, like:

1. Support for oscillator frequencies higher than 64 MHz, either by using a 
larger
counter (4 bytes in stead of 3) or by using a prescaler value for the timer (to 
bu
user specified.  

2. Convert the code to native JAL. The site of Roman Black shows some examples 
in
C-language which can be converted to Jal easily. A first attempt shows a slight
increase of code space. The amount depends on the size of the counter field.   

Original comment by robhamerling on 25 Oct 2009 at 10:44