//---------------------------------------------------------------------
// File: capture.c
//
// Written By: Lawrence Glaister VE7IT
//
// Purpose: This set of routines deals with using 2 pins
// connected to the PC as a quadrature signal for incrementing or
// decementing commanded position. The IC1 and IC2 pins are used
// and are setup to generate an interrupt on each edge change.
// The ISR's then looks at the state of IC1 and IC2 and uses
// a state machine to incr or decr the commanded position.
// The IC1 and IC2 pins are smidt trigger inputs.
// The CN inputs could also have been used to detect change of state on
// the 2 pc command pins as we dont use most of the input capture
// functionality.
//
//
//---------------------------------------------------------------------
//
// Revision History
//
// Aug 7 2006 -- first version Lawrence Glaister
// Aug 15 2006 added pc command pulse multiplier option
//----------------------------------------------------------------------
#include "dspicservo.h"
extern struct PID pid;
volatile unsigned short int cmd_posn; // current posn cmd from PC
volatile unsigned short int cmd_err; // number of bogus encoder positions
detected
volatile unsigned short int cmd_bits; // a 4 bit number with old and new port values
// 4 functions that perform adjustments to the commanded position
void change_NO(void)
{
cmd_err++; // got an intr with no change in port (spike?)
}
void change_UP(void)
{
cmd_posn += pid.multiplier;
}
void change_DN(void)
{
cmd_posn -= pid.multiplier;
评论0