Subversion Repositories HomeAutomation

Rev

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

Rev 2064 Rev 2100
Line 12... Line 12...
12
 
12
 
13
uint16_t demoEndValue[4] = {0,0,0,0};
13
uint16_t demoEndValue[4] = {0,0,0,0};
14
uint16_t demoHighValue[4] = {0,0,0,0};
14
uint16_t demoHighValue[4] = {0,0,0,0};
15
uint8_t demoState[4] = {ACT_HWPWM_DEMO_STATE_NOT_RUNNING, ACT_HWPWM_DEMO_STATE_NOT_RUNNING, ACT_HWPWM_DEMO_STATE_NOT_RUNNING, ACT_HWPWM_DEMO_STATE_NOT_RUNNING};
15
uint8_t demoState[4] = {ACT_HWPWM_DEMO_STATE_NOT_RUNNING, ACT_HWPWM_DEMO_STATE_NOT_RUNNING, ACT_HWPWM_DEMO_STATE_NOT_RUNNING, ACT_HWPWM_DEMO_STATE_NOT_RUNNING};
16
 
16
 
17
static uint16_t lookuptable[256] PROGMEM =
17
static uint16_t lookuptable[257] PROGMEM =
18
{
18
{
-
 
19
  0 ,  4    ,  8    ,  12   ,  17   ,  21   ,  25   ,  30   ,  34   ,  39   ,  //0
-
 
20
43  ,  48   ,  52   ,  57   ,  62   ,  67   ,  72   ,  77   ,  82   ,  87   ,  //10
-
 
21
93  ,  98   ,  104  ,  109  , 115   ,  120  ,  126  ,  132  ,  138  ,  144  ,  //20
-
 
22
150 ,  156  ,  162  ,  169  ,  175  ,  182  ,  188  ,  195  ,  202  ,  209  ,  //30
-
 
23
216 ,  223  ,  230  ,  237  ,  245  ,  252  ,  260  ,  267  ,  275  ,  283  ,  //40
-
 
24
291 ,  299  ,  308  ,  316  ,  325  ,  333  ,  342  ,  351  ,  360  ,  369  ,  //50
-
 
25
378 ,  388  ,  397  ,  407  ,  417  ,  427  ,  437  ,  447  ,  457  ,  468  ,  //60
-
 
26
478 ,  489  ,  500  ,  511  ,  523  ,  534  ,  546  ,  557  ,  569  ,  581  ,  //70
-
 
27
594 ,  606  ,  619  ,  632  ,  645  ,  658  ,  671  ,  685  ,  698  ,  712  ,  //80
-
 
28
726 ,  741  ,  755  ,  770  ,  785  ,  800  ,  815  ,  831  ,  847  ,  863  ,  //90
-
 
29
879 ,  896  ,  912  ,  929  ,  946  ,  964  ,  982  ,  999  ,  1018 ,  1036 ,  //100
-
 
30
1055    ,  1074 ,  1093 ,  1113 ,  1132 ,  1152 ,  1173 ,  1193 ,  1214 ,  1236 ,  //110
-
 
31
1257    ,  1279 ,  1301 ,  1324 ,  1346 ,  1369 ,  1393 ,  1417 ,  1441 ,  1465 ,  //120
-
 
32
1490    ,  1515 ,  1540 ,  1566 ,  1593 ,  1619 ,  1646 ,  1673 ,  1701 ,  1729 ,  //130
-
 
33
1758    ,  1787 ,  1816 ,  1846 ,  1876 ,  1907 ,  1938 ,  1969 ,  2001 ,  2033 ,  //140
-
 
34
2066    ,  2099 ,  2133 ,  2167 ,  2202 ,  2237 ,  2273 ,  2309 ,  2346 ,  2383 ,  //150
19
  0,4, 8,12,  17,  21   ,  25   ,  30   ,  34   ,  39   ,  43   ,  48   ,  52   ,  57   ,  62   ,  67   ,  72   ,  77   ,  82   ,  87   ,  93   ,  98   ,  104  ,  109  , 115   ,  120  ,  126  ,  132  ,  138  ,  144  ,  150  ,  156  ,  162  ,  169  ,  175  ,  182  ,  188  ,  195  ,  202  ,  209  ,  216  ,  223  ,  230  ,  237  ,  245  , 252   ,  260  ,  267  ,  275  ,  283  ,  291  ,  299  ,  308  ,  316  ,  325  ,  333  ,  342  ,  351  ,  360  ,  369  ,  378  ,  388  ,  397  ,  407  ,  417  ,  427  , 437   ,  447  ,  457  ,  468  ,  478  ,  489  ,  500  ,  511  ,  523  ,  534  ,  546  ,  557  ,  569  ,  581  ,  594  ,  606  ,  619  ,  632  ,  645  ,  658  ,  671  , 685   ,  698  ,  712  ,  726  ,  741  ,  755  ,  770  ,  785  ,  800  ,  815  ,  831  ,  847  ,  863  ,  879  ,  896  ,  912  ,  929  ,  946  ,  964  ,  982  ,  999  , 1018  ,  1036 ,  1055 ,  1074 ,  1093 ,  1113 ,  1132 ,  1152 ,  1173 ,  1193 ,  1214 ,  1236 ,  1257 ,  1279 ,  1301 ,  1324 ,  1346 ,  1369 ,  1393 ,  1417 ,  1441 , 1465  ,  1490 ,  1515 ,  1540 ,  1566 ,  1593 ,  1619 ,  1646 ,  1673 ,  1701 ,  1729 ,  1758 ,  1787 ,  1816 ,  1846 ,  1876 ,  1907 ,  1938 ,  1969 ,  2001 ,  2033 , 2066  ,  2099 ,  2133 ,  2167 ,  2202 ,  2237 ,  2273 ,  2309 ,  2346 ,  2383 ,  2421 ,  2459 ,  2498 ,  2538 ,  2577 ,  2618 ,  2659 ,  2701 ,  2743 ,  2786 ,  2829 , 2873  ,  2918 ,  2963 ,  3009 ,  3056 ,  3103 ,  3151 ,  3200 ,  3249 ,  3299 ,  3350 ,  3402 ,  3454 ,  3507 ,  3560 ,  3615 ,  3670 ,  3726 ,  3783 ,  3840 ,  3899 , 3958  ,  4018 ,  4079 ,  4141 ,  4203 ,  4267 ,  4331 ,  4397 ,  4463 ,  4530 ,  4598 ,  4667 ,  4737 ,  4808 ,  4881 ,  4954 ,  5028 ,  5103 ,  5179 ,  5257 ,  5335 , 5415  ,  5495 ,  5577 ,  5660 ,  5744 ,  5830 ,  5916 ,  6004 ,  6093 ,  6183 ,  6275 ,  6368 ,  6462 ,  6557 ,  6654 ,  6752 ,  6852 ,  6953 ,  7055 ,  7159 ,  7265 , 7371  ,  7480 ,  7590 ,  7701 ,  7814 ,  7929 ,  8045 ,  8163 ,  8283 ,  8404 , 8527  ,  8652 ,  8778 ,  8906 ,  9036 ,  9168 ,  9302 ,  9438 ,  9575 ,  9715 , 9856  ,
35
2421    ,  2459 ,  2498 ,  2538 ,  2577 ,  2618 ,  2659 ,  2701 ,  2743 ,  2786 ,  //160
-
 
36
2829    ,  2873 ,  2918 ,  2963 ,  3009 ,  3056 ,  3103 ,  3151 ,  3200 ,  3249 ,  //170
-
 
37
3299    ,  3350 ,  3402 ,  3454 ,  3507 ,  3560 ,  3615 ,  3670 ,  3726 ,  3783 ,  //180
-
 
38
3840    ,  3899 ,  3958 ,  4018 ,  4079 ,  4141 ,  4203 ,  4267 ,  4331 ,  4397 ,  //190
-
 
39
4463    ,  4530 ,  4598 ,  4667 ,  4737 ,  4808 ,  4881 ,  4954 ,  5028 ,  5103 ,  //200
-
 
40
5179    ,  5257 ,  5335 ,  5415 ,  5495 ,  5577 ,  5660 ,  5744 ,  5830 ,  5916 ,  //210
-
 
41
6004    ,  6093 ,  6183 ,  6275 ,  6368 ,  6462 ,  6557 ,  6654 ,  6752 ,  6852 ,  //220
-
 
42
6953    ,  7055 ,  7159 ,  7265 ,  7371 ,  7480 ,  7590 ,  7701 ,  7814 ,  7929 ,  //230
-
 
43
8045    ,  8163 ,  8283 ,  8404 ,  8527 ,  8652 ,  8778 ,  8906 ,  9036 ,  9168 ,  //240
20
  10000 ,
44
9302    ,  9438 ,  9575 ,  9715 ,  9856 ,  10000,  10000               //250
21
};
45
};
22
 
