Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
508 kaklik 1
/* 
2
 * Copyright (C) 2004 Darren Hutchinson (dbh@gbdt.com.au)
3
 * 
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU Library General Public License as published by
6
 * the Free Software Foundation; either version 2 of the License, or (at your
7
 * option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful, but
10
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
12
 * License for more details.
13
 * 
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this software; see the file COPYING.  If not, write to
16
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
17
 * MA 02111-1307, USA. 
18
 *
19
 * $Id: pguide.c,v 1.1.1.1 2004/02/22 08:12:42 dbh Exp $
20
 */
21
 
22
/* This file contains the code that takes inputs from a parallel output
23
 * guider (such as the SBIG ST-4) and uses them to make guiding
24
 * adjustments.
25
 */
26
 
27
#include <avr/io.h>
28
#include <avr/interrupt.h>
29
#include <inttypes.h>
30
 
31
#include "eq6.h"
32
#include "combine.h"
33
#include "pguide.h"
34
 
35
#define GUIDE_BITS      (_BV(G_UP) | _BV(G_DN) | _BV(G_RT) | _BV(G_LT))
36
 
37
/* This module polls the input bits from the guider, applies some
38
 * crude debouncing, and then applies the requested speed adjustment.
39
 *
40
 * This code assumes that the inputs are active low (i.e. they are connected
41
 * to a relay or optocoupler connecting the "active" input to ground).
42
 *
43
 * The polling rate is generated by a 8-bit timer with /256
44
 */
45
 
46
/* pguideInit() initializes the timer used to poll the parallel guiding
47
 * input bits and sets those bit as inputs.
48
 *
49
 * Passed:
50
 *      Nothing
51
 *
52
 * Returns:
53
 *      Nothing
54
 *
55
 */
56
void
57
pguideInit(void)
58
{
59
    /* Set guide bits as inputs with pullups */
60
    GUIDE_DDR &= ~GUIDE_BITS;
61
    GUIDE_PORT |= GUIDE_BITS;
62
 
63
    /* Setup timer 2 to generate interrupts for PWM to the selected
64
     * rate (in CTC mode)
65
     */
66
    OCR2 = (CLK_RATE / GUIDE_RATE / 1024);
67
    TCCR2 = _BV(WGM21) | _BV(CS22) | _BV(CS20);
68
 
69
    /* Enable interrupt generation from timer 2 */
70
    TIMSK |= _BV(OCIE2);
71
}
72
 
73
/* pguideInt() is called whenever a timer 2 overflow interrupt occurs
74
 *
75
 * Passed:
76
 *      Nothing
77
 *
78
 * Returns:
79
 *      Nothing
80
 */
81
SIGNAL(SIG_OUTPUT_COMPARE2)
82
{
83
    uint8_t             guideBits;
84
 
85
    static uint8_t      lastState = GUIDE_BITS;
86
    static uint8_t      lastUsed = GUIDE_BITS;
87
 
88
    /* Get the guide bits */
89
    guideBits = GUIDE_PIN & GUIDE_BITS;
90
 
91
    /* See if they're the same as the last set. If they are then we
92
     * assume that the guide bits are stable
93
     */
94
    if (guideBits != lastState)
95
    {
96
        /* Bits are changing */
97
        lastState = guideBits;
98
    }
99
    else if (lastUsed != lastState)
100
    {
101
        /* They're stable and different from the last used set, so
102
         * update the guiding information
103
         */
104
 
105
        if ((guideBits & _BV(G_UP)) == 0)
106
            rateInput.guideDecRate = SPEED_0_33_X;
107
        else if ((guideBits & _BV(G_DN)) == 0)
108
            rateInput.guideDecRate = -SPEED_0_33_X;
109
        else
110
            rateInput.guideDecRate = SPEED_0_X;
111
 
112
        if ((guideBits & _BV(G_RT)) == 0)
113
            rateInput.guideRaRate = SPEED_0_33_X;
114
        else if ((guideBits & _BV(G_LT)) == 0)
115
            rateInput.guideRaRate = -SPEED_0_33_X;
116
        else
117
            rateInput.guideRaRate = SPEED_0_X;
118
 
119
        /* Update the overall rate */
120
        updateMountSpeed();
121
 
122
        /* Update the last used state ('cuz we used it) */
123
        lastUsed = lastState;
124
    }
125
}