|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
create a counter for the autonomous code?
![]() |
|
#2
|
|||
|
|||
|
Re: how do you...
Quote:
If it is time based then one of the loops of the program happens every 26ms(I think). Just count the program loops and you have time. |
|
#3
|
|||
|
|||
|
Re: how do you...
Quote:
|
|
#4
|
|||||
|
|||||
|
Re: how do you...
How would you create a Time Based counter?
|
|
#5
|
||||
|
||||
|
Re: how do you...
Quote:
~Aaron |
|
#6
|
||||
|
||||
|
Re: how do you...
Quote:
|
|
#7
|
|||||
|
|||||
|
Re: how do you...
From where do you get all these help files and manuals?
|
|
#8
|
|||||
|
|||||
|
Re: how do you...
IFI, mostly.
|
|
#9
|
||||
|
||||
|
Re: how do you...
here is some rather straight forward code, simular to previous years stuff.
Code:
unsigned int counter;
if(autonmous_code)
{
if(counter <= 20)
{
pwm01 = pwm02 = 255;
}
else if(counter >= 21 && counter <= 100 && counter != 99)
{
pwm01 = 255;
pwm02 = (pwm01 -= 254);
}
else
{
die(void);
}
counter++;
}
|
|
#10
|
||||
|
||||
|
Re: how do you...
Quote:
|
|
#11
|
||||
|
||||
|
Re: how do you...
Just like James said earlier in this thread, I highly recommend using something a little more advanced than just incrementing a counter variable every code cycle. The PIC18F8520 comes with 5 seperate timers (the first of which is used by IFI, so we have access to 4). They're pretty well documented in the datasheet for the microcontroller (sections 11 through 15). Three 8bit timers, and one 16bit timer. With all of the capabilities of the processor, itself, I would be very disappointed to see any team counting cycles as a timing system. I'm already forcing my programming mentees to learn about timers, interrupts, and other such features of these nice little machines.
|
|
#12
|
||||
|
||||
|
Re: how do you...
I don't exactly see the advantage of using interrupts over counting cycles. Care to elaborate?
|
|
#13
|
||||
|
||||
|
Re: how do you...
Quote:
|
|
#14
|
|||||
|
|||||
|
Re: how do you...
Quote:
Program cycles will vary as you add and remove code. The cycles are also variable in general because of other events like interrupts that may be going on asynchronously. So one loop might take 50 clock ticks while the next takes 150 ticks. Over time you can accumulate large variations. The clock approach always puts you within a few clock ticks of where you expect to be, and errors don't accumulate over time. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|