Hallo,
ich habe ein kleines Problem mit meinem µC Sourcecode. Ich nehme
verschiedene Messwerte mit den ADCs auf und verarbeite diese weiter und
sende zusätzlich die Messdaten auf eine SDKarte. Jede Sekunde werden
Messwerte gesendet. Das funktioniert auch super. Jedoch habe ich ein
Problem mit meiner Bluetooth Schnittstelle. Ich kann diese nur auf 38.4k
einstellen. Dadurch kommt mein Timer nicht hinterher. Anstatt für 60
Werte 60s zu brauchen, sind es ~70s. Das liegt daran, dass ich für meine
Messwerte ~100ms brauche (512byte bei 38.4k sind ~100ms). Ich habe
meinen Timer im Compare Match laufen und lasse ihn jede 50ms triggern,
da ich noch einen Regler dazwischen setzen möchte (kommt noch).
Meine Überlegung für dieses Problem war es zwei Timer laufen zu lassen.
Den ersten so laufen lassen wie üblich, also jede 50ms und einen der
jede 1s auslöst. Nur irgendwie funktioniert die Geschichte nicht. Ist
das prinzipiell nicht möglich oder habe ich da noch einen Bock drin?
1 | // ~~~ =================================================================== ~~~
|
2 | // === MainTimer Init ========================================================
|
3 | void MainTimer_Init()
|
4 | //
|
5 | //
|
6 | {
|
7 | // CTC modus, Prescaler 8, OCR3A as compare match register
|
8 | // RC Oscilator 10Mhz
|
9 | TCCR3B = (1<<WGM32) | (0<<CS32) | (1<<CS31) | (0<<CS30); // CTC, prescaler
|
10 | TCCR3C = (1<<FOC3A); // force output compare match for channel A
|
11 | OCR3A = 62500-1; // output compare register
|
12 | TIMSK3 = (1<<OCIE3A); // output compare A match interrupt enable
|
13 |
|
14 | // initialization of timevariables
|
15 | twentieth = 0;
|
16 | centisec = 0;
|
17 | second = 0;
|
18 | minute = 0;
|
19 | hour = 0;
|
20 |
|
21 | // CTC modus, Prescaler 64, OCR4A as compare match register
|
22 | // RC Oscilator 10Mhz
|
23 | TCCR4B = (1<<WGM42) | (0<<CS42) | (1<<CS41) | (1<<CS40); // CTC, prescaler
|
24 | TCCR4C = (1<<FOC4A); // force output compare match for channel A
|
25 | OCR4A = 15625-1; // output compare register
|
26 | TIMSK4 = (1<<OCIE4A); // output compare A match interrupt enable
|
27 | }
|
28 |
|
29 | // ~~~ =================================================================== ~~~
|
30 | // === MainTimer ISR =========================================================
|
31 | ISR (TIMER3_COMPA_vect)
|
32 | //
|
33 | //
|
34 | {
|
35 | twentieth++;
|
36 | if(twentieth == 2)
|
37 | {
|
38 | centisec++;
|
39 | twentieth = 0;
|
40 |
|
41 | if(((FET_Read(VALVE0)) != 0) && centisec == 2)
|
42 | // if the switcher (purge-valve) is enabled and x centisec past...
|
43 | FET_Set(VALVE0, 0); // ...reset the purge-valve to zero
|
44 |
|
45 | if(centisec == 10)
|
46 | {
|
47 | if(second == 60)
|
48 | {
|
49 | FET_Set(VALVE0, 1); // through-connect purge-valve after 60 sec
|
50 |
|
51 | minute++;
|
52 | second = 0;
|
53 | }
|
54 | if(minute == 60)
|
55 | {
|
56 | hour++;
|
57 | minute = 0;
|
58 | }
|
59 | if(hour == 24)
|
60 | {
|
61 | hour = 0;
|
62 | }
|
63 |
|
64 | MainTimer_ConvertTime();
|
65 |
|
66 |
|
67 | second++;
|
68 | centisec = 0;
|
69 |
|
70 | }
|
71 | }
|
72 | }
|
73 |
|
74 | ISR (TIMER4_COMPA_vect)
|
75 | {
|
76 | BatLoad -= (long)(SysData[13]*100);
|
77 | SysData[15] = BatLoad;
|
78 |
|
79 | HydrogenLoad -= (SysData[18]*100)/60;
|
80 | SysData[21] = HydrogenLoad;
|
81 |
|
82 |
|
83 | SD_Write(); // save current measurement data to SD card every second
|
84 | Bluetooth_Transmit(BluetoothBuffer);
|
85 | }
|