Subversion Repositories HomeAutomation

Rev

Rev 1388 | Rev 1395 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1388 Rev 1394
Line 2... Line 2...
2
#include "act_softPWM.h"
2
#include "act_softPWM.h"
3
 
3
 
-
 
4
#if (act_softPWM_PIN_0_INVERT == 0)
-
 
5
    #define set_pin_0_below_trigger gpio_set_pin(act_softPWM_PIN_0)
-
 
6
    #define set_pin_0_above_trigger gpio_clr_pin(act_softPWM_PIN_0)
-
 
7
#else
-
 
8
    #define set_pin_0_below_trigger gpio_set_pin(act_softPWM_PIN_0)
-
 
9
    #define set_pin_0_above_trigger gpio_clr_pin(act_softPWM_PIN_0)
-
 
10
#endif
-
 
11
 
-
 
12
#if (act_softPWM_PIN_1_INVERT == 0)
-
 
13
    #define set_pin_1_below_trigger gpio_set_pin(act_softPWM_PIN_1)
-
 
14
    #define set_pin_1_above_trigger gpio_clr_pin(act_softPWM_PIN_1)
-
 
15
#else
-
 
16
    #define set_pin_1_below_trigger gpio_set_pin(act_softPWM_PIN_1)
-
 
17
    #define set_pin_1_above_trigger gpio_clr_pin(act_softPWM_PIN_1)
-
 
18
#endif
-
 
19
 
-
 
20
#if (act_softPWM_PIN_2_INVERT == 0)
-
 
21
    #define set_pin_2_below_trigger gpio_set_pin(act_softPWM_PIN_2)
-
 
22
    #define set_pin_2_above_trigger gpio_clr_pin(act_softPWM_PIN_2)
-
 
23
#else
-
 
24
    #define set_pin_2_below_trigger gpio_set_pin(act_softPWM_PIN_2)
-
 
25
    #define set_pin_2_above_trigger gpio_clr_pin(act_softPWM_PIN_2)
-
 
26
#endif
-
 
27
 
-
 
28
#if (act_softPWM_PIN_3_INVERT == 0)
-
 
29
    #define set_pin_3_below_trigger gpio_set_pin(act_softPWM_PIN_3)
-
 
30
    #define set_pin_3_above_trigger gpio_clr_pin(act_softPWM_PIN_3)
-
 
31
#else
-
 
32
    #define set_pin_3_below_trigger gpio_set_pin(act_softPWM_PIN_3)
-
 
33
    #define set_pin_3_above_trigger gpio_clr_pin(act_softPWM_PIN_3)
-
 
34
#endif
-
 
35
 
-
 
36
#if (act_softPWM_PIN_4_INVERT == 0)
-
 
37
    #define set_pin_4_below_trigger gpio_set_pin(act_softPWM_PIN_4)
-
 
38
    #define set_pin_4_above_trigger gpio_clr_pin(act_softPWM_PIN_4)
-
 
39
#else
-
 
40
    #define set_pin_4_below_trigger gpio_set_pin(act_softPWM_PIN_4)
-
 
41
    #define set_pin_4_above_trigger gpio_clr_pin(act_softPWM_PIN_4)
-
 
42
#endif
-
 
43
 
-
 
44
#if (act_softPWM_PIN_5_INVERT == 0)
-
 
45
    #define set_pin_5_below_trigger gpio_set_pin(act_softPWM_PIN_5)
-
 
46
    #define set_pin_5_above_trigger gpio_clr_pin(act_softPWM_PIN_5)
-
 
47
#else
-
 
48
    #define set_pin_5_below_trigger gpio_set_pin(act_softPWM_PIN_5)
-
 
49
    #define set_pin_5_above_trigger gpio_clr_pin(act_softPWM_PIN_5)
-
 
50
#endif
-
 
51
 
-
 
52
#if (act_softPWM_PIN_6_INVERT == 0)
-
 
