C Control PRO Unit Mega 128 198219 User Manual

Product codes
198219
Page of 429
394
Bibliotheken
© 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
Frequenzerzeugung
Auf jedem der 6 Timerkanäle kann ein Rechtecksignal  erzeugt  werden.  Im  folgenden  Beispiel  wird
ein 50Hz Signal erzeugt,  das  auf den Pin TIMER0-A  und TIMER0-B  (siehe 
) ausgege-
ben wird. Zusätzlich wird ein Interrupt ausgelöst. Der Vorteiler TIM_128 bestimmt  eine Tickdauer von
1,939µs (= 128 / 66.000.000 Mhz). Durch 5157 * 1,939µs = 10ms ergeben sich 100 Flankenwechsel
pro Sekunde = 50Hz.
Beispiel
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
);
}