Hallo,
ich bin gerade dabei mir ein 32 Bit Zeitstempel zu programmieren. Das
funktioniert auch fast perfekt. Um den Code zu testen, habe ich mir eine
Warteschleife programmiert, die eine LED alle X Mikrosekunden
ausschaltet und dann sofort wieder einschaltet. Das funktioniert auch
nur soweit, nur zwischen drin, kommt es immer wieder zu einem
Doppelpuls(Siehe Oszibild). Woher kommt der Ausreißer?
Timer Klasse: CPP-Datei
static Systemtimer* pSystemtimer;
1 | uint32_t Systemtimer::SystemtimerGetTime()
|
2 | {
|
3 | uint32_t time;
|
4 | cli();
|
5 |
|
6 | time=(uint32_t)(TCNT1)+pSystemtimer->Time;
|
7 | sei();
|
8 | return time;
|
9 | }
|
10 |
|
11 | ISR(TIMER1_OVF_vect)
|
12 | {
|
13 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
|
14 | {
|
15 | pSystemtimer->Time+=0x10000;
|
16 |
|
17 | }
|
18 |
|
19 | }
|
Header Datei:
1 | class Systemtimer
|
2 | {
|
3 |
|
4 | uint32_t SystemtimerGetTime();
|
5 |
|
6 | //Use Time in atomic Block
|
7 | volatile uint32_t Time;
|
8 |
|
9 |
|
10 | }; //Systemtimer
|
Main:
1 | uint32_t nexttime,current,waiting=100;
|
2 |
|
3 |
|
4 | current=timestamp.SystemtimerGetTime();
|
5 |
|
6 | while(1)
|
7 | {
|
8 | LED.SetLed(false);
|
9 |
|
10 | do
|
11 | {
|
12 | LED.SetLed(true);
|
13 | nexttime=timestamp.SystemtimerGetTime();
|
14 | } while (nexttime-current<waiting);
|
15 | current=nexttime;
|
16 |
|
17 | }
|