53
    #define set_pin_6_below_trigger gpio_set_pin(act_softPWM_PIN_6)
-
 
54
    #define set_pin_6_above_trigger gpio_clr_pin(act_softPWM_PIN_6)
-
 
55
#else
-
 
56
    #define set_pin_6_below_trigger gpio_set_pin(act_softPWM_PIN_6)
-
 
57
    #define set_pin_6_above_trigger gpio_clr_pin(act_softPWM_PIN_6)
-
 
58
#endif
-
 
59
 
-
 
60
#if (act_softPWM_PIN_7_INVERT == 0)
-
 
61
    #define set_pin_7_below_trigger gpio_set_pin(act_softPWM_PIN_7)
-
 
62
    #define set_pin_7_above_trigger gpio_clr_pin(act_softPWM_PIN_7)
-
 
63
#else
-
 
64
    #define set_pin_7_below_trigger gpio_set_pin(act_softPWM_PIN_7)
-
 
65
    #define set_pin_7_above_trigger gpio_clr_pin(act_softPWM_PIN_7)
-
 
66
#endif
4
 
67
 
5
uint16_t currentTimer = 0;
68
static uint16_t currentTimer = 0;
6
uint16_t maxTimer = 10;
69
static uint16_t maxTimer = 10;
7
uint8_t resolution = 1;
70
static uint8_t  resolution = 1;
8
uint8_t act_softPWM_ReportInterval;
71
static uint8_t act_softPWM_ReportInterval =0;
9
uint8_t currentSendChannelId = 0;
72
static uint8_t currentSendChannelId = 0;
10
 
73
 
11
 
74
 
12
#ifdef act_softPWM_USEEEPROM
75
#ifdef act_softPWM_USEEEPROM
13
#include "act_softPWM_eeprom.h"
76
#include "act_softPWM_eeprom.h"
14
struct eeprom_act_softPWM EEMEM eeprom_act_softPWM =
77
struct eeprom_act_softPWM EEMEM eeprom_act_softPWM =
Line 21... Line 84...
21
    },
84
    },
22
    0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
85
    0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
23
};
86
};
24
#endif
87
#endif
25
 
88
 
26
uint16_t pwmValue[NUMBEROFCHANNELS];
89
static uint16_t pwmValue[NUMBEROFCHANNELS];
27
uint16_t pwmValueCAN[NUMBEROFCHANNELS];
90
static uint16_t pwmValueCAN[NUMBEROFCHANNELS];
-
 
91
 
28
#if act_softPWM_ACTIVATE_AUTOOFF != 0
92
#if act_softPWM_ACTIVATE_AUTOOFF != 0
29
uint8_t offCounter[NUMBEROFCHANNELS];
93
static uint8_t offCounter[NUMBEROFCHANNELS];
30
#endif
94
#endif
-
 
95
 
