ROBOTC.net forums
http://www.robotc.net/forums/

Timers
http://www.robotc.net/forums/viewtopic.php?f=11&t=3240
Page 1 of 1

Author:  Coldedge [ Tue Apr 26, 2011 10:03 pm ]
Post subject:  Timers

ok so i"m having issues with the Timers on PIC. for some reason they count from 0 to 30000 and then count in reverse from -29999 to 0. Here's my code for reference. . . I'm attempting to count rotation using a Limit Switch its working, but i can only do it for 30 seconds.

#pragma config(Sensor, in9, limit, sensorTouch)
#pragma config(Motor, port1, dud1, tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

int previous_value;
int output;

void LCD () {
clearLCDLine(0);
clearLCDLine(1);
displayLCDPos(0,0);
displayNextLCDString("Value:");
displayLCDPos(0,7);
displayNextLCDNumber(output);
displayLCDPos(1,0);
displayNextLCDString("Time:");
displayLCDPos(1,9);
displayNextLCDNumber(time1[T1]);
wait1Msec(10);
}
task motorgo (){
while(time1[T1]<60000){
motor[dud1]=127;
}
motor[dud1]=0;
}
void button (){
bool button_value;
if (SensorValue[limit] == 1 && button_value == false) {
output = previous_value + 1;
previous_value = output;
}
if(SensorValue[limit]==1){
button_value = true;
}
else{
button_value = false;
}

}


task main(){
ClearTimer(T1);
while(1==1){
StartTask(motorgo);
button ();
LCD();
}

}

Author:  magicode [ Tue Apr 26, 2011 10:58 pm ]
Post subject:  Re: Timers

While I haven't read your code too deeply, I have a few questions. One, why do you start your task in your while(1 == 1) loop? You should start your task before the while(1 == 1) loop, and add a "wait1MSec(1)" or an "EndTimeSlice()" inside the loop. Two, where do you reset your timer after you start the while(1 == 1) loop? Also, if you want to look into measuring rotation with a limit switch, I suggest that you look at this forum topic: viewtopic.php?f=11&t=2922

Author:  jbflot [ Wed Apr 27, 2011 4:11 pm ]
Post subject:  Re: Timers

Hi Coldedge,

The PIC is pretty limited as far as memory goes, and as such, the largest number you can store is 32767. Counting one more will result in -32768. There are creative ways of getting around this limitation, such as lowering your resolution or "staring over" after you reach a certain number.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/