Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
275 johboh 1
/*********************************************************************
2
 *
3
 *   Functions for controlling blinds
4
 *
5
 *********************************************************************
6
 * FileName:        $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canTemp/Source/blinds.c $
7
 * Last changed:    $LastChangedDate: 2007-02-25 20:51:08 +0100 (Sun, 25 Feb 2007) $
8
 * By:              $LastChangedBy: johboh $
9
 * Revision:        $Revision: 339 $
10
 ********************************************************************/
11
#include <blinds.h>
12
 
13
#ifdef USE_BLINDS
14
 
277 johboh 15
static unsigned int timerVal = 50536;
339 johboh 16
static unsigned int turnOffIO = 0;
17
static signed char currentPrecent = 0;
275 johboh 18
 
19
/*
20
*   Function: blindsInit
21
*
22
*   Input:  none.
23
*   Output: none.
24
*   Pre-conditions: none
25
*   Affects: none.
26
*   Depends: none.
27
*/
28
void blindsInit()
29
{
30
    // setup timer one on 0.5ms.
31
    // 16 bit write, system clock, prescale 2 bit, oscillator off, 
32
    T1CON = 0b11000001;
277 johboh 33
    TMR1H=((timerVal&0xFF00)>>8);
34
    TMR1L=(timerVal&0xFF);
275 johboh 35
    PIR1bits.TMR1IF = 0;
36
    PIE1bits.TMR1IE = 1;
339 johboh 37
    IPR1bits.TMR1IP = 0; // Low prior
275 johboh 38
}
39
 
40
/*
339 johboh 41
*   Function: blindsGetAngle
42
*
43
*   Input:  none.
44
*   Output: angle.
45
*   Pre-conditions: none
46
*   Affects: none.
47
*   Depends: none.
48
*/
49
BYTE blindsGetPrecent()
50
{
51
    return currentPrecent;
52
}
53
 
54
 
55
/*
276 johboh 56
*   Function: blindsTurn
275 johboh 57
*
277 johboh 58
*   Input:  Angle to turn to.
275 johboh 59
*   Output: none.
60
*   Pre-conditions: none
61
*   Affects: none.
62
*   Depends: none.
63
*/
339 johboh 64
void blindsTurn(BYTE precent)
275 johboh 65
{
277 johboh 66
    // 65536-TIME/0,0000001
67
    // -90 0.5 ms = 60536 (5000)
68
    // 0   1.5 ms = 50536 (15000)
69
    // 90  2.5 ms = 40536 (25000)
275 johboh 70
 
339 johboh 71
    BLINDS0P_IO=1;
72
    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
 
91
    currentPrecent=precent;
92
    if (precent>100) { currentPrecent=100; }
93
    if (precent<0) { currentPrecent=0; }
94
 
95
 
96
    timerVal=60536-(unsigned int)((90+(-1.05*(signed int)currentPrecent+60))*111.111);
275 johboh 97
}
98
 
276 johboh 99
 
275 johboh 100
/*
276 johboh 101
*   Function: blindsISR
275 johboh 102
*
276 johboh 103
*   Input:  none.
275 johboh 104
*   Output: none.
105
*   Pre-conditions: none
106
*   Affects: none.
107
*   Depends: none.
108
*/
109
void blindsISR(void)
110
{
111
    if (PIR1bits.TMR1IF == 1 && PIE1bits.TMR1IE == 1)
112
    {
277 johboh 113
        TMR1H=((timerVal&0xFF00)>>8);
114
        TMR1L=(timerVal&0xFF);
275 johboh 115
 
277 johboh 116
        BLINDS0_IO=~BLINDS0_IO;
275 johboh 117
 
339 johboh 118
        if (turnOffIO--<1)
119
        {
120
            BLINDS0P_IO=0;
121
        }
122
 
275 johboh 123
        PIR1bits.TMR1IF = 0;
124
    }
125
}
126
 
127
#endif