31
void act_softPWM_Init(void)
96
void act_softPWM_Init(void)
32
{
97
{
33
#ifdef act_softPWM_USEEEPROM
98
#ifdef act_softPWM_USEEEPROM
34
    //if (EEDATA_OK)
99
    //if (EEDATA_OK)
35
    //{
100
    //{
Line 49... Line 114...
49
    ///TODO: Initialize hardware etc here
114
    ///TODO: Initialize hardware etc here
50
uint8_t i;
115
uint8_t i;
51
for (i=0; i < NUMBEROFCHANNELS; i++) {
116
for (i=0; i < NUMBEROFCHANNELS; i++) {
52
    pwmValue[i] = 0;
117
    pwmValue[i] = 0;
53
    pwmValueCAN[i] = 0;
118
    pwmValueCAN[i] = 0;
54
}
119
}
55
#ifdef PIN_0
120
#ifdef act_softPWM_PIN_0
56
    gpio_set_out(PIN_0);
121
    gpio_set_out(act_softPWM_PIN_0);
57
    gpio_clr_pin(PIN_0);
122
    set_pin_0_below_trigger;
58
#endif
123
#endif
59
#ifdef PIN_1
124
#ifdef act_softPWM_PIN_1
60
    gpio_set_out(PIN_1);
125
    gpio_set_out(act_softPWM_PIN_1);
61
    gpio_clr_pin(PIN_1);
126
    set_pin_1_below_trigger;
62
#endif
127
#endif
63
#ifdef PIN_2
128
#ifdef act_softPWM_PIN_2
64
    gpio_set_out(PIN_2);
129
    gpio_set_out(act_softPWM_PIN_2);
65
    gpio_clr_pin(PIN_2);
130
    set_pin_2_below_trigger;
66
#endif
131
#endif
67
#ifdef PIN_3
132
#ifdef act_softPWM_PIN_3
68
    gpio_set_out(PIN_3);
133
    gpio_set_out(act_softPWM_PIN_3);
69
    gpio_clr_pin(PIN_3);
134
    set_pin_3_below_trigger;
70
#endif
135
#endif
71
#ifdef PIN_4
136
#ifdef act_softPWM_PIN_4
72
    gpio_set_out(PIN_4);
137
    gpio_set_out(act_softPWM_PIN_4);
73
    gpio_clr_pin(PIN_4);
138
    set_pin_4_below_trigger;
74
#endif
139
#endif
75
#ifdef PIN_5
140
#ifdef act_softPWM_PIN_5
76
    gpio_set_out(PIN_5);
141
    gpio_set_out(act_softPWM_PIN_5);
77
    gpio_clr_pin(PIN_5);
142
    set_pin_5_below_trigger;
78
#endif
143
#endif
79
#ifdef PIN_6
144
#ifdef act_softPWM_PIN_6
80
    gpio_set_out(PIN_6);
145
    gpio_set_out(act_softPWM_PIN_6);
81
    gpio_clr_pin(PIN_6);
146
    set_pin_6_below_trigger;
82
#endif
147
#endif
83
#ifdef PIN_7
148
#ifdef act_softPWM_PIN_7
84
    gpio_set_out(PIN_7);
149
    gpio_set_out(act_softPWM_PIN_7);
85
    gpio_clr_pin(PIN_7);
150
    set_pin_7_below_trigger;
86
#endif
151
#endif
87
   
152
   
88
    Timer_SetTimeout(act_softPWM_TIMER, resolution, TimerTypeFreeRunning, NULL);
153
    Timer_SetTimeout(act_softPWM_TIMER, resolution, TimerTypeFreeRunning, NULL);
89
}
154
}
90
 
155
 
