Moin Moin liebe Forumsmitglieder. Mein erster Beitrag und damit schon mal sorry für eine vielleicht einfache Frage und herzlichsten Dank an diejenigen die unermüdlich Hilfe leisten ( Hut ab! ). Ich möchte unter anderem ein paar multiplexer ( SN74595 ) ansteuern deren daten über ein globales array im Zugriff liegen. Die Multiplexer werden mit einem Timer (Timer 0) alle 4ms auf Stand gebracht indem eine funktion aufgerufen wird die auf das evtl. aktualisierte array zugegreift. Die Idee ist, irgendwo im code das array zu ändern und das dann durch die ISR des Timers abarbeiten zu lassen. Jetzt möchte ich aber auch das array innerhalb einer anderen ISR ( Timer 1 ) verändern. Dazu ist dann das globale array auf volatile zu definieren da es innerhalb einer ISR und im main() geändert wird. Mit
1 | unsigned char mux[MUX_SIZE]; |
global funktioniert das updaten in ISR TM1 tadellos jedoch eine änderung im main() bleibt unbeachtet. Mit
1 | volatile unsigned char mux[MUX_SIZE; |
und folgerichtig in mux_out()
1 | volatile unsigned char *muxp = mux + MUX_SIZE; |
funktioniert das automatische updaten in main() via TM0, aber nicht mehr über ISR TIM1. Ich bin da echt ratlos.... Hat jemand von euch eine Idee was hier falsch ist?? 1000000000000 * 10 ^ 12 Dank für konstruktive Hilfe Karsten
1 | // Defines
|
2 | #define MUX_SIZE 2 // Number of installed MUX ( 74LS595 )
|
3 | |
4 | #define REED1 2 // Multiplexer # for reed relais
|
5 | #define MX_RPAON 1 // Mux OUT for reed PA on
|
6 | #define MX_LPAON 4 // Mux OUT for
|
7 | |
8 | #define INIT 1 // State for Power max
|
9 | #define PWRMAX 2 // State for Power max
|
10 | |
11 | // Prototypes
|
12 | void init(void); |
13 | void mux_out(void); |
14 | |
15 | // Global vars
|
16 | unsigned char mux[MUX_SIZE]; |
17 | int8_t state = INIT; |
18 | |
19 | |
20 | int
|
21 | main(void) { |
22 | |
23 | init(); // initialize timer / mux .... |
24 | sei(); |
25 | |
26 | while(1) { |
27 | |
28 | if(state == PWRON) { |
29 | |
30 | ....
|
31 | state = PWRMAX; // initiate blink of MX_LPAON via TIM1 |
32 | // at ISR TM1 the changed state will update the mux array
|
33 | // at ISR TM0 the mux_out() function is calle to update the
|
34 | // multiplexer outputs.
|
35 | ....
|
36 | |
37 | cli(); |
38 | mux[2] |= (1 << MX_LPAON); |
39 | state = RUN; |
40 | sei(); |
41 | // try atomic. Switch LPAON to off and update state. On next cycle of
|
42 | // TM1 the blink modeof MX_LPAON is off. With next TM0 the mux_out()
|
43 | // function will update the multiplexer outputs.
|
44 | }
|
45 | |
46 | ....
|
47 | if(key_press_short(1 << KEY_PAON)) { |
48 | ....
|
49 | mux[REED1] |= (1 << MX_RPAON); |
50 | // This update should be active with next TH0 cycle.
|
51 | }
|
52 | }
|
53 | |
54 | }
|
55 | |
56 | // ISR called every 4ms
|
57 | ISR(TIM0_COMPA_vect) { |
58 | |
59 | ....
|
60 | mux_out(); |
61 | }
|
62 | |
63 | |
64 | // ISR called every 100ms
|
65 | ISR(TIM1_COMPA_vect) { |
66 | |
67 | ...
|
68 | if(state == PWRMAX) |
69 | mux[REED1] ^= (1 << MX_LPAON); |
70 | }
|
71 | |
72 | |
73 | // write mux array bytes bit per bit to multiplexer
|
74 | void
|
75 | mux_out(void) { |
76 | |
77 | unsigned char* muxp = mux + MUX_SIZE; |
78 | |
79 | .....
|
80 | }
|