Revision: 1906
Author: bvwelch
Date: Sat Apr 10 13:04:15 2010
Log: add 16-bit mode support. tested down to 1 Hz.

http://code.google.com/p/jallib/source/detail?r=1906

Modified:
 /trunk/include/peripheral/timer/timer0_poll_interval.jal

=======================================
--- /trunk/include/peripheral/timer/timer0_poll_interval.jal Fri Apr 9 12:24:38 2010 +++ /trunk/include/peripheral/timer/timer0_poll_interval.jal Sat Apr 10 13:04:15 2010
@@ -45,7 +45,7 @@

 var word timer0_interval_counter
 var word timer0_countdown[DELAY_SLOTS]
-var byte timer0_load
+var word timer0_load

 function interval_counter'get() return word is
    return timer0_interval_counter
@@ -55,7 +55,13 @@
    pragma inline

    if INTCON_TMR0IF == true then
-      tmr0 = timer0_load
+
+      if target_cpu == PIC_16 then
+         tmr0h = byte(timer0_load >> 8)
+         tmr0l = byte(timer0_load)
+      else
+         tmr0 = byte(timer0_load)
+      end if

       -- counters
       timer0_interval_counter = timer0_interval_counter + 1
@@ -100,44 +106,56 @@

 procedure timer0_poll_init() is

-   const dword timer0_div = (target_clock / 4 / timer0_overflow_rate) - 1
+   var dword timer0_div = (target_clock / 4 / timer0_overflow_rate) - 1

    if (timer0_div > ((256 * 256) - 1)) then
-      pragma error  -- requested overflow rate is too low
+      if target_cpu == PIC_16 then
+         T0CON_T0PS = 7 ; prescaler 256
+         timer0_div = timer0_div / 256
+      else
+         pragma error  -- requested overflow rate is too low
+      end if

    elsif (timer0_div > ((128 * 256) - 1)) then
       T0CON_T0PS = 7 ; prescaler 256
-      timer0_load = 255 - timer0_div / 256
+      timer0_div = timer0_div / 256

    elsif (timer0_div > ((64 * 256) - 1)) then
       T0CON_T0PS = 6 ; prescaler 128
-      timer0_load = 255 - timer0_div / 128
+      timer0_div = timer0_div / 128

    elsif (timer0_div > ((32 * 256) - 1)) then
       T0CON_T0PS = 5 ; prescaler 64
-      timer0_load = 255 - byte(timer0_div / 64)
+      timer0_div = timer0_div / 64

    elsif (timer0_div > ((16 * 256) - 1)) then
       T0CON_T0PS = 4 ; prescaler 32
-      timer0_load = 255 - byte(timer0_div / 32)
+      timer0_div = timer0_div / 32

    elsif (timer0_div > ((8 * 256) - 1)) then
       T0CON_T0PS = 3 ; prescaler 16
-      timer0_load = 255 - byte(timer0_div / 16)
+      timer0_div = timer0_div / 16

    elsif (timer0_div > ((4 * 256) - 1)) then
       T0CON_T0PS = 2 ; prescaler 8
-      timer0_load = 255 - byte(timer0_div / 8)
+      timer0_div = timer0_div / 8

    elsif (timer0_div > ((2 * 256) - 1)) then
       T0CON_T0PS = 1 ; prescaler 4
-      timer0_load = 255 - byte(timer0_div / 4)
+      timer0_div = timer0_div / 4

    else
       T0CON_T0PS = 0 ; prescaler 2
-      timer0_load = 255 - timer0_div / 2
+      timer0_div = timer0_div / 2
    end if

+   if target_cpu == PIC_16 then
+      T0CON_T08BIT = 0
+      timer0_load = word(0xFFFF - timer0_div)
+   else
+      timer0_load = byte(0xFF - timer0_div)
+   end if
+
    T0CON_T0CS = 0  ; internal clock
    T0CON_PSA  = 0  ; assign prescaler to timer0

--
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en.

Reply via email to