46
 
23
 
47
 
24
#if act_hwPWM_USEEEPROM==1
48
#if act_hwPWM_USEEEPROM==1
25
#include "act_hwPWM_eeprom.h"
49
#include "act_hwPWM_eeprom.h"
Line 276... Line 300...
276
            txMsg.Length = 3;
300
            txMsg.Length = 3;
277
            txMsg.Data[0] = index;
301
            txMsg.Data[0] = index;
278
            txMsg.Data[1] = (0xff&(pwmValue[index]>>8));
302
            txMsg.Data[1] = (0xff&(pwmValue[index]>>8));
279
            txMsg.Data[2] = (0xff&(pwmValue[index]));
303
            txMsg.Data[2] = (0xff&(pwmValue[index]));
280
            StdCan_Put(&txMsg);
304
            StdCan_Put(&txMsg);
-
 
305
           
-
 
306
            //printf("CH1 PWM: %u, LED: %u, ledindex: %u, ocr: %u\n",pwmValue[1],(uint16_t)(pgm_read_word(&lookuptable[(pwmValue[1]/39)])), (pwmValue[1]/39),OCR_2);
281
        }
307
        }
282
    }
308
    }
283
   
309
   
284
    if (Timer_Expired(act_hwPWM_STORE_VALUE_TIMEOUT))
