Instructions

388Libraries
© 2013 Conrad Electronic
word cnt;
void count_irq(void)
{
cnt++;
Irq_GetCount(INT_TIMER0);
}
void main(void)
{
cnt= 0;
Irq_SetVect(INT_TIMER2, count_irq);
Timer_ConfigCounter(2, COUNTA_1, CNT_RISING, 300);
AbsDelay(10000);
Msg_WriteWord(Timer_GetCounterVal(2));
Msg_WriteChar('\r');
while(1);
}
5.26.2.2 Frequency Generation
On each of the 6 timer channels a rectangular signal can be generated. In the following Example, a
50Hz signal is generated which (see Pin Assignment) is output on pin TIMER0-A and TIMER0-B. In
addition, an interrupt is triggered. The prescaler TIM_128 determines a tick duration of 1,93s (=
128 / 66.000.000 Mhz). By multiplying 5157 * 1.939µs = 10ms results in 100 edge changes per
second = 50Hz.
Example
word cnt;
void irq(void)
{
cnt++;
Irq_GetCount(INT_TIMER0);
}
void main(void)
{
cnt= 0;
Irq_SetVect(INT_TIMER0, irq);
Timer_Set(0, TIM_128, 5157, TIMFLG_IRQ|TIMFLG_PINA|TIMFLG_PINB);
while(1);
}