Rev 347 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 347 | Rev 353 | ||
|---|---|---|---|
| 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-03- |
7 | * Last changed: $LastChangedDate: 2007-03-03 19:07:14 +0100 (Sat, 03 Mar 2007) $ |
| 8 | * By: $LastChangedBy: johboh $ |
8 | * By: $LastChangedBy: johboh $ |
| 9 | * Revision: $Revision: |
9 | * Revision: $Revision: 353 $ |
| 10 | ********************************************************************/ |
10 | ********************************************************************/ |
| 11 | #include <blinds.h> |
11 | #include <blinds.h> |
| 12 | 12 | ||
| 13 | #ifdef USE_BLINDS |
13 | #ifdef USE_BLINDS |
| 14 | 14 | ||
| 15 | static WORD timerVal = 50536; |
15 | static WORD timerVal = 50536; |
| 16 | static WORD turnOffIO = 0; |
16 | static WORD turnOffIO = 0; |
| 17 | static |
17 | static BYTE currentPrecent = 0; |
| 18 | static BYTE dutyOffCounter = 0; |
18 | static BYTE dutyOffCounter = 0; |
| 19 | 19 | ||
| 20 | /* |
20 | /* |
| 21 | * Function: blindsInit |
21 | * Function: blindsInit |
| 22 | * |
22 | * |
| Line 29... | Line 29... | ||
| 29 | void blindsInit() |
29 | void blindsInit() |
| 30 | { |
30 | { |
| 31 | // setup timer one on 0.5ms. |
31 | // setup timer one on 0.5ms. |
| 32 | // 16 bit write, system clock, prescale 2 bit, oscillator off, |
32 | // 16 bit write, system clock, prescale 2 bit, oscillator off, |
| 33 | T1CON = 0b11000001; |
33 | T1CON = 0b11000001; |
| 34 | TMR1H=((timerVal&0xFF00)>>8); |
34 | TMR1H=(BYTE)((timerVal&0xFF00)>>8); |
| 35 | TMR1L=(timerVal&0xFF); |
35 | TMR1L=(timerVal&0xFF); |
| 36 | PIR1bits.TMR1IF = 0; |
36 | PIR1bits.TMR1IF = 0; |
| 37 | PIE1bits.TMR1IE = 1; |
37 | PIE1bits.TMR1IE = 1; |
| 38 | IPR1bits.TMR1IP = |
38 | IPR1bits.TMR1IP = 1; // high prior |
| 39 | } |
39 | } |
| 40 | 40 | ||
| 41 | /* |
41 | /* |
| 42 | * Function: blindsGetAngle |
42 | * Function: blindsGetAngle |
| 43 | * |
43 | * |
| Line 62... | Line 62... | ||
| 62 | * Affects: none. |
62 | * Affects: none. |
| 63 | * Depends: none. |
63 | * Depends: none. |
| 64 | */ |
64 | */ |
| 65 | void blindsTurn(BYTE precent) |
65 | void blindsTurn(BYTE precent) |
| 66 | { |
66 | { |
| - | 67 | ||
| 67 | // 65536-TIME/0,0000001 |
68 | // 65536-TIME/0,0000001 |
| 68 | // -90 0.5 ms = 60536 (5000) |
69 | // -90 0.5 ms = 60536 (5000) |
| 69 | // 0 1.5 ms = 50536 (15000) |
70 | // 0 1.5 ms = 50536 (15000) |
| 70 | // 90 2.5 ms = 40536 (25000) |
71 | // 90 2.5 ms = 40536 (25000) |
| 71 | 72 | ||
| Line 73... | Line 74... | ||
| 73 | turnOffIO = IO_TIMEOUT; |
74 | turnOffIO = IO_TIMEOUT; |
| 74 | 75 | ||
| 75 | currentPrecent = precent; |
76 | currentPrecent = precent; |
| 76 | if (precent>100) { currentPrecent = 100; } |
77 | if (precent>100) { currentPrecent = 100; } |
| 77 | if (precent<0) { currentPrecent = 0; } |
78 | if (precent<0) { currentPrecent = 0; } |
| 78 | dutyOffCounter = 0; |
79 | dutyOffCounter = 0; |
| 79 | 80 | ||
| 80 | timerVal=60536-(unsigned int)((90+(-1.05*( |
81 | timerVal=60536-(unsigned int)((90+(-1.05*(unsigned int)currentPrecent+60))*111.111); |
| - | 82 | ||
| 81 | } |
83 | } |
| 82 | 84 | ||
| 83 | 85 | ||
| 84 | /* |
86 | /* |
| 85 | * Function: blindsISR |
87 | * Function: blindsISR |
| 86 | * |
88 | * |
| Line 89... | Line 91... | ||
| 89 | * Pre-conditions: none |
91 | * Pre-conditions: none |
| 90 | * Affects: none. |
92 | * Affects: none. |
| 91 | * Depends: none. |
93 | * Depends: none. |
| 92 | */ |
94 | */ |
| 93 | void blindsISR(void) |
95 | void blindsISR(void) |
| 94 | { |
96 | { |
| 95 | if (PIR1bits.TMR1IF == 1 && PIE1bits.TMR1IE == 1) |
97 | if (PIR1bits.TMR1IF == 1 && PIE1bits.TMR1IE == 1) |
| 96 | { |
98 | { |
| - | 99 | ||
| 97 | WORD timerValBuffer = timerVal; |
100 | WORD timerValBuffer = timerVal; |
| 98 | 101 | ||
| 99 | dutyOffCounter++; |
102 | dutyOffCounter++; |
| 100 | 103 | ||
| 101 | if (BLINDS0_IO==0 && dutyOffCounter>4) |
104 | if (BLINDS0_IO==0 && dutyOffCounter>4) |
| 102 | { |
105 | { |
| 103 | BLINDS0_IO=1; |
106 | BLINDS0_IO=1; |
| 104 | dutyOffCounter=0; |
107 | dutyOffCounter=0; |
| 105 | } |
108 | } |
| 106 | else if (BLINDS0_IO==0 && dutyOffCounter<=4) |
109 | else if (BLINDS0_IO==0 && dutyOffCounter<=4) |
| 107 | { |
110 | { |
| 108 | timerValBuffer = DUTY_OFF_DELAY; |
111 | timerValBuffer = DUTY_OFF_DELAY; |
| 109 | } |
112 | } |
| 110 | else if (BLINDS0_IO==1) |
113 | else if (BLINDS0_IO==1) |
| 111 | { |
114 | { |
| 112 | BLINDS0_IO=0; |
115 | BLINDS0_IO=0; |
| 113 | } |
116 | } |
| 114 | 117 | ||
| 115 | TMR1H=((timerValBuffer&0xFF00)>>8); |
118 | TMR1H=(BYTE)((timerValBuffer&0xFF00)>>8); |
| 116 | TMR1L=(timerValBuffer&0xFF); |
119 | TMR1L=(timerValBuffer&0xFF); |
| 117 | 120 | ||
| - | 121 | ||
| 118 | if (turnOffIO--<1) |
122 | if (turnOffIO--<1) |
| 119 | { |
123 | { |
| 120 | BLINDS0P_IO=0; |
124 | BLINDS0P_IO=0; |
| 121 | } |
125 | } |
| - | 126 | ||
| 122 | 127 | ||
| 123 | PIR1bits.TMR1IF = 0; |
128 | PIR1bits.TMR1IF = 0; |
| 124 | } |
129 | } |
| 125 | } |
130 | } |
| 126 | 131 | ||