Rev 339 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 339 | Rev 347 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 2 | * |
2 | * |
| 3 | * Functions for controlling blinds |
3 | * Functions for controlling blinds |
| 4 | * |
4 | * |
| 5 | ********************************************************************* |
5 | ********************************************************************* |
| 6 | * FileName: $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canTemp/Source/blinds.c $ |
6 | * FileName: $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canTemp/Source/blinds.c $ |
| 7 | * Last changed: $LastChangedDate: 2007- |
7 | * Last changed: $LastChangedDate: 2007-03-01 14:38:06 +0100 (Thu, 01 Mar 2007) $ |
| 8 | * By: $LastChangedBy: johboh $ |
8 | * By: $LastChangedBy: johboh $ |
| 9 | * Revision: $Revision: |
9 | * Revision: $Revision: 347 $ |
| 10 | ********************************************************************/ |
10 | ********************************************************************/ |
| 11 | #include <blinds.h> |
11 | #include <blinds.h> |
| 12 | 12 | ||
| 13 | #ifdef USE_BLINDS |
13 | #ifdef USE_BLINDS |
| 14 | 14 | ||
| 15 | static |
15 | static WORD timerVal = 50536; |
| 16 | static |
16 | static WORD turnOffIO = 0; |
| 17 | static signed char currentPrecent = 0; |
17 | static signed char currentPrecent = 0; |
| - | 18 | static BYTE dutyOffCounter = 0; |
|
| 18 | 19 | ||
| 19 | /* |
20 | /* |
| 20 | * Function: blindsInit |
21 | * Function: blindsInit |
| 21 | * |
22 | * |
| 22 | * Input: none. |
23 | * Input: none. |
| Line 68... | Line 69... | ||
| 68 | // 0 1.5 ms = 50536 (15000) |
69 | // 0 1.5 ms = 50536 (15000) |
| 69 | // 90 2.5 ms = 40536 (25000) |
70 | // 90 2.5 ms = 40536 (25000) |
| 70 | 71 | ||
| 71 | BLINDS0P_IO=1; |
72 | BLINDS0P_IO=1; |
| 72 | turnOffIO = IO_TIMEOUT; |
73 | turnOffIO = IO_TIMEOUT; |
| 73 | /* |
- | |
| 74 | if (angle<ANGLE_MIN) {timerVal=ANGLE_MIN_TIMER; currentAngle=ANGLE_MIN; } |
- | |
| 75 | else if (angle>ANGLE_MAX) {timerVal=ANGLE_MAX_TIMER; currentAngle=ANGLE_MAX; } |
- | |
| 76 | else |
- | |
| 77 | { |
- | |
| 78 | timerVal=60536-(unsigned int)((90+(signed int)angle)*111.111); |
- | |
| 79 | currentAngle=angle; |
- | |
| 80 | } |
- | |
| 81 | */ |
- | |
| 82 | - | ||
| 83 | /* |
- | |
| 84 | angle=precent* |
- | |
| 85 | - | ||
| 86 | -50=k*100+m |
- | |
| 87 | 60=k*0+m |
- | |
| 88 | angle=-1.1x+60 |
- | |
| 89 | */ |
- | |
| 90 | 74 | ||
| 91 | currentPrecent=precent; |
75 | currentPrecent = precent; |
| 92 | if (precent>100) { currentPrecent=100; } |
76 | if (precent>100) { currentPrecent = 100; } |
| 93 | if (precent<0) { currentPrecent=0; } |
77 | if (precent<0) { currentPrecent = 0; } |
| 94 | - | ||
| - | 78 | dutyOffCounter = 0; |
|
| 95 | 79 | ||
| 96 | timerVal=60536-(unsigned int)((90+(-1.05*(signed int)currentPrecent+60))*111.111); |
80 | timerVal=60536-(unsigned int)((90+(-1.05*(signed int)currentPrecent+60))*111.111); |
| 97 | } |
81 | } |
| 98 | 82 | ||
| 99 | 83 | ||
| 100 | /* |
84 | /* |
| 101 | * Function: blindsISR |
85 | * Function: blindsISR |
| 102 | * |
86 | * |
| 103 | * Input: none. |
87 | * Input: none. |
| Line 106... | Line 90... | ||
| 106 | * Affects: none. |
90 | * Affects: none. |
| 107 | * Depends: none. |
91 | * Depends: none. |
| 108 | */ |
92 | */ |
| 109 | void blindsISR(void) |
93 | void blindsISR(void) |
| 110 | { |
94 | { |
| 111 | if (PIR1bits.TMR1IF == 1 && PIE1bits.TMR1IE == 1) |
95 | if (PIR1bits.TMR1IF == 1 && PIE1bits.TMR1IE == 1) |
| - | 96 | { |
|
| - | 97 | WORD timerValBuffer = timerVal; |
|
| - | 98 | ||
| - | 99 | dutyOffCounter++; |
|
| - | 100 | ||
| - | 101 | if (BLINDS0_IO==0 && dutyOffCounter>4) |
|
| - | 102 | { |
|
| - | 103 | BLINDS0_IO=1; |
|
| - | 104 | dutyOffCounter=0; |
|
| - | 105 | } |
|
| - | 106 | else if (BLINDS0_IO==0 && dutyOffCounter<=4) |
|
| - | 107 | { |
|
| - | 108 | timerValBuffer = DUTY_OFF_DELAY; |
|
| - | 109 | } |
|
| - | 110 | else if (BLINDS0_IO==1) |
|
| 112 | { |
111 | { |
| 113 |
|
112 | BLINDS0_IO=0; |
| 114 |
|
113 | } |
| 115 | 114 | ||
| - | 115 | TMR1H=((timerValBuffer&0xFF00)>>8); |
|
| 116 |
|
116 | TMR1L=(timerValBuffer&0xFF); |
| 117 | 117 | ||
| 118 | if (turnOffIO--<1) |
118 | if (turnOffIO--<1) |
| 119 | { |
119 | { |
| 120 | BLINDS0P_IO=0; |
120 | BLINDS0P_IO=0; |
| 121 | } |
121 | } |