ATtiny414 TCA0 Timer funktioniert nicht wie erwartet

Gast #5935610
Lesenswert?

Guten Morgen,

ich stehe gerade leider etwas auf dem Schlauch. Ich versuche den TCA0 
des ATtiny414 zum laufen zu bekommen.
Ziel ist es ihn so zu konfigurieren, dass er mit 100Hz das 
Timer-Overflow-Interrupt auslöst. Leider scheint es aber so, dass egal 
welchen Prescaler ich einstelle und welchen Wert ich in das Period 
Register schreibe er immer mit 70kHz läuft.

Hier mal ein Auszug wie ich ihn konfiguriert habe:
1
TCA0_SINGLE_CTRLA |= (1<<TCA_SINGLE_CLKSEL2_bp);  //CLKDIV 16 (16MHz core frequency)
2
  TCA0_SINGLE_INTCTRL |= (1<<TCA_SINGLE_OVF_bp);    //Overflow interrupt enabled
3
  TCA0_SINGLE_PER = 9999;                //1MHz / 10000 = 100Hz
4
  TCA0_SINGLE_CTRLA |= (1<<TCA_SINGLE_ENABLE_bp);    //Enable timer
5
  
6
  sei();  //Global interrupt enable
7

8
ISR(TCA0_OVF_vect){
9
  
10
}

Hat jemand eine Idee woran das liegen könnte?

Über ein paar Tipps würde ich mich freuen.
Gruß Dominik
#5935626
Lesenswert?

void tca0_init(void)
{
// First disable and reset the Timer/Counter TCA0
// Use 16-bit mode
tca_disable(&TCA0);

// Clock divider: 4
// Clock frequency: 4000,000 kHz
TCA0.SINGLE.CTRLA=TCA_SINGLE_CLKSEL_DIV4_gc;

// Operating mode: Normal 16-bit OVF=TOP
TCA0.SINGLE.CTRLB=TCA_SINGLE_WGMODE_NORMAL_gc;

// Set the Timer Counter register
TCA0.SINGLE.CNT=0x00;

// Set the Timer Period register
// Specified period: 10 ms
// Obtained: 10 ms, 0,00 % error
TCA0.SINGLE.PER=0x9C3F;

// Set TCA0 interrupts:
// Overflow interrupt: On
// Compare Channel 0 interrupt: Off
// Compare Channel 1 interrupt: Off
// Compare Channel 2 interrupt: Off
TCA0.SINGLE.INTCTRL=
    (1<<TCA_SINGLE_OVF_bp)+
    (0<<TCA_SINGLE_CMP0_bp)+
    (0<<TCA_SINGLE_CMP1_bp)+
    (0<<TCA_SINGLE_CMP2_bp);

// Initialization finished, enable TCA0
TCA0.SINGLE.CTRLA|=TCA_SINGLE_ENABLE_bm;
}

Keine Ahnung ob dir das was hilft und ob das tatsächlich funktioniert.
#5935672
Lesenswert?

Hallo,

bei der mega AVR 0 Serie muss man das Interrupt Flag in der ISR von Hand 
löschen. Könnte beim Tiny ähnlich sein.
Bsp.
1
void TCA0_init(void)
2
{
3
  // enable overflow interrupt 
4
  TCA0.SINGLE.INTCTRL = TCA_SINGLE_OVF_bm;
5
  
6
  // set Normal mode 
7
  TCA0.SINGLE.CTRLB = TCA_SINGLE_WGMODE_NORMAL_gc;
8
  
9
  // disable event counting 
10
  TCA0.SINGLE.EVCTRL &= ~(TCA_SINGLE_CNTEI_bm);
11
  
12
  // set the period 
13
  TCA0.SINGLE.PER = PERIOD_EXAMPLE_VALUE;
14
  
15
  // set clock
16
  TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV8_gc | TCA_SINGLE_ENABLE_bm;    /* source (sys_clk/8) +  start timer */  
17
  
18
               
19
}
20

21
void PORT_init(void)
22
{
23
  // set pin 0 of PORT A as output
24
  PORTF.DIR |= PIN2_bm;
25
}
26

27
ISR(TCA0_OVF_vect)
28
{
29
  // Toggle PIN 2 of PORT F 
30
  PORTF.OUTTGL = PIN2_bm;
31
  
32
  // The interrupt flag has to be cleared manually 
33
  TCA0.SINGLE.INTFLAGS = TCA_SINGLE_OVF_bm;
34
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren