For the navigation mode, I need to decrement a distance counter. Now that I used the interupt pin for the std line, I can think of two options,
1. Use tmr0 and increment it by the motor encorder signal, and do a calculation of the distance entered by the user like,
rounds = distance % 255 + distance / 255
here the distance / 255 is the number of 255 rounds you need to pass and distance % 255 is the remainder.
So I have to constantly check whether 255s are over and at last if they are over,
check whether the remainder = distance % 255
and stop the robot.
2. I can connect the encorder via a diode to the interupt pin, then power on the encorder only when the navigation mode is used, increment a counter and compair the distance, assuming the user wont press a button till the robot gets to position. Or I can also swich off the std line using a transistor. And I can check for a combination to force stop the robot, like if the user press *.
Which way is better? I think the 2nd way is good.
---------- Post added at 19:36 ---------- Previous post was at 18:49 ----------
Code:
//navigational mode
void navigationalMode(struct CTRL *pCtrl)
{
pCtrl->number = 0;
//add a .25S delay
//add a beep to prompt for distance
j = 0;
while(1)
{ // order of the digits - d1,d2,d3 983 - d1 = 9 d2 = 8 d3 = 3
if(j=1)
{
pCtrl->d1 = pCtrl->number;
}
if(j=2)
{
pCtrl->d2 = pCtrl->number;
}
if(j=3)
{
pCtrl->d3 = pCtrl->number;
break;
}
}
j=0;
pCtrl->distance = (pCtrl->d1)*100+(pCtrl->d2)*10+(pCtrl->d3);
//add a .25S delay
// add a beep to prompt for direction
while(1)
{
if(std = 1)
{
pCtrl->direction = pCtrl->number;
break;
}
}
//add a .25S delay
// add a beep to prompt for drive
while(1)
{
if(std == 1 && pCtrl->number == 12)
{
drive(pCtrl);
}
}
}
void interupt()
{
INTCON.GIE = 0;
if(INTCON.INTF)
{
if(control.mode == 1)
{
dtmfToNumber(&control); //which address should I give? control is not a local variable.
INTCON.INTF = 0;
}
if(control.mode == 2)
{
j++;
}
INTCON.GIE = 1;
}
}
Drive mode and interrupt routine are not complete yet, I will set the encorder first. If you give me example of function pointers now, I mean how and where I should use them, I think I can continue.
Thank you.