Hallo zusammen,
ich möchte gerne ein Interrupt auslösen nach 5sec. mit TIMER2. Folgende
Daten werden verwendet:
Clock frequency = 32 768Hz
Prescaler = 256
TIMER2 = 2^32 bit
Mein Problem ist, dass ich nicht weiß wie ich den Wert für T2LD
errechnen kann, damit ich auf die 5sec. komme.
Im Datenblatt steht: "In periodic mode the counter decrements/increments
from the value in the Load Register(TxLD MMR,) until zero/full
scale and starts again at the value stored in the Load Register."
Jedoch weiß ich nicht wie ich auf den Wert für T2LD komme unter
Berücksichtigung von clock frequency and prescaler.
Danke!
Quellcode:
#include<aduc7026.h>
void delay(int);
void ADCpoweron(int);
void My_IRQ_Function(void); // IRQ Function Prototype
int main(void) {
GP4DAT = 0x04000000; // P4.2 configured as an output. LED is
turned on
//timer2 configuration
T2CON = 0xE8; // Configures Timer2 to count down, with
// "Hr:Min:Sec:Hundredths" format and
prescalar of 256
T2CLRI = 0xFF; // Clearing Timer2 Interrupt
T2LD = 0x780; // Sets the counter register to 3 sec.
Format: HH:MM:SS:hh
IRQ = My_IRQ_Function; // Specify Interrupt Service Rountine
IRQEN = WAKEUP_TIMER_BIT; // Enable general purpose timer
while(1){
GP4DAT ^= 0x00040000; // Complement P4.2
delay(100001);
}
}
/********************************************************************/
/* */
/* Interrupt Service Routine */
/* */
/********************************************************************/
void My_IRQ_Function()
{
//Blinking slower each time when interrupt occurs
int i=0;
for (i=0; i<=5; i++){
delay(1000000);
GP4DAT ^= 0x00040000; // Complement P4.2
}
T2CLRI = 0xFF; // Clearing Timer2 Interrupt
return;
}
void ADCpoweron(int time){
ADCCON = 0x620; // power-on the ADC
while (time >=0) // wait for ADC to be fully powered on
time--;
}
void delay (int length) {
while (length >=0){
length--; }
}
Hat sich erledigt, mussteT2CON umändern und neu berechnen. Jetzt klappts, danke!
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.