310
    if (Timer_Expired(act_hwPWM_STORE_VALUE_TIMEOUT))
285
    {
311
    {
Line 301... Line 327...
301
        }
327
        }
302
    }
328
    }
303
                   
329
                   
304
#if act_hwPWM_CH1_COM>0
330
#if act_hwPWM_CH1_COM>0
305
# if act_hwPWM_CH1_LED>0
331
# if act_hwPWM_CH1_LED>0
306
#  define CH1_calculation ((lookuptable[pwmValue[0]/39-1]*act_hwPWM_CH1_FACT)>>8)
332
#  define CH1_calculation ((pgm_read_word(&lookuptable[(pwmValue[0]/39)])*act_hwPWM_CH1_FACT)>>8)
307
# else
333
# else
308
#  define CH1_calculation ((pwmValue[0]*act_hwPWM_CH1_FACT)>>8)
334
#  define CH1_calculation ((pwmValue[0]*act_hwPWM_CH1_FACT)>>8)
309
# endif
335
# endif
310
    if (OCR_1 != (uint16_t)CH1_calculation) {
336
    if (OCR_1 != (uint16_t)CH1_calculation) {
311
        cli(); 
337
        cli(); 
Line 318... Line 344...
318
        {
344
        {
319
            TCCR1A|=(act_hwPWM_CH1_COM<<COM1B0);
345
            TCCR1A|=(act_hwPWM_CH1_COM<<COM1B0);
320
        }
346
        }
321
        sei();
347
        sei();
322
        Timer_SetTimeout(act_hwPWM_STORE_VALUE_TIMEOUT, act_hwPWM_STORE_VALUE_TIMEOUT_TIME*1000, TimerTypeOneShot, 0);
348
        Timer_SetTimeout(act_hwPWM_STORE_VALUE_TIMEOUT, act_hwPWM_STORE_VALUE_TIMEOUT_TIME*1000, TimerTypeOneShot, 0);
-
 
349
        //printf("CH0 PWM: %u, LED: %u, ORG: %u\n",pwmValue[0],(uint16_t)((lookuptable[(pwmValue[0]/39)-1]*act_hwPWM_CH1_FACT)>>8), (uint16_t)((pwmValue[0]*act_hwPWM_CH1_FACT)>>8));
323
    }
350
    }
