Instructions

364Libraries
© 2013 Conrad Electronic
Timer_T3FRQX(10,2,PS_8);
5.26.1.3 Frequency Measurement
Timer_1 (16Bit) and Timer_3 (16Bit) (only Mega128) can be used for direct measurement of a fre-
quency. The pulses per second are being counted, the result is then delivered in Hertz units. The
maximum frequency is 64kHz and is yielded by the 16 bit counter. An example for this kind of fre-
quency measurement can be found under "Demo Programs/FreqMeasurement". By shortening the
measuring time also higher frequencies can be measured. The result has then to be re-calculated
accordingly.
5.26.1.4 Pulse Width Modulation
There are two independent timers available for pulse width modulation. These are
Tim er_0
with 8 bit and
Tim er_1
with 16 bit. By use of a pulse width modulation Digital-Analog-Converters can be realized very
easily. On the Mega128
Tim er_3
can be used additionally.
Timer0 (8 Bit)
Example: Pulse Width Modulation with 138,9 µs Period and 5,42 µs Pulse Width, changed to 10,84 µs
Pulse Width
// Pulse: 10*542,5 ns = 5,42 µs, Period: 256*542,5 ns = 138,9 µs
Timer_T0PWM(10,PS0_8);
Timer_T0PW(20); // Pulse: 20*542,5 ns = 10,84 µs
Timer1 (16 Bit)
Example: Pulse Width Modulation with 6,4 ms Period and 1,28 ms Pulse Width Channel A and 640 µs
Pulse Width Channel B
Timer_T1PWMX(100,20,10,PS_1024); // Period: 100*69,44 µs = 6,94 ms
// PulseA: 20*69,44 µs = 1,389 ms
// PulseB: 10*69,44 µs = 694,4 µs
When using the PWM timer functions a value of zero for the duty parameter is not allowed,
and will not turn the PIN off. To produce a low signal, the timer must be turned off (Timer_Disable)
and the PIN should be switched to output. If a PWM function is used, that generates multiple PWM
signals, then a PWM function should be called (e.g. Timer_T1PWM), that will not include the PIN,
that should be switched to low.
An example:
while(1)
{