Instructions

362Libraries
© 2013 Conrad Electronic
} // after that the thread
// sleeps for 200ms
//-----------------------------------------------------------------
// main program
//
void main(void)
{
Thread_Start(1,thread1); // start new thread
while(true) // endless loop
{
Thread_Delay(100); Msg_WriteText("Thread1");
} // the thread sleeps for 100ms
} // after that "Thread1" is displayed
5.26 Timer
5.26.1 Mega
In C-Control Pro Mega 32 there are two, in Mega128 are three independent timers available. These
are Timer_0 with 8 bit and Timer_1 with 16 bit (Timer_3 with 16 bit for Mega128 only). Timer_2 is
used by the firmware as an internal time base and is set firm to a 10ms interrupt. These internal
timers can be utilized for a multitude of tasks:
Event Counter
Frequency Generation
Pulse Width Modulation
Timer Functions
Pulse & Period Measurement
Frequency Measurement
5.26.1.1 Event Counter
Here are two examples for how a Timer can be used for an Event Counter:
Timer0 (8 Bit)
// Example: Pulse Counting with CNT0
Timer_T0CNT();
pulse(n); // generate n Pulses
count=Timer_T0GetCNT();
With Mega128 for reasons of the hardware the use of
Tim er_0
as counter is not possible!
Timer1 (16 Bit)