324
#endif
351
#endif
325
#if act_hwPWM_CH2_COM>0
352
#if act_hwPWM_CH2_COM>0
326
# if act_hwPWM_CH2_LED>0
353
# if act_hwPWM_CH2_LED>0
327
#  define CH2_calculation ((uint32_t)((lookuptable[pwmValue[1]/39-1]*act_hwPWM_CH2_FACT)>>8))
354
#  define CH2_calculation ((pgm_read_word(&lookuptable[(pwmValue[1]/39)])*act_hwPWM_CH2_FACT)>>8)
328
# else
355
# else
329
#  define CH2_calculation ((uint32_t)((pwmValue[1]*act_hwPWM_CH2_FACT)>>8))
356
#  define CH2_calculation ((pwmValue[1]*act_hwPWM_CH2_FACT)>>8)
330
# endif
357
# endif
331
    if (OCR_2 != (uint16_t)CH2_calculation) {
358
    if (OCR_2 != (uint16_t)CH2_calculation) {
332
        cli(); 
359
        cli(); 
333
        OCR_2=(uint16_t)CH2_calculation;
360
        OCR_2=(uint16_t)CH2_calculation;
334
        if (OCR_2==0)
361
        if (OCR_2==0)
Line 339... Line 366...
339
        {
366
        {
340
            TCCR1A|=(act_hwPWM_CH2_COM<<COM1A0);
367
            TCCR1A|=(act_hwPWM_CH2_COM<<COM1A0);
341
        }
368
        }
342
        sei();
369
        sei();
343
        Timer_SetTimeout(act_hwPWM_STORE_VALUE_TIMEOUT, act_hwPWM_STORE_VALUE_TIMEOUT_TIME*1000, TimerTypeOneShot, 0);
370
        Timer_SetTimeout(act_hwPWM_STORE_VALUE_TIMEOUT, act_hwPWM_STORE_VALUE_TIMEOUT_TIME*1000, TimerTypeOneShot, 0);
-
 
371
        //printf("CH1 PWM: %u, LED: %u, ORG: %u, ocr: %u\n",pwmValue[1],(uint16_t)((lookuptable[(pwmValue[1]/39)-1]*act_hwPWM_CH2_FACT)>>8), (uint16_t)((pwmValue[1]*act_hwPWM_CH2_FACT)>>8),OCR_2);
344
    }
372
    }
