i have a competiion coming up soon and i need to know if i am doing something wrong. i set a timer to run for two minutes but it mever stops. i added a prit to screen to see if i could find the problem and what i found is that the timer keeps resetting to a variable around -32000. how do i keep it going to reach 120000 miliseconds? i know how to stop it and everything but i need it to stop at a variable past the reset point.
i also need to know if there is a way to set a single variable like a counter so that if it passes a point in the program it increase by one. something like,
by “around ~32000”, do you mean a number that is (an integral power of 2) +/-1? If so, you’re probably overflowing your counter. As I don’t know in what language you’re programming, I can’t provide a specific solution. You might be able to use a counter with more bits. If not…
Yes, you can do that, but it’s not clear that you need to.
If you are trying to time something, then that approach is worth pursuing. However, if all you need to do is run a delay for 120,000 milliseconds but have a timer that will run to only approximately 32,000 milliseconds, why not take the easy way out and use four, 30,000 millisecond delays in immediate succession?
i cant have it just have several delays because i need to be able to stop in the middle of different parts of a program. i have many if/else statements and want to stop after two min. no mater what part of the program is in progress. using a timer command doesn’t seem to work b/c of the above stated reset(not intentional) that happens at ~32000 millisecond. but it does not reset to 0 it goes to ~-32000. is this the highest that the microcontroler will go?
I’m pretty sure you are overflowing your timer, there might be a solution in easyC but from what I’ve seen in RobotC the timers count up, hit approx 2^15 then roll over to approx -2^15 (signed and 16 bits - think two’s complement… maybe…). A very umm sketchy? solution would be to run the timer and call a method which increments a variable by 1/10th of the current time then resets the timer. This would give you approx 320000 ms or 320s, more than enough time… with maybe a small error. Though I’m sure there are easier ways and probably smarter ways
If tbe timer is going from 32768 to -32768, it’s probably because it’s using the 16th bit for the sign.
Not being an EasyC user, I’m at a bit of a disadvantage.
If you post a copy of your code in a form that can be read without EasyC (If you need them, there are instructions somewhere in this Forum for doing that.), I’ll take a look.
Have you tested your code with the time set to 30 seconds or some other value that is within the working range of the timer?
How are you having a timer interrupt the program?
How precisely are you trying to time two minutes? Some timing methods will be limited in precision to the time it takes to pass through your main loop. From your remark “want to stop after two min. no mater what part of the program is in progress.” indicates that approach won’t work for you.
Have you considered using whatever mechanism is used to time portions of VEX competitions?
Have you tried using a real time clock (RTC) rather than a timer? Then basic approach is to store the start time in a variable, calculate the end time by adding the desired interval to the start time, then testing however often you deem necessary to see if the RTC value exceeds the calculated end time.
This should make it continue until time is up. I’m not 100% positive thats how you would add to variable counter. Some one with greater programing skills should check this.
Let me know if you need help with this in easyC.
Unfortunately, the PIC18F8520 MCU has only 8-Bit and 16-Bit timers used for measuring time. One possible solution is to use unsigned int which provides a range of 0 to 65535, that prevents the rollover. Another solution is to configure the PIC18F8520 timer peripheral with an appropriate pre-scale and post-scale for longer periods using inline assembly from within the Easy C application. The Timer Peripheral information is available in the PIC18F8520 Data Sheet from Microchip (www.microchip.com).
Connecting an RTC to a PIC is possible if the external oscillator inputs are available, but I don’t believe that the VEX 0.5 Controller has them brought out to the external I/O blocks.
Dallas Semiconductor/MAXIM may have external RTC clocks that could be connected to the VEX Controller using the SPI or I2C or one-wire interfaces.