91
void act_softPWM_Process(void)
156
void act_softPWM_Process(void)
92
{
157
{
93
    if (Timer_Expired(act_softPWM_TIMER)) {
158
    if (Timer_Expired(act_softPWM_TIMER)) {
94
        currentTimer++;
159
        currentTimer++;
95
        if (currentTimer >= maxTimer) {
160
        if (currentTimer >= maxTimer) {
96
//printf("cleard Timer %d\n",pwmValue[0]);
161
//printf("cleard Timer %d\n",pwmValue[0]);
97
            currentTimer=0;
162
            currentTimer=0;
98
            #ifdef PIN_0
163
            #ifdef act_softPWM_PIN_0
99
                if (pwmValue[0]!=0) {
164
                if (pwmValue[0]!=0) {
100
                    gpio_set_pin(PIN_0);
165
                    set_pin_0_below_trigger;
101
//printf("pwm_0 On %d %d %d\n", pwmValue[0], currentTimer, maxTimer); 
-
 
102
}
166
                }
103
            #endif
167
            #endif
104
            #ifdef PIN_1 
168
            #ifdef act_softPWM_PIN_1 
105
                if (pwmValue[1]!=0)
169
                if (pwmValue[1]!=0) {
106
                    gpio_set_pin(PIN_1);
170
                    set_pin_1_below_trigger;
-
 
171
                }
107
            #endif
172
            #endif
108
            #ifdef PIN_2 
173
            #ifdef act_softPWM_PIN_2 
109
                if (pwmValue[2]!=0)
174
                if (pwmValue[2]!=0) {
110
                    gpio_set_pin(PIN_2);
175
                    set_pin_2_below_trigger;
-
 
176
                }
111
            #endif
177
            #endif
112
            #ifdef PIN_3 
178
            #ifdef act_softPWM_PIN_3 
113
                if (pwmValue[3]!=0)
179
                if (pwmValue[3]!=0) {
114
                    gpio_set_pin(PIN_3);
180
                    set_pin_3_below_trigger;
-
 
181
                }
115
            #endif
182
            #endif
116
            #ifdef PIN_4 
183
            #ifdef act_softPWM_PIN_4 
117
                if (pwmValue[4]!=0)
184
                if (pwmValue[4]!=0) {
118
                    gpio_set_pin(PIN_4);
185
                    set_pin_4_below_trigger;
-
 
186
                }
119
            #endif
187
            #endif
120
            #ifdef PIN_5 
188
            #ifdef act_softPWM_PIN_5 
121
                if (pwmValue[5]!=0)
189
                if (pwmValue[5]!=0) {
122
                    gpio_set_pin(PIN_5);
190
                    set_pin_5_below_trigger;
-
 
191
                }
123
            #endif
192
            #endif
124
            #ifdef PIN_6 
193
            #ifdef act_softPWM_PIN_6 
125
                if (pwmValue[6]!=0)
194
                if (pwmValue[6]!=0) {
126
                    gpio_set_pin(PIN_6);
195
                    set_pin_6_below_trigger;
-
 
196
                }
127
            #endif
197
            #endif
128
            #ifdef PIN_7 
198
            #ifdef act_softPWM_PIN_7 
129
                if (pwmValue[7]!=0)
199
                if (pwmValue[7]!=0) {
130
                    gpio_set_pin(PIN_7);
200
                    set_pin_7_below_trigger;
-
 
201
                }
131
            #endif
202
            #endif
132
        }
203
        }
133
        #ifdef PIN_0
204
        #ifdef act_softPWM_PIN_0
134
        if (currentTimer >= pwmValue[0] && gpio_get_state(PIN_0) != 0) {
205
        if (currentTimer >= pwmValue[0] && gpio_get_state(act_softPWM_PIN_0) != 0) {
135
            gpio_clr_pin(PIN_0);
206
            set_pin_0_above_trigger;
136
//printf("pwm_0 Off %d %d %d\n", pwmValue[0], currentTimer, maxTimer);
-
 
137
        }
207
        }
138
        #endif
208
        #endif
139
        #ifdef PIN_1
209
        #ifdef act_softPWM_PIN_1
140
        if (currentTimer >= pwmValue[1] && gpio_get_state(PIN_1) != 0) {
210
        if (currentTimer >= pwmValue[1] && gpio_get_state(act_softPWM_PIN_1) != 0) {
141
            gpio_clr_pin(PIN_1);
211
            set_pin_1_above_trigger;
142
        }
212
        }
143
        #endif
213
        #endif
144
        #ifdef PIN_2
214
        #ifdef act_softPWM_PIN_2
145
        if (currentTimer >= pwmValue[2] && gpio_get_state(PIN_2) != 0) {
215
        if (currentTimer >= pwmValue[2] && gpio_get_state(act_softPWM_PIN_2) != 0) {
146
            gpio_clr_pin(PIN_2);
216
            set_pin_2_above_trigger;
147
        }
217
        }
148
        #endif
218
        #endif
149
        #ifdef PIN_3
219
        #ifdef act_softPWM_PIN_3
150
        if (currentTimer >= pwmValue[3] && gpio_get_state(PIN_3) != 0) {
220
        if (currentTimer >= pwmValue[3] && gpio_get_state(act_softPWM_PIN_3) != 0) {
151
            gpio_clr_pin(PIN_3);
221
            set_pin_3_above_trigger;
152
        }
222
        }
153
        #endif
223
        #endif
154
        #ifdef PIN_4
224
        #ifdef act_softPWM_PIN_4
155
        if (currentTimer >= pwmValue[4] && gpio_get_state(PIN_4) != 0) {
225
        if (currentTimer >= pwmValue[4] && gpio_get_state(act_softPWM_PIN_4) != 0) {
156
            gpio_clr_pin(PIN_4);
226
            set_pin_4_above_trigger;
157
        }
227
        }
158
        #endif
228
        #endif
159
        #ifdef PIN_5
229
        #ifdef act_softPWM_PIN_5
160
        if (currentTimer >= pwmValue[5] && gpio_get_state(PIN_5) != 0) {
230
        if (currentTimer >= pwmValue[5] && gpio_get_state(act_softPWM_PIN_5) != 0) {
161
            gpio_clr_pin(PIN_5);
231
            set_pin_5_above_trigger;
162
        }
232
        }
163
        #endif
233
        #endif
164
        #ifdef PIN_6
234
        #ifdef act_softPWM_PIN_6
165
        if (currentTimer >= pwmValue[6] && gpio_get_state(PIN_6) != 0) {
235
        if (currentTimer >= pwmValue[6] && gpio_get_state(act_softPWM_PIN_6) != 0) {
166
            gpio_clr_pin(PIN_6);
236
            set_pin_6_above_trigger;
167
        }
237
        }
168
        #endif
238
        #endif
169
        #ifdef PIN_7
239
        #ifdef act_softPWM_PIN_7
170
        if (currentTimer >= pwmValue[7] && gpio_get_state(PIN_7) != 0) {
240
        if (currentTimer >= pwmValue[7] && gpio_get_state(act_softPWM_PIN_7) != 0) {
171
            gpio_clr_pin(PIN_7);
241
            set_pin_7_above_trigger;
172
        }
242
        }
173
        #endif
243
        #endif
174
    }
244
    }
175
    if (Timer_Expired(act_softPWM_SEND_TIMER)) {
245
    if (Timer_Expired(act_softPWM_SEND_TIMER)) {
176
//printf("sending...\n");
246
//printf("sending...\n");
177
        while(1)
247
        while(1)
178
        {
248
        {
179
            if (0
249
            if (0
180
                #ifdef PIN_0
250
                #ifdef act_softPWM_PIN_0
181
                || currentSendChannelId == 0
251
                || currentSendChannelId == 0
182
                #endif
252
                #endif
183
                #ifdef PIN_1
253
                #ifdef act_softPWM_PIN_1
184
                || currentSendChannelId == 1
254
                || currentSendChannelId == 1
185
                #endif
255
                #endif
186
                #ifdef PIN_2
256
                #ifdef act_softPWM_PIN_2
187
                || currentSendChannelId == 2
257
                || currentSendChannelId == 2
188
                #endif
258
                #endif
189
                #ifdef PIN_3
259
                #ifdef act_softPWM_PIN_3
190
                || currentSendChannelId == 3
260
                || currentSendChannelId == 3
191
                #endif
261
                #endif
192
                #ifdef PIN_4
262
                #ifdef act_softPWM_PIN_4
193
                || currentSendChannelId == 4
263
                || currentSendChannelId == 4
194
                #endif
264
                #endif
195
                #ifdef PIN_5
265
                #ifdef act_softPWM_PIN_5
196
                || currentSendChannelId == 5
266
                || currentSendChannelId == 5
197
                #endif
267
                #endif
198
                #ifdef PIN_6
268
                #ifdef act_softPWM_PIN_6
199
                || currentSendChannelId == 6
269
                || currentSendChannelId == 6
200
                #endif
270
                #endif
201
                #ifdef PIN_7
271
                #ifdef act_softPWM_PIN_7
202
                || currentSendChannelId == 7
272
                || currentSendChannelId == 7
203
                #endif
273
                #endif
204
            ) {
274
            ) {
205
                break;
275
                break;
206
            }
276
            }
Line 215... Line 285...
215
        txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_SOFTPWM;
285
        txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_SOFTPWM;
216
        txMsg.Header.ModuleId = act_softPWM_ID;
286
        txMsg.Header.ModuleId = act_softPWM_ID;
217
        txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PWM;
287
        txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PWM;
218
        txMsg.Length = 3;
288
        txMsg.Length = 3;
219
        txMsg.Data[0] = currentSendChannelId;
289
        txMsg.Data[0] = currentSendChannelId;
220
        txMsg.Data[1] = (pwmValueCAN[currentSendChannelId]>>8)&0xff;
290
        txMsg.Data[1] = (pwmValue[currentSendChannelId]>>8)&0xff;
221
        txMsg.Data[2] = (pwmValueCAN[currentSendChannelId])&0xff;
291
        txMsg.Data[2] = (pwmValue[currentSendChannelId])&0xff;
222
        while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
292
        while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
223
//printf("sent pwm2: %d %d\n",pwmValueCAN[currentSendChannelId],currentSendChannelId); 
293
//printf("sent pwm2: %d %d\n",pwmValueCAN[currentSendChannelId],currentSendChannelId); 
224
#if act_softPWM_ACTIVATE_AUTOOFF != 0
294
#if act_softPWM_ACTIVATE_AUTOOFF != 0
225
        offCounter[currentSendChannelId]--;
295
        offCounter[currentSendChannelId]--;
226
        if (offCounter[currentSendChannelId] == 0) {
296
        if (offCounter[currentSendChannelId] == 0) {
Line 252... Line 322...
252
            if (rxMsg->Length == 3)
322
            if (rxMsg->Length == 3)
253
            {
323
            {
254
//printf("3\n");
324
//printf("3\n");
255
                if (rxMsg->Data[0] < NUMBEROFCHANNELS) {
325
                if (rxMsg->Data[0] < NUMBEROFCHANNELS) {
256
                    pwmValueCAN[rxMsg->Data[0]] = ((uint16_t)((rxMsg->Data[1]<<8) + rxMsg->Data[2]));
326
                    pwmValueCAN[rxMsg->Data[0]] = ((uint16_t)((rxMsg->Data[1]<<8) + rxMsg->Data[2]));
257
if (act_softPWM_INVERT_PWM == 1) {
327
                    if (pwmValueCAN[rxMsg->Data[0]] >= 10000) {
258
                    pwmValue[rxMsg->Data[0]] = maxTimer - ((uint16_t)((((uint32_t)pwmValueCAN[rxMsg->Data[0]])*(maxTimer))/10000));
328
                        pwmValue[rxMsg->Data[0]] = maxTimer+1;
259
}else {
329
                    } else {
260
pwmValue[rxMsg->Data[0]] = ((uint16_t)((((uint32_t)pwmValueCAN[rxMsg->Data[0]])*(maxTimer))/10000));
330
                        pwmValue[rxMsg->Data[0]] = ((uint16_t)((((uint32_t)pwmValueCAN[rxMsg->Data[0]])*(maxTimer))/10000));
261
}
331
                    }
262
                    rxMsg->Data[1] = (uint8_t)(0x00ff & (pwmValueCAN[rxMsg->Data[0]]>>8));
332
                    rxMsg->Data[1] = (uint8_t)(0x00ff & (pwmValueCAN[rxMsg->Data[0]]>>8));
263
                    rxMsg->Data[2] = (uint8_t)(0x00ff & pwmValueCAN[rxMsg->Data[0]]);
333
                    rxMsg->Data[2] = (uint8_t)(0x00ff & pwmValueCAN[rxMsg->Data[0]]);