345
#endif
373
#endif
346
#if act_hwPWM_CH3_COM>0
374
#if act_hwPWM_CH3_COM>0
347
# if act_hwPWM_CH3_LED>0
375
# if act_hwPWM_CH3_LED>0
348
#  define CH3_calculation ((lookuptable[pwmValue[2]/39-1]*act_hwPWM_CH3_FACT)>>8)
376
#  define CH3_calculation ((pgm_read_word(&lookuptable[(pwmValue[2]/39)])*act_hwPWM_CH3_FACT)>>8)
349
# else
377
# else
350
#  define CH3_calculation ((pwmValue[2]*act_hwPWM_CH3_FACT)>>8)
378
#  define CH3_calculation ((pwmValue[2]*act_hwPWM_CH3_FACT)>>8)
351
# endif
379
# endif
352
    if (OCR_3 != (uint16_t)CH3_calculation) {
380
    if (OCR_3 != (uint16_t)CH3_calculation) {
353
        cli(); 
381
        cli(); 
Line 360... Line 388...
360
        {
388
        {
361
            TCCR0A|=(act_hwPWM_CH3_COM<<COM0A0);
389
            TCCR0A|=(act_hwPWM_CH3_COM<<COM0A0);
362
        }
390
        }
363
        sei();
391
        sei();
364
        Timer_SetTimeout(act_hwPWM_STORE_VALUE_TIMEOUT, act_hwPWM_STORE_VALUE_TIMEOUT_TIME*1000, TimerTypeOneShot, 0);
392
        Timer_SetTimeout(act_hwPWM_STORE_VALUE_TIMEOUT, act_hwPWM_STORE_VALUE_TIMEOUT_TIME*1000, TimerTypeOneShot, 0);
-
 
393
        //printf("CH2 PWM: %u, LED: %u, ORG: %u\n",pwmValue[2],(uint16_t)((lookuptable[(pwmValue[2]/39)-1]*act_hwPWM_CH3_FACT)>>8), (uint16_t)((pwmValue[2]*act_hwPWM_CH3_FACT)>>8));
365
    }
394
    }
366
#endif
395
#endif
367
#if act_hwPWM_CH4_COM>0
396
#if act_hwPWM_CH4_COM>0
368
# if act_hwPWM_CH4_LED>0
397
# if act_hwPWM_CH4_LED>0
369
#  define CH4_calculation ((lookuptable[pwmValue[3]/39-1]*act_hwPWM_CH4_FACT)>>8)
398
#  define CH4_calculation ((pgm_read_word(&lookuptable[(pwmValue[3]/39)])*act_hwPWM_CH4_FACT)>>8)
370
# else
399
# else
371
#  define CH4_calculation ((pwmValue[3]*act_hwPWM_CH4_FACT)>>8)
400
#  define CH4_calculation ((pwmValue[3]*act_hwPWM_CH4_FACT)>>8)
372
# endif
401
# endif
373
    if (OCR_4 != (uint16_t)CH4_calculation) {
402
    if (OCR_4 != (uint16_t)CH4_calculation) {
374
        cli(); 
403
        cli(); 
Line 381... Line 410...
381
        {
410
        {
382
            TCCR0A|=(act_hwPWM_CH4_COM<<COM0B0);
411
            TCCR0A|=(act_hwPWM_CH4_COM<<COM0B0);
383
        }
412
        }
384
        sei();
413
        sei();
385
        Timer_SetTimeout(act_hwPWM_STORE_VALUE_TIMEOUT, act_hwPWM_STORE_VALUE_TIMEOUT_TIME*1000, TimerTypeOneShot, 0);
414
        Timer_SetTimeout(act_hwPWM_STORE_VALUE_TIMEOUT, act_hwPWM_STORE_VALUE_TIMEOUT_TIME*1000, TimerTypeOneShot, 0);
-
 
415
        //printf("CH3 PWM: %u, LED: %u, ORG: %u\n",pwmValue[3],(uint16_t)((lookuptable[(pwmValue[3]/39)-1]*act_hwPWM_CH4_FACT)>>8), (uint16_t)((pwmValue[3]*act_hwPWM_CH4_FACT)>>8));
386
    }
416
    }
387
#endif
417
#endif
388
}
418
}
389
 
419
 
390
void act_hwPWM_HandleMessage(StdCan_Msg_t *rxMsg)
420
void act_hwPWM_HandleMessage(StdCan_Msg_t *rxMsg)