You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
619 lines
16 KiB
619 lines
16 KiB
#include "StdAfx.h"
|
|
#include "ISA.h"
|
|
#include "Timer.h"
|
|
#include "A2D.h"
|
|
#include "SysClock.h"
|
|
|
|
//#define ENCODER_6000_PULSES
|
|
|
|
#define LGS_PULSE_COUNT 6000
|
|
#define LGS_SERIAL_ENABLE // Enable Embed Serial Number
|
|
|
|
#ifdef LGS_SERIAL_ENABLE
|
|
static WORD wBoardSN = 0xABCD; // Serial Number Of Board
|
|
static WORD wProgrammSN = 0;
|
|
static BOOL bWorkingEnable = FALSE;
|
|
#endif
|
|
|
|
#ifdef ENCODER_6000_PULSES
|
|
#define TEMPERATURE_ENABLE
|
|
#else
|
|
#define TEMPERATURE_ENABLE
|
|
|
|
// #define MOTOR_GEAR_RATIO 61 /*150*/ // 61
|
|
// #define ENCODER_PULSE_COUNT 6 /*10*/ // 6
|
|
#define MOTOR_GEAR_RATIO 150 // 50
|
|
#define ENCODER_PULSE_COUNT 1 // 30
|
|
#define ENCODER_PULSE_HIRES_COUNT (LGS_PULSE_COUNT / MOTOR_GEAR_RATIO)
|
|
#define ENCODER_PULSE_HIRES_REMAIN (LGS_PULSE_COUNT % MOTOR_GEAR_RATIO)
|
|
|
|
#define HIRES_MEASUREMENT_START_TIME 150
|
|
#endif
|
|
|
|
//#define ISA_DEFAULT_MODE_READ_BUS
|
|
|
|
sbit ISA_IOW = P3^7;
|
|
sbit ISA_IOR = P3^6;
|
|
sbit ISA_IOCHRDY = P3^5;
|
|
sbit ISA_AEN = P3^4;
|
|
sbit ISA_IRQ5 = P1^0;
|
|
|
|
sbit ISA_BUFFER_OE = P4^6;
|
|
sbit ISA_BUFFER_DIR = P4^7; // if low then A = B (ISA = MCU)
|
|
|
|
sbit ENCODER_PhA = P2^4;
|
|
sbit ENCODER_PhB = P2^5;
|
|
sbit ENCODER_ZERO = P2^6;
|
|
|
|
sbit DRY_CONTACT_1 = P1^6;
|
|
sbit DRY_CONTACT_2 = P1^7;
|
|
|
|
sbit LRF_ENABLE = P0^7;
|
|
sbit LRF_READY = P2^2;
|
|
sbit LRF_SUN_1 = P2^1;
|
|
sbit LRF_SUN_2 = P2^0;
|
|
|
|
sbit HEATER_ENABLE = P0^6;
|
|
|
|
#define ISA_DIR_IOCHRDY P3MDOUT
|
|
#define ISA_DIR_IRQ5 P1MDOUT
|
|
|
|
#define DRY_CONTACT_DIR P1MDOUT
|
|
|
|
#define ISA_REGISTER_COUNT 16
|
|
|
|
// fast variables
|
|
static BYTE ISA_bRegEnable = 0;
|
|
static BYTE ISA_bRegIndex = 0;
|
|
static BYTE ISA_pRegValue[ISA_REGISTER_COUNT];
|
|
|
|
static BYTE ISA_bTxAddress;
|
|
static BYTE ISA_bTxData4[2] = {0};
|
|
static BYTE ISA_bTxData5[2] = {0};
|
|
static BYTE ISA_bTxIndex = 0;
|
|
static BYTE ISA_bAccessCount= 0;
|
|
|
|
CBYTE ISA_BitReverseTable256[] =
|
|
{
|
|
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
|
|
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
|
|
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
|
|
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
|
|
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
|
|
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
|
|
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
|
|
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
|
|
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
|
|
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
|
|
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
|
|
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
|
|
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
|
|
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
|
|
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
|
|
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
|
|
};
|
|
|
|
// slow variables
|
|
static BOOL bZero = TRUE;
|
|
static BOOL bZeroCheck = TRUE;
|
|
|
|
#ifdef ENCODER_6000_PULSES
|
|
static BYTE bPhaseStateAB = 0;
|
|
#else
|
|
static BOOL bReadyZero = FALSE;
|
|
static INT nAngle = 0;
|
|
static WORD nPulseTime = MICRO_SEC_TO_HIRES(160L);
|
|
static BOOL bPhaseCheck = TRUE;
|
|
static INT nAngle6 = 0;
|
|
static BOOL bReady6 = FALSE;
|
|
static INT nPulseCount = 0;
|
|
static WORD nHiResolutionCount = 0;
|
|
static WORD nHiResolutionTemp = 0;
|
|
static DWORD nHiResolutionTimer = 0;
|
|
static BYTE nHiResolutionStart = HIRES_MEASUREMENT_START_TIME;
|
|
#endif
|
|
|
|
static BOOL bReset = TRUE;
|
|
|
|
static UNION_WORD wRange1 = {0};
|
|
static UNION_WORD wRange2 = {0};
|
|
static WORD wTemperature = 0;
|
|
static BOOL bSun1 = FALSE;
|
|
static BOOL bSun2 = FALSE;
|
|
static INT nZeroShift = 0;
|
|
|
|
#ifdef TEMPERATURE_ENABLE
|
|
static WORD wTemperatureON = 0;
|
|
static WORD wTemperatureOFF = 0;
|
|
#endif
|
|
|
|
static BYTE bTemp;
|
|
|
|
static XBYTE pRelayBuffer[32];
|
|
static INT nRelayBuffer = 0;
|
|
|
|
void ISA_Init()
|
|
{
|
|
// init fast variables
|
|
ISA_bRegEnable = 0;
|
|
ISA_bTxIndex = 0;
|
|
ISA_bAccessCount = 0;
|
|
|
|
// init slow variables
|
|
bZero = FALSE;
|
|
bZeroCheck = TRUE;
|
|
|
|
#ifdef ENCODER_6000_PULSES
|
|
bPhaseStateAB = 0;
|
|
#else
|
|
bReadyZero = FALSE;
|
|
nPulseTime = MICRO_SEC_TO_HIRES(160L);
|
|
nAngle = 0;
|
|
bPhaseCheck = TRUE;
|
|
nAngle6 = 0;
|
|
bReady6 = FALSE;
|
|
nPulseCount = 0;
|
|
nHiResolutionCount = 0;
|
|
nHiResolutionTemp = 0;
|
|
nHiResolutionTimer = 0;
|
|
nHiResolutionStart = HIRES_MEASUREMENT_START_TIME;
|
|
#endif
|
|
|
|
wRange1.wValue = 0;
|
|
wRange2.wValue = 0;
|
|
wTemperature = 0;
|
|
bSun1 = FALSE;
|
|
bSun2 = FALSE;
|
|
|
|
bReset = TRUE;
|
|
}
|
|
|
|
void ISA_Serve()
|
|
{
|
|
|
|
// init DAC0
|
|
SFRPAGE = DAC0_PAGE;
|
|
DAC0L = 0xFF;
|
|
DAC0H = 0xFF;
|
|
DAC0CN = 0x80;
|
|
|
|
SFRPAGE = CONFIG_PAGE;
|
|
|
|
#ifdef TEMPERATURE_ENABLE
|
|
// heater control
|
|
P0MDOUT |= (1<<6);
|
|
HEATER_ENABLE = TRUE;
|
|
#endif
|
|
|
|
// clear LRF
|
|
P0MDOUT |= (1<<7);
|
|
LRF_ENABLE = FALSE;
|
|
|
|
// clear dry contacts
|
|
DRY_CONTACT_DIR |= (1<<6);
|
|
DRY_CONTACT_DIR |= (1<<7);
|
|
DRY_CONTACT_1 = TRUE;
|
|
DRY_CONTACT_2 = TRUE;
|
|
|
|
// clear IRQ5
|
|
ISA_DIR_IRQ5 |= (1<<0);
|
|
ISA_IRQ5 = 0;
|
|
|
|
// set ISA data as output
|
|
#ifdef ISA_DEFAULT_MODE_READ_BUS
|
|
P7MDOUT = 0x00; // set P7 as input
|
|
P7 = 0xFF;
|
|
#else
|
|
P7MDOUT = 0xFF; // set P7 as output
|
|
P7 = 0x00;
|
|
#endif
|
|
|
|
|
|
#ifndef ENCODER_6000_PULSES
|
|
// init HI resolution timer
|
|
nHiResolutionCount = HiResTimer0_Get();
|
|
nHiResolutionTimer = 0;
|
|
nHiResolutionStart = HIRES_MEASUREMENT_START_TIME;
|
|
|
|
// restart IRQ timer
|
|
HiResTimer1_Restart( -nPulseTime );
|
|
#endif
|
|
SFRPAGE = DAC0_PAGE; // Add 15Sep2009 to speed up motor
|
|
DAC0L = 0xFF;
|
|
DAC0H = 0xFF; // DAC mid value 0x7D
|
|
SFRPAGE = CONFIG_PAGE;
|
|
|
|
while( TRUE )
|
|
{
|
|
// process ISA requests
|
|
if( ISA_AEN == 0 && P5 == 0x03 )
|
|
{
|
|
ISA_DIR_IOCHRDY |= (1<<5);
|
|
ISA_IOCHRDY = 0; // hold bus circle
|
|
|
|
if( ISA_IOR == 0 )
|
|
{
|
|
if( P6 == 0x04 || P6 == 0x05 || P6 == 0x09 || P6 == 0x0A || P6 == 0x0B )
|
|
{
|
|
ISA_IRQ5 = 0; // clear interrupt
|
|
|
|
#ifdef ISA_DEFAULT_MODE_READ_BUS
|
|
P7MDOUT = 0xFF; // set P7 as output
|
|
#endif
|
|
|
|
ISA_BUFFER_DIR = 0; // set DIR to write to bus
|
|
ISA_BUFFER_OE = 0; // set OE low to enable buffer
|
|
|
|
switch( P6 )
|
|
{
|
|
case 0x04: P7 = ISA_bTxData4[ISA_bTxIndex]; break;
|
|
case 0x05: P7 = ISA_bTxData5[ISA_bTxIndex++]; break;
|
|
case 0x09: P7 = 0x5A; break;
|
|
// Serial Nuber Handshake
|
|
case 0x0A:{
|
|
P7 = ISA_BitReverseTable256[ 0xFF & wBoardSN ];
|
|
break;
|
|
};
|
|
case 0x0B:{
|
|
P7 = ISA_BitReverseTable256[( wBoardSN >> 8)];
|
|
break;
|
|
};
|
|
}
|
|
|
|
ISA_IOCHRDY = 1; // ready to end of bus circle
|
|
ISA_DIR_IOCHRDY &= ~(1<<5);
|
|
|
|
if( ISA_bAccessCount ) // decrease access count
|
|
ISA_bAccessCount--;
|
|
|
|
while( ISA_IOR == 0 ); // wait end of bus circle
|
|
|
|
ISA_BUFFER_OE = 1; // set OE high to Z-state the buffer
|
|
|
|
#ifdef ISA_DEFAULT_MODE_READ_BUS
|
|
P7MDOUT = 0x00; // set P7 as input
|
|
P7 = 0xFF;
|
|
#endif
|
|
}
|
|
}
|
|
else
|
|
if( ISA_IOW == 0 )
|
|
{
|
|
if( P6 == 0x0A || P6 == 0x0A || P6 == 0x06 || P6 == 0x07 || P6 == 0x08 )
|
|
{
|
|
ISA_IRQ5 = 0; // clear interrupt
|
|
|
|
#ifndef ISA_DEFAULT_MODE_READ_BUS
|
|
P7MDOUT = 0x00; // set P7 as input
|
|
P7 = 0xFF;
|
|
#endif
|
|
|
|
ISA_BUFFER_DIR = 1; // set DIR to read from bus
|
|
ISA_BUFFER_OE = 0; // set OE low to enable buffer
|
|
|
|
switch( P6 )
|
|
{
|
|
case 0x06: bTemp = P7; bReset = (bTemp ^ ISA_bRegEnable) & 0xC0; ISA_bRegEnable = bTemp; break;
|
|
case 0x07: ISA_bRegIndex = ISA_BitReverseTable256[P7] & (ISA_REGISTER_COUNT-1); bReset = TRUE; break;
|
|
case 0x08: ISA_pRegValue[ISA_bRegIndex] = ISA_BitReverseTable256[P7]; bReset = TRUE; break;
|
|
// Serial Nuber Handshake
|
|
case 0x0A:{
|
|
bTemp = ISA_BitReverseTable256[P7];
|
|
bWorkingEnable = TRUE;
|
|
wProgrammSN = bTemp;
|
|
break;
|
|
};
|
|
case 0x0B:{
|
|
bTemp = ISA_BitReverseTable256[P7];
|
|
bWorkingEnable = TRUE;
|
|
wProgrammSN = wProgrammSN & ( bTemp<<8 );
|
|
break;
|
|
};
|
|
}
|
|
|
|
#ifndef ISA_DEFAULT_MODE_READ_BUS
|
|
P7MDOUT = 0xFF; // set P7 as output
|
|
#endif
|
|
|
|
ISA_BUFFER_OE = 1; // set OE high to Z-state the buffer
|
|
}
|
|
}
|
|
|
|
ISA_IOCHRDY = 1; // ready to end of bus circle
|
|
ISA_DIR_IOCHRDY &= ~(1<<5);
|
|
}
|
|
|
|
#ifdef ENCODER_6000_PULSES
|
|
|
|
#define PHASE_STATE_AB_MASK ((1<<4)|(1<<5))
|
|
|
|
// wait for phase change
|
|
if( (P2 & PHASE_STATE_AB_MASK) == bPhaseStateAB )
|
|
continue;
|
|
|
|
bPhaseStateAB = P2 & PHASE_STATE_AB_MASK;
|
|
|
|
#else
|
|
// wait for end of ISA serving circle
|
|
SFRPAGE = TIMER01_PAGE;
|
|
if( !TF1 )
|
|
{
|
|
SFRPAGE = CONFIG_PAGE;
|
|
continue;
|
|
}
|
|
TF1 = 0;
|
|
SFRPAGE = CONFIG_PAGE;
|
|
#endif
|
|
// if interrupt no LRF is enabled
|
|
if( (ISA_bRegEnable & 0xC0) == 0 )
|
|
continue;
|
|
|
|
// reset encoder and timeouts
|
|
if( bReset )
|
|
{
|
|
bReset = FALSE;
|
|
|
|
ISA_bAccessCount = 0;
|
|
ISA_IRQ5 = 0;
|
|
|
|
bZero = TRUE;
|
|
bZeroCheck = FALSE;
|
|
|
|
|
|
if ( wProgrammSN > 0 ) bWorkingEnable = TRUE;
|
|
|
|
|
|
#ifndef ENCODER_6000_PULSES
|
|
bReadyZero = FALSE;
|
|
nAngle = 0;
|
|
nPulseTime = MICRO_SEC_TO_HIRES(160L);
|
|
|
|
bPhaseCheck = TRUE;
|
|
nAngle6 = 0;
|
|
bReady6 = FALSE;
|
|
nPulseCount = 0;
|
|
|
|
nHiResolutionCount = 0;
|
|
nHiResolutionTemp = 0;
|
|
nHiResolutionTimer = 0;
|
|
nHiResolutionStart = HIRES_MEASUREMENT_START_TIME;
|
|
#endif
|
|
|
|
nZeroShift = ((WORD)ISA_pRegValue[5] << 8) | ISA_pRegValue[6];
|
|
|
|
#ifdef TEMPERATURE_ENABLE
|
|
wTemperatureON = ADC0_Temperature2Adc( (((LONG)(CHAR)ISA_pRegValue[4]) ) * 10L );
|
|
wTemperatureOFF = ADC0_Temperature2Adc( (((LONG)(CHAR)ISA_pRegValue[4]) + 1L) * 10L );
|
|
#endif
|
|
|
|
wRange1.wValue = 0;
|
|
wRange2.wValue = 0;
|
|
|
|
bSun1 = 0;
|
|
bSun2 = 0;
|
|
|
|
SFRPAGE = DAC0_PAGE; // Add 15Sep2009 to speed up motor after reset
|
|
DAC0L = 0xFF;
|
|
DAC0H = 0xFF; // DAC mid value 0x7D
|
|
SFRPAGE = CONFIG_PAGE;
|
|
|
|
}
|
|
|
|
#ifndef ENCODER_6000_PULSES
|
|
// reset IRQ timer
|
|
HiResTimer1_Restart( -nPulseTime );
|
|
|
|
// calculate hi resolution time
|
|
nHiResolutionTemp = HiResTimer0_Get();
|
|
nHiResolutionTimer += (DWORD)(nHiResolutionTemp - nHiResolutionCount);
|
|
nHiResolutionCount = nHiResolutionTemp;
|
|
#endif
|
|
|
|
// produce zero mark (very importent to syncronize zero mark with encoder positions)
|
|
if( ENCODER_ZERO )
|
|
{
|
|
if( bZeroCheck )
|
|
{
|
|
bZeroCheck = FALSE;
|
|
bZero = TRUE;
|
|
|
|
#ifndef ENCODER_6000_PULSES
|
|
bReadyZero = TRUE;
|
|
nAngle = 0;
|
|
#endif
|
|
}
|
|
}
|
|
else
|
|
bZeroCheck = TRUE;
|
|
|
|
#ifndef ENCODER_6000_PULSES
|
|
// move motor angle
|
|
if( ENCODER_PhA )
|
|
{
|
|
if( bPhaseCheck )
|
|
{
|
|
bPhaseCheck = FALSE;
|
|
|
|
// find synch point
|
|
if( nAngle6 == ENCODER_PULSE_COUNT )
|
|
{
|
|
nAngle6 = 0;
|
|
bReady6 = TRUE;
|
|
|
|
// calculate amount of angles until next sync point
|
|
nPulseCount += ENCODER_PULSE_HIRES_REMAIN;
|
|
if( nPulseCount >= MOTOR_GEAR_RATIO )
|
|
{
|
|
nPulseCount -= MOTOR_GEAR_RATIO;
|
|
nPulseTime = nHiResolutionTimer / ( ENCODER_PULSE_HIRES_COUNT - 1 );
|
|
}
|
|
else
|
|
nPulseTime = nHiResolutionTimer / ( ENCODER_PULSE_HIRES_COUNT ); // changed to +1 from 0 for 6000, in 362 should be 0!!!
|
|
|
|
// validate time measurement
|
|
if( nHiResolutionStart )
|
|
{
|
|
nHiResolutionStart--;
|
|
|
|
if( nPulseTime > MICRO_SEC_TO_HIRES(200L) ) // 3 kHz
|
|
nPulseTime = MICRO_SEC_TO_HIRES(200L);
|
|
}
|
|
else
|
|
{
|
|
if( nPulseTime > MICRO_SEC_TO_HIRES(400L) ) // 2.5 kHz
|
|
nPulseTime = MICRO_SEC_TO_HIRES(400L);
|
|
}
|
|
|
|
nHiResolutionTimer = 0;
|
|
|
|
// update DAC according to speed
|
|
SFRPAGE = DAC0_PAGE;
|
|
DAC0L = nPulseTime << 2;
|
|
DAC0H = nPulseTime >> 6;
|
|
|
|
/* DAC0L = 0xFF; // DAC mid value
|
|
DAC0H = 0x7D;
|
|
*/
|
|
SFRPAGE = CONFIG_PAGE;
|
|
}
|
|
nAngle6++; //moved from "if" condition to avoid false start without motor
|
|
}
|
|
}
|
|
else
|
|
bPhaseCheck = TRUE;
|
|
#endif
|
|
|
|
// set dry contacts
|
|
DRY_CONTACT_1 = (ISA_bRegEnable & 0x10) != 0x10;
|
|
DRY_CONTACT_2 = (ISA_bRegEnable & 0x20) != 0x20;
|
|
|
|
// continue to search for zero mark and 6 angles
|
|
#ifndef ENCODER_6000_PULSES
|
|
if( !bReadyZero || !bReady6 )
|
|
continue;
|
|
|
|
// check zero mark
|
|
bZero = (nZeroShift == nAngle);
|
|
|
|
// move angle
|
|
nAngle++;
|
|
|
|
if( nAngle > LGS_PULSE_COUNT )
|
|
continue;
|
|
#endif
|
|
|
|
// if not all data were processed than stop interrupt generation
|
|
if( ISA_bAccessCount )
|
|
{
|
|
ISA_IRQ5 = 0;
|
|
ISA_bAccessCount = 0;
|
|
ISA_bRegEnable &= ~0xC0;
|
|
continue;
|
|
}
|
|
|
|
// start LRF (and temperature measurenment)
|
|
LRF_ENABLE = TRUE;
|
|
wTemperature = ADC0_Convert( 0x0F );
|
|
LRF_ENABLE = FALSE;
|
|
|
|
// wait for LRF ready (around 15 uS)
|
|
// HiResTimer0_Wait( MICRO_SEC_TO_HIRES(15) ); // 20 - ok, but 25 probably better
|
|
#ifdef ENCODER_6000_PULSES
|
|
// HiResTimer1_Wait( 28+5+15+10 ); // +10 added 2006/11/08
|
|
HiResTimer1_Wait( 58 ); // 07Sep2009 try to optimize
|
|
#else
|
|
// HiResTimer1_Wait( 28+5+10 ); // +10 added 2006/11/08
|
|
HiResTimer1_Wait( 30 ); // 07Sep2009 try to optimize (native 43)
|
|
#endif
|
|
|
|
// convert ranges
|
|
if( (ISA_bRegEnable & 0x80) == 0x80 )
|
|
{
|
|
wRange1.wValue = ADC0_Convert( 0x00 );
|
|
bSun1 = !LRF_SUN_1;
|
|
}
|
|
|
|
if( (ISA_bRegEnable & 0x40) == 0x40 )
|
|
{
|
|
wRange2.wValue = ADC0_Convert( 0x01 );
|
|
bSun2 = !LRF_SUN_2;
|
|
}
|
|
|
|
#ifdef TEMPERATURE_ENABLE
|
|
// heater control
|
|
if( HEATER_ENABLE )
|
|
{
|
|
if( wTemperature < wTemperatureON )
|
|
HEATER_ENABLE = FALSE;
|
|
}
|
|
else
|
|
{
|
|
// histeresis - one degree of Celsius
|
|
if( wTemperature > wTemperatureOFF )
|
|
HEATER_ENABLE = TRUE;
|
|
}
|
|
#endif
|
|
|
|
#ifdef SPIKES_TEST
|
|
if( nAngle & 0x100 )
|
|
{
|
|
wRange1.wValue = 0x0FFF / 2;
|
|
wRange2.wValue = 0x0FFF / 4;
|
|
}
|
|
else
|
|
{
|
|
wRange1.wValue = 0x0FFF / 4;
|
|
wRange2.wValue = 0x0FFF / 2;
|
|
}
|
|
#endif
|
|
|
|
if ( bWorkingEnable ){
|
|
// ranges will be negatived on PC side
|
|
wRange1.wValue = 0x0FFF - wRange1.wValue;
|
|
wRange2.wValue = 0x0FFF - wRange2.wValue;
|
|
} else {
|
|
wRange1.wValue = 0;
|
|
wRange2.wValue = 0;
|
|
if ( (nAngle - nZeroShift) == 1113 ) bZero = TRUE;
|
|
};
|
|
|
|
// prepare data for sending to other side
|
|
|
|
ISA_bTxData4[0] = (ISA_BitReverseTable256[ wRange1.bValue.bLo ] );
|
|
ISA_bTxData5[0] = (ISA_BitReverseTable256[ wRange1.bValue.bHi ] & ~0x0F);
|
|
|
|
ISA_bTxData4[1] = (ISA_BitReverseTable256[ wRange2.bValue.bLo ] );
|
|
ISA_bTxData5[1] = (ISA_BitReverseTable256[ wRange2.bValue.bHi ] & ~0x0F);
|
|
|
|
if( bZero )
|
|
{
|
|
ISA_bTxData5[0] |= 0x08;
|
|
ISA_bTxData5[1] |= 0x08;
|
|
bZero = FALSE;
|
|
}
|
|
|
|
if( bSun1 )
|
|
{
|
|
ISA_bTxData5[0] |= 0x04;
|
|
ISA_bTxData5[1] |= 0x04;
|
|
}
|
|
|
|
if( bSun2 )
|
|
{
|
|
ISA_bTxData5[0] |= 0x02;
|
|
ISA_bTxData5[1] |= 0x02;
|
|
}
|
|
|
|
// power OK
|
|
ISA_bTxData5[0] |= 0x01;
|
|
ISA_bTxData5[1] |= 0x01;
|
|
|
|
// expected 4 inport reads via ISA bus
|
|
ISA_bAccessCount = 4;
|
|
ISA_bTxIndex = 0;
|
|
|
|
// restart ISA bus serve time
|
|
ISA_IRQ5 = 1;
|
|
}
|
|
}
|
|
|