/*
Partial source listing for
Linear Actuator Elevation Control and Display
Jim White, WD0E. February,
2001
*/
bit last_pulse_state = 0;
//save of last pulse high or low state
int up = 0;
//moving
up = 1 or down = 0
char outdata[16];
//buffer
for output to LDC
eeprom int zero_ele;
//counts of
pulses at zero elevation.
eeprom int ninty_ele;
//counts at 90
elevation
eeprom int posit;
//position
in pulse transitions.
int degrees = 0;
//degrees
of elevation
char c;
//input
character from UART
eeprom float mult;
//counts
per degree after calibration
char tmpstring[5];
//diagnostic
for testing
void do_math(void)
//calculate the
counts, then the degrees and display
{
if (up)
posit++;
else
posit--;
degrees =
((float)posit-(float)zero_ele) / mult;
sprintf(outdata,"C=%4d Deg=%d ",posit,degrees);
lcd_gotoxy(0,1);
lcd_puts(outdata);
ftoa(mult,10,tmpstring);
printf("DIAG: posit = %d, mult = %s, degrees %d\n\r",posit,tmpstring,degrees);
}
void main(void)
{
printf("\n\rElevation Control starting\n\r");
while (1)
{
//Loop till power comes on up or down
while(PINA.1 == 0 && PINA.2 == 0) {
//No power
lcd_gotoxy(0,0);
lcd_putsf("ELEVATION OFF ");
//last position
sprintf(outdata,"C=%4d Deg=%2d",posit,degrees);
lcd_gotoxy(0,1);
lcd_puts(outdata);
//if a char in the serial buffer then user wants
if (rx_counter > 0) {
c = getchar(); // to start calibration
switch (c) {
case '0' :
posit = 100;
zero_ele = posit;
printf("\n\rZero location saved.");
printf("\n\rMove elevation to ninty degrees and hit 9 ");
break;
case '9' :
ninty_ele = posit;
mult = ((float)ninty_ele - (float)zero_ele)/90;
ftoa(mult,10,tmpstring);
printf("\n\rmult = %s",tmpstring);
printf("\n\r90 degree elevation saved.");
printf("\n\rCalibration complete");
break;
default :
printf("\n\rStarting calibration.");
printf("\n\rMove elevation to zero degrees and hit 0 ");
break;
} //switch
} //if character in buffer
} //while
no power applied
//Power
is applied
lcd_gotoxy(0,0);
//See
if we are going up or down
if(PINA.1) {
lcd_putsf("ELEVATION UP ");
//And show it
printf("Elevation up posit = %d\n\r",posit);
up = 1;
}
else {
lcd_putsf("ELEVATION DOWN");
printf("Elevation down posit = %d\n\r", posit);
up = 0;
}
//Now count pulses
while(PINA.0 == last_pulse_state) {};
//loop till pulse state changes
last_pulse_state = PINA.0;
//save
this as last state
printf("pulse\n\r");
do_math();
//go
calc the degrees and display
} //while
1
} //main