Blame | Last modification | View Log | Download
/*
* Copyright (C) 2004 Darren Hutchinson (dbh@gbdt.com.au)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
* License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*
* $Id: pguide.c,v 1.1.1.1 2004/02/22 08:12:42 dbh Exp $
*/
/* This file contains the code that takes inputs from a parallel output
* guider (such as the SBIG ST-4) and uses them to make guiding
* adjustments.
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include "eq6.h"
#include "combine.h"
#include "pguide.h"
#define GUIDE_BITS (_BV(G_UP) | _BV(G_DN) | _BV(G_RT) | _BV(G_LT))
/* This module polls the input bits from the guider, applies some
* crude debouncing, and then applies the requested speed adjustment.
*
* This code assumes that the inputs are active low (i.e. they are connected
* to a relay or optocoupler connecting the "active" input to ground).
*
* The polling rate is generated by a 8-bit timer with /256
*/
/* pguideInit() initializes the timer used to poll the parallel guiding
* input bits and sets those bit as inputs.
*
* Passed:
* Nothing
*
* Returns:
* Nothing
*
*/
void
pguideInit(void)
{
/* Set guide bits as inputs with pullups */
GUIDE_DDR &= ~GUIDE_BITS;
GUIDE_PORT |= GUIDE_BITS;
/* Setup timer 2 to generate interrupts for PWM to the selected
* rate (in CTC mode)
*/
OCR2 = (CLK_RATE / GUIDE_RATE / 1024);
TCCR2 = _BV(WGM21) | _BV(CS22) | _BV(CS20);
/* Enable interrupt generation from timer 2 */
TIMSK |= _BV(OCIE2);
}
/* pguideInt() is called whenever a timer 2 overflow interrupt occurs
*
* Passed:
* Nothing
*
* Returns:
* Nothing
*/
SIGNAL(SIG_OUTPUT_COMPARE2)
{
uint8_t guideBits;
static uint8_t lastState = GUIDE_BITS;
static uint8_t lastUsed = GUIDE_BITS;
/* Get the guide bits */
guideBits = GUIDE_PIN & GUIDE_BITS;
/* See if they're the same as the last set. If they are then we
* assume that the guide bits are stable
*/
if (guideBits != lastState)
{
/* Bits are changing */
lastState = guideBits;
}
else if (lastUsed != lastState)
{
/* They're stable and different from the last used set, so
* update the guiding information
*/
if ((guideBits & _BV(G_UP)) == 0)
rateInput.guideDecRate = SPEED_0_33_X;
else if ((guideBits & _BV(G_DN)) == 0)
rateInput.guideDecRate = -SPEED_0_33_X;
else
rateInput.guideDecRate = SPEED_0_X;
if ((guideBits & _BV(G_RT)) == 0)
rateInput.guideRaRate = SPEED_0_33_X;
else if ((guideBits & _BV(G_LT)) == 0)
rateInput.guideRaRate = -SPEED_0_33_X;
else
rateInput.guideRaRate = SPEED_0_X;
/* Update the overall rate */
updateMountSpeed();
/* Update the last used state ('cuz we used it) */
lastUsed = lastState;
}
}