Timer

Most applications for microcontrollers have to refer to some kind of time on one way or the other. The typical AVR controllers have three timers called Timer0, Timer1, and Timer2. Newer controllers sometimes have even more timers. The timers Timer0 and Timer2 are 8-bit wide timers and Timer1 is a 16-bit timer.

If you start working with timers you should refer to the Atmel [application note 130].

Package AVR.Timer0

with Interfaces;                   use Interfaces;
with AVR.MCU;

package AVR.Timer0 is
   pragma Preelaborate;

   --
   --  Different scaling factors for timer clock input.
   --
   --  Verify in the data sheet that the scaling factor is available
   --  at all for your mcu.
   --
   subtype Scale_Type is Unsigned_8;

   function No_Clock_Source return Scale_Type;
   function No_Prescaling   return Scale_Type;
   function Scale_By_8      return Scale_Type;
   function Scale_By_32     return Scale_Type;
   function Scale_By_64     return Scale_Type;
   function Scale_By_128    return Scale_Type;
   function Scale_By_256    return Scale_Type;
   function Scale_By_1024   return Scale_Type;

   procedure Init_Normal (Prescaler : Scale_Type);
   procedure Init_CTC (Prescaler : Scale_Type; Overflow : Unsigned_8 := 0);
   procedure Set_Overflow_At (Overflow : Unsigned_8);

   procedure Set_Output_Compare_Mode_Normal;
   procedure Set_Output_Compare_Mode_Toggle;
   procedure Set_Output_Compare_Mode_Clear;
   procedure Set_Output_Compare_Mode_Set;

   procedure Stop;  --  set prescaler to No_Clock_Source, disable timer interrupts

   procedure Enable_Interrupt_Compare;
   procedure Enable_Interrupt_Overflow;

   Signal_Compare  : constant String;
   Signal_Overflow : constant String;

end AVR.Timer0;

Related

Wiki: Examples
Wiki: Home