xMega A3BU XPlained

Gast #2727874
Lesenswert?

Hallo Zusammen,

ich versuche auf dem oben genanten uC mittels eines Exteneninterrupts 
einen Timer zu reseten und die gezählten Schritte auf dem Display 
auszugeben. Der Interrupt funktioniert soweit leider bekomme ich 
zufällige zahlen beim Timercount. Dabei wird der Intterupt für den 
Timerüberauf nicht aufgerufen. Momentan habe ich keine Idee mehr zur 
Lösung des Probelems und würde mich über jeden Tipp freuen.

Ich bin mir mit dem funktionen für tc_read_count und rc_reset unsicher 
ob die so funktionieren.

Den Quellcode habe ich angehanegn.

Vielen Dank schonmal im Vorraus
1
#include <conf_example.h>
2
#include <stdio.h>
3
#include <asf.h>
4
#include <avr/sleep.h>
5

6

7
char buf[100];
8

9
ISR(PORTB_INT0_vect){ 
10

11
cli();
12
  
13
  itoa(tc_read_count(&TCC0),buf,10);
14
  gfx_mono_draw_string(buf, 1, 1, &sysfont);
15
  
16
  itoa(TCC0.CNT,buf,8);
17
  gfx_mono_draw_string(buf,15, 15, &sysfont);
18
  
19
  TCC0.CNT=0;
20
  tc_reset(&TCC0);
21
  sei();
22
}
23

24
void ticktimer_callback(){
25

26
itoa(tc_read_count(&TCC0),buf,10);
27
gfx_mono_draw_string(buf, 1, 10, &sysfont);
28

29
}
30
static void init_timer_d0(void)
31
{
32

33
  
34
  tc_enable(&TCC0);
35
  tc_set_wgm(&TCC0, TC_WG_NORMAL);
36
  tc_write_period(&TCC0, 50000);
37
  tc_set_overflow_interrupt_level(&TCC0, TC_INT_LVL_HI);
38
  tc_set_overflow_interrupt_callback(&TCC0, ticktimer_callback); 
39
  tc_write_clock_source(&TCC0, TC_CLKSEL_DIV64_gc);
40
}
41

42
int main(void)
43
{
44

45
  board_init();
46
  sysclk_init();
47
  pmic_init();
48
  init_timer_d0();
49
  gfx_mono_init();
50
  cpu_irq_enable();
51
  
52
  
53
  
54
  ioport_configure_pin(PORTB_PIN0CTRL, IOPORT_DIR_INPUT | IOPORT_PULL_DOWN );   //!< Set Proxpoint Data0 port direction to input
55
  PORTB_INTCTRL = PORT_INT0LVL_LO_gc; // set low interrupt level;
56
  PORTB_INT0MASK = 0xFF;  // set all pins as source for port interrupt 0
57
  PORTCFG.MPCMASK = 0xFF;
58
  PORTB.PIN0CTRL = PORT_OPC_PULLUP_gc + PORT_ISC_BOTHEDGES_gc; // set pin pull up, sense both edges
59
  
60
  // Enable interrupts
61
  sei();
62
  
63
  // Enable the back light of the LCD
64
  ioport_set_pin_high(LCD_BACKLIGHT_ENABLE_PIN);
65
  do {
66

67
  } while (1);
68
}
Angehängte Dateien:

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