View unanswered posts | View active topics It is currently Tue Sep 30, 2014 7:19 am






Reply to topic  [ 3 posts ] 
Timers 
Author Message
Rookie

Joined: Mon Nov 15, 2010 9:52 pm
Posts: 4
Post 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();
}

}


Tue Apr 26, 2011 10:03 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post 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

_________________
sudo rm -rf /


Tue Apr 26, 2011 10:58 pm
Profile
Site Admin
Site Admin

Joined: Tue May 15, 2007 9:02 am
Posts: 405
Post 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.

_________________
Jesse Flot
CMU Robotics Academy
ROBOTC Support


Wed Apr 27, 2011 4:11 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.